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 * @extends Roo.util.Observable
30 * Defines the interface and base operation of items that that can be
31 * dragged or can be drop targets. It was designed to be extended, overriding
32 * the event handlers for startDrag, onDrag, onDragOver and onDragOut.
33 * Up to three html elements can be associated with a DragDrop instance:
35 * <li>linked element: the element that is passed into the constructor.
36 * This is the element which defines the boundaries for interaction with
37 * other DragDrop objects.</li>
38 * <li>handle element(s): The drag operation only occurs if the element that
39 * was clicked matches a handle element. By default this is the linked
40 * element, but there are times that you will want only a portion of the
41 * linked element to initiate the drag operation, and the setHandleElId()
42 * method provides a way to define this.</li>
43 * <li>drag element: this represents the element that would be moved along
44 * with the cursor during a drag operation. By default, this is the linked
45 * element itself as in {@link Roo.dd.DD}. setDragElId() lets you define
46 * a separate element that would be moved, as in {@link Roo.dd.DDProxy}.
49 * This class should not be instantiated until the onload event to ensure that
50 * the associated elements are available.
51 * The following would define a DragDrop obj that would interact with any
52 * other DragDrop obj in the "group1" group:
54 * dd = new Roo.dd.DragDrop("div1", "group1");
56 * Since none of the event handlers have been implemented, nothing would
57 * actually happen if you were to run the code above. Normally you would
58 * override this class or one of the default implementations, but you can
59 * also override the methods you want on an instance of the class...
61 * dd.onDragDrop = function(e, id) {
62 * alert("dd was dropped on " + id);
66 * @param {String} id of the element that is linked to this instance
67 * @param {String} sGroup the group of related DragDrop objects
68 * @param {object} config an object containing configurable attributes
69 * Valid properties for DragDrop:
70 * padding, isTarget, maintainOffset, primaryButtonOnly
72 Roo.dd.DragDrop = function(id, sGroup, config) {
74 this.init(id, sGroup, config);
79 Roo.extend(Roo.dd.DragDrop, Roo.util.Observable , {
82 * The id of the element associated with this object. This is what we
83 * refer to as the "linked element" because the size and position of
84 * this element is used to determine when the drag and drop objects have
92 * Configuration attributes passed into the constructor
99 * The id of the element that will be dragged. By default this is same
100 * as the linked element , but could be changed to another element. Ex:
109 * the id of the element that initiates the drag operation. By default
110 * this is the linked element, but could be changed to be a child of this
111 * element. This lets us do things like only starting the drag when the
112 * header element within the linked html element is clicked.
113 * @property handleElId
120 * An associative array of HTML tags that will be ignored if clicked.
121 * @property invalidHandleTypes
122 * @type {string: string}
124 invalidHandleTypes: null,
127 * An associative array of ids for elements that will be ignored if clicked
128 * @property invalidHandleIds
129 * @type {string: string}
131 invalidHandleIds: null,
134 * An indexted array of css class names for elements that will be ignored
136 * @property invalidHandleClasses
139 invalidHandleClasses: null,
142 * The linked element's absolute X position at the time the drag was
144 * @property startPageX
151 * The linked element's absolute X position at the time the drag was
153 * @property startPageY
160 * The group defines a logical collection of DragDrop objects that are
161 * related. Instances only get events when interacting with other
162 * DragDrop object in the same group. This lets us define multiple
163 * groups using a single DragDrop subclass if we want.
165 * @type {string: string}
170 * Individual drag/drop instances can be locked. This will prevent
171 * onmousedown start drag.
182 lock: function() { this.locked = true; },
185 * Unlock this instace
188 unlock: function() { this.locked = false; },
191 * By default, all insances can be a drop target. This can be disabled by
192 * setting isTarget to false.
199 * The padding configured for this drag and drop object for calculating
200 * the drop zone intersection with this object.
207 * Cached reference to the linked element
214 * Internal typeof flag
215 * @property __ygDragDrop
221 * Set to true when horizontal contraints are applied
222 * @property constrainX
229 * Set to true when vertical contraints are applied
230 * @property constrainY
237 * The left constraint
245 * The right constraint
262 * The down constraint
270 * Maintain offsets when we resetconstraints. Set to true when you want
271 * the position of the element relative to its parent to stay the same
272 * when the page changes
274 * @property maintainOffset
277 maintainOffset: false,
280 * Array of pixel locations the element will snap to if we specified a
281 * horizontal graduation/interval. This array is generated automatically
282 * when you define a tick interval.
289 * Array of pixel locations the element will snap to if we specified a
290 * vertical graduation/interval. This array is generated automatically
291 * when you define a tick interval.
298 * By default the drag and drop instance will only respond to the primary
299 * button click (left button for a right-handed mouse). Set to true to
300 * allow drag and drop to start with any mouse click that is propogated
302 * @property primaryButtonOnly
305 primaryButtonOnly: true,
308 * The availabe property is false until the linked dom element is accessible.
309 * @property available
315 * By default, drags can only be initiated if the mousedown occurs in the
316 * region the linked element is. This is done in part to work around a
317 * bug in some browsers that mis-report the mousedown if the previous
318 * mouseup happened outside of the window. This property is set to true
319 * if outer handles are defined.
321 * @property hasOuterHandles
325 hasOuterHandles: false,
328 * Code that executes immediately before the startDrag event
329 * @method b4StartDrag
332 b4StartDrag: function(x, y) { },
335 * Abstract method called after a drag/drop object is clicked
336 * and the drag or mousedown time thresholds have beeen met.
338 * @param {int} X click location
339 * @param {int} Y click location
341 startDrag: function(x, y) { /* override this */ },
344 * Code that executes immediately before the onDrag event
348 b4Drag: function(e) { },
351 * Abstract method called during the onMouseMove event while dragging an
354 * @param {Event} e the mousemove event
356 onDrag: function(e) { /* override this */ },
359 * Abstract method called when this element fist begins hovering over
360 * another DragDrop obj
361 * @method onDragEnter
362 * @param {Event} e the mousemove event
363 * @param {String|DragDrop[]} id In POINT mode, the element
364 * id this is hovering over. In INTERSECT mode, an array of one or more
365 * dragdrop items being hovered over.
367 onDragEnter: function(e, id) { /* override this */ },
370 * Code that executes immediately before the onDragOver event
374 b4DragOver: function(e) { },
377 * Abstract method called when this element is hovering over another
380 * @param {Event} e the mousemove event
381 * @param {String|DragDrop[]} id In POINT mode, the element
382 * id this is hovering over. In INTERSECT mode, an array of dd items
383 * being hovered over.
385 onDragOver: function(e, id) { /* override this */ },
388 * Code that executes immediately before the onDragOut event
392 b4DragOut: function(e) { },
395 * Abstract method called when we are no longer hovering over an element
397 * @param {Event} e the mousemove event
398 * @param {String|DragDrop[]} id In POINT mode, the element
399 * id this was hovering over. In INTERSECT mode, an array of dd items
400 * that the mouse is no longer over.
402 onDragOut: function(e, id) { /* override this */ },
405 * Code that executes immediately before the onDragDrop event
409 b4DragDrop: function(e) { },
412 * Abstract method called when this item is dropped on another DragDrop
415 * @param {Event} e the mouseup event
416 * @param {String|DragDrop[]} id In POINT mode, the element
417 * id this was dropped on. In INTERSECT mode, an array of dd items this
420 onDragDrop: function(e, id) { /* override this */ },
423 * Abstract method called when this item is dropped on an area with no
425 * @method onInvalidDrop
426 * @param {Event} e the mouseup event
428 onInvalidDrop: function(e) { /* override this */ },
431 * Code that executes immediately before the endDrag event
435 b4EndDrag: function(e) { },
438 * Fired when we are done dragging the object
440 * @param {Event} e the mouseup event
442 endDrag: function(e) { /* override this */ },
445 * Code executed immediately before the onMouseDown event
446 * @method b4MouseDown
447 * @param {Event} e the mousedown event
450 b4MouseDown: function(e) { },
453 * Event handler that fires when a drag/drop obj gets a mousedown
454 * @method onMouseDown
455 * @param {Event} e the mousedown event
457 onMouseDown: function(e) { /* override this */ },
460 * Event handler that fires when a drag/drop obj gets a mouseup
462 * @param {Event} e the mouseup event
464 onMouseUp: function(e) { /* override this */ },
467 * Override the onAvailable method to do what is needed after the initial
468 * position was determined.
469 * @method onAvailable
471 onAvailable: function () {
475 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
478 defaultPadding : {left:0, right:0, top:0, bottom:0},
481 * Initializes the drag drop object's constraints to restrict movement to a certain element.
485 var dd = new Roo.dd.DDProxy("dragDiv1", "proxytest",
486 { dragElId: "existingProxyDiv" });
487 dd.startDrag = function(){
488 this.constrainTo("parent-id");
491 * Or you can initalize it using the {@link Roo.Element} object:
493 Roo.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
494 startDrag : function(){
495 this.constrainTo("parent-id");
499 * @param {String/HTMLElement/Element} constrainTo The element to constrain to.
500 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
501 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
502 * an object containing the sides to pad. For example: {right:10, bottom:10}
503 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
505 constrainTo : function(constrainTo, pad, inContent){
506 if(typeof pad == "number"){
507 pad = {left: pad, right:pad, top:pad, bottom:pad};
509 pad = pad || this.defaultPadding;
510 var b = Roo.get(this.getEl()).getBox();
511 var ce = Roo.get(constrainTo);
512 var s = ce.getScroll();
514 if(cd == document.body){
515 c = { x: s.left, y: s.top, width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
518 c = {x : xy[0]+s.left, y: xy[1]+s.top, width: cd.clientWidth, height: cd.clientHeight};
522 var topSpace = b.y - c.y;
523 var leftSpace = b.x - c.x;
525 this.resetConstraints();
526 this.setXConstraint(leftSpace - (pad.left||0), // left
527 c.width - leftSpace - b.width - (pad.right||0) //right
529 this.setYConstraint(topSpace - (pad.top||0), //top
530 c.height - topSpace - b.height - (pad.bottom||0) //bottom
535 * Returns a reference to the linked element
537 * @return {HTMLElement} the html element
541 this._domRef = Roo.getDom(this.id);
548 * Returns a reference to the actual element to drag. By default this is
549 * the same as the html element, but it can be assigned to another
550 * element. An example of this can be found in Roo.dd.DDProxy
552 * @return {HTMLElement} the html element
554 getDragEl: function() {
555 return Roo.getDom(this.dragElId);
559 * Sets up the DragDrop object. Must be called in the constructor of any
560 * Roo.dd.DragDrop subclass
562 * @param id the id of the linked element
563 * @param {String} sGroup the group of related items
564 * @param {object} config configuration attributes
566 init: function(id, sGroup, config) {
567 this.initTarget(id, sGroup, config);
569 Event.on(this.id, "mousedown", this.handleMouseDown, this);
571 Event.on(this.id, "touchstart", this.handleMouseDown, this);
572 // Event.on(this.id, "selectstart", Event.preventDefault);
576 * Initializes Targeting functionality only... the object does not
577 * get a mousedown handler.
579 * @param id the id of the linked element
580 * @param {String} sGroup the group of related items
581 * @param {object} config configuration attributes
583 initTarget: function(id, sGroup, config) {
585 // configuration attributes
586 this.config = config || {};
588 // create a local reference to the drag and drop manager
589 this.DDM = Roo.dd.DDM;
590 // initialize the groups array
593 // assume that we have an element reference instead of an id if the
594 // parameter is not a string
595 if (typeof id !== "string") {
602 // add to an interaction group
603 this.addToGroup((sGroup) ? sGroup : "default");
605 // We don't want to register this as the handle with the manager
606 // so we just set the id rather than calling the setter.
607 this.handleElId = id;
609 // the linked element is the element that gets dragged by default
610 this.setDragElId(id);
612 // by default, clicked anchors will not start drag operations.
613 this.invalidHandleTypes = { A: "A" };
614 this.invalidHandleIds = {};
615 this.invalidHandleClasses = [];
619 this.handleOnAvailable();
623 * Applies the configuration parameters that were passed into the constructor.
624 * This is supposed to happen at each level through the inheritance chain. So
625 * a DDProxy implentation will execute apply config on DDProxy, DD, and
626 * DragDrop in order to get all of the parameters that are available in
628 * @method applyConfig
630 applyConfig: function() {
632 // configurable properties:
633 // padding, isTarget, maintainOffset, primaryButtonOnly
634 this.padding = this.config.padding || [0, 0, 0, 0];
635 this.isTarget = (this.config.isTarget !== false);
636 this.maintainOffset = (this.config.maintainOffset);
637 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
642 * Executed when the linked element is available
643 * @method handleOnAvailable
646 handleOnAvailable: function() {
647 this.available = true;
648 this.resetConstraints();
653 * Configures the padding for the target zone in px. Effectively expands
654 * (or reduces) the virtual object size for targeting calculations.
655 * Supports css-style shorthand; if only one parameter is passed, all sides
656 * will have that padding, and if only two are passed, the top and bottom
657 * will have the first param, the left and right the second.
659 * @param {int} iTop Top pad
660 * @param {int} iRight Right pad
661 * @param {int} iBot Bot pad
662 * @param {int} iLeft Left pad
664 setPadding: function(iTop, iRight, iBot, iLeft) {
665 // this.padding = [iLeft, iRight, iTop, iBot];
666 if (!iRight && 0 !== iRight) {
667 this.padding = [iTop, iTop, iTop, iTop];
668 } else if (!iBot && 0 !== iBot) {
669 this.padding = [iTop, iRight, iTop, iRight];
671 this.padding = [iTop, iRight, iBot, iLeft];
676 * Stores the initial placement of the linked element.
677 * @method setInitialPosition
678 * @param {int} diffX the X offset, default 0
679 * @param {int} diffY the Y offset, default 0
681 setInitPosition: function(diffX, diffY) {
682 var el = this.getEl();
684 if (!this.DDM.verifyEl(el)) {
691 var p = Dom.getXY( el );
693 this.initPageX = p[0] - dx;
694 this.initPageY = p[1] - dy;
696 this.lastPageX = p[0];
697 this.lastPageY = p[1];
700 this.setStartPosition(p);
704 * Sets the start position of the element. This is set when the obj
705 * is initialized, the reset when a drag is started.
706 * @method setStartPosition
707 * @param pos current position (from previous lookup)
710 setStartPosition: function(pos) {
711 var p = pos || Dom.getXY( this.getEl() );
712 this.deltaSetXY = null;
714 this.startPageX = p[0];
715 this.startPageY = p[1];
719 * Add this instance to a group of related drag/drop objects. All
720 * instances belong to at least one group, and can belong to as many
723 * @param sGroup {string} the name of the group
725 addToGroup: function(sGroup) {
726 this.groups[sGroup] = true;
727 this.DDM.regDragDrop(this, sGroup);
731 * Remove's this instance from the supplied interaction group
732 * @method removeFromGroup
733 * @param {string} sGroup The group to drop
735 removeFromGroup: function(sGroup) {
736 if (this.groups[sGroup]) {
737 delete this.groups[sGroup];
740 this.DDM.removeDDFromGroup(this, sGroup);
744 * Allows you to specify that an element other than the linked element
745 * will be moved with the cursor during a drag
746 * @method setDragElId
747 * @param id {string} the id of the element that will be used to initiate the drag
749 setDragElId: function(id) {
754 * Allows you to specify a child of the linked element that should be
755 * used to initiate the drag operation. An example of this would be if
756 * you have a content div with text and links. Clicking anywhere in the
757 * content area would normally start the drag operation. Use this method
758 * to specify that an element inside of the content div is the element
759 * that starts the drag operation.
760 * @method setHandleElId
761 * @param id {string} the id of the element that will be used to
764 setHandleElId: function(id) {
765 if (typeof id !== "string") {
768 this.handleElId = id;
769 this.DDM.regHandle(this.id, id);
773 * Allows you to set an element outside of the linked element as a drag
775 * @method setOuterHandleElId
776 * @param id the id of the element that will be used to initiate the drag
778 setOuterHandleElId: function(id) {
779 if (typeof id !== "string") {
782 Event.on(id, "mousedown",
783 this.handleMouseDown, this);
784 this.setHandleElId(id);
786 this.hasOuterHandles = true;
790 * Remove all drag and drop hooks for this element
794 Event.un(this.id, "mousedown",
795 this.handleMouseDown);
796 Event.un(this.id, "touchstart",
797 this.handleMouseDown);
799 this.DDM._remove(this);
802 destroy : function(){
807 * Returns true if this instance is locked, or the drag drop mgr is locked
808 * (meaning that all drag/drop is disabled on the page.)
810 * @return {boolean} true if this obj or all drag/drop is locked, else
813 isLocked: function() {
814 return (this.DDM.isLocked() || this.locked);
818 * Fired when this object is clicked
819 * @method handleMouseDown
821 * @param {Roo.dd.DragDrop} oDD the clicked dd object (this dd obj)
824 handleMouseDown: function(e, oDD){
827 if (this.primaryButtonOnly && e.button != 0) {
831 if (this.isLocked()) {
835 this.DDM.refreshCache(this.groups);
837 var pt = new Roo.lib.Point(Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e));
838 if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
840 if (this.clickValidator(e)) {
842 // set the initial element position
843 this.setStartPosition();
849 this.DDM.handleMouseDown(e, this);
851 this.DDM.stopEvent(e);
859 clickValidator: function(e) {
860 var target = e.getTarget();
861 return ( this.isValidHandleChild(target) &&
862 (this.id == this.handleElId ||
863 this.DDM.handleWasClicked(target, this.id)) );
867 * Allows you to specify a tag name that should not start a drag operation
868 * when clicked. This is designed to facilitate embedding links within a
869 * drag handle that do something other than start the drag.
870 * @method addInvalidHandleType
871 * @param {string} tagName the type of element to exclude
873 addInvalidHandleType: function(tagName) {
874 var type = tagName.toUpperCase();
875 this.invalidHandleTypes[type] = type;
879 * Lets you to specify an element id for a child of a drag handle
880 * that should not initiate a drag
881 * @method addInvalidHandleId
882 * @param {string} id the element id of the element you wish to ignore
884 addInvalidHandleId: function(id) {
885 if (typeof id !== "string") {
888 this.invalidHandleIds[id] = id;
892 * Lets you specify a css class of elements that will not initiate a drag
893 * @method addInvalidHandleClass
894 * @param {string} cssClass the class of the elements you wish to ignore
896 addInvalidHandleClass: function(cssClass) {
897 this.invalidHandleClasses.push(cssClass);
901 * Unsets an excluded tag name set by addInvalidHandleType
902 * @method removeInvalidHandleType
903 * @param {string} tagName the type of element to unexclude
905 removeInvalidHandleType: function(tagName) {
906 var type = tagName.toUpperCase();
907 // this.invalidHandleTypes[type] = null;
908 delete this.invalidHandleTypes[type];
912 * Unsets an invalid handle id
913 * @method removeInvalidHandleId
914 * @param {string} id the id of the element to re-enable
916 removeInvalidHandleId: function(id) {
917 if (typeof id !== "string") {
920 delete this.invalidHandleIds[id];
924 * Unsets an invalid css class
925 * @method removeInvalidHandleClass
926 * @param {string} cssClass the class of the element(s) you wish to
929 removeInvalidHandleClass: function(cssClass) {
930 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
931 if (this.invalidHandleClasses[i] == cssClass) {
932 delete this.invalidHandleClasses[i];
938 * Checks the tag exclusion list to see if this click should be ignored
939 * @method isValidHandleChild
940 * @param {HTMLElement} node the HTMLElement to evaluate
941 * @return {boolean} true if this is a valid tag type, false if not
943 isValidHandleChild: function(node) {
946 // var n = (node.nodeName == "#text") ? node.parentNode : node;
949 nodeName = node.nodeName.toUpperCase();
951 nodeName = node.nodeName;
953 valid = valid && !this.invalidHandleTypes[nodeName];
954 valid = valid && !this.invalidHandleIds[node.id];
956 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
957 valid = !Dom.hasClass(node, this.invalidHandleClasses[i]);
966 * Create the array of horizontal tick marks if an interval was specified
967 * in setXConstraint().
971 setXTicks: function(iStartX, iTickSize) {
973 this.xTickSize = iTickSize;
977 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
979 this.xTicks[this.xTicks.length] = i;
984 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
986 this.xTicks[this.xTicks.length] = i;
991 this.xTicks.sort(this.DDM.numericSort) ;
995 * Create the array of vertical tick marks if an interval was specified in
1000 setYTicks: function(iStartY, iTickSize) {
1002 this.yTickSize = iTickSize;
1006 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
1008 this.yTicks[this.yTicks.length] = i;
1013 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
1015 this.yTicks[this.yTicks.length] = i;
1020 this.yTicks.sort(this.DDM.numericSort) ;
1024 * By default, the element can be dragged any place on the screen. Use
1025 * this method to limit the horizontal travel of the element. Pass in
1026 * 0,0 for the parameters if you want to lock the drag to the y axis.
1027 * @method setXConstraint
1028 * @param {int} iLeft the number of pixels the element can move to the left
1029 * @param {int} iRight the number of pixels the element can move to the
1031 * @param {int} iTickSize optional parameter for specifying that the
1033 * should move iTickSize pixels at a time.
1035 setXConstraint: function(iLeft, iRight, iTickSize) {
1036 this.leftConstraint = iLeft;
1037 this.rightConstraint = iRight;
1039 this.minX = this.initPageX - iLeft;
1040 this.maxX = this.initPageX + iRight;
1041 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
1043 this.constrainX = true;
1047 * Clears any constraints applied to this instance. Also clears ticks
1048 * since they can't exist independent of a constraint at this time.
1049 * @method clearConstraints
1051 clearConstraints: function() {
1052 this.constrainX = false;
1053 this.constrainY = false;
1058 * Clears any tick interval defined for this instance
1059 * @method clearTicks
1061 clearTicks: function() {
1069 * By default, the element can be dragged any place on the screen. Set
1070 * this to limit the vertical travel of the element. Pass in 0,0 for the
1071 * parameters if you want to lock the drag to the x axis.
1072 * @method setYConstraint
1073 * @param {int} iUp the number of pixels the element can move up
1074 * @param {int} iDown the number of pixels the element can move down
1075 * @param {int} iTickSize optional parameter for specifying that the
1076 * element should move iTickSize pixels at a time.
1078 setYConstraint: function(iUp, iDown, iTickSize) {
1079 this.topConstraint = iUp;
1080 this.bottomConstraint = iDown;
1082 this.minY = this.initPageY - iUp;
1083 this.maxY = this.initPageY + iDown;
1084 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
1086 this.constrainY = true;
1091 * resetConstraints must be called if you manually reposition a dd element.
1092 * @method resetConstraints
1093 * @param {boolean} maintainOffset
1095 resetConstraints: function() {
1098 // Maintain offsets if necessary
1099 if (this.initPageX || this.initPageX === 0) {
1100 // figure out how much this thing has moved
1101 var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
1102 var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
1104 this.setInitPosition(dx, dy);
1106 // This is the first time we have detected the element's position
1108 this.setInitPosition();
1111 if (this.constrainX) {
1112 this.setXConstraint( this.leftConstraint,
1113 this.rightConstraint,
1117 if (this.constrainY) {
1118 this.setYConstraint( this.topConstraint,
1119 this.bottomConstraint,
1125 * Normally the drag element is moved pixel by pixel, but we can specify
1126 * that it move a number of pixels at a time. This method resolves the
1127 * location when we have it set up like this.
1129 * @param {int} val where we want to place the object
1130 * @param {int[]} tickArray sorted array of valid points
1131 * @return {int} the closest tick
1134 getTick: function(val, tickArray) {
1137 // If tick interval is not defined, it is effectively 1 pixel,
1138 // so we return the value passed to us.
1140 } else if (tickArray[0] >= val) {
1141 // The value is lower than the first tick, so we return the first
1143 return tickArray[0];
1145 for (var i=0, len=tickArray.length; i<len; ++i) {
1147 if (tickArray[next] && tickArray[next] >= val) {
1148 var diff1 = val - tickArray[i];
1149 var diff2 = tickArray[next] - val;
1150 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
1154 // The value is larger than the last tick, so we return the last
1156 return tickArray[tickArray.length - 1];
1163 * @return {string} string representation of the dd obj
1165 toString: function() {
1166 return ("DragDrop " + this.id);
1174 * Ext JS Library 1.1.1
1175 * Copyright(c) 2006-2007, Ext JS, LLC.
1177 * Originally Released Under LGPL - original licence link has changed is not relivant.
1180 * <script type="text/javascript">
1185 * The drag and drop utility provides a framework for building drag and drop
1186 * applications. In addition to enabling drag and drop for specific elements,
1187 * the drag and drop elements are tracked by the manager class, and the
1188 * interactions between the various elements are tracked during the drag and
1189 * the implementing code is notified about these important moments.
1192 // Only load the library once. Rewriting the manager class would orphan
1193 // existing drag and drop instances.
1194 if (!Roo.dd.DragDropMgr) {
1197 * @class Roo.dd.DragDropMgr
1198 * DragDropMgr is a singleton that tracks the element interaction for
1199 * all DragDrop items in the window. Generally, you will not call
1200 * this class directly, but it does have helper methods that could
1201 * be useful in your DragDrop implementations.
1204 Roo.dd.DragDropMgr = function() {
1206 var Event = Roo.EventManager;
1211 * Two dimensional Array of registered DragDrop objects. The first
1212 * dimension is the DragDrop item group, the second the DragDrop
1215 * @type {string: string}
1222 * Array of element ids defined as drag handles. Used to determine
1223 * if the element that generated the mousedown event is actually the
1224 * handle and not the html element itself.
1225 * @property handleIds
1226 * @type {string: string}
1233 * the DragDrop object that is currently being dragged
1234 * @property dragCurrent
1242 * the DragDrop object(s) that are being hovered over
1243 * @property dragOvers
1251 * the X distance between the cursor and the object being dragged
1260 * the Y distance between the cursor and the object being dragged
1269 * Flag to determine if we should prevent the default behavior of the
1270 * events we define. By default this is true, but this can be set to
1271 * false if you need the default behavior (not recommended)
1272 * @property preventDefault
1276 preventDefault: true,
1279 * Flag to determine if we should stop the propagation of the events
1280 * we generate. This is true by default but you may want to set it to
1281 * false if the html element contains other features that require the
1283 * @property stopPropagation
1287 stopPropagation: true,
1290 * Internal flag that is set to true when drag and drop has been
1292 * @property initialized
1299 * All drag and drop can be disabled.
1307 * Called the first time an element is registered.
1313 this.initialized = true;
1317 * In point mode, drag and drop interaction is defined by the
1318 * location of the cursor during the drag/drop
1326 * In intersect mode, drag and drop interactio nis defined by the
1327 * overlap of two or more drag and drop objects.
1328 * @property INTERSECT
1335 * The current drag and drop mode. Default: POINT
1343 * Runs method on all drag and drop objects
1344 * @method _execOnAll
1348 _execOnAll: function(sMethod, args) {
1349 for (var i in this.ids) {
1350 for (var j in this.ids[i]) {
1351 var oDD = this.ids[i][j];
1352 if (! this.isTypeOfDD(oDD)) {
1355 oDD[sMethod].apply(oDD, args);
1361 * Drag and drop initialization. Sets up the global event handlers
1366 _onLoad: function() {
1371 Event.on(document, "mouseup", this.handleMouseUp, this, true);
1372 Event.on(document, "mousemove", this.handleMouseMove, this, true);
1374 Event.on(document, "touchend", this.handleMouseUp, this, true);
1375 Event.on(document, "touchmove", this.handleMouseMove, this, true);
1377 Event.on(window, "unload", this._onUnload, this, true);
1378 Event.on(window, "resize", this._onResize, this, true);
1379 // Event.on(window, "mouseout", this._test);
1384 * Reset constraints on all drag and drop objs
1389 _onResize: function(e) {
1390 this._execOnAll("resetConstraints", []);
1394 * Lock all drag and drop functionality
1398 lock: function() { this.locked = true; },
1401 * Unlock all drag and drop functionality
1405 unlock: function() { this.locked = false; },
1408 * Is drag and drop locked?
1410 * @return {boolean} True if drag and drop is locked, false otherwise.
1413 isLocked: function() { return this.locked; },
1416 * Location cache that is set for all drag drop objects when a drag is
1417 * initiated, cleared when the drag is finished.
1418 * @property locationCache
1425 * Set useCache to false if you want to force object the lookup of each
1426 * drag and drop linked element constantly during a drag.
1427 * @property useCache
1434 * The number of pixels that the mouse needs to move after the
1435 * mousedown before the drag is initiated. Default=3;
1436 * @property clickPixelThresh
1440 clickPixelThresh: 3,
1443 * The number of milliseconds after the mousedown event to initiate the
1444 * drag if we don't get a mouseup event. Default=1000
1445 * @property clickTimeThresh
1449 clickTimeThresh: 350,
1452 * Flag that indicates that either the drag pixel threshold or the
1453 * mousdown time threshold has been met
1454 * @property dragThreshMet
1459 dragThreshMet: false,
1462 * Timeout used for the click time threshold
1463 * @property clickTimeout
1471 * The X position of the mousedown event stored for later use when a
1472 * drag threshold is met.
1481 * The Y position of the mousedown event stored for later use when a
1482 * drag threshold is met.
1491 * Each DragDrop instance must be registered with the DragDropMgr.
1492 * This is executed in DragDrop.init()
1493 * @method regDragDrop
1494 * @param {DragDrop} oDD the DragDrop object to register
1495 * @param {String} sGroup the name of the group this element belongs to
1498 regDragDrop: function(oDD, sGroup) {
1499 if (!this.initialized) { this.init(); }
1501 if (!this.ids[sGroup]) {
1502 this.ids[sGroup] = {};
1504 this.ids[sGroup][oDD.id] = oDD;
1508 * Removes the supplied dd instance from the supplied group. Executed
1509 * by DragDrop.removeFromGroup, so don't call this function directly.
1510 * @method removeDDFromGroup
1514 removeDDFromGroup: function(oDD, sGroup) {
1515 if (!this.ids[sGroup]) {
1516 this.ids[sGroup] = {};
1519 var obj = this.ids[sGroup];
1520 if (obj && obj[oDD.id]) {
1526 * Unregisters a drag and drop item. This is executed in
1527 * DragDrop.unreg, use that method instead of calling this directly.
1532 _remove: function(oDD) {
1533 for (var g in oDD.groups) {
1534 if (g && this.ids[g][oDD.id]) {
1535 delete this.ids[g][oDD.id];
1538 delete this.handleIds[oDD.id];
1542 * Each DragDrop handle element must be registered. This is done
1543 * automatically when executing DragDrop.setHandleElId()
1545 * @param {String} sDDId the DragDrop id this element is a handle for
1546 * @param {String} sHandleId the id of the element that is the drag
1550 regHandle: function(sDDId, sHandleId) {
1551 if (!this.handleIds[sDDId]) {
1552 this.handleIds[sDDId] = {};
1554 this.handleIds[sDDId][sHandleId] = sHandleId;
1558 * Utility function to determine if a given element has been
1559 * registered as a drag drop item.
1560 * @method isDragDrop
1561 * @param {String} id the element id to check
1562 * @return {boolean} true if this element is a DragDrop item,
1566 isDragDrop: function(id) {
1567 return ( this.getDDById(id) ) ? true : false;
1571 * Returns the drag and drop instances that are in all groups the
1572 * passed in instance belongs to.
1573 * @method getRelated
1574 * @param {DragDrop} p_oDD the obj to get related data for
1575 * @param {boolean} bTargetsOnly if true, only return targetable objs
1576 * @return {DragDrop[]} the related instances
1579 getRelated: function(p_oDD, bTargetsOnly) {
1581 for (var i in p_oDD.groups) {
1582 for (j in this.ids[i]) {
1583 var dd = this.ids[i][j];
1584 if (! this.isTypeOfDD(dd)) {
1587 if (!bTargetsOnly || dd.isTarget) {
1588 oDDs[oDDs.length] = dd;
1597 * Returns true if the specified dd target is a legal target for
1598 * the specifice drag obj
1599 * @method isLegalTarget
1600 * @param {DragDrop} the drag obj
1601 * @param {DragDrop} the target
1602 * @return {boolean} true if the target is a legal target for the
1606 isLegalTarget: function (oDD, oTargetDD) {
1607 var targets = this.getRelated(oDD, true);
1608 for (var i=0, len=targets.length;i<len;++i) {
1609 if (targets[i].id == oTargetDD.id) {
1618 * My goal is to be able to transparently determine if an object is
1619 * typeof DragDrop, and the exact subclass of DragDrop. typeof
1620 * returns "object", oDD.constructor.toString() always returns
1621 * "DragDrop" and not the name of the subclass. So for now it just
1622 * evaluates a well-known variable in DragDrop.
1623 * @method isTypeOfDD
1624 * @param {Object} the object to evaluate
1625 * @return {boolean} true if typeof oDD = DragDrop
1628 isTypeOfDD: function (oDD) {
1629 return (oDD && oDD.__ygDragDrop);
1633 * Utility function to determine if a given element has been
1634 * registered as a drag drop handle for the given Drag Drop object.
1636 * @param {String} id the element id to check
1637 * @return {boolean} true if this element is a DragDrop handle, false
1641 isHandle: function(sDDId, sHandleId) {
1642 return ( this.handleIds[sDDId] &&
1643 this.handleIds[sDDId][sHandleId] );
1647 * Returns the DragDrop instance for a given id
1649 * @param {String} id the id of the DragDrop object
1650 * @return {DragDrop} the drag drop object, null if it is not found
1653 getDDById: function(id) {
1654 for (var i in this.ids) {
1655 if (this.ids[i][id]) {
1656 return this.ids[i][id];
1663 * Fired after a registered DragDrop object gets the mousedown event.
1664 * Sets up the events required to track the object being dragged
1665 * @method handleMouseDown
1666 * @param {Event} e the event
1667 * @param oDD the DragDrop object being dragged
1671 handleMouseDown: function(e, oDD) {
1673 Roo.QuickTips.disable();
1675 this.currentTarget = e.getTarget();
1677 this.dragCurrent = oDD;
1679 var el = oDD.getEl();
1681 // track start position
1682 this.startX = e.getPageX();
1683 this.startY = e.getPageY();
1685 this.deltaX = this.startX - el.offsetLeft;
1686 this.deltaY = this.startY - el.offsetTop;
1688 this.dragThreshMet = false;
1690 this.clickTimeout = setTimeout(
1692 var DDM = Roo.dd.DDM;
1693 DDM.startDrag(DDM.startX, DDM.startY);
1695 this.clickTimeThresh );
1699 * Fired when either the drag pixel threshol or the mousedown hold
1700 * time threshold has been met.
1702 * @param x {int} the X position of the original mousedown
1703 * @param y {int} the Y position of the original mousedown
1706 startDrag: function(x, y) {
1707 clearTimeout(this.clickTimeout);
1708 if (this.dragCurrent) {
1709 this.dragCurrent.b4StartDrag(x, y);
1710 this.dragCurrent.startDrag(x, y);
1712 this.dragThreshMet = true;
1716 * Internal function to handle the mouseup event. Will be invoked
1717 * from the context of the document.
1718 * @method handleMouseUp
1719 * @param {Event} e the event
1723 handleMouseUp: function(e) {
1726 Roo.QuickTips.enable();
1728 if (! this.dragCurrent) {
1732 clearTimeout(this.clickTimeout);
1734 if (this.dragThreshMet) {
1735 this.fireEvents(e, true);
1745 * Utility to stop event propagation and event default, if these
1746 * features are turned on.
1748 * @param {Event} e the event as returned by this.getEvent()
1751 stopEvent: function(e){
1752 if(this.stopPropagation) {
1753 e.stopPropagation();
1756 if (this.preventDefault) {
1762 * Internal function to clean up event handlers after the drag
1763 * operation is complete
1765 * @param {Event} e the event
1769 stopDrag: function(e) {
1770 // Fire the drag end event for the item that was dragged
1771 if (this.dragCurrent) {
1772 if (this.dragThreshMet) {
1773 this.dragCurrent.b4EndDrag(e);
1774 this.dragCurrent.endDrag(e);
1777 this.dragCurrent.onMouseUp(e);
1780 this.dragCurrent = null;
1781 this.dragOvers = {};
1785 * Internal function to handle the mousemove event. Will be invoked
1786 * from the context of the html element.
1788 * @TODO figure out what we can do about mouse events lost when the
1789 * user drags objects beyond the window boundary. Currently we can
1790 * detect this in internet explorer by verifying that the mouse is
1791 * down during the mousemove event. Firefox doesn't give us the
1792 * button state on the mousemove event.
1793 * @method handleMouseMove
1794 * @param {Event} e the event
1798 handleMouseMove: function(e) {
1799 if (! this.dragCurrent) {
1803 // var button = e.which || e.button;
1805 // check for IE mouseup outside of page boundary
1806 if (Roo.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
1808 return this.handleMouseUp(e);
1811 if (!this.dragThreshMet) {
1812 var diffX = Math.abs(this.startX - e.getPageX());
1813 var diffY = Math.abs(this.startY - e.getPageY());
1814 if (diffX > this.clickPixelThresh ||
1815 diffY > this.clickPixelThresh) {
1816 this.startDrag(this.startX, this.startY);
1820 if (this.dragThreshMet) {
1821 this.dragCurrent.b4Drag(e);
1822 this.dragCurrent.onDrag(e);
1823 if(!this.dragCurrent.moveOnly){
1824 this.fireEvents(e, false);
1834 * Iterates over all of the DragDrop elements to find ones we are
1835 * hovering over or dropping on
1836 * @method fireEvents
1837 * @param {Event} e the event
1838 * @param {boolean} isDrop is this a drop op or a mouseover op?
1842 fireEvents: function(e, isDrop) {
1843 var dc = this.dragCurrent;
1845 // If the user did the mouse up outside of the window, we could
1846 // get here even though we have ended the drag.
1847 if (!dc || dc.isLocked()) {
1851 var pt = e.getPoint();
1853 // cache the previous dragOver array
1861 // Check to see if the object(s) we were hovering over is no longer
1862 // being hovered over so we can fire the onDragOut event
1863 for (var i in this.dragOvers) {
1865 var ddo = this.dragOvers[i];
1867 if (! this.isTypeOfDD(ddo)) {
1871 if (! this.isOverTarget(pt, ddo, this.mode)) {
1872 outEvts.push( ddo );
1876 delete this.dragOvers[i];
1879 for (var sGroup in dc.groups) {
1881 if ("string" != typeof sGroup) {
1885 for (i in this.ids[sGroup]) {
1886 var oDD = this.ids[sGroup][i];
1887 if (! this.isTypeOfDD(oDD)) {
1891 if (oDD.isTarget && !oDD.isLocked() && oDD != dc) {
1892 if (this.isOverTarget(pt, oDD, this.mode)) {
1893 // look for drop interactions
1895 dropEvts.push( oDD );
1896 // look for drag enter and drag over interactions
1899 // initial drag over: dragEnter fires
1900 if (!oldOvers[oDD.id]) {
1901 enterEvts.push( oDD );
1902 // subsequent drag overs: dragOver fires
1904 overEvts.push( oDD );
1907 this.dragOvers[oDD.id] = oDD;
1915 if (outEvts.length) {
1916 dc.b4DragOut(e, outEvts);
1917 dc.onDragOut(e, outEvts);
1920 if (enterEvts.length) {
1921 dc.onDragEnter(e, enterEvts);
1924 if (overEvts.length) {
1925 dc.b4DragOver(e, overEvts);
1926 dc.onDragOver(e, overEvts);
1929 if (dropEvts.length) {
1930 dc.b4DragDrop(e, dropEvts);
1931 dc.onDragDrop(e, dropEvts);
1935 // fire dragout events
1937 for (i=0, len=outEvts.length; i<len; ++i) {
1938 dc.b4DragOut(e, outEvts[i].id);
1939 dc.onDragOut(e, outEvts[i].id);
1942 // fire enter events
1943 for (i=0,len=enterEvts.length; i<len; ++i) {
1944 // dc.b4DragEnter(e, oDD.id);
1945 dc.onDragEnter(e, enterEvts[i].id);
1949 for (i=0,len=overEvts.length; i<len; ++i) {
1950 dc.b4DragOver(e, overEvts[i].id);
1951 dc.onDragOver(e, overEvts[i].id);
1955 for (i=0, len=dropEvts.length; i<len; ++i) {
1956 dc.b4DragDrop(e, dropEvts[i].id);
1957 dc.onDragDrop(e, dropEvts[i].id);
1962 // notify about a drop that did not find a target
1963 if (isDrop && !dropEvts.length) {
1964 dc.onInvalidDrop(e);
1970 * Helper function for getting the best match from the list of drag
1971 * and drop objects returned by the drag and drop events when we are
1972 * in INTERSECT mode. It returns either the first object that the
1973 * cursor is over, or the object that has the greatest overlap with
1974 * the dragged element.
1975 * @method getBestMatch
1976 * @param {DragDrop[]} dds The array of drag and drop objects
1978 * @return {DragDrop} The best single match
1981 getBestMatch: function(dds) {
1983 // Return null if the input is not what we expect
1984 //if (!dds || !dds.length || dds.length == 0) {
1986 // If there is only one item, it wins
1987 //} else if (dds.length == 1) {
1989 var len = dds.length;
1994 // Loop through the targeted items
1995 for (var i=0; i<len; ++i) {
1997 // If the cursor is over the object, it wins. If the
1998 // cursor is over multiple matches, the first one we come
2000 if (dd.cursorIsOver) {
2003 // Otherwise the object with the most overlap wins
2006 winner.overlap.getArea() < dd.overlap.getArea()) {
2017 * Refreshes the cache of the top-left and bottom-right points of the
2018 * drag and drop objects in the specified group(s). This is in the
2019 * format that is stored in the drag and drop instance, so typical
2022 * Roo.dd.DragDropMgr.refreshCache(ddinstance.groups);
2026 * Roo.dd.DragDropMgr.refreshCache({group1:true, group2:true});
2028 * @TODO this really should be an indexed array. Alternatively this
2029 * method could accept both.
2030 * @method refreshCache
2031 * @param {Object} groups an associative array of groups to refresh
2034 refreshCache: function(groups) {
2035 for (var sGroup in groups) {
2036 if ("string" != typeof sGroup) {
2039 for (var i in this.ids[sGroup]) {
2040 var oDD = this.ids[sGroup][i];
2042 if (this.isTypeOfDD(oDD)) {
2043 // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
2044 var loc = this.getLocation(oDD);
2046 this.locationCache[oDD.id] = loc;
2048 delete this.locationCache[oDD.id];
2049 // this will unregister the drag and drop object if
2050 // the element is not in a usable state
2059 * This checks to make sure an element exists and is in the DOM. The
2060 * main purpose is to handle cases where innerHTML is used to remove
2061 * drag and drop objects from the DOM. IE provides an 'unspecified
2062 * error' when trying to access the offsetParent of such an element
2064 * @param {HTMLElement} el the element to check
2065 * @return {boolean} true if the element looks usable
2068 verifyEl: function(el) {
2073 parent = el.offsetParent;
2076 parent = el.offsetParent;
2087 * Returns a Region object containing the drag and drop element's position
2088 * and size, including the padding configured for it
2089 * @method getLocation
2090 * @param {DragDrop} oDD the drag and drop object to get the
2092 * @return {Roo.lib.Region} a Region object representing the total area
2093 * the element occupies, including any padding
2094 * the instance is configured for.
2097 getLocation: function(oDD) {
2098 if (! this.isTypeOfDD(oDD)) {
2102 var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
2105 pos= Roo.lib.Dom.getXY(el);
2113 x2 = x1 + el.offsetWidth;
2115 y2 = y1 + el.offsetHeight;
2117 t = y1 - oDD.padding[0];
2118 r = x2 + oDD.padding[1];
2119 b = y2 + oDD.padding[2];
2120 l = x1 - oDD.padding[3];
2122 return new Roo.lib.Region( t, r, b, l );
2126 * Checks the cursor location to see if it over the target
2127 * @method isOverTarget
2128 * @param {Roo.lib.Point} pt The point to evaluate
2129 * @param {DragDrop} oTarget the DragDrop object we are inspecting
2130 * @return {boolean} true if the mouse is over the target
2134 isOverTarget: function(pt, oTarget, intersect) {
2135 // use cache if available
2136 var loc = this.locationCache[oTarget.id];
2137 if (!loc || !this.useCache) {
2138 loc = this.getLocation(oTarget);
2139 this.locationCache[oTarget.id] = loc;
2147 oTarget.cursorIsOver = loc.contains( pt );
2149 // DragDrop is using this as a sanity check for the initial mousedown
2150 // in this case we are done. In POINT mode, if the drag obj has no
2151 // contraints, we are also done. Otherwise we need to evaluate the
2152 // location of the target as related to the actual location of the
2154 var dc = this.dragCurrent;
2155 if (!dc || !dc.getTargetCoord ||
2156 (!intersect && !dc.constrainX && !dc.constrainY)) {
2157 return oTarget.cursorIsOver;
2160 oTarget.overlap = null;
2162 // Get the current location of the drag element, this is the
2163 // location of the mouse event less the delta that represents
2164 // where the original mousedown happened on the element. We
2165 // need to consider constraints and ticks as well.
2166 var pos = dc.getTargetCoord(pt.x, pt.y);
2168 var el = dc.getDragEl();
2169 var curRegion = new Roo.lib.Region( pos.y,
2170 pos.x + el.offsetWidth,
2171 pos.y + el.offsetHeight,
2174 var overlap = curRegion.intersect(loc);
2177 oTarget.overlap = overlap;
2178 return (intersect) ? true : oTarget.cursorIsOver;
2185 * unload event handler
2190 _onUnload: function(e, me) {
2191 Roo.dd.DragDropMgr.unregAll();
2195 * Cleans up the drag and drop events and objects.
2200 unregAll: function() {
2202 if (this.dragCurrent) {
2204 this.dragCurrent = null;
2207 this._execOnAll("unreg", []);
2209 for (i in this.elementCache) {
2210 delete this.elementCache[i];
2213 this.elementCache = {};
2218 * A cache of DOM elements
2219 * @property elementCache
2226 * Get the wrapper for the DOM element specified
2227 * @method getElWrapper
2228 * @param {String} id the id of the element to get
2229 * @return {Roo.dd.DDM.ElementWrapper} the wrapped element
2231 * @deprecated This wrapper isn't that useful
2234 getElWrapper: function(id) {
2235 var oWrapper = this.elementCache[id];
2236 if (!oWrapper || !oWrapper.el) {
2237 oWrapper = this.elementCache[id] =
2238 new this.ElementWrapper(Roo.getDom(id));
2244 * Returns the actual DOM element
2245 * @method getElement
2246 * @param {String} id the id of the elment to get
2247 * @return {Object} The element
2248 * @deprecated use Roo.getDom instead
2251 getElement: function(id) {
2252 return Roo.getDom(id);
2256 * Returns the style property for the DOM element (i.e.,
2257 * document.getElById(id).style)
2259 * @param {String} id the id of the elment to get
2260 * @return {Object} The style property of the element
2261 * @deprecated use Roo.getDom instead
2264 getCss: function(id) {
2265 var el = Roo.getDom(id);
2266 return (el) ? el.style : null;
2270 * Inner class for cached elements
2271 * @class DragDropMgr.ElementWrapper
2276 ElementWrapper: function(el) {
2281 this.el = el || null;
2286 this.id = this.el && el.id;
2288 * A reference to the style property
2291 this.css = this.el && el.style;
2295 * Returns the X position of an html element
2297 * @param el the element for which to get the position
2298 * @return {int} the X coordinate
2300 * @deprecated use Roo.lib.Dom.getX instead
2303 getPosX: function(el) {
2304 return Roo.lib.Dom.getX(el);
2308 * Returns the Y position of an html element
2310 * @param el the element for which to get the position
2311 * @return {int} the Y coordinate
2312 * @deprecated use Roo.lib.Dom.getY instead
2315 getPosY: function(el) {
2316 return Roo.lib.Dom.getY(el);
2320 * Swap two nodes. In IE, we use the native method, for others we
2321 * emulate the IE behavior
2323 * @param n1 the first node to swap
2324 * @param n2 the other node to swap
2327 swapNode: function(n1, n2) {
2331 var p = n2.parentNode;
2332 var s = n2.nextSibling;
2335 p.insertBefore(n1, n2);
2336 } else if (n2 == n1.nextSibling) {
2337 p.insertBefore(n2, n1);
2339 n1.parentNode.replaceChild(n2, n1);
2340 p.insertBefore(n1, s);
2346 * Returns the current scroll position
2351 getScroll: function () {
2352 var t, l, dde=document.documentElement, db=document.body;
2353 if (dde && (dde.scrollTop || dde.scrollLeft)) {
2362 return { top: t, left: l };
2366 * Returns the specified element style property
2368 * @param {HTMLElement} el the element
2369 * @param {string} styleProp the style property
2370 * @return {string} The value of the style property
2371 * @deprecated use Roo.lib.Dom.getStyle
2374 getStyle: function(el, styleProp) {
2375 return Roo.fly(el).getStyle(styleProp);
2379 * Gets the scrollTop
2380 * @method getScrollTop
2381 * @return {int} the document's scrollTop
2384 getScrollTop: function () { return this.getScroll().top; },
2387 * Gets the scrollLeft
2388 * @method getScrollLeft
2389 * @return {int} the document's scrollTop
2392 getScrollLeft: function () { return this.getScroll().left; },
2395 * Sets the x/y position of an element to the location of the
2398 * @param {HTMLElement} moveEl The element to move
2399 * @param {HTMLElement} targetEl The position reference element
2402 moveToEl: function (moveEl, targetEl) {
2403 var aCoord = Roo.lib.Dom.getXY(targetEl);
2404 Roo.lib.Dom.setXY(moveEl, aCoord);
2408 * Numeric array sort function
2409 * @method numericSort
2412 numericSort: function(a, b) { return (a - b); },
2416 * @property _timeoutCount
2423 * Trying to make the load order less important. Without this we get
2424 * an error if this file is loaded before the Event Utility.
2425 * @method _addListeners
2429 _addListeners: function() {
2430 var DDM = Roo.dd.DDM;
2431 if ( Roo.lib.Event && document ) {
2434 if (DDM._timeoutCount > 2000) {
2436 setTimeout(DDM._addListeners, 10);
2437 if (document && document.body) {
2438 DDM._timeoutCount += 1;
2445 * Recursively searches the immediate parent and all child nodes for
2446 * the handle element in order to determine wheter or not it was
2448 * @method handleWasClicked
2449 * @param node the html element to inspect
2452 handleWasClicked: function(node, id) {
2453 if (this.isHandle(id, node.id)) {
2456 // check to see if this is a text node child of the one we want
2457 var p = node.parentNode;
2460 if (this.isHandle(id, p.id)) {
2475 // shorter alias, save a few bytes
2476 Roo.dd.DDM = Roo.dd.DragDropMgr;
2477 Roo.dd.DDM._addListeners();
2481 * Ext JS Library 1.1.1
2482 * Copyright(c) 2006-2007, Ext JS, LLC.
2484 * Originally Released Under LGPL - original licence link has changed is not relivant.
2487 * <script type="text/javascript">
2492 * A DragDrop implementation where the linked element follows the
2493 * mouse cursor during a drag.
2494 * @extends Roo.dd.DragDrop
2496 * @param {String} id the id of the linked element
2497 * @param {String} sGroup the group of related DragDrop items
2498 * @param {object} config an object containing configurable attributes
2499 * Valid properties for DD:
2502 Roo.dd.DD = function(id, sGroup, config) {
2504 this.init(id, sGroup, config);
2508 Roo.extend(Roo.dd.DD, Roo.dd.DragDrop, {
2511 * When set to true, the utility automatically tries to scroll the browser
2512 * window wehn a drag and drop element is dragged near the viewport boundary.
2520 * Sets the pointer offset to the distance between the linked element's top
2521 * left corner and the location the element was clicked
2522 * @method autoOffset
2523 * @param {int} iPageX the X coordinate of the click
2524 * @param {int} iPageY the Y coordinate of the click
2526 autoOffset: function(iPageX, iPageY) {
2527 var x = iPageX - this.startPageX;
2528 var y = iPageY - this.startPageY;
2529 this.setDelta(x, y);
2533 * Sets the pointer offset. You can call this directly to force the
2534 * offset to be in a particular location (e.g., pass in 0,0 to set it
2535 * to the center of the object)
2537 * @param {int} iDeltaX the distance from the left
2538 * @param {int} iDeltaY the distance from the top
2540 setDelta: function(iDeltaX, iDeltaY) {
2541 this.deltaX = iDeltaX;
2542 this.deltaY = iDeltaY;
2546 * Sets the drag element to the location of the mousedown or click event,
2547 * maintaining the cursor location relative to the location on the element
2548 * that was clicked. Override this if you want to place the element in a
2549 * location other than where the cursor is.
2550 * @method setDragElPos
2551 * @param {int} iPageX the X coordinate of the mousedown or drag event
2552 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2554 setDragElPos: function(iPageX, iPageY) {
2555 // the first time we do this, we are going to check to make sure
2556 // the element has css positioning
2558 var el = this.getDragEl();
2559 this.alignElWithMouse(el, iPageX, iPageY);
2563 * Sets the element to the location of the mousedown or click event,
2564 * maintaining the cursor location relative to the location on the element
2565 * that was clicked. Override this if you want to place the element in a
2566 * location other than where the cursor is.
2567 * @method alignElWithMouse
2568 * @param {HTMLElement} el the element to move
2569 * @param {int} iPageX the X coordinate of the mousedown or drag event
2570 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2572 alignElWithMouse: function(el, iPageX, iPageY) {
2573 var oCoord = this.getTargetCoord(iPageX, iPageY);
2574 var fly = el.dom ? el : Roo.fly(el);
2575 if (!this.deltaSetXY) {
2576 var aCoord = [oCoord.x, oCoord.y];
2578 var newLeft = fly.getLeft(true);
2579 var newTop = fly.getTop(true);
2580 this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
2582 fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
2585 this.cachePosition(oCoord.x, oCoord.y);
2586 this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
2591 * Saves the most recent position so that we can reset the constraints and
2592 * tick marks on-demand. We need to know this so that we can calculate the
2593 * number of pixels the element is offset from its original position.
2594 * @method cachePosition
2595 * @param iPageX the current x position (optional, this just makes it so we
2596 * don't have to look it up again)
2597 * @param iPageY the current y position (optional, this just makes it so we
2598 * don't have to look it up again)
2600 cachePosition: function(iPageX, iPageY) {
2602 this.lastPageX = iPageX;
2603 this.lastPageY = iPageY;
2605 var aCoord = Roo.lib.Dom.getXY(this.getEl());
2606 this.lastPageX = aCoord[0];
2607 this.lastPageY = aCoord[1];
2612 * Auto-scroll the window if the dragged object has been moved beyond the
2613 * visible window boundary.
2614 * @method autoScroll
2615 * @param {int} x the drag element's x position
2616 * @param {int} y the drag element's y position
2617 * @param {int} h the height of the drag element
2618 * @param {int} w the width of the drag element
2621 autoScroll: function(x, y, h, w) {
2624 // The client height
2625 var clientH = Roo.lib.Dom.getViewWidth();
2628 var clientW = Roo.lib.Dom.getViewHeight();
2630 // The amt scrolled down
2631 var st = this.DDM.getScrollTop();
2633 // The amt scrolled right
2634 var sl = this.DDM.getScrollLeft();
2636 // Location of the bottom of the element
2639 // Location of the right of the element
2642 // The distance from the cursor to the bottom of the visible area,
2643 // adjusted so that we don't scroll if the cursor is beyond the
2644 // element drag constraints
2645 var toBot = (clientH + st - y - this.deltaY);
2647 // The distance from the cursor to the right of the visible area
2648 var toRight = (clientW + sl - x - this.deltaX);
2651 // How close to the edge the cursor must be before we scroll
2652 // var thresh = (document.all) ? 100 : 40;
2655 // How many pixels to scroll per autoscroll op. This helps to reduce
2656 // clunky scrolling. IE is more sensitive about this ... it needs this
2657 // value to be higher.
2658 var scrAmt = (document.all) ? 80 : 30;
2660 // Scroll down if we are near the bottom of the visible page and the
2661 // obj extends below the crease
2662 if ( bot > clientH && toBot < thresh ) {
2663 window.scrollTo(sl, st + scrAmt);
2666 // Scroll up if the window is scrolled down and the top of the object
2667 // goes above the top border
2668 if ( y < st && st > 0 && y - st < thresh ) {
2669 window.scrollTo(sl, st - scrAmt);
2672 // Scroll right if the obj is beyond the right border and the cursor is
2674 if ( right > clientW && toRight < thresh ) {
2675 window.scrollTo(sl + scrAmt, st);
2678 // Scroll left if the window has been scrolled to the right and the obj
2679 // extends past the left border
2680 if ( x < sl && sl > 0 && x - sl < thresh ) {
2681 window.scrollTo(sl - scrAmt, st);
2687 * Finds the location the element should be placed if we want to move
2688 * it to where the mouse location less the click offset would place us.
2689 * @method getTargetCoord
2690 * @param {int} iPageX the X coordinate of the click
2691 * @param {int} iPageY the Y coordinate of the click
2692 * @return an object that contains the coordinates (Object.x and Object.y)
2695 getTargetCoord: function(iPageX, iPageY) {
2698 var x = iPageX - this.deltaX;
2699 var y = iPageY - this.deltaY;
2701 if (this.constrainX) {
2702 if (x < this.minX) { x = this.minX; }
2703 if (x > this.maxX) { x = this.maxX; }
2706 if (this.constrainY) {
2707 if (y < this.minY) { y = this.minY; }
2708 if (y > this.maxY) { y = this.maxY; }
2711 x = this.getTick(x, this.xTicks);
2712 y = this.getTick(y, this.yTicks);
2719 * Sets up config options specific to this class. Overrides
2720 * Roo.dd.DragDrop, but all versions of this method through the
2721 * inheritance chain are called
2723 applyConfig: function() {
2724 Roo.dd.DD.superclass.applyConfig.call(this);
2725 this.scroll = (this.config.scroll !== false);
2729 * Event that fires prior to the onMouseDown event. Overrides
2732 b4MouseDown: function(e) {
2733 // this.resetConstraints();
2734 this.autoOffset(e.getPageX(),
2739 * Event that fires prior to the onDrag event. Overrides
2742 b4Drag: function(e) {
2743 this.setDragElPos(e.getPageX(),
2747 toString: function() {
2748 return ("DD " + this.id);
2751 //////////////////////////////////////////////////////////////////////////
2752 // Debugging ygDragDrop events that can be overridden
2753 //////////////////////////////////////////////////////////////////////////
2755 startDrag: function(x, y) {
2758 onDrag: function(e) {
2761 onDragEnter: function(e, id) {
2764 onDragOver: function(e, id) {
2767 onDragOut: function(e, id) {
2770 onDragDrop: function(e, id) {
2773 endDrag: function(e) {
2780 * Ext JS Library 1.1.1
2781 * Copyright(c) 2006-2007, Ext JS, LLC.
2783 * Originally Released Under LGPL - original licence link has changed is not relivant.
2786 * <script type="text/javascript">
2790 * @class Roo.dd.DDProxy
2791 * A DragDrop implementation that inserts an empty, bordered div into
2792 * the document that follows the cursor during drag operations. At the time of
2793 * the click, the frame div is resized to the dimensions of the linked html
2794 * element, and moved to the exact location of the linked element.
2796 * References to the "frame" element refer to the single proxy element that
2797 * was created to be dragged in place of all DDProxy elements on the
2800 * @extends Roo.dd.DD
2802 * @param {String} id the id of the linked html element
2803 * @param {String} sGroup the group of related DragDrop objects
2804 * @param {object} config an object containing configurable attributes
2805 * Valid properties for DDProxy in addition to those in DragDrop:
2806 * resizeFrame, centerFrame, dragElId
2808 Roo.dd.DDProxy = function(id, sGroup, config) {
2810 this.init(id, sGroup, config);
2816 * The default drag frame div id
2817 * @property Roo.dd.DDProxy.dragElId
2821 Roo.dd.DDProxy.dragElId = "ygddfdiv";
2823 Roo.extend(Roo.dd.DDProxy, Roo.dd.DD, {
2826 * By default we resize the drag frame to be the same size as the element
2827 * we want to drag (this is to get the frame effect). We can turn it off
2828 * if we want a different behavior.
2829 * @property resizeFrame
2835 * By default the frame is positioned exactly where the drag element is, so
2836 * we use the cursor offset provided by Roo.dd.DD. Another option that works only if
2837 * you do not have constraints on the obj is to have the drag frame centered
2838 * around the cursor. Set centerFrame to true for this effect.
2839 * @property centerFrame
2845 * Creates the proxy element if it does not yet exist
2846 * @method createFrame
2848 createFrame: function() {
2850 var body = document.body;
2852 if (!body || !body.firstChild) {
2853 setTimeout( function() { self.createFrame(); }, 50 );
2857 var div = this.getDragEl();
2860 div = document.createElement("div");
2861 div.id = this.dragElId;
2864 s.position = "absolute";
2865 s.visibility = "hidden";
2867 s.border = "2px solid #aaa";
2870 // appendChild can blow up IE if invoked prior to the window load event
2871 // while rendering a table. It is possible there are other scenarios
2872 // that would cause this to happen as well.
2873 body.insertBefore(div, body.firstChild);
2878 * Initialization for the drag frame element. Must be called in the
2879 * constructor of all subclasses
2882 initFrame: function() {
2886 applyConfig: function() {
2887 Roo.dd.DDProxy.superclass.applyConfig.call(this);
2889 this.resizeFrame = (this.config.resizeFrame !== false);
2890 this.centerFrame = (this.config.centerFrame);
2891 this.setDragElId(this.config.dragElId || Roo.dd.DDProxy.dragElId);
2895 * Resizes the drag frame to the dimensions of the clicked object, positions
2896 * it over the object, and finally displays it
2898 * @param {int} iPageX X click position
2899 * @param {int} iPageY Y click position
2902 showFrame: function(iPageX, iPageY) {
2903 var el = this.getEl();
2904 var dragEl = this.getDragEl();
2905 var s = dragEl.style;
2907 this._resizeProxy();
2909 if (this.centerFrame) {
2910 this.setDelta( Math.round(parseInt(s.width, 10)/2),
2911 Math.round(parseInt(s.height, 10)/2) );
2914 this.setDragElPos(iPageX, iPageY);
2916 Roo.fly(dragEl).show();
2920 * The proxy is automatically resized to the dimensions of the linked
2921 * element when a drag is initiated, unless resizeFrame is set to false
2922 * @method _resizeProxy
2925 _resizeProxy: function() {
2926 if (this.resizeFrame) {
2927 var el = this.getEl();
2928 Roo.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
2932 // overrides Roo.dd.DragDrop
2933 b4MouseDown: function(e) {
2934 var x = e.getPageX();
2935 var y = e.getPageY();
2936 this.autoOffset(x, y);
2937 this.setDragElPos(x, y);
2940 // overrides Roo.dd.DragDrop
2941 b4StartDrag: function(x, y) {
2942 // show the drag frame
2943 this.showFrame(x, y);
2946 // overrides Roo.dd.DragDrop
2947 b4EndDrag: function(e) {
2948 Roo.fly(this.getDragEl()).hide();
2951 // overrides Roo.dd.DragDrop
2952 // By default we try to move the element to the last location of the frame.
2953 // This is so that the default behavior mirrors that of Roo.dd.DD.
2954 endDrag: function(e) {
2956 var lel = this.getEl();
2957 var del = this.getDragEl();
2959 // Show the drag frame briefly so we can get its position
2960 del.style.visibility = "";
2963 // Hide the linked element before the move to get around a Safari
2965 lel.style.visibility = "hidden";
2966 Roo.dd.DDM.moveToEl(lel, del);
2967 del.style.visibility = "hidden";
2968 lel.style.visibility = "";
2973 beforeMove : function(){
2977 afterDrag : function(){
2981 toString: function() {
2982 return ("DDProxy " + this.id);
2988 * Ext JS Library 1.1.1
2989 * Copyright(c) 2006-2007, Ext JS, LLC.
2991 * Originally Released Under LGPL - original licence link has changed is not relivant.
2994 * <script type="text/javascript">
2998 * @class Roo.dd.DDTarget
2999 * A DragDrop implementation that does not move, but can be a drop
3000 * target. You would get the same result by simply omitting implementation
3001 * for the event callbacks, but this way we reduce the processing cost of the
3002 * event listener and the callbacks.
3003 * @extends Roo.dd.DragDrop
3005 * @param {String} id the id of the element that is a drop target
3006 * @param {String} sGroup the group of related DragDrop objects
3007 * @param {object} config an object containing configurable attributes
3008 * Valid properties for DDTarget in addition to those in
3012 Roo.dd.DDTarget = function(id, sGroup, config) {
3014 this.initTarget(id, sGroup, config);
3016 if (config.listeners || config.events) {
3017 Roo.dd.DragDrop.superclass.constructor.call(this, {
3018 listeners : config.listeners || {},
3019 events : config.events || {}
3024 // Roo.dd.DDTarget.prototype = new Roo.dd.DragDrop();
3025 Roo.extend(Roo.dd.DDTarget, Roo.dd.DragDrop, {
3026 toString: function() {
3027 return ("DDTarget " + this.id);
3032 * Ext JS Library 1.1.1
3033 * Copyright(c) 2006-2007, Ext JS, LLC.
3035 * Originally Released Under LGPL - original licence link has changed is not relivant.
3038 * <script type="text/javascript">
3043 * @class Roo.dd.ScrollManager
3044 * Provides automatic scrolling of overflow regions in the page during drag operations.<br><br>
3045 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
3048 Roo.dd.ScrollManager = function(){
3049 var ddm = Roo.dd.DragDropMgr;
3056 var onStop = function(e){
3061 var triggerRefresh = function(){
3062 if(ddm.dragCurrent){
3063 ddm.refreshCache(ddm.dragCurrent.groups);
3067 var doScroll = function(){
3068 if(ddm.dragCurrent){
3069 var dds = Roo.dd.ScrollManager;
3071 if(proc.el.scroll(proc.dir, dds.increment)){
3075 proc.el.scroll(proc.dir, dds.increment, true, dds.animDuration, triggerRefresh);
3080 var clearProc = function(){
3082 clearInterval(proc.id);
3089 var startProc = function(el, dir){
3090 Roo.log('scroll startproc');
3094 proc.id = setInterval(doScroll, Roo.dd.ScrollManager.frequency);
3097 var onFire = function(e, isDrop){
3099 if(isDrop || !ddm.dragCurrent){ return; }
3100 var dds = Roo.dd.ScrollManager;
3101 if(!dragEl || dragEl != ddm.dragCurrent){
3102 dragEl = ddm.dragCurrent;
3103 // refresh regions on drag start
3107 var xy = Roo.lib.Event.getXY(e);
3108 var pt = new Roo.lib.Point(xy[0], xy[1]);
3110 var el = els[id], r = el._region;
3111 if(r && r.contains(pt) && el.isScrollable()){
3112 if(r.bottom - pt.y <= dds.thresh){
3114 startProc(el, "down");
3117 }else if(r.right - pt.x <= dds.thresh){
3119 startProc(el, "left");
3122 }else if(pt.y - r.top <= dds.thresh){
3124 startProc(el, "up");
3127 }else if(pt.x - r.left <= dds.thresh){
3129 startProc(el, "right");
3138 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
3139 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
3143 * Registers new overflow element(s) to auto scroll
3144 * @param {String/HTMLElement/Element/Array} el The id of or the element to be scrolled or an array of either
3146 register : function(el){
3147 if(el instanceof Array){
3148 for(var i = 0, len = el.length; i < len; i++) {
3149 this.register(el[i]);
3155 Roo.dd.ScrollManager.els = els;
3159 * Unregisters overflow element(s) so they are no longer scrolled
3160 * @param {String/HTMLElement/Element/Array} el The id of or the element to be removed or an array of either
3162 unregister : function(el){
3163 if(el instanceof Array){
3164 for(var i = 0, len = el.length; i < len; i++) {
3165 this.unregister(el[i]);
3174 * The number of pixels from the edge of a container the pointer needs to be to
3175 * trigger scrolling (defaults to 25)
3181 * The number of pixels to scroll in each scroll increment (defaults to 50)
3187 * The frequency of scrolls in milliseconds (defaults to 500)
3193 * True to animate the scroll (defaults to true)
3199 * The animation duration in seconds -
3200 * MUST BE less than Roo.dd.ScrollManager.frequency! (defaults to .4)
3206 * Manually trigger a cache refresh.
3208 refreshCache : function(){
3210 if(typeof els[id] == 'object'){ // for people extending the object prototype
3211 els[id]._region = els[id].getRegion();
3218 * Ext JS Library 1.1.1
3219 * Copyright(c) 2006-2007, Ext JS, LLC.
3221 * Originally Released Under LGPL - original licence link has changed is not relivant.
3224 * <script type="text/javascript">
3229 * @class Roo.dd.Registry
3230 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
3231 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
3234 Roo.dd.Registry = function(){
3239 var getId = function(el, autogen){
3240 if(typeof el == "string"){
3244 if(!id && autogen !== false){
3245 id = "roodd-" + (++autoIdSeed);
3253 * Register a drag drop element
3254 * @param {String|HTMLElement} element The id or DOM node to register
3255 * @param {Object} data (optional) A custom data object that will be passed between the elements that are involved
3256 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
3257 * knows how to interpret, plus there are some specific properties known to the Registry that should be
3258 * populated in the data object (if applicable):
3260 Value Description<br />
3261 --------- ------------------------------------------<br />
3262 handles Array of DOM nodes that trigger dragging<br />
3263 for the element being registered<br />
3264 isHandle True if the element passed in triggers<br />
3265 dragging itself, else false
3268 register : function(el, data){
3270 if(typeof el == "string"){
3271 el = document.getElementById(el);
3274 elements[getId(el)] = data;
3275 if(data.isHandle !== false){
3276 handles[data.ddel.id] = data;
3279 var hs = data.handles;
3280 for(var i = 0, len = hs.length; i < len; i++){
3281 handles[getId(hs[i])] = data;
3287 * Unregister a drag drop element
3288 * @param {String|HTMLElement} element The id or DOM node to unregister
3290 unregister : function(el){
3291 var id = getId(el, false);
3292 var data = elements[id];
3294 delete elements[id];
3296 var hs = data.handles;
3297 for(var i = 0, len = hs.length; i < len; i++){
3298 delete handles[getId(hs[i], false)];
3305 * Returns the handle registered for a DOM Node by id
3306 * @param {String|HTMLElement} id The DOM node or id to look up
3307 * @return {Object} handle The custom handle data
3309 getHandle : function(id){
3310 if(typeof id != "string"){ // must be element?
3317 * Returns the handle that is registered for the DOM node that is the target of the event
3318 * @param {Event} e The event
3319 * @return {Object} handle The custom handle data
3321 getHandleFromEvent : function(e){
3322 var t = Roo.lib.Event.getTarget(e);
3323 return t ? handles[t.id] : null;
3327 * Returns a custom data object that is registered for a DOM node by id
3328 * @param {String|HTMLElement} id The DOM node or id to look up
3329 * @return {Object} data The custom data
3331 getTarget : function(id){
3332 if(typeof id != "string"){ // must be element?
3335 return elements[id];
3339 * Returns a custom data object that is registered for the DOM node that is the target of the event
3340 * @param {Event} e The event
3341 * @return {Object} data The custom data
3343 getTargetFromEvent : function(e){
3344 var t = Roo.lib.Event.getTarget(e);
3345 return t ? elements[t.id] || handles[t.id] : null;
3350 * Ext JS Library 1.1.1
3351 * Copyright(c) 2006-2007, Ext JS, LLC.
3353 * Originally Released Under LGPL - original licence link has changed is not relivant.
3356 * <script type="text/javascript">
3361 * @class Roo.dd.StatusProxy
3362 * A specialized drag proxy that supports a drop status icon, {@link Roo.Layer} styles and auto-repair. This is the
3363 * default drag proxy used by all Roo.dd components.
3365 * @param {Object} config
3367 Roo.dd.StatusProxy = function(config){
3368 Roo.apply(this, config);
3369 this.id = this.id || Roo.id();
3370 this.el = new Roo.Layer({
3372 id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
3373 {tag: "div", cls: "x-dd-drop-icon"},
3374 {tag: "div", cls: "x-dd-drag-ghost"}
3377 shadow: !config || config.shadow !== false
3379 this.ghost = Roo.get(this.el.dom.childNodes[1]);
3380 this.dropStatus = this.dropNotAllowed;
3383 Roo.dd.StatusProxy.prototype = {
3385 * @cfg {String} dropAllowed
3386 * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
3388 dropAllowed : "x-dd-drop-ok",
3390 * @cfg {String} dropNotAllowed
3391 * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
3393 dropNotAllowed : "x-dd-drop-nodrop",
3396 * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
3397 * over the current target element.
3398 * @param {String} cssClass The css class for the new drop status indicator image
3400 setStatus : function(cssClass){
3401 cssClass = cssClass || this.dropNotAllowed;
3402 if(this.dropStatus != cssClass){
3403 this.el.replaceClass(this.dropStatus, cssClass);
3404 this.dropStatus = cssClass;
3409 * Resets the status indicator to the default dropNotAllowed value
3410 * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
3412 reset : function(clearGhost){
3413 this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
3414 this.dropStatus = this.dropNotAllowed;
3416 this.ghost.update("");
3421 * Updates the contents of the ghost element
3422 * @param {String} html The html that will replace the current innerHTML of the ghost element
3424 update : function(html){
3425 if(typeof html == "string"){
3426 this.ghost.update(html);
3428 this.ghost.update("");
3429 html.style.margin = "0";
3430 this.ghost.dom.appendChild(html);
3432 // ensure float = none set?? cant remember why though.
3433 var el = this.ghost.dom.firstChild;
3435 Roo.fly(el).setStyle('float', 'none');
3440 * Returns the underlying proxy {@link Roo.Layer}
3441 * @return {Roo.Layer} el
3448 * Returns the ghost element
3449 * @return {Roo.Element} el
3451 getGhost : function(){
3457 * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
3459 hide : function(clear){
3467 * Stops the repair animation if it's currently running
3470 if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
3476 * Displays this proxy
3483 * Force the Layer to sync its shadow and shim positions to the element
3490 * Causes the proxy to return to its position of origin via an animation. Should be called after an
3491 * invalid drop operation by the item being dragged.
3492 * @param {Array} xy The XY position of the element ([x, y])
3493 * @param {Function} callback The function to call after the repair is complete
3494 * @param {Object} scope The scope in which to execute the callback
3496 repair : function(xy, callback, scope){
3497 this.callback = callback;
3499 if(xy && this.animRepair !== false){
3500 this.el.addClass("x-dd-drag-repair");
3501 this.el.hideUnders(true);
3502 this.anim = this.el.shift({
3503 duration: this.repairDuration || .5,
3507 callback: this.afterRepair,
3516 afterRepair : function(){
3518 if(typeof this.callback == "function"){
3519 this.callback.call(this.scope || this);
3521 this.callback = null;
3526 * Ext JS Library 1.1.1
3527 * Copyright(c) 2006-2007, Ext JS, LLC.
3529 * Originally Released Under LGPL - original licence link has changed is not relivant.
3532 * <script type="text/javascript">
3536 * @class Roo.dd.DragSource
3537 * @extends Roo.dd.DDProxy
3538 * A simple class that provides the basic implementation needed to make any element draggable.
3540 * @param {String/HTMLElement/Element} el The container element
3541 * @param {Object} config
3543 Roo.dd.DragSource = function(el, config){
3544 this.el = Roo.get(el);
3547 Roo.apply(this, config);
3550 this.proxy = new Roo.dd.StatusProxy();
3553 Roo.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
3554 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
3556 this.dragging = false;
3559 Roo.extend(Roo.dd.DragSource, Roo.dd.DDProxy, {
3561 * @cfg {String} dropAllowed
3562 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
3564 dropAllowed : "x-dd-drop-ok",
3566 * @cfg {String} dropNotAllowed
3567 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
3569 dropNotAllowed : "x-dd-drop-nodrop",
3572 * Returns the data object associated with this drag source
3573 * @return {Object} data An object containing arbitrary data
3575 getDragData : function(e){
3576 return this.dragData;
3580 onDragEnter : function(e, id){
3581 var target = Roo.dd.DragDropMgr.getDDById(id);
3582 this.cachedTarget = target;
3583 if(this.beforeDragEnter(target, e, id) !== false){
3584 if(target.isNotifyTarget){
3585 var status = target.notifyEnter(this, e, this.dragData);
3586 this.proxy.setStatus(status);
3588 this.proxy.setStatus(this.dropAllowed);
3591 if(this.afterDragEnter){
3593 * An empty function by default, but provided so that you can perform a custom action
3594 * when the dragged item enters the drop target by providing an implementation.
3595 * @param {Roo.dd.DragDrop} target The drop target
3596 * @param {Event} e The event object
3597 * @param {String} id The id of the dragged element
3598 * @method afterDragEnter
3600 this.afterDragEnter(target, e, id);
3606 * An empty function by default, but provided so that you can perform a custom action
3607 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
3608 * @param {Roo.dd.DragDrop} target The drop target
3609 * @param {Event} e The event object
3610 * @param {String} id The id of the dragged element
3611 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3613 beforeDragEnter : function(target, e, id){
3618 alignElWithMouse: function() {
3619 Roo.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
3624 onDragOver : function(e, id){
3625 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3626 if(this.beforeDragOver(target, e, id) !== false){
3627 if(target.isNotifyTarget){
3628 var status = target.notifyOver(this, e, this.dragData);
3629 this.proxy.setStatus(status);
3632 if(this.afterDragOver){
3634 * An empty function by default, but provided so that you can perform a custom action
3635 * while the dragged item is over the drop target by providing an implementation.
3636 * @param {Roo.dd.DragDrop} target The drop target
3637 * @param {Event} e The event object
3638 * @param {String} id The id of the dragged element
3639 * @method afterDragOver
3641 this.afterDragOver(target, e, id);
3647 * An empty function by default, but provided so that you can perform a custom action
3648 * while the dragged item is over the drop target and optionally cancel the onDragOver.
3649 * @param {Roo.dd.DragDrop} target The drop target
3650 * @param {Event} e The event object
3651 * @param {String} id The id of the dragged element
3652 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3654 beforeDragOver : function(target, e, id){
3659 onDragOut : function(e, id){
3660 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3661 if(this.beforeDragOut(target, e, id) !== false){
3662 if(target.isNotifyTarget){
3663 target.notifyOut(this, e, this.dragData);
3666 if(this.afterDragOut){
3668 * An empty function by default, but provided so that you can perform a custom action
3669 * after the dragged item is dragged out of the target without dropping.
3670 * @param {Roo.dd.DragDrop} target The drop target
3671 * @param {Event} e The event object
3672 * @param {String} id The id of the dragged element
3673 * @method afterDragOut
3675 this.afterDragOut(target, e, id);
3678 this.cachedTarget = null;
3682 * An empty function by default, but provided so that you can perform a custom action before the dragged
3683 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
3684 * @param {Roo.dd.DragDrop} target The drop target
3685 * @param {Event} e The event object
3686 * @param {String} id The id of the dragged element
3687 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3689 beforeDragOut : function(target, e, id){
3694 onDragDrop : function(e, id){
3695 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3696 if(this.beforeDragDrop(target, e, id) !== false){
3697 if(target.isNotifyTarget){
3698 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
3699 this.onValidDrop(target, e, id);
3701 this.onInvalidDrop(target, e, id);
3704 this.onValidDrop(target, e, id);
3707 if(this.afterDragDrop){
3709 * An empty function by default, but provided so that you can perform a custom action
3710 * after a valid drag drop has occurred by providing an implementation.
3711 * @param {Roo.dd.DragDrop} target The drop target
3712 * @param {Event} e The event object
3713 * @param {String} id The id of the dropped element
3714 * @method afterDragDrop
3716 this.afterDragDrop(target, e, id);
3719 delete this.cachedTarget;
3723 * An empty function by default, but provided so that you can perform a custom action before the dragged
3724 * item is dropped onto the target and optionally cancel the onDragDrop.
3725 * @param {Roo.dd.DragDrop} target The drop target
3726 * @param {Event} e The event object
3727 * @param {String} id The id of the dragged element
3728 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
3730 beforeDragDrop : function(target, e, id){
3735 onValidDrop : function(target, e, id){
3737 if(this.afterValidDrop){
3739 * An empty function by default, but provided so that you can perform a custom action
3740 * after a valid drop has occurred by providing an implementation.
3741 * @param {Object} target The target DD
3742 * @param {Event} e The event object
3743 * @param {String} id The id of the dropped element
3744 * @method afterInvalidDrop
3746 this.afterValidDrop(target, e, id);
3751 getRepairXY : function(e, data){
3752 return this.el.getXY();
3756 onInvalidDrop : function(target, e, id){
3757 this.beforeInvalidDrop(target, e, id);
3758 if(this.cachedTarget){
3759 if(this.cachedTarget.isNotifyTarget){
3760 this.cachedTarget.notifyOut(this, e, this.dragData);
3762 this.cacheTarget = null;
3764 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
3766 if(this.afterInvalidDrop){
3768 * An empty function by default, but provided so that you can perform a custom action
3769 * after an invalid drop has occurred by providing an implementation.
3770 * @param {Event} e The event object
3771 * @param {String} id The id of the dropped element
3772 * @method afterInvalidDrop
3774 this.afterInvalidDrop(e, id);
3779 afterRepair : function(){
3781 this.el.highlight(this.hlColor || "c3daf9");
3783 this.dragging = false;
3787 * An empty function by default, but provided so that you can perform a custom action after an invalid
3788 * drop has occurred.
3789 * @param {Roo.dd.DragDrop} target The drop target
3790 * @param {Event} e The event object
3791 * @param {String} id The id of the dragged element
3792 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
3794 beforeInvalidDrop : function(target, e, id){
3799 handleMouseDown : function(e){
3803 var data = this.getDragData(e);
3804 if(data && this.onBeforeDrag(data, e) !== false){
3805 this.dragData = data;
3807 Roo.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
3812 * An empty function by default, but provided so that you can perform a custom action before the initial
3813 * drag event begins and optionally cancel it.
3814 * @param {Object} data An object containing arbitrary data to be shared with drop targets
3815 * @param {Event} e The event object
3816 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3818 onBeforeDrag : function(data, e){
3823 * An empty function by default, but provided so that you can perform a custom action once the initial
3824 * drag event has begun. The drag cannot be canceled from this function.
3825 * @param {Number} x The x position of the click on the dragged object
3826 * @param {Number} y The y position of the click on the dragged object
3828 onStartDrag : Roo.emptyFn,
3830 // private - YUI override
3831 startDrag : function(x, y){
3833 this.dragging = true;
3834 this.proxy.update("");
3835 this.onInitDrag(x, y);
3840 onInitDrag : function(x, y){
3841 var clone = this.el.dom.cloneNode(true);
3842 clone.id = Roo.id(); // prevent duplicate ids
3843 this.proxy.update(clone);
3844 this.onStartDrag(x, y);
3849 * Returns the drag source's underlying {@link Roo.dd.StatusProxy}
3850 * @return {Roo.dd.StatusProxy} proxy The StatusProxy
3852 getProxy : function(){
3857 * Hides the drag source's {@link Roo.dd.StatusProxy}
3859 hideProxy : function(){
3861 this.proxy.reset(true);
3862 this.dragging = false;
3866 triggerCacheRefresh : function(){
3867 Roo.dd.DDM.refreshCache(this.groups);
3870 // private - override to prevent hiding
3871 b4EndDrag: function(e) {
3874 // private - override to prevent moving
3875 endDrag : function(e){
3876 this.onEndDrag(this.dragData, e);
3880 onEndDrag : function(data, e){
3883 // private - pin to cursor
3884 autoOffset : function(x, y) {
3885 this.setDelta(-12, -20);
3889 * Ext JS Library 1.1.1
3890 * Copyright(c) 2006-2007, Ext JS, LLC.
3892 * Originally Released Under LGPL - original licence link has changed is not relivant.
3895 * <script type="text/javascript">
3900 * @class Roo.dd.DropTarget
3901 * @extends Roo.dd.DDTarget
3902 * A simple class that provides the basic implementation needed to make any element a drop target that can have
3903 * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
3905 * @param {String/HTMLElement/Element} el The container element
3906 * @param {Object} config
3908 Roo.dd.DropTarget = function(el, config){
3909 this.el = Roo.get(el);
3911 var listeners = false; ;
3912 if (config && config.listeners) {
3913 listeners= config.listeners;
3914 delete config.listeners;
3916 Roo.apply(this, config);
3918 if(this.containerScroll){
3919 Roo.dd.ScrollManager.register(this.el);
3923 * @scope Roo.dd.DropTarget
3928 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
3929 * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
3930 * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
3932 * IMPORTANT : it should set this.overClass and this.dropAllowed
3934 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3935 * @param {Event} e The event
3936 * @param {Object} data An object containing arbitrary data supplied by the drag source
3942 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the target.
3943 * This method will be called on every mouse movement while the drag source is over the drop target.
3944 * This default implementation simply returns the dropAllowed config value.
3946 * IMPORTANT : it should set this.dropAllowed
3948 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3949 * @param {Event} e The event
3950 * @param {Object} data An object containing arbitrary data supplied by the drag source
3956 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source has been dragged
3957 * out of the target without dropping. This default implementation simply removes the CSS class specified by
3958 * overClass (if any) from the drop element.
3960 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3961 * @param {Event} e The event
3962 * @param {Object} data An object containing arbitrary data supplied by the drag source
3968 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the dragged item has
3969 * been dropped on it. This method has no default implementation and returns false, so you must provide an
3970 * implementation that does something to process the drop event and returns true so that the drag source's
3971 * repair action does not run.
3973 * IMPORTANT : it should set this.success
3975 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3976 * @param {Event} e The event
3977 * @param {Object} data An object containing arbitrary data supplied by the drag source
3983 Roo.dd.DropTarget.superclass.constructor.call( this,
3985 this.ddGroup || this.group,
3988 listeners : listeners || {}
3996 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
3998 * @cfg {String} overClass
3999 * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
4002 * @cfg {String} ddGroup
4003 * The drag drop group to handle drop events for
4007 * @cfg {String} dropAllowed
4008 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
4010 dropAllowed : "x-dd-drop-ok",
4012 * @cfg {String} dropNotAllowed
4013 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
4015 dropNotAllowed : "x-dd-drop-nodrop",
4017 * @cfg {boolean} success
4018 * set this after drop listener..
4022 * @cfg {boolean|String} valid true/false or string (ok-add/ok-sub/ok/nodrop)
4023 * if the drop point is valid for over/enter..
4030 isNotifyTarget : true,
4035 notifyEnter : function(dd, e, data)
4038 this.fireEvent('enter', dd, e, data);
4040 this.el.addClass(this.overClass);
4042 return typeof(this.valid) == 'string' ? 'x-dd-drop-' + this.valid : (
4043 this.valid ? this.dropAllowed : this.dropNotAllowed
4050 notifyOver : function(dd, e, data)
4053 this.fireEvent('over', dd, e, data);
4054 return typeof(this.valid) == 'string' ? 'x-dd-drop-' + this.valid : (
4055 this.valid ? this.dropAllowed : this.dropNotAllowed
4062 notifyOut : function(dd, e, data)
4064 this.fireEvent('out', dd, e, data);
4066 this.el.removeClass(this.overClass);
4073 notifyDrop : function(dd, e, data)
4075 this.success = false;
4076 this.fireEvent('drop', dd, e, data);
4077 return this.success;
4081 * Ext JS Library 1.1.1
4082 * Copyright(c) 2006-2007, Ext JS, LLC.
4084 * Originally Released Under LGPL - original licence link has changed is not relivant.
4087 * <script type="text/javascript">
4092 * @class Roo.dd.DragZone
4093 * @extends Roo.dd.DragSource
4094 * This class provides a container DD instance that proxies for multiple child node sources.<br />
4095 * By default, this class requires that draggable child nodes are registered with {@link Roo.dd.Registry}.
4097 * @param {String/HTMLElement/Element} el The container element
4098 * @param {Object} config
4100 Roo.dd.DragZone = function(el, config){
4101 Roo.dd.DragZone.superclass.constructor.call(this, el, config);
4102 if(this.containerScroll){
4103 Roo.dd.ScrollManager.register(this.el);
4107 Roo.extend(Roo.dd.DragZone, Roo.dd.DragSource, {
4109 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
4110 * for auto scrolling during drag operations.
4113 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
4114 * method after a failed drop (defaults to "c3daf9" - light blue)
4118 * Called when a mousedown occurs in this container. Looks in {@link Roo.dd.Registry}
4119 * for a valid target to drag based on the mouse down. Override this method
4120 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
4121 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
4122 * @param {EventObject} e The mouse down event
4123 * @return {Object} The dragData
4125 getDragData : function(e){
4126 return Roo.dd.Registry.getHandleFromEvent(e);
4130 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
4131 * this.dragData.ddel
4132 * @param {Number} x The x position of the click on the dragged object
4133 * @param {Number} y The y position of the click on the dragged object
4134 * @return {Boolean} true to continue the drag, false to cancel
4136 onInitDrag : function(x, y){
4137 this.proxy.update(this.dragData.ddel.cloneNode(true));
4138 this.onStartDrag(x, y);
4143 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
4145 afterRepair : function(){
4147 Roo.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
4149 this.dragging = false;
4153 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
4154 * the XY of this.dragData.ddel
4155 * @param {EventObject} e The mouse up event
4156 * @return {Array} The xy location (e.g. [100, 200])
4158 getRepairXY : function(e){
4159 return Roo.Element.fly(this.dragData.ddel).getXY();
4163 * Ext JS Library 1.1.1
4164 * Copyright(c) 2006-2007, Ext JS, LLC.
4166 * Originally Released Under LGPL - original licence link has changed is not relivant.
4169 * <script type="text/javascript">
4172 * @class Roo.dd.DropZone
4173 * @extends Roo.dd.DropTarget
4174 * This class provides a container DD instance that proxies for multiple child node targets.<br />
4175 * By default, this class requires that child nodes accepting drop are registered with {@link Roo.dd.Registry}.
4177 * @param {String/HTMLElement/Element} el The container element
4178 * @param {Object} config
4180 Roo.dd.DropZone = function(el, config){
4181 Roo.dd.DropZone.superclass.constructor.call(this, el, config);
4184 Roo.extend(Roo.dd.DropZone, Roo.dd.DropTarget, {
4186 * Returns a custom data object associated with the DOM node that is the target of the event. By default
4187 * this looks up the event target in the {@link Roo.dd.Registry}, although you can override this method to
4188 * provide your own custom lookup.
4189 * @param {Event} e The event
4190 * @return {Object} data The custom data
4192 getTargetFromEvent : function(e){
4193 return Roo.dd.Registry.getTargetFromEvent(e);
4197 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has entered a drop node
4198 * that it has registered. This method has no default implementation and should be overridden to provide
4199 * node-specific processing if necessary.
4200 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4201 * {@link #getTargetFromEvent} for this node)
4202 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4203 * @param {Event} e The event
4204 * @param {Object} data An object containing arbitrary data supplied by the drag source
4206 onNodeEnter : function(n, dd, e, data){
4211 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is over a drop node
4212 * that it has registered. The default implementation returns this.dropNotAllowed, so it should be
4213 * overridden to provide the proper feedback.
4214 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4215 * {@link #getTargetFromEvent} for this node)
4216 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4217 * @param {Event} e The event
4218 * @param {Object} data An object containing arbitrary data supplied by the drag source
4219 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4220 * underlying {@link Roo.dd.StatusProxy} can be updated
4222 onNodeOver : function(n, dd, e, data){
4223 return this.dropAllowed;
4227 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dragged out of
4228 * the drop node without dropping. This method has no default implementation and should be overridden to provide
4229 * node-specific processing if necessary.
4230 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4231 * {@link #getTargetFromEvent} for this node)
4232 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4233 * @param {Event} e The event
4234 * @param {Object} data An object containing arbitrary data supplied by the drag source
4236 onNodeOut : function(n, dd, e, data){
4241 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped onto
4242 * the drop node. The default implementation returns false, so it should be overridden to provide the
4243 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
4244 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4245 * {@link #getTargetFromEvent} for this node)
4246 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4247 * @param {Event} e The event
4248 * @param {Object} data An object containing arbitrary data supplied by the drag source
4249 * @return {Boolean} True if the drop was valid, else false
4251 onNodeDrop : function(n, dd, e, data){
4256 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is being dragged over it,
4257 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
4258 * it should be overridden to provide the proper feedback if necessary.
4259 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4260 * @param {Event} e The event
4261 * @param {Object} data An object containing arbitrary data supplied by the drag source
4262 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4263 * underlying {@link Roo.dd.StatusProxy} can be updated
4265 onContainerOver : function(dd, e, data){
4266 return this.dropNotAllowed;
4270 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped on it,
4271 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
4272 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
4273 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
4274 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4275 * @param {Event} e The event
4276 * @param {Object} data An object containing arbitrary data supplied by the drag source
4277 * @return {Boolean} True if the drop was valid, else false
4279 onContainerDrop : function(dd, e, data){
4284 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source is now over
4285 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
4286 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
4287 * you should override this method and provide a custom implementation.
4288 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4289 * @param {Event} e The event
4290 * @param {Object} data An object containing arbitrary data supplied by the drag source
4291 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4292 * underlying {@link Roo.dd.StatusProxy} can be updated
4294 notifyEnter : function(dd, e, data){
4295 return this.dropNotAllowed;
4299 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the drop zone.
4300 * This method will be called on every mouse movement while the drag source is over the drop zone.
4301 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
4302 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
4303 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
4304 * registered node, it will call {@link #onContainerOver}.
4305 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4306 * @param {Event} e The event
4307 * @param {Object} data An object containing arbitrary data supplied by the drag source
4308 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4309 * underlying {@link Roo.dd.StatusProxy} can be updated
4311 notifyOver : function(dd, e, data){
4312 var n = this.getTargetFromEvent(e);
4313 if(!n){ // not over valid drop target
4314 if(this.lastOverNode){
4315 this.onNodeOut(this.lastOverNode, dd, e, data);
4316 this.lastOverNode = null;
4318 return this.onContainerOver(dd, e, data);
4320 if(this.lastOverNode != n){
4321 if(this.lastOverNode){
4322 this.onNodeOut(this.lastOverNode, dd, e, data);
4324 this.onNodeEnter(n, dd, e, data);
4325 this.lastOverNode = n;
4327 return this.onNodeOver(n, dd, e, data);
4331 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source has been dragged
4332 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
4333 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
4334 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
4335 * @param {Event} e The event
4336 * @param {Object} data An object containing arbitrary data supplied by the drag zone
4338 notifyOut : function(dd, e, data){
4339 if(this.lastOverNode){
4340 this.onNodeOut(this.lastOverNode, dd, e, data);
4341 this.lastOverNode = null;
4346 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the dragged item has
4347 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
4348 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
4349 * otherwise it will call {@link #onContainerDrop}.
4350 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4351 * @param {Event} e The event
4352 * @param {Object} data An object containing arbitrary data supplied by the drag source
4353 * @return {Boolean} True if the drop was valid, else false
4355 notifyDrop : function(dd, e, data){
4356 if(this.lastOverNode){
4357 this.onNodeOut(this.lastOverNode, dd, e, data);
4358 this.lastOverNode = null;
4360 var n = this.getTargetFromEvent(e);
4362 this.onNodeDrop(n, dd, e, data) :
4363 this.onContainerDrop(dd, e, data);
4367 triggerCacheRefresh : function(){
4368 Roo.dd.DDM.refreshCache(this.groups);
4372 * Ext JS Library 1.1.1
4373 * Copyright(c) 2006-2007, Ext JS, LLC.
4375 * Originally Released Under LGPL - original licence link has changed is not relivant.
4378 * <script type="text/javascript">
4383 * @class Roo.data.SortTypes
4385 * Defines the default sorting (casting?) comparison functions used when sorting data.
4387 Roo.data.SortTypes = {
4389 * Default sort that does nothing
4390 * @param {Mixed} s The value being converted
4391 * @return {Mixed} The comparison value
4398 * The regular expression used to strip tags
4402 stripTagsRE : /<\/?[^>]+>/gi,
4405 * Strips all HTML tags to sort on text only
4406 * @param {Mixed} s The value being converted
4407 * @return {String} The comparison value
4409 asText : function(s){
4410 return String(s).replace(this.stripTagsRE, "");
4414 * Strips all HTML tags to sort on text only - Case insensitive
4415 * @param {Mixed} s The value being converted
4416 * @return {String} The comparison value
4418 asUCText : function(s){
4419 return String(s).toUpperCase().replace(this.stripTagsRE, "");
4423 * Case insensitive string
4424 * @param {Mixed} s The value being converted
4425 * @return {String} The comparison value
4427 asUCString : function(s) {
4428 return String(s).toUpperCase();
4433 * @param {Mixed} s The value being converted
4434 * @return {Number} The comparison value
4436 asDate : function(s) {
4440 if(s instanceof Date){
4443 return Date.parse(String(s));
4448 * @param {Mixed} s The value being converted
4449 * @return {Float} The comparison value
4451 asFloat : function(s) {
4452 var val = parseFloat(String(s).replace(/,/g, ""));
4453 if(isNaN(val)) val = 0;
4459 * @param {Mixed} s The value being converted
4460 * @return {Number} The comparison value
4462 asInt : function(s) {
4463 var val = parseInt(String(s).replace(/,/g, ""));
4464 if(isNaN(val)) val = 0;
4469 * Ext JS Library 1.1.1
4470 * Copyright(c) 2006-2007, Ext JS, LLC.
4472 * Originally Released Under LGPL - original licence link has changed is not relivant.
4475 * <script type="text/javascript">
4479 * @class Roo.data.Record
4480 * Instances of this class encapsulate both record <em>definition</em> information, and record
4481 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
4482 * to access Records cached in an {@link Roo.data.Store} object.<br>
4484 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
4485 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
4488 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
4490 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
4491 * {@link #create}. The parameters are the same.
4492 * @param {Array} data An associative Array of data values keyed by the field name.
4493 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
4494 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
4495 * not specified an integer id is generated.
4497 Roo.data.Record = function(data, id){
4498 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
4503 * Generate a constructor for a specific record layout.
4504 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
4505 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
4506 * Each field definition object may contain the following properties: <ul>
4507 * <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,
4508 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
4509 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
4510 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
4511 * is being used, then this is a string containing the javascript expression to reference the data relative to
4512 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
4513 * to the data item relative to the record element. If the mapping expression is the same as the field name,
4514 * this may be omitted.</p></li>
4515 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
4516 * <ul><li>auto (Default, implies no conversion)</li>
4521 * <li>date</li></ul></p></li>
4522 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
4523 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
4524 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
4525 * by the Reader into an object that will be stored in the Record. It is passed the
4526 * following parameters:<ul>
4527 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
4529 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
4531 * <br>usage:<br><pre><code>
4532 var TopicRecord = Roo.data.Record.create(
4533 {name: 'title', mapping: 'topic_title'},
4534 {name: 'author', mapping: 'username'},
4535 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
4536 {name: 'lastPost', mapping: 'post_time', type: 'date'},
4537 {name: 'lastPoster', mapping: 'user2'},
4538 {name: 'excerpt', mapping: 'post_text'}
4541 var myNewRecord = new TopicRecord({
4542 title: 'Do my job please',
4545 lastPost: new Date(),
4546 lastPoster: 'Animal',
4547 excerpt: 'No way dude!'
4549 myStore.add(myNewRecord);
4554 Roo.data.Record.create = function(o){
4556 f.superclass.constructor.apply(this, arguments);
4558 Roo.extend(f, Roo.data.Record);
4559 var p = f.prototype;
4560 p.fields = new Roo.util.MixedCollection(false, function(field){
4563 for(var i = 0, len = o.length; i < len; i++){
4564 p.fields.add(new Roo.data.Field(o[i]));
4566 f.getField = function(name){
4567 return p.fields.get(name);
4572 Roo.data.Record.AUTO_ID = 1000;
4573 Roo.data.Record.EDIT = 'edit';
4574 Roo.data.Record.REJECT = 'reject';
4575 Roo.data.Record.COMMIT = 'commit';
4577 Roo.data.Record.prototype = {
4579 * Readonly flag - true if this record has been modified.
4588 join : function(store){
4593 * Set the named field to the specified value.
4594 * @param {String} name The name of the field to set.
4595 * @param {Object} value The value to set the field to.
4597 set : function(name, value){
4598 if(this.data[name] == value){
4605 if(typeof this.modified[name] == 'undefined'){
4606 this.modified[name] = this.data[name];
4608 this.data[name] = value;
4609 if(!this.editing && this.store){
4610 this.store.afterEdit(this);
4615 * Get the value of the named field.
4616 * @param {String} name The name of the field to get the value of.
4617 * @return {Object} The value of the field.
4619 get : function(name){
4620 return this.data[name];
4624 beginEdit : function(){
4625 this.editing = true;
4630 cancelEdit : function(){
4631 this.editing = false;
4632 delete this.modified;
4636 endEdit : function(){
4637 this.editing = false;
4638 if(this.dirty && this.store){
4639 this.store.afterEdit(this);
4644 * Usually called by the {@link Roo.data.Store} which owns the Record.
4645 * Rejects all changes made to the Record since either creation, or the last commit operation.
4646 * Modified fields are reverted to their original values.
4648 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
4649 * of reject operations.
4651 reject : function(){
4652 var m = this.modified;
4654 if(typeof m[n] != "function"){
4655 this.data[n] = m[n];
4659 delete this.modified;
4660 this.editing = false;
4662 this.store.afterReject(this);
4667 * Usually called by the {@link Roo.data.Store} which owns the Record.
4668 * Commits all changes made to the Record since either creation, or the last commit operation.
4670 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
4671 * of commit operations.
4673 commit : function(){
4675 delete this.modified;
4676 this.editing = false;
4678 this.store.afterCommit(this);
4683 hasError : function(){
4684 return this.error != null;
4688 clearError : function(){
4693 * Creates a copy of this record.
4694 * @param {String} id (optional) A new record id if you don't want to use this record's id
4697 copy : function(newId) {
4698 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
4702 * Ext JS Library 1.1.1
4703 * Copyright(c) 2006-2007, Ext JS, LLC.
4705 * Originally Released Under LGPL - original licence link has changed is not relivant.
4708 * <script type="text/javascript">
4714 * @class Roo.data.Store
4715 * @extends Roo.util.Observable
4716 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
4717 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
4719 * 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
4720 * has no knowledge of the format of the data returned by the Proxy.<br>
4722 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
4723 * instances from the data object. These records are cached and made available through accessor functions.
4725 * Creates a new Store.
4726 * @param {Object} config A config object containing the objects needed for the Store to access data,
4727 * and read the data into Records.
4729 Roo.data.Store = function(config){
4730 this.data = new Roo.util.MixedCollection(false);
4731 this.data.getKey = function(o){
4734 this.baseParams = {};
4741 "multisort" : "_multisort"
4744 if(config && config.data){
4745 this.inlineData = config.data;
4749 Roo.apply(this, config);
4751 if(this.reader){ // reader passed
4752 this.reader = Roo.factory(this.reader, Roo.data);
4753 this.reader.xmodule = this.xmodule || false;
4754 if(!this.recordType){
4755 this.recordType = this.reader.recordType;
4757 if(this.reader.onMetaChange){
4758 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
4762 if(this.recordType){
4763 this.fields = this.recordType.prototype.fields;
4769 * @event datachanged
4770 * Fires when the data cache has changed, and a widget which is using this Store
4771 * as a Record cache should refresh its view.
4772 * @param {Store} this
4777 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
4778 * @param {Store} this
4779 * @param {Object} meta The JSON metadata
4784 * Fires when Records have been added to the Store
4785 * @param {Store} this
4786 * @param {Roo.data.Record[]} records The array of Records added
4787 * @param {Number} index The index at which the record(s) were added
4792 * Fires when a Record has been removed from the Store
4793 * @param {Store} this
4794 * @param {Roo.data.Record} record The Record that was removed
4795 * @param {Number} index The index at which the record was removed
4800 * Fires when a Record has been updated
4801 * @param {Store} this
4802 * @param {Roo.data.Record} record The Record that was updated
4803 * @param {String} operation The update operation being performed. Value may be one of:
4805 Roo.data.Record.EDIT
4806 Roo.data.Record.REJECT
4807 Roo.data.Record.COMMIT
4813 * Fires when the data cache has been cleared.
4814 * @param {Store} this
4819 * Fires before a request is made for a new data object. If the beforeload handler returns false
4820 * the load action will be canceled.
4821 * @param {Store} this
4822 * @param {Object} options The loading options that were specified (see {@link #load} for details)
4826 * @event beforeloadadd
4827 * Fires after a new set of Records has been loaded.
4828 * @param {Store} this
4829 * @param {Roo.data.Record[]} records The Records that were loaded
4830 * @param {Object} options The loading options that were specified (see {@link #load} for details)
4832 beforeloadadd : true,
4835 * Fires after a new set of Records has been loaded, before they are added to the store.
4836 * @param {Store} this
4837 * @param {Roo.data.Record[]} records The Records that were loaded
4838 * @param {Object} options The loading options that were specified (see {@link #load} for details)
4839 * @params {Object} return from reader
4843 * @event loadexception
4844 * Fires if an exception occurs in the Proxy during loading.
4845 * Called with the signature of the Proxy's "loadexception" event.
4846 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
4849 * @param {Object} return from JsonData.reader() - success, totalRecords, records
4850 * @param {Object} load options
4851 * @param {Object} jsonData from your request (normally this contains the Exception)
4853 loadexception : true
4857 this.proxy = Roo.factory(this.proxy, Roo.data);
4858 this.proxy.xmodule = this.xmodule || false;
4859 this.relayEvents(this.proxy, ["loadexception"]);
4861 this.sortToggle = {};
4862 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
4864 Roo.data.Store.superclass.constructor.call(this);
4866 if(this.inlineData){
4867 this.loadData(this.inlineData);
4868 delete this.inlineData;
4872 Roo.extend(Roo.data.Store, Roo.util.Observable, {
4874 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
4875 * without a remote query - used by combo/forms at present.
4879 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
4882 * @cfg {Array} data Inline data to be loaded when the store is initialized.
4885 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
4886 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
4889 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
4890 * on any HTTP request
4893 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
4896 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
4900 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
4901 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
4906 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
4907 * loaded or when a record is removed. (defaults to false).
4909 pruneModifiedRecords : false,
4915 * Add Records to the Store and fires the add event.
4916 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
4918 add : function(records){
4919 records = [].concat(records);
4920 for(var i = 0, len = records.length; i < len; i++){
4921 records[i].join(this);
4923 var index = this.data.length;
4924 this.data.addAll(records);
4925 this.fireEvent("add", this, records, index);
4929 * Remove a Record from the Store and fires the remove event.
4930 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
4932 remove : function(record){
4933 var index = this.data.indexOf(record);
4934 this.data.removeAt(index);
4935 if(this.pruneModifiedRecords){
4936 this.modified.remove(record);
4938 this.fireEvent("remove", this, record, index);
4942 * Remove all Records from the Store and fires the clear event.
4944 removeAll : function(){
4946 if(this.pruneModifiedRecords){
4949 this.fireEvent("clear", this);
4953 * Inserts Records to the Store at the given index and fires the add event.
4954 * @param {Number} index The start index at which to insert the passed Records.
4955 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
4957 insert : function(index, records){
4958 records = [].concat(records);
4959 for(var i = 0, len = records.length; i < len; i++){
4960 this.data.insert(index, records[i]);
4961 records[i].join(this);
4963 this.fireEvent("add", this, records, index);
4967 * Get the index within the cache of the passed Record.
4968 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
4969 * @return {Number} The index of the passed Record. Returns -1 if not found.
4971 indexOf : function(record){
4972 return this.data.indexOf(record);
4976 * Get the index within the cache of the Record with the passed id.
4977 * @param {String} id The id of the Record to find.
4978 * @return {Number} The index of the Record. Returns -1 if not found.
4980 indexOfId : function(id){
4981 return this.data.indexOfKey(id);
4985 * Get the Record with the specified id.
4986 * @param {String} id The id of the Record to find.
4987 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
4989 getById : function(id){
4990 return this.data.key(id);
4994 * Get the Record at the specified index.
4995 * @param {Number} index The index of the Record to find.
4996 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
4998 getAt : function(index){
4999 return this.data.itemAt(index);
5003 * Returns a range of Records between specified indices.
5004 * @param {Number} startIndex (optional) The starting index (defaults to 0)
5005 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
5006 * @return {Roo.data.Record[]} An array of Records
5008 getRange : function(start, end){
5009 return this.data.getRange(start, end);
5013 storeOptions : function(o){
5014 o = Roo.apply({}, o);
5017 this.lastOptions = o;
5021 * Loads the Record cache from the configured Proxy using the configured Reader.
5023 * If using remote paging, then the first load call must specify the <em>start</em>
5024 * and <em>limit</em> properties in the options.params property to establish the initial
5025 * position within the dataset, and the number of Records to cache on each read from the Proxy.
5027 * <strong>It is important to note that for remote data sources, loading is asynchronous,
5028 * and this call will return before the new data has been loaded. Perform any post-processing
5029 * in a callback function, or in a "load" event handler.</strong>
5031 * @param {Object} options An object containing properties which control loading options:<ul>
5032 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
5033 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
5034 * passed the following arguments:<ul>
5035 * <li>r : Roo.data.Record[]</li>
5036 * <li>options: Options object from the load call</li>
5037 * <li>success: Boolean success indicator</li></ul></li>
5038 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
5039 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
5042 load : function(options){
5043 options = options || {};
5044 if(this.fireEvent("beforeload", this, options) !== false){
5045 this.storeOptions(options);
5046 var p = Roo.apply(options.params || {}, this.baseParams);
5047 // if meta was not loaded from remote source.. try requesting it.
5048 if (!this.reader.metaFromRemote) {
5051 if(this.sortInfo && this.remoteSort){
5052 var pn = this.paramNames;
5053 p[pn["sort"]] = this.sortInfo.field;
5054 p[pn["dir"]] = this.sortInfo.direction;
5056 if (this.multiSort) {
5057 var pn = this.paramNames;
5058 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
5061 this.proxy.load(p, this.reader, this.loadRecords, this, options);
5066 * Reloads the Record cache from the configured Proxy using the configured Reader and
5067 * the options from the last load operation performed.
5068 * @param {Object} options (optional) An object containing properties which may override the options
5069 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
5070 * the most recently used options are reused).
5072 reload : function(options){
5073 this.load(Roo.applyIf(options||{}, this.lastOptions));
5077 // Called as a callback by the Reader during a load operation.
5078 loadRecords : function(o, options, success){
5079 if(!o || success === false){
5080 if(success !== false){
5081 this.fireEvent("load", this, [], options, o);
5083 if(options.callback){
5084 options.callback.call(options.scope || this, [], options, false);
5088 // if data returned failure - throw an exception.
5089 if (o.success === false) {
5090 // show a message if no listener is registered.
5091 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
5092 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
5094 // loadmask wil be hooked into this..
5095 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
5098 var r = o.records, t = o.totalRecords || r.length;
5100 this.fireEvent("beforeloadadd", this, r, options, o);
5102 if(!options || options.add !== true){
5103 if(this.pruneModifiedRecords){
5106 for(var i = 0, len = r.length; i < len; i++){
5110 this.data = this.snapshot;
5111 delete this.snapshot;
5114 this.data.addAll(r);
5115 this.totalLength = t;
5117 this.fireEvent("datachanged", this);
5119 this.totalLength = Math.max(t, this.data.length+r.length);
5122 this.fireEvent("load", this, r, options, o);
5123 if(options.callback){
5124 options.callback.call(options.scope || this, r, options, true);
5130 * Loads data from a passed data block. A Reader which understands the format of the data
5131 * must have been configured in the constructor.
5132 * @param {Object} data The data block from which to read the Records. The format of the data expected
5133 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
5134 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
5136 loadData : function(o, append){
5137 var r = this.reader.readRecords(o);
5138 this.loadRecords(r, {add: append}, true);
5142 * Gets the number of cached records.
5144 * <em>If using paging, this may not be the total size of the dataset. If the data object
5145 * used by the Reader contains the dataset size, then the getTotalCount() function returns
5146 * the data set size</em>
5148 getCount : function(){
5149 return this.data.length || 0;
5153 * Gets the total number of records in the dataset as returned by the server.
5155 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
5156 * the dataset size</em>
5158 getTotalCount : function(){
5159 return this.totalLength || 0;
5163 * Returns the sort state of the Store as an object with two properties:
5165 field {String} The name of the field by which the Records are sorted
5166 direction {String} The sort order, "ASC" or "DESC"
5169 getSortState : function(){
5170 return this.sortInfo;
5174 applySort : function(){
5175 if(this.sortInfo && !this.remoteSort){
5176 var s = this.sortInfo, f = s.field;
5177 var st = this.fields.get(f).sortType;
5178 var fn = function(r1, r2){
5179 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
5180 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
5182 this.data.sort(s.direction, fn);
5183 if(this.snapshot && this.snapshot != this.data){
5184 this.snapshot.sort(s.direction, fn);
5190 * Sets the default sort column and order to be used by the next load operation.
5191 * @param {String} fieldName The name of the field to sort by.
5192 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
5194 setDefaultSort : function(field, dir){
5195 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
5200 * If remote sorting is used, the sort is performed on the server, and the cache is
5201 * reloaded. If local sorting is used, the cache is sorted internally.
5202 * @param {String} fieldName The name of the field to sort by.
5203 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
5205 sort : function(fieldName, dir){
5206 var f = this.fields.get(fieldName);
5208 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
5210 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
5211 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
5216 this.sortToggle[f.name] = dir;
5217 this.sortInfo = {field: f.name, direction: dir};
5218 if(!this.remoteSort){
5220 this.fireEvent("datachanged", this);
5222 this.load(this.lastOptions);
5227 * Calls the specified function for each of the Records in the cache.
5228 * @param {Function} fn The function to call. The Record is passed as the first parameter.
5229 * Returning <em>false</em> aborts and exits the iteration.
5230 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
5232 each : function(fn, scope){
5233 this.data.each(fn, scope);
5237 * Gets all records modified since the last commit. Modified records are persisted across load operations
5238 * (e.g., during paging).
5239 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
5241 getModifiedRecords : function(){
5242 return this.modified;
5246 createFilterFn : function(property, value, anyMatch){
5247 if(!value.exec){ // not a regex
5248 value = String(value);
5249 if(value.length == 0){
5252 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
5255 return value.test(r.data[property]);
5260 * Sums the value of <i>property</i> for each record between start and end and returns the result.
5261 * @param {String} property A field on your records
5262 * @param {Number} start The record index to start at (defaults to 0)
5263 * @param {Number} end The last record index to include (defaults to length - 1)
5264 * @return {Number} The sum
5266 sum : function(property, start, end){
5267 var rs = this.data.items, v = 0;
5269 end = (end || end === 0) ? end : rs.length-1;
5271 for(var i = start; i <= end; i++){
5272 v += (rs[i].data[property] || 0);
5278 * Filter the records by a specified property.
5279 * @param {String} field A field on your records
5280 * @param {String/RegExp} value Either a string that the field
5281 * should start with or a RegExp to test against the field
5282 * @param {Boolean} anyMatch True to match any part not just the beginning
5284 filter : function(property, value, anyMatch){
5285 var fn = this.createFilterFn(property, value, anyMatch);
5286 return fn ? this.filterBy(fn) : this.clearFilter();
5290 * Filter by a function. The specified function will be called with each
5291 * record in this data source. If the function returns true the record is included,
5292 * otherwise it is filtered.
5293 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
5294 * @param {Object} scope (optional) The scope of the function (defaults to this)
5296 filterBy : function(fn, scope){
5297 this.snapshot = this.snapshot || this.data;
5298 this.data = this.queryBy(fn, scope||this);
5299 this.fireEvent("datachanged", this);
5303 * Query the records by a specified property.
5304 * @param {String} field A field on your records
5305 * @param {String/RegExp} value Either a string that the field
5306 * should start with or a RegExp to test against the field
5307 * @param {Boolean} anyMatch True to match any part not just the beginning
5308 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
5310 query : function(property, value, anyMatch){
5311 var fn = this.createFilterFn(property, value, anyMatch);
5312 return fn ? this.queryBy(fn) : this.data.clone();
5316 * Query by a function. The specified function will be called with each
5317 * record in this data source. If the function returns true the record is included
5319 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
5320 * @param {Object} scope (optional) The scope of the function (defaults to this)
5321 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
5323 queryBy : function(fn, scope){
5324 var data = this.snapshot || this.data;
5325 return data.filterBy(fn, scope||this);
5329 * Collects unique values for a particular dataIndex from this store.
5330 * @param {String} dataIndex The property to collect
5331 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
5332 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
5333 * @return {Array} An array of the unique values
5335 collect : function(dataIndex, allowNull, bypassFilter){
5336 var d = (bypassFilter === true && this.snapshot) ?
5337 this.snapshot.items : this.data.items;
5338 var v, sv, r = [], l = {};
5339 for(var i = 0, len = d.length; i < len; i++){
5340 v = d[i].data[dataIndex];
5342 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
5351 * Revert to a view of the Record cache with no filtering applied.
5352 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
5354 clearFilter : function(suppressEvent){
5355 if(this.snapshot && this.snapshot != this.data){
5356 this.data = this.snapshot;
5357 delete this.snapshot;
5358 if(suppressEvent !== true){
5359 this.fireEvent("datachanged", this);
5365 afterEdit : function(record){
5366 if(this.modified.indexOf(record) == -1){
5367 this.modified.push(record);
5369 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
5373 afterReject : function(record){
5374 this.modified.remove(record);
5375 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
5379 afterCommit : function(record){
5380 this.modified.remove(record);
5381 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
5385 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
5386 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
5388 commitChanges : function(){
5389 var m = this.modified.slice(0);
5391 for(var i = 0, len = m.length; i < len; i++){
5397 * Cancel outstanding changes on all changed records.
5399 rejectChanges : function(){
5400 var m = this.modified.slice(0);
5402 for(var i = 0, len = m.length; i < len; i++){
5407 onMetaChange : function(meta, rtype, o){
5408 this.recordType = rtype;
5409 this.fields = rtype.prototype.fields;
5410 delete this.snapshot;
5411 this.sortInfo = meta.sortInfo || this.sortInfo;
5413 this.fireEvent('metachange', this, this.reader.meta);
5417 * Ext JS Library 1.1.1
5418 * Copyright(c) 2006-2007, Ext JS, LLC.
5420 * Originally Released Under LGPL - original licence link has changed is not relivant.
5423 * <script type="text/javascript">
5427 * @class Roo.data.SimpleStore
5428 * @extends Roo.data.Store
5429 * Small helper class to make creating Stores from Array data easier.
5430 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
5431 * @cfg {Array} fields An array of field definition objects, or field name strings.
5432 * @cfg {Array} data The multi-dimensional array of data
5434 * @param {Object} config
5436 Roo.data.SimpleStore = function(config){
5437 Roo.data.SimpleStore.superclass.constructor.call(this, {
5439 reader: new Roo.data.ArrayReader({
5442 Roo.data.Record.create(config.fields)
5444 proxy : new Roo.data.MemoryProxy(config.data)
5448 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
5450 * Ext JS Library 1.1.1
5451 * Copyright(c) 2006-2007, Ext JS, LLC.
5453 * Originally Released Under LGPL - original licence link has changed is not relivant.
5456 * <script type="text/javascript">
5461 * @extends Roo.data.Store
5462 * @class Roo.data.JsonStore
5463 * Small helper class to make creating Stores for JSON data easier. <br/>
5465 var store = new Roo.data.JsonStore({
5466 url: 'get-images.php',
5468 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
5471 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
5472 * JsonReader and HttpProxy (unless inline data is provided).</b>
5473 * @cfg {Array} fields An array of field definition objects, or field name strings.
5475 * @param {Object} config
5477 Roo.data.JsonStore = function(c){
5478 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
5479 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
5480 reader: new Roo.data.JsonReader(c, c.fields)
5483 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
5485 * Ext JS Library 1.1.1
5486 * Copyright(c) 2006-2007, Ext JS, LLC.
5488 * Originally Released Under LGPL - original licence link has changed is not relivant.
5491 * <script type="text/javascript">
5495 Roo.data.Field = function(config){
5496 if(typeof config == "string"){
5497 config = {name: config};
5499 Roo.apply(this, config);
5505 var st = Roo.data.SortTypes;
5506 // named sortTypes are supported, here we look them up
5507 if(typeof this.sortType == "string"){
5508 this.sortType = st[this.sortType];
5511 // set default sortType for strings and dates
5515 this.sortType = st.asUCString;
5518 this.sortType = st.asDate;
5521 this.sortType = st.none;
5526 var stripRe = /[\$,%]/g;
5528 // prebuilt conversion function for this field, instead of
5529 // switching every time we're reading a value
5531 var cv, dateFormat = this.dateFormat;
5536 cv = function(v){ return v; };
5539 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
5543 return v !== undefined && v !== null && v !== '' ?
5544 parseInt(String(v).replace(stripRe, ""), 10) : '';
5549 return v !== undefined && v !== null && v !== '' ?
5550 parseFloat(String(v).replace(stripRe, ""), 10) : '';
5555 cv = function(v){ return v === true || v === "true" || v == 1; };
5562 if(v instanceof Date){
5566 if(dateFormat == "timestamp"){
5567 return new Date(v*1000);
5569 return Date.parseDate(v, dateFormat);
5571 var parsed = Date.parse(v);
5572 return parsed ? new Date(parsed) : null;
5581 Roo.data.Field.prototype = {
5589 * Ext JS Library 1.1.1
5590 * Copyright(c) 2006-2007, Ext JS, LLC.
5592 * Originally Released Under LGPL - original licence link has changed is not relivant.
5595 * <script type="text/javascript">
5598 // Base class for reading structured data from a data source. This class is intended to be
5599 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
5602 * @class Roo.data.DataReader
5603 * Base class for reading structured data from a data source. This class is intended to be
5604 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
5607 Roo.data.DataReader = function(meta, recordType){
5611 this.recordType = recordType instanceof Array ?
5612 Roo.data.Record.create(recordType) : recordType;
5615 Roo.data.DataReader.prototype = {
5617 * Create an empty record
5618 * @param {Object} data (optional) - overlay some values
5619 * @return {Roo.data.Record} record created.
5621 newRow : function(d) {
5623 this.recordType.prototype.fields.each(function(c) {
5625 case 'int' : da[c.name] = 0; break;
5626 case 'date' : da[c.name] = new Date(); break;
5627 case 'float' : da[c.name] = 0.0; break;
5628 case 'boolean' : da[c.name] = false; break;
5629 default : da[c.name] = ""; break;
5633 return new this.recordType(Roo.apply(da, d));
5638 * Ext JS Library 1.1.1
5639 * Copyright(c) 2006-2007, Ext JS, LLC.
5641 * Originally Released Under LGPL - original licence link has changed is not relivant.
5644 * <script type="text/javascript">
5648 * @class Roo.data.DataProxy
5649 * @extends Roo.data.Observable
5650 * This class is an abstract base class for implementations which provide retrieval of
5651 * unformatted data objects.<br>
5653 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
5654 * (of the appropriate type which knows how to parse the data object) to provide a block of
5655 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
5657 * Custom implementations must implement the load method as described in
5658 * {@link Roo.data.HttpProxy#load}.
5660 Roo.data.DataProxy = function(){
5664 * Fires before a network request is made to retrieve a data object.
5665 * @param {Object} This DataProxy object.
5666 * @param {Object} params The params parameter to the load function.
5671 * Fires before the load method's callback is called.
5672 * @param {Object} This DataProxy object.
5673 * @param {Object} o The data object.
5674 * @param {Object} arg The callback argument object passed to the load function.
5678 * @event loadexception
5679 * Fires if an Exception occurs during data retrieval.
5680 * @param {Object} This DataProxy object.
5681 * @param {Object} o The data object.
5682 * @param {Object} arg The callback argument object passed to the load function.
5683 * @param {Object} e The Exception.
5685 loadexception : true
5687 Roo.data.DataProxy.superclass.constructor.call(this);
5690 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
5693 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
5697 * Ext JS Library 1.1.1
5698 * Copyright(c) 2006-2007, Ext JS, LLC.
5700 * Originally Released Under LGPL - original licence link has changed is not relivant.
5703 * <script type="text/javascript">
5706 * @class Roo.data.MemoryProxy
5707 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
5708 * to the Reader when its load method is called.
5710 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
5712 Roo.data.MemoryProxy = function(data){
5716 Roo.data.MemoryProxy.superclass.constructor.call(this);
5720 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
5722 * Load data from the requested source (in this case an in-memory
5723 * data object passed to the constructor), read the data object into
5724 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
5725 * process that block using the passed callback.
5726 * @param {Object} params This parameter is not used by the MemoryProxy class.
5727 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5728 * object into a block of Roo.data.Records.
5729 * @param {Function} callback The function into which to pass the block of Roo.data.records.
5730 * The function must be passed <ul>
5731 * <li>The Record block object</li>
5732 * <li>The "arg" argument from the load function</li>
5733 * <li>A boolean success indicator</li>
5735 * @param {Object} scope The scope in which to call the callback
5736 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5738 load : function(params, reader, callback, scope, arg){
5739 params = params || {};
5742 result = reader.readRecords(this.data);
5744 this.fireEvent("loadexception", this, arg, null, e);
5745 callback.call(scope, null, arg, false);
5748 callback.call(scope, result, arg, true);
5752 update : function(params, records){
5757 * Ext JS Library 1.1.1
5758 * Copyright(c) 2006-2007, Ext JS, LLC.
5760 * Originally Released Under LGPL - original licence link has changed is not relivant.
5763 * <script type="text/javascript">
5766 * @class Roo.data.HttpProxy
5767 * @extends Roo.data.DataProxy
5768 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
5769 * configured to reference a certain URL.<br><br>
5771 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
5772 * from which the running page was served.<br><br>
5774 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
5776 * Be aware that to enable the browser to parse an XML document, the server must set
5777 * the Content-Type header in the HTTP response to "text/xml".
5779 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
5780 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
5781 * will be used to make the request.
5783 Roo.data.HttpProxy = function(conn){
5784 Roo.data.HttpProxy.superclass.constructor.call(this);
5785 // is conn a conn config or a real conn?
5787 this.useAjax = !conn || !conn.events;
5791 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
5792 // thse are take from connection...
5795 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
5798 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
5799 * extra parameters to each request made by this object. (defaults to undefined)
5802 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
5803 * to each request made by this object. (defaults to undefined)
5806 * @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)
5809 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
5812 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
5818 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
5822 * Return the {@link Roo.data.Connection} object being used by this Proxy.
5823 * @return {Connection} The Connection object. This object may be used to subscribe to events on
5824 * a finer-grained basis than the DataProxy events.
5826 getConnection : function(){
5827 return this.useAjax ? Roo.Ajax : this.conn;
5831 * Load data from the configured {@link Roo.data.Connection}, read the data object into
5832 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
5833 * process that block using the passed callback.
5834 * @param {Object} params An object containing properties which are to be used as HTTP parameters
5835 * for the request to the remote server.
5836 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5837 * object into a block of Roo.data.Records.
5838 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
5839 * The function must be passed <ul>
5840 * <li>The Record block object</li>
5841 * <li>The "arg" argument from the load function</li>
5842 * <li>A boolean success indicator</li>
5844 * @param {Object} scope The scope in which to call the callback
5845 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5847 load : function(params, reader, callback, scope, arg){
5848 if(this.fireEvent("beforeload", this, params) !== false){
5850 params : params || {},
5852 callback : callback,
5857 callback : this.loadResponse,
5861 Roo.applyIf(o, this.conn);
5862 if(this.activeRequest){
5863 Roo.Ajax.abort(this.activeRequest);
5865 this.activeRequest = Roo.Ajax.request(o);
5867 this.conn.request(o);
5870 callback.call(scope||this, null, arg, false);
5875 loadResponse : function(o, success, response){
5876 delete this.activeRequest;
5878 this.fireEvent("loadexception", this, o, response);
5879 o.request.callback.call(o.request.scope, null, o.request.arg, false);
5884 result = o.reader.read(response);
5886 this.fireEvent("loadexception", this, o, response, e);
5887 o.request.callback.call(o.request.scope, null, o.request.arg, false);
5891 this.fireEvent("load", this, o, o.request.arg);
5892 o.request.callback.call(o.request.scope, result, o.request.arg, true);
5896 update : function(dataSet){
5901 updateResponse : function(dataSet){
5906 * Ext JS Library 1.1.1
5907 * Copyright(c) 2006-2007, Ext JS, LLC.
5909 * Originally Released Under LGPL - original licence link has changed is not relivant.
5912 * <script type="text/javascript">
5916 * @class Roo.data.ScriptTagProxy
5917 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
5918 * other than the originating domain of the running page.<br><br>
5920 * <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
5921 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
5923 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
5924 * source code that is used as the source inside a <script> tag.<br><br>
5926 * In order for the browser to process the returned data, the server must wrap the data object
5927 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
5928 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
5929 * depending on whether the callback name was passed:
5932 boolean scriptTag = false;
5933 String cb = request.getParameter("callback");
5936 response.setContentType("text/javascript");
5938 response.setContentType("application/x-json");
5940 Writer out = response.getWriter();
5942 out.write(cb + "(");
5944 out.print(dataBlock.toJsonString());
5951 * @param {Object} config A configuration object.
5953 Roo.data.ScriptTagProxy = function(config){
5954 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
5955 Roo.apply(this, config);
5956 this.head = document.getElementsByTagName("head")[0];
5959 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
5961 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
5963 * @cfg {String} url The URL from which to request the data object.
5966 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
5970 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
5971 * the server the name of the callback function set up by the load call to process the returned data object.
5972 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
5973 * javascript output which calls this named function passing the data object as its only parameter.
5975 callbackParam : "callback",
5977 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
5978 * name to the request.
5983 * Load data from the configured URL, read the data object into
5984 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
5985 * process that block using the passed callback.
5986 * @param {Object} params An object containing properties which are to be used as HTTP parameters
5987 * for the request to the remote server.
5988 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5989 * object into a block of Roo.data.Records.
5990 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
5991 * The function must be passed <ul>
5992 * <li>The Record block object</li>
5993 * <li>The "arg" argument from the load function</li>
5994 * <li>A boolean success indicator</li>
5996 * @param {Object} scope The scope in which to call the callback
5997 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5999 load : function(params, reader, callback, scope, arg){
6000 if(this.fireEvent("beforeload", this, params) !== false){
6002 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
6005 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
6007 url += "&_dc=" + (new Date().getTime());
6009 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
6012 cb : "stcCallback"+transId,
6013 scriptId : "stcScript"+transId,
6017 callback : callback,
6023 window[trans.cb] = function(o){
6024 conn.handleResponse(o, trans);
6027 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
6029 if(this.autoAbort !== false){
6033 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
6035 var script = document.createElement("script");
6036 script.setAttribute("src", url);
6037 script.setAttribute("type", "text/javascript");
6038 script.setAttribute("id", trans.scriptId);
6039 this.head.appendChild(script);
6043 callback.call(scope||this, null, arg, false);
6048 isLoading : function(){
6049 return this.trans ? true : false;
6053 * Abort the current server request.
6056 if(this.isLoading()){
6057 this.destroyTrans(this.trans);
6062 destroyTrans : function(trans, isLoaded){
6063 this.head.removeChild(document.getElementById(trans.scriptId));
6064 clearTimeout(trans.timeoutId);
6066 window[trans.cb] = undefined;
6068 delete window[trans.cb];
6071 // if hasn't been loaded, wait for load to remove it to prevent script error
6072 window[trans.cb] = function(){
6073 window[trans.cb] = undefined;
6075 delete window[trans.cb];
6082 handleResponse : function(o, trans){
6084 this.destroyTrans(trans, true);
6087 result = trans.reader.readRecords(o);
6089 this.fireEvent("loadexception", this, o, trans.arg, e);
6090 trans.callback.call(trans.scope||window, null, trans.arg, false);
6093 this.fireEvent("load", this, o, trans.arg);
6094 trans.callback.call(trans.scope||window, result, trans.arg, true);
6098 handleFailure : function(trans){
6100 this.destroyTrans(trans, false);
6101 this.fireEvent("loadexception", this, null, trans.arg);
6102 trans.callback.call(trans.scope||window, null, trans.arg, false);
6106 * Ext JS Library 1.1.1
6107 * Copyright(c) 2006-2007, Ext JS, LLC.
6109 * Originally Released Under LGPL - original licence link has changed is not relivant.
6112 * <script type="text/javascript">
6116 * @class Roo.data.JsonReader
6117 * @extends Roo.data.DataReader
6118 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
6119 * based on mappings in a provided Roo.data.Record constructor.
6121 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
6122 * in the reply previously.
6127 var RecordDef = Roo.data.Record.create([
6128 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
6129 {name: 'occupation'} // This field will use "occupation" as the mapping.
6131 var myReader = new Roo.data.JsonReader({
6132 totalProperty: "results", // The property which contains the total dataset size (optional)
6133 root: "rows", // The property which contains an Array of row objects
6134 id: "id" // The property within each row object that provides an ID for the record (optional)
6138 * This would consume a JSON file like this:
6140 { 'results': 2, 'rows': [
6141 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
6142 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
6145 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
6146 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
6147 * paged from the remote server.
6148 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
6149 * @cfg {String} root name of the property which contains the Array of row objects.
6150 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
6152 * Create a new JsonReader
6153 * @param {Object} meta Metadata configuration options
6154 * @param {Object} recordType Either an Array of field definition objects,
6155 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
6157 Roo.data.JsonReader = function(meta, recordType){
6160 // set some defaults:
6162 totalProperty: 'total',
6163 successProperty : 'success',
6168 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
6170 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
6173 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
6174 * Used by Store query builder to append _requestMeta to params.
6177 metaFromRemote : false,
6179 * This method is only used by a DataProxy which has retrieved data from a remote server.
6180 * @param {Object} response The XHR object which contains the JSON data in its responseText.
6181 * @return {Object} data A data block which is used by an Roo.data.Store object as
6182 * a cache of Roo.data.Records.
6184 read : function(response){
6185 var json = response.responseText;
6187 var o = /* eval:var:o */ eval("("+json+")");
6189 throw {message: "JsonReader.read: Json object not found"};
6195 this.metaFromRemote = true;
6196 this.meta = o.metaData;
6197 this.recordType = Roo.data.Record.create(o.metaData.fields);
6198 this.onMetaChange(this.meta, this.recordType, o);
6200 return this.readRecords(o);
6203 // private function a store will implement
6204 onMetaChange : function(meta, recordType, o){
6211 simpleAccess: function(obj, subsc) {
6218 getJsonAccessor: function(){
6220 return function(expr) {
6222 return(re.test(expr))
6223 ? new Function("obj", "return obj." + expr)
6233 * Create a data block containing Roo.data.Records from an XML document.
6234 * @param {Object} o An object which contains an Array of row objects in the property specified
6235 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
6236 * which contains the total size of the dataset.
6237 * @return {Object} data A data block which is used by an Roo.data.Store object as
6238 * a cache of Roo.data.Records.
6240 readRecords : function(o){
6242 * After any data loads, the raw JSON data is available for further custom processing.
6246 var s = this.meta, Record = this.recordType,
6247 f = Record.prototype.fields, fi = f.items, fl = f.length;
6249 // Generate extraction functions for the totalProperty, the root, the id, and for each field
6251 if(s.totalProperty) {
6252 this.getTotal = this.getJsonAccessor(s.totalProperty);
6254 if(s.successProperty) {
6255 this.getSuccess = this.getJsonAccessor(s.successProperty);
6257 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
6259 var g = this.getJsonAccessor(s.id);
6260 this.getId = function(rec) {
6262 return (r === undefined || r === "") ? null : r;
6265 this.getId = function(){return null;};
6268 for(var jj = 0; jj < fl; jj++){
6270 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
6271 this.ef[jj] = this.getJsonAccessor(map);
6275 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
6276 if(s.totalProperty){
6277 var vt = parseInt(this.getTotal(o), 10);
6282 if(s.successProperty){
6283 var vs = this.getSuccess(o);
6284 if(vs === false || vs === 'false'){
6289 for(var i = 0; i < c; i++){
6292 var id = this.getId(n);
6293 for(var j = 0; j < fl; j++){
6295 var v = this.ef[j](n);
6297 Roo.log('missing convert for ' + f.name);
6301 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
6303 var record = new Record(values, id);
6305 records[i] = record;
6311 totalRecords : totalRecords
6316 * Ext JS Library 1.1.1
6317 * Copyright(c) 2006-2007, Ext JS, LLC.
6319 * Originally Released Under LGPL - original licence link has changed is not relivant.
6322 * <script type="text/javascript">
6326 * @class Roo.data.XmlReader
6327 * @extends Roo.data.DataReader
6328 * Data reader class to create an Array of {@link Roo.data.Record} objects from an XML document
6329 * based on mappings in a provided Roo.data.Record constructor.<br><br>
6331 * <em>Note that in order for the browser to parse a returned XML document, the Content-Type
6332 * header in the HTTP response must be set to "text/xml".</em>
6336 var RecordDef = Roo.data.Record.create([
6337 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
6338 {name: 'occupation'} // This field will use "occupation" as the mapping.
6340 var myReader = new Roo.data.XmlReader({
6341 totalRecords: "results", // The element which contains the total dataset size (optional)
6342 record: "row", // The repeated element which contains row information
6343 id: "id" // The element within the row that provides an ID for the record (optional)
6347 * This would consume an XML file like this:
6351 <results>2</results>
6354 <name>Bill</name>
6355 <occupation>Gardener</occupation>
6359 <name>Ben</name>
6360 <occupation>Horticulturalist</occupation>
6364 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
6365 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
6366 * paged from the remote server.
6367 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
6368 * @cfg {String} success The DomQuery path to the success attribute used by forms.
6369 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
6370 * a record identifier value.
6372 * Create a new XmlReader
6373 * @param {Object} meta Metadata configuration options
6374 * @param {Mixed} recordType The definition of the data record type to produce. This can be either a valid
6375 * Record subclass created with {@link Roo.data.Record#create}, or an array of objects with which to call
6376 * Roo.data.Record.create. See the {@link Roo.data.Record} class for more details.
6378 Roo.data.XmlReader = function(meta, recordType){
6380 Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields);
6382 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
6384 * This method is only used by a DataProxy which has retrieved data from a remote server.
6385 * @param {Object} response The XHR object which contains the parsed XML document. The response is expected
6386 * to contain a method called 'responseXML' that returns an XML document object.
6387 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
6388 * a cache of Roo.data.Records.
6390 read : function(response){
6391 var doc = response.responseXML;
6393 throw {message: "XmlReader.read: XML Document not available"};
6395 return this.readRecords(doc);
6399 * Create a data block containing Roo.data.Records from an XML document.
6400 * @param {Object} doc A parsed XML document.
6401 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
6402 * a cache of Roo.data.Records.
6404 readRecords : function(doc){
6406 * After any data loads/reads, the raw XML Document is available for further custom processing.
6410 var root = doc.documentElement || doc;
6411 var q = Roo.DomQuery;
6412 var recordType = this.recordType, fields = recordType.prototype.fields;
6413 var sid = this.meta.id;
6414 var totalRecords = 0, success = true;
6415 if(this.meta.totalRecords){
6416 totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
6419 if(this.meta.success){
6420 var sv = q.selectValue(this.meta.success, root, true);
6421 success = sv !== false && sv !== 'false';
6424 var ns = q.select(this.meta.record, root);
6425 for(var i = 0, len = ns.length; i < len; i++) {
6428 var id = sid ? q.selectValue(sid, n) : undefined;
6429 for(var j = 0, jlen = fields.length; j < jlen; j++){
6430 var f = fields.items[j];
6431 var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
6435 var record = new recordType(values, id);
6437 records[records.length] = record;
6443 totalRecords : totalRecords || records.length
6448 * Ext JS Library 1.1.1
6449 * Copyright(c) 2006-2007, Ext JS, LLC.
6451 * Originally Released Under LGPL - original licence link has changed is not relivant.
6454 * <script type="text/javascript">
6458 * @class Roo.data.ArrayReader
6459 * @extends Roo.data.DataReader
6460 * Data reader class to create an Array of Roo.data.Record objects from an Array.
6461 * Each element of that Array represents a row of data fields. The
6462 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
6463 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
6467 var RecordDef = Roo.data.Record.create([
6468 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
6469 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
6471 var myReader = new Roo.data.ArrayReader({
6472 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
6476 * This would consume an Array like this:
6478 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
6480 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
6482 * Create a new JsonReader
6483 * @param {Object} meta Metadata configuration options.
6484 * @param {Object} recordType Either an Array of field definition objects
6485 * as specified to {@link Roo.data.Record#create},
6486 * or an {@link Roo.data.Record} object
6487 * created using {@link Roo.data.Record#create}.
6489 Roo.data.ArrayReader = function(meta, recordType){
6490 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
6493 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
6495 * Create a data block containing Roo.data.Records from an XML document.
6496 * @param {Object} o An Array of row objects which represents the dataset.
6497 * @return {Object} data A data block which is used by an Roo.data.Store object as
6498 * a cache of Roo.data.Records.
6500 readRecords : function(o){
6501 var sid = this.meta ? this.meta.id : null;
6502 var recordType = this.recordType, fields = recordType.prototype.fields;
6505 for(var i = 0; i < root.length; i++){
6508 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
6509 for(var j = 0, jlen = fields.length; j < jlen; j++){
6510 var f = fields.items[j];
6511 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
6512 var v = n[k] !== undefined ? n[k] : f.defaultValue;
6516 var record = new recordType(values, id);
6518 records[records.length] = record;
6522 totalRecords : records.length
6527 * Ext JS Library 1.1.1
6528 * Copyright(c) 2006-2007, Ext JS, LLC.
6530 * Originally Released Under LGPL - original licence link has changed is not relivant.
6533 * <script type="text/javascript">
6538 * @class Roo.data.Tree
6539 * @extends Roo.util.Observable
6540 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
6541 * in the tree have most standard DOM functionality.
6543 * @param {Node} root (optional) The root node
6545 Roo.data.Tree = function(root){
6548 * The root node for this tree
6553 this.setRootNode(root);
6558 * Fires when a new child node is appended to a node in this tree.
6559 * @param {Tree} tree The owner tree
6560 * @param {Node} parent The parent node
6561 * @param {Node} node The newly appended node
6562 * @param {Number} index The index of the newly appended node
6567 * Fires when a child node is removed from a node in this tree.
6568 * @param {Tree} tree The owner tree
6569 * @param {Node} parent The parent node
6570 * @param {Node} node The child node removed
6575 * Fires when a node is moved to a new location in the tree
6576 * @param {Tree} tree The owner tree
6577 * @param {Node} node The node moved
6578 * @param {Node} oldParent The old parent of this node
6579 * @param {Node} newParent The new parent of this node
6580 * @param {Number} index The index it was moved to
6585 * Fires when a new child node is inserted in a node in this tree.
6586 * @param {Tree} tree The owner tree
6587 * @param {Node} parent The parent node
6588 * @param {Node} node The child node inserted
6589 * @param {Node} refNode The child node the node was inserted before
6593 * @event beforeappend
6594 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
6595 * @param {Tree} tree The owner tree
6596 * @param {Node} parent The parent node
6597 * @param {Node} node The child node to be appended
6599 "beforeappend" : true,
6601 * @event beforeremove
6602 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
6603 * @param {Tree} tree The owner tree
6604 * @param {Node} parent The parent node
6605 * @param {Node} node The child node to be removed
6607 "beforeremove" : true,
6610 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
6611 * @param {Tree} tree The owner tree
6612 * @param {Node} node The node being moved
6613 * @param {Node} oldParent The parent of the node
6614 * @param {Node} newParent The new parent the node is moving to
6615 * @param {Number} index The index it is being moved to
6617 "beforemove" : true,
6619 * @event beforeinsert
6620 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
6621 * @param {Tree} tree The owner tree
6622 * @param {Node} parent The parent node
6623 * @param {Node} node The child node to be inserted
6624 * @param {Node} refNode The child node the node is being inserted before
6626 "beforeinsert" : true
6629 Roo.data.Tree.superclass.constructor.call(this);
6632 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
6635 proxyNodeEvent : function(){
6636 return this.fireEvent.apply(this, arguments);
6640 * Returns the root node for this tree.
6643 getRootNode : function(){
6648 * Sets the root node for this tree.
6649 * @param {Node} node
6652 setRootNode : function(node){
6654 node.ownerTree = this;
6656 this.registerNode(node);
6661 * Gets a node in this tree by its id.
6662 * @param {String} id
6665 getNodeById : function(id){
6666 return this.nodeHash[id];
6669 registerNode : function(node){
6670 this.nodeHash[node.id] = node;
6673 unregisterNode : function(node){
6674 delete this.nodeHash[node.id];
6677 toString : function(){
6678 return "[Tree"+(this.id?" "+this.id:"")+"]";
6683 * @class Roo.data.Node
6684 * @extends Roo.util.Observable
6685 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
6686 * @cfg {String} id The id for this node. If one is not specified, one is generated.
6688 * @param {Object} attributes The attributes/config for the node
6690 Roo.data.Node = function(attributes){
6692 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
6695 this.attributes = attributes || {};
6696 this.leaf = this.attributes.leaf;
6698 * The node id. @type String
6700 this.id = this.attributes.id;
6702 this.id = Roo.id(null, "ynode-");
6703 this.attributes.id = this.id;
6708 * All child nodes of this node. @type Array
6710 this.childNodes = [];
6711 if(!this.childNodes.indexOf){ // indexOf is a must
6712 this.childNodes.indexOf = function(o){
6713 for(var i = 0, len = this.length; i < len; i++){
6722 * The parent node for this node. @type Node
6724 this.parentNode = null;
6726 * The first direct child node of this node, or null if this node has no child nodes. @type Node
6728 this.firstChild = null;
6730 * The last direct child node of this node, or null if this node has no child nodes. @type Node
6732 this.lastChild = null;
6734 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
6736 this.previousSibling = null;
6738 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
6740 this.nextSibling = null;
6745 * Fires when a new child node is appended
6746 * @param {Tree} tree The owner tree
6747 * @param {Node} this This node
6748 * @param {Node} node The newly appended node
6749 * @param {Number} index The index of the newly appended node
6754 * Fires when a child node is removed
6755 * @param {Tree} tree The owner tree
6756 * @param {Node} this This node
6757 * @param {Node} node The removed node
6762 * Fires when this node is moved to a new location in the tree
6763 * @param {Tree} tree The owner tree
6764 * @param {Node} this This node
6765 * @param {Node} oldParent The old parent of this node
6766 * @param {Node} newParent The new parent of this node
6767 * @param {Number} index The index it was moved to
6772 * Fires when a new child node is inserted.
6773 * @param {Tree} tree The owner tree
6774 * @param {Node} this This node
6775 * @param {Node} node The child node inserted
6776 * @param {Node} refNode The child node the node was inserted before
6780 * @event beforeappend
6781 * Fires before a new child is appended, return false to cancel the append.
6782 * @param {Tree} tree The owner tree
6783 * @param {Node} this This node
6784 * @param {Node} node The child node to be appended
6786 "beforeappend" : true,
6788 * @event beforeremove
6789 * Fires before a child is removed, return false to cancel the remove.
6790 * @param {Tree} tree The owner tree
6791 * @param {Node} this This node
6792 * @param {Node} node The child node to be removed
6794 "beforeremove" : true,
6797 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
6798 * @param {Tree} tree The owner tree
6799 * @param {Node} this This node
6800 * @param {Node} oldParent The parent of this node
6801 * @param {Node} newParent The new parent this node is moving to
6802 * @param {Number} index The index it is being moved to
6804 "beforemove" : true,
6806 * @event beforeinsert
6807 * Fires before a new child is inserted, return false to cancel the insert.
6808 * @param {Tree} tree The owner tree
6809 * @param {Node} this This node
6810 * @param {Node} node The child node to be inserted
6811 * @param {Node} refNode The child node the node is being inserted before
6813 "beforeinsert" : true
6815 this.listeners = this.attributes.listeners;
6816 Roo.data.Node.superclass.constructor.call(this);
6819 Roo.extend(Roo.data.Node, Roo.util.Observable, {
6820 fireEvent : function(evtName){
6821 // first do standard event for this node
6822 if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
6825 // then bubble it up to the tree if the event wasn't cancelled
6826 var ot = this.getOwnerTree();
6828 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
6836 * Returns true if this node is a leaf
6839 isLeaf : function(){
6840 return this.leaf === true;
6844 setFirstChild : function(node){
6845 this.firstChild = node;
6849 setLastChild : function(node){
6850 this.lastChild = node;
6855 * Returns true if this node is the last child of its parent
6858 isLast : function(){
6859 return (!this.parentNode ? true : this.parentNode.lastChild == this);
6863 * Returns true if this node is the first child of its parent
6866 isFirst : function(){
6867 return (!this.parentNode ? true : this.parentNode.firstChild == this);
6870 hasChildNodes : function(){
6871 return !this.isLeaf() && this.childNodes.length > 0;
6875 * Insert node(s) as the last child node of this node.
6876 * @param {Node/Array} node The node or Array of nodes to append
6877 * @return {Node} The appended node if single append, or null if an array was passed
6879 appendChild : function(node){
6881 if(node instanceof Array){
6883 }else if(arguments.length > 1){
6886 // if passed an array or multiple args do them one by one
6888 for(var i = 0, len = multi.length; i < len; i++) {
6889 this.appendChild(multi[i]);
6892 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
6895 var index = this.childNodes.length;
6896 var oldParent = node.parentNode;
6897 // it's a move, make sure we move it cleanly
6899 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
6902 oldParent.removeChild(node);
6904 index = this.childNodes.length;
6906 this.setFirstChild(node);
6908 this.childNodes.push(node);
6909 node.parentNode = this;
6910 var ps = this.childNodes[index-1];
6912 node.previousSibling = ps;
6913 ps.nextSibling = node;
6915 node.previousSibling = null;
6917 node.nextSibling = null;
6918 this.setLastChild(node);
6919 node.setOwnerTree(this.getOwnerTree());
6920 this.fireEvent("append", this.ownerTree, this, node, index);
6922 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
6929 * Removes a child node from this node.
6930 * @param {Node} node The node to remove
6931 * @return {Node} The removed node
6933 removeChild : function(node){
6934 var index = this.childNodes.indexOf(node);
6938 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
6942 // remove it from childNodes collection
6943 this.childNodes.splice(index, 1);
6946 if(node.previousSibling){
6947 node.previousSibling.nextSibling = node.nextSibling;
6949 if(node.nextSibling){
6950 node.nextSibling.previousSibling = node.previousSibling;
6953 // update child refs
6954 if(this.firstChild == node){
6955 this.setFirstChild(node.nextSibling);
6957 if(this.lastChild == node){
6958 this.setLastChild(node.previousSibling);
6961 node.setOwnerTree(null);
6962 // clear any references from the node
6963 node.parentNode = null;
6964 node.previousSibling = null;
6965 node.nextSibling = null;
6966 this.fireEvent("remove", this.ownerTree, this, node);
6971 * Inserts the first node before the second node in this nodes childNodes collection.
6972 * @param {Node} node The node to insert
6973 * @param {Node} refNode The node to insert before (if null the node is appended)
6974 * @return {Node} The inserted node
6976 insertBefore : function(node, refNode){
6977 if(!refNode){ // like standard Dom, refNode can be null for append
6978 return this.appendChild(node);
6981 if(node == refNode){
6985 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
6988 var index = this.childNodes.indexOf(refNode);
6989 var oldParent = node.parentNode;
6990 var refIndex = index;
6992 // when moving internally, indexes will change after remove
6993 if(oldParent == this && this.childNodes.indexOf(node) < index){
6997 // it's a move, make sure we move it cleanly
6999 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
7002 oldParent.removeChild(node);
7005 this.setFirstChild(node);
7007 this.childNodes.splice(refIndex, 0, node);
7008 node.parentNode = this;
7009 var ps = this.childNodes[refIndex-1];
7011 node.previousSibling = ps;
7012 ps.nextSibling = node;
7014 node.previousSibling = null;
7016 node.nextSibling = refNode;
7017 refNode.previousSibling = node;
7018 node.setOwnerTree(this.getOwnerTree());
7019 this.fireEvent("insert", this.ownerTree, this, node, refNode);
7021 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
7027 * Returns the child node at the specified index.
7028 * @param {Number} index
7031 item : function(index){
7032 return this.childNodes[index];
7036 * Replaces one child node in this node with another.
7037 * @param {Node} newChild The replacement node
7038 * @param {Node} oldChild The node to replace
7039 * @return {Node} The replaced node
7041 replaceChild : function(newChild, oldChild){
7042 this.insertBefore(newChild, oldChild);
7043 this.removeChild(oldChild);
7048 * Returns the index of a child node
7049 * @param {Node} node
7050 * @return {Number} The index of the node or -1 if it was not found
7052 indexOf : function(child){
7053 return this.childNodes.indexOf(child);
7057 * Returns the tree this node is in.
7060 getOwnerTree : function(){
7061 // if it doesn't have one, look for one
7062 if(!this.ownerTree){
7066 this.ownerTree = p.ownerTree;
7072 return this.ownerTree;
7076 * Returns depth of this node (the root node has a depth of 0)
7079 getDepth : function(){
7082 while(p.parentNode){
7090 setOwnerTree : function(tree){
7091 // if it's move, we need to update everyone
7092 if(tree != this.ownerTree){
7094 this.ownerTree.unregisterNode(this);
7096 this.ownerTree = tree;
7097 var cs = this.childNodes;
7098 for(var i = 0, len = cs.length; i < len; i++) {
7099 cs[i].setOwnerTree(tree);
7102 tree.registerNode(this);
7108 * Returns the path for this node. The path can be used to expand or select this node programmatically.
7109 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
7110 * @return {String} The path
7112 getPath : function(attr){
7113 attr = attr || "id";
7114 var p = this.parentNode;
7115 var b = [this.attributes[attr]];
7117 b.unshift(p.attributes[attr]);
7120 var sep = this.getOwnerTree().pathSeparator;
7121 return sep + b.join(sep);
7125 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
7126 * function call will be the scope provided or the current node. The arguments to the function
7127 * will be the args provided or the current node. If the function returns false at any point,
7128 * the bubble is stopped.
7129 * @param {Function} fn The function to call
7130 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7131 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7133 bubble : function(fn, scope, args){
7136 if(fn.call(scope || p, args || p) === false){
7144 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
7145 * function call will be the scope provided or the current node. The arguments to the function
7146 * will be the args provided or the current node. If the function returns false at any point,
7147 * the cascade is stopped on that branch.
7148 * @param {Function} fn The function to call
7149 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7150 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7152 cascade : function(fn, scope, args){
7153 if(fn.call(scope || this, args || this) !== false){
7154 var cs = this.childNodes;
7155 for(var i = 0, len = cs.length; i < len; i++) {
7156 cs[i].cascade(fn, scope, args);
7162 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
7163 * function call will be the scope provided or the current node. The arguments to the function
7164 * will be the args provided or the current node. If the function returns false at any point,
7165 * the iteration stops.
7166 * @param {Function} fn The function to call
7167 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7168 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7170 eachChild : function(fn, scope, args){
7171 var cs = this.childNodes;
7172 for(var i = 0, len = cs.length; i < len; i++) {
7173 if(fn.call(scope || this, args || cs[i]) === false){
7180 * Finds the first child that has the attribute with the specified value.
7181 * @param {String} attribute The attribute name
7182 * @param {Mixed} value The value to search for
7183 * @return {Node} The found child or null if none was found
7185 findChild : function(attribute, value){
7186 var cs = this.childNodes;
7187 for(var i = 0, len = cs.length; i < len; i++) {
7188 if(cs[i].attributes[attribute] == value){
7196 * Finds the first child by a custom function. The child matches if the function passed
7198 * @param {Function} fn
7199 * @param {Object} scope (optional)
7200 * @return {Node} The found child or null if none was found
7202 findChildBy : function(fn, scope){
7203 var cs = this.childNodes;
7204 for(var i = 0, len = cs.length; i < len; i++) {
7205 if(fn.call(scope||cs[i], cs[i]) === true){
7213 * Sorts this nodes children using the supplied sort function
7214 * @param {Function} fn
7215 * @param {Object} scope (optional)
7217 sort : function(fn, scope){
7218 var cs = this.childNodes;
7219 var len = cs.length;
7221 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
7223 for(var i = 0; i < len; i++){
7225 n.previousSibling = cs[i-1];
7226 n.nextSibling = cs[i+1];
7228 this.setFirstChild(n);
7231 this.setLastChild(n);
7238 * Returns true if this node is an ancestor (at any point) of the passed node.
7239 * @param {Node} node
7242 contains : function(node){
7243 return node.isAncestor(this);
7247 * Returns true if the passed node is an ancestor (at any point) of this node.
7248 * @param {Node} node
7251 isAncestor : function(node){
7252 var p = this.parentNode;
7262 toString : function(){
7263 return "[Node"+(this.id?" "+this.id:"")+"]";
7267 * Ext JS Library 1.1.1
7268 * Copyright(c) 2006-2007, Ext JS, LLC.
7270 * Originally Released Under LGPL - original licence link has changed is not relivant.
7273 * <script type="text/javascript">
7278 * @class Roo.ComponentMgr
7279 * Provides a common registry of all components on a page so that they can be easily accessed by component id (see {@link Roo.getCmp}).
7282 Roo.ComponentMgr = function(){
7283 var all = new Roo.util.MixedCollection();
7287 * Registers a component.
7288 * @param {Roo.Component} c The component
7290 register : function(c){
7295 * Unregisters a component.
7296 * @param {Roo.Component} c The component
7298 unregister : function(c){
7303 * Returns a component by id
7304 * @param {String} id The component id
7311 * Registers a function that will be called when a specified component is added to ComponentMgr
7312 * @param {String} id The component id
7313 * @param {Funtction} fn The callback function
7314 * @param {Object} scope The scope of the callback
7316 onAvailable : function(id, fn, scope){
7317 all.on("add", function(index, o){
7319 fn.call(scope || o, o);
7320 all.un("add", fn, scope);
7327 * Ext JS Library 1.1.1
7328 * Copyright(c) 2006-2007, Ext JS, LLC.
7330 * Originally Released Under LGPL - original licence link has changed is not relivant.
7333 * <script type="text/javascript">
7337 * @class Roo.Component
7338 * @extends Roo.util.Observable
7339 * Base class for all major Roo components. All subclasses of Component can automatically participate in the standard
7340 * Roo component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show
7341 * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Roo.Container} and
7342 * to be automatically registered with the {@link Roo.ComponentMgr} so that it can be referenced at any time via {@link Roo.getCmp}.
7343 * All visual components (widgets) that require rendering into a layout should subclass Component.
7345 * @param {Roo.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
7346 * 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
7347 * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
7349 Roo.Component = function(config){
7350 config = config || {};
7351 if(config.tagName || config.dom || typeof config == "string"){ // element object
7352 config = {el: config, id: config.id || config};
7354 this.initialConfig = config;
7356 Roo.apply(this, config);
7360 * Fires after the component is disabled.
7361 * @param {Roo.Component} this
7366 * Fires after the component is enabled.
7367 * @param {Roo.Component} this
7372 * Fires before the component is shown. Return false to stop the show.
7373 * @param {Roo.Component} this
7378 * Fires after the component is shown.
7379 * @param {Roo.Component} this
7384 * Fires before the component is hidden. Return false to stop the hide.
7385 * @param {Roo.Component} this
7390 * Fires after the component is hidden.
7391 * @param {Roo.Component} this
7395 * @event beforerender
7396 * Fires before the component is rendered. Return false to stop the render.
7397 * @param {Roo.Component} this
7399 beforerender : true,
7402 * Fires after the component is rendered.
7403 * @param {Roo.Component} this
7407 * @event beforedestroy
7408 * Fires before the component is destroyed. Return false to stop the destroy.
7409 * @param {Roo.Component} this
7411 beforedestroy : true,
7414 * Fires after the component is destroyed.
7415 * @param {Roo.Component} this
7420 this.id = "ext-comp-" + (++Roo.Component.AUTO_ID);
7422 Roo.ComponentMgr.register(this);
7423 Roo.Component.superclass.constructor.call(this);
7424 this.initComponent();
7425 if(this.renderTo){ // not supported by all components yet. use at your own risk!
7426 this.render(this.renderTo);
7427 delete this.renderTo;
7432 Roo.Component.AUTO_ID = 1000;
7434 Roo.extend(Roo.Component, Roo.util.Observable, {
7436 * @scope Roo.Component.prototype
7438 * true if this component is hidden. Read-only.
7443 * true if this component is disabled. Read-only.
7448 * true if this component has been rendered. Read-only.
7452 /** @cfg {String} disableClass
7453 * CSS class added to the component when it is disabled (defaults to "x-item-disabled").
7455 disabledClass : "x-item-disabled",
7456 /** @cfg {Boolean} allowDomMove
7457 * Whether the component can move the Dom node when rendering (defaults to true).
7459 allowDomMove : true,
7460 /** @cfg {String} hideMode
7461 * How this component should hidden. Supported values are
7462 * "visibility" (css visibility), "offsets" (negative offset position) and
7463 * "display" (css display) - defaults to "display".
7465 hideMode: 'display',
7468 ctype : "Roo.Component",
7471 * @cfg {String} actionMode
7472 * which property holds the element that used for hide() / show() / disable() / enable()
7478 getActionEl : function(){
7479 return this[this.actionMode];
7482 initComponent : Roo.emptyFn,
7484 * If this is a lazy rendering component, render it to its container element.
7485 * @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.
7487 render : function(container, position){
7488 if(!this.rendered && this.fireEvent("beforerender", this) !== false){
7489 if(!container && this.el){
7490 this.el = Roo.get(this.el);
7491 container = this.el.dom.parentNode;
7492 this.allowDomMove = false;
7494 this.container = Roo.get(container);
7495 this.rendered = true;
7496 if(position !== undefined){
7497 if(typeof position == 'number'){
7498 position = this.container.dom.childNodes[position];
7500 position = Roo.getDom(position);
7503 this.onRender(this.container, position || null);
7505 this.el.addClass(this.cls);
7509 this.el.applyStyles(this.style);
7512 this.fireEvent("render", this);
7513 this.afterRender(this.container);
7525 // default function is not really useful
7526 onRender : function(ct, position){
7528 this.el = Roo.get(this.el);
7529 if(this.allowDomMove !== false){
7530 ct.dom.insertBefore(this.el.dom, position);
7536 getAutoCreate : function(){
7537 var cfg = typeof this.autoCreate == "object" ?
7538 this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
7539 if(this.id && !cfg.id){
7546 afterRender : Roo.emptyFn,
7549 * Destroys this component by purging any event listeners, removing the component's element from the DOM,
7550 * removing the component from its {@link Roo.Container} (if applicable) and unregistering it from {@link Roo.ComponentMgr}.
7552 destroy : function(){
7553 if(this.fireEvent("beforedestroy", this) !== false){
7554 this.purgeListeners();
7555 this.beforeDestroy();
7557 this.el.removeAllListeners();
7559 if(this.actionMode == "container"){
7560 this.container.remove();
7564 Roo.ComponentMgr.unregister(this);
7565 this.fireEvent("destroy", this);
7570 beforeDestroy : function(){
7575 onDestroy : function(){
7580 * Returns the underlying {@link Roo.Element}.
7581 * @return {Roo.Element} The element
7588 * Returns the id of this component.
7596 * Try to focus this component.
7597 * @param {Boolean} selectText True to also select the text in this component (if applicable)
7598 * @return {Roo.Component} this
7600 focus : function(selectText){
7603 if(selectText === true){
7604 this.el.dom.select();
7619 * Disable this component.
7620 * @return {Roo.Component} this
7622 disable : function(){
7626 this.disabled = true;
7627 this.fireEvent("disable", this);
7632 onDisable : function(){
7633 this.getActionEl().addClass(this.disabledClass);
7634 this.el.dom.disabled = true;
7638 * Enable this component.
7639 * @return {Roo.Component} this
7641 enable : function(){
7645 this.disabled = false;
7646 this.fireEvent("enable", this);
7651 onEnable : function(){
7652 this.getActionEl().removeClass(this.disabledClass);
7653 this.el.dom.disabled = false;
7657 * Convenience function for setting disabled/enabled by boolean.
7658 * @param {Boolean} disabled
7660 setDisabled : function(disabled){
7661 this[disabled ? "disable" : "enable"]();
7665 * Show this component.
7666 * @return {Roo.Component} this
7669 if(this.fireEvent("beforeshow", this) !== false){
7670 this.hidden = false;
7674 this.fireEvent("show", this);
7680 onShow : function(){
7681 var ae = this.getActionEl();
7682 if(this.hideMode == 'visibility'){
7683 ae.dom.style.visibility = "visible";
7684 }else if(this.hideMode == 'offsets'){
7685 ae.removeClass('x-hidden');
7687 ae.dom.style.display = "";
7692 * Hide this component.
7693 * @return {Roo.Component} this
7696 if(this.fireEvent("beforehide", this) !== false){
7701 this.fireEvent("hide", this);
7707 onHide : function(){
7708 var ae = this.getActionEl();
7709 if(this.hideMode == 'visibility'){
7710 ae.dom.style.visibility = "hidden";
7711 }else if(this.hideMode == 'offsets'){
7712 ae.addClass('x-hidden');
7714 ae.dom.style.display = "none";
7719 * Convenience function to hide or show this component by boolean.
7720 * @param {Boolean} visible True to show, false to hide
7721 * @return {Roo.Component} this
7723 setVisible: function(visible){
7733 * Returns true if this component is visible.
7735 isVisible : function(){
7736 return this.getActionEl().isVisible();
7739 cloneConfig : function(overrides){
7740 overrides = overrides || {};
7741 var id = overrides.id || Roo.id();
7742 var cfg = Roo.applyIf(overrides, this.initialConfig);
7743 cfg.id = id; // prevent dup id
7744 return new this.constructor(cfg);
7748 * Ext JS Library 1.1.1
7749 * Copyright(c) 2006-2007, Ext JS, LLC.
7751 * Originally Released Under LGPL - original licence link has changed is not relivant.
7754 * <script type="text/javascript">
7759 * @extends Roo.Element
7760 * An extended {@link Roo.Element} object that supports a shadow and shim, constrain to viewport and
7761 * automatic maintaining of shadow/shim positions.
7762 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
7763 * @cfg {String/Boolean} shadow True to create a shadow element with default class "x-layer-shadow", or
7764 * you can pass a string with a CSS class name. False turns off the shadow.
7765 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: "div", cls: "x-layer"}).
7766 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
7767 * @cfg {String} cls CSS class to add to the element
7768 * @cfg {Number} zindex Starting z-index (defaults to 11000)
7769 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 3)
7771 * @param {Object} config An object with config options.
7772 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
7775 Roo.Layer = function(config, existingEl){
7776 config = config || {};
7777 var dh = Roo.DomHelper;
7778 var cp = config.parentEl, pel = cp ? Roo.getDom(cp) : document.body;
7780 this.dom = Roo.getDom(existingEl);
7783 var o = config.dh || {tag: "div", cls: "x-layer"};
7784 this.dom = dh.append(pel, o);
7787 this.addClass(config.cls);
7789 this.constrain = config.constrain !== false;
7790 this.visibilityMode = Roo.Element.VISIBILITY;
7792 this.id = this.dom.id = config.id;
7794 this.id = Roo.id(this.dom);
7796 this.zindex = config.zindex || this.getZIndex();
7797 this.position("absolute", this.zindex);
7799 this.shadowOffset = config.shadowOffset || 4;
7800 this.shadow = new Roo.Shadow({
7801 offset : this.shadowOffset,
7802 mode : config.shadow
7805 this.shadowOffset = 0;
7807 this.useShim = config.shim !== false && Roo.useShims;
7808 this.useDisplay = config.useDisplay;
7812 var supr = Roo.Element.prototype;
7814 // shims are shared among layer to keep from having 100 iframes
7817 Roo.extend(Roo.Layer, Roo.Element, {
7819 getZIndex : function(){
7820 return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
7823 getShim : function(){
7830 var shim = shims.shift();
7832 shim = this.createShim();
7833 shim.enableDisplayMode('block');
7834 shim.dom.style.display = 'none';
7835 shim.dom.style.visibility = 'visible';
7837 var pn = this.dom.parentNode;
7838 if(shim.dom.parentNode != pn){
7839 pn.insertBefore(shim.dom, this.dom);
7841 shim.setStyle('z-index', this.getZIndex()-2);
7846 hideShim : function(){
7848 this.shim.setDisplayed(false);
7849 shims.push(this.shim);
7854 disableShadow : function(){
7856 this.shadowDisabled = true;
7858 this.lastShadowOffset = this.shadowOffset;
7859 this.shadowOffset = 0;
7863 enableShadow : function(show){
7865 this.shadowDisabled = false;
7866 this.shadowOffset = this.lastShadowOffset;
7867 delete this.lastShadowOffset;
7875 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
7876 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
7877 sync : function(doShow){
7878 var sw = this.shadow;
7879 if(!this.updating && this.isVisible() && (sw || this.useShim)){
7880 var sh = this.getShim();
7882 var w = this.getWidth(),
7883 h = this.getHeight();
7885 var l = this.getLeft(true),
7886 t = this.getTop(true);
7888 if(sw && !this.shadowDisabled){
7889 if(doShow && !sw.isVisible()){
7892 sw.realign(l, t, w, h);
7898 // fit the shim behind the shadow, so it is shimmed too
7899 var a = sw.adjusts, s = sh.dom.style;
7900 s.left = (Math.min(l, l+a.l))+"px";
7901 s.top = (Math.min(t, t+a.t))+"px";
7902 s.width = (w+a.w)+"px";
7903 s.height = (h+a.h)+"px";
7910 sh.setLeftTop(l, t);
7917 destroy : function(){
7922 this.removeAllListeners();
7923 var pn = this.dom.parentNode;
7925 pn.removeChild(this.dom);
7927 Roo.Element.uncache(this.id);
7930 remove : function(){
7935 beginUpdate : function(){
7936 this.updating = true;
7940 endUpdate : function(){
7941 this.updating = false;
7946 hideUnders : function(negOffset){
7954 constrainXY : function(){
7956 var vw = Roo.lib.Dom.getViewWidth(),
7957 vh = Roo.lib.Dom.getViewHeight();
7958 var s = Roo.get(document).getScroll();
7960 var xy = this.getXY();
7961 var x = xy[0], y = xy[1];
7962 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
7963 // only move it if it needs it
7965 // first validate right/bottom
7966 if((x + w) > vw+s.left){
7967 x = vw - w - this.shadowOffset;
7970 if((y + h) > vh+s.top){
7971 y = vh - h - this.shadowOffset;
7974 // then make sure top/left isn't negative
7985 var ay = this.avoidY;
7986 if(y <= ay && (y+h) >= ay){
7992 supr.setXY.call(this, xy);
7998 isVisible : function(){
7999 return this.visible;
8003 showAction : function(){
8004 this.visible = true; // track visibility to prevent getStyle calls
8005 if(this.useDisplay === true){
8006 this.setDisplayed("");
8007 }else if(this.lastXY){
8008 supr.setXY.call(this, this.lastXY);
8009 }else if(this.lastLT){
8010 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
8015 hideAction : function(){
8016 this.visible = false;
8017 if(this.useDisplay === true){
8018 this.setDisplayed(false);
8020 this.setLeftTop(-10000,-10000);
8024 // overridden Element method
8025 setVisible : function(v, a, d, c, e){
8030 var cb = function(){
8035 }.createDelegate(this);
8036 supr.setVisible.call(this, true, true, d, cb, e);
8039 this.hideUnders(true);
8048 }.createDelegate(this);
8050 supr.setVisible.call(this, v, a, d, cb, e);
8059 storeXY : function(xy){
8064 storeLeftTop : function(left, top){
8066 this.lastLT = [left, top];
8070 beforeFx : function(){
8071 this.beforeAction();
8072 return Roo.Layer.superclass.beforeFx.apply(this, arguments);
8076 afterFx : function(){
8077 Roo.Layer.superclass.afterFx.apply(this, arguments);
8078 this.sync(this.isVisible());
8082 beforeAction : function(){
8083 if(!this.updating && this.shadow){
8088 // overridden Element method
8089 setLeft : function(left){
8090 this.storeLeftTop(left, this.getTop(true));
8091 supr.setLeft.apply(this, arguments);
8095 setTop : function(top){
8096 this.storeLeftTop(this.getLeft(true), top);
8097 supr.setTop.apply(this, arguments);
8101 setLeftTop : function(left, top){
8102 this.storeLeftTop(left, top);
8103 supr.setLeftTop.apply(this, arguments);
8107 setXY : function(xy, a, d, c, e){
8109 this.beforeAction();
8111 var cb = this.createCB(c);
8112 supr.setXY.call(this, xy, a, d, cb, e);
8119 createCB : function(c){
8130 // overridden Element method
8131 setX : function(x, a, d, c, e){
8132 this.setXY([x, this.getY()], a, d, c, e);
8135 // overridden Element method
8136 setY : function(y, a, d, c, e){
8137 this.setXY([this.getX(), y], a, d, c, e);
8140 // overridden Element method
8141 setSize : function(w, h, a, d, c, e){
8142 this.beforeAction();
8143 var cb = this.createCB(c);
8144 supr.setSize.call(this, w, h, a, d, cb, e);
8150 // overridden Element method
8151 setWidth : function(w, a, d, c, e){
8152 this.beforeAction();
8153 var cb = this.createCB(c);
8154 supr.setWidth.call(this, w, a, d, cb, e);
8160 // overridden Element method
8161 setHeight : function(h, a, d, c, e){
8162 this.beforeAction();
8163 var cb = this.createCB(c);
8164 supr.setHeight.call(this, h, a, d, cb, e);
8170 // overridden Element method
8171 setBounds : function(x, y, w, h, a, d, c, e){
8172 this.beforeAction();
8173 var cb = this.createCB(c);
8175 this.storeXY([x, y]);
8176 supr.setXY.call(this, [x, y]);
8177 supr.setSize.call(this, w, h, a, d, cb, e);
8180 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
8186 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
8187 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
8188 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
8189 * @param {Number} zindex The new z-index to set
8190 * @return {this} The Layer
8192 setZIndex : function(zindex){
8193 this.zindex = zindex;
8194 this.setStyle("z-index", zindex + 2);
8196 this.shadow.setZIndex(zindex + 1);
8199 this.shim.setStyle("z-index", zindex);
8205 * Ext JS Library 1.1.1
8206 * Copyright(c) 2006-2007, Ext JS, LLC.
8208 * Originally Released Under LGPL - original licence link has changed is not relivant.
8211 * <script type="text/javascript">
8217 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
8218 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
8219 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
8221 * Create a new Shadow
8222 * @param {Object} config The config object
8224 Roo.Shadow = function(config){
8225 Roo.apply(this, config);
8226 if(typeof this.mode != "string"){
8227 this.mode = this.defaultMode;
8229 var o = this.offset, a = {h: 0};
8230 var rad = Math.floor(this.offset/2);
8231 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
8237 a.l -= this.offset + rad;
8238 a.t -= this.offset + rad;
8249 a.l -= (this.offset - rad);
8250 a.t -= this.offset + rad;
8252 a.w -= (this.offset - rad)*2;
8263 a.l -= (this.offset - rad);
8264 a.t -= (this.offset - rad);
8266 a.w -= (this.offset + rad + 1);
8267 a.h -= (this.offset + rad);
8276 Roo.Shadow.prototype = {
8278 * @cfg {String} mode
8279 * The shadow display mode. Supports the following options:<br />
8280 * sides: Shadow displays on both sides and bottom only<br />
8281 * frame: Shadow displays equally on all four sides<br />
8282 * drop: Traditional bottom-right drop shadow (default)
8285 * @cfg {String} offset
8286 * The number of pixels to offset the shadow from the element (defaults to 4)
8291 defaultMode: "drop",
8294 * Displays the shadow under the target element
8295 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
8297 show : function(target){
8298 target = Roo.get(target);
8300 this.el = Roo.Shadow.Pool.pull();
8301 if(this.el.dom.nextSibling != target.dom){
8302 this.el.insertBefore(target);
8305 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
8307 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
8310 target.getLeft(true),
8311 target.getTop(true),
8315 this.el.dom.style.display = "block";
8319 * Returns true if the shadow is visible, else false
8321 isVisible : function(){
8322 return this.el ? true : false;
8326 * Direct alignment when values are already available. Show must be called at least once before
8327 * calling this method to ensure it is initialized.
8328 * @param {Number} left The target element left position
8329 * @param {Number} top The target element top position
8330 * @param {Number} width The target element width
8331 * @param {Number} height The target element height
8333 realign : function(l, t, w, h){
8337 var a = this.adjusts, d = this.el.dom, s = d.style;
8339 s.left = (l+a.l)+"px";
8340 s.top = (t+a.t)+"px";
8341 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
8343 if(s.width != sws || s.height != shs){
8347 var cn = d.childNodes;
8348 var sww = Math.max(0, (sw-12))+"px";
8349 cn[0].childNodes[1].style.width = sww;
8350 cn[1].childNodes[1].style.width = sww;
8351 cn[2].childNodes[1].style.width = sww;
8352 cn[1].style.height = Math.max(0, (sh-12))+"px";
8362 this.el.dom.style.display = "none";
8363 Roo.Shadow.Pool.push(this.el);
8369 * Adjust the z-index of this shadow
8370 * @param {Number} zindex The new z-index
8372 setZIndex : function(z){
8375 this.el.setStyle("z-index", z);
8380 // Private utility class that manages the internal Shadow cache
8381 Roo.Shadow.Pool = function(){
8383 var markup = Roo.isIE ?
8384 '<div class="x-ie-shadow"></div>' :
8385 '<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>';
8390 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
8391 sh.autoBoxAdjust = false;
8396 push : function(sh){
8402 * Ext JS Library 1.1.1
8403 * Copyright(c) 2006-2007, Ext JS, LLC.
8405 * Originally Released Under LGPL - original licence link has changed is not relivant.
8408 * <script type="text/javascript">
8412 * @class Roo.BoxComponent
8413 * @extends Roo.Component
8414 * Base class for any visual {@link Roo.Component} that uses a box container. BoxComponent provides automatic box
8415 * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model. All
8416 * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext
8417 * layout containers.
8419 * @param {Roo.Element/String/Object} config The configuration options.
8421 Roo.BoxComponent = function(config){
8422 Roo.Component.call(this, config);
8426 * Fires after the component is resized.
8427 * @param {Roo.Component} this
8428 * @param {Number} adjWidth The box-adjusted width that was set
8429 * @param {Number} adjHeight The box-adjusted height that was set
8430 * @param {Number} rawWidth The width that was originally specified
8431 * @param {Number} rawHeight The height that was originally specified
8436 * Fires after the component is moved.
8437 * @param {Roo.Component} this
8438 * @param {Number} x The new x position
8439 * @param {Number} y The new y position
8445 Roo.extend(Roo.BoxComponent, Roo.Component, {
8446 // private, set in afterRender to signify that the component has been rendered
8448 // private, used to defer height settings to subclasses
8450 /** @cfg {Number} width
8451 * width (optional) size of component
8453 /** @cfg {Number} height
8454 * height (optional) size of component
8458 * Sets the width and height of the component. This method fires the resize event. This method can accept
8459 * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.
8460 * @param {Number/Object} width The new width to set, or a size object in the format {width, height}
8461 * @param {Number} height The new height to set (not required if a size object is passed as the first arg)
8462 * @return {Roo.BoxComponent} this
8464 setSize : function(w, h){
8465 // support for standard size objects
8466 if(typeof w == 'object'){
8477 // prevent recalcs when not needed
8478 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
8481 this.lastSize = {width: w, height: h};
8483 var adj = this.adjustSize(w, h);
8484 var aw = adj.width, ah = adj.height;
8485 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
8486 var rz = this.getResizeEl();
8487 if(!this.deferHeight && aw !== undefined && ah !== undefined){
8489 }else if(!this.deferHeight && ah !== undefined){
8491 }else if(aw !== undefined){
8494 this.onResize(aw, ah, w, h);
8495 this.fireEvent('resize', this, aw, ah, w, h);
8501 * Gets the current size of the component's underlying element.
8502 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
8504 getSize : function(){
8505 return this.el.getSize();
8509 * Gets the current XY position of the component's underlying element.
8510 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
8511 * @return {Array} The XY position of the element (e.g., [100, 200])
8513 getPosition : function(local){
8515 return [this.el.getLeft(true), this.el.getTop(true)];
8517 return this.xy || this.el.getXY();
8521 * Gets the current box measurements of the component's underlying element.
8522 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
8523 * @returns {Object} box An object in the format {x, y, width, height}
8525 getBox : function(local){
8526 var s = this.el.getSize();
8528 s.x = this.el.getLeft(true);
8529 s.y = this.el.getTop(true);
8531 var xy = this.xy || this.el.getXY();
8539 * Sets the current box measurements of the component's underlying element.
8540 * @param {Object} box An object in the format {x, y, width, height}
8541 * @returns {Roo.BoxComponent} this
8543 updateBox : function(box){
8544 this.setSize(box.width, box.height);
8545 this.setPagePosition(box.x, box.y);
8550 getResizeEl : function(){
8551 return this.resizeEl || this.el;
8555 getPositionEl : function(){
8556 return this.positionEl || this.el;
8560 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
8561 * This method fires the move event.
8562 * @param {Number} left The new left
8563 * @param {Number} top The new top
8564 * @returns {Roo.BoxComponent} this
8566 setPosition : function(x, y){
8572 var adj = this.adjustPosition(x, y);
8573 var ax = adj.x, ay = adj.y;
8575 var el = this.getPositionEl();
8576 if(ax !== undefined || ay !== undefined){
8577 if(ax !== undefined && ay !== undefined){
8578 el.setLeftTop(ax, ay);
8579 }else if(ax !== undefined){
8581 }else if(ay !== undefined){
8584 this.onPosition(ax, ay);
8585 this.fireEvent('move', this, ax, ay);
8591 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
8592 * This method fires the move event.
8593 * @param {Number} x The new x position
8594 * @param {Number} y The new y position
8595 * @returns {Roo.BoxComponent} this
8597 setPagePosition : function(x, y){
8603 if(x === undefined || y === undefined){ // cannot translate undefined points
8606 var p = this.el.translatePoints(x, y);
8607 this.setPosition(p.left, p.top);
8612 onRender : function(ct, position){
8613 Roo.BoxComponent.superclass.onRender.call(this, ct, position);
8615 this.resizeEl = Roo.get(this.resizeEl);
8617 if(this.positionEl){
8618 this.positionEl = Roo.get(this.positionEl);
8623 afterRender : function(){
8624 Roo.BoxComponent.superclass.afterRender.call(this);
8625 this.boxReady = true;
8626 this.setSize(this.width, this.height);
8627 if(this.x || this.y){
8628 this.setPosition(this.x, this.y);
8630 if(this.pageX || this.pageY){
8631 this.setPagePosition(this.pageX, this.pageY);
8636 * Force the component's size to recalculate based on the underlying element's current height and width.
8637 * @returns {Roo.BoxComponent} this
8639 syncSize : function(){
8640 delete this.lastSize;
8641 this.setSize(this.el.getWidth(), this.el.getHeight());
8646 * Called after the component is resized, this method is empty by default but can be implemented by any
8647 * subclass that needs to perform custom logic after a resize occurs.
8648 * @param {Number} adjWidth The box-adjusted width that was set
8649 * @param {Number} adjHeight The box-adjusted height that was set
8650 * @param {Number} rawWidth The width that was originally specified
8651 * @param {Number} rawHeight The height that was originally specified
8653 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
8658 * Called after the component is moved, this method is empty by default but can be implemented by any
8659 * subclass that needs to perform custom logic after a move occurs.
8660 * @param {Number} x The new x position
8661 * @param {Number} y The new y position
8663 onPosition : function(x, y){
8668 adjustSize : function(w, h){
8672 if(this.autoHeight){
8675 return {width : w, height: h};
8679 adjustPosition : function(x, y){
8680 return {x : x, y: y};
8684 * Ext JS Library 1.1.1
8685 * Copyright(c) 2006-2007, Ext JS, LLC.
8687 * Originally Released Under LGPL - original licence link has changed is not relivant.
8690 * <script type="text/javascript">
8695 * @class Roo.SplitBar
8696 * @extends Roo.util.Observable
8697 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
8701 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
8702 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
8703 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
8704 split.minSize = 100;
8705 split.maxSize = 600;
8706 split.animate = true;
8707 split.on('moved', splitterMoved);
8710 * Create a new SplitBar
8711 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
8712 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
8713 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
8714 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
8715 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
8716 position of the SplitBar).
8718 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
8721 this.el = Roo.get(dragElement, true);
8722 this.el.dom.unselectable = "on";
8724 this.resizingEl = Roo.get(resizingElement, true);
8728 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
8729 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
8732 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
8735 * The minimum size of the resizing element. (Defaults to 0)
8741 * The maximum size of the resizing element. (Defaults to 2000)
8744 this.maxSize = 2000;
8747 * Whether to animate the transition to the new size
8750 this.animate = false;
8753 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
8756 this.useShim = false;
8763 this.proxy = Roo.SplitBar.createProxy(this.orientation);
8765 this.proxy = Roo.get(existingProxy).dom;
8768 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
8771 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
8774 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
8777 this.dragSpecs = {};
8780 * @private The adapter to use to positon and resize elements
8782 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
8783 this.adapter.init(this);
8785 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8787 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
8788 this.el.addClass("x-splitbar-h");
8791 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
8792 this.el.addClass("x-splitbar-v");
8798 * Fires when the splitter is moved (alias for {@link #event-moved})
8799 * @param {Roo.SplitBar} this
8800 * @param {Number} newSize the new width or height
8805 * Fires when the splitter is moved
8806 * @param {Roo.SplitBar} this
8807 * @param {Number} newSize the new width or height
8811 * @event beforeresize
8812 * Fires before the splitter is dragged
8813 * @param {Roo.SplitBar} this
8815 "beforeresize" : true,
8817 "beforeapply" : true
8820 Roo.util.Observable.call(this);
8823 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
8824 onStartProxyDrag : function(x, y){
8825 this.fireEvent("beforeresize", this);
8827 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
8829 o.enableDisplayMode("block");
8830 // all splitbars share the same overlay
8831 Roo.SplitBar.prototype.overlay = o;
8833 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
8834 this.overlay.show();
8835 Roo.get(this.proxy).setDisplayed("block");
8836 var size = this.adapter.getElementSize(this);
8837 this.activeMinSize = this.getMinimumSize();;
8838 this.activeMaxSize = this.getMaximumSize();;
8839 var c1 = size - this.activeMinSize;
8840 var c2 = Math.max(this.activeMaxSize - size, 0);
8841 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8842 this.dd.resetConstraints();
8843 this.dd.setXConstraint(
8844 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
8845 this.placement == Roo.SplitBar.LEFT ? c2 : c1
8847 this.dd.setYConstraint(0, 0);
8849 this.dd.resetConstraints();
8850 this.dd.setXConstraint(0, 0);
8851 this.dd.setYConstraint(
8852 this.placement == Roo.SplitBar.TOP ? c1 : c2,
8853 this.placement == Roo.SplitBar.TOP ? c2 : c1
8856 this.dragSpecs.startSize = size;
8857 this.dragSpecs.startPoint = [x, y];
8858 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
8862 * @private Called after the drag operation by the DDProxy
8864 onEndProxyDrag : function(e){
8865 Roo.get(this.proxy).setDisplayed(false);
8866 var endPoint = Roo.lib.Event.getXY(e);
8868 this.overlay.hide();
8871 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8872 newSize = this.dragSpecs.startSize +
8873 (this.placement == Roo.SplitBar.LEFT ?
8874 endPoint[0] - this.dragSpecs.startPoint[0] :
8875 this.dragSpecs.startPoint[0] - endPoint[0]
8878 newSize = this.dragSpecs.startSize +
8879 (this.placement == Roo.SplitBar.TOP ?
8880 endPoint[1] - this.dragSpecs.startPoint[1] :
8881 this.dragSpecs.startPoint[1] - endPoint[1]
8884 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
8885 if(newSize != this.dragSpecs.startSize){
8886 if(this.fireEvent('beforeapply', this, newSize) !== false){
8887 this.adapter.setElementSize(this, newSize);
8888 this.fireEvent("moved", this, newSize);
8889 this.fireEvent("resize", this, newSize);
8895 * Get the adapter this SplitBar uses
8896 * @return The adapter object
8898 getAdapter : function(){
8899 return this.adapter;
8903 * Set the adapter this SplitBar uses
8904 * @param {Object} adapter A SplitBar adapter object
8906 setAdapter : function(adapter){
8907 this.adapter = adapter;
8908 this.adapter.init(this);
8912 * Gets the minimum size for the resizing element
8913 * @return {Number} The minimum size
8915 getMinimumSize : function(){
8916 return this.minSize;
8920 * Sets the minimum size for the resizing element
8921 * @param {Number} minSize The minimum size
8923 setMinimumSize : function(minSize){
8924 this.minSize = minSize;
8928 * Gets the maximum size for the resizing element
8929 * @return {Number} The maximum size
8931 getMaximumSize : function(){
8932 return this.maxSize;
8936 * Sets the maximum size for the resizing element
8937 * @param {Number} maxSize The maximum size
8939 setMaximumSize : function(maxSize){
8940 this.maxSize = maxSize;
8944 * Sets the initialize size for the resizing element
8945 * @param {Number} size The initial size
8947 setCurrentSize : function(size){
8948 var oldAnimate = this.animate;
8949 this.animate = false;
8950 this.adapter.setElementSize(this, size);
8951 this.animate = oldAnimate;
8955 * Destroy this splitbar.
8956 * @param {Boolean} removeEl True to remove the element
8958 destroy : function(removeEl){
8963 this.proxy.parentNode.removeChild(this.proxy);
8971 * @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.
8973 Roo.SplitBar.createProxy = function(dir){
8974 var proxy = new Roo.Element(document.createElement("div"));
8975 proxy.unselectable();
8976 var cls = 'x-splitbar-proxy';
8977 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
8978 document.body.appendChild(proxy.dom);
8983 * @class Roo.SplitBar.BasicLayoutAdapter
8984 * Default Adapter. It assumes the splitter and resizing element are not positioned
8985 * elements and only gets/sets the width of the element. Generally used for table based layouts.
8987 Roo.SplitBar.BasicLayoutAdapter = function(){
8990 Roo.SplitBar.BasicLayoutAdapter.prototype = {
8991 // do nothing for now
8996 * Called before drag operations to get the current size of the resizing element.
8997 * @param {Roo.SplitBar} s The SplitBar using this adapter
8999 getElementSize : function(s){
9000 if(s.orientation == Roo.SplitBar.HORIZONTAL){
9001 return s.resizingEl.getWidth();
9003 return s.resizingEl.getHeight();
9008 * Called after drag operations to set the size of the resizing element.
9009 * @param {Roo.SplitBar} s The SplitBar using this adapter
9010 * @param {Number} newSize The new size to set
9011 * @param {Function} onComplete A function to be invoked when resizing is complete
9013 setElementSize : function(s, newSize, onComplete){
9014 if(s.orientation == Roo.SplitBar.HORIZONTAL){
9016 s.resizingEl.setWidth(newSize);
9018 onComplete(s, newSize);
9021 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
9026 s.resizingEl.setHeight(newSize);
9028 onComplete(s, newSize);
9031 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
9038 *@class Roo.SplitBar.AbsoluteLayoutAdapter
9039 * @extends Roo.SplitBar.BasicLayoutAdapter
9040 * Adapter that moves the splitter element to align with the resized sizing element.
9041 * Used with an absolute positioned SplitBar.
9042 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
9043 * document.body, make sure you assign an id to the body element.
9045 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
9046 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
9047 this.container = Roo.get(container);
9050 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
9055 getElementSize : function(s){
9056 return this.basic.getElementSize(s);
9059 setElementSize : function(s, newSize, onComplete){
9060 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
9063 moveSplitter : function(s){
9064 var yes = Roo.SplitBar;
9065 switch(s.placement){
9067 s.el.setX(s.resizingEl.getRight());
9070 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
9073 s.el.setY(s.resizingEl.getBottom());
9076 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
9083 * Orientation constant - Create a vertical SplitBar
9087 Roo.SplitBar.VERTICAL = 1;
9090 * Orientation constant - Create a horizontal SplitBar
9094 Roo.SplitBar.HORIZONTAL = 2;
9097 * Placement constant - The resizing element is to the left of the splitter element
9101 Roo.SplitBar.LEFT = 1;
9104 * Placement constant - The resizing element is to the right of the splitter element
9108 Roo.SplitBar.RIGHT = 2;
9111 * Placement constant - The resizing element is positioned above the splitter element
9115 Roo.SplitBar.TOP = 3;
9118 * Placement constant - The resizing element is positioned under splitter element
9122 Roo.SplitBar.BOTTOM = 4;
9125 * Ext JS Library 1.1.1
9126 * Copyright(c) 2006-2007, Ext JS, LLC.
9128 * Originally Released Under LGPL - original licence link has changed is not relivant.
9131 * <script type="text/javascript">
9136 * @extends Roo.util.Observable
9137 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
9138 * This class also supports single and multi selection modes. <br>
9139 * Create a data model bound view:
9141 var store = new Roo.data.Store(...);
9143 var view = new Roo.View({
9145 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
9148 selectedClass: "ydataview-selected",
9152 // listen for node click?
9153 view.on("click", function(vw, index, node, e){
9154 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
9158 dataModel.load("foobar.xml");
9160 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
9162 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
9163 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
9165 * Note: old style constructor is still suported (container, template, config)
9169 * @param {Object} config The config object
9172 Roo.View = function(config, depreciated_tpl, depreciated_config){
9174 if (typeof(depreciated_tpl) == 'undefined') {
9175 // new way.. - universal constructor.
9176 Roo.apply(this, config);
9177 this.el = Roo.get(this.el);
9180 this.el = Roo.get(config);
9181 this.tpl = depreciated_tpl;
9182 Roo.apply(this, depreciated_config);
9184 this.wrapEl = this.el.wrap().wrap();
9185 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
9188 if(typeof(this.tpl) == "string"){
9189 this.tpl = new Roo.Template(this.tpl);
9191 // support xtype ctors..
9192 this.tpl = new Roo.factory(this.tpl, Roo);
9204 * @event beforeclick
9205 * Fires before a click is processed. Returns false to cancel the default action.
9206 * @param {Roo.View} this
9207 * @param {Number} index The index of the target node
9208 * @param {HTMLElement} node The target node
9209 * @param {Roo.EventObject} e The raw event object
9211 "beforeclick" : true,
9214 * Fires when a template node is clicked.
9215 * @param {Roo.View} this
9216 * @param {Number} index The index of the target node
9217 * @param {HTMLElement} node The target node
9218 * @param {Roo.EventObject} e The raw event object
9223 * Fires when a template node is double clicked.
9224 * @param {Roo.View} this
9225 * @param {Number} index The index of the target node
9226 * @param {HTMLElement} node The target node
9227 * @param {Roo.EventObject} e The raw event object
9231 * @event contextmenu
9232 * Fires when a template node is right clicked.
9233 * @param {Roo.View} this
9234 * @param {Number} index The index of the target node
9235 * @param {HTMLElement} node The target node
9236 * @param {Roo.EventObject} e The raw event object
9238 "contextmenu" : true,
9240 * @event selectionchange
9241 * Fires when the selected nodes change.
9242 * @param {Roo.View} this
9243 * @param {Array} selections Array of the selected nodes
9245 "selectionchange" : true,
9248 * @event beforeselect
9249 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
9250 * @param {Roo.View} this
9251 * @param {HTMLElement} node The node to be selected
9252 * @param {Array} selections Array of currently selected nodes
9254 "beforeselect" : true,
9256 * @event preparedata
9257 * Fires on every row to render, to allow you to change the data.
9258 * @param {Roo.View} this
9259 * @param {Object} data to be rendered (change this)
9261 "preparedata" : true
9269 "click": this.onClick,
9270 "dblclick": this.onDblClick,
9271 "contextmenu": this.onContextMenu,
9275 this.selections = [];
9277 this.cmp = new Roo.CompositeElementLite([]);
9279 this.store = Roo.factory(this.store, Roo.data);
9280 this.setStore(this.store, true);
9283 if ( this.footer && this.footer.xtype) {
9285 var fctr = this.wrapEl.appendChild(document.createElement("div"));
9287 this.footer.dataSource = this.store
9288 this.footer.container = fctr;
9289 this.footer = Roo.factory(this.footer, Roo);
9290 fctr.insertFirst(this.el);
9292 // this is a bit insane - as the paging toolbar seems to detach the el..
9293 // dom.parentNode.parentNode.parentNode
9294 // they get detached?
9298 Roo.View.superclass.constructor.call(this);
9303 Roo.extend(Roo.View, Roo.util.Observable, {
9306 * @cfg {Roo.data.Store} store Data store to load data from.
9311 * @cfg {String|Roo.Element} el The container element.
9316 * @cfg {String|Roo.Template} tpl The template used by this View
9320 * @cfg {String} dataName the named area of the template to use as the data area
9321 * Works with domtemplates roo-name="name"
9325 * @cfg {String} selectedClass The css class to add to selected nodes
9327 selectedClass : "x-view-selected",
9329 * @cfg {String} emptyText The empty text to show when nothing is loaded.
9334 * @cfg {String} text to display on mask (default Loading)
9338 * @cfg {Boolean} multiSelect Allow multiple selection
9340 multiSelect : false,
9342 * @cfg {Boolean} singleSelect Allow single selection
9344 singleSelect: false,
9347 * @cfg {Boolean} toggleSelect - selecting
9349 toggleSelect : false,
9352 * Returns the element this view is bound to.
9353 * @return {Roo.Element}
9362 * Refreshes the view. - called by datachanged on the store. - do not call directly.
9364 refresh : function(){
9367 // if we are using something like 'domtemplate', then
9368 // the what gets used is:
9369 // t.applySubtemplate(NAME, data, wrapping data..)
9370 // the outer template then get' applied with
9371 // the store 'extra data'
9372 // and the body get's added to the
9373 // roo-name="data" node?
9374 // <span class='roo-tpl-{name}'></span> ?????
9378 this.clearSelections();
9381 var records = this.store.getRange();
9382 if(records.length < 1) {
9384 // is this valid?? = should it render a template??
9386 this.el.update(this.emptyText);
9390 if (this.dataName) {
9391 this.el.update(t.apply(this.store.meta)); //????
9392 el = this.el.child('.roo-tpl-' + this.dataName);
9395 for(var i = 0, len = records.length; i < len; i++){
9396 var data = this.prepareData(records[i].data, i, records[i]);
9397 this.fireEvent("preparedata", this, data, i, records[i]);
9398 html[html.length] = Roo.util.Format.trim(
9400 t.applySubtemplate(this.dataName, data, this.store.meta) :
9407 el.update(html.join(""));
9408 this.nodes = el.dom.childNodes;
9409 this.updateIndexes(0);
9413 * Function to override to reformat the data that is sent to
9414 * the template for each node.
9415 * DEPRICATED - use the preparedata event handler.
9416 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
9417 * a JSON object for an UpdateManager bound view).
9419 prepareData : function(data, index, record)
9421 this.fireEvent("preparedata", this, data, index, record);
9425 onUpdate : function(ds, record){
9426 this.clearSelections();
9427 var index = this.store.indexOf(record);
9428 var n = this.nodes[index];
9429 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
9430 n.parentNode.removeChild(n);
9431 this.updateIndexes(index, index);
9437 onAdd : function(ds, records, index)
9439 this.clearSelections();
9440 if(this.nodes.length == 0){
9444 var n = this.nodes[index];
9445 for(var i = 0, len = records.length; i < len; i++){
9446 var d = this.prepareData(records[i].data, i, records[i]);
9448 this.tpl.insertBefore(n, d);
9451 this.tpl.append(this.el, d);
9454 this.updateIndexes(index);
9457 onRemove : function(ds, record, index){
9458 this.clearSelections();
9459 var el = this.dataName ?
9460 this.el.child('.roo-tpl-' + this.dataName) :
9462 el.dom.removeChild(this.nodes[index]);
9463 this.updateIndexes(index);
9467 * Refresh an individual node.
9468 * @param {Number} index
9470 refreshNode : function(index){
9471 this.onUpdate(this.store, this.store.getAt(index));
9474 updateIndexes : function(startIndex, endIndex){
9475 var ns = this.nodes;
9476 startIndex = startIndex || 0;
9477 endIndex = endIndex || ns.length - 1;
9478 for(var i = startIndex; i <= endIndex; i++){
9479 ns[i].nodeIndex = i;
9484 * Changes the data store this view uses and refresh the view.
9485 * @param {Store} store
9487 setStore : function(store, initial){
9488 if(!initial && this.store){
9489 this.store.un("datachanged", this.refresh);
9490 this.store.un("add", this.onAdd);
9491 this.store.un("remove", this.onRemove);
9492 this.store.un("update", this.onUpdate);
9493 this.store.un("clear", this.refresh);
9494 this.store.un("beforeload", this.onBeforeLoad);
9495 this.store.un("load", this.onLoad);
9496 this.store.un("loadexception", this.onLoad);
9500 store.on("datachanged", this.refresh, this);
9501 store.on("add", this.onAdd, this);
9502 store.on("remove", this.onRemove, this);
9503 store.on("update", this.onUpdate, this);
9504 store.on("clear", this.refresh, this);
9505 store.on("beforeload", this.onBeforeLoad, this);
9506 store.on("load", this.onLoad, this);
9507 store.on("loadexception", this.onLoad, this);
9515 * onbeforeLoad - masks the loading area.
9518 onBeforeLoad : function()
9521 this.el.mask(this.mask ? this.mask : "Loading" );
9523 onLoad : function ()
9530 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
9531 * @param {HTMLElement} node
9532 * @return {HTMLElement} The template node
9534 findItemFromChild : function(node){
9535 var el = this.dataName ?
9536 this.el.child('.roo-tpl-' + this.dataName,true) :
9539 if(!node || node.parentNode == el){
9542 var p = node.parentNode;
9543 while(p && p != el){
9544 if(p.parentNode == el){
9553 onClick : function(e){
9554 var item = this.findItemFromChild(e.getTarget());
9556 var index = this.indexOf(item);
9557 if(this.onItemClick(item, index, e) !== false){
9558 this.fireEvent("click", this, index, item, e);
9561 this.clearSelections();
9566 onContextMenu : function(e){
9567 var item = this.findItemFromChild(e.getTarget());
9569 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
9574 onDblClick : function(e){
9575 var item = this.findItemFromChild(e.getTarget());
9577 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
9581 onItemClick : function(item, index, e)
9583 if(this.fireEvent("beforeclick", this, index, item, e) === false){
9586 if (this.toggleSelect) {
9587 var m = this.isSelected(item) ? 'unselect' : 'select';
9590 _t[m](item, true, false);
9593 if(this.multiSelect || this.singleSelect){
9594 if(this.multiSelect && e.shiftKey && this.lastSelection){
9595 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
9597 this.select(item, this.multiSelect && e.ctrlKey);
9598 this.lastSelection = item;
9606 * Get the number of selected nodes.
9609 getSelectionCount : function(){
9610 return this.selections.length;
9614 * Get the currently selected nodes.
9615 * @return {Array} An array of HTMLElements
9617 getSelectedNodes : function(){
9618 return this.selections;
9622 * Get the indexes of the selected nodes.
9625 getSelectedIndexes : function(){
9626 var indexes = [], s = this.selections;
9627 for(var i = 0, len = s.length; i < len; i++){
9628 indexes.push(s[i].nodeIndex);
9634 * Clear all selections
9635 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
9637 clearSelections : function(suppressEvent){
9638 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
9639 this.cmp.elements = this.selections;
9640 this.cmp.removeClass(this.selectedClass);
9641 this.selections = [];
9643 this.fireEvent("selectionchange", this, this.selections);
9649 * Returns true if the passed node is selected
9650 * @param {HTMLElement/Number} node The node or node index
9653 isSelected : function(node){
9654 var s = this.selections;
9658 node = this.getNode(node);
9659 return s.indexOf(node) !== -1;
9664 * @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
9665 * @param {Boolean} keepExisting (optional) true to keep existing selections
9666 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
9668 select : function(nodeInfo, keepExisting, suppressEvent){
9669 if(nodeInfo instanceof Array){
9671 this.clearSelections(true);
9673 for(var i = 0, len = nodeInfo.length; i < len; i++){
9674 this.select(nodeInfo[i], true, true);
9678 var node = this.getNode(nodeInfo);
9679 if(!node || this.isSelected(node)){
9680 return; // already selected.
9683 this.clearSelections(true);
9685 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
9686 Roo.fly(node).addClass(this.selectedClass);
9687 this.selections.push(node);
9689 this.fireEvent("selectionchange", this, this.selections);
9697 * @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
9698 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
9699 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
9701 unselect : function(nodeInfo, keepExisting, suppressEvent)
9703 if(nodeInfo instanceof Array){
9704 Roo.each(this.selections, function(s) {
9705 this.unselect(s, nodeInfo);
9709 var node = this.getNode(nodeInfo);
9710 if(!node || !this.isSelected(node)){
9711 Roo.log("not selected");
9712 return; // not selected.
9716 Roo.each(this.selections, function(s) {
9718 Roo.fly(node).removeClass(this.selectedClass);
9725 this.selections= ns;
9726 this.fireEvent("selectionchange", this, this.selections);
9730 * Gets a template node.
9731 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
9732 * @return {HTMLElement} The node or null if it wasn't found
9734 getNode : function(nodeInfo){
9735 if(typeof nodeInfo == "string"){
9736 return document.getElementById(nodeInfo);
9737 }else if(typeof nodeInfo == "number"){
9738 return this.nodes[nodeInfo];
9744 * Gets a range template nodes.
9745 * @param {Number} startIndex
9746 * @param {Number} endIndex
9747 * @return {Array} An array of nodes
9749 getNodes : function(start, end){
9750 var ns = this.nodes;
9752 end = typeof end == "undefined" ? ns.length - 1 : end;
9755 for(var i = start; i <= end; i++){
9759 for(var i = start; i >= end; i--){
9767 * Finds the index of the passed node
9768 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
9769 * @return {Number} The index of the node or -1
9771 indexOf : function(node){
9772 node = this.getNode(node);
9773 if(typeof node.nodeIndex == "number"){
9774 return node.nodeIndex;
9776 var ns = this.nodes;
9777 for(var i = 0, len = ns.length; i < len; i++){
9787 * Ext JS Library 1.1.1
9788 * Copyright(c) 2006-2007, Ext JS, LLC.
9790 * Originally Released Under LGPL - original licence link has changed is not relivant.
9793 * <script type="text/javascript">
9797 * @class Roo.JsonView
9799 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
9801 var view = new Roo.JsonView({
9802 container: "my-element",
9803 tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
9808 // listen for node click?
9809 view.on("click", function(vw, index, node, e){
9810 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
9813 // direct load of JSON data
9814 view.load("foobar.php");
9816 // Example from my blog list
9817 var tpl = new Roo.Template(
9818 '<div class="entry">' +
9819 '<a class="entry-title" href="{link}">{title}</a>' +
9820 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
9821 "</div><hr />"
9824 var moreView = new Roo.JsonView({
9825 container : "entry-list",
9829 moreView.on("beforerender", this.sortEntries, this);
9831 url: "/blog/get-posts.php",
9832 params: "allposts=true",
9833 text: "Loading Blog Entries..."
9837 * Note: old code is supported with arguments : (container, template, config)
9841 * Create a new JsonView
9843 * @param {Object} config The config object
9846 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
9849 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
9851 var um = this.el.getUpdateManager();
9852 um.setRenderer(this);
9853 um.on("update", this.onLoad, this);
9854 um.on("failure", this.onLoadException, this);
9857 * @event beforerender
9858 * Fires before rendering of the downloaded JSON data.
9859 * @param {Roo.JsonView} this
9860 * @param {Object} data The JSON data loaded
9864 * Fires when data is loaded.
9865 * @param {Roo.JsonView} this
9866 * @param {Object} data The JSON data loaded
9867 * @param {Object} response The raw Connect response object
9870 * @event loadexception
9871 * Fires when loading fails.
9872 * @param {Roo.JsonView} this
9873 * @param {Object} response The raw Connect response object
9876 'beforerender' : true,
9878 'loadexception' : true
9881 Roo.extend(Roo.JsonView, Roo.View, {
9883 * @type {String} The root property in the loaded JSON object that contains the data
9888 * Refreshes the view.
9890 refresh : function(){
9891 this.clearSelections();
9894 var o = this.jsonData;
9895 if(o && o.length > 0){
9896 for(var i = 0, len = o.length; i < len; i++){
9897 var data = this.prepareData(o[i], i, o);
9898 html[html.length] = this.tpl.apply(data);
9901 html.push(this.emptyText);
9903 this.el.update(html.join(""));
9904 this.nodes = this.el.dom.childNodes;
9905 this.updateIndexes(0);
9909 * 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.
9910 * @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:
9913 url: "your-url.php",
9914 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
9915 callback: yourFunction,
9916 scope: yourObject, //(optional scope)
9924 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
9925 * 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.
9926 * @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}
9927 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
9928 * @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.
9931 var um = this.el.getUpdateManager();
9932 um.update.apply(um, arguments);
9935 render : function(el, response){
9936 this.clearSelections();
9940 o = Roo.util.JSON.decode(response.responseText);
9943 o = o[this.jsonRoot];
9948 * The current JSON data or null
9951 this.beforeRender();
9956 * Get the number of records in the current JSON dataset
9959 getCount : function(){
9960 return this.jsonData ? this.jsonData.length : 0;
9964 * Returns the JSON object for the specified node(s)
9965 * @param {HTMLElement/Array} node The node or an array of nodes
9966 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
9967 * you get the JSON object for the node
9969 getNodeData : function(node){
9970 if(node instanceof Array){
9972 for(var i = 0, len = node.length; i < len; i++){
9973 data.push(this.getNodeData(node[i]));
9977 return this.jsonData[this.indexOf(node)] || null;
9980 beforeRender : function(){
9981 this.snapshot = this.jsonData;
9983 this.sort.apply(this, this.sortInfo);
9985 this.fireEvent("beforerender", this, this.jsonData);
9988 onLoad : function(el, o){
9989 this.fireEvent("load", this, this.jsonData, o);
9992 onLoadException : function(el, o){
9993 this.fireEvent("loadexception", this, o);
9997 * Filter the data by a specific property.
9998 * @param {String} property A property on your JSON objects
9999 * @param {String/RegExp} value Either string that the property values
10000 * should start with, or a RegExp to test against the property
10002 filter : function(property, value){
10005 var ss = this.snapshot;
10006 if(typeof value == "string"){
10007 var vlen = value.length;
10009 this.clearFilter();
10012 value = value.toLowerCase();
10013 for(var i = 0, len = ss.length; i < len; i++){
10015 if(o[property].substr(0, vlen).toLowerCase() == value){
10019 } else if(value.exec){ // regex?
10020 for(var i = 0, len = ss.length; i < len; i++){
10022 if(value.test(o[property])){
10029 this.jsonData = data;
10035 * Filter by a function. The passed function will be called with each
10036 * object in the current dataset. If the function returns true the value is kept,
10037 * otherwise it is filtered.
10038 * @param {Function} fn
10039 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
10041 filterBy : function(fn, scope){
10044 var ss = this.snapshot;
10045 for(var i = 0, len = ss.length; i < len; i++){
10047 if(fn.call(scope || this, o)){
10051 this.jsonData = data;
10057 * Clears the current filter.
10059 clearFilter : function(){
10060 if(this.snapshot && this.jsonData != this.snapshot){
10061 this.jsonData = this.snapshot;
10068 * Sorts the data for this view and refreshes it.
10069 * @param {String} property A property on your JSON objects to sort on
10070 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
10071 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
10073 sort : function(property, dir, sortType){
10074 this.sortInfo = Array.prototype.slice.call(arguments, 0);
10077 var dsc = dir && dir.toLowerCase() == "desc";
10078 var f = function(o1, o2){
10079 var v1 = sortType ? sortType(o1[p]) : o1[p];
10080 var v2 = sortType ? sortType(o2[p]) : o2[p];
10083 return dsc ? +1 : -1;
10084 } else if(v1 > v2){
10085 return dsc ? -1 : +1;
10090 this.jsonData.sort(f);
10092 if(this.jsonData != this.snapshot){
10093 this.snapshot.sort(f);
10099 * Ext JS Library 1.1.1
10100 * Copyright(c) 2006-2007, Ext JS, LLC.
10102 * Originally Released Under LGPL - original licence link has changed is not relivant.
10105 * <script type="text/javascript">
10110 * @class Roo.ColorPalette
10111 * @extends Roo.Component
10112 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
10113 * Here's an example of typical usage:
10115 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
10116 cp.render('my-div');
10118 cp.on('select', function(palette, selColor){
10119 // do something with selColor
10123 * Create a new ColorPalette
10124 * @param {Object} config The config object
10126 Roo.ColorPalette = function(config){
10127 Roo.ColorPalette.superclass.constructor.call(this, config);
10131 * Fires when a color is selected
10132 * @param {ColorPalette} this
10133 * @param {String} color The 6-digit color hex code (without the # symbol)
10139 this.on("select", this.handler, this.scope, true);
10142 Roo.extend(Roo.ColorPalette, Roo.Component, {
10144 * @cfg {String} itemCls
10145 * The CSS class to apply to the containing element (defaults to "x-color-palette")
10147 itemCls : "x-color-palette",
10149 * @cfg {String} value
10150 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
10151 * the hex codes are case-sensitive.
10154 clickEvent:'click',
10156 ctype: "Roo.ColorPalette",
10159 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
10161 allowReselect : false,
10164 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
10165 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
10166 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
10167 * of colors with the width setting until the box is symmetrical.</p>
10168 * <p>You can override individual colors if needed:</p>
10170 var cp = new Roo.ColorPalette();
10171 cp.colors[0] = "FF0000"; // change the first box to red
10174 Or you can provide a custom array of your own for complete control:
10176 var cp = new Roo.ColorPalette();
10177 cp.colors = ["000000", "993300", "333300"];
10182 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
10183 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
10184 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
10185 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
10186 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
10190 onRender : function(container, position){
10191 var t = new Roo.MasterTemplate(
10192 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
10194 var c = this.colors;
10195 for(var i = 0, len = c.length; i < len; i++){
10198 var el = document.createElement("div");
10199 el.className = this.itemCls;
10201 container.dom.insertBefore(el, position);
10202 this.el = Roo.get(el);
10203 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
10204 if(this.clickEvent != 'click'){
10205 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
10210 afterRender : function(){
10211 Roo.ColorPalette.superclass.afterRender.call(this);
10213 var s = this.value;
10220 handleClick : function(e, t){
10221 e.preventDefault();
10222 if(!this.disabled){
10223 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
10224 this.select(c.toUpperCase());
10229 * Selects the specified color in the palette (fires the select event)
10230 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
10232 select : function(color){
10233 color = color.replace("#", "");
10234 if(color != this.value || this.allowReselect){
10237 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
10239 el.child("a.color-"+color).addClass("x-color-palette-sel");
10240 this.value = color;
10241 this.fireEvent("select", this, color);
10246 * Ext JS Library 1.1.1
10247 * Copyright(c) 2006-2007, Ext JS, LLC.
10249 * Originally Released Under LGPL - original licence link has changed is not relivant.
10252 * <script type="text/javascript">
10256 * @class Roo.DatePicker
10257 * @extends Roo.Component
10258 * Simple date picker class.
10260 * Create a new DatePicker
10261 * @param {Object} config The config object
10263 Roo.DatePicker = function(config){
10264 Roo.DatePicker.superclass.constructor.call(this, config);
10266 this.value = config && config.value ?
10267 config.value.clearTime() : new Date().clearTime();
10272 * Fires when a date is selected
10273 * @param {DatePicker} this
10274 * @param {Date} date The selected date
10278 * @event monthchange
10279 * Fires when the displayed month changes
10280 * @param {DatePicker} this
10281 * @param {Date} date The selected month
10283 'monthchange': true
10287 this.on("select", this.handler, this.scope || this);
10289 // build the disabledDatesRE
10290 if(!this.disabledDatesRE && this.disabledDates){
10291 var dd = this.disabledDates;
10293 for(var i = 0; i < dd.length; i++){
10295 if(i != dd.length-1) re += "|";
10297 this.disabledDatesRE = new RegExp(re + ")");
10301 Roo.extend(Roo.DatePicker, Roo.Component, {
10303 * @cfg {String} todayText
10304 * The text to display on the button that selects the current date (defaults to "Today")
10306 todayText : "Today",
10308 * @cfg {String} okText
10309 * The text to display on the ok button
10311 okText : " OK ", //   to give the user extra clicking room
10313 * @cfg {String} cancelText
10314 * The text to display on the cancel button
10316 cancelText : "Cancel",
10318 * @cfg {String} todayTip
10319 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
10321 todayTip : "{0} (Spacebar)",
10323 * @cfg {Date} minDate
10324 * Minimum allowable date (JavaScript date object, defaults to null)
10328 * @cfg {Date} maxDate
10329 * Maximum allowable date (JavaScript date object, defaults to null)
10333 * @cfg {String} minText
10334 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
10336 minText : "This date is before the minimum date",
10338 * @cfg {String} maxText
10339 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
10341 maxText : "This date is after the maximum date",
10343 * @cfg {String} format
10344 * The default date format string which can be overriden for localization support. The format must be
10345 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
10349 * @cfg {Array} disabledDays
10350 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
10352 disabledDays : null,
10354 * @cfg {String} disabledDaysText
10355 * The tooltip to display when the date falls on a disabled day (defaults to "")
10357 disabledDaysText : "",
10359 * @cfg {RegExp} disabledDatesRE
10360 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
10362 disabledDatesRE : null,
10364 * @cfg {String} disabledDatesText
10365 * The tooltip text to display when the date falls on a disabled date (defaults to "")
10367 disabledDatesText : "",
10369 * @cfg {Boolean} constrainToViewport
10370 * True to constrain the date picker to the viewport (defaults to true)
10372 constrainToViewport : true,
10374 * @cfg {Array} monthNames
10375 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
10377 monthNames : Date.monthNames,
10379 * @cfg {Array} dayNames
10380 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
10382 dayNames : Date.dayNames,
10384 * @cfg {String} nextText
10385 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
10387 nextText: 'Next Month (Control+Right)',
10389 * @cfg {String} prevText
10390 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
10392 prevText: 'Previous Month (Control+Left)',
10394 * @cfg {String} monthYearText
10395 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
10397 monthYearText: 'Choose a month (Control+Up/Down to move years)',
10399 * @cfg {Number} startDay
10400 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
10404 * @cfg {Bool} showClear
10405 * Show a clear button (usefull for date form elements that can be blank.)
10411 * Sets the value of the date field
10412 * @param {Date} value The date to set
10414 setValue : function(value){
10415 var old = this.value;
10417 if (typeof(value) == 'string') {
10419 value = Date.parseDate(value, this.format);
10422 value = new Date();
10425 this.value = value.clearTime(true);
10427 this.update(this.value);
10432 * Gets the current selected value of the date field
10433 * @return {Date} The selected date
10435 getValue : function(){
10440 focus : function(){
10442 this.update(this.activeDate);
10447 onRender : function(container, position){
10450 '<table cellspacing="0">',
10451 '<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>',
10452 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
10453 var dn = this.dayNames;
10454 for(var i = 0; i < 7; i++){
10455 var d = this.startDay+i;
10459 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
10461 m[m.length] = "</tr></thead><tbody><tr>";
10462 for(var i = 0; i < 42; i++) {
10463 if(i % 7 == 0 && i != 0){
10464 m[m.length] = "</tr><tr>";
10466 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
10468 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
10469 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
10471 var el = document.createElement("div");
10472 el.className = "x-date-picker";
10473 el.innerHTML = m.join("");
10475 container.dom.insertBefore(el, position);
10477 this.el = Roo.get(el);
10478 this.eventEl = Roo.get(el.firstChild);
10480 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
10481 handler: this.showPrevMonth,
10483 preventDefault:true,
10487 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
10488 handler: this.showNextMonth,
10490 preventDefault:true,
10494 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
10496 this.monthPicker = this.el.down('div.x-date-mp');
10497 this.monthPicker.enableDisplayMode('block');
10499 var kn = new Roo.KeyNav(this.eventEl, {
10500 "left" : function(e){
10502 this.showPrevMonth() :
10503 this.update(this.activeDate.add("d", -1));
10506 "right" : function(e){
10508 this.showNextMonth() :
10509 this.update(this.activeDate.add("d", 1));
10512 "up" : function(e){
10514 this.showNextYear() :
10515 this.update(this.activeDate.add("d", -7));
10518 "down" : function(e){
10520 this.showPrevYear() :
10521 this.update(this.activeDate.add("d", 7));
10524 "pageUp" : function(e){
10525 this.showNextMonth();
10528 "pageDown" : function(e){
10529 this.showPrevMonth();
10532 "enter" : function(e){
10533 e.stopPropagation();
10540 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
10542 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
10544 this.el.unselectable();
10546 this.cells = this.el.select("table.x-date-inner tbody td");
10547 this.textNodes = this.el.query("table.x-date-inner tbody span");
10549 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
10551 tooltip: this.monthYearText
10554 this.mbtn.on('click', this.showMonthPicker, this);
10555 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
10558 var today = (new Date()).dateFormat(this.format);
10560 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
10561 if (this.showClear) {
10562 baseTb.add( new Roo.Toolbar.Fill());
10565 text: String.format(this.todayText, today),
10566 tooltip: String.format(this.todayTip, today),
10567 handler: this.selectToday,
10571 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
10574 if (this.showClear) {
10576 baseTb.add( new Roo.Toolbar.Fill());
10579 cls: 'x-btn-icon x-btn-clear',
10580 handler: function() {
10582 this.fireEvent("select", this, '');
10592 this.update(this.value);
10595 createMonthPicker : function(){
10596 if(!this.monthPicker.dom.firstChild){
10597 var buf = ['<table border="0" cellspacing="0">'];
10598 for(var i = 0; i < 6; i++){
10600 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
10601 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
10603 '<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>' :
10604 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
10608 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
10610 '</button><button type="button" class="x-date-mp-cancel">',
10612 '</button></td></tr>',
10615 this.monthPicker.update(buf.join(''));
10616 this.monthPicker.on('click', this.onMonthClick, this);
10617 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
10619 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
10620 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
10622 this.mpMonths.each(function(m, a, i){
10625 m.dom.xmonth = 5 + Math.round(i * .5);
10627 m.dom.xmonth = Math.round((i-1) * .5);
10633 showMonthPicker : function(){
10634 this.createMonthPicker();
10635 var size = this.el.getSize();
10636 this.monthPicker.setSize(size);
10637 this.monthPicker.child('table').setSize(size);
10639 this.mpSelMonth = (this.activeDate || this.value).getMonth();
10640 this.updateMPMonth(this.mpSelMonth);
10641 this.mpSelYear = (this.activeDate || this.value).getFullYear();
10642 this.updateMPYear(this.mpSelYear);
10644 this.monthPicker.slideIn('t', {duration:.2});
10647 updateMPYear : function(y){
10649 var ys = this.mpYears.elements;
10650 for(var i = 1; i <= 10; i++){
10651 var td = ys[i-1], y2;
10653 y2 = y + Math.round(i * .5);
10654 td.firstChild.innerHTML = y2;
10657 y2 = y - (5-Math.round(i * .5));
10658 td.firstChild.innerHTML = y2;
10661 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
10665 updateMPMonth : function(sm){
10666 this.mpMonths.each(function(m, a, i){
10667 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
10671 selectMPMonth: function(m){
10675 onMonthClick : function(e, t){
10677 var el = new Roo.Element(t), pn;
10678 if(el.is('button.x-date-mp-cancel')){
10679 this.hideMonthPicker();
10681 else if(el.is('button.x-date-mp-ok')){
10682 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
10683 this.hideMonthPicker();
10685 else if(pn = el.up('td.x-date-mp-month', 2)){
10686 this.mpMonths.removeClass('x-date-mp-sel');
10687 pn.addClass('x-date-mp-sel');
10688 this.mpSelMonth = pn.dom.xmonth;
10690 else if(pn = el.up('td.x-date-mp-year', 2)){
10691 this.mpYears.removeClass('x-date-mp-sel');
10692 pn.addClass('x-date-mp-sel');
10693 this.mpSelYear = pn.dom.xyear;
10695 else if(el.is('a.x-date-mp-prev')){
10696 this.updateMPYear(this.mpyear-10);
10698 else if(el.is('a.x-date-mp-next')){
10699 this.updateMPYear(this.mpyear+10);
10703 onMonthDblClick : function(e, t){
10705 var el = new Roo.Element(t), pn;
10706 if(pn = el.up('td.x-date-mp-month', 2)){
10707 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
10708 this.hideMonthPicker();
10710 else if(pn = el.up('td.x-date-mp-year', 2)){
10711 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
10712 this.hideMonthPicker();
10716 hideMonthPicker : function(disableAnim){
10717 if(this.monthPicker){
10718 if(disableAnim === true){
10719 this.monthPicker.hide();
10721 this.monthPicker.slideOut('t', {duration:.2});
10727 showPrevMonth : function(e){
10728 this.update(this.activeDate.add("mo", -1));
10732 showNextMonth : function(e){
10733 this.update(this.activeDate.add("mo", 1));
10737 showPrevYear : function(){
10738 this.update(this.activeDate.add("y", -1));
10742 showNextYear : function(){
10743 this.update(this.activeDate.add("y", 1));
10747 handleMouseWheel : function(e){
10748 var delta = e.getWheelDelta();
10750 this.showPrevMonth();
10752 } else if(delta < 0){
10753 this.showNextMonth();
10759 handleDateClick : function(e, t){
10761 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
10762 this.setValue(new Date(t.dateValue));
10763 this.fireEvent("select", this, this.value);
10768 selectToday : function(){
10769 this.setValue(new Date().clearTime());
10770 this.fireEvent("select", this, this.value);
10774 update : function(date)
10776 var vd = this.activeDate;
10777 this.activeDate = date;
10779 var t = date.getTime();
10780 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
10781 this.cells.removeClass("x-date-selected");
10782 this.cells.each(function(c){
10783 if(c.dom.firstChild.dateValue == t){
10784 c.addClass("x-date-selected");
10785 setTimeout(function(){
10786 try{c.dom.firstChild.focus();}catch(e){}
10795 var days = date.getDaysInMonth();
10796 var firstOfMonth = date.getFirstDateOfMonth();
10797 var startingPos = firstOfMonth.getDay()-this.startDay;
10799 if(startingPos <= this.startDay){
10803 var pm = date.add("mo", -1);
10804 var prevStart = pm.getDaysInMonth()-startingPos;
10806 var cells = this.cells.elements;
10807 var textEls = this.textNodes;
10808 days += startingPos;
10810 // convert everything to numbers so it's fast
10811 var day = 86400000;
10812 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
10813 var today = new Date().clearTime().getTime();
10814 var sel = date.clearTime().getTime();
10815 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
10816 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
10817 var ddMatch = this.disabledDatesRE;
10818 var ddText = this.disabledDatesText;
10819 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
10820 var ddaysText = this.disabledDaysText;
10821 var format = this.format;
10823 var setCellClass = function(cal, cell){
10825 var t = d.getTime();
10826 cell.firstChild.dateValue = t;
10828 cell.className += " x-date-today";
10829 cell.title = cal.todayText;
10832 cell.className += " x-date-selected";
10833 setTimeout(function(){
10834 try{cell.firstChild.focus();}catch(e){}
10839 cell.className = " x-date-disabled";
10840 cell.title = cal.minText;
10844 cell.className = " x-date-disabled";
10845 cell.title = cal.maxText;
10849 if(ddays.indexOf(d.getDay()) != -1){
10850 cell.title = ddaysText;
10851 cell.className = " x-date-disabled";
10854 if(ddMatch && format){
10855 var fvalue = d.dateFormat(format);
10856 if(ddMatch.test(fvalue)){
10857 cell.title = ddText.replace("%0", fvalue);
10858 cell.className = " x-date-disabled";
10864 for(; i < startingPos; i++) {
10865 textEls[i].innerHTML = (++prevStart);
10866 d.setDate(d.getDate()+1);
10867 cells[i].className = "x-date-prevday";
10868 setCellClass(this, cells[i]);
10870 for(; i < days; i++){
10871 intDay = i - startingPos + 1;
10872 textEls[i].innerHTML = (intDay);
10873 d.setDate(d.getDate()+1);
10874 cells[i].className = "x-date-active";
10875 setCellClass(this, cells[i]);
10878 for(; i < 42; i++) {
10879 textEls[i].innerHTML = (++extraDays);
10880 d.setDate(d.getDate()+1);
10881 cells[i].className = "x-date-nextday";
10882 setCellClass(this, cells[i]);
10885 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
10886 this.fireEvent('monthchange', this, date);
10888 if(!this.internalRender){
10889 var main = this.el.dom.firstChild;
10890 var w = main.offsetWidth;
10891 this.el.setWidth(w + this.el.getBorderWidth("lr"));
10892 Roo.fly(main).setWidth(w);
10893 this.internalRender = true;
10894 // opera does not respect the auto grow header center column
10895 // then, after it gets a width opera refuses to recalculate
10896 // without a second pass
10897 if(Roo.isOpera && !this.secondPass){
10898 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
10899 this.secondPass = true;
10900 this.update.defer(10, this, [date]);
10908 * Ext JS Library 1.1.1
10909 * Copyright(c) 2006-2007, Ext JS, LLC.
10911 * Originally Released Under LGPL - original licence link has changed is not relivant.
10914 * <script type="text/javascript">
10917 * @class Roo.TabPanel
10918 * @extends Roo.util.Observable
10919 * A lightweight tab container.
10923 // basic tabs 1, built from existing content
10924 var tabs = new Roo.TabPanel("tabs1");
10925 tabs.addTab("script", "View Script");
10926 tabs.addTab("markup", "View Markup");
10927 tabs.activate("script");
10929 // more advanced tabs, built from javascript
10930 var jtabs = new Roo.TabPanel("jtabs");
10931 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
10933 // set up the UpdateManager
10934 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
10935 var updater = tab2.getUpdateManager();
10936 updater.setDefaultUrl("ajax1.htm");
10937 tab2.on('activate', updater.refresh, updater, true);
10939 // Use setUrl for Ajax loading
10940 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
10941 tab3.setUrl("ajax2.htm", null, true);
10944 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
10947 jtabs.activate("jtabs-1");
10950 * Create a new TabPanel.
10951 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
10952 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
10954 Roo.TabPanel = function(container, config){
10956 * The container element for this TabPanel.
10957 * @type Roo.Element
10959 this.el = Roo.get(container, true);
10961 if(typeof config == "boolean"){
10962 this.tabPosition = config ? "bottom" : "top";
10964 Roo.apply(this, config);
10967 if(this.tabPosition == "bottom"){
10968 this.bodyEl = Roo.get(this.createBody(this.el.dom));
10969 this.el.addClass("x-tabs-bottom");
10971 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
10972 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
10973 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
10975 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
10977 if(this.tabPosition != "bottom"){
10978 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
10979 * @type Roo.Element
10981 this.bodyEl = Roo.get(this.createBody(this.el.dom));
10982 this.el.addClass("x-tabs-top");
10986 this.bodyEl.setStyle("position", "relative");
10988 this.active = null;
10989 this.activateDelegate = this.activate.createDelegate(this);
10994 * Fires when the active tab changes
10995 * @param {Roo.TabPanel} this
10996 * @param {Roo.TabPanelItem} activePanel The new active tab
11000 * @event beforetabchange
11001 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
11002 * @param {Roo.TabPanel} this
11003 * @param {Object} e Set cancel to true on this object to cancel the tab change
11004 * @param {Roo.TabPanelItem} tab The tab being changed to
11006 "beforetabchange" : true
11009 Roo.EventManager.onWindowResize(this.onResize, this);
11010 this.cpad = this.el.getPadding("lr");
11011 this.hiddenCount = 0;
11014 // toolbar on the tabbar support...
11015 if (this.toolbar) {
11016 var tcfg = this.toolbar;
11017 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
11018 this.toolbar = new Roo.Toolbar(tcfg);
11019 if (Roo.isSafari) {
11020 var tbl = tcfg.container.child('table', true);
11021 tbl.setAttribute('width', '100%');
11028 Roo.TabPanel.superclass.constructor.call(this);
11031 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
11033 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
11035 tabPosition : "top",
11037 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
11039 currentTabWidth : 0,
11041 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
11045 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
11049 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
11051 preferredTabWidth : 175,
11053 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
11055 resizeTabs : false,
11057 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
11059 monitorResize : true,
11061 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
11066 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
11067 * @param {String} id The id of the div to use <b>or create</b>
11068 * @param {String} text The text for the tab
11069 * @param {String} content (optional) Content to put in the TabPanelItem body
11070 * @param {Boolean} closable (optional) True to create a close icon on the tab
11071 * @return {Roo.TabPanelItem} The created TabPanelItem
11073 addTab : function(id, text, content, closable){
11074 var item = new Roo.TabPanelItem(this, id, text, closable);
11075 this.addTabItem(item);
11077 item.setContent(content);
11083 * Returns the {@link Roo.TabPanelItem} with the specified id/index
11084 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
11085 * @return {Roo.TabPanelItem}
11087 getTab : function(id){
11088 return this.items[id];
11092 * Hides the {@link Roo.TabPanelItem} with the specified id/index
11093 * @param {String/Number} id The id or index of the TabPanelItem to hide.
11095 hideTab : function(id){
11096 var t = this.items[id];
11099 this.hiddenCount++;
11100 this.autoSizeTabs();
11105 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
11106 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
11108 unhideTab : function(id){
11109 var t = this.items[id];
11111 t.setHidden(false);
11112 this.hiddenCount--;
11113 this.autoSizeTabs();
11118 * Adds an existing {@link Roo.TabPanelItem}.
11119 * @param {Roo.TabPanelItem} item The TabPanelItem to add
11121 addTabItem : function(item){
11122 this.items[item.id] = item;
11123 this.items.push(item);
11124 if(this.resizeTabs){
11125 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
11126 this.autoSizeTabs();
11133 * Removes a {@link Roo.TabPanelItem}.
11134 * @param {String/Number} id The id or index of the TabPanelItem to remove.
11136 removeTab : function(id){
11137 var items = this.items;
11138 var tab = items[id];
11139 if(!tab) { return; }
11140 var index = items.indexOf(tab);
11141 if(this.active == tab && items.length > 1){
11142 var newTab = this.getNextAvailable(index);
11147 this.stripEl.dom.removeChild(tab.pnode.dom);
11148 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
11149 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
11151 items.splice(index, 1);
11152 delete this.items[tab.id];
11153 tab.fireEvent("close", tab);
11154 tab.purgeListeners();
11155 this.autoSizeTabs();
11158 getNextAvailable : function(start){
11159 var items = this.items;
11161 // look for a next tab that will slide over to
11162 // replace the one being removed
11163 while(index < items.length){
11164 var item = items[++index];
11165 if(item && !item.isHidden()){
11169 // if one isn't found select the previous tab (on the left)
11172 var item = items[--index];
11173 if(item && !item.isHidden()){
11181 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
11182 * @param {String/Number} id The id or index of the TabPanelItem to disable.
11184 disableTab : function(id){
11185 var tab = this.items[id];
11186 if(tab && this.active != tab){
11192 * Enables a {@link Roo.TabPanelItem} that is disabled.
11193 * @param {String/Number} id The id or index of the TabPanelItem to enable.
11195 enableTab : function(id){
11196 var tab = this.items[id];
11201 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
11202 * @param {String/Number} id The id or index of the TabPanelItem to activate.
11203 * @return {Roo.TabPanelItem} The TabPanelItem.
11205 activate : function(id){
11206 var tab = this.items[id];
11210 if(tab == this.active || tab.disabled){
11214 this.fireEvent("beforetabchange", this, e, tab);
11215 if(e.cancel !== true && !tab.disabled){
11217 this.active.hide();
11219 this.active = this.items[id];
11220 this.active.show();
11221 this.fireEvent("tabchange", this, this.active);
11227 * Gets the active {@link Roo.TabPanelItem}.
11228 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
11230 getActiveTab : function(){
11231 return this.active;
11235 * Updates the tab body element to fit the height of the container element
11236 * for overflow scrolling
11237 * @param {Number} targetHeight (optional) Override the starting height from the elements height
11239 syncHeight : function(targetHeight){
11240 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
11241 var bm = this.bodyEl.getMargins();
11242 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
11243 this.bodyEl.setHeight(newHeight);
11247 onResize : function(){
11248 if(this.monitorResize){
11249 this.autoSizeTabs();
11254 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
11256 beginUpdate : function(){
11257 this.updating = true;
11261 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
11263 endUpdate : function(){
11264 this.updating = false;
11265 this.autoSizeTabs();
11269 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
11271 autoSizeTabs : function(){
11272 var count = this.items.length;
11273 var vcount = count - this.hiddenCount;
11274 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) return;
11275 var w = Math.max(this.el.getWidth() - this.cpad, 10);
11276 var availWidth = Math.floor(w / vcount);
11277 var b = this.stripBody;
11278 if(b.getWidth() > w){
11279 var tabs = this.items;
11280 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
11281 if(availWidth < this.minTabWidth){
11282 /*if(!this.sleft){ // incomplete scrolling code
11283 this.createScrollButtons();
11286 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
11289 if(this.currentTabWidth < this.preferredTabWidth){
11290 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
11296 * Returns the number of tabs in this TabPanel.
11299 getCount : function(){
11300 return this.items.length;
11304 * Resizes all the tabs to the passed width
11305 * @param {Number} The new width
11307 setTabWidth : function(width){
11308 this.currentTabWidth = width;
11309 for(var i = 0, len = this.items.length; i < len; i++) {
11310 if(!this.items[i].isHidden())this.items[i].setWidth(width);
11315 * Destroys this TabPanel
11316 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
11318 destroy : function(removeEl){
11319 Roo.EventManager.removeResizeListener(this.onResize, this);
11320 for(var i = 0, len = this.items.length; i < len; i++){
11321 this.items[i].purgeListeners();
11323 if(removeEl === true){
11324 this.el.update("");
11331 * @class Roo.TabPanelItem
11332 * @extends Roo.util.Observable
11333 * Represents an individual item (tab plus body) in a TabPanel.
11334 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
11335 * @param {String} id The id of this TabPanelItem
11336 * @param {String} text The text for the tab of this TabPanelItem
11337 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
11339 Roo.TabPanelItem = function(tabPanel, id, text, closable){
11341 * The {@link Roo.TabPanel} this TabPanelItem belongs to
11342 * @type Roo.TabPanel
11344 this.tabPanel = tabPanel;
11346 * The id for this TabPanelItem
11351 this.disabled = false;
11355 this.loaded = false;
11356 this.closable = closable;
11359 * The body element for this TabPanelItem.
11360 * @type Roo.Element
11362 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
11363 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
11364 this.bodyEl.setStyle("display", "block");
11365 this.bodyEl.setStyle("zoom", "1");
11368 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
11370 this.el = Roo.get(els.el, true);
11371 this.inner = Roo.get(els.inner, true);
11372 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
11373 this.pnode = Roo.get(els.el.parentNode, true);
11374 this.el.on("mousedown", this.onTabMouseDown, this);
11375 this.el.on("click", this.onTabClick, this);
11378 var c = Roo.get(els.close, true);
11379 c.dom.title = this.closeText;
11380 c.addClassOnOver("close-over");
11381 c.on("click", this.closeClick, this);
11387 * Fires when this tab becomes the active tab.
11388 * @param {Roo.TabPanel} tabPanel The parent TabPanel
11389 * @param {Roo.TabPanelItem} this
11393 * @event beforeclose
11394 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
11395 * @param {Roo.TabPanelItem} this
11396 * @param {Object} e Set cancel to true on this object to cancel the close.
11398 "beforeclose": true,
11401 * Fires when this tab is closed.
11402 * @param {Roo.TabPanelItem} this
11406 * @event deactivate
11407 * Fires when this tab is no longer the active tab.
11408 * @param {Roo.TabPanel} tabPanel The parent TabPanel
11409 * @param {Roo.TabPanelItem} this
11411 "deactivate" : true
11413 this.hidden = false;
11415 Roo.TabPanelItem.superclass.constructor.call(this);
11418 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
11419 purgeListeners : function(){
11420 Roo.util.Observable.prototype.purgeListeners.call(this);
11421 this.el.removeAllListeners();
11424 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
11427 this.pnode.addClass("on");
11430 this.tabPanel.stripWrap.repaint();
11432 this.fireEvent("activate", this.tabPanel, this);
11436 * Returns true if this tab is the active tab.
11437 * @return {Boolean}
11439 isActive : function(){
11440 return this.tabPanel.getActiveTab() == this;
11444 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
11447 this.pnode.removeClass("on");
11449 this.fireEvent("deactivate", this.tabPanel, this);
11452 hideAction : function(){
11453 this.bodyEl.hide();
11454 this.bodyEl.setStyle("position", "absolute");
11455 this.bodyEl.setLeft("-20000px");
11456 this.bodyEl.setTop("-20000px");
11459 showAction : function(){
11460 this.bodyEl.setStyle("position", "relative");
11461 this.bodyEl.setTop("");
11462 this.bodyEl.setLeft("");
11463 this.bodyEl.show();
11467 * Set the tooltip for the tab.
11468 * @param {String} tooltip The tab's tooltip
11470 setTooltip : function(text){
11471 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
11472 this.textEl.dom.qtip = text;
11473 this.textEl.dom.removeAttribute('title');
11475 this.textEl.dom.title = text;
11479 onTabClick : function(e){
11480 e.preventDefault();
11481 this.tabPanel.activate(this.id);
11484 onTabMouseDown : function(e){
11485 e.preventDefault();
11486 this.tabPanel.activate(this.id);
11489 getWidth : function(){
11490 return this.inner.getWidth();
11493 setWidth : function(width){
11494 var iwidth = width - this.pnode.getPadding("lr");
11495 this.inner.setWidth(iwidth);
11496 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
11497 this.pnode.setWidth(width);
11501 * Show or hide the tab
11502 * @param {Boolean} hidden True to hide or false to show.
11504 setHidden : function(hidden){
11505 this.hidden = hidden;
11506 this.pnode.setStyle("display", hidden ? "none" : "");
11510 * Returns true if this tab is "hidden"
11511 * @return {Boolean}
11513 isHidden : function(){
11514 return this.hidden;
11518 * Returns the text for this tab
11521 getText : function(){
11525 autoSize : function(){
11526 //this.el.beginMeasure();
11527 this.textEl.setWidth(1);
11528 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr"));
11529 //this.el.endMeasure();
11533 * Sets the text for the tab (Note: this also sets the tooltip text)
11534 * @param {String} text The tab's text and tooltip
11536 setText : function(text){
11538 this.textEl.update(text);
11539 this.setTooltip(text);
11540 if(!this.tabPanel.resizeTabs){
11545 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
11547 activate : function(){
11548 this.tabPanel.activate(this.id);
11552 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
11554 disable : function(){
11555 if(this.tabPanel.active != this){
11556 this.disabled = true;
11557 this.pnode.addClass("disabled");
11562 * Enables this TabPanelItem if it was previously disabled.
11564 enable : function(){
11565 this.disabled = false;
11566 this.pnode.removeClass("disabled");
11570 * Sets the content for this TabPanelItem.
11571 * @param {String} content The content
11572 * @param {Boolean} loadScripts true to look for and load scripts
11574 setContent : function(content, loadScripts){
11575 this.bodyEl.update(content, loadScripts);
11579 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
11580 * @return {Roo.UpdateManager} The UpdateManager
11582 getUpdateManager : function(){
11583 return this.bodyEl.getUpdateManager();
11587 * Set a URL to be used to load the content for this TabPanelItem.
11588 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
11589 * @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)
11590 * @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)
11591 * @return {Roo.UpdateManager} The UpdateManager
11593 setUrl : function(url, params, loadOnce){
11594 if(this.refreshDelegate){
11595 this.un('activate', this.refreshDelegate);
11597 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
11598 this.on("activate", this.refreshDelegate);
11599 return this.bodyEl.getUpdateManager();
11603 _handleRefresh : function(url, params, loadOnce){
11604 if(!loadOnce || !this.loaded){
11605 var updater = this.bodyEl.getUpdateManager();
11606 updater.update(url, params, this._setLoaded.createDelegate(this));
11611 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
11612 * Will fail silently if the setUrl method has not been called.
11613 * This does not activate the panel, just updates its content.
11615 refresh : function(){
11616 if(this.refreshDelegate){
11617 this.loaded = false;
11618 this.refreshDelegate();
11623 _setLoaded : function(){
11624 this.loaded = true;
11628 closeClick : function(e){
11631 this.fireEvent("beforeclose", this, o);
11632 if(o.cancel !== true){
11633 this.tabPanel.removeTab(this.id);
11637 * The text displayed in the tooltip for the close icon.
11640 closeText : "Close this tab"
11644 Roo.TabPanel.prototype.createStrip = function(container){
11645 var strip = document.createElement("div");
11646 strip.className = "x-tabs-wrap";
11647 container.appendChild(strip);
11651 Roo.TabPanel.prototype.createStripList = function(strip){
11652 // div wrapper for retard IE
11653 // returns the "tr" element.
11654 strip.innerHTML = '<div class="x-tabs-strip-wrap">'+
11655 '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
11656 '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
11657 return strip.firstChild.firstChild.firstChild.firstChild;
11660 Roo.TabPanel.prototype.createBody = function(container){
11661 var body = document.createElement("div");
11662 Roo.id(body, "tab-body");
11663 Roo.fly(body).addClass("x-tabs-body");
11664 container.appendChild(body);
11668 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
11669 var body = Roo.getDom(id);
11671 body = document.createElement("div");
11674 Roo.fly(body).addClass("x-tabs-item-body");
11675 bodyEl.insertBefore(body, bodyEl.firstChild);
11679 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
11680 var td = document.createElement("td");
11681 stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
11682 //stripEl.appendChild(td);
11684 td.className = "x-tabs-closable";
11685 if(!this.closeTpl){
11686 this.closeTpl = new Roo.Template(
11687 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
11688 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
11689 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
11692 var el = this.closeTpl.overwrite(td, {"text": text});
11693 var close = el.getElementsByTagName("div")[0];
11694 var inner = el.getElementsByTagName("em")[0];
11695 return {"el": el, "close": close, "inner": inner};
11698 this.tabTpl = new Roo.Template(
11699 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
11700 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
11703 var el = this.tabTpl.overwrite(td, {"text": text});
11704 var inner = el.getElementsByTagName("em")[0];
11705 return {"el": el, "inner": inner};
11709 * Ext JS Library 1.1.1
11710 * Copyright(c) 2006-2007, Ext JS, LLC.
11712 * Originally Released Under LGPL - original licence link has changed is not relivant.
11715 * <script type="text/javascript">
11719 * @class Roo.Button
11720 * @extends Roo.util.Observable
11721 * Simple Button class
11722 * @cfg {String} text The button text
11723 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
11724 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
11725 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
11726 * @cfg {Object} scope The scope of the handler
11727 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
11728 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
11729 * @cfg {Boolean} hidden True to start hidden (defaults to false)
11730 * @cfg {Boolean} disabled True to start disabled (defaults to false)
11731 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
11732 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
11733 applies if enableToggle = true)
11734 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
11735 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
11736 an {@link Roo.util.ClickRepeater} config object (defaults to false).
11738 * Create a new button
11739 * @param {Object} config The config object
11741 Roo.Button = function(renderTo, config)
11745 renderTo = config.renderTo || false;
11748 Roo.apply(this, config);
11752 * Fires when this button is clicked
11753 * @param {Button} this
11754 * @param {EventObject} e The click event
11759 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
11760 * @param {Button} this
11761 * @param {Boolean} pressed
11766 * Fires when the mouse hovers over the button
11767 * @param {Button} this
11768 * @param {Event} e The event object
11770 'mouseover' : true,
11773 * Fires when the mouse exits the button
11774 * @param {Button} this
11775 * @param {Event} e The event object
11780 * Fires when the button is rendered
11781 * @param {Button} this
11786 this.menu = Roo.menu.MenuMgr.get(this.menu);
11788 // register listeners first!! - so render can be captured..
11789 Roo.util.Observable.call(this);
11791 this.render(renderTo);
11797 Roo.extend(Roo.Button, Roo.util.Observable, {
11803 * Read-only. True if this button is hidden
11808 * Read-only. True if this button is disabled
11813 * Read-only. True if this button is pressed (only if enableToggle = true)
11819 * @cfg {Number} tabIndex
11820 * The DOM tabIndex for this button (defaults to undefined)
11822 tabIndex : undefined,
11825 * @cfg {Boolean} enableToggle
11826 * True to enable pressed/not pressed toggling (defaults to false)
11828 enableToggle: false,
11830 * @cfg {Mixed} menu
11831 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
11835 * @cfg {String} menuAlign
11836 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
11838 menuAlign : "tl-bl?",
11841 * @cfg {String} iconCls
11842 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
11844 iconCls : undefined,
11846 * @cfg {String} type
11847 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
11852 menuClassTarget: 'tr',
11855 * @cfg {String} clickEvent
11856 * The type of event to map to the button's event handler (defaults to 'click')
11858 clickEvent : 'click',
11861 * @cfg {Boolean} handleMouseEvents
11862 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
11864 handleMouseEvents : true,
11867 * @cfg {String} tooltipType
11868 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
11870 tooltipType : 'qtip',
11873 * @cfg {String} cls
11874 * A CSS class to apply to the button's main element.
11878 * @cfg {Roo.Template} template (Optional)
11879 * An {@link Roo.Template} with which to create the Button's main element. This Template must
11880 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
11881 * require code modifications if required elements (e.g. a button) aren't present.
11885 render : function(renderTo){
11887 if(this.hideParent){
11888 this.parentEl = Roo.get(renderTo);
11890 if(!this.dhconfig){
11891 if(!this.template){
11892 if(!Roo.Button.buttonTemplate){
11893 // hideous table template
11894 Roo.Button.buttonTemplate = new Roo.Template(
11895 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
11896 '<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>',
11897 "</tr></tbody></table>");
11899 this.template = Roo.Button.buttonTemplate;
11901 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
11902 var btnEl = btn.child("button:first");
11903 btnEl.on('focus', this.onFocus, this);
11904 btnEl.on('blur', this.onBlur, this);
11906 btn.addClass(this.cls);
11909 btnEl.setStyle('background-image', 'url(' +this.icon +')');
11912 btnEl.addClass(this.iconCls);
11914 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
11917 if(this.tabIndex !== undefined){
11918 btnEl.dom.tabIndex = this.tabIndex;
11921 if(typeof this.tooltip == 'object'){
11922 Roo.QuickTips.tips(Roo.apply({
11926 btnEl.dom[this.tooltipType] = this.tooltip;
11930 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
11934 this.el.dom.id = this.el.id = this.id;
11937 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
11938 this.menu.on("show", this.onMenuShow, this);
11939 this.menu.on("hide", this.onMenuHide, this);
11941 btn.addClass("x-btn");
11942 if(Roo.isIE && !Roo.isIE7){
11943 this.autoWidth.defer(1, this);
11947 if(this.handleMouseEvents){
11948 btn.on("mouseover", this.onMouseOver, this);
11949 btn.on("mouseout", this.onMouseOut, this);
11950 btn.on("mousedown", this.onMouseDown, this);
11952 btn.on(this.clickEvent, this.onClick, this);
11953 //btn.on("mouseup", this.onMouseUp, this);
11960 Roo.ButtonToggleMgr.register(this);
11962 this.el.addClass("x-btn-pressed");
11965 var repeater = new Roo.util.ClickRepeater(btn,
11966 typeof this.repeat == "object" ? this.repeat : {}
11968 repeater.on("click", this.onClick, this);
11971 this.fireEvent('render', this);
11975 * Returns the button's underlying element
11976 * @return {Roo.Element} The element
11978 getEl : function(){
11983 * Destroys this Button and removes any listeners.
11985 destroy : function(){
11986 Roo.ButtonToggleMgr.unregister(this);
11987 this.el.removeAllListeners();
11988 this.purgeListeners();
11993 autoWidth : function(){
11995 this.el.setWidth("auto");
11996 if(Roo.isIE7 && Roo.isStrict){
11997 var ib = this.el.child('button');
11998 if(ib && ib.getWidth() > 20){
12000 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
12005 this.el.beginMeasure();
12007 if(this.el.getWidth() < this.minWidth){
12008 this.el.setWidth(this.minWidth);
12011 this.el.endMeasure();
12018 * Assigns this button's click handler
12019 * @param {Function} handler The function to call when the button is clicked
12020 * @param {Object} scope (optional) Scope for the function passed in
12022 setHandler : function(handler, scope){
12023 this.handler = handler;
12024 this.scope = scope;
12028 * Sets this button's text
12029 * @param {String} text The button text
12031 setText : function(text){
12034 this.el.child("td.x-btn-center button.x-btn-text").update(text);
12040 * Gets the text for this button
12041 * @return {String} The button text
12043 getText : function(){
12051 this.hidden = false;
12053 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
12061 this.hidden = true;
12063 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
12068 * Convenience function for boolean show/hide
12069 * @param {Boolean} visible True to show, false to hide
12071 setVisible: function(visible){
12080 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
12081 * @param {Boolean} state (optional) Force a particular state
12083 toggle : function(state){
12084 state = state === undefined ? !this.pressed : state;
12085 if(state != this.pressed){
12087 this.el.addClass("x-btn-pressed");
12088 this.pressed = true;
12089 this.fireEvent("toggle", this, true);
12091 this.el.removeClass("x-btn-pressed");
12092 this.pressed = false;
12093 this.fireEvent("toggle", this, false);
12095 if(this.toggleHandler){
12096 this.toggleHandler.call(this.scope || this, this, state);
12104 focus : function(){
12105 this.el.child('button:first').focus();
12109 * Disable this button
12111 disable : function(){
12113 this.el.addClass("x-btn-disabled");
12115 this.disabled = true;
12119 * Enable this button
12121 enable : function(){
12123 this.el.removeClass("x-btn-disabled");
12125 this.disabled = false;
12129 * Convenience function for boolean enable/disable
12130 * @param {Boolean} enabled True to enable, false to disable
12132 setDisabled : function(v){
12133 this[v !== true ? "enable" : "disable"]();
12137 onClick : function(e){
12139 e.preventDefault();
12144 if(!this.disabled){
12145 if(this.enableToggle){
12148 if(this.menu && !this.menu.isVisible()){
12149 this.menu.show(this.el, this.menuAlign);
12151 this.fireEvent("click", this, e);
12153 this.el.removeClass("x-btn-over");
12154 this.handler.call(this.scope || this, this, e);
12159 onMouseOver : function(e){
12160 if(!this.disabled){
12161 this.el.addClass("x-btn-over");
12162 this.fireEvent('mouseover', this, e);
12166 onMouseOut : function(e){
12167 if(!e.within(this.el, true)){
12168 this.el.removeClass("x-btn-over");
12169 this.fireEvent('mouseout', this, e);
12173 onFocus : function(e){
12174 if(!this.disabled){
12175 this.el.addClass("x-btn-focus");
12179 onBlur : function(e){
12180 this.el.removeClass("x-btn-focus");
12183 onMouseDown : function(e){
12184 if(!this.disabled && e.button == 0){
12185 this.el.addClass("x-btn-click");
12186 Roo.get(document).on('mouseup', this.onMouseUp, this);
12190 onMouseUp : function(e){
12192 this.el.removeClass("x-btn-click");
12193 Roo.get(document).un('mouseup', this.onMouseUp, this);
12197 onMenuShow : function(e){
12198 this.el.addClass("x-btn-menu-active");
12201 onMenuHide : function(e){
12202 this.el.removeClass("x-btn-menu-active");
12206 // Private utility class used by Button
12207 Roo.ButtonToggleMgr = function(){
12210 function toggleGroup(btn, state){
12212 var g = groups[btn.toggleGroup];
12213 for(var i = 0, l = g.length; i < l; i++){
12215 g[i].toggle(false);
12222 register : function(btn){
12223 if(!btn.toggleGroup){
12226 var g = groups[btn.toggleGroup];
12228 g = groups[btn.toggleGroup] = [];
12231 btn.on("toggle", toggleGroup);
12234 unregister : function(btn){
12235 if(!btn.toggleGroup){
12238 var g = groups[btn.toggleGroup];
12241 btn.un("toggle", toggleGroup);
12247 * Ext JS Library 1.1.1
12248 * Copyright(c) 2006-2007, Ext JS, LLC.
12250 * Originally Released Under LGPL - original licence link has changed is not relivant.
12253 * <script type="text/javascript">
12257 * @class Roo.SplitButton
12258 * @extends Roo.Button
12259 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
12260 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
12261 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
12262 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
12263 * @cfg {String} arrowTooltip The title attribute of the arrow
12265 * Create a new menu button
12266 * @param {String/HTMLElement/Element} renderTo The element to append the button to
12267 * @param {Object} config The config object
12269 Roo.SplitButton = function(renderTo, config){
12270 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
12272 * @event arrowclick
12273 * Fires when this button's arrow is clicked
12274 * @param {SplitButton} this
12275 * @param {EventObject} e The click event
12277 this.addEvents({"arrowclick":true});
12280 Roo.extend(Roo.SplitButton, Roo.Button, {
12281 render : function(renderTo){
12282 // this is one sweet looking template!
12283 var tpl = new Roo.Template(
12284 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
12285 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
12286 '<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>',
12287 "</tbody></table></td><td>",
12288 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
12289 '<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>',
12290 "</tbody></table></td></tr></table>"
12292 var btn = tpl.append(renderTo, [this.text, this.type], true);
12293 var btnEl = btn.child("button");
12295 btn.addClass(this.cls);
12298 btnEl.setStyle('background-image', 'url(' +this.icon +')');
12301 btnEl.addClass(this.iconCls);
12303 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
12307 if(this.handleMouseEvents){
12308 btn.on("mouseover", this.onMouseOver, this);
12309 btn.on("mouseout", this.onMouseOut, this);
12310 btn.on("mousedown", this.onMouseDown, this);
12311 btn.on("mouseup", this.onMouseUp, this);
12313 btn.on(this.clickEvent, this.onClick, this);
12315 if(typeof this.tooltip == 'object'){
12316 Roo.QuickTips.tips(Roo.apply({
12320 btnEl.dom[this.tooltipType] = this.tooltip;
12323 if(this.arrowTooltip){
12324 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
12333 this.el.addClass("x-btn-pressed");
12335 if(Roo.isIE && !Roo.isIE7){
12336 this.autoWidth.defer(1, this);
12341 this.menu.on("show", this.onMenuShow, this);
12342 this.menu.on("hide", this.onMenuHide, this);
12344 this.fireEvent('render', this);
12348 autoWidth : function(){
12350 var tbl = this.el.child("table:first");
12351 var tbl2 = this.el.child("table:last");
12352 this.el.setWidth("auto");
12353 tbl.setWidth("auto");
12354 if(Roo.isIE7 && Roo.isStrict){
12355 var ib = this.el.child('button:first');
12356 if(ib && ib.getWidth() > 20){
12358 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
12363 this.el.beginMeasure();
12365 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
12366 tbl.setWidth(this.minWidth-tbl2.getWidth());
12369 this.el.endMeasure();
12372 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
12376 * Sets this button's click handler
12377 * @param {Function} handler The function to call when the button is clicked
12378 * @param {Object} scope (optional) Scope for the function passed above
12380 setHandler : function(handler, scope){
12381 this.handler = handler;
12382 this.scope = scope;
12386 * Sets this button's arrow click handler
12387 * @param {Function} handler The function to call when the arrow is clicked
12388 * @param {Object} scope (optional) Scope for the function passed above
12390 setArrowHandler : function(handler, scope){
12391 this.arrowHandler = handler;
12392 this.scope = scope;
12398 focus : function(){
12400 this.el.child("button:first").focus();
12405 onClick : function(e){
12406 e.preventDefault();
12407 if(!this.disabled){
12408 if(e.getTarget(".x-btn-menu-arrow-wrap")){
12409 if(this.menu && !this.menu.isVisible()){
12410 this.menu.show(this.el, this.menuAlign);
12412 this.fireEvent("arrowclick", this, e);
12413 if(this.arrowHandler){
12414 this.arrowHandler.call(this.scope || this, this, e);
12417 this.fireEvent("click", this, e);
12419 this.handler.call(this.scope || this, this, e);
12425 onMouseDown : function(e){
12426 if(!this.disabled){
12427 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
12431 onMouseUp : function(e){
12432 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
12437 // backwards compat
12438 Roo.MenuButton = Roo.SplitButton;/*
12440 * Ext JS Library 1.1.1
12441 * Copyright(c) 2006-2007, Ext JS, LLC.
12443 * Originally Released Under LGPL - original licence link has changed is not relivant.
12446 * <script type="text/javascript">
12450 * @class Roo.Toolbar
12451 * Basic Toolbar class.
12453 * Creates a new Toolbar
12454 * @param {Object} container The config object
12456 Roo.Toolbar = function(container, buttons, config)
12458 /// old consturctor format still supported..
12459 if(container instanceof Array){ // omit the container for later rendering
12460 buttons = container;
12464 if (typeof(container) == 'object' && container.xtype) {
12465 config = container;
12466 container = config.container;
12467 buttons = config.buttons || []; // not really - use items!!
12470 if (config && config.items) {
12471 xitems = config.items;
12472 delete config.items;
12474 Roo.apply(this, config);
12475 this.buttons = buttons;
12478 this.render(container);
12480 this.xitems = xitems;
12481 Roo.each(xitems, function(b) {
12487 Roo.Toolbar.prototype = {
12489 * @cfg {Array} items
12490 * array of button configs or elements to add (will be converted to a MixedCollection)
12494 * @cfg {String/HTMLElement/Element} container
12495 * The id or element that will contain the toolbar
12498 render : function(ct){
12499 this.el = Roo.get(ct);
12501 this.el.addClass(this.cls);
12503 // using a table allows for vertical alignment
12504 // 100% width is needed by Safari...
12505 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
12506 this.tr = this.el.child("tr", true);
12508 this.items = new Roo.util.MixedCollection(false, function(o){
12509 return o.id || ("item" + (++autoId));
12512 this.add.apply(this, this.buttons);
12513 delete this.buttons;
12518 * Adds element(s) to the toolbar -- this function takes a variable number of
12519 * arguments of mixed type and adds them to the toolbar.
12520 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
12522 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
12523 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
12524 * <li>Field: Any form field (equivalent to {@link #addField})</li>
12525 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
12526 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
12527 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
12528 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
12529 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
12530 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
12532 * @param {Mixed} arg2
12533 * @param {Mixed} etc.
12536 var a = arguments, l = a.length;
12537 for(var i = 0; i < l; i++){
12542 _add : function(el) {
12545 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
12548 if (el.applyTo){ // some kind of form field
12549 return this.addField(el);
12551 if (el.render){ // some kind of Toolbar.Item
12552 return this.addItem(el);
12554 if (typeof el == "string"){ // string
12555 if(el == "separator" || el == "-"){
12556 return this.addSeparator();
12559 return this.addSpacer();
12562 return this.addFill();
12564 return this.addText(el);
12567 if(el.tagName){ // element
12568 return this.addElement(el);
12570 if(typeof el == "object"){ // must be button config?
12571 return this.addButton(el);
12573 // and now what?!?!
12579 * Add an Xtype element
12580 * @param {Object} xtype Xtype Object
12581 * @return {Object} created Object
12583 addxtype : function(e){
12584 return this.add(e);
12588 * Returns the Element for this toolbar.
12589 * @return {Roo.Element}
12591 getEl : function(){
12597 * @return {Roo.Toolbar.Item} The separator item
12599 addSeparator : function(){
12600 return this.addItem(new Roo.Toolbar.Separator());
12604 * Adds a spacer element
12605 * @return {Roo.Toolbar.Spacer} The spacer item
12607 addSpacer : function(){
12608 return this.addItem(new Roo.Toolbar.Spacer());
12612 * Adds a fill element that forces subsequent additions to the right side of the toolbar
12613 * @return {Roo.Toolbar.Fill} The fill item
12615 addFill : function(){
12616 return this.addItem(new Roo.Toolbar.Fill());
12620 * Adds any standard HTML element to the toolbar
12621 * @param {String/HTMLElement/Element} el The element or id of the element to add
12622 * @return {Roo.Toolbar.Item} The element's item
12624 addElement : function(el){
12625 return this.addItem(new Roo.Toolbar.Item(el));
12628 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
12629 * @type Roo.util.MixedCollection
12634 * Adds any Toolbar.Item or subclass
12635 * @param {Roo.Toolbar.Item} item
12636 * @return {Roo.Toolbar.Item} The item
12638 addItem : function(item){
12639 var td = this.nextBlock();
12641 this.items.add(item);
12646 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
12647 * @param {Object/Array} config A button config or array of configs
12648 * @return {Roo.Toolbar.Button/Array}
12650 addButton : function(config){
12651 if(config instanceof Array){
12653 for(var i = 0, len = config.length; i < len; i++) {
12654 buttons.push(this.addButton(config[i]));
12659 if(!(config instanceof Roo.Toolbar.Button)){
12661 new Roo.Toolbar.SplitButton(config) :
12662 new Roo.Toolbar.Button(config);
12664 var td = this.nextBlock();
12671 * Adds text to the toolbar
12672 * @param {String} text The text to add
12673 * @return {Roo.Toolbar.Item} The element's item
12675 addText : function(text){
12676 return this.addItem(new Roo.Toolbar.TextItem(text));
12680 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
12681 * @param {Number} index The index where the item is to be inserted
12682 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
12683 * @return {Roo.Toolbar.Button/Item}
12685 insertButton : function(index, item){
12686 if(item instanceof Array){
12688 for(var i = 0, len = item.length; i < len; i++) {
12689 buttons.push(this.insertButton(index + i, item[i]));
12693 if (!(item instanceof Roo.Toolbar.Button)){
12694 item = new Roo.Toolbar.Button(item);
12696 var td = document.createElement("td");
12697 this.tr.insertBefore(td, this.tr.childNodes[index]);
12699 this.items.insert(index, item);
12704 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
12705 * @param {Object} config
12706 * @return {Roo.Toolbar.Item} The element's item
12708 addDom : function(config, returnEl){
12709 var td = this.nextBlock();
12710 Roo.DomHelper.overwrite(td, config);
12711 var ti = new Roo.Toolbar.Item(td.firstChild);
12713 this.items.add(ti);
12718 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
12719 * @type Roo.util.MixedCollection
12724 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc).
12725 * Note: the field should not have been rendered yet. For a field that has already been
12726 * rendered, use {@link #addElement}.
12727 * @param {Roo.form.Field} field
12728 * @return {Roo.ToolbarItem}
12732 addField : function(field) {
12733 if (!this.fields) {
12735 this.fields = new Roo.util.MixedCollection(false, function(o){
12736 return o.id || ("item" + (++autoId));
12741 var td = this.nextBlock();
12743 var ti = new Roo.Toolbar.Item(td.firstChild);
12745 this.items.add(ti);
12746 this.fields.add(field);
12757 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
12758 this.el.child('div').hide();
12766 this.el.child('div').show();
12770 nextBlock : function(){
12771 var td = document.createElement("td");
12772 this.tr.appendChild(td);
12777 destroy : function(){
12778 if(this.items){ // rendered?
12779 Roo.destroy.apply(Roo, this.items.items);
12781 if(this.fields){ // rendered?
12782 Roo.destroy.apply(Roo, this.fields.items);
12784 Roo.Element.uncache(this.el, this.tr);
12789 * @class Roo.Toolbar.Item
12790 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
12792 * Creates a new Item
12793 * @param {HTMLElement} el
12795 Roo.Toolbar.Item = function(el){
12796 this.el = Roo.getDom(el);
12797 this.id = Roo.id(this.el);
12798 this.hidden = false;
12801 Roo.Toolbar.Item.prototype = {
12804 * Get this item's HTML Element
12805 * @return {HTMLElement}
12807 getEl : function(){
12812 render : function(td){
12814 td.appendChild(this.el);
12818 * Removes and destroys this item.
12820 destroy : function(){
12821 this.td.parentNode.removeChild(this.td);
12828 this.hidden = false;
12829 this.td.style.display = "";
12836 this.hidden = true;
12837 this.td.style.display = "none";
12841 * Convenience function for boolean show/hide.
12842 * @param {Boolean} visible true to show/false to hide
12844 setVisible: function(visible){
12853 * Try to focus this item.
12855 focus : function(){
12856 Roo.fly(this.el).focus();
12860 * Disables this item.
12862 disable : function(){
12863 Roo.fly(this.td).addClass("x-item-disabled");
12864 this.disabled = true;
12865 this.el.disabled = true;
12869 * Enables this item.
12871 enable : function(){
12872 Roo.fly(this.td).removeClass("x-item-disabled");
12873 this.disabled = false;
12874 this.el.disabled = false;
12880 * @class Roo.Toolbar.Separator
12881 * @extends Roo.Toolbar.Item
12882 * A simple toolbar separator class
12884 * Creates a new Separator
12886 Roo.Toolbar.Separator = function(){
12887 var s = document.createElement("span");
12888 s.className = "ytb-sep";
12889 Roo.Toolbar.Separator.superclass.constructor.call(this, s);
12891 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
12892 enable:Roo.emptyFn,
12893 disable:Roo.emptyFn,
12898 * @class Roo.Toolbar.Spacer
12899 * @extends Roo.Toolbar.Item
12900 * A simple element that adds extra horizontal space to a toolbar.
12902 * Creates a new Spacer
12904 Roo.Toolbar.Spacer = function(){
12905 var s = document.createElement("div");
12906 s.className = "ytb-spacer";
12907 Roo.Toolbar.Spacer.superclass.constructor.call(this, s);
12909 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
12910 enable:Roo.emptyFn,
12911 disable:Roo.emptyFn,
12916 * @class Roo.Toolbar.Fill
12917 * @extends Roo.Toolbar.Spacer
12918 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
12920 * Creates a new Spacer
12922 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
12924 render : function(td){
12925 td.style.width = '100%';
12926 Roo.Toolbar.Fill.superclass.render.call(this, td);
12931 * @class Roo.Toolbar.TextItem
12932 * @extends Roo.Toolbar.Item
12933 * A simple class that renders text directly into a toolbar.
12935 * Creates a new TextItem
12936 * @param {String} text
12938 Roo.Toolbar.TextItem = function(text){
12939 if (typeof(text) == 'object') {
12942 var s = document.createElement("span");
12943 s.className = "ytb-text";
12944 s.innerHTML = text;
12945 Roo.Toolbar.TextItem.superclass.constructor.call(this, s);
12947 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
12948 enable:Roo.emptyFn,
12949 disable:Roo.emptyFn,
12954 * @class Roo.Toolbar.Button
12955 * @extends Roo.Button
12956 * A button that renders into a toolbar.
12958 * Creates a new Button
12959 * @param {Object} config A standard {@link Roo.Button} config object
12961 Roo.Toolbar.Button = function(config){
12962 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
12964 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
12965 render : function(td){
12967 Roo.Toolbar.Button.superclass.render.call(this, td);
12971 * Removes and destroys this button
12973 destroy : function(){
12974 Roo.Toolbar.Button.superclass.destroy.call(this);
12975 this.td.parentNode.removeChild(this.td);
12979 * Shows this button
12982 this.hidden = false;
12983 this.td.style.display = "";
12987 * Hides this button
12990 this.hidden = true;
12991 this.td.style.display = "none";
12995 * Disables this item
12997 disable : function(){
12998 Roo.fly(this.td).addClass("x-item-disabled");
12999 this.disabled = true;
13003 * Enables this item
13005 enable : function(){
13006 Roo.fly(this.td).removeClass("x-item-disabled");
13007 this.disabled = false;
13010 // backwards compat
13011 Roo.ToolbarButton = Roo.Toolbar.Button;
13014 * @class Roo.Toolbar.SplitButton
13015 * @extends Roo.SplitButton
13016 * A menu button that renders into a toolbar.
13018 * Creates a new SplitButton
13019 * @param {Object} config A standard {@link Roo.SplitButton} config object
13021 Roo.Toolbar.SplitButton = function(config){
13022 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
13024 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
13025 render : function(td){
13027 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
13031 * Removes and destroys this button
13033 destroy : function(){
13034 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
13035 this.td.parentNode.removeChild(this.td);
13039 * Shows this button
13042 this.hidden = false;
13043 this.td.style.display = "";
13047 * Hides this button
13050 this.hidden = true;
13051 this.td.style.display = "none";
13055 // backwards compat
13056 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
13058 * Ext JS Library 1.1.1
13059 * Copyright(c) 2006-2007, Ext JS, LLC.
13061 * Originally Released Under LGPL - original licence link has changed is not relivant.
13064 * <script type="text/javascript">
13068 * @class Roo.PagingToolbar
13069 * @extends Roo.Toolbar
13070 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
13072 * Create a new PagingToolbar
13073 * @param {Object} config The config object
13075 Roo.PagingToolbar = function(el, ds, config)
13077 // old args format still supported... - xtype is prefered..
13078 if (typeof(el) == 'object' && el.xtype) {
13079 // created from xtype...
13081 ds = el.dataSource;
13082 el = config.container;
13085 if (config.items) {
13086 items = config.items;
13090 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
13093 this.renderButtons(this.el);
13096 // supprot items array.
13098 Roo.each(items, function(e) {
13099 this.add(Roo.factory(e));
13104 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
13106 * @cfg {Roo.data.Store} dataSource
13107 * The underlying data store providing the paged data
13110 * @cfg {String/HTMLElement/Element} container
13111 * container The id or element that will contain the toolbar
13114 * @cfg {Boolean} displayInfo
13115 * True to display the displayMsg (defaults to false)
13118 * @cfg {Number} pageSize
13119 * The number of records to display per page (defaults to 20)
13123 * @cfg {String} displayMsg
13124 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
13126 displayMsg : 'Displaying {0} - {1} of {2}',
13128 * @cfg {String} emptyMsg
13129 * The message to display when no records are found (defaults to "No data to display")
13131 emptyMsg : 'No data to display',
13133 * Customizable piece of the default paging text (defaults to "Page")
13136 beforePageText : "Page",
13138 * Customizable piece of the default paging text (defaults to "of %0")
13141 afterPageText : "of {0}",
13143 * Customizable piece of the default paging text (defaults to "First Page")
13146 firstText : "First Page",
13148 * Customizable piece of the default paging text (defaults to "Previous Page")
13151 prevText : "Previous Page",
13153 * Customizable piece of the default paging text (defaults to "Next Page")
13156 nextText : "Next Page",
13158 * Customizable piece of the default paging text (defaults to "Last Page")
13161 lastText : "Last Page",
13163 * Customizable piece of the default paging text (defaults to "Refresh")
13166 refreshText : "Refresh",
13169 renderButtons : function(el){
13170 Roo.PagingToolbar.superclass.render.call(this, el);
13171 this.first = this.addButton({
13172 tooltip: this.firstText,
13173 cls: "x-btn-icon x-grid-page-first",
13175 handler: this.onClick.createDelegate(this, ["first"])
13177 this.prev = this.addButton({
13178 tooltip: this.prevText,
13179 cls: "x-btn-icon x-grid-page-prev",
13181 handler: this.onClick.createDelegate(this, ["prev"])
13183 //this.addSeparator();
13184 this.add(this.beforePageText);
13185 this.field = Roo.get(this.addDom({
13190 cls: "x-grid-page-number"
13192 this.field.on("keydown", this.onPagingKeydown, this);
13193 this.field.on("focus", function(){this.dom.select();});
13194 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
13195 this.field.setHeight(18);
13196 //this.addSeparator();
13197 this.next = this.addButton({
13198 tooltip: this.nextText,
13199 cls: "x-btn-icon x-grid-page-next",
13201 handler: this.onClick.createDelegate(this, ["next"])
13203 this.last = this.addButton({
13204 tooltip: this.lastText,
13205 cls: "x-btn-icon x-grid-page-last",
13207 handler: this.onClick.createDelegate(this, ["last"])
13209 //this.addSeparator();
13210 this.loading = this.addButton({
13211 tooltip: this.refreshText,
13212 cls: "x-btn-icon x-grid-loading",
13213 handler: this.onClick.createDelegate(this, ["refresh"])
13216 if(this.displayInfo){
13217 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
13222 updateInfo : function(){
13223 if(this.displayEl){
13224 var count = this.ds.getCount();
13225 var msg = count == 0 ?
13229 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
13231 this.displayEl.update(msg);
13236 onLoad : function(ds, r, o){
13237 this.cursor = o.params ? o.params.start : 0;
13238 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
13240 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
13241 this.field.dom.value = ap;
13242 this.first.setDisabled(ap == 1);
13243 this.prev.setDisabled(ap == 1);
13244 this.next.setDisabled(ap == ps);
13245 this.last.setDisabled(ap == ps);
13246 this.loading.enable();
13251 getPageData : function(){
13252 var total = this.ds.getTotalCount();
13255 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
13256 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
13261 onLoadError : function(){
13262 this.loading.enable();
13266 onPagingKeydown : function(e){
13267 var k = e.getKey();
13268 var d = this.getPageData();
13270 var v = this.field.dom.value, pageNum;
13271 if(!v || isNaN(pageNum = parseInt(v, 10))){
13272 this.field.dom.value = d.activePage;
13275 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
13276 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
13279 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))
13281 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
13282 this.field.dom.value = pageNum;
13283 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
13286 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
13288 var v = this.field.dom.value, pageNum;
13289 var increment = (e.shiftKey) ? 10 : 1;
13290 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
13292 if(!v || isNaN(pageNum = parseInt(v, 10))) {
13293 this.field.dom.value = d.activePage;
13296 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
13298 this.field.dom.value = parseInt(v, 10) + increment;
13299 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
13300 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
13307 beforeLoad : function(){
13309 this.loading.disable();
13314 onClick : function(which){
13318 ds.load({params:{start: 0, limit: this.pageSize}});
13321 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
13324 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
13327 var total = ds.getTotalCount();
13328 var extra = total % this.pageSize;
13329 var lastStart = extra ? (total - extra) : total-this.pageSize;
13330 ds.load({params:{start: lastStart, limit: this.pageSize}});
13333 ds.load({params:{start: this.cursor, limit: this.pageSize}});
13339 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
13340 * @param {Roo.data.Store} store The data store to unbind
13342 unbind : function(ds){
13343 ds.un("beforeload", this.beforeLoad, this);
13344 ds.un("load", this.onLoad, this);
13345 ds.un("loadexception", this.onLoadError, this);
13346 ds.un("remove", this.updateInfo, this);
13347 ds.un("add", this.updateInfo, this);
13348 this.ds = undefined;
13352 * Binds the paging toolbar to the specified {@link Roo.data.Store}
13353 * @param {Roo.data.Store} store The data store to bind
13355 bind : function(ds){
13356 ds.on("beforeload", this.beforeLoad, this);
13357 ds.on("load", this.onLoad, this);
13358 ds.on("loadexception", this.onLoadError, this);
13359 ds.on("remove", this.updateInfo, this);
13360 ds.on("add", this.updateInfo, this);
13365 * Ext JS Library 1.1.1
13366 * Copyright(c) 2006-2007, Ext JS, LLC.
13368 * Originally Released Under LGPL - original licence link has changed is not relivant.
13371 * <script type="text/javascript">
13375 * @class Roo.Resizable
13376 * @extends Roo.util.Observable
13377 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
13378 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
13379 * 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
13380 * the element will be wrapped for you automatically.</p>
13381 * <p>Here is the list of valid resize handles:</p>
13384 ------ -------------------
13393 'hd' horizontal drag
13396 * <p>Here's an example showing the creation of a typical Resizable:</p>
13398 var resizer = new Roo.Resizable("element-id", {
13406 resizer.on("resize", myHandler);
13408 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
13409 * resizer.east.setDisplayed(false);</p>
13410 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
13411 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
13412 * resize operation's new size (defaults to [0, 0])
13413 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
13414 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
13415 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
13416 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
13417 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
13418 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
13419 * @cfg {Number} width The width of the element in pixels (defaults to null)
13420 * @cfg {Number} height The height of the element in pixels (defaults to null)
13421 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
13422 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
13423 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
13424 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
13425 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
13426 * in favor of the handles config option (defaults to false)
13427 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
13428 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
13429 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
13430 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
13431 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
13432 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
13433 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
13434 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
13435 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
13436 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
13437 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
13439 * Create a new resizable component
13440 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
13441 * @param {Object} config configuration options
13443 Roo.Resizable = function(el, config)
13445 this.el = Roo.get(el);
13447 if(config && config.wrap){
13448 config.resizeChild = this.el;
13449 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
13450 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
13451 this.el.setStyle("overflow", "hidden");
13452 this.el.setPositioning(config.resizeChild.getPositioning());
13453 config.resizeChild.clearPositioning();
13454 if(!config.width || !config.height){
13455 var csize = config.resizeChild.getSize();
13456 this.el.setSize(csize.width, csize.height);
13458 if(config.pinned && !config.adjustments){
13459 config.adjustments = "auto";
13463 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
13464 this.proxy.unselectable();
13465 this.proxy.enableDisplayMode('block');
13467 Roo.apply(this, config);
13470 this.disableTrackOver = true;
13471 this.el.addClass("x-resizable-pinned");
13473 // if the element isn't positioned, make it relative
13474 var position = this.el.getStyle("position");
13475 if(position != "absolute" && position != "fixed"){
13476 this.el.setStyle("position", "relative");
13478 if(!this.handles){ // no handles passed, must be legacy style
13479 this.handles = 's,e,se';
13480 if(this.multiDirectional){
13481 this.handles += ',n,w';
13484 if(this.handles == "all"){
13485 this.handles = "n s e w ne nw se sw";
13487 var hs = this.handles.split(/\s*?[,;]\s*?| /);
13488 var ps = Roo.Resizable.positions;
13489 for(var i = 0, len = hs.length; i < len; i++){
13490 if(hs[i] && ps[hs[i]]){
13491 var pos = ps[hs[i]];
13492 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
13496 this.corner = this.southeast;
13498 // updateBox = the box can move..
13499 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1 || this.handles.indexOf("hd") != -1) {
13500 this.updateBox = true;
13503 this.activeHandle = null;
13505 if(this.resizeChild){
13506 if(typeof this.resizeChild == "boolean"){
13507 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
13509 this.resizeChild = Roo.get(this.resizeChild, true);
13513 if(this.adjustments == "auto"){
13514 var rc = this.resizeChild;
13515 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
13516 if(rc && (hw || hn)){
13517 rc.position("relative");
13518 rc.setLeft(hw ? hw.el.getWidth() : 0);
13519 rc.setTop(hn ? hn.el.getHeight() : 0);
13521 this.adjustments = [
13522 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
13523 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
13527 if(this.draggable){
13528 this.dd = this.dynamic ?
13529 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
13530 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
13536 * @event beforeresize
13537 * Fired before resize is allowed. Set enabled to false to cancel resize.
13538 * @param {Roo.Resizable} this
13539 * @param {Roo.EventObject} e The mousedown event
13541 "beforeresize" : true,
13544 * Fired a resizing.
13545 * @param {Roo.Resizable} this
13546 * @param {Number} x The new x position
13547 * @param {Number} y The new y position
13548 * @param {Number} w The new w width
13549 * @param {Number} h The new h hight
13550 * @param {Roo.EventObject} e The mouseup event
13555 * Fired after a resize.
13556 * @param {Roo.Resizable} this
13557 * @param {Number} width The new width
13558 * @param {Number} height The new height
13559 * @param {Roo.EventObject} e The mouseup event
13564 if(this.width !== null && this.height !== null){
13565 this.resizeTo(this.width, this.height);
13567 this.updateChildSize();
13570 this.el.dom.style.zoom = 1;
13572 Roo.Resizable.superclass.constructor.call(this);
13575 Roo.extend(Roo.Resizable, Roo.util.Observable, {
13576 resizeChild : false,
13577 adjustments : [0, 0],
13587 multiDirectional : false,
13588 disableTrackOver : false,
13589 easing : 'easeOutStrong',
13590 widthIncrement : 0,
13591 heightIncrement : 0,
13595 preserveRatio : false,
13596 transparent: false,
13602 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
13604 constrainTo: undefined,
13606 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
13608 resizeRegion: undefined,
13612 * Perform a manual resize
13613 * @param {Number} width
13614 * @param {Number} height
13616 resizeTo : function(width, height){
13617 this.el.setSize(width, height);
13618 this.updateChildSize();
13619 this.fireEvent("resize", this, width, height, null);
13623 startSizing : function(e, handle){
13624 this.fireEvent("beforeresize", this, e);
13625 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
13628 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
13629 this.overlay.unselectable();
13630 this.overlay.enableDisplayMode("block");
13631 this.overlay.on("mousemove", this.onMouseMove, this);
13632 this.overlay.on("mouseup", this.onMouseUp, this);
13634 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
13636 this.resizing = true;
13637 this.startBox = this.el.getBox();
13638 this.startPoint = e.getXY();
13639 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
13640 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
13642 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
13643 this.overlay.show();
13645 if(this.constrainTo) {
13646 var ct = Roo.get(this.constrainTo);
13647 this.resizeRegion = ct.getRegion().adjust(
13648 ct.getFrameWidth('t'),
13649 ct.getFrameWidth('l'),
13650 -ct.getFrameWidth('b'),
13651 -ct.getFrameWidth('r')
13655 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
13657 this.proxy.setBox(this.startBox);
13659 this.proxy.setStyle('visibility', 'visible');
13665 onMouseDown : function(handle, e){
13668 this.activeHandle = handle;
13669 this.startSizing(e, handle);
13674 onMouseUp : function(e){
13675 var size = this.resizeElement();
13676 this.resizing = false;
13678 this.overlay.hide();
13680 this.fireEvent("resize", this, size.width, size.height, e);
13684 updateChildSize : function(){
13686 if(this.resizeChild){
13688 var child = this.resizeChild;
13689 var adj = this.adjustments;
13690 if(el.dom.offsetWidth){
13691 var b = el.getSize(true);
13692 child.setSize(b.width+adj[0], b.height+adj[1]);
13694 // Second call here for IE
13695 // The first call enables instant resizing and
13696 // the second call corrects scroll bars if they
13699 setTimeout(function(){
13700 if(el.dom.offsetWidth){
13701 var b = el.getSize(true);
13702 child.setSize(b.width+adj[0], b.height+adj[1]);
13710 snap : function(value, inc, min){
13711 if(!inc || !value) return value;
13712 var newValue = value;
13713 var m = value % inc;
13716 newValue = value + (inc-m);
13718 newValue = value - m;
13721 return Math.max(min, newValue);
13725 resizeElement : function(){
13726 var box = this.proxy.getBox();
13727 if(this.updateBox){
13728 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
13730 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
13732 this.updateChildSize();
13740 constrain : function(v, diff, m, mx){
13743 }else if(v - diff > mx){
13750 onMouseMove : function(e){
13753 try{// try catch so if something goes wrong the user doesn't get hung
13755 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
13759 //var curXY = this.startPoint;
13760 var curSize = this.curSize || this.startBox;
13761 var x = this.startBox.x, y = this.startBox.y;
13762 var ox = x, oy = y;
13763 var w = curSize.width, h = curSize.height;
13764 var ow = w, oh = h;
13765 var mw = this.minWidth, mh = this.minHeight;
13766 var mxw = this.maxWidth, mxh = this.maxHeight;
13767 var wi = this.widthIncrement;
13768 var hi = this.heightIncrement;
13770 var eventXY = e.getXY();
13771 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
13772 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
13774 var pos = this.activeHandle.position;
13779 w = Math.min(Math.max(mw, w), mxw);
13784 h = Math.min(Math.max(mh, h), mxh);
13789 w = Math.min(Math.max(mw, w), mxw);
13790 h = Math.min(Math.max(mh, h), mxh);
13793 diffY = this.constrain(h, diffY, mh, mxh);
13800 var adiffX = Math.abs(diffX);
13801 var sub = (adiffX % wi); // how much
13802 if (sub > (wi/2)) { // far enough to snap
13803 diffX = (diffX > 0) ? diffX-sub + wi : diffX+sub - wi;
13805 // remove difference..
13806 diffX = (diffX > 0) ? diffX-sub : diffX+sub;
13810 x = Math.max(this.minX, x);
13813 diffX = this.constrain(w, diffX, mw, mxw);
13819 w = Math.min(Math.max(mw, w), mxw);
13820 diffY = this.constrain(h, diffY, mh, mxh);
13825 diffX = this.constrain(w, diffX, mw, mxw);
13826 diffY = this.constrain(h, diffY, mh, mxh);
13833 diffX = this.constrain(w, diffX, mw, mxw);
13835 h = Math.min(Math.max(mh, h), mxh);
13841 var sw = this.snap(w, wi, mw);
13842 var sh = this.snap(h, hi, mh);
13843 if(sw != w || sh != h){
13866 if(this.preserveRatio){
13871 h = Math.min(Math.max(mh, h), mxh);
13876 w = Math.min(Math.max(mw, w), mxw);
13881 w = Math.min(Math.max(mw, w), mxw);
13887 w = Math.min(Math.max(mw, w), mxw);
13893 h = Math.min(Math.max(mh, h), mxh);
13901 h = Math.min(Math.max(mh, h), mxh);
13911 h = Math.min(Math.max(mh, h), mxh);
13919 if (pos == 'hdrag') {
13922 this.proxy.setBounds(x, y, w, h);
13924 this.resizeElement();
13928 this.fireEvent("resizing", this, x, y, w, h, e);
13932 handleOver : function(){
13934 this.el.addClass("x-resizable-over");
13939 handleOut : function(){
13940 if(!this.resizing){
13941 this.el.removeClass("x-resizable-over");
13946 * Returns the element this component is bound to.
13947 * @return {Roo.Element}
13949 getEl : function(){
13954 * Returns the resizeChild element (or null).
13955 * @return {Roo.Element}
13957 getResizeChild : function(){
13958 return this.resizeChild;
13960 groupHandler : function()
13965 * Destroys this resizable. If the element was wrapped and
13966 * removeEl is not true then the element remains.
13967 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
13969 destroy : function(removeEl){
13970 this.proxy.remove();
13972 this.overlay.removeAllListeners();
13973 this.overlay.remove();
13975 var ps = Roo.Resizable.positions;
13977 if(typeof ps[k] != "function" && this[ps[k]]){
13978 var h = this[ps[k]];
13979 h.el.removeAllListeners();
13984 this.el.update("");
13991 // hash to map config positions to true positions
13992 Roo.Resizable.positions = {
13993 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast",
13998 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
14000 // only initialize the template if resizable is used
14001 var tpl = Roo.DomHelper.createTemplate(
14002 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
14005 Roo.Resizable.Handle.prototype.tpl = tpl;
14007 this.position = pos;
14009 // show north drag fro topdra
14010 var handlepos = pos == 'hdrag' ? 'north' : pos;
14012 this.el = this.tpl.append(rz.el.dom, [handlepos], true);
14013 if (pos == 'hdrag') {
14014 this.el.setStyle('cursor', 'pointer');
14016 this.el.unselectable();
14018 this.el.setOpacity(0);
14020 this.el.on("mousedown", this.onMouseDown, this);
14021 if(!disableTrackOver){
14022 this.el.on("mouseover", this.onMouseOver, this);
14023 this.el.on("mouseout", this.onMouseOut, this);
14028 Roo.Resizable.Handle.prototype = {
14029 afterResize : function(rz){
14033 onMouseDown : function(e){
14034 this.rz.onMouseDown(this, e);
14037 onMouseOver : function(e){
14038 this.rz.handleOver(this, e);
14041 onMouseOut : function(e){
14042 this.rz.handleOut(this, e);
14046 * Ext JS Library 1.1.1
14047 * Copyright(c) 2006-2007, Ext JS, LLC.
14049 * Originally Released Under LGPL - original licence link has changed is not relivant.
14052 * <script type="text/javascript">
14056 * @class Roo.Editor
14057 * @extends Roo.Component
14058 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
14060 * Create a new Editor
14061 * @param {Roo.form.Field} field The Field object (or descendant)
14062 * @param {Object} config The config object
14064 Roo.Editor = function(field, config){
14065 Roo.Editor.superclass.constructor.call(this, config);
14066 this.field = field;
14069 * @event beforestartedit
14070 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
14071 * false from the handler of this event.
14072 * @param {Editor} this
14073 * @param {Roo.Element} boundEl The underlying element bound to this editor
14074 * @param {Mixed} value The field value being set
14076 "beforestartedit" : true,
14079 * Fires when this editor is displayed
14080 * @param {Roo.Element} boundEl The underlying element bound to this editor
14081 * @param {Mixed} value The starting field value
14083 "startedit" : true,
14085 * @event beforecomplete
14086 * Fires after a change has been made to the field, but before the change is reflected in the underlying
14087 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
14088 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
14089 * event will not fire since no edit actually occurred.
14090 * @param {Editor} this
14091 * @param {Mixed} value The current field value
14092 * @param {Mixed} startValue The original field value
14094 "beforecomplete" : true,
14097 * Fires after editing is complete and any changed value has been written to the underlying field.
14098 * @param {Editor} this
14099 * @param {Mixed} value The current field value
14100 * @param {Mixed} startValue The original field value
14104 * @event specialkey
14105 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
14106 * {@link Roo.EventObject#getKey} to determine which key was pressed.
14107 * @param {Roo.form.Field} this
14108 * @param {Roo.EventObject} e The event object
14110 "specialkey" : true
14114 Roo.extend(Roo.Editor, Roo.Component, {
14116 * @cfg {Boolean/String} autosize
14117 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
14118 * or "height" to adopt the height only (defaults to false)
14121 * @cfg {Boolean} revertInvalid
14122 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
14123 * validation fails (defaults to true)
14126 * @cfg {Boolean} ignoreNoChange
14127 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
14128 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
14129 * will never be ignored.
14132 * @cfg {Boolean} hideEl
14133 * False to keep the bound element visible while the editor is displayed (defaults to true)
14136 * @cfg {Mixed} value
14137 * The data value of the underlying field (defaults to "")
14141 * @cfg {String} alignment
14142 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
14146 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
14147 * for bottom-right shadow (defaults to "frame")
14151 * @cfg {Boolean} constrain True to constrain the editor to the viewport
14155 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
14157 completeOnEnter : false,
14159 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
14161 cancelOnEsc : false,
14163 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
14168 onRender : function(ct, position){
14169 this.el = new Roo.Layer({
14170 shadow: this.shadow,
14176 constrain: this.constrain
14178 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
14179 if(this.field.msgTarget != 'title'){
14180 this.field.msgTarget = 'qtip';
14182 this.field.render(this.el);
14184 this.field.el.dom.setAttribute('autocomplete', 'off');
14186 this.field.on("specialkey", this.onSpecialKey, this);
14187 if(this.swallowKeys){
14188 this.field.el.swallowEvent(['keydown','keypress']);
14191 this.field.on("blur", this.onBlur, this);
14192 if(this.field.grow){
14193 this.field.on("autosize", this.el.sync, this.el, {delay:1});
14197 onSpecialKey : function(field, e)
14199 //Roo.log('editor onSpecialKey');
14200 if(this.completeOnEnter && e.getKey() == e.ENTER){
14202 this.completeEdit();
14205 // do not fire special key otherwise it might hide close the editor...
14206 if(e.getKey() == e.ENTER){
14209 if(this.cancelOnEsc && e.getKey() == e.ESC){
14213 this.fireEvent('specialkey', field, e);
14218 * Starts the editing process and shows the editor.
14219 * @param {String/HTMLElement/Element} el The element to edit
14220 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
14221 * to the innerHTML of el.
14223 startEdit : function(el, value){
14225 this.completeEdit();
14227 this.boundEl = Roo.get(el);
14228 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
14229 if(!this.rendered){
14230 this.render(this.parentEl || document.body);
14232 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
14235 this.startValue = v;
14236 this.field.setValue(v);
14238 var sz = this.boundEl.getSize();
14239 switch(this.autoSize){
14241 this.setSize(sz.width, "");
14244 this.setSize("", sz.height);
14247 this.setSize(sz.width, sz.height);
14250 this.el.alignTo(this.boundEl, this.alignment);
14251 this.editing = true;
14253 Roo.QuickTips.disable();
14259 * Sets the height and width of this editor.
14260 * @param {Number} width The new width
14261 * @param {Number} height The new height
14263 setSize : function(w, h){
14264 this.field.setSize(w, h);
14271 * Realigns the editor to the bound field based on the current alignment config value.
14273 realign : function(){
14274 this.el.alignTo(this.boundEl, this.alignment);
14278 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
14279 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
14281 completeEdit : function(remainVisible){
14285 var v = this.getValue();
14286 if(this.revertInvalid !== false && !this.field.isValid()){
14287 v = this.startValue;
14288 this.cancelEdit(true);
14290 if(String(v) === String(this.startValue) && this.ignoreNoChange){
14291 this.editing = false;
14295 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
14296 this.editing = false;
14297 if(this.updateEl && this.boundEl){
14298 this.boundEl.update(v);
14300 if(remainVisible !== true){
14303 this.fireEvent("complete", this, v, this.startValue);
14308 onShow : function(){
14310 if(this.hideEl !== false){
14311 this.boundEl.hide();
14314 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
14315 this.fixIEFocus = true;
14316 this.deferredFocus.defer(50, this);
14318 this.field.focus();
14320 this.fireEvent("startedit", this.boundEl, this.startValue);
14323 deferredFocus : function(){
14325 this.field.focus();
14330 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
14331 * reverted to the original starting value.
14332 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
14333 * cancel (defaults to false)
14335 cancelEdit : function(remainVisible){
14337 this.setValue(this.startValue);
14338 if(remainVisible !== true){
14345 onBlur : function(){
14346 if(this.allowBlur !== true && this.editing){
14347 this.completeEdit();
14352 onHide : function(){
14354 this.completeEdit();
14358 if(this.field.collapse){
14359 this.field.collapse();
14362 if(this.hideEl !== false){
14363 this.boundEl.show();
14366 Roo.QuickTips.enable();
14371 * Sets the data value of the editor
14372 * @param {Mixed} value Any valid value supported by the underlying field
14374 setValue : function(v){
14375 this.field.setValue(v);
14379 * Gets the data value of the editor
14380 * @return {Mixed} The data value
14382 getValue : function(){
14383 return this.field.getValue();
14387 * Ext JS Library 1.1.1
14388 * Copyright(c) 2006-2007, Ext JS, LLC.
14390 * Originally Released Under LGPL - original licence link has changed is not relivant.
14393 * <script type="text/javascript">
14397 * @class Roo.BasicDialog
14398 * @extends Roo.util.Observable
14399 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
14401 var dlg = new Roo.BasicDialog("my-dlg", {
14410 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
14411 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
14412 dlg.addButton('Cancel', dlg.hide, dlg);
14415 <b>A Dialog should always be a direct child of the body element.</b>
14416 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
14417 * @cfg {String} title Default text to display in the title bar (defaults to null)
14418 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
14419 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
14420 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
14421 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
14422 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
14423 * (defaults to null with no animation)
14424 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
14425 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
14426 * property for valid values (defaults to 'all')
14427 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
14428 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
14429 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
14430 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
14431 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
14432 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
14433 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
14434 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
14435 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
14436 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
14437 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
14438 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
14439 * draggable = true (defaults to false)
14440 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
14441 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
14442 * shadow (defaults to false)
14443 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
14444 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
14445 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
14446 * @cfg {Array} buttons Array of buttons
14447 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
14449 * Create a new BasicDialog.
14450 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
14451 * @param {Object} config Configuration options
14453 Roo.BasicDialog = function(el, config){
14454 this.el = Roo.get(el);
14455 var dh = Roo.DomHelper;
14456 if(!this.el && config && config.autoCreate){
14457 if(typeof config.autoCreate == "object"){
14458 if(!config.autoCreate.id){
14459 config.autoCreate.id = el;
14461 this.el = dh.append(document.body,
14462 config.autoCreate, true);
14464 this.el = dh.append(document.body,
14465 {tag: "div", id: el, style:'visibility:hidden;'}, true);
14469 el.setDisplayed(true);
14470 el.hide = this.hideAction;
14472 el.addClass("x-dlg");
14474 Roo.apply(this, config);
14476 this.proxy = el.createProxy("x-dlg-proxy");
14477 this.proxy.hide = this.hideAction;
14478 this.proxy.setOpacity(.5);
14482 el.setWidth(config.width);
14485 el.setHeight(config.height);
14487 this.size = el.getSize();
14488 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
14489 this.xy = [config.x,config.y];
14491 this.xy = el.getCenterXY(true);
14493 /** The header element @type Roo.Element */
14494 this.header = el.child("> .x-dlg-hd");
14495 /** The body element @type Roo.Element */
14496 this.body = el.child("> .x-dlg-bd");
14497 /** The footer element @type Roo.Element */
14498 this.footer = el.child("> .x-dlg-ft");
14501 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
14504 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
14507 this.header.unselectable();
14509 this.header.update(this.title);
14511 // this element allows the dialog to be focused for keyboard event
14512 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
14513 this.focusEl.swallowEvent("click", true);
14515 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
14517 // wrap the body and footer for special rendering
14518 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
14520 this.bwrap.dom.appendChild(this.footer.dom);
14523 this.bg = this.el.createChild({
14524 tag: "div", cls:"x-dlg-bg",
14525 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
14527 this.centerBg = this.bg.child("div.x-dlg-bg-center");
14530 if(this.autoScroll !== false && !this.autoTabs){
14531 this.body.setStyle("overflow", "auto");
14534 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
14536 if(this.closable !== false){
14537 this.el.addClass("x-dlg-closable");
14538 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
14539 this.close.on("click", this.closeClick, this);
14540 this.close.addClassOnOver("x-dlg-close-over");
14542 if(this.collapsible !== false){
14543 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
14544 this.collapseBtn.on("click", this.collapseClick, this);
14545 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
14546 this.header.on("dblclick", this.collapseClick, this);
14548 if(this.resizable !== false){
14549 this.el.addClass("x-dlg-resizable");
14550 this.resizer = new Roo.Resizable(el, {
14551 minWidth: this.minWidth || 80,
14552 minHeight:this.minHeight || 80,
14553 handles: this.resizeHandles || "all",
14556 this.resizer.on("beforeresize", this.beforeResize, this);
14557 this.resizer.on("resize", this.onResize, this);
14559 if(this.draggable !== false){
14560 el.addClass("x-dlg-draggable");
14561 if (!this.proxyDrag) {
14562 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
14565 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
14567 dd.setHandleElId(this.header.id);
14568 dd.endDrag = this.endMove.createDelegate(this);
14569 dd.startDrag = this.startMove.createDelegate(this);
14570 dd.onDrag = this.onDrag.createDelegate(this);
14575 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
14576 this.mask.enableDisplayMode("block");
14578 this.el.addClass("x-dlg-modal");
14581 this.shadow = new Roo.Shadow({
14582 mode : typeof this.shadow == "string" ? this.shadow : "sides",
14583 offset : this.shadowOffset
14586 this.shadowOffset = 0;
14588 if(Roo.useShims && this.shim !== false){
14589 this.shim = this.el.createShim();
14590 this.shim.hide = this.hideAction;
14598 if (this.buttons) {
14599 var bts= this.buttons;
14601 Roo.each(bts, function(b) {
14610 * Fires when a key is pressed
14611 * @param {Roo.BasicDialog} this
14612 * @param {Roo.EventObject} e
14617 * Fires when this dialog is moved by the user.
14618 * @param {Roo.BasicDialog} this
14619 * @param {Number} x The new page X
14620 * @param {Number} y The new page Y
14625 * Fires when this dialog is resized by the user.
14626 * @param {Roo.BasicDialog} this
14627 * @param {Number} width The new width
14628 * @param {Number} height The new height
14632 * @event beforehide
14633 * Fires before this dialog is hidden.
14634 * @param {Roo.BasicDialog} this
14636 "beforehide" : true,
14639 * Fires when this dialog is hidden.
14640 * @param {Roo.BasicDialog} this
14644 * @event beforeshow
14645 * Fires before this dialog is shown.
14646 * @param {Roo.BasicDialog} this
14648 "beforeshow" : true,
14651 * Fires when this dialog is shown.
14652 * @param {Roo.BasicDialog} this
14656 el.on("keydown", this.onKeyDown, this);
14657 el.on("mousedown", this.toFront, this);
14658 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
14660 Roo.DialogManager.register(this);
14661 Roo.BasicDialog.superclass.constructor.call(this);
14664 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
14665 shadowOffset: Roo.isIE ? 6 : 5,
14668 minButtonWidth: 75,
14669 defaultButton: null,
14670 buttonAlign: "right",
14675 * Sets the dialog title text
14676 * @param {String} text The title text to display
14677 * @return {Roo.BasicDialog} this
14679 setTitle : function(text){
14680 this.header.update(text);
14685 closeClick : function(){
14690 collapseClick : function(){
14691 this[this.collapsed ? "expand" : "collapse"]();
14695 * Collapses the dialog to its minimized state (only the title bar is visible).
14696 * Equivalent to the user clicking the collapse dialog button.
14698 collapse : function(){
14699 if(!this.collapsed){
14700 this.collapsed = true;
14701 this.el.addClass("x-dlg-collapsed");
14702 this.restoreHeight = this.el.getHeight();
14703 this.resizeTo(this.el.getWidth(), this.header.getHeight());
14708 * Expands a collapsed dialog back to its normal state. Equivalent to the user
14709 * clicking the expand dialog button.
14711 expand : function(){
14712 if(this.collapsed){
14713 this.collapsed = false;
14714 this.el.removeClass("x-dlg-collapsed");
14715 this.resizeTo(this.el.getWidth(), this.restoreHeight);
14720 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
14721 * @return {Roo.TabPanel} The tabs component
14723 initTabs : function(){
14724 var tabs = this.getTabs();
14725 while(tabs.getTab(0)){
14728 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
14730 tabs.addTab(Roo.id(dom), dom.title);
14738 beforeResize : function(){
14739 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
14743 onResize : function(){
14744 this.refreshSize();
14745 this.syncBodyHeight();
14746 this.adjustAssets();
14748 this.fireEvent("resize", this, this.size.width, this.size.height);
14752 onKeyDown : function(e){
14753 if(this.isVisible()){
14754 this.fireEvent("keydown", this, e);
14759 * Resizes the dialog.
14760 * @param {Number} width
14761 * @param {Number} height
14762 * @return {Roo.BasicDialog} this
14764 resizeTo : function(width, height){
14765 this.el.setSize(width, height);
14766 this.size = {width: width, height: height};
14767 this.syncBodyHeight();
14768 if(this.fixedcenter){
14771 if(this.isVisible()){
14772 this.constrainXY();
14773 this.adjustAssets();
14775 this.fireEvent("resize", this, width, height);
14781 * Resizes the dialog to fit the specified content size.
14782 * @param {Number} width
14783 * @param {Number} height
14784 * @return {Roo.BasicDialog} this
14786 setContentSize : function(w, h){
14787 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
14788 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
14789 //if(!this.el.isBorderBox()){
14790 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
14791 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
14794 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
14795 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
14797 this.resizeTo(w, h);
14802 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
14803 * executed in response to a particular key being pressed while the dialog is active.
14804 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
14805 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
14806 * @param {Function} fn The function to call
14807 * @param {Object} scope (optional) The scope of the function
14808 * @return {Roo.BasicDialog} this
14810 addKeyListener : function(key, fn, scope){
14811 var keyCode, shift, ctrl, alt;
14812 if(typeof key == "object" && !(key instanceof Array)){
14813 keyCode = key["key"];
14814 shift = key["shift"];
14815 ctrl = key["ctrl"];
14820 var handler = function(dlg, e){
14821 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
14822 var k = e.getKey();
14823 if(keyCode instanceof Array){
14824 for(var i = 0, len = keyCode.length; i < len; i++){
14825 if(keyCode[i] == k){
14826 fn.call(scope || window, dlg, k, e);
14832 fn.call(scope || window, dlg, k, e);
14837 this.on("keydown", handler);
14842 * Returns the TabPanel component (creates it if it doesn't exist).
14843 * Note: If you wish to simply check for the existence of tabs without creating them,
14844 * check for a null 'tabs' property.
14845 * @return {Roo.TabPanel} The tabs component
14847 getTabs : function(){
14849 this.el.addClass("x-dlg-auto-tabs");
14850 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
14851 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
14857 * Adds a button to the footer section of the dialog.
14858 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
14859 * object or a valid Roo.DomHelper element config
14860 * @param {Function} handler The function called when the button is clicked
14861 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
14862 * @return {Roo.Button} The new button
14864 addButton : function(config, handler, scope){
14865 var dh = Roo.DomHelper;
14867 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
14869 if(!this.btnContainer){
14870 var tb = this.footer.createChild({
14872 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
14873 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
14875 this.btnContainer = tb.firstChild.firstChild.firstChild;
14880 minWidth: this.minButtonWidth,
14883 if(typeof config == "string"){
14884 bconfig.text = config;
14887 bconfig.dhconfig = config;
14889 Roo.apply(bconfig, config);
14893 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
14894 bconfig.position = Math.max(0, bconfig.position);
14895 fc = this.btnContainer.childNodes[bconfig.position];
14898 var btn = new Roo.Button(
14900 this.btnContainer.insertBefore(document.createElement("td"),fc)
14901 : this.btnContainer.appendChild(document.createElement("td")),
14902 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
14905 this.syncBodyHeight();
14908 * Array of all the buttons that have been added to this dialog via addButton
14913 this.buttons.push(btn);
14918 * Sets the default button to be focused when the dialog is displayed.
14919 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
14920 * @return {Roo.BasicDialog} this
14922 setDefaultButton : function(btn){
14923 this.defaultButton = btn;
14928 getHeaderFooterHeight : function(safe){
14931 height += this.header.getHeight();
14934 var fm = this.footer.getMargins();
14935 height += (this.footer.getHeight()+fm.top+fm.bottom);
14937 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
14938 height += this.centerBg.getPadding("tb");
14943 syncBodyHeight : function()
14945 var bd = this.body, // the text
14946 cb = this.centerBg, // wrapper around bottom.. but does not seem to be used..
14948 var height = this.size.height - this.getHeaderFooterHeight(false);
14949 bd.setHeight(height-bd.getMargins("tb"));
14950 var hh = this.header.getHeight();
14951 var h = this.size.height-hh;
14954 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
14955 bw.setHeight(h-cb.getPadding("tb"));
14957 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
14958 bd.setWidth(bw.getWidth(true));
14960 this.tabs.syncHeight();
14962 this.tabs.el.repaint();
14968 * Restores the previous state of the dialog if Roo.state is configured.
14969 * @return {Roo.BasicDialog} this
14971 restoreState : function(){
14972 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
14973 if(box && box.width){
14974 this.xy = [box.x, box.y];
14975 this.resizeTo(box.width, box.height);
14981 beforeShow : function(){
14983 if(this.fixedcenter){
14984 this.xy = this.el.getCenterXY(true);
14987 Roo.get(document.body).addClass("x-body-masked");
14988 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14991 this.constrainXY();
14995 animShow : function(){
14996 var b = Roo.get(this.animateTarget).getBox();
14997 this.proxy.setSize(b.width, b.height);
14998 this.proxy.setLocation(b.x, b.y);
15000 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
15001 true, .35, this.showEl.createDelegate(this));
15005 * Shows the dialog.
15006 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
15007 * @return {Roo.BasicDialog} this
15009 show : function(animateTarget){
15010 if (this.fireEvent("beforeshow", this) === false){
15013 if(this.syncHeightBeforeShow){
15014 this.syncBodyHeight();
15015 }else if(this.firstShow){
15016 this.firstShow = false;
15017 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
15019 this.animateTarget = animateTarget || this.animateTarget;
15020 if(!this.el.isVisible()){
15022 if(this.animateTarget && Roo.get(this.animateTarget)){
15032 showEl : function(){
15034 this.el.setXY(this.xy);
15036 this.adjustAssets(true);
15039 // IE peekaboo bug - fix found by Dave Fenwick
15043 this.fireEvent("show", this);
15047 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
15048 * dialog itself will receive focus.
15050 focus : function(){
15051 if(this.defaultButton){
15052 this.defaultButton.focus();
15054 this.focusEl.focus();
15059 constrainXY : function(){
15060 if(this.constraintoviewport !== false){
15061 if(!this.viewSize){
15062 if(this.container){
15063 var s = this.container.getSize();
15064 this.viewSize = [s.width, s.height];
15066 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
15069 var s = Roo.get(this.container||document).getScroll();
15071 var x = this.xy[0], y = this.xy[1];
15072 var w = this.size.width, h = this.size.height;
15073 var vw = this.viewSize[0], vh = this.viewSize[1];
15074 // only move it if it needs it
15076 // first validate right/bottom
15077 if(x + w > vw+s.left){
15081 if(y + h > vh+s.top){
15085 // then make sure top/left isn't negative
15097 if(this.isVisible()){
15098 this.el.setLocation(x, y);
15099 this.adjustAssets();
15106 onDrag : function(){
15107 if(!this.proxyDrag){
15108 this.xy = this.el.getXY();
15109 this.adjustAssets();
15114 adjustAssets : function(doShow){
15115 var x = this.xy[0], y = this.xy[1];
15116 var w = this.size.width, h = this.size.height;
15117 if(doShow === true){
15119 this.shadow.show(this.el);
15125 if(this.shadow && this.shadow.isVisible()){
15126 this.shadow.show(this.el);
15128 if(this.shim && this.shim.isVisible()){
15129 this.shim.setBounds(x, y, w, h);
15134 adjustViewport : function(w, h){
15136 w = Roo.lib.Dom.getViewWidth();
15137 h = Roo.lib.Dom.getViewHeight();
15140 this.viewSize = [w, h];
15141 if(this.modal && this.mask.isVisible()){
15142 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
15143 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15145 if(this.isVisible()){
15146 this.constrainXY();
15151 * Destroys this dialog and all its supporting elements (including any tabs, shim,
15152 * shadow, proxy, mask, etc.) Also removes all event listeners.
15153 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
15155 destroy : function(removeEl){
15156 if(this.isVisible()){
15157 this.animateTarget = null;
15160 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
15162 this.tabs.destroy(removeEl);
15175 for(var i = 0, len = this.buttons.length; i < len; i++){
15176 this.buttons[i].destroy();
15179 this.el.removeAllListeners();
15180 if(removeEl === true){
15181 this.el.update("");
15184 Roo.DialogManager.unregister(this);
15188 startMove : function(){
15189 if(this.proxyDrag){
15192 if(this.constraintoviewport !== false){
15193 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
15198 endMove : function(){
15199 if(!this.proxyDrag){
15200 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
15202 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
15205 this.refreshSize();
15206 this.adjustAssets();
15208 this.fireEvent("move", this, this.xy[0], this.xy[1]);
15212 * Brings this dialog to the front of any other visible dialogs
15213 * @return {Roo.BasicDialog} this
15215 toFront : function(){
15216 Roo.DialogManager.bringToFront(this);
15221 * Sends this dialog to the back (under) of any other visible dialogs
15222 * @return {Roo.BasicDialog} this
15224 toBack : function(){
15225 Roo.DialogManager.sendToBack(this);
15230 * Centers this dialog in the viewport
15231 * @return {Roo.BasicDialog} this
15233 center : function(){
15234 var xy = this.el.getCenterXY(true);
15235 this.moveTo(xy[0], xy[1]);
15240 * Moves the dialog's top-left corner to the specified point
15241 * @param {Number} x
15242 * @param {Number} y
15243 * @return {Roo.BasicDialog} this
15245 moveTo : function(x, y){
15247 if(this.isVisible()){
15248 this.el.setXY(this.xy);
15249 this.adjustAssets();
15255 * Aligns the dialog to the specified element
15256 * @param {String/HTMLElement/Roo.Element} element The element to align to.
15257 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
15258 * @param {Array} offsets (optional) Offset the positioning by [x, y]
15259 * @return {Roo.BasicDialog} this
15261 alignTo : function(element, position, offsets){
15262 this.xy = this.el.getAlignToXY(element, position, offsets);
15263 if(this.isVisible()){
15264 this.el.setXY(this.xy);
15265 this.adjustAssets();
15271 * Anchors an element to another element and realigns it when the window is resized.
15272 * @param {String/HTMLElement/Roo.Element} element The element to align to.
15273 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
15274 * @param {Array} offsets (optional) Offset the positioning by [x, y]
15275 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
15276 * is a number, it is used as the buffer delay (defaults to 50ms).
15277 * @return {Roo.BasicDialog} this
15279 anchorTo : function(el, alignment, offsets, monitorScroll){
15280 var action = function(){
15281 this.alignTo(el, alignment, offsets);
15283 Roo.EventManager.onWindowResize(action, this);
15284 var tm = typeof monitorScroll;
15285 if(tm != 'undefined'){
15286 Roo.EventManager.on(window, 'scroll', action, this,
15287 {buffer: tm == 'number' ? monitorScroll : 50});
15294 * Returns true if the dialog is visible
15295 * @return {Boolean}
15297 isVisible : function(){
15298 return this.el.isVisible();
15302 animHide : function(callback){
15303 var b = Roo.get(this.animateTarget).getBox();
15305 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
15307 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
15308 this.hideEl.createDelegate(this, [callback]));
15312 * Hides the dialog.
15313 * @param {Function} callback (optional) Function to call when the dialog is hidden
15314 * @return {Roo.BasicDialog} this
15316 hide : function(callback){
15317 if (this.fireEvent("beforehide", this) === false){
15321 this.shadow.hide();
15326 // sometimes animateTarget seems to get set.. causing problems...
15327 // this just double checks..
15328 if(this.animateTarget && Roo.get(this.animateTarget)) {
15329 this.animHide(callback);
15332 this.hideEl(callback);
15338 hideEl : function(callback){
15342 Roo.get(document.body).removeClass("x-body-masked");
15344 this.fireEvent("hide", this);
15345 if(typeof callback == "function"){
15351 hideAction : function(){
15352 this.setLeft("-10000px");
15353 this.setTop("-10000px");
15354 this.setStyle("visibility", "hidden");
15358 refreshSize : function(){
15359 this.size = this.el.getSize();
15360 this.xy = this.el.getXY();
15361 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
15365 // z-index is managed by the DialogManager and may be overwritten at any time
15366 setZIndex : function(index){
15368 this.mask.setStyle("z-index", index);
15371 this.shim.setStyle("z-index", ++index);
15374 this.shadow.setZIndex(++index);
15376 this.el.setStyle("z-index", ++index);
15378 this.proxy.setStyle("z-index", ++index);
15381 this.resizer.proxy.setStyle("z-index", ++index);
15384 this.lastZIndex = index;
15388 * Returns the element for this dialog
15389 * @return {Roo.Element} The underlying dialog Element
15391 getEl : function(){
15397 * @class Roo.DialogManager
15398 * Provides global access to BasicDialogs that have been created and
15399 * support for z-indexing (layering) multiple open dialogs.
15401 Roo.DialogManager = function(){
15403 var accessList = [];
15407 var sortDialogs = function(d1, d2){
15408 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
15412 var orderDialogs = function(){
15413 accessList.sort(sortDialogs);
15414 var seed = Roo.DialogManager.zseed;
15415 for(var i = 0, len = accessList.length; i < len; i++){
15416 var dlg = accessList[i];
15418 dlg.setZIndex(seed + (i*10));
15425 * The starting z-index for BasicDialogs (defaults to 9000)
15426 * @type Number The z-index value
15431 register : function(dlg){
15432 list[dlg.id] = dlg;
15433 accessList.push(dlg);
15437 unregister : function(dlg){
15438 delete list[dlg.id];
15441 if(!accessList.indexOf){
15442 for( i = 0, len = accessList.length; i < len; i++){
15443 if(accessList[i] == dlg){
15444 accessList.splice(i, 1);
15449 i = accessList.indexOf(dlg);
15451 accessList.splice(i, 1);
15457 * Gets a registered dialog by id
15458 * @param {String/Object} id The id of the dialog or a dialog
15459 * @return {Roo.BasicDialog} this
15461 get : function(id){
15462 return typeof id == "object" ? id : list[id];
15466 * Brings the specified dialog to the front
15467 * @param {String/Object} dlg The id of the dialog or a dialog
15468 * @return {Roo.BasicDialog} this
15470 bringToFront : function(dlg){
15471 dlg = this.get(dlg);
15474 dlg._lastAccess = new Date().getTime();
15481 * Sends the specified dialog to the back
15482 * @param {String/Object} dlg The id of the dialog or a dialog
15483 * @return {Roo.BasicDialog} this
15485 sendToBack : function(dlg){
15486 dlg = this.get(dlg);
15487 dlg._lastAccess = -(new Date().getTime());
15493 * Hides all dialogs
15495 hideAll : function(){
15496 for(var id in list){
15497 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
15506 * @class Roo.LayoutDialog
15507 * @extends Roo.BasicDialog
15508 * Dialog which provides adjustments for working with a layout in a Dialog.
15509 * Add your necessary layout config options to the dialog's config.<br>
15510 * Example usage (including a nested layout):
15513 dialog = new Roo.LayoutDialog("download-dlg", {
15522 // layout config merges with the dialog config
15524 tabPosition: "top",
15525 alwaysShowTabs: true
15528 dialog.addKeyListener(27, dialog.hide, dialog);
15529 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
15530 dialog.addButton("Build It!", this.getDownload, this);
15532 // we can even add nested layouts
15533 var innerLayout = new Roo.BorderLayout("dl-inner", {
15543 innerLayout.beginUpdate();
15544 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
15545 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
15546 innerLayout.endUpdate(true);
15548 var layout = dialog.getLayout();
15549 layout.beginUpdate();
15550 layout.add("center", new Roo.ContentPanel("standard-panel",
15551 {title: "Download the Source", fitToFrame:true}));
15552 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
15553 {title: "Build your own roo.js"}));
15554 layout.getRegion("center").showPanel(sp);
15555 layout.endUpdate();
15559 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
15560 * @param {Object} config configuration options
15562 Roo.LayoutDialog = function(el, cfg){
15565 if (typeof(cfg) == 'undefined') {
15566 config = Roo.apply({}, el);
15567 // not sure why we use documentElement here.. - it should always be body.
15568 // IE7 borks horribly if we use documentElement.
15569 // webkit also does not like documentElement - it creates a body element...
15570 el = Roo.get( document.body || document.documentElement ).createChild();
15571 //config.autoCreate = true;
15575 config.autoTabs = false;
15576 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
15577 this.body.setStyle({overflow:"hidden", position:"relative"});
15578 this.layout = new Roo.BorderLayout(this.body.dom, config);
15579 this.layout.monitorWindowResize = false;
15580 this.el.addClass("x-dlg-auto-layout");
15581 // fix case when center region overwrites center function
15582 this.center = Roo.BasicDialog.prototype.center;
15583 this.on("show", this.layout.layout, this.layout, true);
15584 if (config.items) {
15585 var xitems = config.items;
15586 delete config.items;
15587 Roo.each(xitems, this.addxtype, this);
15592 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
15594 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
15597 endUpdate : function(){
15598 this.layout.endUpdate();
15602 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
15605 beginUpdate : function(){
15606 this.layout.beginUpdate();
15610 * Get the BorderLayout for this dialog
15611 * @return {Roo.BorderLayout}
15613 getLayout : function(){
15614 return this.layout;
15617 showEl : function(){
15618 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
15620 this.layout.layout();
15625 // Use the syncHeightBeforeShow config option to control this automatically
15626 syncBodyHeight : function(){
15627 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
15628 if(this.layout){this.layout.layout();}
15632 * Add an xtype element (actually adds to the layout.)
15633 * @return {Object} xdata xtype object data.
15636 addxtype : function(c) {
15637 return this.layout.addxtype(c);
15641 * Ext JS Library 1.1.1
15642 * Copyright(c) 2006-2007, Ext JS, LLC.
15644 * Originally Released Under LGPL - original licence link has changed is not relivant.
15647 * <script type="text/javascript">
15651 * @class Roo.MessageBox
15652 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
15656 Roo.Msg.alert('Status', 'Changes saved successfully.');
15658 // Prompt for user data:
15659 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
15661 // process text value...
15665 // Show a dialog using config options:
15667 title:'Save Changes?',
15668 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
15669 buttons: Roo.Msg.YESNOCANCEL,
15676 Roo.MessageBox = function(){
15677 var dlg, opt, mask, waitTimer;
15678 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
15679 var buttons, activeTextEl, bwidth;
15682 var handleButton = function(button){
15684 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
15688 var handleHide = function(){
15689 if(opt && opt.cls){
15690 dlg.el.removeClass(opt.cls);
15693 Roo.TaskMgr.stop(waitTimer);
15699 var updateButtons = function(b){
15702 buttons["ok"].hide();
15703 buttons["cancel"].hide();
15704 buttons["yes"].hide();
15705 buttons["no"].hide();
15706 dlg.footer.dom.style.display = 'none';
15709 dlg.footer.dom.style.display = '';
15710 for(var k in buttons){
15711 if(typeof buttons[k] != "function"){
15714 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
15715 width += buttons[k].el.getWidth()+15;
15725 var handleEsc = function(d, k, e){
15726 if(opt && opt.closable !== false){
15736 * Returns a reference to the underlying {@link Roo.BasicDialog} element
15737 * @return {Roo.BasicDialog} The BasicDialog element
15739 getDialog : function(){
15741 dlg = new Roo.BasicDialog("x-msg-box", {
15746 constraintoviewport:false,
15748 collapsible : false,
15751 width:400, height:100,
15752 buttonAlign:"center",
15753 closeClick : function(){
15754 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
15755 handleButton("no");
15757 handleButton("cancel");
15761 dlg.on("hide", handleHide);
15763 dlg.addKeyListener(27, handleEsc);
15765 var bt = this.buttonText;
15766 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
15767 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
15768 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
15769 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
15770 bodyEl = dlg.body.createChild({
15772 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>'
15774 msgEl = bodyEl.dom.firstChild;
15775 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
15776 textboxEl.enableDisplayMode();
15777 textboxEl.addKeyListener([10,13], function(){
15778 if(dlg.isVisible() && opt && opt.buttons){
15779 if(opt.buttons.ok){
15780 handleButton("ok");
15781 }else if(opt.buttons.yes){
15782 handleButton("yes");
15786 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
15787 textareaEl.enableDisplayMode();
15788 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
15789 progressEl.enableDisplayMode();
15790 var pf = progressEl.dom.firstChild;
15792 pp = Roo.get(pf.firstChild);
15793 pp.setHeight(pf.offsetHeight);
15801 * Updates the message box body text
15802 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
15803 * the XHTML-compliant non-breaking space character '&#160;')
15804 * @return {Roo.MessageBox} This message box
15806 updateText : function(text){
15807 if(!dlg.isVisible() && !opt.width){
15808 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
15810 msgEl.innerHTML = text || ' ';
15812 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
15813 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
15815 Math.min(opt.width || cw , this.maxWidth),
15816 Math.max(opt.minWidth || this.minWidth, bwidth)
15819 activeTextEl.setWidth(w);
15821 if(dlg.isVisible()){
15822 dlg.fixedcenter = false;
15824 // to big, make it scroll. = But as usual stupid IE does not support
15827 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
15828 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
15829 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
15831 bodyEl.dom.style.height = '';
15832 bodyEl.dom.style.overflowY = '';
15835 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
15837 bodyEl.dom.style.overflowX = '';
15840 dlg.setContentSize(w, bodyEl.getHeight());
15841 if(dlg.isVisible()){
15842 dlg.fixedcenter = true;
15848 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
15849 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
15850 * @param {Number} value Any number between 0 and 1 (e.g., .5)
15851 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
15852 * @return {Roo.MessageBox} This message box
15854 updateProgress : function(value, text){
15856 this.updateText(text);
15858 if (pp) { // weird bug on my firefox - for some reason this is not defined
15859 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
15865 * Returns true if the message box is currently displayed
15866 * @return {Boolean} True if the message box is visible, else false
15868 isVisible : function(){
15869 return dlg && dlg.isVisible();
15873 * Hides the message box if it is displayed
15876 if(this.isVisible()){
15882 * Displays a new message box, or reinitializes an existing message box, based on the config options
15883 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
15884 * The following config object properties are supported:
15886 Property Type Description
15887 ---------- --------------- ------------------------------------------------------------------------------------
15888 animEl String/Element An id or Element from which the message box should animate as it opens and
15889 closes (defaults to undefined)
15890 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
15891 cancel:'Bar'}), or false to not show any buttons (defaults to false)
15892 closable Boolean False to hide the top-right close button (defaults to true). Note that
15893 progress and wait dialogs will ignore this property and always hide the
15894 close button as they can only be closed programmatically.
15895 cls String A custom CSS class to apply to the message box element
15896 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
15897 displayed (defaults to 75)
15898 fn Function A callback function to execute after closing the dialog. The arguments to the
15899 function will be btn (the name of the button that was clicked, if applicable,
15900 e.g. "ok"), and text (the value of the active text field, if applicable).
15901 Progress and wait dialogs will ignore this option since they do not respond to
15902 user actions and can only be closed programmatically, so any required function
15903 should be called by the same code after it closes the dialog.
15904 icon String A CSS class that provides a background image to be used as an icon for
15905 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
15906 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
15907 minWidth Number The minimum width in pixels of the message box (defaults to 100)
15908 modal Boolean False to allow user interaction with the page while the message box is
15909 displayed (defaults to true)
15910 msg String A string that will replace the existing message box body text (defaults
15911 to the XHTML-compliant non-breaking space character ' ')
15912 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
15913 progress Boolean True to display a progress bar (defaults to false)
15914 progressText String The text to display inside the progress bar if progress = true (defaults to '')
15915 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
15916 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
15917 title String The title text
15918 value String The string value to set into the active textbox element if displayed
15919 wait Boolean True to display a progress bar (defaults to false)
15920 width Number The width of the dialog in pixels
15927 msg: 'Please enter your address:',
15929 buttons: Roo.MessageBox.OKCANCEL,
15932 animEl: 'addAddressBtn'
15935 * @param {Object} config Configuration options
15936 * @return {Roo.MessageBox} This message box
15938 show : function(options)
15941 // this causes nightmares if you show one dialog after another
15942 // especially on callbacks..
15944 if(this.isVisible()){
15947 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
15948 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
15949 Roo.log("New Dialog Message:" + options.msg )
15950 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
15951 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
15954 var d = this.getDialog();
15956 d.setTitle(opt.title || " ");
15957 d.close.setDisplayed(opt.closable !== false);
15958 activeTextEl = textboxEl;
15959 opt.prompt = opt.prompt || (opt.multiline ? true : false);
15964 textareaEl.setHeight(typeof opt.multiline == "number" ?
15965 opt.multiline : this.defaultTextHeight);
15966 activeTextEl = textareaEl;
15975 progressEl.setDisplayed(opt.progress === true);
15976 this.updateProgress(0);
15977 activeTextEl.dom.value = opt.value || "";
15979 dlg.setDefaultButton(activeTextEl);
15981 var bs = opt.buttons;
15984 db = buttons["ok"];
15985 }else if(bs && bs.yes){
15986 db = buttons["yes"];
15988 dlg.setDefaultButton(db);
15990 bwidth = updateButtons(opt.buttons);
15991 this.updateText(opt.msg);
15993 d.el.addClass(opt.cls);
15995 d.proxyDrag = opt.proxyDrag === true;
15996 d.modal = opt.modal !== false;
15997 d.mask = opt.modal !== false ? mask : false;
15998 if(!d.isVisible()){
15999 // force it to the end of the z-index stack so it gets a cursor in FF
16000 document.body.appendChild(dlg.el.dom);
16001 d.animateTarget = null;
16002 d.show(options.animEl);
16008 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
16009 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
16010 * and closing the message box when the process is complete.
16011 * @param {String} title The title bar text
16012 * @param {String} msg The message box body text
16013 * @return {Roo.MessageBox} This message box
16015 progress : function(title, msg){
16022 minWidth: this.minProgressWidth,
16029 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
16030 * If a callback function is passed it will be called after the user clicks the button, and the
16031 * id of the button that was clicked will be passed as the only parameter to the callback
16032 * (could also be the top-right close button).
16033 * @param {String} title The title bar text
16034 * @param {String} msg The message box body text
16035 * @param {Function} fn (optional) The callback function invoked after the message box is closed
16036 * @param {Object} scope (optional) The scope of the callback function
16037 * @return {Roo.MessageBox} This message box
16039 alert : function(title, msg, fn, scope){
16052 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
16053 * interaction while waiting for a long-running process to complete that does not have defined intervals.
16054 * You are responsible for closing the message box when the process is complete.
16055 * @param {String} msg The message box body text
16056 * @param {String} title (optional) The title bar text
16057 * @return {Roo.MessageBox} This message box
16059 wait : function(msg, title){
16070 waitTimer = Roo.TaskMgr.start({
16072 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
16080 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
16081 * If a callback function is passed it will be called after the user clicks either button, and the id of the
16082 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
16083 * @param {String} title The title bar text
16084 * @param {String} msg The message box body text
16085 * @param {Function} fn (optional) The callback function invoked after the message box is closed
16086 * @param {Object} scope (optional) The scope of the callback function
16087 * @return {Roo.MessageBox} This message box
16089 confirm : function(title, msg, fn, scope){
16093 buttons: this.YESNO,
16102 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
16103 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
16104 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
16105 * (could also be the top-right close button) and the text that was entered will be passed as the two
16106 * parameters to the callback.
16107 * @param {String} title The title bar text
16108 * @param {String} msg The message box body text
16109 * @param {Function} fn (optional) The callback function invoked after the message box is closed
16110 * @param {Object} scope (optional) The scope of the callback function
16111 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
16112 * property, or the height in pixels to create the textbox (defaults to false / single-line)
16113 * @return {Roo.MessageBox} This message box
16115 prompt : function(title, msg, fn, scope, multiline){
16119 buttons: this.OKCANCEL,
16124 multiline: multiline,
16131 * Button config that displays a single OK button
16136 * Button config that displays Yes and No buttons
16139 YESNO : {yes:true, no:true},
16141 * Button config that displays OK and Cancel buttons
16144 OKCANCEL : {ok:true, cancel:true},
16146 * Button config that displays Yes, No and Cancel buttons
16149 YESNOCANCEL : {yes:true, no:true, cancel:true},
16152 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
16155 defaultTextHeight : 75,
16157 * The maximum width in pixels of the message box (defaults to 600)
16162 * The minimum width in pixels of the message box (defaults to 100)
16167 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
16168 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
16171 minProgressWidth : 250,
16173 * An object containing the default button text strings that can be overriden for localized language support.
16174 * Supported properties are: ok, cancel, yes and no.
16175 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
16188 * Shorthand for {@link Roo.MessageBox}
16190 Roo.Msg = Roo.MessageBox;/*
16192 * Ext JS Library 1.1.1
16193 * Copyright(c) 2006-2007, Ext JS, LLC.
16195 * Originally Released Under LGPL - original licence link has changed is not relivant.
16198 * <script type="text/javascript">
16201 * @class Roo.QuickTips
16202 * Provides attractive and customizable tooltips for any element.
16205 Roo.QuickTips = function(){
16206 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
16207 var ce, bd, xy, dd;
16208 var visible = false, disabled = true, inited = false;
16209 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
16211 var onOver = function(e){
16215 var t = e.getTarget();
16216 if(!t || t.nodeType !== 1 || t == document || t == document.body){
16219 if(ce && t == ce.el){
16220 clearTimeout(hideProc);
16223 if(t && tagEls[t.id]){
16224 tagEls[t.id].el = t;
16225 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
16228 var ttp, et = Roo.fly(t);
16229 var ns = cfg.namespace;
16230 if(tm.interceptTitles && t.title){
16233 t.removeAttribute("title");
16234 e.preventDefault();
16236 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute);
16239 showProc = show.defer(tm.showDelay, tm, [{
16242 width: et.getAttributeNS(ns, cfg.width),
16243 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
16244 title: et.getAttributeNS(ns, cfg.title),
16245 cls: et.getAttributeNS(ns, cfg.cls)
16250 var onOut = function(e){
16251 clearTimeout(showProc);
16252 var t = e.getTarget();
16253 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
16254 hideProc = setTimeout(hide, tm.hideDelay);
16258 var onMove = function(e){
16264 if(tm.trackMouse && ce){
16269 var onDown = function(e){
16270 clearTimeout(showProc);
16271 clearTimeout(hideProc);
16273 if(tm.hideOnClick){
16276 tm.enable.defer(100, tm);
16281 var getPad = function(){
16282 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
16285 var show = function(o){
16289 clearTimeout(dismissProc);
16291 if(removeCls){ // in case manually hidden
16292 el.removeClass(removeCls);
16296 el.addClass(ce.cls);
16297 removeCls = ce.cls;
16300 tipTitle.update(ce.title);
16303 tipTitle.update('');
16306 el.dom.style.width = tm.maxWidth+'px';
16307 //tipBody.dom.style.width = '';
16308 tipBodyText.update(o.text);
16309 var p = getPad(), w = ce.width;
16311 var td = tipBodyText.dom;
16312 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
16313 if(aw > tm.maxWidth){
16315 }else if(aw < tm.minWidth){
16321 //tipBody.setWidth(w);
16322 el.setWidth(parseInt(w, 10) + p);
16323 if(ce.autoHide === false){
16324 close.setDisplayed(true);
16329 close.setDisplayed(false);
16335 el.avoidY = xy[1]-18;
16340 el.setStyle("visibility", "visible");
16341 el.fadeIn({callback: afterShow});
16347 var afterShow = function(){
16351 if(tm.autoDismiss && ce.autoHide !== false){
16352 dismissProc = setTimeout(hide, tm.autoDismissDelay);
16357 var hide = function(noanim){
16358 clearTimeout(dismissProc);
16359 clearTimeout(hideProc);
16361 if(el.isVisible()){
16363 if(noanim !== true && tm.animate){
16364 el.fadeOut({callback: afterHide});
16371 var afterHide = function(){
16374 el.removeClass(removeCls);
16381 * @cfg {Number} minWidth
16382 * The minimum width of the quick tip (defaults to 40)
16386 * @cfg {Number} maxWidth
16387 * The maximum width of the quick tip (defaults to 300)
16391 * @cfg {Boolean} interceptTitles
16392 * True to automatically use the element's DOM title value if available (defaults to false)
16394 interceptTitles : false,
16396 * @cfg {Boolean} trackMouse
16397 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
16399 trackMouse : false,
16401 * @cfg {Boolean} hideOnClick
16402 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
16404 hideOnClick : true,
16406 * @cfg {Number} showDelay
16407 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
16411 * @cfg {Number} hideDelay
16412 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
16416 * @cfg {Boolean} autoHide
16417 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
16418 * Used in conjunction with hideDelay.
16423 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
16424 * (defaults to true). Used in conjunction with autoDismissDelay.
16426 autoDismiss : true,
16429 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
16431 autoDismissDelay : 5000,
16433 * @cfg {Boolean} animate
16434 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
16439 * @cfg {String} title
16440 * Title text to display (defaults to ''). This can be any valid HTML markup.
16444 * @cfg {String} text
16445 * Body text to display (defaults to ''). This can be any valid HTML markup.
16449 * @cfg {String} cls
16450 * A CSS class to apply to the base quick tip element (defaults to '').
16454 * @cfg {Number} width
16455 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
16456 * minWidth or maxWidth.
16461 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
16462 * or display QuickTips in a page.
16465 tm = Roo.QuickTips;
16466 cfg = tm.tagConfig;
16468 if(!Roo.isReady){ // allow calling of init() before onReady
16469 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
16472 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
16473 el.fxDefaults = {stopFx: true};
16474 // maximum custom styling
16475 //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>');
16476 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>');
16477 tipTitle = el.child('h3');
16478 tipTitle.enableDisplayMode("block");
16479 tipBody = el.child('div.x-tip-bd');
16480 tipBodyText = el.child('div.x-tip-bd-inner');
16481 //bdLeft = el.child('div.x-tip-bd-left');
16482 //bdRight = el.child('div.x-tip-bd-right');
16483 close = el.child('div.x-tip-close');
16484 close.enableDisplayMode("block");
16485 close.on("click", hide);
16486 var d = Roo.get(document);
16487 d.on("mousedown", onDown);
16488 d.on("mouseover", onOver);
16489 d.on("mouseout", onOut);
16490 d.on("mousemove", onMove);
16491 esc = d.addKeyListener(27, hide);
16494 dd = el.initDD("default", null, {
16495 onDrag : function(){
16499 dd.setHandleElId(tipTitle.id);
16508 * Configures a new quick tip instance and assigns it to a target element. The following config options
16511 Property Type Description
16512 ---------- --------------------- ------------------------------------------------------------------------
16513 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
16515 * @param {Object} config The config object
16517 register : function(config){
16518 var cs = config instanceof Array ? config : arguments;
16519 for(var i = 0, len = cs.length; i < len; i++) {
16521 var target = c.target;
16523 if(target instanceof Array){
16524 for(var j = 0, jlen = target.length; j < jlen; j++){
16525 tagEls[target[j]] = c;
16528 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
16535 * Removes this quick tip from its element and destroys it.
16536 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
16538 unregister : function(el){
16539 delete tagEls[Roo.id(el)];
16543 * Enable this quick tip.
16545 enable : function(){
16546 if(inited && disabled){
16548 if(locks.length < 1){
16555 * Disable this quick tip.
16557 disable : function(){
16559 clearTimeout(showProc);
16560 clearTimeout(hideProc);
16561 clearTimeout(dismissProc);
16569 * Returns true if the quick tip is enabled, else false.
16571 isEnabled : function(){
16578 attribute : "qtip",
16588 // backwards compat
16589 Roo.QuickTips.tips = Roo.QuickTips.register;/*
16591 * Ext JS Library 1.1.1
16592 * Copyright(c) 2006-2007, Ext JS, LLC.
16594 * Originally Released Under LGPL - original licence link has changed is not relivant.
16597 * <script type="text/javascript">
16602 * @class Roo.tree.TreePanel
16603 * @extends Roo.data.Tree
16605 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
16606 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
16607 * @cfg {Boolean} enableDD true to enable drag and drop
16608 * @cfg {Boolean} enableDrag true to enable just drag
16609 * @cfg {Boolean} enableDrop true to enable just drop
16610 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
16611 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
16612 * @cfg {String} ddGroup The DD group this TreePanel belongs to
16613 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
16614 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
16615 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
16616 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
16617 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
16618 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
16619 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
16620 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
16621 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
16622 * @cfg {Object|Roo.tree.TreeEditor} editor The TreeEditor or xtype data to display when clicked.
16623 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
16624 * @cfg {Function} renderer DEPRECATED - use TreeLoader:create event / 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>
16625 * @cfg {Function} rendererTip DEPRECATED - use TreeLoader:create event / 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>
16628 * @param {String/HTMLElement/Element} el The container element
16629 * @param {Object} config
16631 Roo.tree.TreePanel = function(el, config){
16633 var loader = false;
16635 root = config.root;
16636 delete config.root;
16638 if (config.loader) {
16639 loader = config.loader;
16640 delete config.loader;
16643 Roo.apply(this, config);
16644 Roo.tree.TreePanel.superclass.constructor.call(this);
16645 this.el = Roo.get(el);
16646 this.el.addClass('x-tree');
16647 //console.log(root);
16649 this.setRootNode( Roo.factory(root, Roo.tree));
16652 this.loader = Roo.factory(loader, Roo.tree);
16655 * Read-only. The id of the container element becomes this TreePanel's id.
16657 this.id = this.el.id;
16660 * @event beforeload
16661 * Fires before a node is loaded, return false to cancel
16662 * @param {Node} node The node being loaded
16664 "beforeload" : true,
16667 * Fires when a node is loaded
16668 * @param {Node} node The node that was loaded
16672 * @event textchange
16673 * Fires when the text for a node is changed
16674 * @param {Node} node The node
16675 * @param {String} text The new text
16676 * @param {String} oldText The old text
16678 "textchange" : true,
16680 * @event beforeexpand
16681 * Fires before a node is expanded, return false to cancel.
16682 * @param {Node} node The node
16683 * @param {Boolean} deep
16684 * @param {Boolean} anim
16686 "beforeexpand" : true,
16688 * @event beforecollapse
16689 * Fires before a node is collapsed, return false to cancel.
16690 * @param {Node} node The node
16691 * @param {Boolean} deep
16692 * @param {Boolean} anim
16694 "beforecollapse" : true,
16697 * Fires when a node is expanded
16698 * @param {Node} node The node
16702 * @event disabledchange
16703 * Fires when the disabled status of a node changes
16704 * @param {Node} node The node
16705 * @param {Boolean} disabled
16707 "disabledchange" : true,
16710 * Fires when a node is collapsed
16711 * @param {Node} node The node
16715 * @event beforeclick
16716 * Fires before click processing on a node. Return false to cancel the default action.
16717 * @param {Node} node The node
16718 * @param {Roo.EventObject} e The event object
16720 "beforeclick":true,
16722 * @event checkchange
16723 * Fires when a node with a checkbox's checked property changes
16724 * @param {Node} this This node
16725 * @param {Boolean} checked
16727 "checkchange":true,
16730 * Fires when a node is clicked
16731 * @param {Node} node The node
16732 * @param {Roo.EventObject} e The event object
16737 * Fires when a node is double clicked
16738 * @param {Node} node The node
16739 * @param {Roo.EventObject} e The event object
16743 * @event contextmenu
16744 * Fires when a node is right clicked
16745 * @param {Node} node The node
16746 * @param {Roo.EventObject} e The event object
16748 "contextmenu":true,
16750 * @event beforechildrenrendered
16751 * Fires right before the child nodes for a node are rendered
16752 * @param {Node} node The node
16754 "beforechildrenrendered":true,
16757 * Fires when a node starts being dragged
16758 * @param {Roo.tree.TreePanel} this
16759 * @param {Roo.tree.TreeNode} node
16760 * @param {event} e The raw browser event
16762 "startdrag" : true,
16765 * Fires when a drag operation is complete
16766 * @param {Roo.tree.TreePanel} this
16767 * @param {Roo.tree.TreeNode} node
16768 * @param {event} e The raw browser event
16773 * Fires when a dragged node is dropped on a valid DD target
16774 * @param {Roo.tree.TreePanel} this
16775 * @param {Roo.tree.TreeNode} node
16776 * @param {DD} dd The dd it was dropped on
16777 * @param {event} e The raw browser event
16781 * @event beforenodedrop
16782 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
16783 * passed to handlers has the following properties:<br />
16784 * <ul style="padding:5px;padding-left:16px;">
16785 * <li>tree - The TreePanel</li>
16786 * <li>target - The node being targeted for the drop</li>
16787 * <li>data - The drag data from the drag source</li>
16788 * <li>point - The point of the drop - append, above or below</li>
16789 * <li>source - The drag source</li>
16790 * <li>rawEvent - Raw mouse event</li>
16791 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
16792 * to be inserted by setting them on this object.</li>
16793 * <li>cancel - Set this to true to cancel the drop.</li>
16795 * @param {Object} dropEvent
16797 "beforenodedrop" : true,
16800 * Fires after a DD object is dropped on a node in this tree. The dropEvent
16801 * passed to handlers has the following properties:<br />
16802 * <ul style="padding:5px;padding-left:16px;">
16803 * <li>tree - The TreePanel</li>
16804 * <li>target - The node being targeted for the drop</li>
16805 * <li>data - The drag data from the drag source</li>
16806 * <li>point - The point of the drop - append, above or below</li>
16807 * <li>source - The drag source</li>
16808 * <li>rawEvent - Raw mouse event</li>
16809 * <li>dropNode - Dropped node(s).</li>
16811 * @param {Object} dropEvent
16815 * @event nodedragover
16816 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
16817 * passed to handlers has the following properties:<br />
16818 * <ul style="padding:5px;padding-left:16px;">
16819 * <li>tree - The TreePanel</li>
16820 * <li>target - The node being targeted for the drop</li>
16821 * <li>data - The drag data from the drag source</li>
16822 * <li>point - The point of the drop - append, above or below</li>
16823 * <li>source - The drag source</li>
16824 * <li>rawEvent - Raw mouse event</li>
16825 * <li>dropNode - Drop node(s) provided by the source.</li>
16826 * <li>cancel - Set this to true to signal drop not allowed.</li>
16828 * @param {Object} dragOverEvent
16830 "nodedragover" : true
16833 if(this.singleExpand){
16834 this.on("beforeexpand", this.restrictExpand, this);
16837 this.editor.tree = this;
16838 this.editor = Roo.factory(this.editor, Roo.tree);
16841 if (this.selModel) {
16842 this.selModel = Roo.factory(this.selModel, Roo.tree);
16846 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
16847 rootVisible : true,
16848 animate: Roo.enableFx,
16851 hlDrop : Roo.enableFx,
16855 rendererTip: false,
16857 restrictExpand : function(node){
16858 var p = node.parentNode;
16860 if(p.expandedChild && p.expandedChild.parentNode == p){
16861 p.expandedChild.collapse();
16863 p.expandedChild = node;
16867 // private override
16868 setRootNode : function(node){
16869 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
16870 if(!this.rootVisible){
16871 node.ui = new Roo.tree.RootTreeNodeUI(node);
16877 * Returns the container element for this TreePanel
16879 getEl : function(){
16884 * Returns the default TreeLoader for this TreePanel
16886 getLoader : function(){
16887 return this.loader;
16893 expandAll : function(){
16894 this.root.expand(true);
16898 * Collapse all nodes
16900 collapseAll : function(){
16901 this.root.collapse(true);
16905 * Returns the selection model used by this TreePanel
16907 getSelectionModel : function(){
16908 if(!this.selModel){
16909 this.selModel = new Roo.tree.DefaultSelectionModel();
16911 return this.selModel;
16915 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
16916 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
16917 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
16920 getChecked : function(a, startNode){
16921 startNode = startNode || this.root;
16923 var f = function(){
16924 if(this.attributes.checked){
16925 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
16928 startNode.cascade(f);
16933 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
16934 * @param {String} path
16935 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
16936 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
16937 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
16939 expandPath : function(path, attr, callback){
16940 attr = attr || "id";
16941 var keys = path.split(this.pathSeparator);
16942 var curNode = this.root;
16943 if(curNode.attributes[attr] != keys[1]){ // invalid root
16945 callback(false, null);
16950 var f = function(){
16951 if(++index == keys.length){
16953 callback(true, curNode);
16957 var c = curNode.findChild(attr, keys[index]);
16960 callback(false, curNode);
16965 c.expand(false, false, f);
16967 curNode.expand(false, false, f);
16971 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
16972 * @param {String} path
16973 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
16974 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
16975 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
16977 selectPath : function(path, attr, callback){
16978 attr = attr || "id";
16979 var keys = path.split(this.pathSeparator);
16980 var v = keys.pop();
16981 if(keys.length > 0){
16982 var f = function(success, node){
16983 if(success && node){
16984 var n = node.findChild(attr, v);
16990 }else if(callback){
16991 callback(false, n);
16995 callback(false, n);
16999 this.expandPath(keys.join(this.pathSeparator), attr, f);
17001 this.root.select();
17003 callback(true, this.root);
17008 getTreeEl : function(){
17013 * Trigger rendering of this TreePanel
17015 render : function(){
17016 if (this.innerCt) {
17017 return this; // stop it rendering more than once!!
17020 this.innerCt = this.el.createChild({tag:"ul",
17021 cls:"x-tree-root-ct " +
17022 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
17024 if(this.containerScroll){
17025 Roo.dd.ScrollManager.register(this.el);
17027 if((this.enableDD || this.enableDrop) && !this.dropZone){
17029 * The dropZone used by this tree if drop is enabled
17030 * @type Roo.tree.TreeDropZone
17032 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
17033 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
17036 if((this.enableDD || this.enableDrag) && !this.dragZone){
17038 * The dragZone used by this tree if drag is enabled
17039 * @type Roo.tree.TreeDragZone
17041 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
17042 ddGroup: this.ddGroup || "TreeDD",
17043 scroll: this.ddScroll
17046 this.getSelectionModel().init(this);
17048 Roo.log("ROOT not set in tree");
17051 this.root.render();
17052 if(!this.rootVisible){
17053 this.root.renderChildren();
17059 * Ext JS Library 1.1.1
17060 * Copyright(c) 2006-2007, Ext JS, LLC.
17062 * Originally Released Under LGPL - original licence link has changed is not relivant.
17065 * <script type="text/javascript">
17070 * @class Roo.tree.DefaultSelectionModel
17071 * @extends Roo.util.Observable
17072 * The default single selection for a TreePanel.
17073 * @param {Object} cfg Configuration
17075 Roo.tree.DefaultSelectionModel = function(cfg){
17076 this.selNode = null;
17082 * @event selectionchange
17083 * Fires when the selected node changes
17084 * @param {DefaultSelectionModel} this
17085 * @param {TreeNode} node the new selection
17087 "selectionchange" : true,
17090 * @event beforeselect
17091 * Fires before the selected node changes, return false to cancel the change
17092 * @param {DefaultSelectionModel} this
17093 * @param {TreeNode} node the new selection
17094 * @param {TreeNode} node the old selection
17096 "beforeselect" : true
17099 Roo.tree.DefaultSelectionModel.superclass.constructor.call(this,cfg);
17102 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
17103 init : function(tree){
17105 tree.getTreeEl().on("keydown", this.onKeyDown, this);
17106 tree.on("click", this.onNodeClick, this);
17109 onNodeClick : function(node, e){
17110 if (e.ctrlKey && this.selNode == node) {
17111 this.unselect(node);
17119 * @param {TreeNode} node The node to select
17120 * @return {TreeNode} The selected node
17122 select : function(node){
17123 var last = this.selNode;
17124 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
17126 last.ui.onSelectedChange(false);
17128 this.selNode = node;
17129 node.ui.onSelectedChange(true);
17130 this.fireEvent("selectionchange", this, node, last);
17137 * @param {TreeNode} node The node to unselect
17139 unselect : function(node){
17140 if(this.selNode == node){
17141 this.clearSelections();
17146 * Clear all selections
17148 clearSelections : function(){
17149 var n = this.selNode;
17151 n.ui.onSelectedChange(false);
17152 this.selNode = null;
17153 this.fireEvent("selectionchange", this, null);
17159 * Get the selected node
17160 * @return {TreeNode} The selected node
17162 getSelectedNode : function(){
17163 return this.selNode;
17167 * Returns true if the node is selected
17168 * @param {TreeNode} node The node to check
17169 * @return {Boolean}
17171 isSelected : function(node){
17172 return this.selNode == node;
17176 * Selects the node above the selected node in the tree, intelligently walking the nodes
17177 * @return TreeNode The new selection
17179 selectPrevious : function(){
17180 var s = this.selNode || this.lastSelNode;
17184 var ps = s.previousSibling;
17186 if(!ps.isExpanded() || ps.childNodes.length < 1){
17187 return this.select(ps);
17189 var lc = ps.lastChild;
17190 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
17193 return this.select(lc);
17195 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
17196 return this.select(s.parentNode);
17202 * Selects the node above the selected node in the tree, intelligently walking the nodes
17203 * @return TreeNode The new selection
17205 selectNext : function(){
17206 var s = this.selNode || this.lastSelNode;
17210 if(s.firstChild && s.isExpanded()){
17211 return this.select(s.firstChild);
17212 }else if(s.nextSibling){
17213 return this.select(s.nextSibling);
17214 }else if(s.parentNode){
17216 s.parentNode.bubble(function(){
17217 if(this.nextSibling){
17218 newS = this.getOwnerTree().selModel.select(this.nextSibling);
17227 onKeyDown : function(e){
17228 var s = this.selNode || this.lastSelNode;
17229 // undesirable, but required
17234 var k = e.getKey();
17242 this.selectPrevious();
17245 e.preventDefault();
17246 if(s.hasChildNodes()){
17247 if(!s.isExpanded()){
17249 }else if(s.firstChild){
17250 this.select(s.firstChild, e);
17255 e.preventDefault();
17256 if(s.hasChildNodes() && s.isExpanded()){
17258 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
17259 this.select(s.parentNode, e);
17267 * @class Roo.tree.MultiSelectionModel
17268 * @extends Roo.util.Observable
17269 * Multi selection for a TreePanel.
17270 * @param {Object} cfg Configuration
17272 Roo.tree.MultiSelectionModel = function(){
17273 this.selNodes = [];
17277 * @event selectionchange
17278 * Fires when the selected nodes change
17279 * @param {MultiSelectionModel} this
17280 * @param {Array} nodes Array of the selected nodes
17282 "selectionchange" : true
17284 Roo.tree.MultiSelectionModel.superclass.constructor.call(this,cfg);
17288 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
17289 init : function(tree){
17291 tree.getTreeEl().on("keydown", this.onKeyDown, this);
17292 tree.on("click", this.onNodeClick, this);
17295 onNodeClick : function(node, e){
17296 this.select(node, e, e.ctrlKey);
17301 * @param {TreeNode} node The node to select
17302 * @param {EventObject} e (optional) An event associated with the selection
17303 * @param {Boolean} keepExisting True to retain existing selections
17304 * @return {TreeNode} The selected node
17306 select : function(node, e, keepExisting){
17307 if(keepExisting !== true){
17308 this.clearSelections(true);
17310 if(this.isSelected(node)){
17311 this.lastSelNode = node;
17314 this.selNodes.push(node);
17315 this.selMap[node.id] = node;
17316 this.lastSelNode = node;
17317 node.ui.onSelectedChange(true);
17318 this.fireEvent("selectionchange", this, this.selNodes);
17324 * @param {TreeNode} node The node to unselect
17326 unselect : function(node){
17327 if(this.selMap[node.id]){
17328 node.ui.onSelectedChange(false);
17329 var sn = this.selNodes;
17332 index = sn.indexOf(node);
17334 for(var i = 0, len = sn.length; i < len; i++){
17342 this.selNodes.splice(index, 1);
17344 delete this.selMap[node.id];
17345 this.fireEvent("selectionchange", this, this.selNodes);
17350 * Clear all selections
17352 clearSelections : function(suppressEvent){
17353 var sn = this.selNodes;
17355 for(var i = 0, len = sn.length; i < len; i++){
17356 sn[i].ui.onSelectedChange(false);
17358 this.selNodes = [];
17360 if(suppressEvent !== true){
17361 this.fireEvent("selectionchange", this, this.selNodes);
17367 * Returns true if the node is selected
17368 * @param {TreeNode} node The node to check
17369 * @return {Boolean}
17371 isSelected : function(node){
17372 return this.selMap[node.id] ? true : false;
17376 * Returns an array of the selected nodes
17379 getSelectedNodes : function(){
17380 return this.selNodes;
17383 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
17385 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
17387 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
17390 * Ext JS Library 1.1.1
17391 * Copyright(c) 2006-2007, Ext JS, LLC.
17393 * Originally Released Under LGPL - original licence link has changed is not relivant.
17396 * <script type="text/javascript">
17400 * @class Roo.tree.TreeNode
17401 * @extends Roo.data.Node
17402 * @cfg {String} text The text for this node
17403 * @cfg {Boolean} expanded true to start the node expanded
17404 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
17405 * @cfg {Boolean} allowDrop false if this node cannot be drop on
17406 * @cfg {Boolean} disabled true to start the node disabled
17407 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
17408 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
17409 * @cfg {String} cls A css class to be added to the node
17410 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
17411 * @cfg {String} href URL of the link used for the node (defaults to #)
17412 * @cfg {String} hrefTarget target frame for the link
17413 * @cfg {String} qtip An Ext QuickTip for the node
17414 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
17415 * @cfg {Boolean} singleClickExpand True for single click expand on this node
17416 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
17417 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
17418 * (defaults to undefined with no checkbox rendered)
17420 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
17422 Roo.tree.TreeNode = function(attributes){
17423 attributes = attributes || {};
17424 if(typeof attributes == "string"){
17425 attributes = {text: attributes};
17427 this.childrenRendered = false;
17428 this.rendered = false;
17429 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
17430 this.expanded = attributes.expanded === true;
17431 this.isTarget = attributes.isTarget !== false;
17432 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
17433 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
17436 * Read-only. The text for this node. To change it use setText().
17439 this.text = attributes.text;
17441 * True if this node is disabled.
17444 this.disabled = attributes.disabled === true;
17448 * @event textchange
17449 * Fires when the text for this node is changed
17450 * @param {Node} this This node
17451 * @param {String} text The new text
17452 * @param {String} oldText The old text
17454 "textchange" : true,
17456 * @event beforeexpand
17457 * Fires before this node is expanded, return false to cancel.
17458 * @param {Node} this This node
17459 * @param {Boolean} deep
17460 * @param {Boolean} anim
17462 "beforeexpand" : true,
17464 * @event beforecollapse
17465 * Fires before this node is collapsed, return false to cancel.
17466 * @param {Node} this This node
17467 * @param {Boolean} deep
17468 * @param {Boolean} anim
17470 "beforecollapse" : true,
17473 * Fires when this node is expanded
17474 * @param {Node} this This node
17478 * @event disabledchange
17479 * Fires when the disabled status of this node changes
17480 * @param {Node} this This node
17481 * @param {Boolean} disabled
17483 "disabledchange" : true,
17486 * Fires when this node is collapsed
17487 * @param {Node} this This node
17491 * @event beforeclick
17492 * Fires before click processing. Return false to cancel the default action.
17493 * @param {Node} this This node
17494 * @param {Roo.EventObject} e The event object
17496 "beforeclick":true,
17498 * @event checkchange
17499 * Fires when a node with a checkbox's checked property changes
17500 * @param {Node} this This node
17501 * @param {Boolean} checked
17503 "checkchange":true,
17506 * Fires when this node is clicked
17507 * @param {Node} this This node
17508 * @param {Roo.EventObject} e The event object
17513 * Fires when this node is double clicked
17514 * @param {Node} this This node
17515 * @param {Roo.EventObject} e The event object
17519 * @event contextmenu
17520 * Fires when this node is right clicked
17521 * @param {Node} this This node
17522 * @param {Roo.EventObject} e The event object
17524 "contextmenu":true,
17526 * @event beforechildrenrendered
17527 * Fires right before the child nodes for this node are rendered
17528 * @param {Node} this This node
17530 "beforechildrenrendered":true
17533 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
17536 * Read-only. The UI for this node
17539 this.ui = new uiClass(this);
17541 // finally support items[]
17542 if (typeof(this.attributes.items) == 'undefined' || !this.attributes.items) {
17547 Roo.each(this.attributes.items, function(c) {
17548 this.appendChild(Roo.factory(c,Roo.Tree));
17550 delete this.attributes.items;
17555 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
17556 preventHScroll: true,
17558 * Returns true if this node is expanded
17559 * @return {Boolean}
17561 isExpanded : function(){
17562 return this.expanded;
17566 * Returns the UI object for this node
17567 * @return {TreeNodeUI}
17569 getUI : function(){
17573 // private override
17574 setFirstChild : function(node){
17575 var of = this.firstChild;
17576 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
17577 if(this.childrenRendered && of && node != of){
17578 of.renderIndent(true, true);
17581 this.renderIndent(true, true);
17585 // private override
17586 setLastChild : function(node){
17587 var ol = this.lastChild;
17588 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
17589 if(this.childrenRendered && ol && node != ol){
17590 ol.renderIndent(true, true);
17593 this.renderIndent(true, true);
17597 // these methods are overridden to provide lazy rendering support
17598 // private override
17599 appendChild : function()
17601 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
17602 if(node && this.childrenRendered){
17605 this.ui.updateExpandIcon();
17609 // private override
17610 removeChild : function(node){
17611 this.ownerTree.getSelectionModel().unselect(node);
17612 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
17613 // if it's been rendered remove dom node
17614 if(this.childrenRendered){
17617 if(this.childNodes.length < 1){
17618 this.collapse(false, false);
17620 this.ui.updateExpandIcon();
17622 if(!this.firstChild) {
17623 this.childrenRendered = false;
17628 // private override
17629 insertBefore : function(node, refNode){
17630 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
17631 if(newNode && refNode && this.childrenRendered){
17634 this.ui.updateExpandIcon();
17639 * Sets the text for this node
17640 * @param {String} text
17642 setText : function(text){
17643 var oldText = this.text;
17645 this.attributes.text = text;
17646 if(this.rendered){ // event without subscribing
17647 this.ui.onTextChange(this, text, oldText);
17649 this.fireEvent("textchange", this, text, oldText);
17653 * Triggers selection of this node
17655 select : function(){
17656 this.getOwnerTree().getSelectionModel().select(this);
17660 * Triggers deselection of this node
17662 unselect : function(){
17663 this.getOwnerTree().getSelectionModel().unselect(this);
17667 * Returns true if this node is selected
17668 * @return {Boolean}
17670 isSelected : function(){
17671 return this.getOwnerTree().getSelectionModel().isSelected(this);
17675 * Expand this node.
17676 * @param {Boolean} deep (optional) True to expand all children as well
17677 * @param {Boolean} anim (optional) false to cancel the default animation
17678 * @param {Function} callback (optional) A callback to be called when
17679 * expanding this node completes (does not wait for deep expand to complete).
17680 * Called with 1 parameter, this node.
17682 expand : function(deep, anim, callback){
17683 if(!this.expanded){
17684 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
17687 if(!this.childrenRendered){
17688 this.renderChildren();
17690 this.expanded = true;
17691 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
17692 this.ui.animExpand(function(){
17693 this.fireEvent("expand", this);
17694 if(typeof callback == "function"){
17698 this.expandChildNodes(true);
17700 }.createDelegate(this));
17704 this.fireEvent("expand", this);
17705 if(typeof callback == "function"){
17710 if(typeof callback == "function"){
17715 this.expandChildNodes(true);
17719 isHiddenRoot : function(){
17720 return this.isRoot && !this.getOwnerTree().rootVisible;
17724 * Collapse this node.
17725 * @param {Boolean} deep (optional) True to collapse all children as well
17726 * @param {Boolean} anim (optional) false to cancel the default animation
17728 collapse : function(deep, anim){
17729 if(this.expanded && !this.isHiddenRoot()){
17730 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
17733 this.expanded = false;
17734 if((this.getOwnerTree().animate && anim !== false) || anim){
17735 this.ui.animCollapse(function(){
17736 this.fireEvent("collapse", this);
17738 this.collapseChildNodes(true);
17740 }.createDelegate(this));
17743 this.ui.collapse();
17744 this.fireEvent("collapse", this);
17748 var cs = this.childNodes;
17749 for(var i = 0, len = cs.length; i < len; i++) {
17750 cs[i].collapse(true, false);
17756 delayedExpand : function(delay){
17757 if(!this.expandProcId){
17758 this.expandProcId = this.expand.defer(delay, this);
17763 cancelExpand : function(){
17764 if(this.expandProcId){
17765 clearTimeout(this.expandProcId);
17767 this.expandProcId = false;
17771 * Toggles expanded/collapsed state of the node
17773 toggle : function(){
17782 * Ensures all parent nodes are expanded
17784 ensureVisible : function(callback){
17785 var tree = this.getOwnerTree();
17786 tree.expandPath(this.parentNode.getPath(), false, function(){
17787 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
17788 Roo.callback(callback);
17789 }.createDelegate(this));
17793 * Expand all child nodes
17794 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
17796 expandChildNodes : function(deep){
17797 var cs = this.childNodes;
17798 for(var i = 0, len = cs.length; i < len; i++) {
17799 cs[i].expand(deep);
17804 * Collapse all child nodes
17805 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
17807 collapseChildNodes : function(deep){
17808 var cs = this.childNodes;
17809 for(var i = 0, len = cs.length; i < len; i++) {
17810 cs[i].collapse(deep);
17815 * Disables this node
17817 disable : function(){
17818 this.disabled = true;
17820 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
17821 this.ui.onDisableChange(this, true);
17823 this.fireEvent("disabledchange", this, true);
17827 * Enables this node
17829 enable : function(){
17830 this.disabled = false;
17831 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
17832 this.ui.onDisableChange(this, false);
17834 this.fireEvent("disabledchange", this, false);
17838 renderChildren : function(suppressEvent){
17839 if(suppressEvent !== false){
17840 this.fireEvent("beforechildrenrendered", this);
17842 var cs = this.childNodes;
17843 for(var i = 0, len = cs.length; i < len; i++){
17844 cs[i].render(true);
17846 this.childrenRendered = true;
17850 sort : function(fn, scope){
17851 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
17852 if(this.childrenRendered){
17853 var cs = this.childNodes;
17854 for(var i = 0, len = cs.length; i < len; i++){
17855 cs[i].render(true);
17861 render : function(bulkRender){
17862 this.ui.render(bulkRender);
17863 if(!this.rendered){
17864 this.rendered = true;
17866 this.expanded = false;
17867 this.expand(false, false);
17873 renderIndent : function(deep, refresh){
17875 this.ui.childIndent = null;
17877 this.ui.renderIndent();
17878 if(deep === true && this.childrenRendered){
17879 var cs = this.childNodes;
17880 for(var i = 0, len = cs.length; i < len; i++){
17881 cs[i].renderIndent(true, refresh);
17887 * Ext JS Library 1.1.1
17888 * Copyright(c) 2006-2007, Ext JS, LLC.
17890 * Originally Released Under LGPL - original licence link has changed is not relivant.
17893 * <script type="text/javascript">
17897 * @class Roo.tree.AsyncTreeNode
17898 * @extends Roo.tree.TreeNode
17899 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
17901 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
17903 Roo.tree.AsyncTreeNode = function(config){
17904 this.loaded = false;
17905 this.loading = false;
17906 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
17908 * @event beforeload
17909 * Fires before this node is loaded, return false to cancel
17910 * @param {Node} this This node
17912 this.addEvents({'beforeload':true, 'load': true});
17915 * Fires when this node is loaded
17916 * @param {Node} this This node
17919 * The loader used by this node (defaults to using the tree's defined loader)
17924 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
17925 expand : function(deep, anim, callback){
17926 if(this.loading){ // if an async load is already running, waiting til it's done
17928 var f = function(){
17929 if(!this.loading){ // done loading
17930 clearInterval(timer);
17931 this.expand(deep, anim, callback);
17933 }.createDelegate(this);
17934 timer = setInterval(f, 200);
17938 if(this.fireEvent("beforeload", this) === false){
17941 this.loading = true;
17942 this.ui.beforeLoad(this);
17943 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
17945 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
17949 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
17953 * Returns true if this node is currently loading
17954 * @return {Boolean}
17956 isLoading : function(){
17957 return this.loading;
17960 loadComplete : function(deep, anim, callback){
17961 this.loading = false;
17962 this.loaded = true;
17963 this.ui.afterLoad(this);
17964 this.fireEvent("load", this);
17965 this.expand(deep, anim, callback);
17969 * Returns true if this node has been loaded
17970 * @return {Boolean}
17972 isLoaded : function(){
17973 return this.loaded;
17976 hasChildNodes : function(){
17977 if(!this.isLeaf() && !this.loaded){
17980 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
17985 * Trigger a reload for this node
17986 * @param {Function} callback
17988 reload : function(callback){
17989 this.collapse(false, false);
17990 while(this.firstChild){
17991 this.removeChild(this.firstChild);
17993 this.childrenRendered = false;
17994 this.loaded = false;
17995 if(this.isHiddenRoot()){
17996 this.expanded = false;
17998 this.expand(false, false, callback);
18002 * Ext JS Library 1.1.1
18003 * Copyright(c) 2006-2007, Ext JS, LLC.
18005 * Originally Released Under LGPL - original licence link has changed is not relivant.
18008 * <script type="text/javascript">
18012 * @class Roo.tree.TreeNodeUI
18014 * @param {Object} node The node to render
18015 * The TreeNode UI implementation is separate from the
18016 * tree implementation. Unless you are customizing the tree UI,
18017 * you should never have to use this directly.
18019 Roo.tree.TreeNodeUI = function(node){
18021 this.rendered = false;
18022 this.animating = false;
18023 this.emptyIcon = Roo.BLANK_IMAGE_URL;
18026 Roo.tree.TreeNodeUI.prototype = {
18027 removeChild : function(node){
18029 this.ctNode.removeChild(node.ui.getEl());
18033 beforeLoad : function(){
18034 this.addClass("x-tree-node-loading");
18037 afterLoad : function(){
18038 this.removeClass("x-tree-node-loading");
18041 onTextChange : function(node, text, oldText){
18043 this.textNode.innerHTML = text;
18047 onDisableChange : function(node, state){
18048 this.disabled = state;
18050 this.addClass("x-tree-node-disabled");
18052 this.removeClass("x-tree-node-disabled");
18056 onSelectedChange : function(state){
18059 this.addClass("x-tree-selected");
18062 this.removeClass("x-tree-selected");
18066 onMove : function(tree, node, oldParent, newParent, index, refNode){
18067 this.childIndent = null;
18069 var targetNode = newParent.ui.getContainer();
18070 if(!targetNode){//target not rendered
18071 this.holder = document.createElement("div");
18072 this.holder.appendChild(this.wrap);
18075 var insertBefore = refNode ? refNode.ui.getEl() : null;
18077 targetNode.insertBefore(this.wrap, insertBefore);
18079 targetNode.appendChild(this.wrap);
18081 this.node.renderIndent(true);
18085 addClass : function(cls){
18087 Roo.fly(this.elNode).addClass(cls);
18091 removeClass : function(cls){
18093 Roo.fly(this.elNode).removeClass(cls);
18097 remove : function(){
18099 this.holder = document.createElement("div");
18100 this.holder.appendChild(this.wrap);
18104 fireEvent : function(){
18105 return this.node.fireEvent.apply(this.node, arguments);
18108 initEvents : function(){
18109 this.node.on("move", this.onMove, this);
18110 var E = Roo.EventManager;
18111 var a = this.anchor;
18113 var el = Roo.fly(a, '_treeui');
18115 if(Roo.isOpera){ // opera render bug ignores the CSS
18116 el.setStyle("text-decoration", "none");
18119 el.on("click", this.onClick, this);
18120 el.on("dblclick", this.onDblClick, this);
18123 Roo.EventManager.on(this.checkbox,
18124 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
18127 el.on("contextmenu", this.onContextMenu, this);
18129 var icon = Roo.fly(this.iconNode);
18130 icon.on("click", this.onClick, this);
18131 icon.on("dblclick", this.onDblClick, this);
18132 icon.on("contextmenu", this.onContextMenu, this);
18133 E.on(this.ecNode, "click", this.ecClick, this, true);
18135 if(this.node.disabled){
18136 this.addClass("x-tree-node-disabled");
18138 if(this.node.hidden){
18139 this.addClass("x-tree-node-disabled");
18141 var ot = this.node.getOwnerTree();
18142 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
18143 if(dd && (!this.node.isRoot || ot.rootVisible)){
18144 Roo.dd.Registry.register(this.elNode, {
18146 handles: this.getDDHandles(),
18152 getDDHandles : function(){
18153 return [this.iconNode, this.textNode];
18158 this.wrap.style.display = "none";
18164 this.wrap.style.display = "";
18168 onContextMenu : function(e){
18169 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
18170 e.preventDefault();
18172 this.fireEvent("contextmenu", this.node, e);
18176 onClick : function(e){
18181 if(this.fireEvent("beforeclick", this.node, e) !== false){
18182 if(!this.disabled && this.node.attributes.href){
18183 this.fireEvent("click", this.node, e);
18186 e.preventDefault();
18191 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
18192 this.node.toggle();
18195 this.fireEvent("click", this.node, e);
18201 onDblClick : function(e){
18202 e.preventDefault();
18207 this.toggleCheck();
18209 if(!this.animating && this.node.hasChildNodes()){
18210 this.node.toggle();
18212 this.fireEvent("dblclick", this.node, e);
18215 onCheckChange : function(){
18216 var checked = this.checkbox.checked;
18217 this.node.attributes.checked = checked;
18218 this.fireEvent('checkchange', this.node, checked);
18221 ecClick : function(e){
18222 if(!this.animating && this.node.hasChildNodes()){
18223 this.node.toggle();
18227 startDrop : function(){
18228 this.dropping = true;
18231 // delayed drop so the click event doesn't get fired on a drop
18232 endDrop : function(){
18233 setTimeout(function(){
18234 this.dropping = false;
18235 }.createDelegate(this), 50);
18238 expand : function(){
18239 this.updateExpandIcon();
18240 this.ctNode.style.display = "";
18243 focus : function(){
18244 if(!this.node.preventHScroll){
18245 try{this.anchor.focus();
18247 }else if(!Roo.isIE){
18249 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
18250 var l = noscroll.scrollLeft;
18251 this.anchor.focus();
18252 noscroll.scrollLeft = l;
18257 toggleCheck : function(value){
18258 var cb = this.checkbox;
18260 cb.checked = (value === undefined ? !cb.checked : value);
18266 this.anchor.blur();
18270 animExpand : function(callback){
18271 var ct = Roo.get(this.ctNode);
18273 if(!this.node.hasChildNodes()){
18274 this.updateExpandIcon();
18275 this.ctNode.style.display = "";
18276 Roo.callback(callback);
18279 this.animating = true;
18280 this.updateExpandIcon();
18283 callback : function(){
18284 this.animating = false;
18285 Roo.callback(callback);
18288 duration: this.node.ownerTree.duration || .25
18292 highlight : function(){
18293 var tree = this.node.getOwnerTree();
18294 Roo.fly(this.wrap).highlight(
18295 tree.hlColor || "C3DAF9",
18296 {endColor: tree.hlBaseColor}
18300 collapse : function(){
18301 this.updateExpandIcon();
18302 this.ctNode.style.display = "none";
18305 animCollapse : function(callback){
18306 var ct = Roo.get(this.ctNode);
18307 ct.enableDisplayMode('block');
18310 this.animating = true;
18311 this.updateExpandIcon();
18314 callback : function(){
18315 this.animating = false;
18316 Roo.callback(callback);
18319 duration: this.node.ownerTree.duration || .25
18323 getContainer : function(){
18324 return this.ctNode;
18327 getEl : function(){
18331 appendDDGhost : function(ghostNode){
18332 ghostNode.appendChild(this.elNode.cloneNode(true));
18335 getDDRepairXY : function(){
18336 return Roo.lib.Dom.getXY(this.iconNode);
18339 onRender : function(){
18343 render : function(bulkRender){
18344 var n = this.node, a = n.attributes;
18345 var targetNode = n.parentNode ?
18346 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
18348 if(!this.rendered){
18349 this.rendered = true;
18351 this.renderElements(n, a, targetNode, bulkRender);
18354 if(this.textNode.setAttributeNS){
18355 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
18357 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
18360 this.textNode.setAttribute("ext:qtip", a.qtip);
18362 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
18365 }else if(a.qtipCfg){
18366 a.qtipCfg.target = Roo.id(this.textNode);
18367 Roo.QuickTips.register(a.qtipCfg);
18370 if(!this.node.expanded){
18371 this.updateExpandIcon();
18374 if(bulkRender === true) {
18375 targetNode.appendChild(this.wrap);
18380 renderElements : function(n, a, targetNode, bulkRender)
18382 // add some indent caching, this helps performance when rendering a large tree
18383 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
18384 var t = n.getOwnerTree();
18385 var txt = t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
18386 if (typeof(n.attributes.html) != 'undefined') {
18387 txt = n.attributes.html;
18389 var tip = t.rendererTip ? t.rendererTip(n.attributes) : txt;
18390 var cb = typeof a.checked == 'boolean';
18391 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
18392 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
18393 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
18394 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
18395 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
18396 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
18397 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
18398 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
18399 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
18400 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
18403 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
18404 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
18405 n.nextSibling.ui.getEl(), buf.join(""));
18407 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
18410 this.elNode = this.wrap.childNodes[0];
18411 this.ctNode = this.wrap.childNodes[1];
18412 var cs = this.elNode.childNodes;
18413 this.indentNode = cs[0];
18414 this.ecNode = cs[1];
18415 this.iconNode = cs[2];
18418 this.checkbox = cs[3];
18421 this.anchor = cs[index];
18422 this.textNode = cs[index].firstChild;
18425 getAnchor : function(){
18426 return this.anchor;
18429 getTextEl : function(){
18430 return this.textNode;
18433 getIconEl : function(){
18434 return this.iconNode;
18437 isChecked : function(){
18438 return this.checkbox ? this.checkbox.checked : false;
18441 updateExpandIcon : function(){
18443 var n = this.node, c1, c2;
18444 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
18445 var hasChild = n.hasChildNodes();
18449 c1 = "x-tree-node-collapsed";
18450 c2 = "x-tree-node-expanded";
18453 c1 = "x-tree-node-expanded";
18454 c2 = "x-tree-node-collapsed";
18457 this.removeClass("x-tree-node-leaf");
18458 this.wasLeaf = false;
18460 if(this.c1 != c1 || this.c2 != c2){
18461 Roo.fly(this.elNode).replaceClass(c1, c2);
18462 this.c1 = c1; this.c2 = c2;
18465 // this changes non-leafs into leafs if they have no children.
18466 // it's not very rational behaviour..
18468 if(!this.wasLeaf && this.node.leaf){
18469 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
18472 this.wasLeaf = true;
18475 var ecc = "x-tree-ec-icon "+cls;
18476 if(this.ecc != ecc){
18477 this.ecNode.className = ecc;
18483 getChildIndent : function(){
18484 if(!this.childIndent){
18488 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
18490 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
18492 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
18497 this.childIndent = buf.join("");
18499 return this.childIndent;
18502 renderIndent : function(){
18505 var p = this.node.parentNode;
18507 indent = p.ui.getChildIndent();
18509 if(this.indentMarkup != indent){ // don't rerender if not required
18510 this.indentNode.innerHTML = indent;
18511 this.indentMarkup = indent;
18513 this.updateExpandIcon();
18518 Roo.tree.RootTreeNodeUI = function(){
18519 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
18521 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
18522 render : function(){
18523 if(!this.rendered){
18524 var targetNode = this.node.ownerTree.innerCt.dom;
18525 this.node.expanded = true;
18526 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
18527 this.wrap = this.ctNode = targetNode.firstChild;
18530 collapse : function(){
18532 expand : function(){
18536 * Ext JS Library 1.1.1
18537 * Copyright(c) 2006-2007, Ext JS, LLC.
18539 * Originally Released Under LGPL - original licence link has changed is not relivant.
18542 * <script type="text/javascript">
18545 * @class Roo.tree.TreeLoader
18546 * @extends Roo.util.Observable
18547 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
18548 * nodes from a specified URL. The response must be a javascript Array definition
18549 * who's elements are node definition objects. eg:
18554 { 'id': 1, 'text': 'A folder Node', 'leaf': false },
18555 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }
18562 * The old style respose with just an array is still supported, but not recommended.
18565 * A server request is sent, and child nodes are loaded only when a node is expanded.
18566 * The loading node's id is passed to the server under the parameter name "node" to
18567 * enable the server to produce the correct child nodes.
18569 * To pass extra parameters, an event handler may be attached to the "beforeload"
18570 * event, and the parameters specified in the TreeLoader's baseParams property:
18572 myTreeLoader.on("beforeload", function(treeLoader, node) {
18573 this.baseParams.category = node.attributes.category;
18576 * This would pass an HTTP parameter called "category" to the server containing
18577 * the value of the Node's "category" attribute.
18579 * Creates a new Treeloader.
18580 * @param {Object} config A config object containing config properties.
18582 Roo.tree.TreeLoader = function(config){
18583 this.baseParams = {};
18584 this.requestMethod = "POST";
18585 Roo.apply(this, config);
18590 * @event beforeload
18591 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
18592 * @param {Object} This TreeLoader object.
18593 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18594 * @param {Object} callback The callback function specified in the {@link #load} call.
18599 * Fires when the node has been successfuly loaded.
18600 * @param {Object} This TreeLoader object.
18601 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18602 * @param {Object} response The response object containing the data from the server.
18606 * @event loadexception
18607 * Fires if the network request failed.
18608 * @param {Object} This TreeLoader object.
18609 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18610 * @param {Object} response The response object containing the data from the server.
18612 loadexception : true,
18615 * Fires before a node is created, enabling you to return custom Node types
18616 * @param {Object} This TreeLoader object.
18617 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
18622 Roo.tree.TreeLoader.superclass.constructor.call(this);
18625 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
18627 * @cfg {String} dataUrl The URL from which to request a Json string which
18628 * specifies an array of node definition object representing the child nodes
18632 * @cfg {String} requestMethod either GET or POST
18633 * defaults to POST (due to BC)
18637 * @cfg {Object} baseParams (optional) An object containing properties which
18638 * specify HTTP parameters to be passed to each request for child nodes.
18641 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
18642 * created by this loader. If the attributes sent by the server have an attribute in this object,
18643 * they take priority.
18646 * @cfg {Object} uiProviders (optional) An object containing properties which
18648 * DEPRECATED - use 'create' event handler to modify attributes - which affect creation.
18649 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
18650 * <i>uiProvider</i> attribute of a returned child node is a string rather
18651 * than a reference to a TreeNodeUI implementation, this that string value
18652 * is used as a property name in the uiProviders object. You can define the provider named
18653 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
18658 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
18659 * child nodes before loading.
18661 clearOnLoad : true,
18664 * @cfg {String} root (optional) Default to false. Use this to read data from an object
18665 * property on loading, rather than expecting an array. (eg. more compatible to a standard
18666 * Grid query { data : [ .....] }
18671 * @cfg {String} queryParam (optional)
18672 * Name of the query as it will be passed on the querystring (defaults to 'node')
18673 * eg. the request will be ?node=[id]
18680 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
18681 * This is called automatically when a node is expanded, but may be used to reload
18682 * a node (or append new children if the {@link #clearOnLoad} option is false.)
18683 * @param {Roo.tree.TreeNode} node
18684 * @param {Function} callback
18686 load : function(node, callback){
18687 if(this.clearOnLoad){
18688 while(node.firstChild){
18689 node.removeChild(node.firstChild);
18692 if(node.attributes.children){ // preloaded json children
18693 var cs = node.attributes.children;
18694 for(var i = 0, len = cs.length; i < len; i++){
18695 node.appendChild(this.createNode(cs[i]));
18697 if(typeof callback == "function"){
18700 }else if(this.dataUrl){
18701 this.requestData(node, callback);
18705 getParams: function(node){
18706 var buf = [], bp = this.baseParams;
18707 for(var key in bp){
18708 if(typeof bp[key] != "function"){
18709 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
18712 var n = this.queryParam === false ? 'node' : this.queryParam;
18713 buf.push(n + "=", encodeURIComponent(node.id));
18714 return buf.join("");
18717 requestData : function(node, callback){
18718 if(this.fireEvent("beforeload", this, node, callback) !== false){
18719 this.transId = Roo.Ajax.request({
18720 method:this.requestMethod,
18721 url: this.dataUrl||this.url,
18722 success: this.handleResponse,
18723 failure: this.handleFailure,
18725 argument: {callback: callback, node: node},
18726 params: this.getParams(node)
18729 // if the load is cancelled, make sure we notify
18730 // the node that we are done
18731 if(typeof callback == "function"){
18737 isLoading : function(){
18738 return this.transId ? true : false;
18741 abort : function(){
18742 if(this.isLoading()){
18743 Roo.Ajax.abort(this.transId);
18748 createNode : function(attr)
18750 // apply baseAttrs, nice idea Corey!
18751 if(this.baseAttrs){
18752 Roo.applyIf(attr, this.baseAttrs);
18754 if(this.applyLoader !== false){
18755 attr.loader = this;
18757 // uiProvider = depreciated..
18759 if(typeof(attr.uiProvider) == 'string'){
18760 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
18761 /** eval:var:attr */ eval(attr.uiProvider);
18763 if(typeof(this.uiProviders['default']) != 'undefined') {
18764 attr.uiProvider = this.uiProviders['default'];
18767 this.fireEvent('create', this, attr);
18769 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
18771 new Roo.tree.TreeNode(attr) :
18772 new Roo.tree.AsyncTreeNode(attr));
18775 processResponse : function(response, node, callback)
18777 var json = response.responseText;
18780 var o = Roo.decode(json);
18782 if (this.root === false && typeof(o.success) != undefined) {
18783 this.root = 'data'; // the default behaviour for list like data..
18786 if (this.root !== false && !o.success) {
18787 // it's a failure condition.
18788 var a = response.argument;
18789 this.fireEvent("loadexception", this, a.node, response);
18790 Roo.log("Load failed - should have a handler really");
18796 if (this.root !== false) {
18800 for(var i = 0, len = o.length; i < len; i++){
18801 var n = this.createNode(o[i]);
18803 node.appendChild(n);
18806 if(typeof callback == "function"){
18807 callback(this, node);
18810 this.handleFailure(response);
18814 handleResponse : function(response){
18815 this.transId = false;
18816 var a = response.argument;
18817 this.processResponse(response, a.node, a.callback);
18818 this.fireEvent("load", this, a.node, response);
18821 handleFailure : function(response)
18823 // should handle failure better..
18824 this.transId = false;
18825 var a = response.argument;
18826 this.fireEvent("loadexception", this, a.node, response);
18827 if(typeof a.callback == "function"){
18828 a.callback(this, a.node);
18833 * Ext JS Library 1.1.1
18834 * Copyright(c) 2006-2007, Ext JS, LLC.
18836 * Originally Released Under LGPL - original licence link has changed is not relivant.
18839 * <script type="text/javascript">
18843 * @class Roo.tree.TreeFilter
18844 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
18845 * @param {TreePanel} tree
18846 * @param {Object} config (optional)
18848 Roo.tree.TreeFilter = function(tree, config){
18850 this.filtered = {};
18851 Roo.apply(this, config);
18854 Roo.tree.TreeFilter.prototype = {
18861 * Filter the data by a specific attribute.
18862 * @param {String/RegExp} value Either string that the attribute value
18863 * should start with or a RegExp to test against the attribute
18864 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
18865 * @param {TreeNode} startNode (optional) The node to start the filter at.
18867 filter : function(value, attr, startNode){
18868 attr = attr || "text";
18870 if(typeof value == "string"){
18871 var vlen = value.length;
18872 // auto clear empty filter
18873 if(vlen == 0 && this.clearBlank){
18877 value = value.toLowerCase();
18879 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
18881 }else if(value.exec){ // regex?
18883 return value.test(n.attributes[attr]);
18886 throw 'Illegal filter type, must be string or regex';
18888 this.filterBy(f, null, startNode);
18892 * Filter by a function. The passed function will be called with each
18893 * node in the tree (or from the startNode). If the function returns true, the node is kept
18894 * otherwise it is filtered. If a node is filtered, its children are also filtered.
18895 * @param {Function} fn The filter function
18896 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
18898 filterBy : function(fn, scope, startNode){
18899 startNode = startNode || this.tree.root;
18900 if(this.autoClear){
18903 var af = this.filtered, rv = this.reverse;
18904 var f = function(n){
18905 if(n == startNode){
18911 var m = fn.call(scope || n, n);
18919 startNode.cascade(f);
18922 if(typeof id != "function"){
18924 if(n && n.parentNode){
18925 n.parentNode.removeChild(n);
18933 * Clears the current filter. Note: with the "remove" option
18934 * set a filter cannot be cleared.
18936 clear : function(){
18938 var af = this.filtered;
18940 if(typeof id != "function"){
18947 this.filtered = {};
18952 * Ext JS Library 1.1.1
18953 * Copyright(c) 2006-2007, Ext JS, LLC.
18955 * Originally Released Under LGPL - original licence link has changed is not relivant.
18958 * <script type="text/javascript">
18963 * @class Roo.tree.TreeSorter
18964 * Provides sorting of nodes in a TreePanel
18966 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
18967 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
18968 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
18969 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
18970 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
18971 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
18973 * @param {TreePanel} tree
18974 * @param {Object} config
18976 Roo.tree.TreeSorter = function(tree, config){
18977 Roo.apply(this, config);
18978 tree.on("beforechildrenrendered", this.doSort, this);
18979 tree.on("append", this.updateSort, this);
18980 tree.on("insert", this.updateSort, this);
18982 var dsc = this.dir && this.dir.toLowerCase() == "desc";
18983 var p = this.property || "text";
18984 var sortType = this.sortType;
18985 var fs = this.folderSort;
18986 var cs = this.caseSensitive === true;
18987 var leafAttr = this.leafAttr || 'leaf';
18989 this.sortFn = function(n1, n2){
18991 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
18994 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
18998 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
18999 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
19001 return dsc ? +1 : -1;
19003 return dsc ? -1 : +1;
19010 Roo.tree.TreeSorter.prototype = {
19011 doSort : function(node){
19012 node.sort(this.sortFn);
19015 compareNodes : function(n1, n2){
19016 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
19019 updateSort : function(tree, node){
19020 if(node.childrenRendered){
19021 this.doSort.defer(1, this, [node]);
19026 * Ext JS Library 1.1.1
19027 * Copyright(c) 2006-2007, Ext JS, LLC.
19029 * Originally Released Under LGPL - original licence link has changed is not relivant.
19032 * <script type="text/javascript">
19035 if(Roo.dd.DropZone){
19037 Roo.tree.TreeDropZone = function(tree, config){
19038 this.allowParentInsert = false;
19039 this.allowContainerDrop = false;
19040 this.appendOnly = false;
19041 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
19043 this.lastInsertClass = "x-tree-no-status";
19044 this.dragOverData = {};
19047 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
19048 ddGroup : "TreeDD",
19051 expandDelay : 1000,
19053 expandNode : function(node){
19054 if(node.hasChildNodes() && !node.isExpanded()){
19055 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
19059 queueExpand : function(node){
19060 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
19063 cancelExpand : function(){
19064 if(this.expandProcId){
19065 clearTimeout(this.expandProcId);
19066 this.expandProcId = false;
19070 isValidDropPoint : function(n, pt, dd, e, data){
19071 if(!n || !data){ return false; }
19072 var targetNode = n.node;
19073 var dropNode = data.node;
19074 // default drop rules
19075 if(!(targetNode && targetNode.isTarget && pt)){
19078 if(pt == "append" && targetNode.allowChildren === false){
19081 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
19084 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
19087 // reuse the object
19088 var overEvent = this.dragOverData;
19089 overEvent.tree = this.tree;
19090 overEvent.target = targetNode;
19091 overEvent.data = data;
19092 overEvent.point = pt;
19093 overEvent.source = dd;
19094 overEvent.rawEvent = e;
19095 overEvent.dropNode = dropNode;
19096 overEvent.cancel = false;
19097 var result = this.tree.fireEvent("nodedragover", overEvent);
19098 return overEvent.cancel === false && result !== false;
19101 getDropPoint : function(e, n, dd)
19105 return tn.allowChildren !== false ? "append" : false; // always append for root
19107 var dragEl = n.ddel;
19108 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
19109 var y = Roo.lib.Event.getPageY(e);
19110 //var noAppend = tn.allowChildren === false || tn.isLeaf();
19112 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
19113 var noAppend = tn.allowChildren === false;
19114 if(this.appendOnly || tn.parentNode.allowChildren === false){
19115 return noAppend ? false : "append";
19117 var noBelow = false;
19118 if(!this.allowParentInsert){
19119 noBelow = tn.hasChildNodes() && tn.isExpanded();
19121 var q = (b - t) / (noAppend ? 2 : 3);
19122 if(y >= t && y < (t + q)){
19124 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
19131 onNodeEnter : function(n, dd, e, data)
19133 this.cancelExpand();
19136 onNodeOver : function(n, dd, e, data)
19139 var pt = this.getDropPoint(e, n, dd);
19142 // auto node expand check
19143 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
19144 this.queueExpand(node);
19145 }else if(pt != "append"){
19146 this.cancelExpand();
19149 // set the insert point style on the target node
19150 var returnCls = this.dropNotAllowed;
19151 if(this.isValidDropPoint(n, pt, dd, e, data)){
19156 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
19157 cls = "x-tree-drag-insert-above";
19158 }else if(pt == "below"){
19159 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
19160 cls = "x-tree-drag-insert-below";
19162 returnCls = "x-tree-drop-ok-append";
19163 cls = "x-tree-drag-append";
19165 if(this.lastInsertClass != cls){
19166 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
19167 this.lastInsertClass = cls;
19174 onNodeOut : function(n, dd, e, data){
19176 this.cancelExpand();
19177 this.removeDropIndicators(n);
19180 onNodeDrop : function(n, dd, e, data){
19181 var point = this.getDropPoint(e, n, dd);
19182 var targetNode = n.node;
19183 targetNode.ui.startDrop();
19184 if(!this.isValidDropPoint(n, point, dd, e, data)){
19185 targetNode.ui.endDrop();
19188 // first try to find the drop node
19189 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
19192 target: targetNode,
19197 dropNode: dropNode,
19200 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
19201 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
19202 targetNode.ui.endDrop();
19205 // allow target changing
19206 targetNode = dropEvent.target;
19207 if(point == "append" && !targetNode.isExpanded()){
19208 targetNode.expand(false, null, function(){
19209 this.completeDrop(dropEvent);
19210 }.createDelegate(this));
19212 this.completeDrop(dropEvent);
19217 completeDrop : function(de){
19218 var ns = de.dropNode, p = de.point, t = de.target;
19219 if(!(ns instanceof Array)){
19223 for(var i = 0, len = ns.length; i < len; i++){
19226 t.parentNode.insertBefore(n, t);
19227 }else if(p == "below"){
19228 t.parentNode.insertBefore(n, t.nextSibling);
19234 if(this.tree.hlDrop){
19238 this.tree.fireEvent("nodedrop", de);
19241 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
19242 if(this.tree.hlDrop){
19243 dropNode.ui.focus();
19244 dropNode.ui.highlight();
19246 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
19249 getTree : function(){
19253 removeDropIndicators : function(n){
19256 Roo.fly(el).removeClass([
19257 "x-tree-drag-insert-above",
19258 "x-tree-drag-insert-below",
19259 "x-tree-drag-append"]);
19260 this.lastInsertClass = "_noclass";
19264 beforeDragDrop : function(target, e, id){
19265 this.cancelExpand();
19269 afterRepair : function(data){
19270 if(data && Roo.enableFx){
19271 data.node.ui.highlight();
19281 * Ext JS Library 1.1.1
19282 * Copyright(c) 2006-2007, Ext JS, LLC.
19284 * Originally Released Under LGPL - original licence link has changed is not relivant.
19287 * <script type="text/javascript">
19291 if(Roo.dd.DragZone){
19292 Roo.tree.TreeDragZone = function(tree, config){
19293 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
19297 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
19298 ddGroup : "TreeDD",
19300 onBeforeDrag : function(data, e){
19302 return n && n.draggable && !n.disabled;
19306 onInitDrag : function(e){
19307 var data = this.dragData;
19308 this.tree.getSelectionModel().select(data.node);
19309 this.proxy.update("");
19310 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
19311 this.tree.fireEvent("startdrag", this.tree, data.node, e);
19314 getRepairXY : function(e, data){
19315 return data.node.ui.getDDRepairXY();
19318 onEndDrag : function(data, e){
19319 this.tree.fireEvent("enddrag", this.tree, data.node, e);
19324 onValidDrop : function(dd, e, id){
19325 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
19329 beforeInvalidDrop : function(e, id){
19330 // this scrolls the original position back into view
19331 var sm = this.tree.getSelectionModel();
19332 sm.clearSelections();
19333 sm.select(this.dragData.node);
19338 * Ext JS Library 1.1.1
19339 * Copyright(c) 2006-2007, Ext JS, LLC.
19341 * Originally Released Under LGPL - original licence link has changed is not relivant.
19344 * <script type="text/javascript">
19347 * @class Roo.tree.TreeEditor
19348 * @extends Roo.Editor
19349 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
19350 * as the editor field.
19352 * @param {Object} config (used to be the tree panel.)
19353 * @param {Object} oldconfig DEPRECIATED Either a prebuilt {@link Roo.form.Field} instance or a Field config object
19355 * @cfg {Roo.tree.TreePanel} tree The tree to bind to.
19356 * @cfg {Roo.form.TextField|Object} field The field configuration
19360 Roo.tree.TreeEditor = function(config, oldconfig) { // was -- (tree, config){
19363 if (oldconfig) { // old style..
19364 field = oldconfig.events ? oldconfig : new Roo.form.TextField(oldconfig);
19367 tree = config.tree;
19368 config.field = config.field || {};
19369 config.field.xtype = 'TextField';
19370 field = Roo.factory(config.field, Roo.form);
19372 config = config || {};
19377 * @event beforenodeedit
19378 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
19379 * false from the handler of this event.
19380 * @param {Editor} this
19381 * @param {Roo.tree.Node} node
19383 "beforenodeedit" : true
19387 Roo.tree.TreeEditor.superclass.constructor.call(this, field, config);
19391 tree.on('beforeclick', this.beforeNodeClick, this);
19392 tree.getTreeEl().on('mousedown', this.hide, this);
19393 this.on('complete', this.updateNode, this);
19394 this.on('beforestartedit', this.fitToTree, this);
19395 this.on('startedit', this.bindScroll, this, {delay:10});
19396 this.on('specialkey', this.onSpecialKey, this);
19399 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
19401 * @cfg {String} alignment
19402 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
19408 * @cfg {Boolean} hideEl
19409 * True to hide the bound element while the editor is displayed (defaults to false)
19413 * @cfg {String} cls
19414 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
19416 cls: "x-small-editor x-tree-editor",
19418 * @cfg {Boolean} shim
19419 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
19425 * @cfg {Number} maxWidth
19426 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
19427 * the containing tree element's size, it will be automatically limited for you to the container width, taking
19428 * scroll and client offsets into account prior to each edit.
19435 fitToTree : function(ed, el){
19436 var td = this.tree.getTreeEl().dom, nd = el.dom;
19437 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
19438 td.scrollLeft = nd.offsetLeft;
19442 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
19443 this.setSize(w, '');
19445 return this.fireEvent('beforenodeedit', this, this.editNode);
19450 triggerEdit : function(node){
19451 this.completeEdit();
19452 this.editNode = node;
19453 this.startEdit(node.ui.textNode, node.text);
19457 bindScroll : function(){
19458 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
19462 beforeNodeClick : function(node, e){
19463 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
19464 this.lastClick = new Date();
19465 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
19467 this.triggerEdit(node);
19474 updateNode : function(ed, value){
19475 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
19476 this.editNode.setText(value);
19480 onHide : function(){
19481 Roo.tree.TreeEditor.superclass.onHide.call(this);
19483 this.editNode.ui.focus();
19488 onSpecialKey : function(field, e){
19489 var k = e.getKey();
19493 }else if(k == e.ENTER && !e.hasModifier()){
19495 this.completeEdit();
19498 });//<Script type="text/javascript">
19501 * Ext JS Library 1.1.1
19502 * Copyright(c) 2006-2007, Ext JS, LLC.
19504 * Originally Released Under LGPL - original licence link has changed is not relivant.
19507 * <script type="text/javascript">
19511 * Not documented??? - probably should be...
19514 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
19515 //focus: Roo.emptyFn, // prevent odd scrolling behavior
19517 renderElements : function(n, a, targetNode, bulkRender){
19518 //consel.log("renderElements?");
19519 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
19521 var t = n.getOwnerTree();
19522 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
19524 var cols = t.columns;
19525 var bw = t.borderWidth;
19527 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
19528 var cb = typeof a.checked == "boolean";
19529 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
19530 var colcls = 'x-t-' + tid + '-c0';
19532 '<li class="x-tree-node">',
19535 '<div class="x-tree-node-el ', a.cls,'">',
19537 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
19540 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
19541 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
19542 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
19543 (a.icon ? ' x-tree-node-inline-icon' : ''),
19544 (a.iconCls ? ' '+a.iconCls : ''),
19545 '" unselectable="on" />',
19546 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
19547 (a.checked ? 'checked="checked" />' : ' />')) : ''),
19549 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
19550 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
19551 '<span unselectable="on" qtip="' + tx + '">',
19555 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
19556 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>'
19558 for(var i = 1, len = cols.length; i < len; i++){
19560 colcls = 'x-t-' + tid + '-c' +i;
19561 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
19562 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
19563 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
19569 '<div class="x-clear"></div></div>',
19570 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
19573 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
19574 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
19575 n.nextSibling.ui.getEl(), buf.join(""));
19577 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
19579 var el = this.wrap.firstChild;
19581 this.elNode = el.firstChild;
19582 this.ranchor = el.childNodes[1];
19583 this.ctNode = this.wrap.childNodes[1];
19584 var cs = el.firstChild.childNodes;
19585 this.indentNode = cs[0];
19586 this.ecNode = cs[1];
19587 this.iconNode = cs[2];
19590 this.checkbox = cs[3];
19593 this.anchor = cs[index];
19595 this.textNode = cs[index].firstChild;
19597 //el.on("click", this.onClick, this);
19598 //el.on("dblclick", this.onDblClick, this);
19601 // console.log(this);
19603 initEvents : function(){
19604 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
19607 var a = this.ranchor;
19609 var el = Roo.get(a);
19611 if(Roo.isOpera){ // opera render bug ignores the CSS
19612 el.setStyle("text-decoration", "none");
19615 el.on("click", this.onClick, this);
19616 el.on("dblclick", this.onDblClick, this);
19617 el.on("contextmenu", this.onContextMenu, this);
19621 /*onSelectedChange : function(state){
19624 this.addClass("x-tree-selected");
19627 this.removeClass("x-tree-selected");
19630 addClass : function(cls){
19632 Roo.fly(this.elRow).addClass(cls);
19638 removeClass : function(cls){
19640 Roo.fly(this.elRow).removeClass(cls);
19646 });//<Script type="text/javascript">
19650 * Ext JS Library 1.1.1
19651 * Copyright(c) 2006-2007, Ext JS, LLC.
19653 * Originally Released Under LGPL - original licence link has changed is not relivant.
19656 * <script type="text/javascript">
19661 * @class Roo.tree.ColumnTree
19662 * @extends Roo.data.TreePanel
19663 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
19664 * @cfg {int} borderWidth compined right/left border allowance
19666 * @param {String/HTMLElement/Element} el The container element
19667 * @param {Object} config
19669 Roo.tree.ColumnTree = function(el, config)
19671 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
19675 * Fire this event on a container when it resizes
19676 * @param {int} w Width
19677 * @param {int} h Height
19681 this.on('resize', this.onResize, this);
19684 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
19688 borderWidth: Roo.isBorderBox ? 0 : 2,
19691 render : function(){
19692 // add the header.....
19694 Roo.tree.ColumnTree.superclass.render.apply(this);
19696 this.el.addClass('x-column-tree');
19698 this.headers = this.el.createChild(
19699 {cls:'x-tree-headers'},this.innerCt.dom);
19701 var cols = this.columns, c;
19702 var totalWidth = 0;
19704 var len = cols.length;
19705 for(var i = 0; i < len; i++){
19707 totalWidth += c.width;
19708 this.headEls.push(this.headers.createChild({
19709 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
19711 cls:'x-tree-hd-text',
19714 style:'width:'+(c.width-this.borderWidth)+'px;'
19717 this.headers.createChild({cls:'x-clear'});
19718 // prevent floats from wrapping when clipped
19719 this.headers.setWidth(totalWidth);
19720 //this.innerCt.setWidth(totalWidth);
19721 this.innerCt.setStyle({ overflow: 'auto' });
19722 this.onResize(this.width, this.height);
19726 onResize : function(w,h)
19731 this.innerCt.setWidth(this.width);
19732 this.innerCt.setHeight(this.height-20);
19735 var cols = this.columns, c;
19736 var totalWidth = 0;
19738 var len = cols.length;
19739 for(var i = 0; i < len; i++){
19741 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
19742 // it's the expander..
19743 expEl = this.headEls[i];
19746 totalWidth += c.width;
19750 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
19752 this.headers.setWidth(w-20);
19761 * Ext JS Library 1.1.1
19762 * Copyright(c) 2006-2007, Ext JS, LLC.
19764 * Originally Released Under LGPL - original licence link has changed is not relivant.
19767 * <script type="text/javascript">
19771 * @class Roo.menu.Menu
19772 * @extends Roo.util.Observable
19773 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
19774 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
19776 * Creates a new Menu
19777 * @param {Object} config Configuration options
19779 Roo.menu.Menu = function(config){
19780 Roo.apply(this, config);
19781 this.id = this.id || Roo.id();
19784 * @event beforeshow
19785 * Fires before this menu is displayed
19786 * @param {Roo.menu.Menu} this
19790 * @event beforehide
19791 * Fires before this menu is hidden
19792 * @param {Roo.menu.Menu} this
19797 * Fires after this menu is displayed
19798 * @param {Roo.menu.Menu} this
19803 * Fires after this menu is hidden
19804 * @param {Roo.menu.Menu} this
19809 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
19810 * @param {Roo.menu.Menu} this
19811 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19812 * @param {Roo.EventObject} e
19817 * Fires when the mouse is hovering over this menu
19818 * @param {Roo.menu.Menu} this
19819 * @param {Roo.EventObject} e
19820 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19825 * Fires when the mouse exits this menu
19826 * @param {Roo.menu.Menu} this
19827 * @param {Roo.EventObject} e
19828 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19833 * Fires when a menu item contained in this menu is clicked
19834 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
19835 * @param {Roo.EventObject} e
19839 if (this.registerMenu) {
19840 Roo.menu.MenuMgr.register(this);
19843 var mis = this.items;
19844 this.items = new Roo.util.MixedCollection();
19846 this.add.apply(this, mis);
19850 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
19852 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
19856 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
19857 * for bottom-right shadow (defaults to "sides")
19861 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
19862 * this menu (defaults to "tl-tr?")
19864 subMenuAlign : "tl-tr?",
19866 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
19867 * relative to its element of origin (defaults to "tl-bl?")
19869 defaultAlign : "tl-bl?",
19871 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
19873 allowOtherMenus : false,
19875 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
19877 registerMenu : true,
19882 render : function(){
19886 var el = this.el = new Roo.Layer({
19888 shadow:this.shadow,
19890 parentEl: this.parentEl || document.body,
19894 this.keyNav = new Roo.menu.MenuNav(this);
19897 el.addClass("x-menu-plain");
19900 el.addClass(this.cls);
19902 // generic focus element
19903 this.focusEl = el.createChild({
19904 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
19906 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
19907 ul.on("click", this.onClick, this);
19908 ul.on("mouseover", this.onMouseOver, this);
19909 ul.on("mouseout", this.onMouseOut, this);
19910 this.items.each(function(item){
19915 var li = document.createElement("li");
19916 li.className = "x-menu-list-item";
19917 ul.dom.appendChild(li);
19918 item.render(li, this);
19925 autoWidth : function(){
19926 var el = this.el, ul = this.ul;
19930 var w = this.width;
19933 }else if(Roo.isIE){
19934 el.setWidth(this.minWidth);
19935 var t = el.dom.offsetWidth; // force recalc
19936 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
19941 delayAutoWidth : function(){
19944 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
19946 this.awTask.delay(20);
19951 findTargetItem : function(e){
19952 var t = e.getTarget(".x-menu-list-item", this.ul, true);
19953 if(t && t.menuItemId){
19954 return this.items.get(t.menuItemId);
19959 onClick : function(e){
19961 if(t = this.findTargetItem(e)){
19963 this.fireEvent("click", this, t, e);
19968 setActiveItem : function(item, autoExpand){
19969 if(item != this.activeItem){
19970 if(this.activeItem){
19971 this.activeItem.deactivate();
19973 this.activeItem = item;
19974 item.activate(autoExpand);
19975 }else if(autoExpand){
19981 tryActivate : function(start, step){
19982 var items = this.items;
19983 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
19984 var item = items.get(i);
19985 if(!item.disabled && item.canActivate){
19986 this.setActiveItem(item, false);
19994 onMouseOver : function(e){
19996 if(t = this.findTargetItem(e)){
19997 if(t.canActivate && !t.disabled){
19998 this.setActiveItem(t, true);
20001 this.fireEvent("mouseover", this, e, t);
20005 onMouseOut : function(e){
20007 if(t = this.findTargetItem(e)){
20008 if(t == this.activeItem && t.shouldDeactivate(e)){
20009 this.activeItem.deactivate();
20010 delete this.activeItem;
20013 this.fireEvent("mouseout", this, e, t);
20017 * Read-only. Returns true if the menu is currently displayed, else false.
20020 isVisible : function(){
20021 return this.el && !this.hidden;
20025 * Displays this menu relative to another element
20026 * @param {String/HTMLElement/Roo.Element} element The element to align to
20027 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
20028 * the element (defaults to this.defaultAlign)
20029 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
20031 show : function(el, pos, parentMenu){
20032 this.parentMenu = parentMenu;
20036 this.fireEvent("beforeshow", this);
20037 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
20041 * Displays this menu at a specific xy position
20042 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
20043 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
20045 showAt : function(xy, parentMenu, /* private: */_e){
20046 this.parentMenu = parentMenu;
20051 this.fireEvent("beforeshow", this);
20052 xy = this.el.adjustForConstraints(xy);
20056 this.hidden = false;
20058 this.fireEvent("show", this);
20061 focus : function(){
20063 this.doFocus.defer(50, this);
20067 doFocus : function(){
20069 this.focusEl.focus();
20074 * Hides this menu and optionally all parent menus
20075 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
20077 hide : function(deep){
20078 if(this.el && this.isVisible()){
20079 this.fireEvent("beforehide", this);
20080 if(this.activeItem){
20081 this.activeItem.deactivate();
20082 this.activeItem = null;
20085 this.hidden = true;
20086 this.fireEvent("hide", this);
20088 if(deep === true && this.parentMenu){
20089 this.parentMenu.hide(true);
20094 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
20095 * Any of the following are valid:
20097 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
20098 * <li>An HTMLElement object which will be converted to a menu item</li>
20099 * <li>A menu item config object that will be created as a new menu item</li>
20100 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
20101 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
20106 var menu = new Roo.menu.Menu();
20108 // Create a menu item to add by reference
20109 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
20111 // Add a bunch of items at once using different methods.
20112 // Only the last item added will be returned.
20113 var item = menu.add(
20114 menuItem, // add existing item by ref
20115 'Dynamic Item', // new TextItem
20116 '-', // new separator
20117 { text: 'Config Item' } // new item by config
20120 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
20121 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
20124 var a = arguments, l = a.length, item;
20125 for(var i = 0; i < l; i++){
20127 if ((typeof(el) == "object") && el.xtype && el.xns) {
20128 el = Roo.factory(el, Roo.menu);
20131 if(el.render){ // some kind of Item
20132 item = this.addItem(el);
20133 }else if(typeof el == "string"){ // string
20134 if(el == "separator" || el == "-"){
20135 item = this.addSeparator();
20137 item = this.addText(el);
20139 }else if(el.tagName || el.el){ // element
20140 item = this.addElement(el);
20141 }else if(typeof el == "object"){ // must be menu item config?
20142 item = this.addMenuItem(el);
20149 * Returns this menu's underlying {@link Roo.Element} object
20150 * @return {Roo.Element} The element
20152 getEl : function(){
20160 * Adds a separator bar to the menu
20161 * @return {Roo.menu.Item} The menu item that was added
20163 addSeparator : function(){
20164 return this.addItem(new Roo.menu.Separator());
20168 * Adds an {@link Roo.Element} object to the menu
20169 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
20170 * @return {Roo.menu.Item} The menu item that was added
20172 addElement : function(el){
20173 return this.addItem(new Roo.menu.BaseItem(el));
20177 * Adds an existing object based on {@link Roo.menu.Item} to the menu
20178 * @param {Roo.menu.Item} item The menu item to add
20179 * @return {Roo.menu.Item} The menu item that was added
20181 addItem : function(item){
20182 this.items.add(item);
20184 var li = document.createElement("li");
20185 li.className = "x-menu-list-item";
20186 this.ul.dom.appendChild(li);
20187 item.render(li, this);
20188 this.delayAutoWidth();
20194 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
20195 * @param {Object} config A MenuItem config object
20196 * @return {Roo.menu.Item} The menu item that was added
20198 addMenuItem : function(config){
20199 if(!(config instanceof Roo.menu.Item)){
20200 if(typeof config.checked == "boolean"){ // must be check menu item config?
20201 config = new Roo.menu.CheckItem(config);
20203 config = new Roo.menu.Item(config);
20206 return this.addItem(config);
20210 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
20211 * @param {String} text The text to display in the menu item
20212 * @return {Roo.menu.Item} The menu item that was added
20214 addText : function(text){
20215 return this.addItem(new Roo.menu.TextItem({ text : text }));
20219 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
20220 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
20221 * @param {Roo.menu.Item} item The menu item to add
20222 * @return {Roo.menu.Item} The menu item that was added
20224 insert : function(index, item){
20225 this.items.insert(index, item);
20227 var li = document.createElement("li");
20228 li.className = "x-menu-list-item";
20229 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
20230 item.render(li, this);
20231 this.delayAutoWidth();
20237 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
20238 * @param {Roo.menu.Item} item The menu item to remove
20240 remove : function(item){
20241 this.items.removeKey(item.id);
20246 * Removes and destroys all items in the menu
20248 removeAll : function(){
20250 while(f = this.items.first()){
20256 // MenuNav is a private utility class used internally by the Menu
20257 Roo.menu.MenuNav = function(menu){
20258 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
20259 this.scope = this.menu = menu;
20262 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
20263 doRelay : function(e, h){
20264 var k = e.getKey();
20265 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
20266 this.menu.tryActivate(0, 1);
20269 return h.call(this.scope || this, e, this.menu);
20272 up : function(e, m){
20273 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
20274 m.tryActivate(m.items.length-1, -1);
20278 down : function(e, m){
20279 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
20280 m.tryActivate(0, 1);
20284 right : function(e, m){
20286 m.activeItem.expandMenu(true);
20290 left : function(e, m){
20292 if(m.parentMenu && m.parentMenu.activeItem){
20293 m.parentMenu.activeItem.activate();
20297 enter : function(e, m){
20299 e.stopPropagation();
20300 m.activeItem.onClick(e);
20301 m.fireEvent("click", this, m.activeItem);
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.MenuMgr
20318 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
20321 Roo.menu.MenuMgr = function(){
20322 var menus, active, groups = {}, attached = false, lastShow = new Date();
20324 // private - called when first menu is created
20327 active = new Roo.util.MixedCollection();
20328 Roo.get(document).addKeyListener(27, function(){
20329 if(active.length > 0){
20336 function hideAll(){
20337 if(active && active.length > 0){
20338 var c = active.clone();
20339 c.each(function(m){
20346 function onHide(m){
20348 if(active.length < 1){
20349 Roo.get(document).un("mousedown", onMouseDown);
20355 function onShow(m){
20356 var last = active.last();
20357 lastShow = new Date();
20360 Roo.get(document).on("mousedown", onMouseDown);
20364 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
20365 m.parentMenu.activeChild = m;
20366 }else if(last && last.isVisible()){
20367 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
20372 function onBeforeHide(m){
20374 m.activeChild.hide();
20376 if(m.autoHideTimer){
20377 clearTimeout(m.autoHideTimer);
20378 delete m.autoHideTimer;
20383 function onBeforeShow(m){
20384 var pm = m.parentMenu;
20385 if(!pm && !m.allowOtherMenus){
20387 }else if(pm && pm.activeChild && active != m){
20388 pm.activeChild.hide();
20393 function onMouseDown(e){
20394 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
20400 function onBeforeCheck(mi, state){
20402 var g = groups[mi.group];
20403 for(var i = 0, l = g.length; i < l; i++){
20405 g[i].setChecked(false);
20414 * Hides all menus that are currently visible
20416 hideAll : function(){
20421 register : function(menu){
20425 menus[menu.id] = menu;
20426 menu.on("beforehide", onBeforeHide);
20427 menu.on("hide", onHide);
20428 menu.on("beforeshow", onBeforeShow);
20429 menu.on("show", onShow);
20430 var g = menu.group;
20431 if(g && menu.events["checkchange"]){
20435 groups[g].push(menu);
20436 menu.on("checkchange", onCheck);
20441 * Returns a {@link Roo.menu.Menu} object
20442 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
20443 * be used to generate and return a new Menu instance.
20445 get : function(menu){
20446 if(typeof menu == "string"){ // menu id
20447 return menus[menu];
20448 }else if(menu.events){ // menu instance
20450 }else if(typeof menu.length == 'number'){ // array of menu items?
20451 return new Roo.menu.Menu({items:menu});
20452 }else{ // otherwise, must be a config
20453 return new Roo.menu.Menu(menu);
20458 unregister : function(menu){
20459 delete menus[menu.id];
20460 menu.un("beforehide", onBeforeHide);
20461 menu.un("hide", onHide);
20462 menu.un("beforeshow", onBeforeShow);
20463 menu.un("show", onShow);
20464 var g = menu.group;
20465 if(g && menu.events["checkchange"]){
20466 groups[g].remove(menu);
20467 menu.un("checkchange", onCheck);
20472 registerCheckable : function(menuItem){
20473 var g = menuItem.group;
20478 groups[g].push(menuItem);
20479 menuItem.on("beforecheckchange", onBeforeCheck);
20484 unregisterCheckable : function(menuItem){
20485 var g = menuItem.group;
20487 groups[g].remove(menuItem);
20488 menuItem.un("beforecheckchange", onBeforeCheck);
20494 * Ext JS Library 1.1.1
20495 * Copyright(c) 2006-2007, Ext JS, LLC.
20497 * Originally Released Under LGPL - original licence link has changed is not relivant.
20500 * <script type="text/javascript">
20505 * @class Roo.menu.BaseItem
20506 * @extends Roo.Component
20507 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
20508 * management and base configuration options shared by all menu components.
20510 * Creates a new BaseItem
20511 * @param {Object} config Configuration options
20513 Roo.menu.BaseItem = function(config){
20514 Roo.menu.BaseItem.superclass.constructor.call(this, config);
20519 * Fires when this item is clicked
20520 * @param {Roo.menu.BaseItem} this
20521 * @param {Roo.EventObject} e
20526 * Fires when this item is activated
20527 * @param {Roo.menu.BaseItem} this
20531 * @event deactivate
20532 * Fires when this item is deactivated
20533 * @param {Roo.menu.BaseItem} this
20539 this.on("click", this.handler, this.scope, true);
20543 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
20545 * @cfg {Function} handler
20546 * A function that will handle the click event of this menu item (defaults to undefined)
20549 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
20551 canActivate : false,
20554 * @cfg {Boolean} hidden True to prevent creation of this menu item (defaults to false)
20559 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
20561 activeClass : "x-menu-item-active",
20563 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
20565 hideOnClick : true,
20567 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
20572 ctype: "Roo.menu.BaseItem",
20575 actionMode : "container",
20578 render : function(container, parentMenu){
20579 this.parentMenu = parentMenu;
20580 Roo.menu.BaseItem.superclass.render.call(this, container);
20581 this.container.menuItemId = this.id;
20585 onRender : function(container, position){
20586 this.el = Roo.get(this.el);
20587 container.dom.appendChild(this.el.dom);
20591 onClick : function(e){
20592 if(!this.disabled && this.fireEvent("click", this, e) !== false
20593 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
20594 this.handleClick(e);
20601 activate : function(){
20605 var li = this.container;
20606 li.addClass(this.activeClass);
20607 this.region = li.getRegion().adjust(2, 2, -2, -2);
20608 this.fireEvent("activate", this);
20613 deactivate : function(){
20614 this.container.removeClass(this.activeClass);
20615 this.fireEvent("deactivate", this);
20619 shouldDeactivate : function(e){
20620 return !this.region || !this.region.contains(e.getPoint());
20624 handleClick : function(e){
20625 if(this.hideOnClick){
20626 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
20631 expandMenu : function(autoActivate){
20636 hideMenu : function(){
20641 * Ext JS Library 1.1.1
20642 * Copyright(c) 2006-2007, Ext JS, LLC.
20644 * Originally Released Under LGPL - original licence link has changed is not relivant.
20647 * <script type="text/javascript">
20651 * @class Roo.menu.Adapter
20652 * @extends Roo.menu.BaseItem
20653 * 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.
20654 * It provides basic rendering, activation management and enable/disable logic required to work in menus.
20656 * Creates a new Adapter
20657 * @param {Object} config Configuration options
20659 Roo.menu.Adapter = function(component, config){
20660 Roo.menu.Adapter.superclass.constructor.call(this, config);
20661 this.component = component;
20663 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
20665 canActivate : true,
20668 onRender : function(container, position){
20669 this.component.render(container);
20670 this.el = this.component.getEl();
20674 activate : function(){
20678 this.component.focus();
20679 this.fireEvent("activate", this);
20684 deactivate : function(){
20685 this.fireEvent("deactivate", this);
20689 disable : function(){
20690 this.component.disable();
20691 Roo.menu.Adapter.superclass.disable.call(this);
20695 enable : function(){
20696 this.component.enable();
20697 Roo.menu.Adapter.superclass.enable.call(this);
20701 * Ext JS Library 1.1.1
20702 * Copyright(c) 2006-2007, Ext JS, LLC.
20704 * Originally Released Under LGPL - original licence link has changed is not relivant.
20707 * <script type="text/javascript">
20711 * @class Roo.menu.TextItem
20712 * @extends Roo.menu.BaseItem
20713 * Adds a static text string to a menu, usually used as either a heading or group separator.
20714 * Note: old style constructor with text is still supported.
20717 * Creates a new TextItem
20718 * @param {Object} cfg Configuration
20720 Roo.menu.TextItem = function(cfg){
20721 if (typeof(cfg) == 'string') {
20724 Roo.apply(this,cfg);
20727 Roo.menu.TextItem.superclass.constructor.call(this);
20730 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
20732 * @cfg {Boolean} text Text to show on item.
20737 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
20739 hideOnClick : false,
20741 * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
20743 itemCls : "x-menu-text",
20746 onRender : function(){
20747 var s = document.createElement("span");
20748 s.className = this.itemCls;
20749 s.innerHTML = this.text;
20751 Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
20755 * Ext JS Library 1.1.1
20756 * Copyright(c) 2006-2007, Ext JS, LLC.
20758 * Originally Released Under LGPL - original licence link has changed is not relivant.
20761 * <script type="text/javascript">
20765 * @class Roo.menu.Separator
20766 * @extends Roo.menu.BaseItem
20767 * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
20768 * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
20770 * @param {Object} config Configuration options
20772 Roo.menu.Separator = function(config){
20773 Roo.menu.Separator.superclass.constructor.call(this, config);
20776 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
20778 * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
20780 itemCls : "x-menu-sep",
20782 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
20784 hideOnClick : false,
20787 onRender : function(li){
20788 var s = document.createElement("span");
20789 s.className = this.itemCls;
20790 s.innerHTML = " ";
20792 li.addClass("x-menu-sep-li");
20793 Roo.menu.Separator.superclass.onRender.apply(this, arguments);
20797 * Ext JS Library 1.1.1
20798 * Copyright(c) 2006-2007, Ext JS, LLC.
20800 * Originally Released Under LGPL - original licence link has changed is not relivant.
20803 * <script type="text/javascript">
20806 * @class Roo.menu.Item
20807 * @extends Roo.menu.BaseItem
20808 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
20809 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
20810 * activation and click handling.
20812 * Creates a new Item
20813 * @param {Object} config Configuration options
20815 Roo.menu.Item = function(config){
20816 Roo.menu.Item.superclass.constructor.call(this, config);
20818 this.menu = Roo.menu.MenuMgr.get(this.menu);
20821 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
20824 * @cfg {String} text
20825 * The text to show on the menu item.
20829 * @cfg {String} HTML to render in menu
20830 * The text to show on the menu item (HTML version).
20834 * @cfg {String} icon
20835 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
20839 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
20841 itemCls : "x-menu-item",
20843 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
20845 canActivate : true,
20847 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
20850 // doc'd in BaseItem
20854 ctype: "Roo.menu.Item",
20857 onRender : function(container, position){
20858 var el = document.createElement("a");
20859 el.hideFocus = true;
20860 el.unselectable = "on";
20861 el.href = this.href || "#";
20862 if(this.hrefTarget){
20863 el.target = this.hrefTarget;
20865 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
20867 var html = this.html.length ? this.html : String.format('{0}',this.text);
20869 el.innerHTML = String.format(
20870 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
20871 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
20873 Roo.menu.Item.superclass.onRender.call(this, container, position);
20877 * Sets the text to display in this menu item
20878 * @param {String} text The text to display
20879 * @param {Boolean} isHTML true to indicate text is pure html.
20881 setText : function(text, isHTML){
20889 var html = this.html.length ? this.html : String.format('{0}',this.text);
20891 this.el.update(String.format(
20892 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
20893 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
20894 this.parentMenu.autoWidth();
20899 handleClick : function(e){
20900 if(!this.href){ // if no link defined, stop the event automatically
20903 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
20907 activate : function(autoExpand){
20908 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
20918 shouldDeactivate : function(e){
20919 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
20920 if(this.menu && this.menu.isVisible()){
20921 return !this.menu.getEl().getRegion().contains(e.getPoint());
20929 deactivate : function(){
20930 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
20935 expandMenu : function(autoActivate){
20936 if(!this.disabled && this.menu){
20937 clearTimeout(this.hideTimer);
20938 delete this.hideTimer;
20939 if(!this.menu.isVisible() && !this.showTimer){
20940 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
20941 }else if (this.menu.isVisible() && autoActivate){
20942 this.menu.tryActivate(0, 1);
20948 deferExpand : function(autoActivate){
20949 delete this.showTimer;
20950 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
20952 this.menu.tryActivate(0, 1);
20957 hideMenu : function(){
20958 clearTimeout(this.showTimer);
20959 delete this.showTimer;
20960 if(!this.hideTimer && this.menu && this.menu.isVisible()){
20961 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
20966 deferHide : function(){
20967 delete this.hideTimer;
20972 * Ext JS Library 1.1.1
20973 * Copyright(c) 2006-2007, Ext JS, LLC.
20975 * Originally Released Under LGPL - original licence link has changed is not relivant.
20978 * <script type="text/javascript">
20982 * @class Roo.menu.CheckItem
20983 * @extends Roo.menu.Item
20984 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
20986 * Creates a new CheckItem
20987 * @param {Object} config Configuration options
20989 Roo.menu.CheckItem = function(config){
20990 Roo.menu.CheckItem.superclass.constructor.call(this, config);
20993 * @event beforecheckchange
20994 * Fires before the checked value is set, providing an opportunity to cancel if needed
20995 * @param {Roo.menu.CheckItem} this
20996 * @param {Boolean} checked The new checked value that will be set
20998 "beforecheckchange" : true,
21000 * @event checkchange
21001 * Fires after the checked value has been set
21002 * @param {Roo.menu.CheckItem} this
21003 * @param {Boolean} checked The checked value that was set
21005 "checkchange" : true
21007 if(this.checkHandler){
21008 this.on('checkchange', this.checkHandler, this.scope);
21011 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
21013 * @cfg {String} group
21014 * All check items with the same group name will automatically be grouped into a single-select
21015 * radio button group (defaults to '')
21018 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
21020 itemCls : "x-menu-item x-menu-check-item",
21022 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
21024 groupClass : "x-menu-group-item",
21027 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
21028 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
21029 * initialized with checked = true will be rendered as checked.
21034 ctype: "Roo.menu.CheckItem",
21037 onRender : function(c){
21038 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
21040 this.el.addClass(this.groupClass);
21042 Roo.menu.MenuMgr.registerCheckable(this);
21044 this.checked = false;
21045 this.setChecked(true, true);
21050 destroy : function(){
21052 Roo.menu.MenuMgr.unregisterCheckable(this);
21054 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
21058 * Set the checked state of this item
21059 * @param {Boolean} checked The new checked value
21060 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
21062 setChecked : function(state, suppressEvent){
21063 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
21064 if(this.container){
21065 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
21067 this.checked = state;
21068 if(suppressEvent !== true){
21069 this.fireEvent("checkchange", this, state);
21075 handleClick : function(e){
21076 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
21077 this.setChecked(!this.checked);
21079 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
21083 * Ext JS Library 1.1.1
21084 * Copyright(c) 2006-2007, Ext JS, LLC.
21086 * Originally Released Under LGPL - original licence link has changed is not relivant.
21089 * <script type="text/javascript">
21093 * @class Roo.menu.DateItem
21094 * @extends Roo.menu.Adapter
21095 * A menu item that wraps the {@link Roo.DatPicker} component.
21097 * Creates a new DateItem
21098 * @param {Object} config Configuration options
21100 Roo.menu.DateItem = function(config){
21101 Roo.menu.DateItem.superclass.constructor.call(this, new Roo.DatePicker(config), config);
21102 /** The Roo.DatePicker object @type Roo.DatePicker */
21103 this.picker = this.component;
21104 this.addEvents({select: true});
21106 this.picker.on("render", function(picker){
21107 picker.getEl().swallowEvent("click");
21108 picker.container.addClass("x-menu-date-item");
21111 this.picker.on("select", this.onSelect, this);
21114 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
21116 onSelect : function(picker, date){
21117 this.fireEvent("select", this, date, picker);
21118 Roo.menu.DateItem.superclass.handleClick.call(this);
21122 * Ext JS Library 1.1.1
21123 * Copyright(c) 2006-2007, Ext JS, LLC.
21125 * Originally Released Under LGPL - original licence link has changed is not relivant.
21128 * <script type="text/javascript">
21132 * @class Roo.menu.ColorItem
21133 * @extends Roo.menu.Adapter
21134 * A menu item that wraps the {@link Roo.ColorPalette} component.
21136 * Creates a new ColorItem
21137 * @param {Object} config Configuration options
21139 Roo.menu.ColorItem = function(config){
21140 Roo.menu.ColorItem.superclass.constructor.call(this, new Roo.ColorPalette(config), config);
21141 /** The Roo.ColorPalette object @type Roo.ColorPalette */
21142 this.palette = this.component;
21143 this.relayEvents(this.palette, ["select"]);
21144 if(this.selectHandler){
21145 this.on('select', this.selectHandler, this.scope);
21148 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);/*
21150 * Ext JS Library 1.1.1
21151 * Copyright(c) 2006-2007, Ext JS, LLC.
21153 * Originally Released Under LGPL - original licence link has changed is not relivant.
21156 * <script type="text/javascript">
21161 * @class Roo.menu.DateMenu
21162 * @extends Roo.menu.Menu
21163 * A menu containing a {@link Roo.menu.DateItem} component (which provides a date picker).
21165 * Creates a new DateMenu
21166 * @param {Object} config Configuration options
21168 Roo.menu.DateMenu = function(config){
21169 Roo.menu.DateMenu.superclass.constructor.call(this, config);
21171 var di = new Roo.menu.DateItem(config);
21174 * The {@link Roo.DatePicker} instance for this DateMenu
21177 this.picker = di.picker;
21180 * @param {DatePicker} picker
21181 * @param {Date} date
21183 this.relayEvents(di, ["select"]);
21184 this.on('beforeshow', function(){
21186 this.picker.hideMonthPicker(false);
21190 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
21194 * Ext JS Library 1.1.1
21195 * Copyright(c) 2006-2007, Ext JS, LLC.
21197 * Originally Released Under LGPL - original licence link has changed is not relivant.
21200 * <script type="text/javascript">
21205 * @class Roo.menu.ColorMenu
21206 * @extends Roo.menu.Menu
21207 * A menu containing a {@link Roo.menu.ColorItem} component (which provides a basic color picker).
21209 * Creates a new ColorMenu
21210 * @param {Object} config Configuration options
21212 Roo.menu.ColorMenu = function(config){
21213 Roo.menu.ColorMenu.superclass.constructor.call(this, config);
21215 var ci = new Roo.menu.ColorItem(config);
21218 * The {@link Roo.ColorPalette} instance for this ColorMenu
21219 * @type ColorPalette
21221 this.palette = ci.palette;
21224 * @param {ColorPalette} palette
21225 * @param {String} color
21227 this.relayEvents(ci, ["select"]);
21229 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);/*
21231 * Ext JS Library 1.1.1
21232 * Copyright(c) 2006-2007, Ext JS, LLC.
21234 * Originally Released Under LGPL - original licence link has changed is not relivant.
21237 * <script type="text/javascript">
21241 * @class Roo.form.Field
21242 * @extends Roo.BoxComponent
21243 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
21245 * Creates a new Field
21246 * @param {Object} config Configuration options
21248 Roo.form.Field = function(config){
21249 Roo.form.Field.superclass.constructor.call(this, config);
21252 Roo.extend(Roo.form.Field, Roo.BoxComponent, {
21254 * @cfg {String} fieldLabel Label to use when rendering a form.
21257 * @cfg {String} qtip Mouse over tip
21261 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
21263 invalidClass : "x-form-invalid",
21265 * @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")
21267 invalidText : "The value in this field is invalid",
21269 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
21271 focusClass : "x-form-focus",
21273 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
21274 automatic validation (defaults to "keyup").
21276 validationEvent : "keyup",
21278 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
21280 validateOnBlur : true,
21282 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
21284 validationDelay : 250,
21286 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
21287 * {tag: "input", type: "text", size: "20", autocomplete: "off"})
21289 defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"},
21291 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field")
21293 fieldClass : "x-form-field",
21295 * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'):
21298 ----------- ----------------------------------------------------------------------
21299 qtip Display a quick tip when the user hovers over the field
21300 title Display a default browser title attribute popup
21301 under Add a block div beneath the field containing the error text
21302 side Add an error icon to the right of the field with a popup on hover
21303 [element id] Add the error text directly to the innerHTML of the specified element
21306 msgTarget : 'qtip',
21308 * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal').
21313 * @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.
21318 * @cfg {Boolean} disabled True to disable the field (defaults to false).
21323 * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password (defaults to "text").
21325 inputType : undefined,
21328 * @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).
21330 tabIndex : undefined,
21333 isFormField : true,
21338 * @property {Roo.Element} fieldEl
21339 * Element Containing the rendered Field (with label etc.)
21342 * @cfg {Mixed} value A value to initialize this field with.
21347 * @cfg {String} name The field's HTML name attribute.
21350 * @cfg {String} cls A CSS class to apply to the field's underlying element.
21354 initComponent : function(){
21355 Roo.form.Field.superclass.initComponent.call(this);
21359 * Fires when this field receives input focus.
21360 * @param {Roo.form.Field} this
21365 * Fires when this field loses input focus.
21366 * @param {Roo.form.Field} this
21370 * @event specialkey
21371 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
21372 * {@link Roo.EventObject#getKey} to determine which key was pressed.
21373 * @param {Roo.form.Field} this
21374 * @param {Roo.EventObject} e The event object
21379 * Fires just before the field blurs if the field value has changed.
21380 * @param {Roo.form.Field} this
21381 * @param {Mixed} newValue The new value
21382 * @param {Mixed} oldValue The original value
21387 * Fires after the field has been marked as invalid.
21388 * @param {Roo.form.Field} this
21389 * @param {String} msg The validation message
21394 * Fires after the field has been validated with no errors.
21395 * @param {Roo.form.Field} this
21400 * Fires after the key up
21401 * @param {Roo.form.Field} this
21402 * @param {Roo.EventObject} e The event Object
21409 * Returns the name attribute of the field if available
21410 * @return {String} name The field name
21412 getName: function(){
21413 return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
21417 onRender : function(ct, position){
21418 Roo.form.Field.superclass.onRender.call(this, ct, position);
21420 var cfg = this.getAutoCreate();
21422 cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
21424 if (!cfg.name.length) {
21427 if(this.inputType){
21428 cfg.type = this.inputType;
21430 this.el = ct.createChild(cfg, position);
21432 var type = this.el.dom.type;
21434 if(type == 'password'){
21437 this.el.addClass('x-form-'+type);
21440 this.el.dom.readOnly = true;
21442 if(this.tabIndex !== undefined){
21443 this.el.dom.setAttribute('tabIndex', this.tabIndex);
21446 this.el.addClass([this.fieldClass, this.cls]);
21451 * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b>
21452 * @param {String/HTMLElement/Element} el The id of the node, a DOM node or an existing Element
21453 * @return {Roo.form.Field} this
21455 applyTo : function(target){
21456 this.allowDomMove = false;
21457 this.el = Roo.get(target);
21458 this.render(this.el.dom.parentNode);
21463 initValue : function(){
21464 if(this.value !== undefined){
21465 this.setValue(this.value);
21466 }else if(this.el.dom.value.length > 0){
21467 this.setValue(this.el.dom.value);
21472 * Returns true if this field has been changed since it was originally loaded and is not disabled.
21474 isDirty : function() {
21475 if(this.disabled) {
21478 return String(this.getValue()) !== String(this.originalValue);
21482 afterRender : function(){
21483 Roo.form.Field.superclass.afterRender.call(this);
21488 fireKey : function(e){
21489 //Roo.log('field ' + e.getKey());
21490 if(e.isNavKeyPress()){
21491 this.fireEvent("specialkey", this, e);
21496 * Resets the current field value to the originally loaded value and clears any validation messages
21498 reset : function(){
21499 this.setValue(this.originalValue);
21500 this.clearInvalid();
21504 initEvents : function(){
21505 // safari killled keypress - so keydown is now used..
21506 this.el.on("keydown" , this.fireKey, this);
21507 this.el.on("focus", this.onFocus, this);
21508 this.el.on("blur", this.onBlur, this);
21509 this.el.relayEvent('keyup', this);
21511 // reference to original value for reset
21512 this.originalValue = this.getValue();
21516 onFocus : function(){
21517 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
21518 this.el.addClass(this.focusClass);
21520 if(!this.hasFocus){
21521 this.hasFocus = true;
21522 this.startValue = this.getValue();
21523 this.fireEvent("focus", this);
21527 beforeBlur : Roo.emptyFn,
21530 onBlur : function(){
21532 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
21533 this.el.removeClass(this.focusClass);
21535 this.hasFocus = false;
21536 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
21539 var v = this.getValue();
21540 if(String(v) !== String(this.startValue)){
21541 this.fireEvent('change', this, v, this.startValue);
21543 this.fireEvent("blur", this);
21547 * Returns whether or not the field value is currently valid
21548 * @param {Boolean} preventMark True to disable marking the field invalid
21549 * @return {Boolean} True if the value is valid, else false
21551 isValid : function(preventMark){
21555 var restore = this.preventMark;
21556 this.preventMark = preventMark === true;
21557 var v = this.validateValue(this.processValue(this.getRawValue()));
21558 this.preventMark = restore;
21563 * Validates the field value
21564 * @return {Boolean} True if the value is valid, else false
21566 validate : function(){
21567 if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
21568 this.clearInvalid();
21574 processValue : function(value){
21579 // Subclasses should provide the validation implementation by overriding this
21580 validateValue : function(value){
21585 * Mark this field as invalid
21586 * @param {String} msg The validation message
21588 markInvalid : function(msg){
21589 if(!this.rendered || this.preventMark){ // not rendered
21592 this.el.addClass(this.invalidClass);
21593 msg = msg || this.invalidText;
21594 switch(this.msgTarget){
21596 this.el.dom.qtip = msg;
21597 this.el.dom.qclass = 'x-form-invalid-tip';
21598 if(Roo.QuickTips){ // fix for floating editors interacting with DND
21599 Roo.QuickTips.enable();
21603 this.el.dom.title = msg;
21607 var elp = this.el.findParent('.x-form-element', 5, true);
21608 this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
21609 this.errorEl.setWidth(elp.getWidth(true)-20);
21611 this.errorEl.update(msg);
21612 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
21615 if(!this.errorIcon){
21616 var elp = this.el.findParent('.x-form-element', 5, true);
21617 this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
21619 this.alignErrorIcon();
21620 this.errorIcon.dom.qtip = msg;
21621 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
21622 this.errorIcon.show();
21623 this.on('resize', this.alignErrorIcon, this);
21626 var t = Roo.getDom(this.msgTarget);
21628 t.style.display = this.msgDisplay;
21631 this.fireEvent('invalid', this, msg);
21635 alignErrorIcon : function(){
21636 this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
21640 * Clear any invalid styles/messages for this field
21642 clearInvalid : function(){
21643 if(!this.rendered || this.preventMark){ // not rendered
21646 this.el.removeClass(this.invalidClass);
21647 switch(this.msgTarget){
21649 this.el.dom.qtip = '';
21652 this.el.dom.title = '';
21656 Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
21660 if(this.errorIcon){
21661 this.errorIcon.dom.qtip = '';
21662 this.errorIcon.hide();
21663 this.un('resize', this.alignErrorIcon, this);
21667 var t = Roo.getDom(this.msgTarget);
21669 t.style.display = 'none';
21672 this.fireEvent('valid', this);
21676 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
21677 * @return {Mixed} value The field value
21679 getRawValue : function(){
21680 var v = this.el.getValue();
21686 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
21687 * @return {Mixed} value The field value
21689 getValue : function(){
21690 var v = this.el.getValue();
21696 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
21697 * @param {Mixed} value The value to set
21699 setRawValue : function(v){
21700 return this.el.dom.value = (v === null || v === undefined ? '' : v);
21704 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
21705 * @param {Mixed} value The value to set
21707 setValue : function(v){
21710 this.el.dom.value = (v === null || v === undefined ? '' : v);
21715 adjustSize : function(w, h){
21716 var s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
21717 s.width = this.adjustWidth(this.el.dom.tagName, s.width);
21721 adjustWidth : function(tag, w){
21722 tag = tag.toLowerCase();
21723 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
21724 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
21725 if(tag == 'input'){
21728 if(tag == 'textarea'){
21731 }else if(Roo.isOpera){
21732 if(tag == 'input'){
21735 if(tag == 'textarea'){
21745 // anything other than normal should be considered experimental
21746 Roo.form.Field.msgFx = {
21748 show: function(msgEl, f){
21749 msgEl.setDisplayed('block');
21752 hide : function(msgEl, f){
21753 msgEl.setDisplayed(false).update('');
21758 show: function(msgEl, f){
21759 msgEl.slideIn('t', {stopFx:true});
21762 hide : function(msgEl, f){
21763 msgEl.slideOut('t', {stopFx:true,useDisplay:true});
21768 show: function(msgEl, f){
21769 msgEl.fixDisplay();
21770 msgEl.alignTo(f.el, 'tl-tr');
21771 msgEl.slideIn('l', {stopFx:true});
21774 hide : function(msgEl, f){
21775 msgEl.slideOut('l', {stopFx:true,useDisplay:true});
21780 * Ext JS Library 1.1.1
21781 * Copyright(c) 2006-2007, Ext JS, LLC.
21783 * Originally Released Under LGPL - original licence link has changed is not relivant.
21786 * <script type="text/javascript">
21791 * @class Roo.form.TextField
21792 * @extends Roo.form.Field
21793 * Basic text field. Can be used as a direct replacement for traditional text inputs, or as the base
21794 * class for more sophisticated input controls (like {@link Roo.form.TextArea} and {@link Roo.form.ComboBox}).
21796 * Creates a new TextField
21797 * @param {Object} config Configuration options
21799 Roo.form.TextField = function(config){
21800 Roo.form.TextField.superclass.constructor.call(this, config);
21804 * Fires when the autosize function is triggered. The field may or may not have actually changed size
21805 * according to the default logic, but this event provides a hook for the developer to apply additional
21806 * logic at runtime to resize the field if needed.
21807 * @param {Roo.form.Field} this This text field
21808 * @param {Number} width The new field width
21814 Roo.extend(Roo.form.TextField, Roo.form.Field, {
21816 * @cfg {Boolean} grow True if this field should automatically grow and shrink to its content
21820 * @cfg {Number} growMin The minimum width to allow when grow = true (defaults to 30)
21824 * @cfg {Number} growMax The maximum width to allow when grow = true (defaults to 800)
21828 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
21832 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
21836 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
21838 disableKeyFilter : false,
21840 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
21844 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
21848 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
21850 maxLength : Number.MAX_VALUE,
21852 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
21854 minLengthText : "The minimum length for this field is {0}",
21856 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
21858 maxLengthText : "The maximum length for this field is {0}",
21860 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
21862 selectOnFocus : false,
21864 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
21866 blankText : "This field is required",
21868 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
21869 * If available, this function will be called only after the basic validators all return true, and will be passed the
21870 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
21874 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
21875 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
21876 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
21880 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
21884 * @cfg {String} emptyText The default text to display in an empty field - placeholder... (defaults to null).
21890 initEvents : function()
21892 if (this.emptyText) {
21893 this.el.attr('placeholder', this.emptyText);
21896 Roo.form.TextField.superclass.initEvents.call(this);
21897 if(this.validationEvent == 'keyup'){
21898 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
21899 this.el.on('keyup', this.filterValidation, this);
21901 else if(this.validationEvent !== false){
21902 this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
21905 if(this.selectOnFocus){
21906 this.on("focus", this.preFocus, this);
21909 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
21910 this.el.on("keypress", this.filterKeys, this);
21913 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
21914 this.el.on("click", this.autoSize, this);
21916 if(this.el.is('input[type=password]') && Roo.isSafari){
21917 this.el.on('keydown', this.SafariOnKeyDown, this);
21921 processValue : function(value){
21922 if(this.stripCharsRe){
21923 var newValue = value.replace(this.stripCharsRe, '');
21924 if(newValue !== value){
21925 this.setRawValue(newValue);
21932 filterValidation : function(e){
21933 if(!e.isNavKeyPress()){
21934 this.validationTask.delay(this.validationDelay);
21939 onKeyUp : function(e){
21940 if(!e.isNavKeyPress()){
21946 * Resets the current field value to the originally-loaded value and clears any validation messages.
21949 reset : function(){
21950 Roo.form.TextField.superclass.reset.call(this);
21956 preFocus : function(){
21958 if(this.selectOnFocus){
21959 this.el.dom.select();
21965 filterKeys : function(e){
21966 var k = e.getKey();
21967 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
21970 var c = e.getCharCode(), cc = String.fromCharCode(c);
21971 if(Roo.isIE && (e.isSpecialKey() || !cc)){
21974 if(!this.maskRe.test(cc)){
21979 setValue : function(v){
21981 Roo.form.TextField.superclass.setValue.apply(this, arguments);
21987 * Validates a value according to the field's validation rules and marks the field as invalid
21988 * if the validation fails
21989 * @param {Mixed} value The value to validate
21990 * @return {Boolean} True if the value is valid, else false
21992 validateValue : function(value){
21993 if(value.length < 1) { // if it's blank
21994 if(this.allowBlank){
21995 this.clearInvalid();
21998 this.markInvalid(this.blankText);
22002 if(value.length < this.minLength){
22003 this.markInvalid(String.format(this.minLengthText, this.minLength));
22006 if(value.length > this.maxLength){
22007 this.markInvalid(String.format(this.maxLengthText, this.maxLength));
22011 var vt = Roo.form.VTypes;
22012 if(!vt[this.vtype](value, this)){
22013 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
22017 if(typeof this.validator == "function"){
22018 var msg = this.validator(value);
22020 this.markInvalid(msg);
22024 if(this.regex && !this.regex.test(value)){
22025 this.markInvalid(this.regexText);
22032 * Selects text in this field
22033 * @param {Number} start (optional) The index where the selection should start (defaults to 0)
22034 * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
22036 selectText : function(start, end){
22037 var v = this.getRawValue();
22039 start = start === undefined ? 0 : start;
22040 end = end === undefined ? v.length : end;
22041 var d = this.el.dom;
22042 if(d.setSelectionRange){
22043 d.setSelectionRange(start, end);
22044 }else if(d.createTextRange){
22045 var range = d.createTextRange();
22046 range.moveStart("character", start);
22047 range.moveEnd("character", v.length-end);
22054 * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
22055 * This only takes effect if grow = true, and fires the autosize event.
22057 autoSize : function(){
22058 if(!this.grow || !this.rendered){
22062 this.metrics = Roo.util.TextMetrics.createInstance(this.el);
22065 var v = el.dom.value;
22066 var d = document.createElement('div');
22067 d.appendChild(document.createTextNode(v));
22071 var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
22072 this.el.setWidth(w);
22073 this.fireEvent("autosize", this, w);
22077 SafariOnKeyDown : function(event)
22079 // this is a workaround for a password hang bug on chrome/ webkit.
22081 var isSelectAll = false;
22083 if(this.el.dom.selectionEnd > 0){
22084 isSelectAll = (this.el.dom.selectionEnd - this.el.dom.selectionStart - this.getValue().length == 0) ? true : false;
22086 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
22087 event.preventDefault();
22092 if(isSelectAll){ // backspace and delete key
22094 event.preventDefault();
22095 // this is very hacky as keydown always get's upper case.
22097 var cc = String.fromCharCode(event.getCharCode());
22098 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
22106 * Ext JS Library 1.1.1
22107 * Copyright(c) 2006-2007, Ext JS, LLC.
22109 * Originally Released Under LGPL - original licence link has changed is not relivant.
22112 * <script type="text/javascript">
22116 * @class Roo.form.Hidden
22117 * @extends Roo.form.TextField
22118 * Simple Hidden element used on forms
22120 * usage: form.add(new Roo.form.HiddenField({ 'name' : 'test1' }));
22123 * Creates a new Hidden form element.
22124 * @param {Object} config Configuration options
22129 // easy hidden field...
22130 Roo.form.Hidden = function(config){
22131 Roo.form.Hidden.superclass.constructor.call(this, config);
22134 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
22136 inputType: 'hidden',
22139 labelSeparator: '',
22141 itemCls : 'x-form-item-display-none'
22149 * Ext JS Library 1.1.1
22150 * Copyright(c) 2006-2007, Ext JS, LLC.
22152 * Originally Released Under LGPL - original licence link has changed is not relivant.
22155 * <script type="text/javascript">
22159 * @class Roo.form.TriggerField
22160 * @extends Roo.form.TextField
22161 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
22162 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
22163 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
22164 * for which you can provide a custom implementation. For example:
22166 var trigger = new Roo.form.TriggerField();
22167 trigger.onTriggerClick = myTriggerFn;
22168 trigger.applyTo('my-field');
22171 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
22172 * {@link Roo.form.DateField} and {@link Roo.form.ComboBox} are perfect examples of this.
22173 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
22174 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
22176 * Create a new TriggerField.
22177 * @param {Object} config Configuration options (valid {@Roo.form.TextField} config options will also be applied
22178 * to the base TextField)
22180 Roo.form.TriggerField = function(config){
22181 this.mimicing = false;
22182 Roo.form.TriggerField.superclass.constructor.call(this, config);
22185 Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
22187 * @cfg {String} triggerClass A CSS class to apply to the trigger
22190 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
22191 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
22193 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
22195 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
22199 /** @cfg {Boolean} grow @hide */
22200 /** @cfg {Number} growMin @hide */
22201 /** @cfg {Number} growMax @hide */
22207 autoSize: Roo.emptyFn,
22211 deferHeight : true,
22214 actionMode : 'wrap',
22216 onResize : function(w, h){
22217 Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
22218 if(typeof w == 'number'){
22219 var x = w - this.trigger.getWidth();
22220 this.el.setWidth(this.adjustWidth('input', x));
22221 this.trigger.setStyle('left', x+'px');
22226 adjustSize : Roo.BoxComponent.prototype.adjustSize,
22229 getResizeEl : function(){
22234 getPositionEl : function(){
22239 alignErrorIcon : function(){
22240 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
22244 onRender : function(ct, position){
22245 Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
22246 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
22247 this.trigger = this.wrap.createChild(this.triggerConfig ||
22248 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
22249 if(this.hideTrigger){
22250 this.trigger.setDisplayed(false);
22252 this.initTrigger();
22254 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
22259 initTrigger : function(){
22260 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
22261 this.trigger.addClassOnOver('x-form-trigger-over');
22262 this.trigger.addClassOnClick('x-form-trigger-click');
22266 onDestroy : function(){
22268 this.trigger.removeAllListeners();
22269 this.trigger.remove();
22272 this.wrap.remove();
22274 Roo.form.TriggerField.superclass.onDestroy.call(this);
22278 onFocus : function(){
22279 Roo.form.TriggerField.superclass.onFocus.call(this);
22280 if(!this.mimicing){
22281 this.wrap.addClass('x-trigger-wrap-focus');
22282 this.mimicing = true;
22283 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
22284 if(this.monitorTab){
22285 this.el.on("keydown", this.checkTab, this);
22291 checkTab : function(e){
22292 if(e.getKey() == e.TAB){
22293 this.triggerBlur();
22298 onBlur : function(){
22303 mimicBlur : function(e, t){
22304 if(!this.wrap.contains(t) && this.validateBlur()){
22305 this.triggerBlur();
22310 triggerBlur : function(){
22311 this.mimicing = false;
22312 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
22313 if(this.monitorTab){
22314 this.el.un("keydown", this.checkTab, this);
22316 this.wrap.removeClass('x-trigger-wrap-focus');
22317 Roo.form.TriggerField.superclass.onBlur.call(this);
22321 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
22322 validateBlur : function(e, t){
22327 onDisable : function(){
22328 Roo.form.TriggerField.superclass.onDisable.call(this);
22330 this.wrap.addClass('x-item-disabled');
22335 onEnable : function(){
22336 Roo.form.TriggerField.superclass.onEnable.call(this);
22338 this.wrap.removeClass('x-item-disabled');
22343 onShow : function(){
22344 var ae = this.getActionEl();
22347 ae.dom.style.display = '';
22348 ae.dom.style.visibility = 'visible';
22354 onHide : function(){
22355 var ae = this.getActionEl();
22356 ae.dom.style.display = 'none';
22360 * The function that should handle the trigger's click event. This method does nothing by default until overridden
22361 * by an implementing function.
22363 * @param {EventObject} e
22365 onTriggerClick : Roo.emptyFn
22368 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
22369 // to be extended by an implementing class. For an example of implementing this class, see the custom
22370 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
22371 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
22372 initComponent : function(){
22373 Roo.form.TwinTriggerField.superclass.initComponent.call(this);
22375 this.triggerConfig = {
22376 tag:'span', cls:'x-form-twin-triggers', cn:[
22377 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
22378 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
22382 getTrigger : function(index){
22383 return this.triggers[index];
22386 initTrigger : function(){
22387 var ts = this.trigger.select('.x-form-trigger', true);
22388 this.wrap.setStyle('overflow', 'hidden');
22389 var triggerField = this;
22390 ts.each(function(t, all, index){
22391 t.hide = function(){
22392 var w = triggerField.wrap.getWidth();
22393 this.dom.style.display = 'none';
22394 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
22396 t.show = function(){
22397 var w = triggerField.wrap.getWidth();
22398 this.dom.style.display = '';
22399 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
22401 var triggerIndex = 'Trigger'+(index+1);
22403 if(this['hide'+triggerIndex]){
22404 t.dom.style.display = 'none';
22406 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
22407 t.addClassOnOver('x-form-trigger-over');
22408 t.addClassOnClick('x-form-trigger-click');
22410 this.triggers = ts.elements;
22413 onTrigger1Click : Roo.emptyFn,
22414 onTrigger2Click : Roo.emptyFn
22417 * Ext JS Library 1.1.1
22418 * Copyright(c) 2006-2007, Ext JS, LLC.
22420 * Originally Released Under LGPL - original licence link has changed is not relivant.
22423 * <script type="text/javascript">
22427 * @class Roo.form.TextArea
22428 * @extends Roo.form.TextField
22429 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
22430 * support for auto-sizing.
22432 * Creates a new TextArea
22433 * @param {Object} config Configuration options
22435 Roo.form.TextArea = function(config){
22436 Roo.form.TextArea.superclass.constructor.call(this, config);
22437 // these are provided exchanges for backwards compat
22438 // minHeight/maxHeight were replaced by growMin/growMax to be
22439 // compatible with TextField growing config values
22440 if(this.minHeight !== undefined){
22441 this.growMin = this.minHeight;
22443 if(this.maxHeight !== undefined){
22444 this.growMax = this.maxHeight;
22448 Roo.extend(Roo.form.TextArea, Roo.form.TextField, {
22450 * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
22454 * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
22458 * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
22459 * in the field (equivalent to setting overflow: hidden, defaults to false)
22461 preventScrollbars: false,
22463 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
22464 * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"})
22468 onRender : function(ct, position){
22470 this.defaultAutoCreate = {
22472 style:"width:300px;height:60px;",
22473 autocomplete: "off"
22476 Roo.form.TextArea.superclass.onRender.call(this, ct, position);
22478 this.textSizeEl = Roo.DomHelper.append(document.body, {
22479 tag: "pre", cls: "x-form-grow-sizer"
22481 if(this.preventScrollbars){
22482 this.el.setStyle("overflow", "hidden");
22484 this.el.setHeight(this.growMin);
22488 onDestroy : function(){
22489 if(this.textSizeEl){
22490 this.textSizeEl.parentNode.removeChild(this.textSizeEl);
22492 Roo.form.TextArea.superclass.onDestroy.call(this);
22496 onKeyUp : function(e){
22497 if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
22503 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
22504 * This only takes effect if grow = true, and fires the autosize event if the height changes.
22506 autoSize : function(){
22507 if(!this.grow || !this.textSizeEl){
22511 var v = el.dom.value;
22512 var ts = this.textSizeEl;
22515 ts.appendChild(document.createTextNode(v));
22518 Roo.fly(ts).setWidth(this.el.getWidth());
22520 v = "  ";
22523 v = v.replace(/\n/g, '<p> </p>');
22525 v += " \n ";
22528 var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
22529 if(h != this.lastHeight){
22530 this.lastHeight = h;
22531 this.el.setHeight(h);
22532 this.fireEvent("autosize", this, h);
22537 * Ext JS Library 1.1.1
22538 * Copyright(c) 2006-2007, Ext JS, LLC.
22540 * Originally Released Under LGPL - original licence link has changed is not relivant.
22543 * <script type="text/javascript">
22548 * @class Roo.form.NumberField
22549 * @extends Roo.form.TextField
22550 * Numeric text field that provides automatic keystroke filtering and numeric validation.
22552 * Creates a new NumberField
22553 * @param {Object} config Configuration options
22555 Roo.form.NumberField = function(config){
22556 Roo.form.NumberField.superclass.constructor.call(this, config);
22559 Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
22561 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
22563 fieldClass: "x-form-field x-form-num-field",
22565 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
22567 allowDecimals : true,
22569 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
22571 decimalSeparator : ".",
22573 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
22575 decimalPrecision : 2,
22577 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
22579 allowNegative : true,
22581 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
22583 minValue : Number.NEGATIVE_INFINITY,
22585 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
22587 maxValue : Number.MAX_VALUE,
22589 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
22591 minText : "The minimum value for this field is {0}",
22593 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
22595 maxText : "The maximum value for this field is {0}",
22597 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
22598 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
22600 nanText : "{0} is not a valid number",
22603 initEvents : function(){
22604 Roo.form.NumberField.superclass.initEvents.call(this);
22605 var allowed = "0123456789";
22606 if(this.allowDecimals){
22607 allowed += this.decimalSeparator;
22609 if(this.allowNegative){
22612 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
22613 var keyPress = function(e){
22614 var k = e.getKey();
22615 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
22618 var c = e.getCharCode();
22619 if(allowed.indexOf(String.fromCharCode(c)) === -1){
22623 this.el.on("keypress", keyPress, this);
22627 validateValue : function(value){
22628 if(!Roo.form.NumberField.superclass.validateValue.call(this, value)){
22631 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
22634 var num = this.parseValue(value);
22636 this.markInvalid(String.format(this.nanText, value));
22639 if(num < this.minValue){
22640 this.markInvalid(String.format(this.minText, this.minValue));
22643 if(num > this.maxValue){
22644 this.markInvalid(String.format(this.maxText, this.maxValue));
22650 getValue : function(){
22651 return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
22655 parseValue : function(value){
22656 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
22657 return isNaN(value) ? '' : value;
22661 fixPrecision : function(value){
22662 var nan = isNaN(value);
22663 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
22664 return nan ? '' : value;
22666 return parseFloat(value).toFixed(this.decimalPrecision);
22669 setValue : function(v){
22670 v = this.fixPrecision(v);
22671 Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
22675 decimalPrecisionFcn : function(v){
22676 return Math.floor(v);
22679 beforeBlur : function(){
22680 var v = this.parseValue(this.getRawValue());
22687 * Ext JS Library 1.1.1
22688 * Copyright(c) 2006-2007, Ext JS, LLC.
22690 * Originally Released Under LGPL - original licence link has changed is not relivant.
22693 * <script type="text/javascript">
22697 * @class Roo.form.DateField
22698 * @extends Roo.form.TriggerField
22699 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
22701 * Create a new DateField
22702 * @param {Object} config
22704 Roo.form.DateField = function(config){
22705 Roo.form.DateField.superclass.constructor.call(this, config);
22711 * Fires when a date is selected
22712 * @param {Roo.form.DateField} combo This combo box
22713 * @param {Date} date The date selected
22720 if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
22721 if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
22722 this.ddMatch = null;
22723 if(this.disabledDates){
22724 var dd = this.disabledDates;
22726 for(var i = 0; i < dd.length; i++){
22728 if(i != dd.length-1) re += "|";
22730 this.ddMatch = new RegExp(re + ")");
22734 Roo.extend(Roo.form.DateField, Roo.form.TriggerField, {
22736 * @cfg {String} format
22737 * The default date format string which can be overriden for localization support. The format must be
22738 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
22742 * @cfg {String} altFormats
22743 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
22744 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
22746 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
22748 * @cfg {Array} disabledDays
22749 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
22751 disabledDays : null,
22753 * @cfg {String} disabledDaysText
22754 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
22756 disabledDaysText : "Disabled",
22758 * @cfg {Array} disabledDates
22759 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
22760 * expression so they are very powerful. Some examples:
22762 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
22763 * <li>["03/08", "09/16"] would disable those days for every year</li>
22764 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
22765 * <li>["03/../2006"] would disable every day in March 2006</li>
22766 * <li>["^03"] would disable every day in every March</li>
22768 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
22769 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
22771 disabledDates : null,
22773 * @cfg {String} disabledDatesText
22774 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
22776 disabledDatesText : "Disabled",
22778 * @cfg {Date/String} minValue
22779 * The minimum allowed date. Can be either a Javascript date object or a string date in a
22780 * valid format (defaults to null).
22784 * @cfg {Date/String} maxValue
22785 * The maximum allowed date. Can be either a Javascript date object or a string date in a
22786 * valid format (defaults to null).
22790 * @cfg {String} minText
22791 * The error text to display when the date in the cell is before minValue (defaults to
22792 * 'The date in this field must be after {minValue}').
22794 minText : "The date in this field must be equal to or after {0}",
22796 * @cfg {String} maxText
22797 * The error text to display when the date in the cell is after maxValue (defaults to
22798 * 'The date in this field must be before {maxValue}').
22800 maxText : "The date in this field must be equal to or before {0}",
22802 * @cfg {String} invalidText
22803 * The error text to display when the date in the field is invalid (defaults to
22804 * '{value} is not a valid date - it must be in the format {format}').
22806 invalidText : "{0} is not a valid date - it must be in the format {1}",
22808 * @cfg {String} triggerClass
22809 * An additional CSS class used to style the trigger button. The trigger will always get the
22810 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
22811 * which displays a calendar icon).
22813 triggerClass : 'x-form-date-trigger',
22817 * @cfg {Boolean} useIso
22818 * if enabled, then the date field will use a hidden field to store the
22819 * real value as iso formated date. default (false)
22823 * @cfg {String/Object} autoCreate
22824 * A DomHelper element spec, or true for a default element spec (defaults to
22825 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
22828 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
22831 hiddenField: false,
22833 onRender : function(ct, position)
22835 Roo.form.DateField.superclass.onRender.call(this, ct, position);
22837 //this.el.dom.removeAttribute('name');
22838 Roo.log("Changing name?");
22839 this.el.dom.setAttribute('name', this.name + '____hidden___' );
22840 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
22842 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
22843 // prevent input submission
22844 this.hiddenName = this.name;
22851 validateValue : function(value)
22853 value = this.formatDate(value);
22854 if(!Roo.form.DateField.superclass.validateValue.call(this, value)){
22855 Roo.log('super failed');
22858 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
22861 var svalue = value;
22862 value = this.parseDate(value);
22864 Roo.log('parse date failed' + svalue);
22865 this.markInvalid(String.format(this.invalidText, svalue, this.format));
22868 var time = value.getTime();
22869 if(this.minValue && time < this.minValue.getTime()){
22870 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
22873 if(this.maxValue && time > this.maxValue.getTime()){
22874 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
22877 if(this.disabledDays){
22878 var day = value.getDay();
22879 for(var i = 0; i < this.disabledDays.length; i++) {
22880 if(day === this.disabledDays[i]){
22881 this.markInvalid(this.disabledDaysText);
22886 var fvalue = this.formatDate(value);
22887 if(this.ddMatch && this.ddMatch.test(fvalue)){
22888 this.markInvalid(String.format(this.disabledDatesText, fvalue));
22895 // Provides logic to override the default TriggerField.validateBlur which just returns true
22896 validateBlur : function(){
22897 return !this.menu || !this.menu.isVisible();
22900 getName: function()
22902 // returns hidden if it's set..
22903 if (!this.rendered) {return ''};
22904 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
22909 * Returns the current date value of the date field.
22910 * @return {Date} The date value
22912 getValue : function(){
22914 return this.hiddenField ?
22915 this.hiddenField.value :
22916 this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
22920 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
22921 * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}
22922 * (the default format used is "m/d/y").
22925 //All of these calls set the same date value (May 4, 2006)
22927 //Pass a date object:
22928 var dt = new Date('5/4/06');
22929 dateField.setValue(dt);
22931 //Pass a date string (default format):
22932 dateField.setValue('5/4/06');
22934 //Pass a date string (custom format):
22935 dateField.format = 'Y-m-d';
22936 dateField.setValue('2006-5-4');
22938 * @param {String/Date} date The date or valid date string
22940 setValue : function(date){
22941 if (this.hiddenField) {
22942 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
22944 Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
22945 // make sure the value field is always stored as a date..
22946 this.value = this.parseDate(date);
22952 parseDate : function(value){
22953 if(!value || value instanceof Date){
22956 var v = Date.parseDate(value, this.format);
22957 if (!v && this.useIso) {
22958 v = Date.parseDate(value, 'Y-m-d');
22960 if(!v && this.altFormats){
22961 if(!this.altFormatsArray){
22962 this.altFormatsArray = this.altFormats.split("|");
22964 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
22965 v = Date.parseDate(value, this.altFormatsArray[i]);
22972 formatDate : function(date, fmt){
22973 return (!date || !(date instanceof Date)) ?
22974 date : date.dateFormat(fmt || this.format);
22979 select: function(m, d){
22982 this.fireEvent('select', this, d);
22984 show : function(){ // retain focus styling
22988 this.focus.defer(10, this);
22989 var ml = this.menuListeners;
22990 this.menu.un("select", ml.select, this);
22991 this.menu.un("show", ml.show, this);
22992 this.menu.un("hide", ml.hide, this);
22997 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
22998 onTriggerClick : function(){
23002 if(this.menu == null){
23003 this.menu = new Roo.menu.DateMenu();
23005 Roo.apply(this.menu.picker, {
23006 showClear: this.allowBlank,
23007 minDate : this.minValue,
23008 maxDate : this.maxValue,
23009 disabledDatesRE : this.ddMatch,
23010 disabledDatesText : this.disabledDatesText,
23011 disabledDays : this.disabledDays,
23012 disabledDaysText : this.disabledDaysText,
23013 format : this.useIso ? 'Y-m-d' : this.format,
23014 minText : String.format(this.minText, this.formatDate(this.minValue)),
23015 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
23017 this.menu.on(Roo.apply({}, this.menuListeners, {
23020 this.menu.picker.setValue(this.getValue() || new Date());
23021 this.menu.show(this.el, "tl-bl?");
23024 beforeBlur : function(){
23025 var v = this.parseDate(this.getRawValue());
23031 /** @cfg {Boolean} grow @hide */
23032 /** @cfg {Number} growMin @hide */
23033 /** @cfg {Number} growMax @hide */
23040 * Ext JS Library 1.1.1
23041 * Copyright(c) 2006-2007, Ext JS, LLC.
23043 * Originally Released Under LGPL - original licence link has changed is not relivant.
23046 * <script type="text/javascript">
23050 * @class Roo.form.MonthField
23051 * @extends Roo.form.TriggerField
23052 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
23054 * Create a new MonthField
23055 * @param {Object} config
23057 Roo.form.MonthField = function(config){
23059 Roo.form.MonthField.superclass.constructor.call(this, config);
23065 * Fires when a date is selected
23066 * @param {Roo.form.MonthFieeld} combo This combo box
23067 * @param {Date} date The date selected
23074 if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
23075 if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
23076 this.ddMatch = null;
23077 if(this.disabledDates){
23078 var dd = this.disabledDates;
23080 for(var i = 0; i < dd.length; i++){
23082 if(i != dd.length-1) re += "|";
23084 this.ddMatch = new RegExp(re + ")");
23088 Roo.extend(Roo.form.MonthField, Roo.form.TriggerField, {
23090 * @cfg {String} format
23091 * The default date format string which can be overriden for localization support. The format must be
23092 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
23096 * @cfg {String} altFormats
23097 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
23098 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
23100 altFormats : "M Y|m/Y|m-y|m-Y|my|mY",
23102 * @cfg {Array} disabledDays
23103 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
23105 disabledDays : [0,1,2,3,4,5,6],
23107 * @cfg {String} disabledDaysText
23108 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
23110 disabledDaysText : "Disabled",
23112 * @cfg {Array} disabledDates
23113 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
23114 * expression so they are very powerful. Some examples:
23116 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
23117 * <li>["03/08", "09/16"] would disable those days for every year</li>
23118 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
23119 * <li>["03/../2006"] would disable every day in March 2006</li>
23120 * <li>["^03"] would disable every day in every March</li>
23122 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
23123 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
23125 disabledDates : null,
23127 * @cfg {String} disabledDatesText
23128 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
23130 disabledDatesText : "Disabled",
23132 * @cfg {Date/String} minValue
23133 * The minimum allowed date. Can be either a Javascript date object or a string date in a
23134 * valid format (defaults to null).
23138 * @cfg {Date/String} maxValue
23139 * The maximum allowed date. Can be either a Javascript date object or a string date in a
23140 * valid format (defaults to null).
23144 * @cfg {String} minText
23145 * The error text to display when the date in the cell is before minValue (defaults to
23146 * 'The date in this field must be after {minValue}').
23148 minText : "The date in this field must be equal to or after {0}",
23150 * @cfg {String} maxTextf
23151 * The error text to display when the date in the cell is after maxValue (defaults to
23152 * 'The date in this field must be before {maxValue}').
23154 maxText : "The date in this field must be equal to or before {0}",
23156 * @cfg {String} invalidText
23157 * The error text to display when the date in the field is invalid (defaults to
23158 * '{value} is not a valid date - it must be in the format {format}').
23160 invalidText : "{0} is not a valid date - it must be in the format {1}",
23162 * @cfg {String} triggerClass
23163 * An additional CSS class used to style the trigger button. The trigger will always get the
23164 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
23165 * which displays a calendar icon).
23167 triggerClass : 'x-form-date-trigger',
23171 * @cfg {Boolean} useIso
23172 * if enabled, then the date field will use a hidden field to store the
23173 * real value as iso formated date. default (true)
23177 * @cfg {String/Object} autoCreate
23178 * A DomHelper element spec, or true for a default element spec (defaults to
23179 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
23182 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
23185 hiddenField: false,
23187 hideMonthPicker : false,
23189 onRender : function(ct, position)
23191 Roo.form.MonthField.superclass.onRender.call(this, ct, position);
23193 this.el.dom.removeAttribute('name');
23194 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
23196 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
23197 // prevent input submission
23198 this.hiddenName = this.name;
23205 validateValue : function(value)
23207 value = this.formatDate(value);
23208 if(!Roo.form.MonthField.superclass.validateValue.call(this, value)){
23211 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
23214 var svalue = value;
23215 value = this.parseDate(value);
23217 this.markInvalid(String.format(this.invalidText, svalue, this.format));
23220 var time = value.getTime();
23221 if(this.minValue && time < this.minValue.getTime()){
23222 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
23225 if(this.maxValue && time > this.maxValue.getTime()){
23226 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
23229 /*if(this.disabledDays){
23230 var day = value.getDay();
23231 for(var i = 0; i < this.disabledDays.length; i++) {
23232 if(day === this.disabledDays[i]){
23233 this.markInvalid(this.disabledDaysText);
23239 var fvalue = this.formatDate(value);
23240 /*if(this.ddMatch && this.ddMatch.test(fvalue)){
23241 this.markInvalid(String.format(this.disabledDatesText, fvalue));
23249 // Provides logic to override the default TriggerField.validateBlur which just returns true
23250 validateBlur : function(){
23251 return !this.menu || !this.menu.isVisible();
23255 * Returns the current date value of the date field.
23256 * @return {Date} The date value
23258 getValue : function(){
23262 return this.hiddenField ?
23263 this.hiddenField.value :
23264 this.parseDate(Roo.form.MonthField.superclass.getValue.call(this)) || "";
23268 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
23269 * date, using MonthField.format as the date format, according to the same rules as {@link Date#parseDate}
23270 * (the default format used is "m/d/y").
23273 //All of these calls set the same date value (May 4, 2006)
23275 //Pass a date object:
23276 var dt = new Date('5/4/06');
23277 monthField.setValue(dt);
23279 //Pass a date string (default format):
23280 monthField.setValue('5/4/06');
23282 //Pass a date string (custom format):
23283 monthField.format = 'Y-m-d';
23284 monthField.setValue('2006-5-4');
23286 * @param {String/Date} date The date or valid date string
23288 setValue : function(date){
23289 Roo.log('month setValue' + date);
23290 // can only be first of month..
23292 var val = this.parseDate(date);
23294 if (this.hiddenField) {
23295 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
23297 Roo.form.MonthField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
23298 this.value = this.parseDate(date);
23302 parseDate : function(value){
23303 if(!value || value instanceof Date){
23304 value = value ? Date.parseDate(value.format('Y-m') + '-01', 'Y-m-d') : null;
23307 var v = Date.parseDate(value, this.format);
23308 if (!v && this.useIso) {
23309 v = Date.parseDate(value, 'Y-m-d');
23313 v = Date.parseDate(v.format('Y-m') +'-01', 'Y-m-d');
23317 if(!v && this.altFormats){
23318 if(!this.altFormatsArray){
23319 this.altFormatsArray = this.altFormats.split("|");
23321 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
23322 v = Date.parseDate(value, this.altFormatsArray[i]);
23329 formatDate : function(date, fmt){
23330 return (!date || !(date instanceof Date)) ?
23331 date : date.dateFormat(fmt || this.format);
23336 select: function(m, d){
23338 this.fireEvent('select', this, d);
23340 show : function(){ // retain focus styling
23344 this.focus.defer(10, this);
23345 var ml = this.menuListeners;
23346 this.menu.un("select", ml.select, this);
23347 this.menu.un("show", ml.show, this);
23348 this.menu.un("hide", ml.hide, this);
23352 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
23353 onTriggerClick : function(){
23357 if(this.menu == null){
23358 this.menu = new Roo.menu.DateMenu();
23362 Roo.apply(this.menu.picker, {
23364 showClear: this.allowBlank,
23365 minDate : this.minValue,
23366 maxDate : this.maxValue,
23367 disabledDatesRE : this.ddMatch,
23368 disabledDatesText : this.disabledDatesText,
23370 format : this.useIso ? 'Y-m-d' : this.format,
23371 minText : String.format(this.minText, this.formatDate(this.minValue)),
23372 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
23375 this.menu.on(Roo.apply({}, this.menuListeners, {
23383 // hide month picker get's called when we called by 'before hide';
23385 var ignorehide = true;
23386 p.hideMonthPicker = function(disableAnim){
23390 if(this.monthPicker){
23391 Roo.log("hideMonthPicker called");
23392 if(disableAnim === true){
23393 this.monthPicker.hide();
23395 this.monthPicker.slideOut('t', {duration:.2});
23396 p.setValue(new Date(m.picker.mpSelYear, m.picker.mpSelMonth, 1));
23397 p.fireEvent("select", this, this.value);
23403 Roo.log('picker set value');
23404 Roo.log(this.getValue());
23405 p.setValue(this.getValue() ? this.parseDate(this.getValue()) : new Date());
23406 m.show(this.el, 'tl-bl?');
23407 ignorehide = false;
23408 // this will trigger hideMonthPicker..
23411 // hidden the day picker
23412 Roo.select('.x-date-picker table', true).first().dom.style.visibility = "hidden";
23418 p.showMonthPicker.defer(100, p);
23424 beforeBlur : function(){
23425 var v = this.parseDate(this.getRawValue());
23431 /** @cfg {Boolean} grow @hide */
23432 /** @cfg {Number} growMin @hide */
23433 /** @cfg {Number} growMax @hide */
23440 * Ext JS Library 1.1.1
23441 * Copyright(c) 2006-2007, Ext JS, LLC.
23443 * Originally Released Under LGPL - original licence link has changed is not relivant.
23446 * <script type="text/javascript">
23451 * @class Roo.form.ComboBox
23452 * @extends Roo.form.TriggerField
23453 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
23455 * Create a new ComboBox.
23456 * @param {Object} config Configuration options
23458 Roo.form.ComboBox = function(config){
23459 Roo.form.ComboBox.superclass.constructor.call(this, config);
23463 * Fires when the dropdown list is expanded
23464 * @param {Roo.form.ComboBox} combo This combo box
23469 * Fires when the dropdown list is collapsed
23470 * @param {Roo.form.ComboBox} combo This combo box
23474 * @event beforeselect
23475 * Fires before a list item is selected. Return false to cancel the selection.
23476 * @param {Roo.form.ComboBox} combo This combo box
23477 * @param {Roo.data.Record} record The data record returned from the underlying store
23478 * @param {Number} index The index of the selected item in the dropdown list
23480 'beforeselect' : true,
23483 * Fires when a list item is selected
23484 * @param {Roo.form.ComboBox} combo This combo box
23485 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
23486 * @param {Number} index The index of the selected item in the dropdown list
23490 * @event beforequery
23491 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
23492 * The event object passed has these properties:
23493 * @param {Roo.form.ComboBox} combo This combo box
23494 * @param {String} query The query
23495 * @param {Boolean} forceAll true to force "all" query
23496 * @param {Boolean} cancel true to cancel the query
23497 * @param {Object} e The query event object
23499 'beforequery': true,
23502 * Fires when the 'add' icon is pressed (add a listener to enable add button)
23503 * @param {Roo.form.ComboBox} combo This combo box
23508 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
23509 * @param {Roo.form.ComboBox} combo This combo box
23510 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
23516 if(this.transform){
23517 this.allowDomMove = false;
23518 var s = Roo.getDom(this.transform);
23519 if(!this.hiddenName){
23520 this.hiddenName = s.name;
23523 this.mode = 'local';
23524 var d = [], opts = s.options;
23525 for(var i = 0, len = opts.length;i < len; i++){
23527 var value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
23529 this.value = value;
23531 d.push([value, o.text]);
23533 this.store = new Roo.data.SimpleStore({
23535 fields: ['value', 'text'],
23538 this.valueField = 'value';
23539 this.displayField = 'text';
23541 s.name = Roo.id(); // wipe out the name in case somewhere else they have a reference
23542 if(!this.lazyRender){
23543 this.target = true;
23544 this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
23545 s.parentNode.removeChild(s); // remove it
23546 this.render(this.el.parentNode);
23548 s.parentNode.removeChild(s); // remove it
23553 this.store = Roo.factory(this.store, Roo.data);
23556 this.selectedIndex = -1;
23557 if(this.mode == 'local'){
23558 if(config.queryDelay === undefined){
23559 this.queryDelay = 10;
23561 if(config.minChars === undefined){
23567 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
23569 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
23572 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
23573 * rendering into an Roo.Editor, defaults to false)
23576 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
23577 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
23580 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
23583 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
23584 * the dropdown list (defaults to undefined, with no header element)
23588 * @cfg {String/Roo.Template} tpl The template to use to render the output
23592 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
23594 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
23596 listWidth: undefined,
23598 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
23599 * mode = 'remote' or 'text' if mode = 'local')
23601 displayField: undefined,
23603 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
23604 * mode = 'remote' or 'value' if mode = 'local').
23605 * Note: use of a valueField requires the user make a selection
23606 * in order for a value to be mapped.
23608 valueField: undefined,
23612 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
23613 * field's data value (defaults to the underlying DOM element's name)
23615 hiddenName: undefined,
23617 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
23621 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
23623 selectedClass: 'x-combo-selected',
23625 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
23626 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
23627 * which displays a downward arrow icon).
23629 triggerClass : 'x-form-arrow-trigger',
23631 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
23635 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
23636 * anchor positions (defaults to 'tl-bl')
23638 listAlign: 'tl-bl?',
23640 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
23644 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
23645 * query specified by the allQuery config option (defaults to 'query')
23647 triggerAction: 'query',
23649 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
23650 * (defaults to 4, does not apply if editable = false)
23654 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
23655 * delay (typeAheadDelay) if it matches a known value (defaults to false)
23659 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
23660 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
23664 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
23665 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
23669 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
23670 * when editable = true (defaults to false)
23672 selectOnFocus:false,
23674 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
23676 queryParam: 'query',
23678 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
23679 * when mode = 'remote' (defaults to 'Loading...')
23681 loadingText: 'Loading...',
23683 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
23687 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
23691 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
23692 * traditional select (defaults to true)
23696 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
23700 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
23704 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
23705 * listWidth has a higher value)
23709 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
23710 * allow the user to set arbitrary text into the field (defaults to false)
23712 forceSelection:false,
23714 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
23715 * if typeAhead = true (defaults to 250)
23717 typeAheadDelay : 250,
23719 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
23720 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
23722 valueNotFoundText : undefined,
23724 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
23726 blockFocus : false,
23729 * @cfg {Boolean} disableClear Disable showing of clear button.
23731 disableClear : false,
23733 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
23735 alwaysQuery : false,
23741 // element that contains real text value.. (when hidden is used..)
23744 onRender : function(ct, position){
23745 Roo.form.ComboBox.superclass.onRender.call(this, ct, position);
23746 if(this.hiddenName){
23747 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
23749 this.hiddenField.value =
23750 this.hiddenValue !== undefined ? this.hiddenValue :
23751 this.value !== undefined ? this.value : '';
23753 // prevent input submission
23754 this.el.dom.removeAttribute('name');
23759 this.el.dom.setAttribute('autocomplete', 'off');
23762 var cls = 'x-combo-list';
23764 this.list = new Roo.Layer({
23765 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
23768 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
23769 this.list.setWidth(lw);
23770 this.list.swallowEvent('mousewheel');
23771 this.assetHeight = 0;
23774 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
23775 this.assetHeight += this.header.getHeight();
23778 this.innerList = this.list.createChild({cls:cls+'-inner'});
23779 this.innerList.on('mouseover', this.onViewOver, this);
23780 this.innerList.on('mousemove', this.onViewMove, this);
23781 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
23783 if(this.allowBlank && !this.pageSize && !this.disableClear){
23784 this.footer = this.list.createChild({cls:cls+'-ft'});
23785 this.pageTb = new Roo.Toolbar(this.footer);
23789 this.footer = this.list.createChild({cls:cls+'-ft'});
23790 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
23791 {pageSize: this.pageSize});
23795 if (this.pageTb && this.allowBlank && !this.disableClear) {
23797 this.pageTb.add(new Roo.Toolbar.Fill(), {
23798 cls: 'x-btn-icon x-btn-clear',
23800 handler: function()
23803 _this.clearValue();
23804 _this.onSelect(false, -1);
23809 this.assetHeight += this.footer.getHeight();
23814 this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
23817 this.view = new Roo.View(this.innerList, this.tpl, {
23818 singleSelect:true, store: this.store, selectedClass: this.selectedClass
23821 this.view.on('click', this.onViewClick, this);
23823 this.store.on('beforeload', this.onBeforeLoad, this);
23824 this.store.on('load', this.onLoad, this);
23825 this.store.on('loadexception', this.onLoadException, this);
23827 if(this.resizable){
23828 this.resizer = new Roo.Resizable(this.list, {
23829 pinned:true, handles:'se'
23831 this.resizer.on('resize', function(r, w, h){
23832 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
23833 this.listWidth = w;
23834 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
23835 this.restrictHeight();
23837 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
23839 if(!this.editable){
23840 this.editable = true;
23841 this.setEditable(false);
23845 if (typeof(this.events.add.listeners) != 'undefined') {
23847 this.addicon = this.wrap.createChild(
23848 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
23850 this.addicon.on('click', function(e) {
23851 this.fireEvent('add', this);
23854 if (typeof(this.events.edit.listeners) != 'undefined') {
23856 this.editicon = this.wrap.createChild(
23857 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
23858 if (this.addicon) {
23859 this.editicon.setStyle('margin-left', '40px');
23861 this.editicon.on('click', function(e) {
23863 // we fire even if inothing is selected..
23864 this.fireEvent('edit', this, this.lastData );
23874 initEvents : function(){
23875 Roo.form.ComboBox.superclass.initEvents.call(this);
23877 this.keyNav = new Roo.KeyNav(this.el, {
23878 "up" : function(e){
23879 this.inKeyMode = true;
23883 "down" : function(e){
23884 if(!this.isExpanded()){
23885 this.onTriggerClick();
23887 this.inKeyMode = true;
23892 "enter" : function(e){
23893 this.onViewClick();
23897 "esc" : function(e){
23901 "tab" : function(e){
23902 this.onViewClick(false);
23903 this.fireEvent("specialkey", this, e);
23909 doRelay : function(foo, bar, hname){
23910 if(hname == 'down' || this.scope.isExpanded()){
23911 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
23918 this.queryDelay = Math.max(this.queryDelay || 10,
23919 this.mode == 'local' ? 10 : 250);
23920 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
23921 if(this.typeAhead){
23922 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
23924 if(this.editable !== false){
23925 this.el.on("keyup", this.onKeyUp, this);
23927 if(this.forceSelection){
23928 this.on('blur', this.doForce, this);
23932 onDestroy : function(){
23934 this.view.setStore(null);
23935 this.view.el.removeAllListeners();
23936 this.view.el.remove();
23937 this.view.purgeListeners();
23940 this.list.destroy();
23943 this.store.un('beforeload', this.onBeforeLoad, this);
23944 this.store.un('load', this.onLoad, this);
23945 this.store.un('loadexception', this.onLoadException, this);
23947 Roo.form.ComboBox.superclass.onDestroy.call(this);
23951 fireKey : function(e){
23952 if(e.isNavKeyPress() && !this.list.isVisible()){
23953 this.fireEvent("specialkey", this, e);
23958 onResize: function(w, h){
23959 Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
23961 if(typeof w != 'number'){
23962 // we do not handle it!?!?
23965 var tw = this.trigger.getWidth();
23966 tw += this.addicon ? this.addicon.getWidth() : 0;
23967 tw += this.editicon ? this.editicon.getWidth() : 0;
23969 this.el.setWidth( this.adjustWidth('input', x));
23971 this.trigger.setStyle('left', x+'px');
23973 if(this.list && this.listWidth === undefined){
23974 var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
23975 this.list.setWidth(lw);
23976 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
23984 * Allow or prevent the user from directly editing the field text. If false is passed,
23985 * the user will only be able to select from the items defined in the dropdown list. This method
23986 * is the runtime equivalent of setting the 'editable' config option at config time.
23987 * @param {Boolean} value True to allow the user to directly edit the field text
23989 setEditable : function(value){
23990 if(value == this.editable){
23993 this.editable = value;
23995 this.el.dom.setAttribute('readOnly', true);
23996 this.el.on('mousedown', this.onTriggerClick, this);
23997 this.el.addClass('x-combo-noedit');
23999 this.el.dom.setAttribute('readOnly', false);
24000 this.el.un('mousedown', this.onTriggerClick, this);
24001 this.el.removeClass('x-combo-noedit');
24006 onBeforeLoad : function(){
24007 if(!this.hasFocus){
24010 this.innerList.update(this.loadingText ?
24011 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
24012 this.restrictHeight();
24013 this.selectedIndex = -1;
24017 onLoad : function(){
24018 if(!this.hasFocus){
24021 if(this.store.getCount() > 0){
24023 this.restrictHeight();
24024 if(this.lastQuery == this.allQuery){
24026 this.el.dom.select();
24028 if(!this.selectByValue(this.value, true)){
24029 this.select(0, true);
24033 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
24034 this.taTask.delay(this.typeAheadDelay);
24038 this.onEmptyResults();
24043 onLoadException : function()
24046 Roo.log(this.store.reader.jsonData);
24047 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
24048 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
24054 onTypeAhead : function(){
24055 if(this.store.getCount() > 0){
24056 var r = this.store.getAt(0);
24057 var newValue = r.data[this.displayField];
24058 var len = newValue.length;
24059 var selStart = this.getRawValue().length;
24060 if(selStart != len){
24061 this.setRawValue(newValue);
24062 this.selectText(selStart, newValue.length);
24068 onSelect : function(record, index){
24069 if(this.fireEvent('beforeselect', this, record, index) !== false){
24070 this.setFromData(index > -1 ? record.data : false);
24072 this.fireEvent('select', this, record, index);
24077 * Returns the currently selected field value or empty string if no value is set.
24078 * @return {String} value The selected value
24080 getValue : function(){
24081 if(this.valueField){
24082 return typeof this.value != 'undefined' ? this.value : '';
24084 return Roo.form.ComboBox.superclass.getValue.call(this);
24089 * Clears any text/value currently set in the field
24091 clearValue : function(){
24092 if(this.hiddenField){
24093 this.hiddenField.value = '';
24096 this.setRawValue('');
24097 this.lastSelectionText = '';
24102 * Sets the specified value into the field. If the value finds a match, the corresponding record text
24103 * will be displayed in the field. If the value does not match the data value of an existing item,
24104 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
24105 * Otherwise the field will be blank (although the value will still be set).
24106 * @param {String} value The value to match
24108 setValue : function(v){
24110 if(this.valueField){
24111 var r = this.findRecord(this.valueField, v);
24113 text = r.data[this.displayField];
24114 }else if(this.valueNotFoundText !== undefined){
24115 text = this.valueNotFoundText;
24118 this.lastSelectionText = text;
24119 if(this.hiddenField){
24120 this.hiddenField.value = v;
24122 Roo.form.ComboBox.superclass.setValue.call(this, text);
24126 * @property {Object} the last set data for the element
24131 * Sets the value of the field based on a object which is related to the record format for the store.
24132 * @param {Object} value the value to set as. or false on reset?
24134 setFromData : function(o){
24135 var dv = ''; // display value
24136 var vv = ''; // value value..
24138 if (this.displayField) {
24139 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
24141 // this is an error condition!!!
24142 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
24145 if(this.valueField){
24146 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
24148 if(this.hiddenField){
24149 this.hiddenField.value = vv;
24151 this.lastSelectionText = dv;
24152 Roo.form.ComboBox.superclass.setValue.call(this, dv);
24156 // no hidden field.. - we store the value in 'value', but still display
24157 // display field!!!!
24158 this.lastSelectionText = dv;
24159 Roo.form.ComboBox.superclass.setValue.call(this, dv);
24165 reset : function(){
24166 // overridden so that last data is reset..
24167 this.setValue(this.originalValue);
24168 this.clearInvalid();
24169 this.lastData = false;
24171 this.view.clearSelections();
24175 findRecord : function(prop, value){
24177 if(this.store.getCount() > 0){
24178 this.store.each(function(r){
24179 if(r.data[prop] == value){
24189 getName: function()
24191 // returns hidden if it's set..
24192 if (!this.rendered) {return ''};
24193 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
24197 onViewMove : function(e, t){
24198 this.inKeyMode = false;
24202 onViewOver : function(e, t){
24203 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
24206 var item = this.view.findItemFromChild(t);
24208 var index = this.view.indexOf(item);
24209 this.select(index, false);
24214 onViewClick : function(doFocus)
24216 var index = this.view.getSelectedIndexes()[0];
24217 var r = this.store.getAt(index);
24219 this.onSelect(r, index);
24221 if(doFocus !== false && !this.blockFocus){
24227 restrictHeight : function(){
24228 this.innerList.dom.style.height = '';
24229 var inner = this.innerList.dom;
24230 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
24231 this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
24232 this.list.beginUpdate();
24233 this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
24234 this.list.alignTo(this.el, this.listAlign);
24235 this.list.endUpdate();
24239 onEmptyResults : function(){
24244 * Returns true if the dropdown list is expanded, else false.
24246 isExpanded : function(){
24247 return this.list.isVisible();
24251 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
24252 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
24253 * @param {String} value The data value of the item to select
24254 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
24255 * selected item if it is not currently in view (defaults to true)
24256 * @return {Boolean} True if the value matched an item in the list, else false
24258 selectByValue : function(v, scrollIntoView){
24259 if(v !== undefined && v !== null){
24260 var r = this.findRecord(this.valueField || this.displayField, v);
24262 this.select(this.store.indexOf(r), scrollIntoView);
24270 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
24271 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
24272 * @param {Number} index The zero-based index of the list item to select
24273 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
24274 * selected item if it is not currently in view (defaults to true)
24276 select : function(index, scrollIntoView){
24277 this.selectedIndex = index;
24278 this.view.select(index);
24279 if(scrollIntoView !== false){
24280 var el = this.view.getNode(index);
24282 this.innerList.scrollChildIntoView(el, false);
24288 selectNext : function(){
24289 var ct = this.store.getCount();
24291 if(this.selectedIndex == -1){
24293 }else if(this.selectedIndex < ct-1){
24294 this.select(this.selectedIndex+1);
24300 selectPrev : function(){
24301 var ct = this.store.getCount();
24303 if(this.selectedIndex == -1){
24305 }else if(this.selectedIndex != 0){
24306 this.select(this.selectedIndex-1);
24312 onKeyUp : function(e){
24313 if(this.editable !== false && !e.isSpecialKey()){
24314 this.lastKey = e.getKey();
24315 this.dqTask.delay(this.queryDelay);
24320 validateBlur : function(){
24321 return !this.list || !this.list.isVisible();
24325 initQuery : function(){
24326 this.doQuery(this.getRawValue());
24330 doForce : function(){
24331 if(this.el.dom.value.length > 0){
24332 this.el.dom.value =
24333 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
24339 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
24340 * query allowing the query action to be canceled if needed.
24341 * @param {String} query The SQL query to execute
24342 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
24343 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
24344 * saved in the current store (defaults to false)
24346 doQuery : function(q, forceAll){
24347 if(q === undefined || q === null){
24352 forceAll: forceAll,
24356 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
24360 forceAll = qe.forceAll;
24361 if(forceAll === true || (q.length >= this.minChars)){
24362 if(this.lastQuery != q || this.alwaysQuery){
24363 this.lastQuery = q;
24364 if(this.mode == 'local'){
24365 this.selectedIndex = -1;
24367 this.store.clearFilter();
24369 this.store.filter(this.displayField, q);
24373 this.store.baseParams[this.queryParam] = q;
24375 params: this.getParams(q)
24380 this.selectedIndex = -1;
24387 getParams : function(q){
24389 //p[this.queryParam] = q;
24392 p.limit = this.pageSize;
24398 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
24400 collapse : function(){
24401 if(!this.isExpanded()){
24405 Roo.get(document).un('mousedown', this.collapseIf, this);
24406 Roo.get(document).un('mousewheel', this.collapseIf, this);
24407 if (!this.editable) {
24408 Roo.get(document).un('keydown', this.listKeyPress, this);
24410 this.fireEvent('collapse', this);
24414 collapseIf : function(e){
24415 if(!e.within(this.wrap) && !e.within(this.list)){
24421 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
24423 expand : function(){
24424 if(this.isExpanded() || !this.hasFocus){
24427 this.list.alignTo(this.el, this.listAlign);
24429 Roo.get(document).on('mousedown', this.collapseIf, this);
24430 Roo.get(document).on('mousewheel', this.collapseIf, this);
24431 if (!this.editable) {
24432 Roo.get(document).on('keydown', this.listKeyPress, this);
24435 this.fireEvent('expand', this);
24439 // Implements the default empty TriggerField.onTriggerClick function
24440 onTriggerClick : function(){
24444 if(this.isExpanded()){
24446 if (!this.blockFocus) {
24451 this.hasFocus = true;
24452 if(this.triggerAction == 'all') {
24453 this.doQuery(this.allQuery, true);
24455 this.doQuery(this.getRawValue());
24457 if (!this.blockFocus) {
24462 listKeyPress : function(e)
24464 //Roo.log('listkeypress');
24465 // scroll to first matching element based on key pres..
24466 if (e.isSpecialKey()) {
24469 var k = String.fromCharCode(e.getKey()).toUpperCase();
24472 var csel = this.view.getSelectedNodes();
24473 var cselitem = false;
24475 var ix = this.view.indexOf(csel[0]);
24476 cselitem = this.store.getAt(ix);
24477 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
24483 this.store.each(function(v) {
24485 // start at existing selection.
24486 if (cselitem.id == v.id) {
24492 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
24493 match = this.store.indexOf(v);
24498 if (match === false) {
24499 return true; // no more action?
24502 this.view.select(match);
24503 var sn = Roo.get(this.view.getSelectedNodes()[0])
24504 sn.scrollIntoView(sn.dom.parentNode, false);
24508 * @cfg {Boolean} grow
24512 * @cfg {Number} growMin
24516 * @cfg {Number} growMax
24524 * Copyright(c) 2010-2012, Roo J Solutions Limited
24531 * @class Roo.form.ComboBoxArray
24532 * @extends Roo.form.TextField
24533 * A facebook style adder... for lists of email / people / countries etc...
24534 * pick multiple items from a combo box, and shows each one.
24536 * Fred [x] Brian [x] [Pick another |v]
24539 * For this to work: it needs various extra information
24540 * - normal combo problay has
24542 * + displayField, valueField
24544 * For our purpose...
24547 * If we change from 'extends' to wrapping...
24554 * Create a new ComboBoxArray.
24555 * @param {Object} config Configuration options
24559 Roo.form.ComboBoxArray = function(config)
24562 Roo.form.ComboBoxArray.superclass.constructor.call(this, config);
24564 this.items = new Roo.util.MixedCollection(false);
24566 // construct the child combo...
24576 Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField,
24579 * @cfg {Roo.form.Combo} combo The combo box that is wrapped
24584 // behavies liek a hiddne field
24585 inputType: 'hidden',
24587 * @cfg {Number} width The width of the box that displays the selected element
24594 * @cfg {String} name The name of the visable items on this form (eg. titles not ids)
24598 * @cfg {String} hiddenName The hidden name of the field, often contains an comma seperated list of names
24600 hiddenName : false,
24603 // private the array of items that are displayed..
24605 // private - the hidden field el.
24607 // private - the filed el..
24610 //validateValue : function() { return true; }, // all values are ok!
24611 //onAddClick: function() { },
24613 onRender : function(ct, position)
24616 // create the standard hidden element
24617 //Roo.form.ComboBoxArray.superclass.onRender.call(this, ct, position);
24620 // give fake names to child combo;
24621 this.combo.hiddenName = this.hiddenName ? (this.hiddenName+'-subcombo') : this.hiddenName;
24622 this.combo.name = this.name? (this.name+'-subcombo') : this.name;
24624 this.combo = Roo.factory(this.combo, Roo.form);
24625 this.combo.onRender(ct, position);
24626 if (typeof(this.combo.width) != 'undefined') {
24627 this.combo.onResize(this.combo.width,0);
24630 this.combo.initEvents();
24632 // assigned so form know we need to do this..
24633 this.store = this.combo.store;
24634 this.valueField = this.combo.valueField;
24635 this.displayField = this.combo.displayField ;
24638 this.combo.wrap.addClass('x-cbarray-grp');
24640 var cbwrap = this.combo.wrap.createChild(
24641 {tag: 'div', cls: 'x-cbarray-cb'},
24646 this.hiddenEl = this.combo.wrap.createChild({
24647 tag: 'input', type:'hidden' , name: this.hiddenName, value : ''
24649 this.el = this.combo.wrap.createChild({
24650 tag: 'input', type:'hidden' , name: this.name, value : ''
24652 // this.el.dom.removeAttribute("name");
24655 this.outerWrap = this.combo.wrap;
24656 this.wrap = cbwrap;
24658 this.outerWrap.setWidth(this.width);
24659 this.outerWrap.dom.removeChild(this.el.dom);
24661 this.wrap.dom.appendChild(this.el.dom);
24662 this.outerWrap.dom.removeChild(this.combo.trigger.dom);
24663 this.combo.wrap.dom.appendChild(this.combo.trigger.dom);
24665 this.combo.trigger.setStyle('position','relative');
24666 this.combo.trigger.setStyle('left', '0px');
24667 this.combo.trigger.setStyle('top', '2px');
24669 this.combo.el.setStyle('vertical-align', 'text-bottom');
24671 //this.trigger.setStyle('vertical-align', 'top');
24673 // this should use the code from combo really... on('add' ....)
24677 this.adder = this.outerWrap.createChild(
24678 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-adder', style: 'margin-left:2px'});
24680 this.adder.on('click', function(e) {
24681 _t.fireEvent('adderclick', this, e);
24685 //this.adder.on('click', this.onAddClick, _t);
24688 this.combo.on('select', function(cb, rec, ix) {
24689 this.addItem(rec.data);
24692 cb.el.dom.value = '';
24693 //cb.lastData = rec.data;
24702 getName: function()
24704 // returns hidden if it's set..
24705 if (!this.rendered) {return ''};
24706 return this.hiddenName ? this.hiddenName : this.name;
24711 onResize: function(w, h){
24714 // not sure if this is needed..
24715 //this.combo.onResize(w,h);
24717 if(typeof w != 'number'){
24718 // we do not handle it!?!?
24721 var tw = this.combo.trigger.getWidth();
24722 tw += this.addicon ? this.addicon.getWidth() : 0;
24723 tw += this.editicon ? this.editicon.getWidth() : 0;
24725 this.combo.el.setWidth( this.combo.adjustWidth('input', x));
24727 this.combo.trigger.setStyle('left', '0px');
24729 if(this.list && this.listWidth === undefined){
24730 var lw = Math.max(x + this.combo.trigger.getWidth(), this.combo.minListWidth);
24731 this.list.setWidth(lw);
24732 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
24739 addItem: function(rec)
24741 var valueField = this.combo.valueField;
24742 var displayField = this.combo.displayField;
24743 if (this.items.indexOfKey(rec[valueField]) > -1) {
24744 //console.log("GOT " + rec.data.id);
24748 var x = new Roo.form.ComboBoxArray.Item({
24749 //id : rec[this.idField],
24751 displayField : displayField ,
24752 tipField : displayField ,
24756 this.items.add(rec[valueField],x);
24757 // add it before the element..
24758 this.updateHiddenEl();
24759 x.render(this.outerWrap, this.wrap.dom);
24760 // add the image handler..
24763 updateHiddenEl : function()
24766 if (!this.hiddenEl) {
24770 var idField = this.combo.valueField;
24772 this.items.each(function(f) {
24773 ar.push(f.data[idField]);
24776 this.hiddenEl.dom.value = ar.join(',');
24782 //Roo.form.ComboBoxArray.superclass.reset.call(this);
24783 this.items.each(function(f) {
24786 this.el.dom.value = '';
24787 if (this.hiddenEl) {
24788 this.hiddenEl.dom.value = '';
24792 getValue: function()
24794 return this.hiddenEl ? this.hiddenEl.dom.value : '';
24796 setValue: function(v) // not a valid action - must use addItems..
24803 if (this.store.isLocal && (typeof(v) == 'string')) {
24804 // then we can use the store to find the values..
24805 // comma seperated at present.. this needs to allow JSON based encoding..
24806 this.hiddenEl.value = v;
24808 Roo.each(v.split(','), function(k) {
24809 Roo.log("CHECK " + this.valueField + ',' + k);
24810 var li = this.store.query(this.valueField, k);
24815 add[this.valueField] = k;
24816 add[this.displayField] = li.item(0).data[this.displayField];
24822 if (typeof(v) == 'object') {
24823 // then let's assume it's an array of objects..
24824 Roo.each(v, function(l) {
24832 setFromData: function(v)
24834 // this recieves an object, if setValues is called.
24836 this.el.dom.value = v[this.displayField];
24837 this.hiddenEl.dom.value = v[this.valueField];
24838 if (typeof(v[this.valueField]) != 'string' || !v[this.valueField].length) {
24841 var kv = v[this.valueField];
24842 var dv = v[this.displayField];
24843 kv = typeof(kv) != 'string' ? '' : kv;
24844 dv = typeof(dv) != 'string' ? '' : dv;
24847 var keys = kv.split(',');
24848 var display = dv.split(',');
24849 for (var i = 0 ; i < keys.length; i++) {
24852 add[this.valueField] = keys[i];
24853 add[this.displayField] = display[i];
24861 validateValue : function(value){
24862 return Roo.form.ComboBoxArray.superclass.validateValue.call(this, this.getValue());
24871 * @class Roo.form.ComboBoxArray.Item
24872 * @extends Roo.BoxComponent
24873 * A selected item in the list
24874 * Fred [x] Brian [x] [Pick another |v]
24877 * Create a new item.
24878 * @param {Object} config Configuration options
24881 Roo.form.ComboBoxArray.Item = function(config) {
24882 config.id = Roo.id();
24883 Roo.form.ComboBoxArray.Item.superclass.constructor.call(this, config);
24886 Roo.extend(Roo.form.ComboBoxArray.Item, Roo.BoxComponent, {
24889 displayField : false,
24893 defaultAutoCreate : {
24895 cls: 'x-cbarray-item',
24902 src : Roo.BLANK_IMAGE_URL ,
24910 onRender : function(ct, position)
24912 Roo.form.Field.superclass.onRender.call(this, ct, position);
24915 var cfg = this.getAutoCreate();
24916 this.el = ct.createChild(cfg, position);
24919 this.el.child('img').dom.setAttribute('src', Roo.BLANK_IMAGE_URL);
24921 this.el.child('div').dom.innerHTML = this.cb.renderer ?
24922 this.cb.renderer(this.data) :
24923 String.format('{0}',this.data[this.displayField]);
24926 this.el.child('div').dom.setAttribute('qtip',
24927 String.format('{0}',this.data[this.tipField])
24930 this.el.child('img').on('click', this.remove, this);
24934 remove : function()
24937 this.cb.items.remove(this);
24938 this.el.child('img').un('click', this.remove, this);
24940 this.cb.updateHiddenEl();
24946 * Ext JS Library 1.1.1
24947 * Copyright(c) 2006-2007, Ext JS, LLC.
24949 * Originally Released Under LGPL - original licence link has changed is not relivant.
24952 * <script type="text/javascript">
24955 * @class Roo.form.Checkbox
24956 * @extends Roo.form.Field
24957 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
24959 * Creates a new Checkbox
24960 * @param {Object} config Configuration options
24962 Roo.form.Checkbox = function(config){
24963 Roo.form.Checkbox.superclass.constructor.call(this, config);
24967 * Fires when the checkbox is checked or unchecked.
24968 * @param {Roo.form.Checkbox} this This checkbox
24969 * @param {Boolean} checked The new checked value
24975 Roo.extend(Roo.form.Checkbox, Roo.form.Field, {
24977 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
24979 focusClass : undefined,
24981 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
24983 fieldClass: "x-form-field",
24985 * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
24989 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
24990 * {tag: "input", type: "checkbox", autocomplete: "off"})
24992 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
24994 * @cfg {String} boxLabel The text that appears beside the checkbox
24998 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
25002 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
25004 valueOff: '0', // value when not checked..
25006 actionMode : 'viewEl',
25009 itemCls : 'x-menu-check-item x-form-item',
25010 groupClass : 'x-menu-group-item',
25011 inputType : 'hidden',
25014 inSetChecked: false, // check that we are not calling self...
25016 inputElement: false, // real input element?
25017 basedOn: false, // ????
25019 isFormField: true, // not sure where this is needed!!!!
25021 onResize : function(){
25022 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
25023 if(!this.boxLabel){
25024 this.el.alignTo(this.wrap, 'c-c');
25028 initEvents : function(){
25029 Roo.form.Checkbox.superclass.initEvents.call(this);
25030 this.el.on("click", this.onClick, this);
25031 this.el.on("change", this.onClick, this);
25035 getResizeEl : function(){
25039 getPositionEl : function(){
25044 onRender : function(ct, position){
25045 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
25047 if(this.inputValue !== undefined){
25048 this.el.dom.value = this.inputValue;
25051 //this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
25052 this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
25053 var viewEl = this.wrap.createChild({
25054 tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
25055 this.viewEl = viewEl;
25056 this.wrap.on('click', this.onClick, this);
25058 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
25059 this.el.on('propertychange', this.setFromHidden, this); //ie
25064 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
25065 // viewEl.on('click', this.onClick, this);
25067 //if(this.checked){
25068 this.setChecked(this.checked);
25070 //this.checked = this.el.dom;
25076 initValue : Roo.emptyFn,
25079 * Returns the checked state of the checkbox.
25080 * @return {Boolean} True if checked, else false
25082 getValue : function(){
25084 return String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
25086 return this.valueOff;
25091 onClick : function(){
25092 this.setChecked(!this.checked);
25094 //if(this.el.dom.checked != this.checked){
25095 // this.setValue(this.el.dom.checked);
25100 * Sets the checked state of the checkbox.
25101 * On is always based on a string comparison between inputValue and the param.
25102 * @param {Boolean/String} value - the value to set
25103 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
25105 setValue : function(v,suppressEvent){
25108 //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
25109 //if(this.el && this.el.dom){
25110 // this.el.dom.checked = this.checked;
25111 // this.el.dom.defaultChecked = this.checked;
25113 this.setChecked(String(v) === String(this.inputValue), suppressEvent);
25114 //this.fireEvent("check", this, this.checked);
25117 setChecked : function(state,suppressEvent)
25119 if (this.inSetChecked) {
25120 this.checked = state;
25126 this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked');
25128 this.checked = state;
25129 if(suppressEvent !== true){
25130 this.fireEvent('check', this, state);
25132 this.inSetChecked = true;
25133 this.el.dom.value = state ? this.inputValue : this.valueOff;
25134 this.inSetChecked = false;
25137 // handle setting of hidden value by some other method!!?!?
25138 setFromHidden: function()
25143 //console.log("SET FROM HIDDEN");
25144 //alert('setFrom hidden');
25145 this.setValue(this.el.dom.value);
25148 onDestroy : function()
25151 Roo.get(this.viewEl).remove();
25154 Roo.form.Checkbox.superclass.onDestroy.call(this);
25159 * Ext JS Library 1.1.1
25160 * Copyright(c) 2006-2007, Ext JS, LLC.
25162 * Originally Released Under LGPL - original licence link has changed is not relivant.
25165 * <script type="text/javascript">
25169 * @class Roo.form.Radio
25170 * @extends Roo.form.Checkbox
25171 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
25172 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
25174 * Creates a new Radio
25175 * @param {Object} config Configuration options
25177 Roo.form.Radio = function(){
25178 Roo.form.Radio.superclass.constructor.apply(this, arguments);
25180 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
25181 inputType: 'radio',
25184 * If this radio is part of a group, it will return the selected value
25187 getGroupValue : function(){
25188 return this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
25192 onRender : function(ct, position){
25193 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
25195 if(this.inputValue !== undefined){
25196 this.el.dom.value = this.inputValue;
25199 this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
25200 //this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
25201 //var viewEl = this.wrap.createChild({
25202 // tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
25203 //this.viewEl = viewEl;
25204 //this.wrap.on('click', this.onClick, this);
25206 //this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
25207 //this.el.on('propertychange', this.setFromHidden, this); //ie
25212 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
25213 // viewEl.on('click', this.onClick, this);
25216 this.el.dom.checked = 'checked' ;
25222 });//<script type="text/javascript">
25225 * Ext JS Library 1.1.1
25226 * Copyright(c) 2006-2007, Ext JS, LLC.
25227 * licensing@extjs.com
25229 * http://www.extjs.com/license
25235 * Default CSS appears to render it as fixed text by default (should really be Sans-Serif)
25236 * - IE ? - no idea how much works there.
25244 * @class Ext.form.HtmlEditor
25245 * @extends Ext.form.Field
25246 * Provides a lightweight HTML Editor component.
25248 * This has been tested on Fireforx / Chrome.. IE may not be so great..
25250 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
25251 * supported by this editor.</b><br/><br/>
25252 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
25253 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
25255 Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
25257 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
25261 * @cfg {String} createLinkText The default text for the create link prompt
25263 createLinkText : 'Please enter the URL for the link:',
25265 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
25267 defaultLinkValue : 'http:/'+'/',
25270 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
25275 * @cfg {Number} height (in pixels)
25279 * @cfg {Number} width (in pixels)
25284 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
25287 stylesheets: false,
25292 // private properties
25293 validationEvent : false,
25295 initialized : false,
25297 sourceEditMode : false,
25298 onFocus : Roo.emptyFn,
25300 hideMode:'offsets',
25302 defaultAutoCreate : { // modified by initCompnoent..
25304 style:"width:500px;height:300px;",
25305 autocomplete: "off"
25309 initComponent : function(){
25312 * @event initialize
25313 * Fires when the editor is fully initialized (including the iframe)
25314 * @param {HtmlEditor} this
25319 * Fires when the editor is first receives the focus. Any insertion must wait
25320 * until after this event.
25321 * @param {HtmlEditor} this
25325 * @event beforesync
25326 * Fires before the textarea is updated with content from the editor iframe. Return false
25327 * to cancel the sync.
25328 * @param {HtmlEditor} this
25329 * @param {String} html
25333 * @event beforepush
25334 * Fires before the iframe editor is updated with content from the textarea. Return false
25335 * to cancel the push.
25336 * @param {HtmlEditor} this
25337 * @param {String} html
25342 * Fires when the textarea is updated with content from the editor iframe.
25343 * @param {HtmlEditor} this
25344 * @param {String} html
25349 * Fires when the iframe editor is updated with content from the textarea.
25350 * @param {HtmlEditor} this
25351 * @param {String} html
25355 * @event editmodechange
25356 * Fires when the editor switches edit modes
25357 * @param {HtmlEditor} this
25358 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
25360 editmodechange: true,
25362 * @event editorevent
25363 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
25364 * @param {HtmlEditor} this
25368 this.defaultAutoCreate = {
25370 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
25371 autocomplete: "off"
25376 * Protected method that will not generally be called directly. It
25377 * is called when the editor creates its toolbar. Override this method if you need to
25378 * add custom toolbar buttons.
25379 * @param {HtmlEditor} editor
25381 createToolbar : function(editor){
25382 if (!editor.toolbars || !editor.toolbars.length) {
25383 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
25386 for (var i =0 ; i < editor.toolbars.length;i++) {
25387 editor.toolbars[i] = Roo.factory(
25388 typeof(editor.toolbars[i]) == 'string' ?
25389 { xtype: editor.toolbars[i]} : editor.toolbars[i],
25390 Roo.form.HtmlEditor);
25391 editor.toolbars[i].init(editor);
25398 * Protected method that will not generally be called directly. It
25399 * is called when the editor initializes the iframe with HTML contents. Override this method if you
25400 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
25402 getDocMarkup : function(){
25405 if (this.stylesheets === false) {
25407 Roo.get(document.head).select('style').each(function(node) {
25408 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
25411 Roo.get(document.head).select('link').each(function(node) {
25412 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
25415 } else if (!this.stylesheets.length) {
25417 st = '<style type="text/css">' +
25418 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
25421 Roo.each(this.stylesheets, function(s) {
25422 st += '<link rel="stylesheet" type="text/css" href="' + s +'" />'
25427 st += '<style type="text/css">' +
25428 'IMG { cursor: pointer } ' +
25432 return '<html><head>' + st +
25433 //<style type="text/css">' +
25434 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
25436 ' </head><body class="roo-htmleditor-body"></body></html>';
25440 onRender : function(ct, position)
25443 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
25444 this.el.dom.style.border = '0 none';
25445 this.el.dom.setAttribute('tabIndex', -1);
25446 this.el.addClass('x-hidden');
25447 if(Roo.isIE){ // fix IE 1px bogus margin
25448 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
25450 this.wrap = this.el.wrap({
25451 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
25454 if (this.resizable) {
25455 this.resizeEl = new Roo.Resizable(this.wrap, {
25459 minHeight : this.height,
25460 height: this.height,
25461 handles : this.resizable,
25464 resize : function(r, w, h) {
25465 _t.onResize(w,h); // -something
25472 this.frameId = Roo.id();
25474 this.createToolbar(this);
25478 var iframe = this.wrap.createChild({
25481 name: this.frameId,
25482 frameBorder : 'no',
25483 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
25487 // console.log(iframe);
25488 //this.wrap.dom.appendChild(iframe);
25490 this.iframe = iframe.dom;
25492 this.assignDocWin();
25494 this.doc.designMode = 'on';
25497 this.doc.write(this.getDocMarkup());
25501 var task = { // must defer to wait for browser to be ready
25503 //console.log("run task?" + this.doc.readyState);
25504 this.assignDocWin();
25505 if(this.doc.body || this.doc.readyState == 'complete'){
25507 this.doc.designMode="on";
25511 Roo.TaskMgr.stop(task);
25512 this.initEditor.defer(10, this);
25519 Roo.TaskMgr.start(task);
25522 this.setSize(this.wrap.getSize());
25524 if (this.resizeEl) {
25525 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
25526 // should trigger onReize..
25531 onResize : function(w, h)
25533 //Roo.log('resize: ' +w + ',' + h );
25534 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
25535 if(this.el && this.iframe){
25536 if(typeof w == 'number'){
25537 var aw = w - this.wrap.getFrameWidth('lr');
25538 this.el.setWidth(this.adjustWidth('textarea', aw));
25539 this.iframe.style.width = aw + 'px';
25541 if(typeof h == 'number'){
25543 for (var i =0; i < this.toolbars.length;i++) {
25544 // fixme - ask toolbars for heights?
25545 tbh += this.toolbars[i].tb.el.getHeight();
25546 if (this.toolbars[i].footer) {
25547 tbh += this.toolbars[i].footer.el.getHeight();
25554 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
25555 ah -= 5; // knock a few pixes off for look..
25556 this.el.setHeight(this.adjustWidth('textarea', ah));
25557 this.iframe.style.height = ah + 'px';
25559 (this.doc.body || this.doc.documentElement).style.height = (ah - (this.iframePad*2)) + 'px';
25566 * Toggles the editor between standard and source edit mode.
25567 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
25569 toggleSourceEdit : function(sourceEditMode){
25571 this.sourceEditMode = sourceEditMode === true;
25573 if(this.sourceEditMode){
25575 // Roo.log(this.syncValue());
25577 this.iframe.className = 'x-hidden';
25578 this.el.removeClass('x-hidden');
25579 this.el.dom.removeAttribute('tabIndex');
25583 // Roo.log(this.pushValue());
25585 this.iframe.className = '';
25586 this.el.addClass('x-hidden');
25587 this.el.dom.setAttribute('tabIndex', -1);
25590 this.setSize(this.wrap.getSize());
25591 this.fireEvent('editmodechange', this, this.sourceEditMode);
25594 // private used internally
25595 createLink : function(){
25596 var url = prompt(this.createLinkText, this.defaultLinkValue);
25597 if(url && url != 'http:/'+'/'){
25598 this.relayCmd('createlink', url);
25602 // private (for BoxComponent)
25603 adjustSize : Roo.BoxComponent.prototype.adjustSize,
25605 // private (for BoxComponent)
25606 getResizeEl : function(){
25610 // private (for BoxComponent)
25611 getPositionEl : function(){
25616 initEvents : function(){
25617 this.originalValue = this.getValue();
25621 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
25624 markInvalid : Roo.emptyFn,
25626 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
25629 clearInvalid : Roo.emptyFn,
25631 setValue : function(v){
25632 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
25637 * Protected method that will not generally be called directly. If you need/want
25638 * custom HTML cleanup, this is the method you should override.
25639 * @param {String} html The HTML to be cleaned
25640 * return {String} The cleaned HTML
25642 cleanHtml : function(html){
25643 html = String(html);
25644 if(html.length > 5){
25645 if(Roo.isSafari){ // strip safari nonsense
25646 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
25649 if(html == ' '){
25656 * Protected method that will not generally be called directly. Syncs the contents
25657 * of the editor iframe with the textarea.
25659 syncValue : function(){
25660 if(this.initialized){
25661 var bd = (this.doc.body || this.doc.documentElement);
25662 //this.cleanUpPaste(); -- this is done else where and causes havoc..
25663 var html = bd.innerHTML;
25665 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
25666 var m = bs.match(/text-align:(.*?);/i);
25668 html = '<div style="'+m[0]+'">' + html + '</div>';
25671 html = this.cleanHtml(html);
25672 // fix up the special chars.. normaly like back quotes in word...
25673 // however we do not want to do this with chinese..
25674 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
25675 var cc = b.charCodeAt();
25677 (cc >= 0x4E00 && cc < 0xA000 ) ||
25678 (cc >= 0x3400 && cc < 0x4E00 ) ||
25679 (cc >= 0xf900 && cc < 0xfb00 )
25685 if(this.fireEvent('beforesync', this, html) !== false){
25686 this.el.dom.value = html;
25687 this.fireEvent('sync', this, html);
25693 * Protected method that will not generally be called directly. Pushes the value of the textarea
25694 * into the iframe editor.
25696 pushValue : function(){
25697 if(this.initialized){
25698 var v = this.el.dom.value;
25704 if(this.fireEvent('beforepush', this, v) !== false){
25705 var d = (this.doc.body || this.doc.documentElement);
25707 this.cleanUpPaste();
25708 this.el.dom.value = d.innerHTML;
25709 this.fireEvent('push', this, v);
25715 deferFocus : function(){
25716 this.focus.defer(10, this);
25720 focus : function(){
25721 if(this.win && !this.sourceEditMode){
25728 assignDocWin: function()
25730 var iframe = this.iframe;
25733 this.doc = iframe.contentWindow.document;
25734 this.win = iframe.contentWindow;
25736 if (!Roo.get(this.frameId)) {
25739 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
25740 this.win = Roo.get(this.frameId).dom.contentWindow;
25745 initEditor : function(){
25746 //console.log("INIT EDITOR");
25747 this.assignDocWin();
25751 this.doc.designMode="on";
25753 this.doc.write(this.getDocMarkup());
25756 var dbody = (this.doc.body || this.doc.documentElement);
25757 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
25758 // this copies styles from the containing element into thsi one..
25759 // not sure why we need all of this..
25760 var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
25761 ss['background-attachment'] = 'fixed'; // w3c
25762 dbody.bgProperties = 'fixed'; // ie
25763 Roo.DomHelper.applyStyles(dbody, ss);
25764 Roo.EventManager.on(this.doc, {
25765 //'mousedown': this.onEditorEvent,
25766 'mouseup': this.onEditorEvent,
25767 'dblclick': this.onEditorEvent,
25768 'click': this.onEditorEvent,
25769 'keyup': this.onEditorEvent,
25774 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
25776 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
25777 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
25779 this.initialized = true;
25781 this.fireEvent('initialize', this);
25786 onDestroy : function(){
25792 for (var i =0; i < this.toolbars.length;i++) {
25793 // fixme - ask toolbars for heights?
25794 this.toolbars[i].onDestroy();
25797 this.wrap.dom.innerHTML = '';
25798 this.wrap.remove();
25803 onFirstFocus : function(){
25805 this.assignDocWin();
25808 this.activated = true;
25809 for (var i =0; i < this.toolbars.length;i++) {
25810 this.toolbars[i].onFirstFocus();
25813 if(Roo.isGecko){ // prevent silly gecko errors
25815 var s = this.win.getSelection();
25816 if(!s.focusNode || s.focusNode.nodeType != 3){
25817 var r = s.getRangeAt(0);
25818 r.selectNodeContents((this.doc.body || this.doc.documentElement));
25823 this.execCmd('useCSS', true);
25824 this.execCmd('styleWithCSS', false);
25827 this.fireEvent('activate', this);
25831 adjustFont: function(btn){
25832 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
25833 //if(Roo.isSafari){ // safari
25836 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
25837 if(Roo.isSafari){ // safari
25838 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
25839 v = (v < 10) ? 10 : v;
25840 v = (v > 48) ? 48 : v;
25841 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
25846 v = Math.max(1, v+adjust);
25848 this.execCmd('FontSize', v );
25851 onEditorEvent : function(e){
25852 this.fireEvent('editorevent', this, e);
25853 // this.updateToolbar();
25854 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
25857 insertTag : function(tg)
25859 // could be a bit smarter... -> wrap the current selected tRoo..
25860 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
25862 range = this.createRange(this.getSelection());
25863 var wrappingNode = this.doc.createElement(tg.toLowerCase());
25864 wrappingNode.appendChild(range.extractContents());
25865 range.insertNode(wrappingNode);
25872 this.execCmd("formatblock", tg);
25876 insertText : function(txt)
25880 var range = this.createRange();
25881 range.deleteContents();
25882 //alert(Sender.getAttribute('label'));
25884 range.insertNode(this.doc.createTextNode(txt));
25888 relayBtnCmd : function(btn){
25889 this.relayCmd(btn.cmd);
25893 * Executes a Midas editor command on the editor document and performs necessary focus and
25894 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
25895 * @param {String} cmd The Midas command
25896 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
25898 relayCmd : function(cmd, value){
25900 this.execCmd(cmd, value);
25901 this.fireEvent('editorevent', this);
25902 //this.updateToolbar();
25907 * Executes a Midas editor command directly on the editor document.
25908 * For visual commands, you should use {@link #relayCmd} instead.
25909 * <b>This should only be called after the editor is initialized.</b>
25910 * @param {String} cmd The Midas command
25911 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
25913 execCmd : function(cmd, value){
25914 this.doc.execCommand(cmd, false, value === undefined ? null : value);
25921 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
25923 * @param {String} text | dom node..
25925 insertAtCursor : function(text)
25930 if(!this.activated){
25936 var r = this.doc.selection.createRange();
25947 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
25951 // from jquery ui (MIT licenced)
25953 var win = this.win;
25955 if (win.getSelection && win.getSelection().getRangeAt) {
25956 range = win.getSelection().getRangeAt(0);
25957 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
25958 range.insertNode(node);
25959 } else if (win.document.selection && win.document.selection.createRange) {
25960 // no firefox support
25961 var txt = typeof(text) == 'string' ? text : text.outerHTML;
25962 win.document.selection.createRange().pasteHTML(txt);
25964 // no firefox support
25965 var txt = typeof(text) == 'string' ? text : text.outerHTML;
25966 this.execCmd('InsertHTML', txt);
25975 mozKeyPress : function(e){
25977 var c = e.getCharCode(), cmd;
25980 c = String.fromCharCode(c).toLowerCase();
25994 this.cleanUpPaste.defer(100, this);
26002 e.preventDefault();
26010 fixKeys : function(){ // load time branching for fastest keydown performance
26012 return function(e){
26013 var k = e.getKey(), r;
26016 r = this.doc.selection.createRange();
26019 r.pasteHTML('    ');
26026 r = this.doc.selection.createRange();
26028 var target = r.parentElement();
26029 if(!target || target.tagName.toLowerCase() != 'li'){
26031 r.pasteHTML('<br />');
26037 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
26038 this.cleanUpPaste.defer(100, this);
26044 }else if(Roo.isOpera){
26045 return function(e){
26046 var k = e.getKey();
26050 this.execCmd('InsertHTML','    ');
26053 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
26054 this.cleanUpPaste.defer(100, this);
26059 }else if(Roo.isSafari){
26060 return function(e){
26061 var k = e.getKey();
26065 this.execCmd('InsertText','\t');
26069 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
26070 this.cleanUpPaste.defer(100, this);
26078 getAllAncestors: function()
26080 var p = this.getSelectedNode();
26083 a.push(p); // push blank onto stack..
26084 p = this.getParentElement();
26088 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
26092 a.push(this.doc.body);
26096 lastSelNode : false,
26099 getSelection : function()
26101 this.assignDocWin();
26102 return Roo.isIE ? this.doc.selection : this.win.getSelection();
26105 getSelectedNode: function()
26107 // this may only work on Gecko!!!
26109 // should we cache this!!!!
26114 var range = this.createRange(this.getSelection()).cloneRange();
26117 var parent = range.parentElement();
26119 var testRange = range.duplicate();
26120 testRange.moveToElementText(parent);
26121 if (testRange.inRange(range)) {
26124 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
26127 parent = parent.parentElement;
26132 // is ancestor a text element.
26133 var ac = range.commonAncestorContainer;
26134 if (ac.nodeType == 3) {
26135 ac = ac.parentNode;
26138 var ar = ac.childNodes;
26141 var other_nodes = [];
26142 var has_other_nodes = false;
26143 for (var i=0;i<ar.length;i++) {
26144 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
26147 // fullly contained node.
26149 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
26154 // probably selected..
26155 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
26156 other_nodes.push(ar[i]);
26160 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
26165 has_other_nodes = true;
26167 if (!nodes.length && other_nodes.length) {
26168 nodes= other_nodes;
26170 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
26176 createRange: function(sel)
26178 // this has strange effects when using with
26179 // top toolbar - not sure if it's a great idea.
26180 //this.editor.contentWindow.focus();
26181 if (typeof sel != "undefined") {
26183 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
26185 return this.doc.createRange();
26188 return this.doc.createRange();
26191 getParentElement: function()
26194 this.assignDocWin();
26195 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
26197 var range = this.createRange(sel);
26200 var p = range.commonAncestorContainer;
26201 while (p.nodeType == 3) { // text node
26212 * Range intersection.. the hard stuff...
26216 * [ -- selected range --- ]
26220 * if end is before start or hits it. fail.
26221 * if start is after end or hits it fail.
26223 * if either hits (but other is outside. - then it's not
26229 // @see http://www.thismuchiknow.co.uk/?p=64.
26230 rangeIntersectsNode : function(range, node)
26232 var nodeRange = node.ownerDocument.createRange();
26234 nodeRange.selectNode(node);
26236 nodeRange.selectNodeContents(node);
26239 var rangeStartRange = range.cloneRange();
26240 rangeStartRange.collapse(true);
26242 var rangeEndRange = range.cloneRange();
26243 rangeEndRange.collapse(false);
26245 var nodeStartRange = nodeRange.cloneRange();
26246 nodeStartRange.collapse(true);
26248 var nodeEndRange = nodeRange.cloneRange();
26249 nodeEndRange.collapse(false);
26251 return rangeStartRange.compareBoundaryPoints(
26252 Range.START_TO_START, nodeEndRange) == -1 &&
26253 rangeEndRange.compareBoundaryPoints(
26254 Range.START_TO_START, nodeStartRange) == 1;
26258 rangeCompareNode : function(range, node)
26260 var nodeRange = node.ownerDocument.createRange();
26262 nodeRange.selectNode(node);
26264 nodeRange.selectNodeContents(node);
26268 range.collapse(true);
26270 nodeRange.collapse(true);
26272 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
26273 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
26275 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
26277 var nodeIsBefore = ss == 1;
26278 var nodeIsAfter = ee == -1;
26280 if (nodeIsBefore && nodeIsAfter)
26282 if (!nodeIsBefore && nodeIsAfter)
26283 return 1; //right trailed.
26285 if (nodeIsBefore && !nodeIsAfter)
26286 return 2; // left trailed.
26291 // private? - in a new class?
26292 cleanUpPaste : function()
26294 // cleans up the whole document..
26295 Roo.log('cleanuppaste');
26296 this.cleanUpChildren(this.doc.body);
26297 var clean = this.cleanWordChars(this.doc.body.innerHTML);
26298 if (clean != this.doc.body.innerHTML) {
26299 this.doc.body.innerHTML = clean;
26304 cleanWordChars : function(input) {// change the chars to hex code
26305 var he = Roo.form.HtmlEditor;
26307 var output = input;
26308 Roo.each(he.swapCodes, function(sw) {
26309 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
26311 output = output.replace(swapper, sw[1]);
26318 cleanUpChildren : function (n)
26320 if (!n.childNodes.length) {
26323 for (var i = n.childNodes.length-1; i > -1 ; i--) {
26324 this.cleanUpChild(n.childNodes[i]);
26331 cleanUpChild : function (node)
26334 //console.log(node);
26335 if (node.nodeName == "#text") {
26336 // clean up silly Windows -- stuff?
26339 if (node.nodeName == "#comment") {
26340 node.parentNode.removeChild(node);
26341 // clean up silly Windows -- stuff?
26345 if (Roo.form.HtmlEditor.black.indexOf(node.tagName.toLowerCase()) > -1) {
26347 node.parentNode.removeChild(node);
26352 var remove_keep_children= Roo.form.HtmlEditor.remove.indexOf(node.tagName.toLowerCase()) > -1;
26354 // remove <a name=....> as rendering on yahoo mailer is borked with this.
26355 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
26357 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
26358 // remove_keep_children = true;
26361 if (remove_keep_children) {
26362 this.cleanUpChildren(node);
26363 // inserts everything just before this node...
26364 while (node.childNodes.length) {
26365 var cn = node.childNodes[0];
26366 node.removeChild(cn);
26367 node.parentNode.insertBefore(cn, node);
26369 node.parentNode.removeChild(node);
26373 if (!node.attributes || !node.attributes.length) {
26374 this.cleanUpChildren(node);
26378 function cleanAttr(n,v)
26381 if (v.match(/^\./) || v.match(/^\//)) {
26384 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
26387 if (v.match(/^#/)) {
26390 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
26391 node.removeAttribute(n);
26395 function cleanStyle(n,v)
26397 if (v.match(/expression/)) { //XSS?? should we even bother..
26398 node.removeAttribute(n);
26401 var cwhite = typeof(ed.cwhite) == 'undefined' ? Roo.form.HtmlEditor.cwhite : ed.cwhite;
26402 var cblack = typeof(ed.cblack) == 'undefined' ? Roo.form.HtmlEditor.cblack : ed.cblack;
26405 var parts = v.split(/;/);
26408 Roo.each(parts, function(p) {
26409 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
26413 var l = p.split(':').shift().replace(/\s+/g,'');
26414 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
26417 if ( cblack.indexOf(l) > -1) {
26418 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
26419 //node.removeAttribute(n);
26423 // only allow 'c whitelisted system attributes'
26424 if ( cwhite.length && cwhite.indexOf(l) < 0) {
26425 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
26426 //node.removeAttribute(n);
26436 if (clean.length) {
26437 node.setAttribute(n, clean.join(';'));
26439 node.removeAttribute(n);
26445 for (var i = node.attributes.length-1; i > -1 ; i--) {
26446 var a = node.attributes[i];
26449 if (a.name.toLowerCase().substr(0,2)=='on') {
26450 node.removeAttribute(a.name);
26453 if (Roo.form.HtmlEditor.ablack.indexOf(a.name.toLowerCase()) > -1) {
26454 node.removeAttribute(a.name);
26457 if (Roo.form.HtmlEditor.aclean.indexOf(a.name.toLowerCase()) > -1) {
26458 cleanAttr(a.name,a.value); // fixme..
26461 if (a.name == 'style') {
26462 cleanStyle(a.name,a.value);
26465 /// clean up MS crap..
26466 // tecnically this should be a list of valid class'es..
26469 if (a.name == 'class') {
26470 if (a.value.match(/^Mso/)) {
26471 node.className = '';
26474 if (a.value.match(/body/)) {
26475 node.className = '';
26486 this.cleanUpChildren(node);
26492 // hide stuff that is not compatible
26506 * @event specialkey
26510 * @cfg {String} fieldClass @hide
26513 * @cfg {String} focusClass @hide
26516 * @cfg {String} autoCreate @hide
26519 * @cfg {String} inputType @hide
26522 * @cfg {String} invalidClass @hide
26525 * @cfg {String} invalidText @hide
26528 * @cfg {String} msgFx @hide
26531 * @cfg {String} validateOnBlur @hide
26535 Roo.form.HtmlEditor.white = [
26536 'area', 'br', 'img', 'input', 'hr', 'wbr',
26538 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
26539 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
26540 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
26541 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
26542 'table', 'ul', 'xmp',
26544 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
26547 'dir', 'menu', 'ol', 'ul', 'dl',
26553 Roo.form.HtmlEditor.black = [
26554 // 'embed', 'object', // enable - backend responsiblity to clean thiese
26556 'base', 'basefont', 'bgsound', 'blink', 'body',
26557 'frame', 'frameset', 'head', 'html', 'ilayer',
26558 'iframe', 'layer', 'link', 'meta', 'object',
26559 'script', 'style' ,'title', 'xml' // clean later..
26561 Roo.form.HtmlEditor.clean = [
26562 'script', 'style', 'title', 'xml'
26564 Roo.form.HtmlEditor.remove = [
26569 Roo.form.HtmlEditor.ablack = [
26573 Roo.form.HtmlEditor.aclean = [
26574 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
26578 Roo.form.HtmlEditor.pwhite= [
26579 'http', 'https', 'mailto'
26582 // white listed style attributes.
26583 Roo.form.HtmlEditor.cwhite= [
26584 // 'text-align', /// default is to allow most things..
26590 // black listed style attributes.
26591 Roo.form.HtmlEditor.cblack= [
26592 // 'font-size' -- this can be set by the project
26596 Roo.form.HtmlEditor.swapCodes =[
26607 // <script type="text/javascript">
26610 * Ext JS Library 1.1.1
26611 * Copyright(c) 2006-2007, Ext JS, LLC.
26617 * @class Roo.form.HtmlEditorToolbar1
26622 new Roo.form.HtmlEditor({
26625 new Roo.form.HtmlEditorToolbar1({
26626 disable : { fonts: 1 , format: 1, ..., ... , ...],
26632 * @cfg {Object} disable List of elements to disable..
26633 * @cfg {Array} btns List of additional buttons.
26637 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
26640 Roo.form.HtmlEditor.ToolbarStandard = function(config)
26643 Roo.apply(this, config);
26645 // default disabled, based on 'good practice'..
26646 this.disable = this.disable || {};
26647 Roo.applyIf(this.disable, {
26650 specialElements : true
26654 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
26655 // dont call parent... till later.
26658 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
26666 * @cfg {Object} disable List of toolbar elements to disable
26671 * @cfg {Array} fontFamilies An array of available font families
26689 // "á" , ?? a acute?
26694 "°" // , // degrees
26696 // "é" , // e ecute
26697 // "ú" , // u ecute?
26700 specialElements : [
26702 text: "Insert Table",
26705 ihtml : '<table><tr><td>Cell</td></tr></table>'
26709 text: "Insert Image",
26712 ihtml : '<img src="about:blank"/>'
26721 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
26722 "input:submit", "input:button", "select", "textarea", "label" ],
26725 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
26727 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"],
26731 * @cfg {String} defaultFont default font to use.
26733 defaultFont: 'tahoma',
26735 fontSelect : false,
26738 formatCombo : false,
26740 init : function(editor)
26742 this.editor = editor;
26745 var fid = editor.frameId;
26747 function btn(id, toggle, handler){
26748 var xid = fid + '-'+ id ;
26752 cls : 'x-btn-icon x-edit-'+id,
26753 enableToggle:toggle !== false,
26754 scope: editor, // was editor...
26755 handler:handler||editor.relayBtnCmd,
26756 clickEvent:'mousedown',
26757 tooltip: etb.buttonTips[id] || undefined, ///tips ???
26764 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
26766 // stop form submits
26767 tb.el.on('click', function(e){
26768 e.preventDefault(); // what does this do?
26771 if(!this.disable.font) { // && !Roo.isSafari){
26772 /* why no safari for fonts
26773 editor.fontSelect = tb.el.createChild({
26776 cls:'x-font-select',
26777 html: this.createFontOptions()
26780 editor.fontSelect.on('change', function(){
26781 var font = editor.fontSelect.dom.value;
26782 editor.relayCmd('fontname', font);
26783 editor.deferFocus();
26787 editor.fontSelect.dom,
26793 if(!this.disable.formats){
26794 this.formatCombo = new Roo.form.ComboBox({
26795 store: new Roo.data.SimpleStore({
26798 data : this.formats // from states.js
26802 //autoCreate : {tag: "div", size: "20"},
26803 displayField:'tag',
26807 triggerAction: 'all',
26808 emptyText:'Add tag',
26809 selectOnFocus:true,
26812 'select': function(c, r, i) {
26813 editor.insertTag(r.get('tag'));
26819 tb.addField(this.formatCombo);
26823 if(!this.disable.format){
26830 if(!this.disable.fontSize){
26835 btn('increasefontsize', false, editor.adjustFont),
26836 btn('decreasefontsize', false, editor.adjustFont)
26841 if(!this.disable.colors){
26844 id:editor.frameId +'-forecolor',
26845 cls:'x-btn-icon x-edit-forecolor',
26846 clickEvent:'mousedown',
26847 tooltip: this.buttonTips['forecolor'] || undefined,
26849 menu : new Roo.menu.ColorMenu({
26850 allowReselect: true,
26851 focus: Roo.emptyFn,
26854 selectHandler: function(cp, color){
26855 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
26856 editor.deferFocus();
26859 clickEvent:'mousedown'
26862 id:editor.frameId +'backcolor',
26863 cls:'x-btn-icon x-edit-backcolor',
26864 clickEvent:'mousedown',
26865 tooltip: this.buttonTips['backcolor'] || undefined,
26867 menu : new Roo.menu.ColorMenu({
26868 focus: Roo.emptyFn,
26871 allowReselect: true,
26872 selectHandler: function(cp, color){
26874 editor.execCmd('useCSS', false);
26875 editor.execCmd('hilitecolor', color);
26876 editor.execCmd('useCSS', true);
26877 editor.deferFocus();
26879 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
26880 Roo.isSafari || Roo.isIE ? '#'+color : color);
26881 editor.deferFocus();
26885 clickEvent:'mousedown'
26890 // now add all the items...
26893 if(!this.disable.alignments){
26896 btn('justifyleft'),
26897 btn('justifycenter'),
26898 btn('justifyright')
26902 //if(!Roo.isSafari){
26903 if(!this.disable.links){
26906 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
26910 if(!this.disable.lists){
26913 btn('insertorderedlist'),
26914 btn('insertunorderedlist')
26917 if(!this.disable.sourceEdit){
26920 btn('sourceedit', true, function(btn){
26921 this.toggleSourceEdit(btn.pressed);
26928 // special menu.. - needs to be tidied up..
26929 if (!this.disable.special) {
26932 cls: 'x-edit-none',
26938 for (var i =0; i < this.specialChars.length; i++) {
26939 smenu.menu.items.push({
26941 html: this.specialChars[i],
26942 handler: function(a,b) {
26943 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
26944 //editor.insertAtCursor(a.html);
26957 if (!this.disable.specialElements) {
26960 cls: 'x-edit-none',
26965 for (var i =0; i < this.specialElements.length; i++) {
26966 semenu.menu.items.push(
26968 handler: function(a,b) {
26969 editor.insertAtCursor(this.ihtml);
26971 }, this.specialElements[i])
26983 for(var i =0; i< this.btns.length;i++) {
26984 var b = Roo.factory(this.btns[i],Roo.form);
26985 b.cls = 'x-edit-none';
26994 // disable everything...
26996 this.tb.items.each(function(item){
26997 if(item.id != editor.frameId+ '-sourceedit'){
27001 this.rendered = true;
27003 // the all the btns;
27004 editor.on('editorevent', this.updateToolbar, this);
27005 // other toolbars need to implement this..
27006 //editor.on('editmodechange', this.updateToolbar, this);
27012 * Protected method that will not generally be called directly. It triggers
27013 * a toolbar update by reading the markup state of the current selection in the editor.
27015 updateToolbar: function(){
27017 if(!this.editor.activated){
27018 this.editor.onFirstFocus();
27022 var btns = this.tb.items.map,
27023 doc = this.editor.doc,
27024 frameId = this.editor.frameId;
27026 if(!this.disable.font && !Roo.isSafari){
27028 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
27029 if(name != this.fontSelect.dom.value){
27030 this.fontSelect.dom.value = name;
27034 if(!this.disable.format){
27035 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
27036 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
27037 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
27039 if(!this.disable.alignments){
27040 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
27041 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
27042 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
27044 if(!Roo.isSafari && !this.disable.lists){
27045 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
27046 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
27049 var ans = this.editor.getAllAncestors();
27050 if (this.formatCombo) {
27053 var store = this.formatCombo.store;
27054 this.formatCombo.setValue("");
27055 for (var i =0; i < ans.length;i++) {
27056 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
27058 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
27066 // hides menus... - so this cant be on a menu...
27067 Roo.menu.MenuMgr.hideAll();
27069 //this.editorsyncValue();
27073 createFontOptions : function(){
27074 var buf = [], fs = this.fontFamilies, ff, lc;
27078 for(var i = 0, len = fs.length; i< len; i++){
27080 lc = ff.toLowerCase();
27082 '<option value="',lc,'" style="font-family:',ff,';"',
27083 (this.defaultFont == lc ? ' selected="true">' : '>'),
27088 return buf.join('');
27091 toggleSourceEdit : function(sourceEditMode){
27092 if(sourceEditMode === undefined){
27093 sourceEditMode = !this.sourceEditMode;
27095 this.sourceEditMode = sourceEditMode === true;
27096 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
27097 // just toggle the button?
27098 if(btn.pressed !== this.editor.sourceEditMode){
27099 btn.toggle(this.editor.sourceEditMode);
27103 if(this.sourceEditMode){
27104 this.tb.items.each(function(item){
27105 if(item.cmd != 'sourceedit'){
27111 if(this.initialized){
27112 this.tb.items.each(function(item){
27118 // tell the editor that it's been pressed..
27119 this.editor.toggleSourceEdit(sourceEditMode);
27123 * Object collection of toolbar tooltips for the buttons in the editor. The key
27124 * is the command id associated with that button and the value is a valid QuickTips object.
27129 title: 'Bold (Ctrl+B)',
27130 text: 'Make the selected text bold.',
27131 cls: 'x-html-editor-tip'
27134 title: 'Italic (Ctrl+I)',
27135 text: 'Make the selected text italic.',
27136 cls: 'x-html-editor-tip'
27144 title: 'Bold (Ctrl+B)',
27145 text: 'Make the selected text bold.',
27146 cls: 'x-html-editor-tip'
27149 title: 'Italic (Ctrl+I)',
27150 text: 'Make the selected text italic.',
27151 cls: 'x-html-editor-tip'
27154 title: 'Underline (Ctrl+U)',
27155 text: 'Underline the selected text.',
27156 cls: 'x-html-editor-tip'
27158 increasefontsize : {
27159 title: 'Grow Text',
27160 text: 'Increase the font size.',
27161 cls: 'x-html-editor-tip'
27163 decreasefontsize : {
27164 title: 'Shrink Text',
27165 text: 'Decrease the font size.',
27166 cls: 'x-html-editor-tip'
27169 title: 'Text Highlight Color',
27170 text: 'Change the background color of the selected text.',
27171 cls: 'x-html-editor-tip'
27174 title: 'Font Color',
27175 text: 'Change the color of the selected text.',
27176 cls: 'x-html-editor-tip'
27179 title: 'Align Text Left',
27180 text: 'Align text to the left.',
27181 cls: 'x-html-editor-tip'
27184 title: 'Center Text',
27185 text: 'Center text in the editor.',
27186 cls: 'x-html-editor-tip'
27189 title: 'Align Text Right',
27190 text: 'Align text to the right.',
27191 cls: 'x-html-editor-tip'
27193 insertunorderedlist : {
27194 title: 'Bullet List',
27195 text: 'Start a bulleted list.',
27196 cls: 'x-html-editor-tip'
27198 insertorderedlist : {
27199 title: 'Numbered List',
27200 text: 'Start a numbered list.',
27201 cls: 'x-html-editor-tip'
27204 title: 'Hyperlink',
27205 text: 'Make the selected text a hyperlink.',
27206 cls: 'x-html-editor-tip'
27209 title: 'Source Edit',
27210 text: 'Switch to source editing mode.',
27211 cls: 'x-html-editor-tip'
27215 onDestroy : function(){
27218 this.tb.items.each(function(item){
27220 item.menu.removeAll();
27222 item.menu.el.destroy();
27230 onFirstFocus: function() {
27231 this.tb.items.each(function(item){
27240 // <script type="text/javascript">
27243 * Ext JS Library 1.1.1
27244 * Copyright(c) 2006-2007, Ext JS, LLC.
27251 * @class Roo.form.HtmlEditor.ToolbarContext
27256 new Roo.form.HtmlEditor({
27259 { xtype: 'ToolbarStandard', styles : {} }
27260 { xtype: 'ToolbarContext', disable : {} }
27266 * @config : {Object} disable List of elements to disable.. (not done yet.)
27267 * @config : {Object} styles Map of styles available.
27271 Roo.form.HtmlEditor.ToolbarContext = function(config)
27274 Roo.apply(this, config);
27275 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
27276 // dont call parent... till later.
27277 this.styles = this.styles || {};
27282 Roo.form.HtmlEditor.ToolbarContext.types = {
27294 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
27356 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
27361 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
27371 style : 'fontFamily',
27372 displayField: 'display',
27373 optname : 'font-family',
27422 // should we really allow this??
27423 // should this just be
27434 style : 'fontFamily',
27435 displayField: 'display',
27436 optname : 'font-family',
27443 style : 'fontFamily',
27444 displayField: 'display',
27445 optname : 'font-family',
27452 style : 'fontFamily',
27453 displayField: 'display',
27454 optname : 'font-family',
27465 // this should be configurable.. - you can either set it up using stores, or modify options somehwere..
27466 Roo.form.HtmlEditor.ToolbarContext.stores = false;
27468 Roo.form.HtmlEditor.ToolbarContext.options = {
27470 [ 'Helvetica,Arial,sans-serif', 'Helvetica'],
27471 [ 'Courier New', 'Courier New'],
27472 [ 'Tahoma', 'Tahoma'],
27473 [ 'Times New Roman,serif', 'Times'],
27474 [ 'Verdana','Verdana' ]
27478 // fixme - these need to be configurable..
27481 Roo.form.HtmlEditor.ToolbarContext.types
27484 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
27492 * @cfg {Object} disable List of toolbar elements to disable
27497 * @cfg {Object} styles List of styles
27498 * eg. { '*' : [ 'headline' ] , 'TD' : [ 'underline', 'double-underline' ] }
27500 * These must be defined in the page, so they get rendered correctly..
27511 init : function(editor)
27513 this.editor = editor;
27516 var fid = editor.frameId;
27518 function btn(id, toggle, handler){
27519 var xid = fid + '-'+ id ;
27523 cls : 'x-btn-icon x-edit-'+id,
27524 enableToggle:toggle !== false,
27525 scope: editor, // was editor...
27526 handler:handler||editor.relayBtnCmd,
27527 clickEvent:'mousedown',
27528 tooltip: etb.buttonTips[id] || undefined, ///tips ???
27532 // create a new element.
27533 var wdiv = editor.wrap.createChild({
27535 }, editor.wrap.dom.firstChild.nextSibling, true);
27537 // can we do this more than once??
27539 // stop form submits
27542 // disable everything...
27543 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
27544 this.toolbars = {};
27546 for (var i in ty) {
27548 this.toolbars[i] = this.buildToolbar(ty[i],i);
27550 this.tb = this.toolbars.BODY;
27552 this.buildFooter();
27553 this.footer.show();
27554 editor.on('hide', function( ) { this.footer.hide() }, this);
27555 editor.on('show', function( ) { this.footer.show() }, this);
27558 this.rendered = true;
27560 // the all the btns;
27561 editor.on('editorevent', this.updateToolbar, this);
27562 // other toolbars need to implement this..
27563 //editor.on('editmodechange', this.updateToolbar, this);
27569 * Protected method that will not generally be called directly. It triggers
27570 * a toolbar update by reading the markup state of the current selection in the editor.
27572 updateToolbar: function(editor,ev,sel){
27575 // capture mouse up - this is handy for selecting images..
27576 // perhaps should go somewhere else...
27577 if(!this.editor.activated){
27578 this.editor.onFirstFocus();
27582 // http://developer.yahoo.com/yui/docs/simple-editor.js.html
27583 // selectNode - might want to handle IE?
27585 (ev.type == 'mouseup' || ev.type == 'click' ) &&
27586 ev.target && ev.target.tagName == 'IMG') {
27587 // they have click on an image...
27588 // let's see if we can change the selection...
27591 var nodeRange = sel.ownerDocument.createRange();
27593 nodeRange.selectNode(sel);
27595 nodeRange.selectNodeContents(sel);
27597 //nodeRange.collapse(true);
27598 var s = editor.win.getSelection();
27599 s.removeAllRanges();
27600 s.addRange(nodeRange);
27604 var updateFooter = sel ? false : true;
27607 var ans = this.editor.getAllAncestors();
27610 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
27613 sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editor.doc.body;
27614 sel = sel ? sel : this.editor.doc.body;
27615 sel = sel.tagName.length ? sel : this.editor.doc.body;
27618 // pick a menu that exists..
27619 var tn = sel.tagName.toUpperCase();
27620 //sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
27622 tn = sel.tagName.toUpperCase();
27624 var lastSel = this.tb.selectedNode
27626 this.tb.selectedNode = sel;
27628 // if current menu does not match..
27629 if ((this.tb.name != tn) || (lastSel != this.tb.selectedNode)) {
27632 ///console.log("show: " + tn);
27633 this.tb = typeof(ty[tn]) != 'undefined' ? this.toolbars[tn] : this.toolbars['*'];
27636 this.tb.items.first().el.innerHTML = tn + ': ';
27639 // update attributes
27640 if (this.tb.fields) {
27641 this.tb.fields.each(function(e) {
27643 e.setValue(sel.style[e.stylename]);
27646 e.setValue(sel.getAttribute(e.attrname));
27650 var hasStyles = false;
27651 for(var i in this.styles) {
27658 var st = this.tb.fields.item(0);
27660 st.store.removeAll();
27663 var cn = sel.className.split(/\s+/);
27666 if (this.styles['*']) {
27668 Roo.each(this.styles['*'], function(v) {
27669 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
27672 if (this.styles[tn]) {
27673 Roo.each(this.styles[tn], function(v) {
27674 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
27678 st.store.loadData(avs);
27682 // flag our selected Node.
27683 this.tb.selectedNode = sel;
27686 Roo.menu.MenuMgr.hideAll();
27690 if (!updateFooter) {
27691 //this.footDisp.dom.innerHTML = '';
27694 // update the footer
27698 this.footerEls = ans.reverse();
27699 Roo.each(this.footerEls, function(a,i) {
27700 if (!a) { return; }
27701 html += html.length ? ' > ' : '';
27703 html += '<span class="x-ed-loc-' + i + '">' + a.tagName + '</span>';
27708 var sz = this.footDisp.up('td').getSize();
27709 this.footDisp.dom.style.width = (sz.width -10) + 'px';
27710 this.footDisp.dom.style.marginLeft = '5px';
27712 this.footDisp.dom.style.overflow = 'hidden';
27714 this.footDisp.dom.innerHTML = html;
27716 //this.editorsyncValue();
27723 onDestroy : function(){
27726 this.tb.items.each(function(item){
27728 item.menu.removeAll();
27730 item.menu.el.destroy();
27738 onFirstFocus: function() {
27739 // need to do this for all the toolbars..
27740 this.tb.items.each(function(item){
27744 buildToolbar: function(tlist, nm)
27746 var editor = this.editor;
27747 // create a new element.
27748 var wdiv = editor.wrap.createChild({
27750 }, editor.wrap.dom.firstChild.nextSibling, true);
27753 var tb = new Roo.Toolbar(wdiv);
27756 tb.add(nm+ ": ");
27759 for(var i in this.styles) {
27764 if (styles && styles.length) {
27766 // this needs a multi-select checkbox...
27767 tb.addField( new Roo.form.ComboBox({
27768 store: new Roo.data.SimpleStore({
27770 fields: ['val', 'selected'],
27773 name : '-roo-edit-className',
27774 attrname : 'className',
27775 displayField: 'val',
27779 triggerAction: 'all',
27780 emptyText:'Select Style',
27781 selectOnFocus:true,
27784 'select': function(c, r, i) {
27785 // initial support only for on class per el..
27786 tb.selectedNode.className = r ? r.get('val') : '';
27787 editor.syncValue();
27794 var tbc = Roo.form.HtmlEditor.ToolbarContext;
27795 var tbops = tbc.options;
27797 for (var i in tlist) {
27799 var item = tlist[i];
27800 tb.add(item.title + ": ");
27803 //optname == used so you can configure the options available..
27804 var opts = item.opts ? item.opts : false;
27805 if (item.optname) {
27806 opts = tbops[item.optname];
27811 // opts == pulldown..
27812 tb.addField( new Roo.form.ComboBox({
27813 store: typeof(tbc.stores[i]) != 'undefined' ? Roo.factory(tbc.stores[i],Roo.data) : new Roo.data.SimpleStore({
27815 fields: ['val', 'display'],
27818 name : '-roo-edit-' + i,
27820 stylename : item.style ? item.style : false,
27821 displayField: item.displayField ? item.displayField : 'val',
27822 valueField : 'val',
27824 mode: typeof(tbc.stores[i]) != 'undefined' ? 'remote' : 'local',
27826 triggerAction: 'all',
27827 emptyText:'Select',
27828 selectOnFocus:true,
27829 width: item.width ? item.width : 130,
27831 'select': function(c, r, i) {
27833 tb.selectedNode.style[c.stylename] = r.get('val');
27836 tb.selectedNode.setAttribute(c.attrname, r.get('val'));
27845 tb.addField( new Roo.form.TextField({
27848 //allowBlank:false,
27853 tb.addField( new Roo.form.TextField({
27854 name: '-roo-edit-' + i,
27861 'change' : function(f, nv, ov) {
27862 tb.selectedNode.setAttribute(f.attrname, nv);
27871 text: 'Remove Tag',
27874 click : function ()
27877 // undo does not work.
27879 var sn = tb.selectedNode;
27881 var pn = sn.parentNode;
27883 var stn = sn.childNodes[0];
27884 var en = sn.childNodes[sn.childNodes.length - 1 ];
27885 while (sn.childNodes.length) {
27886 var node = sn.childNodes[0];
27887 sn.removeChild(node);
27889 pn.insertBefore(node, sn);
27892 pn.removeChild(sn);
27893 var range = editor.createRange();
27895 range.setStart(stn,0);
27896 range.setEnd(en,0); //????
27897 //range.selectNode(sel);
27900 var selection = editor.getSelection();
27901 selection.removeAllRanges();
27902 selection.addRange(range);
27906 //_this.updateToolbar(null, null, pn);
27907 _this.updateToolbar(null, null, null);
27908 _this.footDisp.dom.innerHTML = '';
27918 tb.el.on('click', function(e){
27919 e.preventDefault(); // what does this do?
27921 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
27924 // dont need to disable them... as they will get hidden
27929 buildFooter : function()
27932 var fel = this.editor.wrap.createChild();
27933 this.footer = new Roo.Toolbar(fel);
27934 // toolbar has scrolly on left / right?
27935 var footDisp= new Roo.Toolbar.Fill();
27941 handler : function() {
27942 _t.footDisp.scrollTo('left',0,true)
27946 this.footer.add( footDisp );
27951 handler : function() {
27953 _t.footDisp.select('span').last().scrollIntoView(_t.footDisp,true);
27957 var fel = Roo.get(footDisp.el);
27958 fel.addClass('x-editor-context');
27959 this.footDispWrap = fel;
27960 this.footDispWrap.overflow = 'hidden';
27962 this.footDisp = fel.createChild();
27963 this.footDispWrap.on('click', this.onContextClick, this)
27967 onContextClick : function (ev,dom)
27969 ev.preventDefault();
27970 var cn = dom.className;
27972 if (!cn.match(/x-ed-loc-/)) {
27975 var n = cn.split('-').pop();
27976 var ans = this.footerEls;
27980 var range = this.editor.createRange();
27982 range.selectNodeContents(sel);
27983 //range.selectNode(sel);
27986 var selection = this.editor.getSelection();
27987 selection.removeAllRanges();
27988 selection.addRange(range);
27992 this.updateToolbar(null, null, sel);
28009 * Ext JS Library 1.1.1
28010 * Copyright(c) 2006-2007, Ext JS, LLC.
28012 * Originally Released Under LGPL - original licence link has changed is not relivant.
28015 * <script type="text/javascript">
28019 * @class Roo.form.BasicForm
28020 * @extends Roo.util.Observable
28021 * Supplies the functionality to do "actions" on forms and initialize Roo.form.Field types on existing markup.
28023 * @param {String/HTMLElement/Roo.Element} el The form element or its id
28024 * @param {Object} config Configuration options
28026 Roo.form.BasicForm = function(el, config){
28027 this.allItems = [];
28028 this.childForms = [];
28029 Roo.apply(this, config);
28031 * The Roo.form.Field items in this form.
28032 * @type MixedCollection
28036 this.items = new Roo.util.MixedCollection(false, function(o){
28037 return o.id || (o.id = Roo.id());
28041 * @event beforeaction
28042 * Fires before any action is performed. Return false to cancel the action.
28043 * @param {Form} this
28044 * @param {Action} action The action to be performed
28046 beforeaction: true,
28048 * @event actionfailed
28049 * Fires when an action fails.
28050 * @param {Form} this
28051 * @param {Action} action The action that failed
28053 actionfailed : true,
28055 * @event actioncomplete
28056 * Fires when an action is completed.
28057 * @param {Form} this
28058 * @param {Action} action The action that completed
28060 actioncomplete : true
28065 Roo.form.BasicForm.superclass.constructor.call(this);
28068 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
28070 * @cfg {String} method
28071 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
28074 * @cfg {DataReader} reader
28075 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when executing "load" actions.
28076 * This is optional as there is built-in support for processing JSON.
28079 * @cfg {DataReader} errorReader
28080 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
28081 * This is completely optional as there is built-in support for processing JSON.
28084 * @cfg {String} url
28085 * The URL to use for form actions if one isn't supplied in the action options.
28088 * @cfg {Boolean} fileUpload
28089 * Set to true if this form is a file upload.
28093 * @cfg {Object} baseParams
28094 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
28099 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
28104 activeAction : null,
28107 * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded
28108 * or setValues() data instead of when the form was first created.
28110 trackResetOnLoad : false,
28114 * childForms - used for multi-tab forms
28117 childForms : false,
28120 * allItems - full list of fields.
28126 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
28127 * element by passing it or its id or mask the form itself by passing in true.
28130 waitMsgTarget : false,
28133 initEl : function(el){
28134 this.el = Roo.get(el);
28135 this.id = this.el.id || Roo.id();
28136 this.el.on('submit', this.onSubmit, this);
28137 this.el.addClass('x-form');
28141 onSubmit : function(e){
28146 * Returns true if client-side validation on the form is successful.
28149 isValid : function(){
28151 this.items.each(function(f){
28160 * Returns true if any fields in this form have changed since their original load.
28163 isDirty : function(){
28165 this.items.each(function(f){
28175 * Performs a predefined action (submit or load) or custom actions you define on this form.
28176 * @param {String} actionName The name of the action type
28177 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
28178 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
28179 * accept other config options):
28181 Property Type Description
28182 ---------------- --------------- ----------------------------------------------------------------------------------
28183 url String The url for the action (defaults to the form's url)
28184 method String The form method to use (defaults to the form's method, or POST if not defined)
28185 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
28186 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
28187 validate the form on the client (defaults to false)
28189 * @return {BasicForm} this
28191 doAction : function(action, options){
28192 if(typeof action == 'string'){
28193 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
28195 if(this.fireEvent('beforeaction', this, action) !== false){
28196 this.beforeAction(action);
28197 action.run.defer(100, action);
28203 * Shortcut to do a submit action.
28204 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
28205 * @return {BasicForm} this
28207 submit : function(options){
28208 this.doAction('submit', options);
28213 * Shortcut to do a load action.
28214 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
28215 * @return {BasicForm} this
28217 load : function(options){
28218 this.doAction('load', options);
28223 * Persists the values in this form into the passed Roo.data.Record object in a beginEdit/endEdit block.
28224 * @param {Record} record The record to edit
28225 * @return {BasicForm} this
28227 updateRecord : function(record){
28228 record.beginEdit();
28229 var fs = record.fields;
28230 fs.each(function(f){
28231 var field = this.findField(f.name);
28233 record.set(f.name, field.getValue());
28241 * Loads an Roo.data.Record into this form.
28242 * @param {Record} record The record to load
28243 * @return {BasicForm} this
28245 loadRecord : function(record){
28246 this.setValues(record.data);
28251 beforeAction : function(action){
28252 var o = action.options;
28255 if(this.waitMsgTarget === true){
28256 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
28257 }else if(this.waitMsgTarget){
28258 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
28259 this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
28261 Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
28267 afterAction : function(action, success){
28268 this.activeAction = null;
28269 var o = action.options;
28271 if(this.waitMsgTarget === true){
28273 }else if(this.waitMsgTarget){
28274 this.waitMsgTarget.unmask();
28276 Roo.MessageBox.updateProgress(1);
28277 Roo.MessageBox.hide();
28284 Roo.callback(o.success, o.scope, [this, action]);
28285 this.fireEvent('actioncomplete', this, action);
28289 // failure condition..
28290 // we have a scenario where updates need confirming.
28291 // eg. if a locking scenario exists..
28292 // we look for { errors : { needs_confirm : true }} in the response.
28294 (typeof(action.result) != 'undefined') &&
28295 (typeof(action.result.errors) != 'undefined') &&
28296 (typeof(action.result.errors.needs_confirm) != 'undefined')
28299 Roo.MessageBox.confirm(
28300 "Change requires confirmation",
28301 action.result.errorMsg,
28306 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
28316 Roo.callback(o.failure, o.scope, [this, action]);
28317 // show an error message if no failed handler is set..
28318 if (!this.hasListener('actionfailed')) {
28319 Roo.MessageBox.alert("Error",
28320 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
28321 action.result.errorMsg :
28322 "Saving Failed, please check your entries or try again"
28326 this.fireEvent('actionfailed', this, action);
28332 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
28333 * @param {String} id The value to search for
28336 findField : function(id){
28337 var field = this.items.get(id);
28339 this.items.each(function(f){
28340 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
28346 return field || null;
28350 * Add a secondary form to this one,
28351 * Used to provide tabbed forms. One form is primary, with hidden values
28352 * which mirror the elements from the other forms.
28354 * @param {Roo.form.Form} form to add.
28357 addForm : function(form)
28360 if (this.childForms.indexOf(form) > -1) {
28364 this.childForms.push(form);
28366 Roo.each(form.allItems, function (fe) {
28368 n = typeof(fe.getName) == 'undefined' ? fe.name : fe.getName();
28369 if (this.findField(n)) { // already added..
28372 var add = new Roo.form.Hidden({
28375 add.render(this.el);
28382 * Mark fields in this form invalid in bulk.
28383 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
28384 * @return {BasicForm} this
28386 markInvalid : function(errors){
28387 if(errors instanceof Array){
28388 for(var i = 0, len = errors.length; i < len; i++){
28389 var fieldError = errors[i];
28390 var f = this.findField(fieldError.id);
28392 f.markInvalid(fieldError.msg);
28398 if(typeof errors[id] != 'function' && (field = this.findField(id))){
28399 field.markInvalid(errors[id]);
28403 Roo.each(this.childForms || [], function (f) {
28404 f.markInvalid(errors);
28411 * Set values for fields in this form in bulk.
28412 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
28413 * @return {BasicForm} this
28415 setValues : function(values){
28416 if(values instanceof Array){ // array of objects
28417 for(var i = 0, len = values.length; i < len; i++){
28419 var f = this.findField(v.id);
28421 f.setValue(v.value);
28422 if(this.trackResetOnLoad){
28423 f.originalValue = f.getValue();
28427 }else{ // object hash
28430 if(typeof values[id] != 'function' && (field = this.findField(id))){
28432 if (field.setFromData &&
28433 field.valueField &&
28434 field.displayField &&
28435 // combos' with local stores can
28436 // be queried via setValue()
28437 // to set their value..
28438 (field.store && !field.store.isLocal)
28442 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
28443 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
28444 field.setFromData(sd);
28447 field.setValue(values[id]);
28451 if(this.trackResetOnLoad){
28452 field.originalValue = field.getValue();
28458 Roo.each(this.childForms || [], function (f) {
28459 f.setValues(values);
28466 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
28467 * they are returned as an array.
28468 * @param {Boolean} asString
28471 getValues : function(asString){
28472 if (this.childForms) {
28473 // copy values from the child forms
28474 Roo.each(this.childForms, function (f) {
28475 this.setValues(f.getValues());
28481 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
28482 if(asString === true){
28485 return Roo.urlDecode(fs);
28489 * Returns the fields in this form as an object with key/value pairs.
28490 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
28493 getFieldValues : function(with_hidden)
28495 if (this.childForms) {
28496 // copy values from the child forms
28497 // should this call getFieldValues - probably not as we do not currently copy
28498 // hidden fields when we generate..
28499 Roo.each(this.childForms, function (f) {
28500 this.setValues(f.getValues());
28505 this.items.each(function(f){
28506 if (!f.getName()) {
28509 var v = f.getValue();
28510 if (f.inputType =='radio') {
28511 if (typeof(ret[f.getName()]) == 'undefined') {
28512 ret[f.getName()] = ''; // empty..
28515 if (!f.el.dom.checked) {
28519 v = f.el.dom.value;
28523 // not sure if this supported any more..
28524 if ((typeof(v) == 'object') && f.getRawValue) {
28525 v = f.getRawValue() ; // dates..
28527 // combo boxes where name != hiddenName...
28528 if (f.name != f.getName()) {
28529 ret[f.name] = f.getRawValue();
28531 ret[f.getName()] = v;
28538 * Clears all invalid messages in this form.
28539 * @return {BasicForm} this
28541 clearInvalid : function(){
28542 this.items.each(function(f){
28546 Roo.each(this.childForms || [], function (f) {
28555 * Resets this form.
28556 * @return {BasicForm} this
28558 reset : function(){
28559 this.items.each(function(f){
28563 Roo.each(this.childForms || [], function (f) {
28572 * Add Roo.form components to this form.
28573 * @param {Field} field1
28574 * @param {Field} field2 (optional)
28575 * @param {Field} etc (optional)
28576 * @return {BasicForm} this
28579 this.items.addAll(Array.prototype.slice.call(arguments, 0));
28585 * Removes a field from the items collection (does NOT remove its markup).
28586 * @param {Field} field
28587 * @return {BasicForm} this
28589 remove : function(field){
28590 this.items.remove(field);
28595 * Looks at the fields in this form, checks them for an id attribute,
28596 * and calls applyTo on the existing dom element with that id.
28597 * @return {BasicForm} this
28599 render : function(){
28600 this.items.each(function(f){
28601 if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
28609 * Calls {@link Ext#apply} for all fields in this form with the passed object.
28610 * @param {Object} values
28611 * @return {BasicForm} this
28613 applyToFields : function(o){
28614 this.items.each(function(f){
28621 * Calls {@link Ext#applyIf} for all field in this form with the passed object.
28622 * @param {Object} values
28623 * @return {BasicForm} this
28625 applyIfToFields : function(o){
28626 this.items.each(function(f){
28634 Roo.BasicForm = Roo.form.BasicForm;/*
28636 * Ext JS Library 1.1.1
28637 * Copyright(c) 2006-2007, Ext JS, LLC.
28639 * Originally Released Under LGPL - original licence link has changed is not relivant.
28642 * <script type="text/javascript">
28646 * @class Roo.form.Form
28647 * @extends Roo.form.BasicForm
28648 * Adds the ability to dynamically render forms with JavaScript to {@link Roo.form.BasicForm}.
28650 * @param {Object} config Configuration options
28652 Roo.form.Form = function(config){
28654 if (config.items) {
28655 xitems = config.items;
28656 delete config.items;
28660 Roo.form.Form.superclass.constructor.call(this, null, config);
28661 this.url = this.url || this.action;
28663 this.root = new Roo.form.Layout(Roo.applyIf({
28667 this.active = this.root;
28669 * Array of all the buttons that have been added to this form via {@link addButton}
28673 this.allItems = [];
28676 * @event clientvalidation
28677 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
28678 * @param {Form} this
28679 * @param {Boolean} valid true if the form has passed client-side validation
28681 clientvalidation: true,
28684 * Fires when the form is rendered
28685 * @param {Roo.form.Form} form
28690 if (this.progressUrl) {
28691 // push a hidden field onto the list of fields..
28695 name : 'UPLOAD_IDENTIFIER'
28700 Roo.each(xitems, this.addxtype, this);
28706 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
28708 * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
28711 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
28714 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
28716 buttonAlign:'center',
28719 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
28724 * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
28725 * This property cascades to child containers if not set.
28730 * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
28731 * fires a looping event with that state. This is required to bind buttons to the valid
28732 * state using the config value formBind:true on the button.
28734 monitorValid : false,
28737 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
28742 * @cfg {String} progressUrl - Url to return progress data
28745 progressUrl : false,
28748 * Opens a new {@link Roo.form.Column} container in the layout stack. If fields are passed after the config, the
28749 * fields are added and the column is closed. If no fields are passed the column remains open
28750 * until end() is called.
28751 * @param {Object} config The config to pass to the column
28752 * @param {Field} field1 (optional)
28753 * @param {Field} field2 (optional)
28754 * @param {Field} etc (optional)
28755 * @return Column The column container object
28757 column : function(c){
28758 var col = new Roo.form.Column(c);
28760 if(arguments.length > 1){ // duplicate code required because of Opera
28761 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
28768 * Opens a new {@link Roo.form.FieldSet} container in the layout stack. If fields are passed after the config, the
28769 * fields are added and the fieldset is closed. If no fields are passed the fieldset remains open
28770 * until end() is called.
28771 * @param {Object} config The config to pass to the fieldset
28772 * @param {Field} field1 (optional)
28773 * @param {Field} field2 (optional)
28774 * @param {Field} etc (optional)
28775 * @return FieldSet The fieldset container object
28777 fieldset : function(c){
28778 var fs = new Roo.form.FieldSet(c);
28780 if(arguments.length > 1){ // duplicate code required because of Opera
28781 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
28788 * Opens a new {@link Roo.form.Layout} container in the layout stack. If fields are passed after the config, the
28789 * fields are added and the container is closed. If no fields are passed the container remains open
28790 * until end() is called.
28791 * @param {Object} config The config to pass to the Layout
28792 * @param {Field} field1 (optional)
28793 * @param {Field} field2 (optional)
28794 * @param {Field} etc (optional)
28795 * @return Layout The container object
28797 container : function(c){
28798 var l = new Roo.form.Layout(c);
28800 if(arguments.length > 1){ // duplicate code required because of Opera
28801 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
28808 * Opens the passed container in the layout stack. The container can be any {@link Roo.form.Layout} or subclass.
28809 * @param {Object} container A Roo.form.Layout or subclass of Layout
28810 * @return {Form} this
28812 start : function(c){
28813 // cascade label info
28814 Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
28815 this.active.stack.push(c);
28816 c.ownerCt = this.active;
28822 * Closes the current open container
28823 * @return {Form} this
28826 if(this.active == this.root){
28829 this.active = this.active.ownerCt;
28834 * Add Roo.form components to the current open container (e.g. column, fieldset, etc.). Fields added via this method
28835 * can also be passed with an additional property of fieldLabel, which if supplied, will provide the text to display
28836 * as the label of the field.
28837 * @param {Field} field1
28838 * @param {Field} field2 (optional)
28839 * @param {Field} etc. (optional)
28840 * @return {Form} this
28843 this.active.stack.push.apply(this.active.stack, arguments);
28844 this.allItems.push.apply(this.allItems,arguments);
28846 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
28847 if(a[i].isFormField){
28852 Roo.form.Form.superclass.add.apply(this, r);
28862 * Find any element that has been added to a form, using it's ID or name
28863 * This can include framesets, columns etc. along with regular fields..
28864 * @param {String} id - id or name to find.
28866 * @return {Element} e - or false if nothing found.
28868 findbyId : function(id)
28874 Roo.each(this.allItems, function(f){
28875 if (f.id == id || f.name == id ){
28886 * Render this form into the passed container. This should only be called once!
28887 * @param {String/HTMLElement/Element} container The element this component should be rendered into
28888 * @return {Form} this
28890 render : function(ct)
28896 var o = this.autoCreate || {
28898 method : this.method || 'POST',
28899 id : this.id || Roo.id()
28901 this.initEl(ct.createChild(o));
28903 this.root.render(this.el);
28907 this.items.each(function(f){
28908 f.render('x-form-el-'+f.id);
28911 if(this.buttons.length > 0){
28912 // tables are required to maintain order and for correct IE layout
28913 var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
28914 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
28915 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
28917 var tr = tb.getElementsByTagName('tr')[0];
28918 for(var i = 0, len = this.buttons.length; i < len; i++) {
28919 var b = this.buttons[i];
28920 var td = document.createElement('td');
28921 td.className = 'x-form-btn-td';
28922 b.render(tr.appendChild(td));
28925 if(this.monitorValid){ // initialize after render
28926 this.startMonitoring();
28928 this.fireEvent('rendered', this);
28933 * Adds a button to the footer of the form - this <b>must</b> be called before the form is rendered.
28934 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
28935 * object or a valid Roo.DomHelper element config
28936 * @param {Function} handler The function called when the button is clicked
28937 * @param {Object} scope (optional) The scope of the handler function
28938 * @return {Roo.Button}
28940 addButton : function(config, handler, scope){
28944 minWidth: this.minButtonWidth,
28947 if(typeof config == "string"){
28950 Roo.apply(bc, config);
28952 var btn = new Roo.Button(null, bc);
28953 this.buttons.push(btn);
28958 * Adds a series of form elements (using the xtype property as the factory method.
28959 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column, (and 'end' to close a block)
28960 * @param {Object} config
28963 addxtype : function()
28965 var ar = Array.prototype.slice.call(arguments, 0);
28967 for(var i = 0; i < ar.length; i++) {
28969 continue; // skip -- if this happends something invalid got sent, we
28970 // should ignore it, as basically that interface element will not show up
28971 // and that should be pretty obvious!!
28974 if (Roo.form[ar[i].xtype]) {
28976 var fe = Roo.factory(ar[i], Roo.form);
28982 fe.store.form = this;
28987 this.allItems.push(fe);
28988 if (fe.items && fe.addxtype) {
28989 fe.addxtype.apply(fe, fe.items);
28999 // console.log('adding ' + ar[i].xtype);
29001 if (ar[i].xtype == 'Button') {
29002 //console.log('adding button');
29003 //console.log(ar[i]);
29004 this.addButton(ar[i]);
29005 this.allItems.push(fe);
29009 if (ar[i].xtype == 'end') { // so we can add fieldsets... / layout etc.
29010 alert('end is not supported on xtype any more, use items');
29012 // //console.log('adding end');
29020 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
29021 * option "monitorValid"
29023 startMonitoring : function(){
29026 Roo.TaskMgr.start({
29027 run : this.bindHandler,
29028 interval : this.monitorPoll || 200,
29035 * Stops monitoring of the valid state of this form
29037 stopMonitoring : function(){
29038 this.bound = false;
29042 bindHandler : function(){
29044 return false; // stops binding
29047 this.items.each(function(f){
29048 if(!f.isValid(true)){
29053 for(var i = 0, len = this.buttons.length; i < len; i++){
29054 var btn = this.buttons[i];
29055 if(btn.formBind === true && btn.disabled === valid){
29056 btn.setDisabled(!valid);
29059 this.fireEvent('clientvalidation', this, valid);
29073 Roo.Form = Roo.form.Form;
29076 * Ext JS Library 1.1.1
29077 * Copyright(c) 2006-2007, Ext JS, LLC.
29079 * Originally Released Under LGPL - original licence link has changed is not relivant.
29082 * <script type="text/javascript">
29086 * @class Roo.form.Action
29087 * Internal Class used to handle form actions
29089 * @param {Roo.form.BasicForm} el The form element or its id
29090 * @param {Object} config Configuration options
29094 // define the action interface
29095 Roo.form.Action = function(form, options){
29097 this.options = options || {};
29100 * Client Validation Failed
29103 Roo.form.Action.CLIENT_INVALID = 'client';
29105 * Server Validation Failed
29108 Roo.form.Action.SERVER_INVALID = 'server';
29110 * Connect to Server Failed
29113 Roo.form.Action.CONNECT_FAILURE = 'connect';
29115 * Reading Data from Server Failed
29118 Roo.form.Action.LOAD_FAILURE = 'load';
29120 Roo.form.Action.prototype = {
29122 failureType : undefined,
29123 response : undefined,
29124 result : undefined,
29126 // interface method
29127 run : function(options){
29131 // interface method
29132 success : function(response){
29136 // interface method
29137 handleResponse : function(response){
29141 // default connection failure
29142 failure : function(response){
29144 this.response = response;
29145 this.failureType = Roo.form.Action.CONNECT_FAILURE;
29146 this.form.afterAction(this, false);
29149 processResponse : function(response){
29150 this.response = response;
29151 if(!response.responseText){
29154 this.result = this.handleResponse(response);
29155 return this.result;
29158 // utility functions used internally
29159 getUrl : function(appendParams){
29160 var url = this.options.url || this.form.url || this.form.el.dom.action;
29162 var p = this.getParams();
29164 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
29170 getMethod : function(){
29171 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
29174 getParams : function(){
29175 var bp = this.form.baseParams;
29176 var p = this.options.params;
29178 if(typeof p == "object"){
29179 p = Roo.urlEncode(Roo.applyIf(p, bp));
29180 }else if(typeof p == 'string' && bp){
29181 p += '&' + Roo.urlEncode(bp);
29184 p = Roo.urlEncode(bp);
29189 createCallback : function(){
29191 success: this.success,
29192 failure: this.failure,
29194 timeout: (this.form.timeout*1000),
29195 upload: this.form.fileUpload ? this.success : undefined
29200 Roo.form.Action.Submit = function(form, options){
29201 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
29204 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
29207 haveProgress : false,
29208 uploadComplete : false,
29210 // uploadProgress indicator.
29211 uploadProgress : function()
29213 if (!this.form.progressUrl) {
29217 if (!this.haveProgress) {
29218 Roo.MessageBox.progress("Uploading", "Uploading");
29220 if (this.uploadComplete) {
29221 Roo.MessageBox.hide();
29225 this.haveProgress = true;
29227 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
29229 var c = new Roo.data.Connection();
29231 url : this.form.progressUrl,
29236 success : function(req){
29237 //console.log(data);
29241 rdata = Roo.decode(req.responseText)
29243 Roo.log("Invalid data from server..");
29247 if (!rdata || !rdata.success) {
29249 Roo.MessageBox.alert(Roo.encode(rdata));
29252 var data = rdata.data;
29254 if (this.uploadComplete) {
29255 Roo.MessageBox.hide();
29260 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
29261 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
29264 this.uploadProgress.defer(2000,this);
29267 failure: function(data) {
29268 Roo.log('progress url failed ');
29279 // run get Values on the form, so it syncs any secondary forms.
29280 this.form.getValues();
29282 var o = this.options;
29283 var method = this.getMethod();
29284 var isPost = method == 'POST';
29285 if(o.clientValidation === false || this.form.isValid()){
29287 if (this.form.progressUrl) {
29288 this.form.findField('UPLOAD_IDENTIFIER').setValue(
29289 (new Date() * 1) + '' + Math.random());
29294 Roo.Ajax.request(Roo.apply(this.createCallback(), {
29295 form:this.form.el.dom,
29296 url:this.getUrl(!isPost),
29298 params:isPost ? this.getParams() : null,
29299 isUpload: this.form.fileUpload
29302 this.uploadProgress();
29304 }else if (o.clientValidation !== false){ // client validation failed
29305 this.failureType = Roo.form.Action.CLIENT_INVALID;
29306 this.form.afterAction(this, false);
29310 success : function(response)
29312 this.uploadComplete= true;
29313 if (this.haveProgress) {
29314 Roo.MessageBox.hide();
29318 var result = this.processResponse(response);
29319 if(result === true || result.success){
29320 this.form.afterAction(this, true);
29324 this.form.markInvalid(result.errors);
29325 this.failureType = Roo.form.Action.SERVER_INVALID;
29327 this.form.afterAction(this, false);
29329 failure : function(response)
29331 this.uploadComplete= true;
29332 if (this.haveProgress) {
29333 Roo.MessageBox.hide();
29336 this.response = response;
29337 this.failureType = Roo.form.Action.CONNECT_FAILURE;
29338 this.form.afterAction(this, false);
29341 handleResponse : function(response){
29342 if(this.form.errorReader){
29343 var rs = this.form.errorReader.read(response);
29346 for(var i = 0, len = rs.records.length; i < len; i++) {
29347 var r = rs.records[i];
29348 errors[i] = r.data;
29351 if(errors.length < 1){
29355 success : rs.success,
29361 ret = Roo.decode(response.responseText);
29365 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
29375 Roo.form.Action.Load = function(form, options){
29376 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
29377 this.reader = this.form.reader;
29380 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
29385 Roo.Ajax.request(Roo.apply(
29386 this.createCallback(), {
29387 method:this.getMethod(),
29388 url:this.getUrl(false),
29389 params:this.getParams()
29393 success : function(response){
29395 var result = this.processResponse(response);
29396 if(result === true || !result.success || !result.data){
29397 this.failureType = Roo.form.Action.LOAD_FAILURE;
29398 this.form.afterAction(this, false);
29401 this.form.clearInvalid();
29402 this.form.setValues(result.data);
29403 this.form.afterAction(this, true);
29406 handleResponse : function(response){
29407 if(this.form.reader){
29408 var rs = this.form.reader.read(response);
29409 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
29411 success : rs.success,
29415 return Roo.decode(response.responseText);
29419 Roo.form.Action.ACTION_TYPES = {
29420 'load' : Roo.form.Action.Load,
29421 'submit' : Roo.form.Action.Submit
29424 * Ext JS Library 1.1.1
29425 * Copyright(c) 2006-2007, Ext JS, LLC.
29427 * Originally Released Under LGPL - original licence link has changed is not relivant.
29430 * <script type="text/javascript">
29434 * @class Roo.form.Layout
29435 * @extends Roo.Component
29436 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
29438 * @param {Object} config Configuration options
29440 Roo.form.Layout = function(config){
29442 if (config.items) {
29443 xitems = config.items;
29444 delete config.items;
29446 Roo.form.Layout.superclass.constructor.call(this, config);
29448 Roo.each(xitems, this.addxtype, this);
29452 Roo.extend(Roo.form.Layout, Roo.Component, {
29454 * @cfg {String/Object} autoCreate
29455 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
29458 * @cfg {String/Object/Function} style
29459 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
29460 * a function which returns such a specification.
29463 * @cfg {String} labelAlign
29464 * Valid values are "left," "top" and "right" (defaults to "left")
29467 * @cfg {Number} labelWidth
29468 * Fixed width in pixels of all field labels (defaults to undefined)
29471 * @cfg {Boolean} clear
29472 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
29476 * @cfg {String} labelSeparator
29477 * The separator to use after field labels (defaults to ':')
29479 labelSeparator : ':',
29481 * @cfg {Boolean} hideLabels
29482 * True to suppress the display of field labels in this layout (defaults to false)
29484 hideLabels : false,
29487 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
29492 onRender : function(ct, position){
29493 if(this.el){ // from markup
29494 this.el = Roo.get(this.el);
29495 }else { // generate
29496 var cfg = this.getAutoCreate();
29497 this.el = ct.createChild(cfg, position);
29500 this.el.applyStyles(this.style);
29502 if(this.labelAlign){
29503 this.el.addClass('x-form-label-'+this.labelAlign);
29505 if(this.hideLabels){
29506 this.labelStyle = "display:none";
29507 this.elementStyle = "padding-left:0;";
29509 if(typeof this.labelWidth == 'number'){
29510 this.labelStyle = "width:"+this.labelWidth+"px;";
29511 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
29513 if(this.labelAlign == 'top'){
29514 this.labelStyle = "width:auto;";
29515 this.elementStyle = "padding-left:0;";
29518 var stack = this.stack;
29519 var slen = stack.length;
29521 if(!this.fieldTpl){
29522 var t = new Roo.Template(
29523 '<div class="x-form-item {5}">',
29524 '<label for="{0}" style="{2}">{1}{4}</label>',
29525 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
29527 '</div><div class="x-form-clear-left"></div>'
29529 t.disableFormats = true;
29531 Roo.form.Layout.prototype.fieldTpl = t;
29533 for(var i = 0; i < slen; i++) {
29534 if(stack[i].isFormField){
29535 this.renderField(stack[i]);
29537 this.renderComponent(stack[i]);
29542 this.el.createChild({cls:'x-form-clear'});
29547 renderField : function(f){
29548 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
29551 f.labelStyle||this.labelStyle||'', //2
29552 this.elementStyle||'', //3
29553 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
29554 f.itemCls||this.itemCls||'' //5
29555 ], true).getPrevSibling());
29559 renderComponent : function(c){
29560 c.render(c.isLayout ? this.el : this.el.createChild());
29563 * Adds a object form elements (using the xtype property as the factory method.)
29564 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
29565 * @param {Object} config
29567 addxtype : function(o)
29569 // create the lement.
29570 o.form = this.form;
29571 var fe = Roo.factory(o, Roo.form);
29572 this.form.allItems.push(fe);
29573 this.stack.push(fe);
29575 if (fe.isFormField) {
29576 this.form.items.add(fe);
29584 * @class Roo.form.Column
29585 * @extends Roo.form.Layout
29586 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
29588 * @param {Object} config Configuration options
29590 Roo.form.Column = function(config){
29591 Roo.form.Column.superclass.constructor.call(this, config);
29594 Roo.extend(Roo.form.Column, Roo.form.Layout, {
29596 * @cfg {Number/String} width
29597 * The fixed width of the column in pixels or CSS value (defaults to "auto")
29600 * @cfg {String/Object} autoCreate
29601 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
29605 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
29608 onRender : function(ct, position){
29609 Roo.form.Column.superclass.onRender.call(this, ct, position);
29611 this.el.setWidth(this.width);
29618 * @class Roo.form.Row
29619 * @extends Roo.form.Layout
29620 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
29622 * @param {Object} config Configuration options
29626 Roo.form.Row = function(config){
29627 Roo.form.Row.superclass.constructor.call(this, config);
29630 Roo.extend(Roo.form.Row, Roo.form.Layout, {
29632 * @cfg {Number/String} width
29633 * The fixed width of the column in pixels or CSS value (defaults to "auto")
29636 * @cfg {Number/String} height
29637 * The fixed height of the column in pixels or CSS value (defaults to "auto")
29639 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
29643 onRender : function(ct, position){
29644 //console.log('row render');
29646 var t = new Roo.Template(
29647 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
29648 '<label for="{0}" style="{2}">{1}{4}</label>',
29649 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
29653 t.disableFormats = true;
29655 Roo.form.Layout.prototype.rowTpl = t;
29657 this.fieldTpl = this.rowTpl;
29659 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
29660 var labelWidth = 100;
29662 if ((this.labelAlign != 'top')) {
29663 if (typeof this.labelWidth == 'number') {
29664 labelWidth = this.labelWidth
29666 this.padWidth = 20 + labelWidth;
29670 Roo.form.Column.superclass.onRender.call(this, ct, position);
29672 this.el.setWidth(this.width);
29675 this.el.setHeight(this.height);
29680 renderField : function(f){
29681 f.fieldEl = this.fieldTpl.append(this.el, [
29682 f.id, f.fieldLabel,
29683 f.labelStyle||this.labelStyle||'',
29684 this.elementStyle||'',
29685 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
29686 f.itemCls||this.itemCls||'',
29687 f.width ? f.width + this.padWidth : 160 + this.padWidth
29694 * @class Roo.form.FieldSet
29695 * @extends Roo.form.Layout
29696 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
29698 * @param {Object} config Configuration options
29700 Roo.form.FieldSet = function(config){
29701 Roo.form.FieldSet.superclass.constructor.call(this, config);
29704 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
29706 * @cfg {String} legend
29707 * The text to display as the legend for the FieldSet (defaults to '')
29710 * @cfg {String/Object} autoCreate
29711 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
29715 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
29718 onRender : function(ct, position){
29719 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
29721 this.setLegend(this.legend);
29726 setLegend : function(text){
29728 this.el.child('legend').update(text);
29733 * Ext JS Library 1.1.1
29734 * Copyright(c) 2006-2007, Ext JS, LLC.
29736 * Originally Released Under LGPL - original licence link has changed is not relivant.
29739 * <script type="text/javascript">
29742 * @class Roo.form.VTypes
29743 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
29746 Roo.form.VTypes = function(){
29747 // closure these in so they are only created once.
29748 var alpha = /^[a-zA-Z_]+$/;
29749 var alphanum = /^[a-zA-Z0-9_]+$/;
29750 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
29751 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
29753 // All these messages and functions are configurable
29756 * The function used to validate email addresses
29757 * @param {String} value The email address
29759 'email' : function(v){
29760 return email.test(v);
29763 * The error text to display when the email validation function returns false
29766 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
29768 * The keystroke filter mask to be applied on email input
29771 'emailMask' : /[a-z0-9_\.\-@]/i,
29774 * The function used to validate URLs
29775 * @param {String} value The URL
29777 'url' : function(v){
29778 return url.test(v);
29781 * The error text to display when the url validation function returns false
29784 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
29787 * The function used to validate alpha values
29788 * @param {String} value The value
29790 'alpha' : function(v){
29791 return alpha.test(v);
29794 * The error text to display when the alpha validation function returns false
29797 'alphaText' : 'This field should only contain letters and _',
29799 * The keystroke filter mask to be applied on alpha input
29802 'alphaMask' : /[a-z_]/i,
29805 * The function used to validate alphanumeric values
29806 * @param {String} value The value
29808 'alphanum' : function(v){
29809 return alphanum.test(v);
29812 * The error text to display when the alphanumeric validation function returns false
29815 'alphanumText' : 'This field should only contain letters, numbers and _',
29817 * The keystroke filter mask to be applied on alphanumeric input
29820 'alphanumMask' : /[a-z0-9_]/i
29822 }();//<script type="text/javascript">
29825 * @class Roo.form.FCKeditor
29826 * @extends Roo.form.TextArea
29827 * Wrapper around the FCKEditor http://www.fckeditor.net
29829 * Creates a new FCKeditor
29830 * @param {Object} config Configuration options
29832 Roo.form.FCKeditor = function(config){
29833 Roo.form.FCKeditor.superclass.constructor.call(this, config);
29836 * @event editorinit
29837 * Fired when the editor is initialized - you can add extra handlers here..
29838 * @param {FCKeditor} this
29839 * @param {Object} the FCK object.
29846 Roo.form.FCKeditor.editors = { };
29847 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
29849 //defaultAutoCreate : {
29850 // tag : "textarea",style : "width:100px;height:60px;" ,autocomplete : "off"
29854 * @cfg {Object} fck options - see fck manual for details.
29859 * @cfg {Object} fck toolbar set (Basic or Default)
29861 toolbarSet : 'Basic',
29863 * @cfg {Object} fck BasePath
29865 basePath : '/fckeditor/',
29873 onRender : function(ct, position)
29876 this.defaultAutoCreate = {
29878 style:"width:300px;height:60px;",
29879 autocomplete: "off"
29882 Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
29885 this.textSizeEl = Roo.DomHelper.append(document.body, {tag: "pre", cls: "x-form-grow-sizer"});
29886 if(this.preventScrollbars){
29887 this.el.setStyle("overflow", "hidden");
29889 this.el.setHeight(this.growMin);
29892 //console.log('onrender' + this.getId() );
29893 Roo.form.FCKeditor.editors[this.getId()] = this;
29896 this.replaceTextarea() ;
29900 getEditor : function() {
29901 return this.fckEditor;
29904 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
29905 * @param {Mixed} value The value to set
29909 setValue : function(value)
29911 //console.log('setValue: ' + value);
29913 if(typeof(value) == 'undefined') { // not sure why this is happending...
29916 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
29918 //if(!this.el || !this.getEditor()) {
29919 // this.value = value;
29920 //this.setValue.defer(100,this,[value]);
29924 if(!this.getEditor()) {
29928 this.getEditor().SetData(value);
29935 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
29936 * @return {Mixed} value The field value
29938 getValue : function()
29941 if (this.frame && this.frame.dom.style.display == 'none') {
29942 return Roo.form.FCKeditor.superclass.getValue.call(this);
29945 if(!this.el || !this.getEditor()) {
29947 // this.getValue.defer(100,this);
29952 var value=this.getEditor().GetData();
29953 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
29954 return Roo.form.FCKeditor.superclass.getValue.call(this);
29960 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
29961 * @return {Mixed} value The field value
29963 getRawValue : function()
29965 if (this.frame && this.frame.dom.style.display == 'none') {
29966 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
29969 if(!this.el || !this.getEditor()) {
29970 //this.getRawValue.defer(100,this);
29977 var value=this.getEditor().GetData();
29978 Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
29979 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
29983 setSize : function(w,h) {
29987 //if (this.frame && this.frame.dom.style.display == 'none') {
29988 // Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
29991 //if(!this.el || !this.getEditor()) {
29992 // this.setSize.defer(100,this, [w,h]);
29998 Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
30000 this.frame.dom.setAttribute('width', w);
30001 this.frame.dom.setAttribute('height', h);
30002 this.frame.setSize(w,h);
30006 toggleSourceEdit : function(value) {
30010 this.el.dom.style.display = value ? '' : 'none';
30011 this.frame.dom.style.display = value ? 'none' : '';
30016 focus: function(tag)
30018 if (this.frame.dom.style.display == 'none') {
30019 return Roo.form.FCKeditor.superclass.focus.call(this);
30021 if(!this.el || !this.getEditor()) {
30022 this.focus.defer(100,this, [tag]);
30029 var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
30030 this.getEditor().Focus();
30032 if (!this.getEditor().Selection.GetSelection()) {
30033 this.focus.defer(100,this, [tag]);
30038 var r = this.getEditor().EditorDocument.createRange();
30039 r.setStart(tgs[0],0);
30040 r.setEnd(tgs[0],0);
30041 this.getEditor().Selection.GetSelection().removeAllRanges();
30042 this.getEditor().Selection.GetSelection().addRange(r);
30043 this.getEditor().Focus();
30050 replaceTextarea : function()
30052 if ( document.getElementById( this.getId() + '___Frame' ) )
30054 //if ( !this.checkBrowser || this._isCompatibleBrowser() )
30056 // We must check the elements firstly using the Id and then the name.
30057 var oTextarea = document.getElementById( this.getId() );
30059 var colElementsByName = document.getElementsByName( this.getId() ) ;
30061 oTextarea.style.display = 'none' ;
30063 if ( oTextarea.tabIndex ) {
30064 this.TabIndex = oTextarea.tabIndex ;
30067 this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
30068 this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
30069 this.frame = Roo.get(this.getId() + '___Frame')
30072 _getConfigHtml : function()
30076 for ( var o in this.fckconfig ) {
30077 sConfig += sConfig.length > 0 ? '&' : '';
30078 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
30081 return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
30085 _getIFrameHtml : function()
30087 var sFile = 'fckeditor.html' ;
30088 /* no idea what this is about..
30091 if ( (/fcksource=true/i).test( window.top.location.search ) )
30092 sFile = 'fckeditor.original.html' ;
30097 var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
30098 sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
30101 var html = '<iframe id="' + this.getId() +
30102 '___Frame" src="' + sLink +
30103 '" width="' + this.width +
30104 '" height="' + this.height + '"' +
30105 (this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
30106 ' frameborder="0" scrolling="no"></iframe>' ;
30111 _insertHtmlBefore : function( html, element )
30113 if ( element.insertAdjacentHTML ) {
30115 element.insertAdjacentHTML( 'beforeBegin', html ) ;
30117 var oRange = document.createRange() ;
30118 oRange.setStartBefore( element ) ;
30119 var oFragment = oRange.createContextualFragment( html );
30120 element.parentNode.insertBefore( oFragment, element ) ;
30133 //Roo.reg('fckeditor', Roo.form.FCKeditor);
30135 function FCKeditor_OnComplete(editorInstance){
30136 var f = Roo.form.FCKeditor.editors[editorInstance.Name];
30137 f.fckEditor = editorInstance;
30138 //console.log("loaded");
30139 f.fireEvent('editorinit', f, editorInstance);
30159 //<script type="text/javascript">
30161 * @class Roo.form.GridField
30162 * @extends Roo.form.Field
30163 * Embed a grid (or editable grid into a form)
30166 * This embeds a grid in a form, the value of the field should be the json encoded array of rows
30168 * xgrid.store = Roo.data.Store
30169 * xgrid.store.proxy = Roo.data.MemoryProxy (data = [] )
30170 * xgrid.store.reader = Roo.data.JsonReader
30174 * Creates a new GridField
30175 * @param {Object} config Configuration options
30177 Roo.form.GridField = function(config){
30178 Roo.form.GridField.superclass.constructor.call(this, config);
30182 Roo.extend(Roo.form.GridField, Roo.form.Field, {
30184 * @cfg {Number} width - used to restrict width of grid..
30188 * @cfg {Number} height - used to restrict height of grid..
30192 * @cfg {Object} xgrid (xtype'd description of grid) { xtype : 'Grid', dataSource: .... }
30198 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
30199 * {tag: "input", type: "checkbox", autocomplete: "off"})
30201 // defaultAutoCreate : { tag: 'div' },
30202 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
30204 * @cfg {String} addTitle Text to include for adding a title.
30208 onResize : function(){
30209 Roo.form.Field.superclass.onResize.apply(this, arguments);
30212 initEvents : function(){
30213 // Roo.form.Checkbox.superclass.initEvents.call(this);
30214 // has no events...
30219 getResizeEl : function(){
30223 getPositionEl : function(){
30228 onRender : function(ct, position){
30230 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
30231 var style = this.style;
30234 Roo.form.GridField.superclass.onRender.call(this, ct, position);
30235 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
30236 this.viewEl = this.wrap.createChild({ tag: 'div' });
30238 this.viewEl.applyStyles(style);
30241 this.viewEl.setWidth(this.width);
30244 this.viewEl.setHeight(this.height);
30246 //if(this.inputValue !== undefined){
30247 //this.setValue(this.value);
30250 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
30253 this.grid.render();
30254 this.grid.getDataSource().on('remove', this.refreshValue, this);
30255 this.grid.getDataSource().on('update', this.refreshValue, this);
30256 this.grid.on('afteredit', this.refreshValue, this);
30262 * Sets the value of the item.
30263 * @param {String} either an object or a string..
30265 setValue : function(v){
30267 v = v || []; // empty set..
30268 // this does not seem smart - it really only affects memoryproxy grids..
30269 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
30270 var ds = this.grid.getDataSource();
30271 // assumes a json reader..
30273 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
30274 ds.loadData( data);
30276 // clear selection so it does not get stale.
30277 if (this.grid.sm) {
30278 this.grid.sm.clearSelections();
30281 Roo.form.GridField.superclass.setValue.call(this, v);
30282 this.refreshValue();
30283 // should load data in the grid really....
30287 refreshValue: function() {
30289 this.grid.getDataSource().each(function(r) {
30292 this.el.dom.value = Roo.encode(val);
30300 * Ext JS Library 1.1.1
30301 * Copyright(c) 2006-2007, Ext JS, LLC.
30303 * Originally Released Under LGPL - original licence link has changed is not relivant.
30306 * <script type="text/javascript">
30309 * @class Roo.form.DisplayField
30310 * @extends Roo.form.Field
30311 * A generic Field to display non-editable data.
30313 * Creates a new Display Field item.
30314 * @param {Object} config Configuration options
30316 Roo.form.DisplayField = function(config){
30317 Roo.form.DisplayField.superclass.constructor.call(this, config);
30321 Roo.extend(Roo.form.DisplayField, Roo.form.TextField, {
30322 inputType: 'hidden',
30328 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
30330 focusClass : undefined,
30332 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
30334 fieldClass: 'x-form-field',
30337 * @cfg {Function} valueRenderer The renderer for the field (so you can reformat output). should return raw HTML
30339 valueRenderer: undefined,
30343 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
30344 * {tag: "input", type: "checkbox", autocomplete: "off"})
30347 // defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
30349 onResize : function(){
30350 Roo.form.DisplayField.superclass.onResize.apply(this, arguments);
30354 initEvents : function(){
30355 // Roo.form.Checkbox.superclass.initEvents.call(this);
30356 // has no events...
30361 getResizeEl : function(){
30365 getPositionEl : function(){
30370 onRender : function(ct, position){
30372 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
30373 //if(this.inputValue !== undefined){
30374 this.wrap = this.el.wrap();
30376 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
30378 if (this.bodyStyle) {
30379 this.viewEl.applyStyles(this.bodyStyle);
30381 //this.viewEl.setStyle('padding', '2px');
30383 this.setValue(this.value);
30388 initValue : Roo.emptyFn,
30393 onClick : function(){
30398 * Sets the checked state of the checkbox.
30399 * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
30401 setValue : function(v){
30403 var html = this.valueRenderer ? this.valueRenderer(v) : String.format('{0}', v);
30404 // this might be called before we have a dom element..
30405 if (!this.viewEl) {
30408 this.viewEl.dom.innerHTML = html;
30409 Roo.form.DisplayField.superclass.setValue.call(this, v);
30419 * @class Roo.form.DayPicker
30420 * @extends Roo.form.Field
30421 * A Day picker show [M] [T] [W] ....
30423 * Creates a new Day Picker
30424 * @param {Object} config Configuration options
30426 Roo.form.DayPicker= function(config){
30427 Roo.form.DayPicker.superclass.constructor.call(this, config);
30431 Roo.extend(Roo.form.DayPicker, Roo.form.Field, {
30433 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
30435 focusClass : undefined,
30437 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
30439 fieldClass: "x-form-field",
30442 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
30443 * {tag: "input", type: "checkbox", autocomplete: "off"})
30445 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
30448 actionMode : 'viewEl',
30452 inputType : 'hidden',
30455 inputElement: false, // real input element?
30456 basedOn: false, // ????
30458 isFormField: true, // not sure where this is needed!!!!
30460 onResize : function(){
30461 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
30462 if(!this.boxLabel){
30463 this.el.alignTo(this.wrap, 'c-c');
30467 initEvents : function(){
30468 Roo.form.Checkbox.superclass.initEvents.call(this);
30469 this.el.on("click", this.onClick, this);
30470 this.el.on("change", this.onClick, this);
30474 getResizeEl : function(){
30478 getPositionEl : function(){
30484 onRender : function(ct, position){
30485 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
30487 this.wrap = this.el.wrap({cls: 'x-form-daypick-item '});
30489 var r1 = '<table><tr>';
30490 var r2 = '<tr class="x-form-daypick-icons">';
30491 for (var i=0; i < 7; i++) {
30492 r1+= '<td><div>' + Date.dayNames[i].substring(0,3) + '</div></td>';
30493 r2+= '<td><img class="x-menu-item-icon" src="' + Roo.BLANK_IMAGE_URL +'"></td>';
30496 var viewEl = this.wrap.createChild( r1 + '</tr>' + r2 + '</tr></table>');
30497 viewEl.select('img').on('click', this.onClick, this);
30498 this.viewEl = viewEl;
30501 // this will not work on Chrome!!!
30502 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
30503 this.el.on('propertychange', this.setFromHidden, this); //ie
30511 initValue : Roo.emptyFn,
30514 * Returns the checked state of the checkbox.
30515 * @return {Boolean} True if checked, else false
30517 getValue : function(){
30518 return this.el.dom.value;
30523 onClick : function(e){
30524 //this.setChecked(!this.checked);
30525 Roo.get(e.target).toggleClass('x-menu-item-checked');
30526 this.refreshValue();
30527 //if(this.el.dom.checked != this.checked){
30528 // this.setValue(this.el.dom.checked);
30533 refreshValue : function()
30536 this.viewEl.select('img',true).each(function(e,i,n) {
30537 val += e.is(".x-menu-item-checked") ? String(n) : '';
30539 this.setValue(val, true);
30543 * Sets the checked state of the checkbox.
30544 * On is always based on a string comparison between inputValue and the param.
30545 * @param {Boolean/String} value - the value to set
30546 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
30548 setValue : function(v,suppressEvent){
30549 if (!this.el.dom) {
30552 var old = this.el.dom.value ;
30553 this.el.dom.value = v;
30554 if (suppressEvent) {
30558 // update display..
30559 this.viewEl.select('img',true).each(function(e,i,n) {
30561 var on = e.is(".x-menu-item-checked");
30562 var newv = v.indexOf(String(n)) > -1;
30564 e.toggleClass('x-menu-item-checked');
30570 this.fireEvent('change', this, v, old);
30575 // handle setting of hidden value by some other method!!?!?
30576 setFromHidden: function()
30581 //console.log("SET FROM HIDDEN");
30582 //alert('setFrom hidden');
30583 this.setValue(this.el.dom.value);
30586 onDestroy : function()
30589 Roo.get(this.viewEl).remove();
30592 Roo.form.DayPicker.superclass.onDestroy.call(this);
30596 * RooJS Library 1.1.1
30597 * Copyright(c) 2008-2011 Alan Knowles
30604 * @class Roo.form.ComboCheck
30605 * @extends Roo.form.ComboBox
30606 * A combobox for multiple select items.
30608 * FIXME - could do with a reset button..
30611 * Create a new ComboCheck
30612 * @param {Object} config Configuration options
30614 Roo.form.ComboCheck = function(config){
30615 Roo.form.ComboCheck.superclass.constructor.call(this, config);
30616 // should verify some data...
30618 // hiddenName = required..
30619 // displayField = required
30620 // valudField == required
30621 var req= [ 'hiddenName', 'displayField', 'valueField' ];
30623 Roo.each(req, function(e) {
30624 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
30625 throw "Roo.form.ComboCheck : missing value for: " + e;
30632 Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
30637 selectedClass: 'x-menu-item-checked',
30640 onRender : function(ct, position){
30646 var cls = 'x-combo-list';
30649 this.tpl = new Roo.Template({
30650 html : '<div class="'+cls+'-item x-menu-check-item">' +
30651 '<img class="x-menu-item-icon" style="margin: 0px;" src="' + Roo.BLANK_IMAGE_URL + '">' +
30652 '<span>{' + this.displayField + '}</span>' +
30659 Roo.form.ComboCheck.superclass.onRender.call(this, ct, position);
30660 this.view.singleSelect = false;
30661 this.view.multiSelect = true;
30662 this.view.toggleSelect = true;
30663 this.pageTb.add(new Roo.Toolbar.Fill(), {
30666 handler: function()
30673 onViewOver : function(e, t){
30679 onViewClick : function(doFocus,index){
30683 select: function () {
30684 //Roo.log("SELECT CALLED");
30687 selectByValue : function(xv, scrollIntoView){
30688 var ar = this.getValueArray();
30691 Roo.each(ar, function(v) {
30692 if(v === undefined || v === null){
30695 var r = this.findRecord(this.valueField, v);
30697 sels.push(this.store.indexOf(r))
30701 this.view.select(sels);
30707 onSelect : function(record, index){
30708 // Roo.log("onselect Called");
30709 // this is only called by the clear button now..
30710 this.view.clearSelections();
30711 this.setValue('[]');
30712 if (this.value != this.valueBefore) {
30713 this.fireEvent('change', this, this.value, this.valueBefore);
30714 this.valueBefore = this.value;
30717 getValueArray : function()
30722 //Roo.log(this.value);
30723 if (typeof(this.value) == 'undefined') {
30726 var ar = Roo.decode(this.value);
30727 return ar instanceof Array ? ar : []; //?? valid?
30730 Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
30735 expand : function ()
30738 Roo.form.ComboCheck.superclass.expand.call(this);
30739 this.valueBefore = typeof(this.value) == 'undefined' ? '' : this.value;
30740 //this.valueBefore = typeof(this.valueBefore) == 'undefined' ? '' : this.valueBefore;
30745 collapse : function(){
30746 Roo.form.ComboCheck.superclass.collapse.call(this);
30747 var sl = this.view.getSelectedIndexes();
30748 var st = this.store;
30752 Roo.each(sl, function(i) {
30754 nv.push(r.get(this.valueField));
30756 this.setValue(Roo.encode(nv));
30757 if (this.value != this.valueBefore) {
30759 this.fireEvent('change', this, this.value, this.valueBefore);
30760 this.valueBefore = this.value;
30765 setValue : function(v){
30769 var vals = this.getValueArray();
30771 Roo.each(vals, function(k) {
30772 var r = this.findRecord(this.valueField, k);
30774 tv.push(r.data[this.displayField]);
30775 }else if(this.valueNotFoundText !== undefined){
30776 tv.push( this.valueNotFoundText );
30781 Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
30782 this.hiddenField.value = v;
30788 * Ext JS Library 1.1.1
30789 * Copyright(c) 2006-2007, Ext JS, LLC.
30791 * Originally Released Under LGPL - original licence link has changed is not relivant.
30794 * <script type="text/javascript">
30798 * @class Roo.form.Signature
30799 * @extends Roo.form.Field
30803 * @param {Object} config Configuration options
30806 Roo.form.Signature = function(config){
30807 Roo.form.Signature.superclass.constructor.call(this, config);
30809 this.addEvents({// not in used??
30812 * Fires when the 'confirm' icon is pressed (add a listener to enable add button)
30813 * @param {Roo.form.Signature} combo This combo box
30818 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
30819 * @param {Roo.form.ComboBox} combo This combo box
30820 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
30826 Roo.extend(Roo.form.Signature, Roo.form.Field, {
30828 * @cfg {Object} labels Label to use when rendering a form.
30832 * confirm : "Confirm"
30837 confirm : "Confirm"
30840 * @cfg {Number} width The signature panel width (defaults to 300)
30844 * @cfg {Number} height The signature panel height (defaults to 100)
30848 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to false)
30850 allowBlank : false,
30853 // {Object} signPanel The signature SVG panel element (defaults to {})
30855 // {Boolean} isMouseDown False to validate that the mouse down event (defaults to false)
30856 isMouseDown : false,
30857 // {Boolean} isConfirmed validate the signature is confirmed or not for submitting form (defaults to false)
30858 isConfirmed : false,
30859 // {String} signatureTmp SVG mapping string (defaults to empty string)
30863 defaultAutoCreate : { // modified by initCompnoent..
30869 onRender : function(ct, position){
30871 Roo.form.Signature.superclass.onRender.call(this, ct, position);
30873 this.wrap = this.el.wrap({
30874 cls:'x-form-signature-wrap', style : 'width: ' + this.width + 'px', cn:{cls:'x-form-signature'}
30877 this.createToolbar(this);
30878 this.signPanel = this.wrap.createChild({
30880 style: 'width: ' + this.width + 'px; height: ' + this.height + 'px; border: 0;'
30884 this.svgID = Roo.id();
30885 this.svgEl = this.signPanel.createChild({
30886 xmlns : 'http://www.w3.org/2000/svg',
30888 id : this.svgID + "-svg",
30890 height: this.height,
30891 viewBox: '0 0 '+this.width+' '+this.height,
30895 id: this.svgID + "-svg-r",
30897 height: this.height,
30902 id: this.svgID + "-svg-l",
30904 y1: (this.height*0.8), // start set the line in 80% of height
30905 x2: this.width, // end
30906 y2: (this.height*0.8), // end set the line in 80% of height
30908 'stroke-width': "1",
30909 'stroke-dasharray': "3",
30910 'shape-rendering': "crispEdges",
30911 'pointer-events': "none"
30915 id: this.svgID + "-svg-p",
30917 'stroke-width': "3",
30919 'pointer-events': 'none'
30924 this.svgBox = this.svgEl.dom.getScreenCTM();
30926 createSVG : function(){
30927 var svg = this.signPanel;
30928 var r = svg.select('#'+ this.svgID + '-svg-r', true).first().dom;
30931 r.addEventListener('mousedown', function(e) { return t.down(e); }, false);
30932 r.addEventListener('mousemove', function(e) { return t.move(e); }, false);
30933 r.addEventListener('mouseup', function(e) { return t.up(e); }, false);
30934 r.addEventListener('mouseout', function(e) { return t.up(e); }, false);
30935 r.addEventListener('touchstart', function(e) { return t.down(e); }, false);
30936 r.addEventListener('touchmove', function(e) { return t.move(e); }, false);
30937 r.addEventListener('touchend', function(e) { return t.up(e); }, false);
30940 isTouchEvent : function(e){
30941 return e.type.match(/^touch/);
30943 getCoords : function (e) {
30944 var pt = this.svgEl.dom.createSVGPoint();
30947 if (this.isTouchEvent(e)) {
30948 pt.x = e.targetTouches[0].clientX
30949 pt.y = e.targetTouches[0].clientY;
30951 var a = this.svgEl.dom.getScreenCTM();
30952 var b = a.inverse();
30953 var mx = pt.matrixTransform(b);
30954 return mx.x + ',' + mx.y;
30956 //mouse event headler
30957 down : function (e) {
30958 this.signatureTmp += 'M' + this.getCoords(e) + ' ';
30959 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr('d', this.signatureTmp);
30961 this.isMouseDown = true;
30963 e.preventDefault();
30965 move : function (e) {
30966 if (this.isMouseDown) {
30967 this.signatureTmp += 'L' + this.getCoords(e) + ' ';
30968 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', this.signatureTmp);
30971 e.preventDefault();
30973 up : function (e) {
30974 this.isMouseDown = false;
30975 var sp = this.signatureTmp.split(' ');
30978 if(!sp[sp.length-2].match(/^L/)){
30982 this.signatureTmp = sp.join(" ");
30985 if(this.getValue() != this.signatureTmp){
30986 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
30987 this.isConfirmed = false;
30989 e.preventDefault();
30993 * Protected method that will not generally be called directly. It
30994 * is called when the editor creates its toolbar. Override this method if you need to
30995 * add custom toolbar buttons.
30996 * @param {HtmlEditor} editor
30998 createToolbar : function(editor){
30999 function btn(id, toggle, handler){
31000 var xid = fid + '-'+ id ;
31004 cls : 'x-btn-icon x-edit-'+id,
31005 enableToggle:toggle !== false,
31006 scope: editor, // was editor...
31007 handler:handler||editor.relayBtnCmd,
31008 clickEvent:'mousedown',
31009 tooltip: etb.buttonTips[id] || undefined, ///tips ???
31015 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
31019 cls : ' x-signature-btn x-signature-'+id,
31020 scope: editor, // was editor...
31021 handler: this.reset,
31022 clickEvent:'mousedown',
31023 text: this.labels.clear
31030 cls : ' x-signature-btn x-signature-'+id,
31031 scope: editor, // was editor...
31032 handler: this.confirmHandler,
31033 clickEvent:'mousedown',
31034 text: this.labels.confirm
31041 * when user is clicked confirm then show this image.....
31043 * @return {String} Image Data URI
31045 getImageDataURI : function(){
31046 var svg = this.svgEl.dom.parentNode.innerHTML;
31047 var src = 'data:image/svg+xml;base64,'+window.btoa(svg);
31052 * @return {Boolean} this.isConfirmed
31054 getConfirmed : function(){
31055 return this.isConfirmed;
31059 * @return {Number} this.width
31061 getWidth : function(){
31066 * @return {Number} this.height
31068 getHeight : function(){
31069 return this.height;
31072 getSignature : function(){
31073 return this.signatureTmp;
31076 reset : function(){
31077 this.signatureTmp = '';
31078 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
31079 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', '');
31080 this.isConfirmed = false;
31081 Roo.form.Signature.superclass.reset.call(this);
31083 setSignature : function(s){
31084 this.signatureTmp = s;
31085 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
31086 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', s);
31088 this.isConfirmed = false;
31089 Roo.form.Signature.superclass.reset.call(this);
31092 // Roo.log(this.signPanel.dom.contentWindow.up())
31095 setConfirmed : function(){
31099 // Roo.log(Roo.get(this.signPanel.dom.contentWindow.r).attr('fill', '#cfc'));
31102 confirmHandler : function(){
31103 if(!this.getSignature()){
31107 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#cfc');
31108 this.setValue(this.getSignature());
31109 this.isConfirmed = true;
31111 this.fireEvent('confirm', this);
31114 // Subclasses should provide the validation implementation by overriding this
31115 validateValue : function(value){
31116 if(this.allowBlank){
31120 if(this.isConfirmed){
31127 * Ext JS Library 1.1.1
31128 * Copyright(c) 2006-2007, Ext JS, LLC.
31130 * Originally Released Under LGPL - original licence link has changed is not relivant.
31133 * <script type="text/javascript">
31138 * @class Roo.form.ComboBox
31139 * @extends Roo.form.TriggerField
31140 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
31142 * Create a new ComboBox.
31143 * @param {Object} config Configuration options
31145 Roo.form.Select = function(config){
31146 Roo.form.Select.superclass.constructor.call(this, config);
31150 Roo.extend(Roo.form.Select , Roo.form.ComboBox, {
31152 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
31155 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
31156 * rendering into an Roo.Editor, defaults to false)
31159 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
31160 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
31163 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
31166 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
31167 * the dropdown list (defaults to undefined, with no header element)
31171 * @cfg {String/Roo.Template} tpl The template to use to render the output
31175 defaultAutoCreate : {tag: "select" },
31177 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
31179 listWidth: undefined,
31181 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
31182 * mode = 'remote' or 'text' if mode = 'local')
31184 displayField: undefined,
31186 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
31187 * mode = 'remote' or 'value' if mode = 'local').
31188 * Note: use of a valueField requires the user make a selection
31189 * in order for a value to be mapped.
31191 valueField: undefined,
31195 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
31196 * field's data value (defaults to the underlying DOM element's name)
31198 hiddenName: undefined,
31200 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
31204 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
31206 selectedClass: 'x-combo-selected',
31208 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
31209 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
31210 * which displays a downward arrow icon).
31212 triggerClass : 'x-form-arrow-trigger',
31214 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
31218 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
31219 * anchor positions (defaults to 'tl-bl')
31221 listAlign: 'tl-bl?',
31223 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
31227 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
31228 * query specified by the allQuery config option (defaults to 'query')
31230 triggerAction: 'query',
31232 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
31233 * (defaults to 4, does not apply if editable = false)
31237 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
31238 * delay (typeAheadDelay) if it matches a known value (defaults to false)
31242 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
31243 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
31247 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
31248 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
31252 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
31253 * when editable = true (defaults to false)
31255 selectOnFocus:false,
31257 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
31259 queryParam: 'query',
31261 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
31262 * when mode = 'remote' (defaults to 'Loading...')
31264 loadingText: 'Loading...',
31266 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
31270 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
31274 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
31275 * traditional select (defaults to true)
31279 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
31283 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
31287 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
31288 * listWidth has a higher value)
31292 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
31293 * allow the user to set arbitrary text into the field (defaults to false)
31295 forceSelection:false,
31297 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
31298 * if typeAhead = true (defaults to 250)
31300 typeAheadDelay : 250,
31302 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
31303 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
31305 valueNotFoundText : undefined,
31308 * @cfg {String} defaultValue The value displayed after loading the store.
31313 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
31315 blockFocus : false,
31318 * @cfg {Boolean} disableClear Disable showing of clear button.
31320 disableClear : false,
31322 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
31324 alwaysQuery : false,
31330 // element that contains real text value.. (when hidden is used..)
31333 onRender : function(ct, position){
31334 Roo.form.Field.prototype.onRender.call(this, ct, position);
31337 this.store.on('beforeload', this.onBeforeLoad, this);
31338 this.store.on('load', this.onLoad, this);
31339 this.store.on('loadexception', this.onLoadException, this);
31340 this.store.load({});
31348 initEvents : function(){
31349 //Roo.form.ComboBox.superclass.initEvents.call(this);
31353 onDestroy : function(){
31356 this.store.un('beforeload', this.onBeforeLoad, this);
31357 this.store.un('load', this.onLoad, this);
31358 this.store.un('loadexception', this.onLoadException, this);
31360 //Roo.form.ComboBox.superclass.onDestroy.call(this);
31364 fireKey : function(e){
31365 if(e.isNavKeyPress() && !this.list.isVisible()){
31366 this.fireEvent("specialkey", this, e);
31371 onResize: function(w, h){
31379 * Allow or prevent the user from directly editing the field text. If false is passed,
31380 * the user will only be able to select from the items defined in the dropdown list. This method
31381 * is the runtime equivalent of setting the 'editable' config option at config time.
31382 * @param {Boolean} value True to allow the user to directly edit the field text
31384 setEditable : function(value){
31389 onBeforeLoad : function(){
31391 Roo.log("Select before load");
31394 this.innerList.update(this.loadingText ?
31395 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
31396 //this.restrictHeight();
31397 this.selectedIndex = -1;
31401 onLoad : function(){
31404 var dom = this.el.dom;
31405 dom.innerHTML = '';
31406 var od = dom.ownerDocument;
31408 if (this.emptyText) {
31409 var op = od.createElement('option');
31410 op.setAttribute('value', '');
31411 op.innerHTML = String.format('{0}', this.emptyText);
31412 dom.appendChild(op);
31414 if(this.store.getCount() > 0){
31416 var vf = this.valueField;
31417 var df = this.displayField;
31418 this.store.data.each(function(r) {
31419 // which colmsn to use... testing - cdoe / title..
31420 var op = od.createElement('option');
31421 op.setAttribute('value', r.data[vf]);
31422 op.innerHTML = String.format('{0}', r.data[df]);
31423 dom.appendChild(op);
31425 if (typeof(this.defaultValue != 'undefined')) {
31426 this.setValue(this.defaultValue);
31431 //this.onEmptyResults();
31436 onLoadException : function()
31438 dom.innerHTML = '';
31440 Roo.log("Select on load exception");
31444 Roo.log(this.store.reader.jsonData);
31445 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
31446 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
31452 onTypeAhead : function(){
31457 onSelect : function(record, index){
31458 Roo.log('on select?');
31460 if(this.fireEvent('beforeselect', this, record, index) !== false){
31461 this.setFromData(index > -1 ? record.data : false);
31463 this.fireEvent('select', this, record, index);
31468 * Returns the currently selected field value or empty string if no value is set.
31469 * @return {String} value The selected value
31471 getValue : function(){
31472 var dom = this.el.dom;
31473 this.value = dom.options[dom.selectedIndex].value;
31479 * Clears any text/value currently set in the field
31481 clearValue : function(){
31483 this.el.dom.selectedIndex = this.emptyText ? 0 : -1;
31488 * Sets the specified value into the field. If the value finds a match, the corresponding record text
31489 * will be displayed in the field. If the value does not match the data value of an existing item,
31490 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
31491 * Otherwise the field will be blank (although the value will still be set).
31492 * @param {String} value The value to match
31494 setValue : function(v){
31495 var d = this.el.dom;
31496 for (var i =0; i < d.options.length;i++) {
31497 if (v == d.options[i].value) {
31498 d.selectedIndex = i;
31506 * @property {Object} the last set data for the element
31511 * Sets the value of the field based on a object which is related to the record format for the store.
31512 * @param {Object} value the value to set as. or false on reset?
31514 setFromData : function(o){
31515 Roo.log('setfrom data?');
31521 reset : function(){
31525 findRecord : function(prop, value){
31530 if(this.store.getCount() > 0){
31531 this.store.each(function(r){
31532 if(r.data[prop] == value){
31542 getName: function()
31544 // returns hidden if it's set..
31545 if (!this.rendered) {return ''};
31546 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
31554 onEmptyResults : function(){
31555 Roo.log('empty results');
31560 * Returns true if the dropdown list is expanded, else false.
31562 isExpanded : function(){
31567 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
31568 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
31569 * @param {String} value The data value of the item to select
31570 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
31571 * selected item if it is not currently in view (defaults to true)
31572 * @return {Boolean} True if the value matched an item in the list, else false
31574 selectByValue : function(v, scrollIntoView){
31575 Roo.log('select By Value');
31578 if(v !== undefined && v !== null){
31579 var r = this.findRecord(this.valueField || this.displayField, v);
31581 this.select(this.store.indexOf(r), scrollIntoView);
31589 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
31590 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
31591 * @param {Number} index The zero-based index of the list item to select
31592 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
31593 * selected item if it is not currently in view (defaults to true)
31595 select : function(index, scrollIntoView){
31596 Roo.log('select ');
31599 this.selectedIndex = index;
31600 this.view.select(index);
31601 if(scrollIntoView !== false){
31602 var el = this.view.getNode(index);
31604 this.innerList.scrollChildIntoView(el, false);
31612 validateBlur : function(){
31619 initQuery : function(){
31620 this.doQuery(this.getRawValue());
31624 doForce : function(){
31625 if(this.el.dom.value.length > 0){
31626 this.el.dom.value =
31627 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
31633 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
31634 * query allowing the query action to be canceled if needed.
31635 * @param {String} query The SQL query to execute
31636 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
31637 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
31638 * saved in the current store (defaults to false)
31640 doQuery : function(q, forceAll){
31642 Roo.log('doQuery?');
31643 if(q === undefined || q === null){
31648 forceAll: forceAll,
31652 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
31656 forceAll = qe.forceAll;
31657 if(forceAll === true || (q.length >= this.minChars)){
31658 if(this.lastQuery != q || this.alwaysQuery){
31659 this.lastQuery = q;
31660 if(this.mode == 'local'){
31661 this.selectedIndex = -1;
31663 this.store.clearFilter();
31665 this.store.filter(this.displayField, q);
31669 this.store.baseParams[this.queryParam] = q;
31671 params: this.getParams(q)
31676 this.selectedIndex = -1;
31683 getParams : function(q){
31685 //p[this.queryParam] = q;
31688 p.limit = this.pageSize;
31694 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
31696 collapse : function(){
31701 collapseIf : function(e){
31706 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
31708 expand : function(){
31716 * @cfg {Boolean} grow
31720 * @cfg {Number} growMin
31724 * @cfg {Number} growMax
31732 setWidth : function()
31736 getResizeEl : function(){
31739 });//<script type="text/javasscript">
31743 * @class Roo.DDView
31744 * A DnD enabled version of Roo.View.
31745 * @param {Element/String} container The Element in which to create the View.
31746 * @param {String} tpl The template string used to create the markup for each element of the View
31747 * @param {Object} config The configuration properties. These include all the config options of
31748 * {@link Roo.View} plus some specific to this class.<br>
31750 * Drag/drop is implemented by adding {@link Roo.data.Record}s to the target DDView. If copying is
31751 * not being performed, the original {@link Roo.data.Record} is removed from the source DDView.<br>
31753 * The following extra CSS rules are needed to provide insertion point highlighting:<pre><code>
31754 .x-view-drag-insert-above {
31755 border-top:1px dotted #3366cc;
31757 .x-view-drag-insert-below {
31758 border-bottom:1px dotted #3366cc;
31764 Roo.DDView = function(container, tpl, config) {
31765 Roo.DDView.superclass.constructor.apply(this, arguments);
31766 this.getEl().setStyle("outline", "0px none");
31767 this.getEl().unselectable();
31768 if (this.dragGroup) {
31769 this.setDraggable(this.dragGroup.split(","));
31771 if (this.dropGroup) {
31772 this.setDroppable(this.dropGroup.split(","));
31774 if (this.deletable) {
31775 this.setDeletable();
31777 this.isDirtyFlag = false;
31783 Roo.extend(Roo.DDView, Roo.View, {
31784 /** @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone. */
31785 /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
31786 /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
31787 /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
31791 reset: Roo.emptyFn,
31793 clearInvalid: Roo.form.Field.prototype.clearInvalid,
31795 validate: function() {
31799 destroy: function() {
31800 this.purgeListeners();
31801 this.getEl.removeAllListeners();
31802 this.getEl().remove();
31803 if (this.dragZone) {
31804 if (this.dragZone.destroy) {
31805 this.dragZone.destroy();
31808 if (this.dropZone) {
31809 if (this.dropZone.destroy) {
31810 this.dropZone.destroy();
31815 /** Allows this class to be an Roo.form.Field so it can be found using {@link Roo.form.BasicForm#findField}. */
31816 getName: function() {
31820 /** Loads the View from a JSON string representing the Records to put into the Store. */
31821 setValue: function(v) {
31823 throw "DDView.setValue(). DDView must be constructed with a valid Store";
31826 data[this.store.reader.meta.root] = v ? [].concat(v) : [];
31827 this.store.proxy = new Roo.data.MemoryProxy(data);
31831 /** @return {String} a parenthesised list of the ids of the Records in the View. */
31832 getValue: function() {
31834 this.store.each(function(rec) {
31835 result += rec.id + ',';
31837 return result.substr(0, result.length - 1) + ')';
31840 getIds: function() {
31841 var i = 0, result = new Array(this.store.getCount());
31842 this.store.each(function(rec) {
31843 result[i++] = rec.id;
31848 isDirty: function() {
31849 return this.isDirtyFlag;
31853 * Part of the Roo.dd.DropZone interface. If no target node is found, the
31854 * whole Element becomes the target, and this causes the drop gesture to append.
31856 getTargetFromEvent : function(e) {
31857 var target = e.getTarget();
31858 while ((target !== null) && (target.parentNode != this.el.dom)) {
31859 target = target.parentNode;
31862 target = this.el.dom.lastChild || this.el.dom;
31868 * Create the drag data which consists of an object which has the property "ddel" as
31869 * the drag proxy element.
31871 getDragData : function(e) {
31872 var target = this.findItemFromChild(e.getTarget());
31874 this.handleSelection(e);
31875 var selNodes = this.getSelectedNodes();
31878 copy: this.copy || (this.allowCopy && e.ctrlKey),
31882 var selectedIndices = this.getSelectedIndexes();
31883 for (var i = 0; i < selectedIndices.length; i++) {
31884 dragData.records.push(this.store.getAt(selectedIndices[i]));
31886 if (selNodes.length == 1) {
31887 dragData.ddel = target.cloneNode(true); // the div element
31889 var div = document.createElement('div'); // create the multi element drag "ghost"
31890 div.className = 'multi-proxy';
31891 for (var i = 0, len = selNodes.length; i < len; i++) {
31892 div.appendChild(selNodes[i].cloneNode(true));
31894 dragData.ddel = div;
31896 //console.log(dragData)
31897 //console.log(dragData.ddel.innerHTML)
31900 //console.log('nodragData')
31904 /** Specify to which ddGroup items in this DDView may be dragged. */
31905 setDraggable: function(ddGroup) {
31906 if (ddGroup instanceof Array) {
31907 Roo.each(ddGroup, this.setDraggable, this);
31910 if (this.dragZone) {
31911 this.dragZone.addToGroup(ddGroup);
31913 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
31914 containerScroll: true,
31918 // Draggability implies selection. DragZone's mousedown selects the element.
31919 if (!this.multiSelect) { this.singleSelect = true; }
31921 // Wire the DragZone's handlers up to methods in *this*
31922 this.dragZone.getDragData = this.getDragData.createDelegate(this);
31926 /** Specify from which ddGroup this DDView accepts drops. */
31927 setDroppable: function(ddGroup) {
31928 if (ddGroup instanceof Array) {
31929 Roo.each(ddGroup, this.setDroppable, this);
31932 if (this.dropZone) {
31933 this.dropZone.addToGroup(ddGroup);
31935 this.dropZone = new Roo.dd.DropZone(this.getEl(), {
31936 containerScroll: true,
31940 // Wire the DropZone's handlers up to methods in *this*
31941 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
31942 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
31943 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
31944 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
31945 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
31949 /** Decide whether to drop above or below a View node. */
31950 getDropPoint : function(e, n, dd){
31951 if (n == this.el.dom) { return "above"; }
31952 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
31953 var c = t + (b - t) / 2;
31954 var y = Roo.lib.Event.getPageY(e);
31962 onNodeEnter : function(n, dd, e, data){
31966 onNodeOver : function(n, dd, e, data){
31967 var pt = this.getDropPoint(e, n, dd);
31968 // set the insert point style on the target node
31969 var dragElClass = this.dropNotAllowed;
31972 if (pt == "above"){
31973 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
31974 targetElClass = "x-view-drag-insert-above";
31976 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
31977 targetElClass = "x-view-drag-insert-below";
31979 if (this.lastInsertClass != targetElClass){
31980 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
31981 this.lastInsertClass = targetElClass;
31984 return dragElClass;
31987 onNodeOut : function(n, dd, e, data){
31988 this.removeDropIndicators(n);
31991 onNodeDrop : function(n, dd, e, data){
31992 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
31995 var pt = this.getDropPoint(e, n, dd);
31996 var insertAt = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
31997 if (pt == "below") { insertAt++; }
31998 for (var i = 0; i < data.records.length; i++) {
31999 var r = data.records[i];
32000 var dup = this.store.getById(r.id);
32001 if (dup && (dd != this.dragZone)) {
32002 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
32005 this.store.insert(insertAt++, r.copy());
32007 data.source.isDirtyFlag = true;
32009 this.store.insert(insertAt++, r);
32011 this.isDirtyFlag = true;
32014 this.dragZone.cachedTarget = null;
32018 removeDropIndicators : function(n){
32020 Roo.fly(n).removeClass([
32021 "x-view-drag-insert-above",
32022 "x-view-drag-insert-below"]);
32023 this.lastInsertClass = "_noclass";
32028 * Utility method. Add a delete option to the DDView's context menu.
32029 * @param {String} imageUrl The URL of the "delete" icon image.
32031 setDeletable: function(imageUrl) {
32032 if (!this.singleSelect && !this.multiSelect) {
32033 this.singleSelect = true;
32035 var c = this.getContextMenu();
32036 this.contextMenu.on("itemclick", function(item) {
32039 this.remove(this.getSelectedIndexes());
32043 this.contextMenu.add({
32050 /** Return the context menu for this DDView. */
32051 getContextMenu: function() {
32052 if (!this.contextMenu) {
32053 // Create the View's context menu
32054 this.contextMenu = new Roo.menu.Menu({
32055 id: this.id + "-contextmenu"
32057 this.el.on("contextmenu", this.showContextMenu, this);
32059 return this.contextMenu;
32062 disableContextMenu: function() {
32063 if (this.contextMenu) {
32064 this.el.un("contextmenu", this.showContextMenu, this);
32068 showContextMenu: function(e, item) {
32069 item = this.findItemFromChild(e.getTarget());
32072 this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true);
32073 this.contextMenu.showAt(e.getXY());
32078 * Remove {@link Roo.data.Record}s at the specified indices.
32079 * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove.
32081 remove: function(selectedIndices) {
32082 selectedIndices = [].concat(selectedIndices);
32083 for (var i = 0; i < selectedIndices.length; i++) {
32084 var rec = this.store.getAt(selectedIndices[i]);
32085 this.store.remove(rec);
32090 * Double click fires the event, but also, if this is draggable, and there is only one other
32091 * related DropZone, it transfers the selected node.
32093 onDblClick : function(e){
32094 var item = this.findItemFromChild(e.getTarget());
32096 if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) {
32099 if (this.dragGroup) {
32100 var targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
32101 while (targets.indexOf(this.dropZone) > -1) {
32102 targets.remove(this.dropZone);
32104 if (targets.length == 1) {
32105 this.dragZone.cachedTarget = null;
32106 var el = Roo.get(targets[0].getEl());
32107 var box = el.getBox(true);
32108 targets[0].onNodeDrop(el.dom, {
32110 xy: [box.x, box.y + box.height - 1]
32111 }, null, this.getDragData(e));
32117 handleSelection: function(e) {
32118 this.dragZone.cachedTarget = null;
32119 var item = this.findItemFromChild(e.getTarget());
32121 this.clearSelections(true);
32124 if (item && (this.multiSelect || this.singleSelect)){
32125 if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
32126 this.select(this.getNodes(this.indexOf(this.lastSelection), item.nodeIndex), false);
32127 }else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
32128 this.unselect(item);
32130 this.select(item, this.multiSelect && e.ctrlKey);
32131 this.lastSelection = item;
32136 onItemClick : function(item, index, e){
32137 if(this.fireEvent("beforeclick", this, index, item, e) === false){
32143 unselect : function(nodeInfo, suppressEvent){
32144 var node = this.getNode(nodeInfo);
32145 if(node && this.isSelected(node)){
32146 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
32147 Roo.fly(node).removeClass(this.selectedClass);
32148 this.selections.remove(node);
32149 if(!suppressEvent){
32150 this.fireEvent("selectionchange", this, this.selections);
32158 * Ext JS Library 1.1.1
32159 * Copyright(c) 2006-2007, Ext JS, LLC.
32161 * Originally Released Under LGPL - original licence link has changed is not relivant.
32164 * <script type="text/javascript">
32168 * @class Roo.LayoutManager
32169 * @extends Roo.util.Observable
32170 * Base class for layout managers.
32172 Roo.LayoutManager = function(container, config){
32173 Roo.LayoutManager.superclass.constructor.call(this);
32174 this.el = Roo.get(container);
32175 // ie scrollbar fix
32176 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
32177 document.body.scroll = "no";
32178 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
32179 this.el.position('relative');
32181 this.id = this.el.id;
32182 this.el.addClass("x-layout-container");
32183 /** false to disable window resize monitoring @type Boolean */
32184 this.monitorWindowResize = true;
32189 * Fires when a layout is performed.
32190 * @param {Roo.LayoutManager} this
32194 * @event regionresized
32195 * Fires when the user resizes a region.
32196 * @param {Roo.LayoutRegion} region The resized region
32197 * @param {Number} newSize The new size (width for east/west, height for north/south)
32199 "regionresized" : true,
32201 * @event regioncollapsed
32202 * Fires when a region is collapsed.
32203 * @param {Roo.LayoutRegion} region The collapsed region
32205 "regioncollapsed" : true,
32207 * @event regionexpanded
32208 * Fires when a region is expanded.
32209 * @param {Roo.LayoutRegion} region The expanded region
32211 "regionexpanded" : true
32213 this.updating = false;
32214 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
32217 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
32219 * Returns true if this layout is currently being updated
32220 * @return {Boolean}
32222 isUpdating : function(){
32223 return this.updating;
32227 * Suspend the LayoutManager from doing auto-layouts while
32228 * making multiple add or remove calls
32230 beginUpdate : function(){
32231 this.updating = true;
32235 * Restore auto-layouts and optionally disable the manager from performing a layout
32236 * @param {Boolean} noLayout true to disable a layout update
32238 endUpdate : function(noLayout){
32239 this.updating = false;
32245 layout: function(){
32249 onRegionResized : function(region, newSize){
32250 this.fireEvent("regionresized", region, newSize);
32254 onRegionCollapsed : function(region){
32255 this.fireEvent("regioncollapsed", region);
32258 onRegionExpanded : function(region){
32259 this.fireEvent("regionexpanded", region);
32263 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
32264 * performs box-model adjustments.
32265 * @return {Object} The size as an object {width: (the width), height: (the height)}
32267 getViewSize : function(){
32269 if(this.el.dom != document.body){
32270 size = this.el.getSize();
32272 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
32274 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
32275 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
32280 * Returns the Element this layout is bound to.
32281 * @return {Roo.Element}
32283 getEl : function(){
32288 * Returns the specified region.
32289 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
32290 * @return {Roo.LayoutRegion}
32292 getRegion : function(target){
32293 return this.regions[target.toLowerCase()];
32296 onWindowResize : function(){
32297 if(this.monitorWindowResize){
32303 * Ext JS Library 1.1.1
32304 * Copyright(c) 2006-2007, Ext JS, LLC.
32306 * Originally Released Under LGPL - original licence link has changed is not relivant.
32309 * <script type="text/javascript">
32312 * @class Roo.BorderLayout
32313 * @extends Roo.LayoutManager
32314 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
32315 * please see: <br><br>
32316 * <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>
32317 * <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>
32320 var layout = new Roo.BorderLayout(document.body, {
32354 preferredTabWidth: 150
32359 var CP = Roo.ContentPanel;
32361 layout.beginUpdate();
32362 layout.add("north", new CP("north", "North"));
32363 layout.add("south", new CP("south", {title: "South", closable: true}));
32364 layout.add("west", new CP("west", {title: "West"}));
32365 layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
32366 layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
32367 layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
32368 layout.getRegion("center").showPanel("center1");
32369 layout.endUpdate();
32372 <b>The container the layout is rendered into can be either the body element or any other element.
32373 If it is not the body element, the container needs to either be an absolute positioned element,
32374 or you will need to add "position:relative" to the css of the container. You will also need to specify
32375 the container size if it is not the body element.</b>
32378 * Create a new BorderLayout
32379 * @param {String/HTMLElement/Element} container The container this layout is bound to
32380 * @param {Object} config Configuration options
32382 Roo.BorderLayout = function(container, config){
32383 config = config || {};
32384 Roo.BorderLayout.superclass.constructor.call(this, container, config);
32385 this.factory = config.factory || Roo.BorderLayout.RegionFactory;
32386 for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
32387 var target = this.factory.validRegions[i];
32388 if(config[target]){
32389 this.addRegion(target, config[target]);
32394 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
32396 * Creates and adds a new region if it doesn't already exist.
32397 * @param {String} target The target region key (north, south, east, west or center).
32398 * @param {Object} config The regions config object
32399 * @return {BorderLayoutRegion} The new region
32401 addRegion : function(target, config){
32402 if(!this.regions[target]){
32403 var r = this.factory.create(target, this, config);
32404 this.bindRegion(target, r);
32406 return this.regions[target];
32410 bindRegion : function(name, r){
32411 this.regions[name] = r;
32412 r.on("visibilitychange", this.layout, this);
32413 r.on("paneladded", this.layout, this);
32414 r.on("panelremoved", this.layout, this);
32415 r.on("invalidated", this.layout, this);
32416 r.on("resized", this.onRegionResized, this);
32417 r.on("collapsed", this.onRegionCollapsed, this);
32418 r.on("expanded", this.onRegionExpanded, this);
32422 * Performs a layout update.
32424 layout : function(){
32425 if(this.updating) return;
32426 var size = this.getViewSize();
32427 var w = size.width;
32428 var h = size.height;
32433 //var x = 0, y = 0;
32435 var rs = this.regions;
32436 var north = rs["north"];
32437 var south = rs["south"];
32438 var west = rs["west"];
32439 var east = rs["east"];
32440 var center = rs["center"];
32441 //if(this.hideOnLayout){ // not supported anymore
32442 //c.el.setStyle("display", "none");
32444 if(north && north.isVisible()){
32445 var b = north.getBox();
32446 var m = north.getMargins();
32447 b.width = w - (m.left+m.right);
32450 centerY = b.height + b.y + m.bottom;
32451 centerH -= centerY;
32452 north.updateBox(this.safeBox(b));
32454 if(south && south.isVisible()){
32455 var b = south.getBox();
32456 var m = south.getMargins();
32457 b.width = w - (m.left+m.right);
32459 var totalHeight = (b.height + m.top + m.bottom);
32460 b.y = h - totalHeight + m.top;
32461 centerH -= totalHeight;
32462 south.updateBox(this.safeBox(b));
32464 if(west && west.isVisible()){
32465 var b = west.getBox();
32466 var m = west.getMargins();
32467 b.height = centerH - (m.top+m.bottom);
32469 b.y = centerY + m.top;
32470 var totalWidth = (b.width + m.left + m.right);
32471 centerX += totalWidth;
32472 centerW -= totalWidth;
32473 west.updateBox(this.safeBox(b));
32475 if(east && east.isVisible()){
32476 var b = east.getBox();
32477 var m = east.getMargins();
32478 b.height = centerH - (m.top+m.bottom);
32479 var totalWidth = (b.width + m.left + m.right);
32480 b.x = w - totalWidth + m.left;
32481 b.y = centerY + m.top;
32482 centerW -= totalWidth;
32483 east.updateBox(this.safeBox(b));
32486 var m = center.getMargins();
32488 x: centerX + m.left,
32489 y: centerY + m.top,
32490 width: centerW - (m.left+m.right),
32491 height: centerH - (m.top+m.bottom)
32493 //if(this.hideOnLayout){
32494 //center.el.setStyle("display", "block");
32496 center.updateBox(this.safeBox(centerBox));
32499 this.fireEvent("layout", this);
32503 safeBox : function(box){
32504 box.width = Math.max(0, box.width);
32505 box.height = Math.max(0, box.height);
32510 * Adds a ContentPanel (or subclass) to this layout.
32511 * @param {String} target The target region key (north, south, east, west or center).
32512 * @param {Roo.ContentPanel} panel The panel to add
32513 * @return {Roo.ContentPanel} The added panel
32515 add : function(target, panel){
32517 target = target.toLowerCase();
32518 return this.regions[target].add(panel);
32522 * Remove a ContentPanel (or subclass) to this layout.
32523 * @param {String} target The target region key (north, south, east, west or center).
32524 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
32525 * @return {Roo.ContentPanel} The removed panel
32527 remove : function(target, panel){
32528 target = target.toLowerCase();
32529 return this.regions[target].remove(panel);
32533 * Searches all regions for a panel with the specified id
32534 * @param {String} panelId
32535 * @return {Roo.ContentPanel} The panel or null if it wasn't found
32537 findPanel : function(panelId){
32538 var rs = this.regions;
32539 for(var target in rs){
32540 if(typeof rs[target] != "function"){
32541 var p = rs[target].getPanel(panelId);
32551 * Searches all regions for a panel with the specified id and activates (shows) it.
32552 * @param {String/ContentPanel} panelId The panels id or the panel itself
32553 * @return {Roo.ContentPanel} The shown panel or null
32555 showPanel : function(panelId) {
32556 var rs = this.regions;
32557 for(var target in rs){
32558 var r = rs[target];
32559 if(typeof r != "function"){
32560 if(r.hasPanel(panelId)){
32561 return r.showPanel(panelId);
32569 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
32570 * @param {Roo.state.Provider} provider (optional) An alternate state provider
32572 restoreState : function(provider){
32574 provider = Roo.state.Manager;
32576 var sm = new Roo.LayoutStateManager();
32577 sm.init(this, provider);
32581 * Adds a batch of multiple ContentPanels dynamically by passing a special regions config object. This config
32582 * object should contain properties for each region to add ContentPanels to, and each property's value should be
32583 * a valid ContentPanel config object. Example:
32585 // Create the main layout
32586 var layout = new Roo.BorderLayout('main-ct', {
32597 // Create and add multiple ContentPanels at once via configs
32600 id: 'source-files',
32602 title:'Ext Source Files',
32615 * @param {Object} regions An object containing ContentPanel configs by region name
32617 batchAdd : function(regions){
32618 this.beginUpdate();
32619 for(var rname in regions){
32620 var lr = this.regions[rname];
32622 this.addTypedPanels(lr, regions[rname]);
32629 addTypedPanels : function(lr, ps){
32630 if(typeof ps == 'string'){
32631 lr.add(new Roo.ContentPanel(ps));
32633 else if(ps instanceof Array){
32634 for(var i =0, len = ps.length; i < len; i++){
32635 this.addTypedPanels(lr, ps[i]);
32638 else if(!ps.events){ // raw config?
32640 delete ps.el; // prevent conflict
32641 lr.add(new Roo.ContentPanel(el || Roo.id(), ps));
32643 else { // panel object assumed!
32648 * Adds a xtype elements to the layout.
32652 xtype : 'ContentPanel',
32659 xtype : 'NestedLayoutPanel',
32665 items : [ ... list of content panels or nested layout panels.. ]
32669 * @param {Object} cfg Xtype definition of item to add.
32671 addxtype : function(cfg)
32673 // basically accepts a pannel...
32674 // can accept a layout region..!?!?
32675 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
32677 if (!cfg.xtype.match(/Panel$/)) {
32682 if (typeof(cfg.region) == 'undefined') {
32683 Roo.log("Failed to add Panel, region was not set");
32687 var region = cfg.region;
32693 xitems = cfg.items;
32700 case 'ContentPanel': // ContentPanel (el, cfg)
32701 case 'ScrollPanel': // ContentPanel (el, cfg)
32703 if(cfg.autoCreate) {
32704 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
32706 var el = this.el.createChild();
32707 ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
32710 this.add(region, ret);
32714 case 'TreePanel': // our new panel!
32715 cfg.el = this.el.createChild();
32716 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
32717 this.add(region, ret);
32720 case 'NestedLayoutPanel':
32721 // create a new Layout (which is a Border Layout...
32722 var el = this.el.createChild();
32723 var clayout = cfg.layout;
32725 clayout.items = clayout.items || [];
32726 // replace this exitems with the clayout ones..
32727 xitems = clayout.items;
32730 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
32731 cfg.background = false;
32733 var layout = new Roo.BorderLayout(el, clayout);
32735 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
32736 //console.log('adding nested layout panel ' + cfg.toSource());
32737 this.add(region, ret);
32738 nb = {}; /// find first...
32743 // needs grid and region
32745 //var el = this.getRegion(region).el.createChild();
32746 var el = this.el.createChild();
32747 // create the grid first...
32749 var grid = new Roo.grid[cfg.grid.xtype](el, cfg.grid);
32751 if (region == 'center' && this.active ) {
32752 cfg.background = false;
32754 ret = new Roo[cfg.xtype](grid, cfg); // new panel!!!!!
32756 this.add(region, ret);
32757 if (cfg.background) {
32758 ret.on('activate', function(gp) {
32759 if (!gp.grid.rendered) {
32774 alert("Can not add '" + cfg.xtype + "' to BorderLayout");
32776 // GridPanel (grid, cfg)
32779 this.beginUpdate();
32783 Roo.each(xitems, function(i) {
32784 region = nb && i.region ? i.region : false;
32786 var add = ret.addxtype(i);
32789 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
32790 if (!i.background) {
32791 abn[region] = nb[region] ;
32798 // make the last non-background panel active..
32799 //if (nb) { Roo.log(abn); }
32802 for(var r in abn) {
32803 region = this.getRegion(r);
32805 // tried using nb[r], but it does not work..
32807 region.showPanel(abn[r]);
32818 * Shortcut for creating a new BorderLayout object and adding one or more ContentPanels to it in a single step, handling
32819 * the beginUpdate and endUpdate calls internally. The key to this method is the <b>panels</b> property that can be
32820 * provided with each region config, which allows you to add ContentPanel configs in addition to the region configs
32821 * during creation. The following code is equivalent to the constructor-based example at the beginning of this class:
32824 var CP = Roo.ContentPanel;
32826 var layout = Roo.BorderLayout.create({
32830 panels: [new CP("north", "North")]
32839 panels: [new CP("west", {title: "West"})]
32848 panels: [new CP("autoTabs", {title: "Auto Tabs", closable: true})]
32857 panels: [new CP("south", {title: "South", closable: true})]
32864 preferredTabWidth: 150,
32866 new CP("center1", {title: "Close Me", closable: true}),
32867 new CP("center2", {title: "Center Panel", closable: false})
32872 layout.getRegion("center").showPanel("center1");
32877 Roo.BorderLayout.create = function(config, targetEl){
32878 var layout = new Roo.BorderLayout(targetEl || document.body, config);
32879 layout.beginUpdate();
32880 var regions = Roo.BorderLayout.RegionFactory.validRegions;
32881 for(var j = 0, jlen = regions.length; j < jlen; j++){
32882 var lr = regions[j];
32883 if(layout.regions[lr] && config[lr].panels){
32884 var r = layout.regions[lr];
32885 var ps = config[lr].panels;
32886 layout.addTypedPanels(r, ps);
32889 layout.endUpdate();
32894 Roo.BorderLayout.RegionFactory = {
32896 validRegions : ["north","south","east","west","center"],
32899 create : function(target, mgr, config){
32900 target = target.toLowerCase();
32901 if(config.lightweight || config.basic){
32902 return new Roo.BasicLayoutRegion(mgr, config, target);
32906 return new Roo.NorthLayoutRegion(mgr, config);
32908 return new Roo.SouthLayoutRegion(mgr, config);
32910 return new Roo.EastLayoutRegion(mgr, config);
32912 return new Roo.WestLayoutRegion(mgr, config);
32914 return new Roo.CenterLayoutRegion(mgr, config);
32916 throw 'Layout region "'+target+'" not supported.';
32920 * Ext JS Library 1.1.1
32921 * Copyright(c) 2006-2007, Ext JS, LLC.
32923 * Originally Released Under LGPL - original licence link has changed is not relivant.
32926 * <script type="text/javascript">
32930 * @class Roo.BasicLayoutRegion
32931 * @extends Roo.util.Observable
32932 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
32933 * and does not have a titlebar, tabs or any other features. All it does is size and position
32934 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
32936 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
32938 this.position = pos;
32941 * @scope Roo.BasicLayoutRegion
32945 * @event beforeremove
32946 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
32947 * @param {Roo.LayoutRegion} this
32948 * @param {Roo.ContentPanel} panel The panel
32949 * @param {Object} e The cancel event object
32951 "beforeremove" : true,
32953 * @event invalidated
32954 * Fires when the layout for this region is changed.
32955 * @param {Roo.LayoutRegion} this
32957 "invalidated" : true,
32959 * @event visibilitychange
32960 * Fires when this region is shown or hidden
32961 * @param {Roo.LayoutRegion} this
32962 * @param {Boolean} visibility true or false
32964 "visibilitychange" : true,
32966 * @event paneladded
32967 * Fires when a panel is added.
32968 * @param {Roo.LayoutRegion} this
32969 * @param {Roo.ContentPanel} panel The panel
32971 "paneladded" : true,
32973 * @event panelremoved
32974 * Fires when a panel is removed.
32975 * @param {Roo.LayoutRegion} this
32976 * @param {Roo.ContentPanel} panel The panel
32978 "panelremoved" : true,
32981 * Fires when this region is collapsed.
32982 * @param {Roo.LayoutRegion} this
32984 "collapsed" : true,
32987 * Fires when this region is expanded.
32988 * @param {Roo.LayoutRegion} this
32993 * Fires when this region is slid into view.
32994 * @param {Roo.LayoutRegion} this
32996 "slideshow" : true,
32999 * Fires when this region slides out of view.
33000 * @param {Roo.LayoutRegion} this
33002 "slidehide" : true,
33004 * @event panelactivated
33005 * Fires when a panel is activated.
33006 * @param {Roo.LayoutRegion} this
33007 * @param {Roo.ContentPanel} panel The activated panel
33009 "panelactivated" : true,
33012 * Fires when the user resizes this region.
33013 * @param {Roo.LayoutRegion} this
33014 * @param {Number} newSize The new size (width for east/west, height for north/south)
33018 /** A collection of panels in this region. @type Roo.util.MixedCollection */
33019 this.panels = new Roo.util.MixedCollection();
33020 this.panels.getKey = this.getPanelId.createDelegate(this);
33022 this.activePanel = null;
33023 // ensure listeners are added...
33025 if (config.listeners || config.events) {
33026 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
33027 listeners : config.listeners || {},
33028 events : config.events || {}
33032 if(skipConfig !== true){
33033 this.applyConfig(config);
33037 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
33038 getPanelId : function(p){
33042 applyConfig : function(config){
33043 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
33044 this.config = config;
33049 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
33050 * the width, for horizontal (north, south) the height.
33051 * @param {Number} newSize The new width or height
33053 resizeTo : function(newSize){
33054 var el = this.el ? this.el :
33055 (this.activePanel ? this.activePanel.getEl() : null);
33057 switch(this.position){
33060 el.setWidth(newSize);
33061 this.fireEvent("resized", this, newSize);
33065 el.setHeight(newSize);
33066 this.fireEvent("resized", this, newSize);
33072 getBox : function(){
33073 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
33076 getMargins : function(){
33077 return this.margins;
33080 updateBox : function(box){
33082 var el = this.activePanel.getEl();
33083 el.dom.style.left = box.x + "px";
33084 el.dom.style.top = box.y + "px";
33085 this.activePanel.setSize(box.width, box.height);
33089 * Returns the container element for this region.
33090 * @return {Roo.Element}
33092 getEl : function(){
33093 return this.activePanel;
33097 * Returns true if this region is currently visible.
33098 * @return {Boolean}
33100 isVisible : function(){
33101 return this.activePanel ? true : false;
33104 setActivePanel : function(panel){
33105 panel = this.getPanel(panel);
33106 if(this.activePanel && this.activePanel != panel){
33107 this.activePanel.setActiveState(false);
33108 this.activePanel.getEl().setLeftTop(-10000,-10000);
33110 this.activePanel = panel;
33111 panel.setActiveState(true);
33113 panel.setSize(this.box.width, this.box.height);
33115 this.fireEvent("panelactivated", this, panel);
33116 this.fireEvent("invalidated");
33120 * Show the specified panel.
33121 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
33122 * @return {Roo.ContentPanel} The shown panel or null
33124 showPanel : function(panel){
33125 if(panel = this.getPanel(panel)){
33126 this.setActivePanel(panel);
33132 * Get the active panel for this region.
33133 * @return {Roo.ContentPanel} The active panel or null
33135 getActivePanel : function(){
33136 return this.activePanel;
33140 * Add the passed ContentPanel(s)
33141 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
33142 * @return {Roo.ContentPanel} The panel added (if only one was added)
33144 add : function(panel){
33145 if(arguments.length > 1){
33146 for(var i = 0, len = arguments.length; i < len; i++) {
33147 this.add(arguments[i]);
33151 if(this.hasPanel(panel)){
33152 this.showPanel(panel);
33155 var el = panel.getEl();
33156 if(el.dom.parentNode != this.mgr.el.dom){
33157 this.mgr.el.dom.appendChild(el.dom);
33159 if(panel.setRegion){
33160 panel.setRegion(this);
33162 this.panels.add(panel);
33163 el.setStyle("position", "absolute");
33164 if(!panel.background){
33165 this.setActivePanel(panel);
33166 if(this.config.initialSize && this.panels.getCount()==1){
33167 this.resizeTo(this.config.initialSize);
33170 this.fireEvent("paneladded", this, panel);
33175 * Returns true if the panel is in this region.
33176 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
33177 * @return {Boolean}
33179 hasPanel : function(panel){
33180 if(typeof panel == "object"){ // must be panel obj
33181 panel = panel.getId();
33183 return this.getPanel(panel) ? true : false;
33187 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
33188 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
33189 * @param {Boolean} preservePanel Overrides the config preservePanel option
33190 * @return {Roo.ContentPanel} The panel that was removed
33192 remove : function(panel, preservePanel){
33193 panel = this.getPanel(panel);
33198 this.fireEvent("beforeremove", this, panel, e);
33199 if(e.cancel === true){
33202 var panelId = panel.getId();
33203 this.panels.removeKey(panelId);
33208 * Returns the panel specified or null if it's not in this region.
33209 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
33210 * @return {Roo.ContentPanel}
33212 getPanel : function(id){
33213 if(typeof id == "object"){ // must be panel obj
33216 return this.panels.get(id);
33220 * Returns this regions position (north/south/east/west/center).
33223 getPosition: function(){
33224 return this.position;
33228 * Ext JS Library 1.1.1
33229 * Copyright(c) 2006-2007, Ext JS, LLC.
33231 * Originally Released Under LGPL - original licence link has changed is not relivant.
33234 * <script type="text/javascript">
33238 * @class Roo.LayoutRegion
33239 * @extends Roo.BasicLayoutRegion
33240 * This class represents a region in a layout manager.
33241 * @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
33242 * @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
33243 * @cfg {Boolean} floatable False to disable floating (defaults to true)
33244 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
33245 * @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})
33246 * @cfg {String} tabPosition "top" or "bottom" (defaults to "bottom")
33247 * @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
33248 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
33249 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
33250 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
33251 * @cfg {String} title The title for the region (overrides panel titles)
33252 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
33253 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
33254 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
33255 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
33256 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
33257 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
33258 * the space available, similar to FireFox 1.5 tabs (defaults to false)
33259 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
33260 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
33261 * @cfg {Boolean} showPin True to show a pin button
33262 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
33263 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
33264 * @cfg {Boolean} disableTabTips True to disable tab tooltips
33265 * @cfg {Number} width For East/West panels
33266 * @cfg {Number} height For North/South panels
33267 * @cfg {Boolean} split To show the splitter
33268 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
33270 Roo.LayoutRegion = function(mgr, config, pos){
33271 Roo.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
33272 var dh = Roo.DomHelper;
33273 /** This region's container element
33274 * @type Roo.Element */
33275 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
33276 /** This region's title element
33277 * @type Roo.Element */
33279 this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
33280 {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
33281 {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
33283 this.titleEl.enableDisplayMode();
33284 /** This region's title text element
33285 * @type HTMLElement */
33286 this.titleTextEl = this.titleEl.dom.firstChild;
33287 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
33288 this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
33289 this.closeBtn.enableDisplayMode();
33290 this.closeBtn.on("click", this.closeClicked, this);
33291 this.closeBtn.hide();
33293 this.createBody(config);
33294 this.visible = true;
33295 this.collapsed = false;
33297 if(config.hideWhenEmpty){
33299 this.on("paneladded", this.validateVisibility, this);
33300 this.on("panelremoved", this.validateVisibility, this);
33302 this.applyConfig(config);
33305 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
33307 createBody : function(){
33308 /** This region's body element
33309 * @type Roo.Element */
33310 this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
33313 applyConfig : function(c){
33314 if(c.collapsible && this.position != "center" && !this.collapsedEl){
33315 var dh = Roo.DomHelper;
33316 if(c.titlebar !== false){
33317 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
33318 this.collapseBtn.on("click", this.collapse, this);
33319 this.collapseBtn.enableDisplayMode();
33321 if(c.showPin === true || this.showPin){
33322 this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
33323 this.stickBtn.enableDisplayMode();
33324 this.stickBtn.on("click", this.expand, this);
33325 this.stickBtn.hide();
33328 /** This region's collapsed element
33329 * @type Roo.Element */
33330 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
33331 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
33333 if(c.floatable !== false){
33334 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
33335 this.collapsedEl.on("click", this.collapseClick, this);
33338 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
33339 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
33340 id: "message", unselectable: "on", style:{"float":"left"}});
33341 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
33343 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
33344 this.expandBtn.on("click", this.expand, this);
33346 if(this.collapseBtn){
33347 this.collapseBtn.setVisible(c.collapsible == true);
33349 this.cmargins = c.cmargins || this.cmargins ||
33350 (this.position == "west" || this.position == "east" ?
33351 {top: 0, left: 2, right:2, bottom: 0} :
33352 {top: 2, left: 0, right:0, bottom: 2});
33353 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
33354 this.bottomTabs = c.tabPosition != "top";
33355 this.autoScroll = c.autoScroll || false;
33356 if(this.autoScroll){
33357 this.bodyEl.setStyle("overflow", "auto");
33359 this.bodyEl.setStyle("overflow", "hidden");
33361 //if(c.titlebar !== false){
33362 if((!c.titlebar && !c.title) || c.titlebar === false){
33363 this.titleEl.hide();
33365 this.titleEl.show();
33367 this.titleTextEl.innerHTML = c.title;
33371 this.duration = c.duration || .30;
33372 this.slideDuration = c.slideDuration || .45;
33375 this.collapse(true);
33382 * Returns true if this region is currently visible.
33383 * @return {Boolean}
33385 isVisible : function(){
33386 return this.visible;
33390 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
33391 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
33393 setCollapsedTitle : function(title){
33394 title = title || " ";
33395 if(this.collapsedTitleTextEl){
33396 this.collapsedTitleTextEl.innerHTML = title;
33400 getBox : function(){
33402 if(!this.collapsed){
33403 b = this.el.getBox(false, true);
33405 b = this.collapsedEl.getBox(false, true);
33410 getMargins : function(){
33411 return this.collapsed ? this.cmargins : this.margins;
33414 highlight : function(){
33415 this.el.addClass("x-layout-panel-dragover");
33418 unhighlight : function(){
33419 this.el.removeClass("x-layout-panel-dragover");
33422 updateBox : function(box){
33424 if(!this.collapsed){
33425 this.el.dom.style.left = box.x + "px";
33426 this.el.dom.style.top = box.y + "px";
33427 this.updateBody(box.width, box.height);
33429 this.collapsedEl.dom.style.left = box.x + "px";
33430 this.collapsedEl.dom.style.top = box.y + "px";
33431 this.collapsedEl.setSize(box.width, box.height);
33434 this.tabs.autoSizeTabs();
33438 updateBody : function(w, h){
33440 this.el.setWidth(w);
33441 w -= this.el.getBorderWidth("rl");
33442 if(this.config.adjustments){
33443 w += this.config.adjustments[0];
33447 this.el.setHeight(h);
33448 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
33449 h -= this.el.getBorderWidth("tb");
33450 if(this.config.adjustments){
33451 h += this.config.adjustments[1];
33453 this.bodyEl.setHeight(h);
33455 h = this.tabs.syncHeight(h);
33458 if(this.panelSize){
33459 w = w !== null ? w : this.panelSize.width;
33460 h = h !== null ? h : this.panelSize.height;
33462 if(this.activePanel){
33463 var el = this.activePanel.getEl();
33464 w = w !== null ? w : el.getWidth();
33465 h = h !== null ? h : el.getHeight();
33466 this.panelSize = {width: w, height: h};
33467 this.activePanel.setSize(w, h);
33469 if(Roo.isIE && this.tabs){
33470 this.tabs.el.repaint();
33475 * Returns the container element for this region.
33476 * @return {Roo.Element}
33478 getEl : function(){
33483 * Hides this region.
33486 if(!this.collapsed){
33487 this.el.dom.style.left = "-2000px";
33490 this.collapsedEl.dom.style.left = "-2000px";
33491 this.collapsedEl.hide();
33493 this.visible = false;
33494 this.fireEvent("visibilitychange", this, false);
33498 * Shows this region if it was previously hidden.
33501 if(!this.collapsed){
33504 this.collapsedEl.show();
33506 this.visible = true;
33507 this.fireEvent("visibilitychange", this, true);
33510 closeClicked : function(){
33511 if(this.activePanel){
33512 this.remove(this.activePanel);
33516 collapseClick : function(e){
33518 e.stopPropagation();
33521 e.stopPropagation();
33527 * Collapses this region.
33528 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
33530 collapse : function(skipAnim){
33531 if(this.collapsed) return;
33532 this.collapsed = true;
33534 this.split.el.hide();
33536 if(this.config.animate && skipAnim !== true){
33537 this.fireEvent("invalidated", this);
33538 this.animateCollapse();
33540 this.el.setLocation(-20000,-20000);
33542 this.collapsedEl.show();
33543 this.fireEvent("collapsed", this);
33544 this.fireEvent("invalidated", this);
33548 animateCollapse : function(){
33553 * Expands this region if it was previously collapsed.
33554 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
33555 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
33557 expand : function(e, skipAnim){
33558 if(e) e.stopPropagation();
33559 if(!this.collapsed || this.el.hasActiveFx()) return;
33561 this.afterSlideIn();
33564 this.collapsed = false;
33565 if(this.config.animate && skipAnim !== true){
33566 this.animateExpand();
33570 this.split.el.show();
33572 this.collapsedEl.setLocation(-2000,-2000);
33573 this.collapsedEl.hide();
33574 this.fireEvent("invalidated", this);
33575 this.fireEvent("expanded", this);
33579 animateExpand : function(){
33583 initTabs : function()
33585 this.bodyEl.setStyle("overflow", "hidden");
33586 var ts = new Roo.TabPanel(
33589 tabPosition: this.bottomTabs ? 'bottom' : 'top',
33590 disableTooltips: this.config.disableTabTips,
33591 toolbar : this.config.toolbar
33594 if(this.config.hideTabs){
33595 ts.stripWrap.setDisplayed(false);
33598 ts.resizeTabs = this.config.resizeTabs === true;
33599 ts.minTabWidth = this.config.minTabWidth || 40;
33600 ts.maxTabWidth = this.config.maxTabWidth || 250;
33601 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
33602 ts.monitorResize = false;
33603 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
33604 ts.bodyEl.addClass('x-layout-tabs-body');
33605 this.panels.each(this.initPanelAsTab, this);
33608 initPanelAsTab : function(panel){
33609 var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
33610 this.config.closeOnTab && panel.isClosable());
33611 if(panel.tabTip !== undefined){
33612 ti.setTooltip(panel.tabTip);
33614 ti.on("activate", function(){
33615 this.setActivePanel(panel);
33617 if(this.config.closeOnTab){
33618 ti.on("beforeclose", function(t, e){
33620 this.remove(panel);
33626 updatePanelTitle : function(panel, title){
33627 if(this.activePanel == panel){
33628 this.updateTitle(title);
33631 var ti = this.tabs.getTab(panel.getEl().id);
33633 if(panel.tabTip !== undefined){
33634 ti.setTooltip(panel.tabTip);
33639 updateTitle : function(title){
33640 if(this.titleTextEl && !this.config.title){
33641 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
33645 setActivePanel : function(panel){
33646 panel = this.getPanel(panel);
33647 if(this.activePanel && this.activePanel != panel){
33648 this.activePanel.setActiveState(false);
33650 this.activePanel = panel;
33651 panel.setActiveState(true);
33652 if(this.panelSize){
33653 panel.setSize(this.panelSize.width, this.panelSize.height);
33656 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
33658 this.updateTitle(panel.getTitle());
33660 this.fireEvent("invalidated", this);
33662 this.fireEvent("panelactivated", this, panel);
33666 * Shows the specified panel.
33667 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
33668 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
33670 showPanel : function(panel){
33671 if(panel = this.getPanel(panel)){
33673 var tab = this.tabs.getTab(panel.getEl().id);
33674 if(tab.isHidden()){
33675 this.tabs.unhideTab(tab.id);
33679 this.setActivePanel(panel);
33686 * Get the active panel for this region.
33687 * @return {Roo.ContentPanel} The active panel or null
33689 getActivePanel : function(){
33690 return this.activePanel;
33693 validateVisibility : function(){
33694 if(this.panels.getCount() < 1){
33695 this.updateTitle(" ");
33696 this.closeBtn.hide();
33699 if(!this.isVisible()){
33706 * Adds the passed ContentPanel(s) to this region.
33707 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
33708 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
33710 add : function(panel){
33711 if(arguments.length > 1){
33712 for(var i = 0, len = arguments.length; i < len; i++) {
33713 this.add(arguments[i]);
33717 if(this.hasPanel(panel)){
33718 this.showPanel(panel);
33721 panel.setRegion(this);
33722 this.panels.add(panel);
33723 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
33724 this.bodyEl.dom.appendChild(panel.getEl().dom);
33725 if(panel.background !== true){
33726 this.setActivePanel(panel);
33728 this.fireEvent("paneladded", this, panel);
33734 this.initPanelAsTab(panel);
33736 if(panel.background !== true){
33737 this.tabs.activate(panel.getEl().id);
33739 this.fireEvent("paneladded", this, panel);
33744 * Hides the tab for the specified panel.
33745 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
33747 hidePanel : function(panel){
33748 if(this.tabs && (panel = this.getPanel(panel))){
33749 this.tabs.hideTab(panel.getEl().id);
33754 * Unhides the tab for a previously hidden panel.
33755 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
33757 unhidePanel : function(panel){
33758 if(this.tabs && (panel = this.getPanel(panel))){
33759 this.tabs.unhideTab(panel.getEl().id);
33763 clearPanels : function(){
33764 while(this.panels.getCount() > 0){
33765 this.remove(this.panels.first());
33770 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
33771 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
33772 * @param {Boolean} preservePanel Overrides the config preservePanel option
33773 * @return {Roo.ContentPanel} The panel that was removed
33775 remove : function(panel, preservePanel){
33776 panel = this.getPanel(panel);
33781 this.fireEvent("beforeremove", this, panel, e);
33782 if(e.cancel === true){
33785 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
33786 var panelId = panel.getId();
33787 this.panels.removeKey(panelId);
33789 document.body.appendChild(panel.getEl().dom);
33792 this.tabs.removeTab(panel.getEl().id);
33793 }else if (!preservePanel){
33794 this.bodyEl.dom.removeChild(panel.getEl().dom);
33796 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
33797 var p = this.panels.first();
33798 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
33799 tempEl.appendChild(p.getEl().dom);
33800 this.bodyEl.update("");
33801 this.bodyEl.dom.appendChild(p.getEl().dom);
33803 this.updateTitle(p.getTitle());
33805 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
33806 this.setActivePanel(p);
33808 panel.setRegion(null);
33809 if(this.activePanel == panel){
33810 this.activePanel = null;
33812 if(this.config.autoDestroy !== false && preservePanel !== true){
33813 try{panel.destroy();}catch(e){}
33815 this.fireEvent("panelremoved", this, panel);
33820 * Returns the TabPanel component used by this region
33821 * @return {Roo.TabPanel}
33823 getTabs : function(){
33827 createTool : function(parentEl, className){
33828 var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
33829 children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
33830 btn.addClassOnOver("x-layout-tools-button-over");
33835 * Ext JS Library 1.1.1
33836 * Copyright(c) 2006-2007, Ext JS, LLC.
33838 * Originally Released Under LGPL - original licence link has changed is not relivant.
33841 * <script type="text/javascript">
33847 * @class Roo.SplitLayoutRegion
33848 * @extends Roo.LayoutRegion
33849 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
33851 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
33852 this.cursor = cursor;
33853 Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
33856 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
33857 splitTip : "Drag to resize.",
33858 collapsibleSplitTip : "Drag to resize. Double click to hide.",
33859 useSplitTips : false,
33861 applyConfig : function(config){
33862 Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
33865 var splitEl = Roo.DomHelper.append(this.mgr.el.dom,
33866 {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: " "});
33867 /** The SplitBar for this region
33868 * @type Roo.SplitBar */
33869 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
33870 this.split.on("moved", this.onSplitMove, this);
33871 this.split.useShim = config.useShim === true;
33872 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
33873 if(this.useSplitTips){
33874 this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
33876 if(config.collapsible){
33877 this.split.el.on("dblclick", this.collapse, this);
33880 if(typeof config.minSize != "undefined"){
33881 this.split.minSize = config.minSize;
33883 if(typeof config.maxSize != "undefined"){
33884 this.split.maxSize = config.maxSize;
33886 if(config.hideWhenEmpty || config.hidden || config.collapsed){
33887 this.hideSplitter();
33892 getHMaxSize : function(){
33893 var cmax = this.config.maxSize || 10000;
33894 var center = this.mgr.getRegion("center");
33895 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
33898 getVMaxSize : function(){
33899 var cmax = this.config.maxSize || 10000;
33900 var center = this.mgr.getRegion("center");
33901 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
33904 onSplitMove : function(split, newSize){
33905 this.fireEvent("resized", this, newSize);
33909 * Returns the {@link Roo.SplitBar} for this region.
33910 * @return {Roo.SplitBar}
33912 getSplitBar : function(){
33917 this.hideSplitter();
33918 Roo.SplitLayoutRegion.superclass.hide.call(this);
33921 hideSplitter : function(){
33923 this.split.el.setLocation(-2000,-2000);
33924 this.split.el.hide();
33930 this.split.el.show();
33932 Roo.SplitLayoutRegion.superclass.show.call(this);
33935 beforeSlide: function(){
33936 if(Roo.isGecko){// firefox overflow auto bug workaround
33937 this.bodyEl.clip();
33938 if(this.tabs) this.tabs.bodyEl.clip();
33939 if(this.activePanel){
33940 this.activePanel.getEl().clip();
33942 if(this.activePanel.beforeSlide){
33943 this.activePanel.beforeSlide();
33949 afterSlide : function(){
33950 if(Roo.isGecko){// firefox overflow auto bug workaround
33951 this.bodyEl.unclip();
33952 if(this.tabs) this.tabs.bodyEl.unclip();
33953 if(this.activePanel){
33954 this.activePanel.getEl().unclip();
33955 if(this.activePanel.afterSlide){
33956 this.activePanel.afterSlide();
33962 initAutoHide : function(){
33963 if(this.autoHide !== false){
33964 if(!this.autoHideHd){
33965 var st = new Roo.util.DelayedTask(this.slideIn, this);
33966 this.autoHideHd = {
33967 "mouseout": function(e){
33968 if(!e.within(this.el, true)){
33972 "mouseover" : function(e){
33978 this.el.on(this.autoHideHd);
33982 clearAutoHide : function(){
33983 if(this.autoHide !== false){
33984 this.el.un("mouseout", this.autoHideHd.mouseout);
33985 this.el.un("mouseover", this.autoHideHd.mouseover);
33989 clearMonitor : function(){
33990 Roo.get(document).un("click", this.slideInIf, this);
33993 // these names are backwards but not changed for compat
33994 slideOut : function(){
33995 if(this.isSlid || this.el.hasActiveFx()){
33998 this.isSlid = true;
33999 if(this.collapseBtn){
34000 this.collapseBtn.hide();
34002 this.closeBtnState = this.closeBtn.getStyle('display');
34003 this.closeBtn.hide();
34005 this.stickBtn.show();
34008 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
34009 this.beforeSlide();
34010 this.el.setStyle("z-index", 10001);
34011 this.el.slideIn(this.getSlideAnchor(), {
34012 callback: function(){
34014 this.initAutoHide();
34015 Roo.get(document).on("click", this.slideInIf, this);
34016 this.fireEvent("slideshow", this);
34023 afterSlideIn : function(){
34024 this.clearAutoHide();
34025 this.isSlid = false;
34026 this.clearMonitor();
34027 this.el.setStyle("z-index", "");
34028 if(this.collapseBtn){
34029 this.collapseBtn.show();
34031 this.closeBtn.setStyle('display', this.closeBtnState);
34033 this.stickBtn.hide();
34035 this.fireEvent("slidehide", this);
34038 slideIn : function(cb){
34039 if(!this.isSlid || this.el.hasActiveFx()){
34043 this.isSlid = false;
34044 this.beforeSlide();
34045 this.el.slideOut(this.getSlideAnchor(), {
34046 callback: function(){
34047 this.el.setLeftTop(-10000, -10000);
34049 this.afterSlideIn();
34057 slideInIf : function(e){
34058 if(!e.within(this.el)){
34063 animateCollapse : function(){
34064 this.beforeSlide();
34065 this.el.setStyle("z-index", 20000);
34066 var anchor = this.getSlideAnchor();
34067 this.el.slideOut(anchor, {
34068 callback : function(){
34069 this.el.setStyle("z-index", "");
34070 this.collapsedEl.slideIn(anchor, {duration:.3});
34072 this.el.setLocation(-10000,-10000);
34074 this.fireEvent("collapsed", this);
34081 animateExpand : function(){
34082 this.beforeSlide();
34083 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
34084 this.el.setStyle("z-index", 20000);
34085 this.collapsedEl.hide({
34088 this.el.slideIn(this.getSlideAnchor(), {
34089 callback : function(){
34090 this.el.setStyle("z-index", "");
34093 this.split.el.show();
34095 this.fireEvent("invalidated", this);
34096 this.fireEvent("expanded", this);
34124 getAnchor : function(){
34125 return this.anchors[this.position];
34128 getCollapseAnchor : function(){
34129 return this.canchors[this.position];
34132 getSlideAnchor : function(){
34133 return this.sanchors[this.position];
34136 getAlignAdj : function(){
34137 var cm = this.cmargins;
34138 switch(this.position){
34154 getExpandAdj : function(){
34155 var c = this.collapsedEl, cm = this.cmargins;
34156 switch(this.position){
34158 return [-(cm.right+c.getWidth()+cm.left), 0];
34161 return [cm.right+c.getWidth()+cm.left, 0];
34164 return [0, -(cm.top+cm.bottom+c.getHeight())];
34167 return [0, cm.top+cm.bottom+c.getHeight()];
34173 * Ext JS Library 1.1.1
34174 * Copyright(c) 2006-2007, Ext JS, LLC.
34176 * Originally Released Under LGPL - original licence link has changed is not relivant.
34179 * <script type="text/javascript">
34182 * These classes are private internal classes
34184 Roo.CenterLayoutRegion = function(mgr, config){
34185 Roo.LayoutRegion.call(this, mgr, config, "center");
34186 this.visible = true;
34187 this.minWidth = config.minWidth || 20;
34188 this.minHeight = config.minHeight || 20;
34191 Roo.extend(Roo.CenterLayoutRegion, Roo.LayoutRegion, {
34193 // center panel can't be hidden
34197 // center panel can't be hidden
34200 getMinWidth: function(){
34201 return this.minWidth;
34204 getMinHeight: function(){
34205 return this.minHeight;
34210 Roo.NorthLayoutRegion = function(mgr, config){
34211 Roo.LayoutRegion.call(this, mgr, config, "north", "n-resize");
34213 this.split.placement = Roo.SplitBar.TOP;
34214 this.split.orientation = Roo.SplitBar.VERTICAL;
34215 this.split.el.addClass("x-layout-split-v");
34217 var size = config.initialSize || config.height;
34218 if(typeof size != "undefined"){
34219 this.el.setHeight(size);
34222 Roo.extend(Roo.NorthLayoutRegion, Roo.SplitLayoutRegion, {
34223 orientation: Roo.SplitBar.VERTICAL,
34224 getBox : function(){
34225 if(this.collapsed){
34226 return this.collapsedEl.getBox();
34228 var box = this.el.getBox();
34230 box.height += this.split.el.getHeight();
34235 updateBox : function(box){
34236 if(this.split && !this.collapsed){
34237 box.height -= this.split.el.getHeight();
34238 this.split.el.setLeft(box.x);
34239 this.split.el.setTop(box.y+box.height);
34240 this.split.el.setWidth(box.width);
34242 if(this.collapsed){
34243 this.updateBody(box.width, null);
34245 Roo.LayoutRegion.prototype.updateBox.call(this, box);
34249 Roo.SouthLayoutRegion = function(mgr, config){
34250 Roo.SplitLayoutRegion.call(this, mgr, config, "south", "s-resize");
34252 this.split.placement = Roo.SplitBar.BOTTOM;
34253 this.split.orientation = Roo.SplitBar.VERTICAL;
34254 this.split.el.addClass("x-layout-split-v");
34256 var size = config.initialSize || config.height;
34257 if(typeof size != "undefined"){
34258 this.el.setHeight(size);
34261 Roo.extend(Roo.SouthLayoutRegion, Roo.SplitLayoutRegion, {
34262 orientation: Roo.SplitBar.VERTICAL,
34263 getBox : function(){
34264 if(this.collapsed){
34265 return this.collapsedEl.getBox();
34267 var box = this.el.getBox();
34269 var sh = this.split.el.getHeight();
34276 updateBox : function(box){
34277 if(this.split && !this.collapsed){
34278 var sh = this.split.el.getHeight();
34281 this.split.el.setLeft(box.x);
34282 this.split.el.setTop(box.y-sh);
34283 this.split.el.setWidth(box.width);
34285 if(this.collapsed){
34286 this.updateBody(box.width, null);
34288 Roo.LayoutRegion.prototype.updateBox.call(this, box);
34292 Roo.EastLayoutRegion = function(mgr, config){
34293 Roo.SplitLayoutRegion.call(this, mgr, config, "east", "e-resize");
34295 this.split.placement = Roo.SplitBar.RIGHT;
34296 this.split.orientation = Roo.SplitBar.HORIZONTAL;
34297 this.split.el.addClass("x-layout-split-h");
34299 var size = config.initialSize || config.width;
34300 if(typeof size != "undefined"){
34301 this.el.setWidth(size);
34304 Roo.extend(Roo.EastLayoutRegion, Roo.SplitLayoutRegion, {
34305 orientation: Roo.SplitBar.HORIZONTAL,
34306 getBox : function(){
34307 if(this.collapsed){
34308 return this.collapsedEl.getBox();
34310 var box = this.el.getBox();
34312 var sw = this.split.el.getWidth();
34319 updateBox : function(box){
34320 if(this.split && !this.collapsed){
34321 var sw = this.split.el.getWidth();
34323 this.split.el.setLeft(box.x);
34324 this.split.el.setTop(box.y);
34325 this.split.el.setHeight(box.height);
34328 if(this.collapsed){
34329 this.updateBody(null, box.height);
34331 Roo.LayoutRegion.prototype.updateBox.call(this, box);
34335 Roo.WestLayoutRegion = function(mgr, config){
34336 Roo.SplitLayoutRegion.call(this, mgr, config, "west", "w-resize");
34338 this.split.placement = Roo.SplitBar.LEFT;
34339 this.split.orientation = Roo.SplitBar.HORIZONTAL;
34340 this.split.el.addClass("x-layout-split-h");
34342 var size = config.initialSize || config.width;
34343 if(typeof size != "undefined"){
34344 this.el.setWidth(size);
34347 Roo.extend(Roo.WestLayoutRegion, Roo.SplitLayoutRegion, {
34348 orientation: Roo.SplitBar.HORIZONTAL,
34349 getBox : function(){
34350 if(this.collapsed){
34351 return this.collapsedEl.getBox();
34353 var box = this.el.getBox();
34355 box.width += this.split.el.getWidth();
34360 updateBox : function(box){
34361 if(this.split && !this.collapsed){
34362 var sw = this.split.el.getWidth();
34364 this.split.el.setLeft(box.x+box.width);
34365 this.split.el.setTop(box.y);
34366 this.split.el.setHeight(box.height);
34368 if(this.collapsed){
34369 this.updateBody(null, box.height);
34371 Roo.LayoutRegion.prototype.updateBox.call(this, box);
34376 * Ext JS Library 1.1.1
34377 * Copyright(c) 2006-2007, Ext JS, LLC.
34379 * Originally Released Under LGPL - original licence link has changed is not relivant.
34382 * <script type="text/javascript">
34387 * Private internal class for reading and applying state
34389 Roo.LayoutStateManager = function(layout){
34390 // default empty state
34399 Roo.LayoutStateManager.prototype = {
34400 init : function(layout, provider){
34401 this.provider = provider;
34402 var state = provider.get(layout.id+"-layout-state");
34404 var wasUpdating = layout.isUpdating();
34406 layout.beginUpdate();
34408 for(var key in state){
34409 if(typeof state[key] != "function"){
34410 var rstate = state[key];
34411 var r = layout.getRegion(key);
34414 r.resizeTo(rstate.size);
34416 if(rstate.collapsed == true){
34419 r.expand(null, true);
34425 layout.endUpdate();
34427 this.state = state;
34429 this.layout = layout;
34430 layout.on("regionresized", this.onRegionResized, this);
34431 layout.on("regioncollapsed", this.onRegionCollapsed, this);
34432 layout.on("regionexpanded", this.onRegionExpanded, this);
34435 storeState : function(){
34436 this.provider.set(this.layout.id+"-layout-state", this.state);
34439 onRegionResized : function(region, newSize){
34440 this.state[region.getPosition()].size = newSize;
34444 onRegionCollapsed : function(region){
34445 this.state[region.getPosition()].collapsed = true;
34449 onRegionExpanded : function(region){
34450 this.state[region.getPosition()].collapsed = false;
34455 * Ext JS Library 1.1.1
34456 * Copyright(c) 2006-2007, Ext JS, LLC.
34458 * Originally Released Under LGPL - original licence link has changed is not relivant.
34461 * <script type="text/javascript">
34464 * @class Roo.ContentPanel
34465 * @extends Roo.util.Observable
34466 * A basic ContentPanel element.
34467 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
34468 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
34469 * @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
34470 * @cfg {Boolean} closable True if the panel can be closed/removed
34471 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
34472 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
34473 * @cfg {Toolbar} toolbar A toolbar for this panel
34474 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
34475 * @cfg {String} title The title for this panel
34476 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
34477 * @cfg {String} url Calls {@link #setUrl} with this value
34478 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
34479 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
34480 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
34481 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
34484 * Create a new ContentPanel.
34485 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
34486 * @param {String/Object} config A string to set only the title or a config object
34487 * @param {String} content (optional) Set the HTML content for this panel
34488 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
34490 Roo.ContentPanel = function(el, config, content){
34494 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
34498 if (config && config.parentLayout) {
34499 el = config.parentLayout.el.createChild();
34502 if(el.autoCreate){ // xtype is available if this is called from factory
34506 this.el = Roo.get(el);
34507 if(!this.el && config && config.autoCreate){
34508 if(typeof config.autoCreate == "object"){
34509 if(!config.autoCreate.id){
34510 config.autoCreate.id = config.id||el;
34512 this.el = Roo.DomHelper.append(document.body,
34513 config.autoCreate, true);
34515 this.el = Roo.DomHelper.append(document.body,
34516 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
34519 this.closable = false;
34520 this.loaded = false;
34521 this.active = false;
34522 if(typeof config == "string"){
34523 this.title = config;
34525 Roo.apply(this, config);
34528 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
34529 this.wrapEl = this.el.wrap();
34530 this.toolbar.container = this.el.insertSibling(false, 'before');
34531 this.toolbar = new Roo.Toolbar(this.toolbar);
34534 // xtype created footer. - not sure if will work as we normally have to render first..
34535 if (this.footer && !this.footer.el && this.footer.xtype) {
34536 if (!this.wrapEl) {
34537 this.wrapEl = this.el.wrap();
34540 this.footer.container = this.wrapEl.createChild();
34542 this.footer = Roo.factory(this.footer, Roo);
34547 this.resizeEl = Roo.get(this.resizeEl, true);
34549 this.resizeEl = this.el;
34551 // handle view.xtype
34559 * Fires when this panel is activated.
34560 * @param {Roo.ContentPanel} this
34564 * @event deactivate
34565 * Fires when this panel is activated.
34566 * @param {Roo.ContentPanel} this
34568 "deactivate" : true,
34572 * Fires when this panel is resized if fitToFrame is true.
34573 * @param {Roo.ContentPanel} this
34574 * @param {Number} width The width after any component adjustments
34575 * @param {Number} height The height after any component adjustments
34581 * Fires when this tab is created
34582 * @param {Roo.ContentPanel} this
34593 if(this.autoScroll){
34594 this.resizeEl.setStyle("overflow", "auto");
34596 // fix randome scrolling
34597 this.el.on('scroll', function() {
34598 Roo.log('fix random scolling');
34599 this.scrollTo('top',0);
34602 content = content || this.content;
34604 this.setContent(content);
34606 if(config && config.url){
34607 this.setUrl(this.url, this.params, this.loadOnce);
34612 Roo.ContentPanel.superclass.constructor.call(this);
34614 if (this.view && typeof(this.view.xtype) != 'undefined') {
34615 this.view.el = this.el.appendChild(document.createElement("div"));
34616 this.view = Roo.factory(this.view);
34617 this.view.render && this.view.render(false, '');
34621 this.fireEvent('render', this);
34624 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
34626 setRegion : function(region){
34627 this.region = region;
34629 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
34631 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
34636 * Returns the toolbar for this Panel if one was configured.
34637 * @return {Roo.Toolbar}
34639 getToolbar : function(){
34640 return this.toolbar;
34643 setActiveState : function(active){
34644 this.active = active;
34646 this.fireEvent("deactivate", this);
34648 this.fireEvent("activate", this);
34652 * Updates this panel's element
34653 * @param {String} content The new content
34654 * @param {Boolean} loadScripts (optional) true to look for and process scripts
34656 setContent : function(content, loadScripts){
34657 this.el.update(content, loadScripts);
34660 ignoreResize : function(w, h){
34661 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
34664 this.lastSize = {width: w, height: h};
34669 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
34670 * @return {Roo.UpdateManager} The UpdateManager
34672 getUpdateManager : function(){
34673 return this.el.getUpdateManager();
34676 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
34677 * @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:
34680 url: "your-url.php",
34681 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
34682 callback: yourFunction,
34683 scope: yourObject, //(optional scope)
34686 text: "Loading...",
34691 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
34692 * 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.
34693 * @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}
34694 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
34695 * @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.
34696 * @return {Roo.ContentPanel} this
34699 var um = this.el.getUpdateManager();
34700 um.update.apply(um, arguments);
34706 * 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.
34707 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
34708 * @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)
34709 * @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)
34710 * @return {Roo.UpdateManager} The UpdateManager
34712 setUrl : function(url, params, loadOnce){
34713 if(this.refreshDelegate){
34714 this.removeListener("activate", this.refreshDelegate);
34716 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
34717 this.on("activate", this.refreshDelegate);
34718 return this.el.getUpdateManager();
34721 _handleRefresh : function(url, params, loadOnce){
34722 if(!loadOnce || !this.loaded){
34723 var updater = this.el.getUpdateManager();
34724 updater.update(url, params, this._setLoaded.createDelegate(this));
34728 _setLoaded : function(){
34729 this.loaded = true;
34733 * Returns this panel's id
34736 getId : function(){
34741 * Returns this panel's element - used by regiosn to add.
34742 * @return {Roo.Element}
34744 getEl : function(){
34745 return this.wrapEl || this.el;
34748 adjustForComponents : function(width, height)
34750 //Roo.log('adjustForComponents ');
34751 if(this.resizeEl != this.el){
34752 width -= this.el.getFrameWidth('lr');
34753 height -= this.el.getFrameWidth('tb');
34756 var te = this.toolbar.getEl();
34757 height -= te.getHeight();
34758 te.setWidth(width);
34761 var te = this.footer.getEl();
34762 Roo.log("footer:" + te.getHeight());
34764 height -= te.getHeight();
34765 te.setWidth(width);
34769 if(this.adjustments){
34770 width += this.adjustments[0];
34771 height += this.adjustments[1];
34773 return {"width": width, "height": height};
34776 setSize : function(width, height){
34777 if(this.fitToFrame && !this.ignoreResize(width, height)){
34778 if(this.fitContainer && this.resizeEl != this.el){
34779 this.el.setSize(width, height);
34781 var size = this.adjustForComponents(width, height);
34782 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
34783 this.fireEvent('resize', this, size.width, size.height);
34788 * Returns this panel's title
34791 getTitle : function(){
34796 * Set this panel's title
34797 * @param {String} title
34799 setTitle : function(title){
34800 this.title = title;
34802 this.region.updatePanelTitle(this, title);
34807 * Returns true is this panel was configured to be closable
34808 * @return {Boolean}
34810 isClosable : function(){
34811 return this.closable;
34814 beforeSlide : function(){
34816 this.resizeEl.clip();
34819 afterSlide : function(){
34821 this.resizeEl.unclip();
34825 * Force a content refresh from the URL specified in the {@link #setUrl} method.
34826 * Will fail silently if the {@link #setUrl} method has not been called.
34827 * This does not activate the panel, just updates its content.
34829 refresh : function(){
34830 if(this.refreshDelegate){
34831 this.loaded = false;
34832 this.refreshDelegate();
34837 * Destroys this panel
34839 destroy : function(){
34840 this.el.removeAllListeners();
34841 var tempEl = document.createElement("span");
34842 tempEl.appendChild(this.el.dom);
34843 tempEl.innerHTML = "";
34849 * form - if the content panel contains a form - this is a reference to it.
34850 * @type {Roo.form.Form}
34854 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
34855 * This contains a reference to it.
34861 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
34871 * @param {Object} cfg Xtype definition of item to add.
34874 addxtype : function(cfg) {
34876 if (cfg.xtype.match(/^Form$/)) {
34879 //if (this.footer) {
34880 // el = this.footer.container.insertSibling(false, 'before');
34882 el = this.el.createChild();
34885 this.form = new Roo.form.Form(cfg);
34888 if ( this.form.allItems.length) this.form.render(el.dom);
34891 // should only have one of theses..
34892 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
34893 // views.. should not be just added - used named prop 'view''
34895 cfg.el = this.el.appendChild(document.createElement("div"));
34898 var ret = new Roo.factory(cfg);
34900 ret.render && ret.render(false, ''); // render blank..
34909 * @class Roo.GridPanel
34910 * @extends Roo.ContentPanel
34912 * Create a new GridPanel.
34913 * @param {Roo.grid.Grid} grid The grid for this panel
34914 * @param {String/Object} config A string to set only the panel's title, or a config object
34916 Roo.GridPanel = function(grid, config){
34919 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
34920 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
34922 this.wrapper.dom.appendChild(grid.getGridEl().dom);
34924 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
34927 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
34929 // xtype created footer. - not sure if will work as we normally have to render first..
34930 if (this.footer && !this.footer.el && this.footer.xtype) {
34932 this.footer.container = this.grid.getView().getFooterPanel(true);
34933 this.footer.dataSource = this.grid.dataSource;
34934 this.footer = Roo.factory(this.footer, Roo);
34938 grid.monitorWindowResize = false; // turn off autosizing
34939 grid.autoHeight = false;
34940 grid.autoWidth = false;
34942 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
34945 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
34946 getId : function(){
34947 return this.grid.id;
34951 * Returns the grid for this panel
34952 * @return {Roo.grid.Grid}
34954 getGrid : function(){
34958 setSize : function(width, height){
34959 if(!this.ignoreResize(width, height)){
34960 var grid = this.grid;
34961 var size = this.adjustForComponents(width, height);
34962 grid.getGridEl().setSize(size.width, size.height);
34967 beforeSlide : function(){
34968 this.grid.getView().scroller.clip();
34971 afterSlide : function(){
34972 this.grid.getView().scroller.unclip();
34975 destroy : function(){
34976 this.grid.destroy();
34978 Roo.GridPanel.superclass.destroy.call(this);
34984 * @class Roo.NestedLayoutPanel
34985 * @extends Roo.ContentPanel
34987 * Create a new NestedLayoutPanel.
34990 * @param {Roo.BorderLayout} layout The layout for this panel
34991 * @param {String/Object} config A string to set only the title or a config object
34993 Roo.NestedLayoutPanel = function(layout, config)
34995 // construct with only one argument..
34996 /* FIXME - implement nicer consturctors
34997 if (layout.layout) {
34999 layout = config.layout;
35000 delete config.layout;
35002 if (layout.xtype && !layout.getEl) {
35003 // then layout needs constructing..
35004 layout = Roo.factory(layout, Roo);
35009 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
35011 layout.monitorWindowResize = false; // turn off autosizing
35012 this.layout = layout;
35013 this.layout.getEl().addClass("x-layout-nested-layout");
35020 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
35022 setSize : function(width, height){
35023 if(!this.ignoreResize(width, height)){
35024 var size = this.adjustForComponents(width, height);
35025 var el = this.layout.getEl();
35026 el.setSize(size.width, size.height);
35027 var touch = el.dom.offsetWidth;
35028 this.layout.layout();
35029 // ie requires a double layout on the first pass
35030 if(Roo.isIE && !this.initialized){
35031 this.initialized = true;
35032 this.layout.layout();
35037 // activate all subpanels if not currently active..
35039 setActiveState : function(active){
35040 this.active = active;
35042 this.fireEvent("deactivate", this);
35046 this.fireEvent("activate", this);
35047 // not sure if this should happen before or after..
35048 if (!this.layout) {
35049 return; // should not happen..
35052 for (var r in this.layout.regions) {
35053 reg = this.layout.getRegion(r);
35054 if (reg.getActivePanel()) {
35055 //reg.showPanel(reg.getActivePanel()); // force it to activate..
35056 reg.setActivePanel(reg.getActivePanel());
35059 if (!reg.panels.length) {
35062 reg.showPanel(reg.getPanel(0));
35071 * Returns the nested BorderLayout for this panel
35072 * @return {Roo.BorderLayout}
35074 getLayout : function(){
35075 return this.layout;
35079 * Adds a xtype elements to the layout of the nested panel
35083 xtype : 'ContentPanel',
35090 xtype : 'NestedLayoutPanel',
35096 items : [ ... list of content panels or nested layout panels.. ]
35100 * @param {Object} cfg Xtype definition of item to add.
35102 addxtype : function(cfg) {
35103 return this.layout.addxtype(cfg);
35108 Roo.ScrollPanel = function(el, config, content){
35109 config = config || {};
35110 config.fitToFrame = true;
35111 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
35113 this.el.dom.style.overflow = "hidden";
35114 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
35115 this.el.removeClass("x-layout-inactive-content");
35116 this.el.on("mousewheel", this.onWheel, this);
35118 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
35119 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
35120 up.unselectable(); down.unselectable();
35121 up.on("click", this.scrollUp, this);
35122 down.on("click", this.scrollDown, this);
35123 up.addClassOnOver("x-scroller-btn-over");
35124 down.addClassOnOver("x-scroller-btn-over");
35125 up.addClassOnClick("x-scroller-btn-click");
35126 down.addClassOnClick("x-scroller-btn-click");
35127 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
35129 this.resizeEl = this.el;
35130 this.el = wrap; this.up = up; this.down = down;
35133 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
35135 wheelIncrement : 5,
35136 scrollUp : function(){
35137 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
35140 scrollDown : function(){
35141 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
35144 afterScroll : function(){
35145 var el = this.resizeEl;
35146 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
35147 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
35148 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
35151 setSize : function(){
35152 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
35153 this.afterScroll();
35156 onWheel : function(e){
35157 var d = e.getWheelDelta();
35158 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
35159 this.afterScroll();
35163 setContent : function(content, loadScripts){
35164 this.resizeEl.update(content, loadScripts);
35178 * @class Roo.TreePanel
35179 * @extends Roo.ContentPanel
35181 * Create a new TreePanel. - defaults to fit/scoll contents.
35182 * @param {String/Object} config A string to set only the panel's title, or a config object
35183 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
35185 Roo.TreePanel = function(config){
35186 var el = config.el;
35187 var tree = config.tree;
35188 delete config.tree;
35189 delete config.el; // hopefull!
35191 // wrapper for IE7 strict & safari scroll issue
35193 var treeEl = el.createChild();
35194 config.resizeEl = treeEl;
35198 Roo.TreePanel.superclass.constructor.call(this, el, config);
35201 this.tree = new Roo.tree.TreePanel(treeEl , tree);
35202 //console.log(tree);
35203 this.on('activate', function()
35205 if (this.tree.rendered) {
35208 //console.log('render tree');
35209 this.tree.render();
35211 // this should not be needed.. - it's actually the 'el' that resizes?
35212 // actuall it breaks the containerScroll - dragging nodes auto scroll at top
35214 //this.on('resize', function (cp, w, h) {
35215 // this.tree.innerCt.setWidth(w);
35216 // this.tree.innerCt.setHeight(h);
35217 // //this.tree.innerCt.setStyle('overflow-y', 'auto');
35224 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {
35241 * Ext JS Library 1.1.1
35242 * Copyright(c) 2006-2007, Ext JS, LLC.
35244 * Originally Released Under LGPL - original licence link has changed is not relivant.
35247 * <script type="text/javascript">
35252 * @class Roo.ReaderLayout
35253 * @extends Roo.BorderLayout
35254 * This is a pre-built layout that represents a classic, 5-pane application. It consists of a header, a primary
35255 * center region containing two nested regions (a top one for a list view and one for item preview below),
35256 * and regions on either side that can be used for navigation, application commands, informational displays, etc.
35257 * The setup and configuration work exactly the same as it does for a {@link Roo.BorderLayout} - this class simply
35258 * expedites the setup of the overall layout and regions for this common application style.
35261 var reader = new Roo.ReaderLayout();
35262 var CP = Roo.ContentPanel; // shortcut for adding
35264 reader.beginUpdate();
35265 reader.add("north", new CP("north", "North"));
35266 reader.add("west", new CP("west", {title: "West"}));
35267 reader.add("east", new CP("east", {title: "East"}));
35269 reader.regions.listView.add(new CP("listView", "List"));
35270 reader.regions.preview.add(new CP("preview", "Preview"));
35271 reader.endUpdate();
35274 * Create a new ReaderLayout
35275 * @param {Object} config Configuration options
35276 * @param {String/HTMLElement/Element} container (optional) The container this layout is bound to (defaults to
35277 * document.body if omitted)
35279 Roo.ReaderLayout = function(config, renderTo){
35280 var c = config || {size:{}};
35281 Roo.ReaderLayout.superclass.constructor.call(this, renderTo || document.body, {
35282 north: c.north !== false ? Roo.apply({
35286 }, c.north) : false,
35287 west: c.west !== false ? Roo.apply({
35295 margins:{left:5,right:0,bottom:5,top:5},
35296 cmargins:{left:5,right:5,bottom:5,top:5}
35297 }, c.west) : false,
35298 east: c.east !== false ? Roo.apply({
35306 margins:{left:0,right:5,bottom:5,top:5},
35307 cmargins:{left:5,right:5,bottom:5,top:5}
35308 }, c.east) : false,
35309 center: Roo.apply({
35310 tabPosition: 'top',
35314 margins:{left:c.west!==false ? 0 : 5,right:c.east!==false ? 0 : 5,bottom:5,top:2}
35318 this.el.addClass('x-reader');
35320 this.beginUpdate();
35322 var inner = new Roo.BorderLayout(Roo.get(document.body).createChild(), {
35323 south: c.preview !== false ? Roo.apply({
35330 cmargins:{top:5,left:0, right:0, bottom:0}
35331 }, c.preview) : false,
35332 center: Roo.apply({
35338 this.add('center', new Roo.NestedLayoutPanel(inner,
35339 Roo.apply({title: c.mainTitle || '',tabTip:''},c.innerPanelCfg)));
35343 this.regions.preview = inner.getRegion('south');
35344 this.regions.listView = inner.getRegion('center');
35347 Roo.extend(Roo.ReaderLayout, Roo.BorderLayout);/*
35349 * Ext JS Library 1.1.1
35350 * Copyright(c) 2006-2007, Ext JS, LLC.
35352 * Originally Released Under LGPL - original licence link has changed is not relivant.
35355 * <script type="text/javascript">
35359 * @class Roo.grid.Grid
35360 * @extends Roo.util.Observable
35361 * This class represents the primary interface of a component based grid control.
35362 * <br><br>Usage:<pre><code>
35363 var grid = new Roo.grid.Grid("my-container-id", {
35366 selModel: mySelectionModel,
35367 autoSizeColumns: true,
35368 monitorWindowResize: false,
35369 trackMouseOver: true
35374 * <b>Common Problems:</b><br/>
35375 * - Grid does not resize properly when going smaller: Setting overflow hidden on the container
35376 * element will correct this<br/>
35377 * - If you get el.style[camel]= NaNpx or -2px or something related, be certain you have given your container element
35378 * dimensions. The grid adapts to your container's size, if your container has no size defined then the results
35379 * are unpredictable.<br/>
35380 * - Do not render the grid into an element with display:none. Try using visibility:hidden. Otherwise there is no way for the
35381 * grid to calculate dimensions/offsets.<br/>
35383 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
35384 * The container MUST have some type of size defined for the grid to fill. The container will be
35385 * automatically set to position relative if it isn't already.
35386 * @param {Object} config A config object that sets properties on this grid.
35388 Roo.grid.Grid = function(container, config){
35389 // initialize the container
35390 this.container = Roo.get(container);
35391 this.container.update("");
35392 this.container.setStyle("overflow", "hidden");
35393 this.container.addClass('x-grid-container');
35395 this.id = this.container.id;
35397 Roo.apply(this, config);
35398 // check and correct shorthanded configs
35400 this.dataSource = this.ds;
35404 this.colModel = this.cm;
35408 this.selModel = this.sm;
35412 if (this.selModel) {
35413 this.selModel = Roo.factory(this.selModel, Roo.grid);
35414 this.sm = this.selModel;
35415 this.sm.xmodule = this.xmodule || false;
35417 if (typeof(this.colModel.config) == 'undefined') {
35418 this.colModel = new Roo.grid.ColumnModel(this.colModel);
35419 this.cm = this.colModel;
35420 this.cm.xmodule = this.xmodule || false;
35422 if (this.dataSource) {
35423 this.dataSource= Roo.factory(this.dataSource, Roo.data);
35424 this.ds = this.dataSource;
35425 this.ds.xmodule = this.xmodule || false;
35432 this.container.setWidth(this.width);
35436 this.container.setHeight(this.height);
35443 * The raw click event for the entire grid.
35444 * @param {Roo.EventObject} e
35449 * The raw dblclick event for the entire grid.
35450 * @param {Roo.EventObject} e
35454 * @event contextmenu
35455 * The raw contextmenu event for the entire grid.
35456 * @param {Roo.EventObject} e
35458 "contextmenu" : true,
35461 * The raw mousedown event for the entire grid.
35462 * @param {Roo.EventObject} e
35464 "mousedown" : true,
35467 * The raw mouseup event for the entire grid.
35468 * @param {Roo.EventObject} e
35473 * The raw mouseover event for the entire grid.
35474 * @param {Roo.EventObject} e
35476 "mouseover" : true,
35479 * The raw mouseout event for the entire grid.
35480 * @param {Roo.EventObject} e
35485 * The raw keypress event for the entire grid.
35486 * @param {Roo.EventObject} e
35491 * The raw keydown event for the entire grid.
35492 * @param {Roo.EventObject} e
35500 * Fires when a cell is clicked
35501 * @param {Grid} this
35502 * @param {Number} rowIndex
35503 * @param {Number} columnIndex
35504 * @param {Roo.EventObject} e
35506 "cellclick" : true,
35508 * @event celldblclick
35509 * Fires when a cell is double clicked
35510 * @param {Grid} this
35511 * @param {Number} rowIndex
35512 * @param {Number} columnIndex
35513 * @param {Roo.EventObject} e
35515 "celldblclick" : true,
35518 * Fires when a row is clicked
35519 * @param {Grid} this
35520 * @param {Number} rowIndex
35521 * @param {Roo.EventObject} e
35525 * @event rowdblclick
35526 * Fires when a row is double clicked
35527 * @param {Grid} this
35528 * @param {Number} rowIndex
35529 * @param {Roo.EventObject} e
35531 "rowdblclick" : true,
35533 * @event headerclick
35534 * Fires when a header is clicked
35535 * @param {Grid} this
35536 * @param {Number} columnIndex
35537 * @param {Roo.EventObject} e
35539 "headerclick" : true,
35541 * @event headerdblclick
35542 * Fires when a header cell is double clicked
35543 * @param {Grid} this
35544 * @param {Number} columnIndex
35545 * @param {Roo.EventObject} e
35547 "headerdblclick" : true,
35549 * @event rowcontextmenu
35550 * Fires when a row is right clicked
35551 * @param {Grid} this
35552 * @param {Number} rowIndex
35553 * @param {Roo.EventObject} e
35555 "rowcontextmenu" : true,
35557 * @event cellcontextmenu
35558 * Fires when a cell is right clicked
35559 * @param {Grid} this
35560 * @param {Number} rowIndex
35561 * @param {Number} cellIndex
35562 * @param {Roo.EventObject} e
35564 "cellcontextmenu" : true,
35566 * @event headercontextmenu
35567 * Fires when a header is right clicked
35568 * @param {Grid} this
35569 * @param {Number} columnIndex
35570 * @param {Roo.EventObject} e
35572 "headercontextmenu" : true,
35574 * @event bodyscroll
35575 * Fires when the body element is scrolled
35576 * @param {Number} scrollLeft
35577 * @param {Number} scrollTop
35579 "bodyscroll" : true,
35581 * @event columnresize
35582 * Fires when the user resizes a column
35583 * @param {Number} columnIndex
35584 * @param {Number} newSize
35586 "columnresize" : true,
35588 * @event columnmove
35589 * Fires when the user moves a column
35590 * @param {Number} oldIndex
35591 * @param {Number} newIndex
35593 "columnmove" : true,
35596 * Fires when row(s) start being dragged
35597 * @param {Grid} this
35598 * @param {Roo.GridDD} dd The drag drop object
35599 * @param {event} e The raw browser event
35601 "startdrag" : true,
35604 * Fires when a drag operation is complete
35605 * @param {Grid} this
35606 * @param {Roo.GridDD} dd The drag drop object
35607 * @param {event} e The raw browser event
35612 * Fires when dragged row(s) are dropped on a valid DD target
35613 * @param {Grid} this
35614 * @param {Roo.GridDD} dd The drag drop object
35615 * @param {String} targetId The target drag drop object
35616 * @param {event} e The raw browser event
35621 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
35622 * @param {Grid} this
35623 * @param {Roo.GridDD} dd The drag drop object
35624 * @param {String} targetId The target drag drop object
35625 * @param {event} e The raw browser event
35630 * Fires when the dragged row(s) first cross another DD target while being dragged
35631 * @param {Grid} this
35632 * @param {Roo.GridDD} dd The drag drop object
35633 * @param {String} targetId The target drag drop object
35634 * @param {event} e The raw browser event
35636 "dragenter" : true,
35639 * Fires when the dragged row(s) leave another DD target while being dragged
35640 * @param {Grid} this
35641 * @param {Roo.GridDD} dd The drag drop object
35642 * @param {String} targetId The target drag drop object
35643 * @param {event} e The raw browser event
35648 * Fires when a row is rendered, so you can change add a style to it.
35649 * @param {GridView} gridview The grid view
35650 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
35656 * Fires when the grid is rendered
35657 * @param {Grid} grid
35662 Roo.grid.Grid.superclass.constructor.call(this);
35664 Roo.extend(Roo.grid.Grid, Roo.util.Observable, {
35667 * @cfg {String} ddGroup - drag drop group.
35671 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Default is 25.
35673 minColumnWidth : 25,
35676 * @cfg {Boolean} autoSizeColumns True to automatically resize the columns to fit their content
35677 * <b>on initial render.</b> It is more efficient to explicitly size the columns
35678 * through the ColumnModel's {@link Roo.grid.ColumnModel#width} config option. Default is false.
35680 autoSizeColumns : false,
35683 * @cfg {Boolean} autoSizeHeaders True to measure headers with column data when auto sizing columns. Default is true.
35685 autoSizeHeaders : true,
35688 * @cfg {Boolean} monitorWindowResize True to autoSize the grid when the window resizes. Default is true.
35690 monitorWindowResize : true,
35693 * @cfg {Boolean} maxRowsToMeasure If autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of
35694 * rows measured to get a columns size. Default is 0 (all rows).
35696 maxRowsToMeasure : 0,
35699 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is true.
35701 trackMouseOver : true,
35704 * @cfg {Boolean} enableDrag True to enable drag of rows. Default is false. (double check if this is needed?)
35708 * @cfg {Boolean} enableDragDrop True to enable drag and drop of rows. Default is false.
35710 enableDragDrop : false,
35713 * @cfg {Boolean} enableColumnMove True to enable drag and drop reorder of columns. Default is true.
35715 enableColumnMove : true,
35718 * @cfg {Boolean} enableColumnHide True to enable hiding of columns with the header context menu. Default is true.
35720 enableColumnHide : true,
35723 * @cfg {Boolean} enableRowHeightSync True to manually sync row heights across locked and not locked rows. Default is false.
35725 enableRowHeightSync : false,
35728 * @cfg {Boolean} stripeRows True to stripe the rows. Default is true.
35733 * @cfg {Boolean} autoHeight True to fit the height of the grid container to the height of the data. Default is false.
35735 autoHeight : false,
35738 * @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.
35740 autoExpandColumn : false,
35743 * @cfg {Number} autoExpandMin The minimum width the autoExpandColumn can have (if enabled).
35746 autoExpandMin : 50,
35749 * @cfg {Number} autoExpandMax The maximum width the autoExpandColumn can have (if enabled). Default is 1000.
35751 autoExpandMax : 1000,
35754 * @cfg {Object} view The {@link Roo.grid.GridView} used by the grid. This can be set before a call to render().
35759 * @cfg {Object} loadMask An {@link Roo.LoadMask} config or true to mask the grid while loading. Default is false.
35763 * @cfg {Roo.dd.DropTarget} dropTarget An {@link Roo.dd.DropTarget} config
35773 * @cfg {Boolean} autoWidth True to set the grid's width to the default total width of the grid's columns instead
35774 * of a fixed width. Default is false.
35777 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if autoHeight is not on.
35780 * Called once after all setup has been completed and the grid is ready to be rendered.
35781 * @return {Roo.grid.Grid} this
35783 render : function()
35785 var c = this.container;
35786 // try to detect autoHeight/width mode
35787 if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
35788 this.autoHeight = true;
35790 var view = this.getView();
35793 c.on("click", this.onClick, this);
35794 c.on("dblclick", this.onDblClick, this);
35795 c.on("contextmenu", this.onContextMenu, this);
35796 c.on("keydown", this.onKeyDown, this);
35798 c.on("touchstart", this.onTouchStart, this);
35801 this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
35803 this.getSelectionModel().init(this);
35808 this.loadMask = new Roo.LoadMask(this.container,
35809 Roo.apply({store:this.dataSource}, this.loadMask));
35813 if (this.toolbar && this.toolbar.xtype) {
35814 this.toolbar.container = this.getView().getHeaderPanel(true);
35815 this.toolbar = new Roo.Toolbar(this.toolbar);
35817 if (this.footer && this.footer.xtype) {
35818 this.footer.dataSource = this.getDataSource();
35819 this.footer.container = this.getView().getFooterPanel(true);
35820 this.footer = Roo.factory(this.footer, Roo);
35822 if (this.dropTarget && this.dropTarget.xtype) {
35823 delete this.dropTarget.xtype;
35824 this.dropTarget = new Roo.dd.DropTarget(this.getView().mainBody, this.dropTarget);
35828 this.rendered = true;
35829 this.fireEvent('render', this);
35834 * Reconfigures the grid to use a different Store and Column Model.
35835 * The View will be bound to the new objects and refreshed.
35836 * @param {Roo.data.Store} dataSource The new {@link Roo.data.Store} object
35837 * @param {Roo.grid.ColumnModel} The new {@link Roo.grid.ColumnModel} object
35839 reconfigure : function(dataSource, colModel){
35841 this.loadMask.destroy();
35842 this.loadMask = new Roo.LoadMask(this.container,
35843 Roo.apply({store:dataSource}, this.loadMask));
35845 this.view.bind(dataSource, colModel);
35846 this.dataSource = dataSource;
35847 this.colModel = colModel;
35848 this.view.refresh(true);
35852 onKeyDown : function(e){
35853 this.fireEvent("keydown", e);
35857 * Destroy this grid.
35858 * @param {Boolean} removeEl True to remove the element
35860 destroy : function(removeEl, keepListeners){
35862 this.loadMask.destroy();
35864 var c = this.container;
35865 c.removeAllListeners();
35866 this.view.destroy();
35867 this.colModel.purgeListeners();
35868 if(!keepListeners){
35869 this.purgeListeners();
35872 if(removeEl === true){
35878 processEvent : function(name, e){
35879 // does this fire select???
35880 Roo.log('grid:processEvent ' + name);
35882 if (name != 'touchstart' ) {
35883 this.fireEvent(name, e);
35886 var t = e.getTarget();
35888 var header = v.findHeaderIndex(t);
35889 if(header !== false){
35890 this.fireEvent("header" + (name == 'touchstart' ? 'click' : name), this, header, e);
35892 var row = v.findRowIndex(t);
35893 var cell = v.findCellIndex(t);
35894 if (name == 'touchstart') {
35895 // first touch is always a click.
35896 // hopefull this happens after selection is updated.?
35899 if (typeof(this.selModel.getSelectedCell) != 'undefined') {
35900 var cs = this.selModel.getSelectedCell();
35901 if (row == cs[0] && cell == cs[1]){
35905 if (typeof(this.selModel.getSelections) != 'undefined') {
35906 var cs = this.selModel.getSelections();
35907 var ds = this.dataSource;
35908 if (cs.length == 1 && ds.getAt(row) == cs[0]){
35919 this.fireEvent("row" + name, this, row, e);
35920 if(cell !== false){
35921 this.fireEvent("cell" + name, this, row, cell, e);
35928 onClick : function(e){
35929 this.processEvent("click", e);
35932 onTouchStart : function(e){
35933 this.processEvent("touchstart", e);
35937 onContextMenu : function(e, t){
35938 this.processEvent("contextmenu", e);
35942 onDblClick : function(e){
35943 this.processEvent("dblclick", e);
35947 walkCells : function(row, col, step, fn, scope){
35948 var cm = this.colModel, clen = cm.getColumnCount();
35949 var ds = this.dataSource, rlen = ds.getCount(), first = true;
35961 if(fn.call(scope || this, row, col, cm) === true){
35979 if(fn.call(scope || this, row, col, cm) === true){
35991 getSelections : function(){
35992 return this.selModel.getSelections();
35996 * Causes the grid to manually recalculate its dimensions. Generally this is done automatically,
35997 * but if manual update is required this method will initiate it.
35999 autoSize : function(){
36001 this.view.layout();
36002 if(this.view.adjustForScroll){
36003 this.view.adjustForScroll();
36009 * Returns the grid's underlying element.
36010 * @return {Element} The element
36012 getGridEl : function(){
36013 return this.container;
36016 // private for compatibility, overridden by editor grid
36017 stopEditing : function(){},
36020 * Returns the grid's SelectionModel.
36021 * @return {SelectionModel}
36023 getSelectionModel : function(){
36024 if(!this.selModel){
36025 this.selModel = new Roo.grid.RowSelectionModel();
36027 return this.selModel;
36031 * Returns the grid's DataSource.
36032 * @return {DataSource}
36034 getDataSource : function(){
36035 return this.dataSource;
36039 * Returns the grid's ColumnModel.
36040 * @return {ColumnModel}
36042 getColumnModel : function(){
36043 return this.colModel;
36047 * Returns the grid's GridView object.
36048 * @return {GridView}
36050 getView : function(){
36052 this.view = new Roo.grid.GridView(this.viewConfig);
36057 * Called to get grid's drag proxy text, by default returns this.ddText.
36060 getDragDropText : function(){
36061 var count = this.selModel.getCount();
36062 return String.format(this.ddText, count, count == 1 ? '' : 's');
36066 * Configures the text is the drag proxy (defaults to "%0 selected row(s)").
36067 * %0 is replaced with the number of selected rows.
36070 Roo.grid.Grid.prototype.ddText = "{0} selected row{1}";/*
36072 * Ext JS Library 1.1.1
36073 * Copyright(c) 2006-2007, Ext JS, LLC.
36075 * Originally Released Under LGPL - original licence link has changed is not relivant.
36078 * <script type="text/javascript">
36081 Roo.grid.AbstractGridView = function(){
36085 "beforerowremoved" : true,
36086 "beforerowsinserted" : true,
36087 "beforerefresh" : true,
36088 "rowremoved" : true,
36089 "rowsinserted" : true,
36090 "rowupdated" : true,
36093 Roo.grid.AbstractGridView.superclass.constructor.call(this);
36096 Roo.extend(Roo.grid.AbstractGridView, Roo.util.Observable, {
36097 rowClass : "x-grid-row",
36098 cellClass : "x-grid-cell",
36099 tdClass : "x-grid-td",
36100 hdClass : "x-grid-hd",
36101 splitClass : "x-grid-hd-split",
36103 init: function(grid){
36105 var cid = this.grid.getGridEl().id;
36106 this.colSelector = "#" + cid + " ." + this.cellClass + "-";
36107 this.tdSelector = "#" + cid + " ." + this.tdClass + "-";
36108 this.hdSelector = "#" + cid + " ." + this.hdClass + "-";
36109 this.splitSelector = "#" + cid + " ." + this.splitClass + "-";
36112 getColumnRenderers : function(){
36113 var renderers = [];
36114 var cm = this.grid.colModel;
36115 var colCount = cm.getColumnCount();
36116 for(var i = 0; i < colCount; i++){
36117 renderers[i] = cm.getRenderer(i);
36122 getColumnIds : function(){
36124 var cm = this.grid.colModel;
36125 var colCount = cm.getColumnCount();
36126 for(var i = 0; i < colCount; i++){
36127 ids[i] = cm.getColumnId(i);
36132 getDataIndexes : function(){
36133 if(!this.indexMap){
36134 this.indexMap = this.buildIndexMap();
36136 return this.indexMap.colToData;
36139 getColumnIndexByDataIndex : function(dataIndex){
36140 if(!this.indexMap){
36141 this.indexMap = this.buildIndexMap();
36143 return this.indexMap.dataToCol[dataIndex];
36147 * Set a css style for a column dynamically.
36148 * @param {Number} colIndex The index of the column
36149 * @param {String} name The css property name
36150 * @param {String} value The css value
36152 setCSSStyle : function(colIndex, name, value){
36153 var selector = "#" + this.grid.id + " .x-grid-col-" + colIndex;
36154 Roo.util.CSS.updateRule(selector, name, value);
36157 generateRules : function(cm){
36158 var ruleBuf = [], rulesId = this.grid.id + '-cssrules';
36159 Roo.util.CSS.removeStyleSheet(rulesId);
36160 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
36161 var cid = cm.getColumnId(i);
36162 ruleBuf.push(this.colSelector, cid, " {\n", cm.config[i].css, "}\n",
36163 this.tdSelector, cid, " {\n}\n",
36164 this.hdSelector, cid, " {\n}\n",
36165 this.splitSelector, cid, " {\n}\n");
36167 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
36171 * Ext JS Library 1.1.1
36172 * Copyright(c) 2006-2007, Ext JS, LLC.
36174 * Originally Released Under LGPL - original licence link has changed is not relivant.
36177 * <script type="text/javascript">
36181 // This is a support class used internally by the Grid components
36182 Roo.grid.HeaderDragZone = function(grid, hd, hd2){
36184 this.view = grid.getView();
36185 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
36186 Roo.grid.HeaderDragZone.superclass.constructor.call(this, hd);
36188 this.setHandleElId(Roo.id(hd));
36189 this.setOuterHandleElId(Roo.id(hd2));
36191 this.scroll = false;
36193 Roo.extend(Roo.grid.HeaderDragZone, Roo.dd.DragZone, {
36195 getDragData : function(e){
36196 var t = Roo.lib.Event.getTarget(e);
36197 var h = this.view.findHeaderCell(t);
36199 return {ddel: h.firstChild, header:h};
36204 onInitDrag : function(e){
36205 this.view.headersDisabled = true;
36206 var clone = this.dragData.ddel.cloneNode(true);
36207 clone.id = Roo.id();
36208 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
36209 this.proxy.update(clone);
36213 afterValidDrop : function(){
36215 setTimeout(function(){
36216 v.headersDisabled = false;
36220 afterInvalidDrop : function(){
36222 setTimeout(function(){
36223 v.headersDisabled = false;
36229 * Ext JS Library 1.1.1
36230 * Copyright(c) 2006-2007, Ext JS, LLC.
36232 * Originally Released Under LGPL - original licence link has changed is not relivant.
36235 * <script type="text/javascript">
36238 // This is a support class used internally by the Grid components
36239 Roo.grid.HeaderDropZone = function(grid, hd, hd2){
36241 this.view = grid.getView();
36242 // split the proxies so they don't interfere with mouse events
36243 this.proxyTop = Roo.DomHelper.append(document.body, {
36244 cls:"col-move-top", html:" "
36246 this.proxyBottom = Roo.DomHelper.append(document.body, {
36247 cls:"col-move-bottom", html:" "
36249 this.proxyTop.hide = this.proxyBottom.hide = function(){
36250 this.setLeftTop(-100,-100);
36251 this.setStyle("visibility", "hidden");
36253 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
36254 // temporarily disabled
36255 //Roo.dd.ScrollManager.register(this.view.scroller.dom);
36256 Roo.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
36258 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
36259 proxyOffsets : [-4, -9],
36260 fly: Roo.Element.fly,
36262 getTargetFromEvent : function(e){
36263 var t = Roo.lib.Event.getTarget(e);
36264 var cindex = this.view.findCellIndex(t);
36265 if(cindex !== false){
36266 return this.view.getHeaderCell(cindex);
36271 nextVisible : function(h){
36272 var v = this.view, cm = this.grid.colModel;
36275 if(!cm.isHidden(v.getCellIndex(h))){
36283 prevVisible : function(h){
36284 var v = this.view, cm = this.grid.colModel;
36287 if(!cm.isHidden(v.getCellIndex(h))){
36295 positionIndicator : function(h, n, e){
36296 var x = Roo.lib.Event.getPageX(e);
36297 var r = Roo.lib.Dom.getRegion(n.firstChild);
36298 var px, pt, py = r.top + this.proxyOffsets[1];
36299 if((r.right - x) <= (r.right-r.left)/2){
36300 px = r.right+this.view.borderWidth;
36306 var oldIndex = this.view.getCellIndex(h);
36307 var newIndex = this.view.getCellIndex(n);
36309 if(this.grid.colModel.isFixed(newIndex)){
36313 var locked = this.grid.colModel.isLocked(newIndex);
36318 if(oldIndex < newIndex){
36321 if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){
36324 px += this.proxyOffsets[0];
36325 this.proxyTop.setLeftTop(px, py);
36326 this.proxyTop.show();
36327 if(!this.bottomOffset){
36328 this.bottomOffset = this.view.mainHd.getHeight();
36330 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
36331 this.proxyBottom.show();
36335 onNodeEnter : function(n, dd, e, data){
36336 if(data.header != n){
36337 this.positionIndicator(data.header, n, e);
36341 onNodeOver : function(n, dd, e, data){
36342 var result = false;
36343 if(data.header != n){
36344 result = this.positionIndicator(data.header, n, e);
36347 this.proxyTop.hide();
36348 this.proxyBottom.hide();
36350 return result ? this.dropAllowed : this.dropNotAllowed;
36353 onNodeOut : function(n, dd, e, data){
36354 this.proxyTop.hide();
36355 this.proxyBottom.hide();
36358 onNodeDrop : function(n, dd, e, data){
36359 var h = data.header;
36361 var cm = this.grid.colModel;
36362 var x = Roo.lib.Event.getPageX(e);
36363 var r = Roo.lib.Dom.getRegion(n.firstChild);
36364 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
36365 var oldIndex = this.view.getCellIndex(h);
36366 var newIndex = this.view.getCellIndex(n);
36367 var locked = cm.isLocked(newIndex);
36371 if(oldIndex < newIndex){
36374 if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){
36377 cm.setLocked(oldIndex, locked, true);
36378 cm.moveColumn(oldIndex, newIndex);
36379 this.grid.fireEvent("columnmove", oldIndex, newIndex);
36387 * Ext JS Library 1.1.1
36388 * Copyright(c) 2006-2007, Ext JS, LLC.
36390 * Originally Released Under LGPL - original licence link has changed is not relivant.
36393 * <script type="text/javascript">
36397 * @class Roo.grid.GridView
36398 * @extends Roo.util.Observable
36401 * @param {Object} config
36403 Roo.grid.GridView = function(config){
36404 Roo.grid.GridView.superclass.constructor.call(this);
36407 Roo.apply(this, config);
36410 Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
36412 unselectable : 'unselectable="on"',
36413 unselectableCls : 'x-unselectable',
36416 rowClass : "x-grid-row",
36418 cellClass : "x-grid-col",
36420 tdClass : "x-grid-td",
36422 hdClass : "x-grid-hd",
36424 splitClass : "x-grid-split",
36426 sortClasses : ["sort-asc", "sort-desc"],
36428 enableMoveAnim : false,
36432 dh : Roo.DomHelper,
36434 fly : Roo.Element.fly,
36436 css : Roo.util.CSS,
36442 scrollIncrement : 22,
36444 cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
36446 findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
36448 bind : function(ds, cm){
36450 this.ds.un("load", this.onLoad, this);
36451 this.ds.un("datachanged", this.onDataChange, this);
36452 this.ds.un("add", this.onAdd, this);
36453 this.ds.un("remove", this.onRemove, this);
36454 this.ds.un("update", this.onUpdate, this);
36455 this.ds.un("clear", this.onClear, this);
36458 ds.on("load", this.onLoad, this);
36459 ds.on("datachanged", this.onDataChange, this);
36460 ds.on("add", this.onAdd, this);
36461 ds.on("remove", this.onRemove, this);
36462 ds.on("update", this.onUpdate, this);
36463 ds.on("clear", this.onClear, this);
36468 this.cm.un("widthchange", this.onColWidthChange, this);
36469 this.cm.un("headerchange", this.onHeaderChange, this);
36470 this.cm.un("hiddenchange", this.onHiddenChange, this);
36471 this.cm.un("columnmoved", this.onColumnMove, this);
36472 this.cm.un("columnlockchange", this.onColumnLock, this);
36475 this.generateRules(cm);
36476 cm.on("widthchange", this.onColWidthChange, this);
36477 cm.on("headerchange", this.onHeaderChange, this);
36478 cm.on("hiddenchange", this.onHiddenChange, this);
36479 cm.on("columnmoved", this.onColumnMove, this);
36480 cm.on("columnlockchange", this.onColumnLock, this);
36485 init: function(grid){
36486 Roo.grid.GridView.superclass.init.call(this, grid);
36488 this.bind(grid.dataSource, grid.colModel);
36490 grid.on("headerclick", this.handleHeaderClick, this);
36492 if(grid.trackMouseOver){
36493 grid.on("mouseover", this.onRowOver, this);
36494 grid.on("mouseout", this.onRowOut, this);
36496 grid.cancelTextSelection = function(){};
36497 this.gridId = grid.id;
36499 var tpls = this.templates || {};
36502 tpls.master = new Roo.Template(
36503 '<div class="x-grid" hidefocus="true">',
36504 '<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
36505 '<div class="x-grid-topbar"></div>',
36506 '<div class="x-grid-scroller"><div></div></div>',
36507 '<div class="x-grid-locked">',
36508 '<div class="x-grid-header">{lockedHeader}</div>',
36509 '<div class="x-grid-body">{lockedBody}</div>',
36511 '<div class="x-grid-viewport">',
36512 '<div class="x-grid-header">{header}</div>',
36513 '<div class="x-grid-body">{body}</div>',
36515 '<div class="x-grid-bottombar"></div>',
36517 '<div class="x-grid-resize-proxy"> </div>',
36520 tpls.master.disableformats = true;
36524 tpls.header = new Roo.Template(
36525 '<table border="0" cellspacing="0" cellpadding="0">',
36526 '<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
36529 tpls.header.disableformats = true;
36531 tpls.header.compile();
36534 tpls.hcell = new Roo.Template(
36535 '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
36536 '<div class="x-grid-hd-text ' + this.unselectableCls + '" ' + this.unselectable +'>{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
36539 tpls.hcell.disableFormats = true;
36541 tpls.hcell.compile();
36544 tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style} ' +
36545 this.unselectableCls + '" ' + this.unselectable +'> </div>');
36546 tpls.hsplit.disableFormats = true;
36548 tpls.hsplit.compile();
36551 tpls.body = new Roo.Template(
36552 '<table border="0" cellspacing="0" cellpadding="0">',
36553 "<tbody>{rows}</tbody>",
36556 tpls.body.disableFormats = true;
36558 tpls.body.compile();
36561 tpls.row = new Roo.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
36562 tpls.row.disableFormats = true;
36564 tpls.row.compile();
36567 tpls.cell = new Roo.Template(
36568 '<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
36569 '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text ' +
36570 this.unselectableCls + '" ' + this.unselectable +'" {attr}>{value}</div></div>',
36573 tpls.cell.disableFormats = true;
36575 tpls.cell.compile();
36577 this.templates = tpls;
36580 // remap these for backwards compat
36581 onColWidthChange : function(){
36582 this.updateColumns.apply(this, arguments);
36584 onHeaderChange : function(){
36585 this.updateHeaders.apply(this, arguments);
36587 onHiddenChange : function(){
36588 this.handleHiddenChange.apply(this, arguments);
36590 onColumnMove : function(){
36591 this.handleColumnMove.apply(this, arguments);
36593 onColumnLock : function(){
36594 this.handleLockChange.apply(this, arguments);
36597 onDataChange : function(){
36599 this.updateHeaderSortState();
36602 onClear : function(){
36606 onUpdate : function(ds, record){
36607 this.refreshRow(record);
36610 refreshRow : function(record){
36611 var ds = this.ds, index;
36612 if(typeof record == 'number'){
36614 record = ds.getAt(index);
36616 index = ds.indexOf(record);
36618 this.insertRows(ds, index, index, true);
36619 this.onRemove(ds, record, index+1, true);
36620 this.syncRowHeights(index, index);
36622 this.fireEvent("rowupdated", this, index, record);
36625 onAdd : function(ds, records, index){
36626 this.insertRows(ds, index, index + (records.length-1));
36629 onRemove : function(ds, record, index, isUpdate){
36630 if(isUpdate !== true){
36631 this.fireEvent("beforerowremoved", this, index, record);
36633 var bt = this.getBodyTable(), lt = this.getLockedTable();
36634 if(bt.rows[index]){
36635 bt.firstChild.removeChild(bt.rows[index]);
36637 if(lt.rows[index]){
36638 lt.firstChild.removeChild(lt.rows[index]);
36640 if(isUpdate !== true){
36641 this.stripeRows(index);
36642 this.syncRowHeights(index, index);
36644 this.fireEvent("rowremoved", this, index, record);
36648 onLoad : function(){
36649 this.scrollToTop();
36653 * Scrolls the grid to the top
36655 scrollToTop : function(){
36657 this.scroller.dom.scrollTop = 0;
36663 * Gets a panel in the header of the grid that can be used for toolbars etc.
36664 * After modifying the contents of this panel a call to grid.autoSize() may be
36665 * required to register any changes in size.
36666 * @param {Boolean} doShow By default the header is hidden. Pass true to show the panel
36667 * @return Roo.Element
36669 getHeaderPanel : function(doShow){
36671 this.headerPanel.show();
36673 return this.headerPanel;
36677 * Gets a panel in the footer of the grid that can be used for toolbars etc.
36678 * After modifying the contents of this panel a call to grid.autoSize() may be
36679 * required to register any changes in size.
36680 * @param {Boolean} doShow By default the footer is hidden. Pass true to show the panel
36681 * @return Roo.Element
36683 getFooterPanel : function(doShow){
36685 this.footerPanel.show();
36687 return this.footerPanel;
36690 initElements : function(){
36691 var E = Roo.Element;
36692 var el = this.grid.getGridEl().dom.firstChild;
36693 var cs = el.childNodes;
36695 this.el = new E(el);
36697 this.focusEl = new E(el.firstChild);
36698 this.focusEl.swallowEvent("click", true);
36700 this.headerPanel = new E(cs[1]);
36701 this.headerPanel.enableDisplayMode("block");
36703 this.scroller = new E(cs[2]);
36704 this.scrollSizer = new E(this.scroller.dom.firstChild);
36706 this.lockedWrap = new E(cs[3]);
36707 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
36708 this.lockedBody = new E(this.lockedWrap.dom.childNodes[1]);
36710 this.mainWrap = new E(cs[4]);
36711 this.mainHd = new E(this.mainWrap.dom.firstChild);
36712 this.mainBody = new E(this.mainWrap.dom.childNodes[1]);
36714 this.footerPanel = new E(cs[5]);
36715 this.footerPanel.enableDisplayMode("block");
36717 this.resizeProxy = new E(cs[6]);
36719 this.headerSelector = String.format(
36720 '#{0} td.x-grid-hd, #{1} td.x-grid-hd',
36721 this.lockedHd.id, this.mainHd.id
36724 this.splitterSelector = String.format(
36725 '#{0} div.x-grid-split, #{1} div.x-grid-split',
36726 this.idToCssName(this.lockedHd.id), this.idToCssName(this.mainHd.id)
36729 idToCssName : function(s)
36731 return s.replace(/[^a-z0-9]+/ig, '-');
36734 getHeaderCell : function(index){
36735 return Roo.DomQuery.select(this.headerSelector)[index];
36738 getHeaderCellMeasure : function(index){
36739 return this.getHeaderCell(index).firstChild;
36742 getHeaderCellText : function(index){
36743 return this.getHeaderCell(index).firstChild.firstChild;
36746 getLockedTable : function(){
36747 return this.lockedBody.dom.firstChild;
36750 getBodyTable : function(){
36751 return this.mainBody.dom.firstChild;
36754 getLockedRow : function(index){
36755 return this.getLockedTable().rows[index];
36758 getRow : function(index){
36759 return this.getBodyTable().rows[index];
36762 getRowComposite : function(index){
36764 this.rowEl = new Roo.CompositeElementLite();
36766 var els = [], lrow, mrow;
36767 if(lrow = this.getLockedRow(index)){
36770 if(mrow = this.getRow(index)){
36773 this.rowEl.elements = els;
36777 * Gets the 'td' of the cell
36779 * @param {Integer} rowIndex row to select
36780 * @param {Integer} colIndex column to select
36784 getCell : function(rowIndex, colIndex){
36785 var locked = this.cm.getLockedCount();
36787 if(colIndex < locked){
36788 source = this.lockedBody.dom.firstChild;
36790 source = this.mainBody.dom.firstChild;
36791 colIndex -= locked;
36793 return source.rows[rowIndex].childNodes[colIndex];
36796 getCellText : function(rowIndex, colIndex){
36797 return this.getCell(rowIndex, colIndex).firstChild.firstChild;
36800 getCellBox : function(cell){
36801 var b = this.fly(cell).getBox();
36802 if(Roo.isOpera){ // opera fails to report the Y
36803 b.y = cell.offsetTop + this.mainBody.getY();
36808 getCellIndex : function(cell){
36809 var id = String(cell.className).match(this.cellRE);
36811 return parseInt(id[1], 10);
36816 findHeaderIndex : function(n){
36817 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
36818 return r ? this.getCellIndex(r) : false;
36821 findHeaderCell : function(n){
36822 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
36823 return r ? r : false;
36826 findRowIndex : function(n){
36830 var r = Roo.fly(n).findParent("tr." + this.rowClass, 6);
36831 return r ? r.rowIndex : false;
36834 findCellIndex : function(node){
36835 var stop = this.el.dom;
36836 while(node && node != stop){
36837 if(this.findRE.test(node.className)){
36838 return this.getCellIndex(node);
36840 node = node.parentNode;
36845 getColumnId : function(index){
36846 return this.cm.getColumnId(index);
36849 getSplitters : function()
36851 if(this.splitterSelector){
36852 return Roo.DomQuery.select(this.splitterSelector);
36858 getSplitter : function(index){
36859 return this.getSplitters()[index];
36862 onRowOver : function(e, t){
36864 if((row = this.findRowIndex(t)) !== false){
36865 this.getRowComposite(row).addClass("x-grid-row-over");
36869 onRowOut : function(e, t){
36871 if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){
36872 this.getRowComposite(row).removeClass("x-grid-row-over");
36876 renderHeaders : function(){
36878 var ct = this.templates.hcell, ht = this.templates.header, st = this.templates.hsplit;
36879 var cb = [], lb = [], sb = [], lsb = [], p = {};
36880 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
36881 p.cellId = "x-grid-hd-0-" + i;
36882 p.splitId = "x-grid-csplit-0-" + i;
36883 p.id = cm.getColumnId(i);
36884 p.title = cm.getColumnTooltip(i) || "";
36885 p.value = cm.getColumnHeader(i) || "";
36886 p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
36887 if(!cm.isLocked(i)){
36888 cb[cb.length] = ct.apply(p);
36889 sb[sb.length] = st.apply(p);
36891 lb[lb.length] = ct.apply(p);
36892 lsb[lsb.length] = st.apply(p);
36895 return [ht.apply({cells: lb.join(""), splits:lsb.join("")}),
36896 ht.apply({cells: cb.join(""), splits:sb.join("")})];
36899 updateHeaders : function(){
36900 var html = this.renderHeaders();
36901 this.lockedHd.update(html[0]);
36902 this.mainHd.update(html[1]);
36906 * Focuses the specified row.
36907 * @param {Number} row The row index
36909 focusRow : function(row)
36911 //Roo.log('GridView.focusRow');
36912 var x = this.scroller.dom.scrollLeft;
36913 this.focusCell(row, 0, false);
36914 this.scroller.dom.scrollLeft = x;
36918 * Focuses the specified cell.
36919 * @param {Number} row The row index
36920 * @param {Number} col The column index
36921 * @param {Boolean} hscroll false to disable horizontal scrolling
36923 focusCell : function(row, col, hscroll)
36925 //Roo.log('GridView.focusCell');
36926 var el = this.ensureVisible(row, col, hscroll);
36927 this.focusEl.alignTo(el, "tl-tl");
36929 this.focusEl.focus();
36931 this.focusEl.focus.defer(1, this.focusEl);
36936 * Scrolls the specified cell into view
36937 * @param {Number} row The row index
36938 * @param {Number} col The column index
36939 * @param {Boolean} hscroll false to disable horizontal scrolling
36941 ensureVisible : function(row, col, hscroll)
36943 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
36944 //return null; //disable for testing.
36945 if(typeof row != "number"){
36946 row = row.rowIndex;
36948 if(row < 0 && row >= this.ds.getCount()){
36951 col = (col !== undefined ? col : 0);
36952 var cm = this.grid.colModel;
36953 while(cm.isHidden(col)){
36957 var el = this.getCell(row, col);
36961 var c = this.scroller.dom;
36963 var ctop = parseInt(el.offsetTop, 10);
36964 var cleft = parseInt(el.offsetLeft, 10);
36965 var cbot = ctop + el.offsetHeight;
36966 var cright = cleft + el.offsetWidth;
36968 var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
36969 var stop = parseInt(c.scrollTop, 10);
36970 var sleft = parseInt(c.scrollLeft, 10);
36971 var sbot = stop + ch;
36972 var sright = sleft + c.clientWidth;
36974 Roo.log('GridView.ensureVisible:' +
36976 ' c.clientHeight:' + c.clientHeight +
36977 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
36985 c.scrollTop = ctop;
36986 //Roo.log("set scrolltop to ctop DISABLE?");
36987 }else if(cbot > sbot){
36988 //Roo.log("set scrolltop to cbot-ch");
36989 c.scrollTop = cbot-ch;
36992 if(hscroll !== false){
36994 c.scrollLeft = cleft;
36995 }else if(cright > sright){
36996 c.scrollLeft = cright-c.clientWidth;
37003 updateColumns : function(){
37004 this.grid.stopEditing();
37005 var cm = this.grid.colModel, colIds = this.getColumnIds();
37006 //var totalWidth = cm.getTotalWidth();
37008 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
37009 //if(cm.isHidden(i)) continue;
37010 var w = cm.getColumnWidth(i);
37011 this.css.updateRule(this.colSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
37012 this.css.updateRule(this.hdSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
37014 this.updateSplitters();
37017 generateRules : function(cm){
37018 var ruleBuf = [], rulesId = this.idToCssName(this.grid.id)+ '-cssrules';
37019 Roo.util.CSS.removeStyleSheet(rulesId);
37020 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
37021 var cid = cm.getColumnId(i);
37023 if(cm.config[i].align){
37024 align = 'text-align:'+cm.config[i].align+';';
37027 if(cm.isHidden(i)){
37028 hidden = 'display:none;';
37030 var width = "width:" + (cm.getColumnWidth(i) - this.borderWidth) + "px;";
37032 this.colSelector, cid, " {\n", cm.config[i].css, align, width, "\n}\n",
37033 this.hdSelector, cid, " {\n", align, width, "}\n",
37034 this.tdSelector, cid, " {\n",hidden,"\n}\n",
37035 this.splitSelector, cid, " {\n", hidden , "\n}\n");
37037 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
37040 updateSplitters : function(){
37041 var cm = this.cm, s = this.getSplitters();
37042 if(s){ // splitters not created yet
37043 var pos = 0, locked = true;
37044 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
37045 if(cm.isHidden(i)) continue;
37046 var w = cm.getColumnWidth(i); // make sure it's a number
37047 if(!cm.isLocked(i) && locked){
37052 s[i].style.left = (pos-this.splitOffset) + "px";
37057 handleHiddenChange : function(colModel, colIndex, hidden){
37059 this.hideColumn(colIndex);
37061 this.unhideColumn(colIndex);
37065 hideColumn : function(colIndex){
37066 var cid = this.getColumnId(colIndex);
37067 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "none");
37068 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "none");
37070 this.updateHeaders();
37072 this.updateSplitters();
37076 unhideColumn : function(colIndex){
37077 var cid = this.getColumnId(colIndex);
37078 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "");
37079 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "");
37082 this.updateHeaders();
37084 this.updateSplitters();
37088 insertRows : function(dm, firstRow, lastRow, isUpdate){
37089 if(firstRow == 0 && lastRow == dm.getCount()-1){
37093 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
37095 var s = this.getScrollState();
37096 var markup = this.renderRows(firstRow, lastRow);
37097 this.bufferRows(markup[0], this.getLockedTable(), firstRow);
37098 this.bufferRows(markup[1], this.getBodyTable(), firstRow);
37099 this.restoreScroll(s);
37101 this.fireEvent("rowsinserted", this, firstRow, lastRow);
37102 this.syncRowHeights(firstRow, lastRow);
37103 this.stripeRows(firstRow);
37109 bufferRows : function(markup, target, index){
37110 var before = null, trows = target.rows, tbody = target.tBodies[0];
37111 if(index < trows.length){
37112 before = trows[index];
37114 var b = document.createElement("div");
37115 b.innerHTML = "<table><tbody>"+markup+"</tbody></table>";
37116 var rows = b.firstChild.rows;
37117 for(var i = 0, len = rows.length; i < len; i++){
37119 tbody.insertBefore(rows[0], before);
37121 tbody.appendChild(rows[0]);
37128 deleteRows : function(dm, firstRow, lastRow){
37129 if(dm.getRowCount()<1){
37130 this.fireEvent("beforerefresh", this);
37131 this.mainBody.update("");
37132 this.lockedBody.update("");
37133 this.fireEvent("refresh", this);
37135 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
37136 var bt = this.getBodyTable();
37137 var tbody = bt.firstChild;
37138 var rows = bt.rows;
37139 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
37140 tbody.removeChild(rows[firstRow]);
37142 this.stripeRows(firstRow);
37143 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
37147 updateRows : function(dataSource, firstRow, lastRow){
37148 var s = this.getScrollState();
37150 this.restoreScroll(s);
37153 handleSort : function(dataSource, sortColumnIndex, sortDir, noRefresh){
37157 this.updateHeaderSortState();
37160 getScrollState : function(){
37162 var sb = this.scroller.dom;
37163 return {left: sb.scrollLeft, top: sb.scrollTop};
37166 stripeRows : function(startRow){
37167 if(!this.grid.stripeRows || this.ds.getCount() < 1){
37170 startRow = startRow || 0;
37171 var rows = this.getBodyTable().rows;
37172 var lrows = this.getLockedTable().rows;
37173 var cls = ' x-grid-row-alt ';
37174 for(var i = startRow, len = rows.length; i < len; i++){
37175 var row = rows[i], lrow = lrows[i];
37176 var isAlt = ((i+1) % 2 == 0);
37177 var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
37178 if(isAlt == hasAlt){
37182 row.className += " x-grid-row-alt";
37184 row.className = row.className.replace("x-grid-row-alt", "");
37187 lrow.className = row.className;
37192 restoreScroll : function(state){
37193 //Roo.log('GridView.restoreScroll');
37194 var sb = this.scroller.dom;
37195 sb.scrollLeft = state.left;
37196 sb.scrollTop = state.top;
37200 syncScroll : function(){
37201 //Roo.log('GridView.syncScroll');
37202 var sb = this.scroller.dom;
37203 var sh = this.mainHd.dom;
37204 var bs = this.mainBody.dom;
37205 var lv = this.lockedBody.dom;
37206 sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
37207 lv.scrollTop = bs.scrollTop = sb.scrollTop;
37210 handleScroll : function(e){
37212 var sb = this.scroller.dom;
37213 this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
37217 handleWheel : function(e){
37218 var d = e.getWheelDelta();
37219 this.scroller.dom.scrollTop -= d*22;
37220 // set this here to prevent jumpy scrolling on large tables
37221 this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
37225 renderRows : function(startRow, endRow){
37226 // pull in all the crap needed to render rows
37227 var g = this.grid, cm = g.colModel, ds = g.dataSource, stripe = g.stripeRows;
37228 var colCount = cm.getColumnCount();
37230 if(ds.getCount() < 1){
37234 // build a map for all the columns
37236 for(var i = 0; i < colCount; i++){
37237 var name = cm.getDataIndex(i);
37239 name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
37240 renderer : cm.getRenderer(i),
37241 id : cm.getColumnId(i),
37242 locked : cm.isLocked(i)
37246 startRow = startRow || 0;
37247 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
37249 // records to render
37250 var rs = ds.getRange(startRow, endRow);
37252 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
37255 // As much as I hate to duplicate code, this was branched because FireFox really hates
37256 // [].join("") on strings. The performance difference was substantial enough to
37257 // branch this function
37258 doRender : Roo.isGecko ?
37259 function(cs, rs, ds, startRow, colCount, stripe){
37260 var ts = this.templates, ct = ts.cell, rt = ts.row;
37262 var buf = "", lbuf = "", cb, lcb, c, p = {}, rp = {}, r, rowIndex;
37264 var hasListener = this.grid.hasListener('rowclass');
37266 for(var j = 0, len = rs.length; j < len; j++){
37267 r = rs[j]; cb = ""; lcb = ""; rowIndex = (j+startRow);
37268 for(var i = 0; i < colCount; i++){
37270 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
37272 p.css = p.attr = "";
37273 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
37274 if(p.value == undefined || p.value === "") p.value = " ";
37275 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
37276 p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
37278 var markup = ct.apply(p);
37286 if(stripe && ((rowIndex+1) % 2 == 0)){
37287 alt.push("x-grid-row-alt")
37290 alt.push( " x-grid-dirty-row");
37293 if(this.getRowClass){
37294 alt.push(this.getRowClass(r, rowIndex));
37300 rowIndex : rowIndex,
37303 this.grid.fireEvent('rowclass', this, rowcfg);
37304 alt.push(rowcfg.rowClass);
37306 rp.alt = alt.join(" ");
37307 lbuf+= rt.apply(rp);
37309 buf+= rt.apply(rp);
37311 return [lbuf, buf];
37313 function(cs, rs, ds, startRow, colCount, stripe){
37314 var ts = this.templates, ct = ts.cell, rt = ts.row;
37316 var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
37317 var hasListener = this.grid.hasListener('rowclass');
37320 for(var j = 0, len = rs.length; j < len; j++){
37321 r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
37322 for(var i = 0; i < colCount; i++){
37324 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
37326 p.css = p.attr = "";
37327 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
37328 if(p.value == undefined || p.value === "") p.value = " ";
37329 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
37330 p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
37333 var markup = ct.apply(p);
37335 cb[cb.length] = markup;
37337 lcb[lcb.length] = markup;
37341 if(stripe && ((rowIndex+1) % 2 == 0)){
37342 alt.push( "x-grid-row-alt");
37345 alt.push(" x-grid-dirty-row");
37348 if(this.getRowClass){
37349 alt.push( this.getRowClass(r, rowIndex));
37355 rowIndex : rowIndex,
37358 this.grid.fireEvent('rowclass', this, rowcfg);
37359 alt.push(rowcfg.rowClass);
37361 rp.alt = alt.join(" ");
37362 rp.cells = lcb.join("");
37363 lbuf[lbuf.length] = rt.apply(rp);
37364 rp.cells = cb.join("");
37365 buf[buf.length] = rt.apply(rp);
37367 return [lbuf.join(""), buf.join("")];
37370 renderBody : function(){
37371 var markup = this.renderRows();
37372 var bt = this.templates.body;
37373 return [bt.apply({rows: markup[0]}), bt.apply({rows: markup[1]})];
37377 * Refreshes the grid
37378 * @param {Boolean} headersToo
37380 refresh : function(headersToo){
37381 this.fireEvent("beforerefresh", this);
37382 this.grid.stopEditing();
37383 var result = this.renderBody();
37384 this.lockedBody.update(result[0]);
37385 this.mainBody.update(result[1]);
37386 if(headersToo === true){
37387 this.updateHeaders();
37388 this.updateColumns();
37389 this.updateSplitters();
37390 this.updateHeaderSortState();
37392 this.syncRowHeights();
37394 this.fireEvent("refresh", this);
37397 handleColumnMove : function(cm, oldIndex, newIndex){
37398 this.indexMap = null;
37399 var s = this.getScrollState();
37400 this.refresh(true);
37401 this.restoreScroll(s);
37402 this.afterMove(newIndex);
37405 afterMove : function(colIndex){
37406 if(this.enableMoveAnim && Roo.enableFx){
37407 this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
37409 // if multisort - fix sortOrder, and reload..
37410 if (this.grid.dataSource.multiSort) {
37411 // the we can call sort again..
37412 var dm = this.grid.dataSource;
37413 var cm = this.grid.colModel;
37415 for(var i = 0; i < cm.config.length; i++ ) {
37417 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined')) {
37418 continue; // dont' bother, it's not in sort list or being set.
37421 so.push(cm.config[i].dataIndex);
37424 dm.load(dm.lastOptions);
37431 updateCell : function(dm, rowIndex, dataIndex){
37432 var colIndex = this.getColumnIndexByDataIndex(dataIndex);
37433 if(typeof colIndex == "undefined"){ // not present in grid
37436 var cm = this.grid.colModel;
37437 var cell = this.getCell(rowIndex, colIndex);
37438 var cellText = this.getCellText(rowIndex, colIndex);
37441 cellId : "x-grid-cell-" + rowIndex + "-" + colIndex,
37442 id : cm.getColumnId(colIndex),
37443 css: colIndex == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
37445 var renderer = cm.getRenderer(colIndex);
37446 var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
37447 if(typeof val == "undefined" || val === "") val = " ";
37448 cellText.innerHTML = val;
37449 cell.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
37450 this.syncRowHeights(rowIndex, rowIndex);
37453 calcColumnWidth : function(colIndex, maxRowsToMeasure){
37455 if(this.grid.autoSizeHeaders){
37456 var h = this.getHeaderCellMeasure(colIndex);
37457 maxWidth = Math.max(maxWidth, h.scrollWidth);
37460 if(this.cm.isLocked(colIndex)){
37461 tb = this.getLockedTable();
37464 tb = this.getBodyTable();
37465 index = colIndex - this.cm.getLockedCount();
37468 var rows = tb.rows;
37469 var stopIndex = Math.min(maxRowsToMeasure || rows.length, rows.length);
37470 for(var i = 0; i < stopIndex; i++){
37471 var cell = rows[i].childNodes[index].firstChild;
37472 maxWidth = Math.max(maxWidth, cell.scrollWidth);
37475 return maxWidth + /*margin for error in IE*/ 5;
37478 * Autofit a column to its content.
37479 * @param {Number} colIndex
37480 * @param {Boolean} forceMinSize true to force the column to go smaller if possible
37482 autoSizeColumn : function(colIndex, forceMinSize, suppressEvent){
37483 if(this.cm.isHidden(colIndex)){
37484 return; // can't calc a hidden column
37487 var cid = this.cm.getColumnId(colIndex);
37488 this.css.updateRule(this.colSelector +this.idToCssName( cid), "width", this.grid.minColumnWidth + "px");
37489 if(this.grid.autoSizeHeaders){
37490 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", this.grid.minColumnWidth + "px");
37493 var newWidth = this.calcColumnWidth(colIndex);
37494 this.cm.setColumnWidth(colIndex,
37495 Math.max(this.grid.minColumnWidth, newWidth), suppressEvent);
37496 if(!suppressEvent){
37497 this.grid.fireEvent("columnresize", colIndex, newWidth);
37502 * Autofits all columns to their content and then expands to fit any extra space in the grid
37504 autoSizeColumns : function(){
37505 var cm = this.grid.colModel;
37506 var colCount = cm.getColumnCount();
37507 for(var i = 0; i < colCount; i++){
37508 this.autoSizeColumn(i, true, true);
37510 if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
37513 this.updateColumns();
37519 * Autofits all columns to the grid's width proportionate with their current size
37520 * @param {Boolean} reserveScrollSpace Reserve space for a scrollbar
37522 fitColumns : function(reserveScrollSpace){
37523 var cm = this.grid.colModel;
37524 var colCount = cm.getColumnCount();
37528 for (i = 0; i < colCount; i++){
37529 if(!cm.isHidden(i) && !cm.isFixed(i)){
37530 w = cm.getColumnWidth(i);
37536 var avail = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
37537 if(reserveScrollSpace){
37540 var frac = (avail - cm.getTotalWidth())/width;
37541 while (cols.length){
37544 cm.setColumnWidth(i, Math.floor(w + w*frac), true);
37546 this.updateColumns();
37550 onRowSelect : function(rowIndex){
37551 var row = this.getRowComposite(rowIndex);
37552 row.addClass("x-grid-row-selected");
37555 onRowDeselect : function(rowIndex){
37556 var row = this.getRowComposite(rowIndex);
37557 row.removeClass("x-grid-row-selected");
37560 onCellSelect : function(row, col){
37561 var cell = this.getCell(row, col);
37563 Roo.fly(cell).addClass("x-grid-cell-selected");
37567 onCellDeselect : function(row, col){
37568 var cell = this.getCell(row, col);
37570 Roo.fly(cell).removeClass("x-grid-cell-selected");
37574 updateHeaderSortState : function(){
37576 // sort state can be single { field: xxx, direction : yyy}
37577 // or { xxx=>ASC , yyy : DESC ..... }
37580 if (!this.ds.multiSort) {
37581 var state = this.ds.getSortState();
37585 mstate[state.field] = state.direction;
37586 // FIXME... - this is not used here.. but might be elsewhere..
37587 this.sortState = state;
37590 mstate = this.ds.sortToggle;
37592 //remove existing sort classes..
37594 var sc = this.sortClasses;
37595 var hds = this.el.select(this.headerSelector).removeClass(sc);
37597 for(var f in mstate) {
37599 var sortColumn = this.cm.findColumnIndex(f);
37601 if(sortColumn != -1){
37602 var sortDir = mstate[f];
37603 hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
37612 handleHeaderClick : function(g, index){
37613 if(this.headersDisabled){
37616 var dm = g.dataSource, cm = g.colModel;
37617 if(!cm.isSortable(index)){
37622 if (dm.multiSort) {
37623 // update the sortOrder
37625 for(var i = 0; i < cm.config.length; i++ ) {
37627 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined') && (index != i)) {
37628 continue; // dont' bother, it's not in sort list or being set.
37631 so.push(cm.config[i].dataIndex);
37637 dm.sort(cm.getDataIndex(index));
37641 destroy : function(){
37643 this.colMenu.removeAll();
37644 Roo.menu.MenuMgr.unregister(this.colMenu);
37645 this.colMenu.getEl().remove();
37646 delete this.colMenu;
37649 this.hmenu.removeAll();
37650 Roo.menu.MenuMgr.unregister(this.hmenu);
37651 this.hmenu.getEl().remove();
37654 if(this.grid.enableColumnMove){
37655 var dds = Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
37657 for(var dd in dds){
37658 if(!dds[dd].config.isTarget && dds[dd].dragElId){
37659 var elid = dds[dd].dragElId;
37661 Roo.get(elid).remove();
37662 } else if(dds[dd].config.isTarget){
37663 dds[dd].proxyTop.remove();
37664 dds[dd].proxyBottom.remove();
37667 if(Roo.dd.DDM.locationCache[dd]){
37668 delete Roo.dd.DDM.locationCache[dd];
37671 delete Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
37674 Roo.util.CSS.removeStyleSheet(this.idToCssName(this.grid.id) + '-cssrules');
37675 this.bind(null, null);
37676 Roo.EventManager.removeResizeListener(this.onWindowResize, this);
37679 handleLockChange : function(){
37680 this.refresh(true);
37683 onDenyColumnLock : function(){
37687 onDenyColumnHide : function(){
37691 handleHdMenuClick : function(item){
37692 var index = this.hdCtxIndex;
37693 var cm = this.cm, ds = this.ds;
37696 ds.sort(cm.getDataIndex(index), "ASC");
37699 ds.sort(cm.getDataIndex(index), "DESC");
37702 var lc = cm.getLockedCount();
37703 if(cm.getColumnCount(true) <= lc+1){
37704 this.onDenyColumnLock();
37708 cm.setLocked(index, true, true);
37709 cm.moveColumn(index, lc);
37710 this.grid.fireEvent("columnmove", index, lc);
37712 cm.setLocked(index, true);
37716 var lc = cm.getLockedCount();
37717 if((lc-1) != index){
37718 cm.setLocked(index, false, true);
37719 cm.moveColumn(index, lc-1);
37720 this.grid.fireEvent("columnmove", index, lc-1);
37722 cm.setLocked(index, false);
37726 index = cm.getIndexById(item.id.substr(4));
37728 if(item.checked && cm.getColumnCount(true) <= 1){
37729 this.onDenyColumnHide();
37732 cm.setHidden(index, item.checked);
37738 beforeColMenuShow : function(){
37739 var cm = this.cm, colCount = cm.getColumnCount();
37740 this.colMenu.removeAll();
37741 for(var i = 0; i < colCount; i++){
37742 this.colMenu.add(new Roo.menu.CheckItem({
37743 id: "col-"+cm.getColumnId(i),
37744 text: cm.getColumnHeader(i),
37745 checked: !cm.isHidden(i),
37751 handleHdCtx : function(g, index, e){
37753 var hd = this.getHeaderCell(index);
37754 this.hdCtxIndex = index;
37755 var ms = this.hmenu.items, cm = this.cm;
37756 ms.get("asc").setDisabled(!cm.isSortable(index));
37757 ms.get("desc").setDisabled(!cm.isSortable(index));
37758 if(this.grid.enableColLock !== false){
37759 ms.get("lock").setDisabled(cm.isLocked(index));
37760 ms.get("unlock").setDisabled(!cm.isLocked(index));
37762 this.hmenu.show(hd, "tl-bl");
37765 handleHdOver : function(e){
37766 var hd = this.findHeaderCell(e.getTarget());
37767 if(hd && !this.headersDisabled){
37768 if(this.grid.colModel.isSortable(this.getCellIndex(hd))){
37769 this.fly(hd).addClass("x-grid-hd-over");
37774 handleHdOut : function(e){
37775 var hd = this.findHeaderCell(e.getTarget());
37777 this.fly(hd).removeClass("x-grid-hd-over");
37781 handleSplitDblClick : function(e, t){
37782 var i = this.getCellIndex(t);
37783 if(this.grid.enableColumnResize !== false && this.cm.isResizable(i) && !this.cm.isFixed(i)){
37784 this.autoSizeColumn(i, true);
37789 render : function(){
37792 var colCount = cm.getColumnCount();
37794 if(this.grid.monitorWindowResize === true){
37795 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
37797 var header = this.renderHeaders();
37798 var body = this.templates.body.apply({rows:""});
37799 var html = this.templates.master.apply({
37802 lockedHeader: header[0],
37806 //this.updateColumns();
37808 this.grid.getGridEl().dom.innerHTML = html;
37810 this.initElements();
37812 // a kludge to fix the random scolling effect in webkit
37813 this.el.on("scroll", function() {
37814 this.el.dom.scrollTop=0; // hopefully not recursive..
37817 this.scroller.on("scroll", this.handleScroll, this);
37818 this.lockedBody.on("mousewheel", this.handleWheel, this);
37819 this.mainBody.on("mousewheel", this.handleWheel, this);
37821 this.mainHd.on("mouseover", this.handleHdOver, this);
37822 this.mainHd.on("mouseout", this.handleHdOut, this);
37823 this.mainHd.on("dblclick", this.handleSplitDblClick, this,
37824 {delegate: "."+this.splitClass});
37826 this.lockedHd.on("mouseover", this.handleHdOver, this);
37827 this.lockedHd.on("mouseout", this.handleHdOut, this);
37828 this.lockedHd.on("dblclick", this.handleSplitDblClick, this,
37829 {delegate: "."+this.splitClass});
37831 if(this.grid.enableColumnResize !== false && Roo.grid.SplitDragZone){
37832 new Roo.grid.SplitDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
37835 this.updateSplitters();
37837 if(this.grid.enableColumnMove && Roo.grid.HeaderDragZone){
37838 new Roo.grid.HeaderDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
37839 new Roo.grid.HeaderDropZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
37842 if(this.grid.enableCtxMenu !== false && Roo.menu.Menu){
37843 this.hmenu = new Roo.menu.Menu({id: this.grid.id + "-hctx"});
37845 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
37846 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
37848 if(this.grid.enableColLock !== false){
37849 this.hmenu.add('-',
37850 {id:"lock", text: this.lockText, cls: "xg-hmenu-lock"},
37851 {id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
37854 if(this.grid.enableColumnHide !== false){
37856 this.colMenu = new Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
37857 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
37858 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
37860 this.hmenu.add('-',
37861 {id:"columns", text: this.columnsText, menu: this.colMenu}
37864 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
37866 this.grid.on("headercontextmenu", this.handleHdCtx, this);
37869 if((this.grid.enableDragDrop || this.grid.enableDrag) && Roo.grid.GridDragZone){
37870 this.dd = new Roo.grid.GridDragZone(this.grid, {
37871 ddGroup : this.grid.ddGroup || 'GridDD'
37877 for(var i = 0; i < colCount; i++){
37878 if(cm.isHidden(i)){
37879 this.hideColumn(i);
37881 if(cm.config[i].align){
37882 this.css.updateRule(this.colSelector + i, "textAlign", cm.config[i].align);
37883 this.css.updateRule(this.hdSelector + i, "textAlign", cm.config[i].align);
37887 this.updateHeaderSortState();
37889 this.beforeInitialResize();
37892 // two part rendering gives faster view to the user
37893 this.renderPhase2.defer(1, this);
37896 renderPhase2 : function(){
37897 // render the rows now
37899 if(this.grid.autoSizeColumns){
37900 this.autoSizeColumns();
37904 beforeInitialResize : function(){
37908 onColumnSplitterMoved : function(i, w){
37909 this.userResized = true;
37910 var cm = this.grid.colModel;
37911 cm.setColumnWidth(i, w, true);
37912 var cid = cm.getColumnId(i);
37913 this.css.updateRule(this.colSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
37914 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
37915 this.updateSplitters();
37917 this.grid.fireEvent("columnresize", i, w);
37920 syncRowHeights : function(startIndex, endIndex){
37921 if(this.grid.enableRowHeightSync === true && this.cm.getLockedCount() > 0){
37922 startIndex = startIndex || 0;
37923 var mrows = this.getBodyTable().rows;
37924 var lrows = this.getLockedTable().rows;
37925 var len = mrows.length-1;
37926 endIndex = Math.min(endIndex || len, len);
37927 for(var i = startIndex; i <= endIndex; i++){
37928 var m = mrows[i], l = lrows[i];
37929 var h = Math.max(m.offsetHeight, l.offsetHeight);
37930 m.style.height = l.style.height = h + "px";
37935 layout : function(initialRender, is2ndPass){
37937 var auto = g.autoHeight;
37938 var scrollOffset = 16;
37939 var c = g.getGridEl(), cm = this.cm,
37940 expandCol = g.autoExpandColumn,
37942 //c.beginMeasure();
37944 if(!c.dom.offsetWidth){ // display:none?
37946 this.lockedWrap.show();
37947 this.mainWrap.show();
37952 var hasLock = this.cm.isLocked(0);
37954 var tbh = this.headerPanel.getHeight();
37955 var bbh = this.footerPanel.getHeight();
37958 var ch = this.getBodyTable().offsetHeight + tbh + bbh + this.mainHd.getHeight();
37959 var newHeight = ch + c.getBorderWidth("tb");
37961 newHeight = Math.min(g.maxHeight, newHeight);
37963 c.setHeight(newHeight);
37967 c.setWidth(cm.getTotalWidth()+c.getBorderWidth('lr'));
37970 var s = this.scroller;
37972 var csize = c.getSize(true);
37974 this.el.setSize(csize.width, csize.height);
37976 this.headerPanel.setWidth(csize.width);
37977 this.footerPanel.setWidth(csize.width);
37979 var hdHeight = this.mainHd.getHeight();
37980 var vw = csize.width;
37981 var vh = csize.height - (tbh + bbh);
37985 var bt = this.getBodyTable();
37986 var ltWidth = hasLock ?
37987 Math.max(this.getLockedTable().offsetWidth, this.lockedHd.dom.firstChild.offsetWidth) : 0;
37989 var scrollHeight = bt.offsetHeight;
37990 var scrollWidth = ltWidth + bt.offsetWidth;
37991 var vscroll = false, hscroll = false;
37993 this.scrollSizer.setSize(scrollWidth, scrollHeight+hdHeight);
37995 var lw = this.lockedWrap, mw = this.mainWrap;
37996 var lb = this.lockedBody, mb = this.mainBody;
37998 setTimeout(function(){
37999 var t = s.dom.offsetTop;
38000 var w = s.dom.clientWidth,
38001 h = s.dom.clientHeight;
38004 lw.setSize(ltWidth, h);
38006 mw.setLeftTop(ltWidth, t);
38007 mw.setSize(w-ltWidth, h);
38009 lb.setHeight(h-hdHeight);
38010 mb.setHeight(h-hdHeight);
38012 if(is2ndPass !== true && !gv.userResized && expandCol){
38013 // high speed resize without full column calculation
38015 var ci = cm.getIndexById(expandCol);
38017 ci = cm.findColumnIndex(expandCol);
38019 ci = Math.max(0, ci); // make sure it's got at least the first col.
38020 var expandId = cm.getColumnId(ci);
38021 var tw = cm.getTotalWidth(false);
38022 var currentWidth = cm.getColumnWidth(ci);
38023 var cw = Math.min(Math.max(((w-tw)+currentWidth-2)-/*scrollbar*/(w <= s.dom.offsetWidth ? 0 : 18), g.autoExpandMin), g.autoExpandMax);
38024 if(currentWidth != cw){
38025 cm.setColumnWidth(ci, cw, true);
38026 gv.css.updateRule(gv.colSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
38027 gv.css.updateRule(gv.hdSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
38028 gv.updateSplitters();
38029 gv.layout(false, true);
38041 onWindowResize : function(){
38042 if(!this.grid.monitorWindowResize || this.grid.autoHeight){
38048 appendFooter : function(parentEl){
38052 sortAscText : "Sort Ascending",
38053 sortDescText : "Sort Descending",
38054 lockText : "Lock Column",
38055 unlockText : "Unlock Column",
38056 columnsText : "Columns"
38060 Roo.grid.GridView.ColumnDragZone = function(grid, hd){
38061 Roo.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
38062 this.proxy.el.addClass('x-grid3-col-dd');
38065 Roo.extend(Roo.grid.GridView.ColumnDragZone, Roo.grid.HeaderDragZone, {
38066 handleMouseDown : function(e){
38070 callHandleMouseDown : function(e){
38071 Roo.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
38076 * Ext JS Library 1.1.1
38077 * Copyright(c) 2006-2007, Ext JS, LLC.
38079 * Originally Released Under LGPL - original licence link has changed is not relivant.
38082 * <script type="text/javascript">
38086 // This is a support class used internally by the Grid components
38087 Roo.grid.SplitDragZone = function(grid, hd, hd2){
38089 this.view = grid.getView();
38090 this.proxy = this.view.resizeProxy;
38091 Roo.grid.SplitDragZone.superclass.constructor.call(this, hd,
38092 "gridSplitters" + this.grid.getGridEl().id, {
38093 dragElId : Roo.id(this.proxy.dom), resizeFrame:false
38095 this.setHandleElId(Roo.id(hd));
38096 this.setOuterHandleElId(Roo.id(hd2));
38097 this.scroll = false;
38099 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
38100 fly: Roo.Element.fly,
38102 b4StartDrag : function(x, y){
38103 this.view.headersDisabled = true;
38104 this.proxy.setHeight(this.view.mainWrap.getHeight());
38105 var w = this.cm.getColumnWidth(this.cellIndex);
38106 var minw = Math.max(w-this.grid.minColumnWidth, 0);
38107 this.resetConstraints();
38108 this.setXConstraint(minw, 1000);
38109 this.setYConstraint(0, 0);
38110 this.minX = x - minw;
38111 this.maxX = x + 1000;
38113 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
38117 handleMouseDown : function(e){
38118 ev = Roo.EventObject.setEvent(e);
38119 var t = this.fly(ev.getTarget());
38120 if(t.hasClass("x-grid-split")){
38121 this.cellIndex = this.view.getCellIndex(t.dom);
38122 this.split = t.dom;
38123 this.cm = this.grid.colModel;
38124 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
38125 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
38130 endDrag : function(e){
38131 this.view.headersDisabled = false;
38132 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
38133 var diff = endX - this.startPos;
38134 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
38137 autoOffset : function(){
38138 this.setDelta(0,0);
38142 * Ext JS Library 1.1.1
38143 * Copyright(c) 2006-2007, Ext JS, LLC.
38145 * Originally Released Under LGPL - original licence link has changed is not relivant.
38148 * <script type="text/javascript">
38152 // This is a support class used internally by the Grid components
38153 Roo.grid.GridDragZone = function(grid, config){
38154 this.view = grid.getView();
38155 Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
38156 if(this.view.lockedBody){
38157 this.setHandleElId(Roo.id(this.view.mainBody.dom));
38158 this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
38160 this.scroll = false;
38162 this.ddel = document.createElement('div');
38163 this.ddel.className = 'x-grid-dd-wrap';
38166 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
38167 ddGroup : "GridDD",
38169 getDragData : function(e){
38170 var t = Roo.lib.Event.getTarget(e);
38171 var rowIndex = this.view.findRowIndex(t);
38172 var sm = this.grid.selModel;
38174 //Roo.log(rowIndex);
38176 if (sm.getSelectedCell) {
38177 // cell selection..
38178 if (!sm.getSelectedCell()) {
38181 if (rowIndex != sm.getSelectedCell()[0]) {
38187 if(rowIndex !== false){
38192 //Roo.log([ sm.getSelectedCell() ? sm.getSelectedCell()[0] : 'NO' , rowIndex ]);
38194 //if(!sm.isSelected(rowIndex) || e.hasModifier()){
38197 if (e.hasModifier()){
38198 sm.handleMouseDown(e, t); // non modifier buttons are handled by row select.
38201 Roo.log("getDragData");
38206 rowIndex: rowIndex,
38207 selections:sm.getSelections ? sm.getSelections() : (
38208 sm.getSelectedCell() ? [ this.grid.ds.getAt(sm.getSelectedCell()[0]) ] : []
38215 onInitDrag : function(e){
38216 var data = this.dragData;
38217 this.ddel.innerHTML = this.grid.getDragDropText();
38218 this.proxy.update(this.ddel);
38219 // fire start drag?
38222 afterRepair : function(){
38223 this.dragging = false;
38226 getRepairXY : function(e, data){
38230 onEndDrag : function(data, e){
38234 onValidDrop : function(dd, e, id){
38239 beforeInvalidDrop : function(e, id){
38244 * Ext JS Library 1.1.1
38245 * Copyright(c) 2006-2007, Ext JS, LLC.
38247 * Originally Released Under LGPL - original licence link has changed is not relivant.
38250 * <script type="text/javascript">
38255 * @class Roo.grid.ColumnModel
38256 * @extends Roo.util.Observable
38257 * This is the default implementation of a ColumnModel used by the Grid. It defines
38258 * the columns in the grid.
38261 var colModel = new Roo.grid.ColumnModel([
38262 {header: "Ticker", width: 60, sortable: true, locked: true},
38263 {header: "Company Name", width: 150, sortable: true},
38264 {header: "Market Cap.", width: 100, sortable: true},
38265 {header: "$ Sales", width: 100, sortable: true, renderer: money},
38266 {header: "Employees", width: 100, sortable: true, resizable: false}
38271 * The config options listed for this class are options which may appear in each
38272 * individual column definition.
38273 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
38275 * @param {Object} config An Array of column config objects. See this class's
38276 * config objects for details.
38278 Roo.grid.ColumnModel = function(config){
38280 * The config passed into the constructor
38282 this.config = config;
38285 // if no id, create one
38286 // if the column does not have a dataIndex mapping,
38287 // map it to the order it is in the config
38288 for(var i = 0, len = config.length; i < len; i++){
38290 if(typeof c.dataIndex == "undefined"){
38293 if(typeof c.renderer == "string"){
38294 c.renderer = Roo.util.Format[c.renderer];
38296 if(typeof c.id == "undefined"){
38299 if(c.editor && c.editor.xtype){
38300 c.editor = Roo.factory(c.editor, Roo.grid);
38302 if(c.editor && c.editor.isFormField){
38303 c.editor = new Roo.grid.GridEditor(c.editor);
38305 this.lookup[c.id] = c;
38309 * The width of columns which have no width specified (defaults to 100)
38312 this.defaultWidth = 100;
38315 * Default sortable of columns which have no sortable specified (defaults to false)
38318 this.defaultSortable = false;
38322 * @event widthchange
38323 * Fires when the width of a column changes.
38324 * @param {ColumnModel} this
38325 * @param {Number} columnIndex The column index
38326 * @param {Number} newWidth The new width
38328 "widthchange": true,
38330 * @event headerchange
38331 * Fires when the text of a header changes.
38332 * @param {ColumnModel} this
38333 * @param {Number} columnIndex The column index
38334 * @param {Number} newText The new header text
38336 "headerchange": true,
38338 * @event hiddenchange
38339 * Fires when a column is hidden or "unhidden".
38340 * @param {ColumnModel} this
38341 * @param {Number} columnIndex The column index
38342 * @param {Boolean} hidden true if hidden, false otherwise
38344 "hiddenchange": true,
38346 * @event columnmoved
38347 * Fires when a column is moved.
38348 * @param {ColumnModel} this
38349 * @param {Number} oldIndex
38350 * @param {Number} newIndex
38352 "columnmoved" : true,
38354 * @event columlockchange
38355 * Fires when a column's locked state is changed
38356 * @param {ColumnModel} this
38357 * @param {Number} colIndex
38358 * @param {Boolean} locked true if locked
38360 "columnlockchange" : true
38362 Roo.grid.ColumnModel.superclass.constructor.call(this);
38364 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
38366 * @cfg {String} header The header text to display in the Grid view.
38369 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
38370 * {@link Roo.data.Record} definition from which to draw the column's value. If not
38371 * specified, the column's index is used as an index into the Record's data Array.
38374 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
38375 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
38378 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
38379 * Defaults to the value of the {@link #defaultSortable} property.
38380 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
38383 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
38386 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
38389 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
38392 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
38395 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
38396 * given the cell's data value. See {@link #setRenderer}. If not specified, the
38397 * default renderer uses the raw data value.
38400 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
38403 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
38407 * Returns the id of the column at the specified index.
38408 * @param {Number} index The column index
38409 * @return {String} the id
38411 getColumnId : function(index){
38412 return this.config[index].id;
38416 * Returns the column for a specified id.
38417 * @param {String} id The column id
38418 * @return {Object} the column
38420 getColumnById : function(id){
38421 return this.lookup[id];
38426 * Returns the column for a specified dataIndex.
38427 * @param {String} dataIndex The column dataIndex
38428 * @return {Object|Boolean} the column or false if not found
38430 getColumnByDataIndex: function(dataIndex){
38431 var index = this.findColumnIndex(dataIndex);
38432 return index > -1 ? this.config[index] : false;
38436 * Returns the index for a specified column id.
38437 * @param {String} id The column id
38438 * @return {Number} the index, or -1 if not found
38440 getIndexById : function(id){
38441 for(var i = 0, len = this.config.length; i < len; i++){
38442 if(this.config[i].id == id){
38450 * Returns the index for a specified column dataIndex.
38451 * @param {String} dataIndex The column dataIndex
38452 * @return {Number} the index, or -1 if not found
38455 findColumnIndex : function(dataIndex){
38456 for(var i = 0, len = this.config.length; i < len; i++){
38457 if(this.config[i].dataIndex == dataIndex){
38465 moveColumn : function(oldIndex, newIndex){
38466 var c = this.config[oldIndex];
38467 this.config.splice(oldIndex, 1);
38468 this.config.splice(newIndex, 0, c);
38469 this.dataMap = null;
38470 this.fireEvent("columnmoved", this, oldIndex, newIndex);
38473 isLocked : function(colIndex){
38474 return this.config[colIndex].locked === true;
38477 setLocked : function(colIndex, value, suppressEvent){
38478 if(this.isLocked(colIndex) == value){
38481 this.config[colIndex].locked = value;
38482 if(!suppressEvent){
38483 this.fireEvent("columnlockchange", this, colIndex, value);
38487 getTotalLockedWidth : function(){
38488 var totalWidth = 0;
38489 for(var i = 0; i < this.config.length; i++){
38490 if(this.isLocked(i) && !this.isHidden(i)){
38491 this.totalWidth += this.getColumnWidth(i);
38497 getLockedCount : function(){
38498 for(var i = 0, len = this.config.length; i < len; i++){
38499 if(!this.isLocked(i)){
38506 * Returns the number of columns.
38509 getColumnCount : function(visibleOnly){
38510 if(visibleOnly === true){
38512 for(var i = 0, len = this.config.length; i < len; i++){
38513 if(!this.isHidden(i)){
38519 return this.config.length;
38523 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
38524 * @param {Function} fn
38525 * @param {Object} scope (optional)
38526 * @return {Array} result
38528 getColumnsBy : function(fn, scope){
38530 for(var i = 0, len = this.config.length; i < len; i++){
38531 var c = this.config[i];
38532 if(fn.call(scope||this, c, i) === true){
38540 * Returns true if the specified column is sortable.
38541 * @param {Number} col The column index
38542 * @return {Boolean}
38544 isSortable : function(col){
38545 if(typeof this.config[col].sortable == "undefined"){
38546 return this.defaultSortable;
38548 return this.config[col].sortable;
38552 * Returns the rendering (formatting) function defined for the column.
38553 * @param {Number} col The column index.
38554 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
38556 getRenderer : function(col){
38557 if(!this.config[col].renderer){
38558 return Roo.grid.ColumnModel.defaultRenderer;
38560 return this.config[col].renderer;
38564 * Sets the rendering (formatting) function for a column.
38565 * @param {Number} col The column index
38566 * @param {Function} fn The function to use to process the cell's raw data
38567 * to return HTML markup for the grid view. The render function is called with
38568 * the following parameters:<ul>
38569 * <li>Data value.</li>
38570 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
38571 * <li>css A CSS style string to apply to the table cell.</li>
38572 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
38573 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
38574 * <li>Row index</li>
38575 * <li>Column index</li>
38576 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
38578 setRenderer : function(col, fn){
38579 this.config[col].renderer = fn;
38583 * Returns the width for the specified column.
38584 * @param {Number} col The column index
38587 getColumnWidth : function(col){
38588 return this.config[col].width * 1 || this.defaultWidth;
38592 * Sets the width for a column.
38593 * @param {Number} col The column index
38594 * @param {Number} width The new width
38596 setColumnWidth : function(col, width, suppressEvent){
38597 this.config[col].width = width;
38598 this.totalWidth = null;
38599 if(!suppressEvent){
38600 this.fireEvent("widthchange", this, col, width);
38605 * Returns the total width of all columns.
38606 * @param {Boolean} includeHidden True to include hidden column widths
38609 getTotalWidth : function(includeHidden){
38610 if(!this.totalWidth){
38611 this.totalWidth = 0;
38612 for(var i = 0, len = this.config.length; i < len; i++){
38613 if(includeHidden || !this.isHidden(i)){
38614 this.totalWidth += this.getColumnWidth(i);
38618 return this.totalWidth;
38622 * Returns the header for the specified column.
38623 * @param {Number} col The column index
38626 getColumnHeader : function(col){
38627 return this.config[col].header;
38631 * Sets the header for a column.
38632 * @param {Number} col The column index
38633 * @param {String} header The new header
38635 setColumnHeader : function(col, header){
38636 this.config[col].header = header;
38637 this.fireEvent("headerchange", this, col, header);
38641 * Returns the tooltip for the specified column.
38642 * @param {Number} col The column index
38645 getColumnTooltip : function(col){
38646 return this.config[col].tooltip;
38649 * Sets the tooltip for a column.
38650 * @param {Number} col The column index
38651 * @param {String} tooltip The new tooltip
38653 setColumnTooltip : function(col, tooltip){
38654 this.config[col].tooltip = tooltip;
38658 * Returns the dataIndex for the specified column.
38659 * @param {Number} col The column index
38662 getDataIndex : function(col){
38663 return this.config[col].dataIndex;
38667 * Sets the dataIndex for a column.
38668 * @param {Number} col The column index
38669 * @param {Number} dataIndex The new dataIndex
38671 setDataIndex : function(col, dataIndex){
38672 this.config[col].dataIndex = dataIndex;
38678 * Returns true if the cell is editable.
38679 * @param {Number} colIndex The column index
38680 * @param {Number} rowIndex The row index
38681 * @return {Boolean}
38683 isCellEditable : function(colIndex, rowIndex){
38684 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
38688 * Returns the editor defined for the cell/column.
38689 * return false or null to disable editing.
38690 * @param {Number} colIndex The column index
38691 * @param {Number} rowIndex The row index
38694 getCellEditor : function(colIndex, rowIndex){
38695 return this.config[colIndex].editor;
38699 * Sets if a column is editable.
38700 * @param {Number} col The column index
38701 * @param {Boolean} editable True if the column is editable
38703 setEditable : function(col, editable){
38704 this.config[col].editable = editable;
38709 * Returns true if the column is hidden.
38710 * @param {Number} colIndex The column index
38711 * @return {Boolean}
38713 isHidden : function(colIndex){
38714 return this.config[colIndex].hidden;
38719 * Returns true if the column width cannot be changed
38721 isFixed : function(colIndex){
38722 return this.config[colIndex].fixed;
38726 * Returns true if the column can be resized
38727 * @return {Boolean}
38729 isResizable : function(colIndex){
38730 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
38733 * Sets if a column is hidden.
38734 * @param {Number} colIndex The column index
38735 * @param {Boolean} hidden True if the column is hidden
38737 setHidden : function(colIndex, hidden){
38738 this.config[colIndex].hidden = hidden;
38739 this.totalWidth = null;
38740 this.fireEvent("hiddenchange", this, colIndex, hidden);
38744 * Sets the editor for a column.
38745 * @param {Number} col The column index
38746 * @param {Object} editor The editor object
38748 setEditor : function(col, editor){
38749 this.config[col].editor = editor;
38753 Roo.grid.ColumnModel.defaultRenderer = function(value){
38754 if(typeof value == "string" && value.length < 1){
38760 // Alias for backwards compatibility
38761 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
38764 * Ext JS Library 1.1.1
38765 * Copyright(c) 2006-2007, Ext JS, LLC.
38767 * Originally Released Under LGPL - original licence link has changed is not relivant.
38770 * <script type="text/javascript">
38774 * @class Roo.grid.AbstractSelectionModel
38775 * @extends Roo.util.Observable
38776 * Abstract base class for grid SelectionModels. It provides the interface that should be
38777 * implemented by descendant classes. This class should not be directly instantiated.
38780 Roo.grid.AbstractSelectionModel = function(){
38781 this.locked = false;
38782 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
38785 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
38786 /** @ignore Called by the grid automatically. Do not call directly. */
38787 init : function(grid){
38793 * Locks the selections.
38796 this.locked = true;
38800 * Unlocks the selections.
38802 unlock : function(){
38803 this.locked = false;
38807 * Returns true if the selections are locked.
38808 * @return {Boolean}
38810 isLocked : function(){
38811 return this.locked;
38815 * Ext JS Library 1.1.1
38816 * Copyright(c) 2006-2007, Ext JS, LLC.
38818 * Originally Released Under LGPL - original licence link has changed is not relivant.
38821 * <script type="text/javascript">
38824 * @extends Roo.grid.AbstractSelectionModel
38825 * @class Roo.grid.RowSelectionModel
38826 * The default SelectionModel used by {@link Roo.grid.Grid}.
38827 * It supports multiple selections and keyboard selection/navigation.
38829 * @param {Object} config
38831 Roo.grid.RowSelectionModel = function(config){
38832 Roo.apply(this, config);
38833 this.selections = new Roo.util.MixedCollection(false, function(o){
38838 this.lastActive = false;
38842 * @event selectionchange
38843 * Fires when the selection changes
38844 * @param {SelectionModel} this
38846 "selectionchange" : true,
38848 * @event afterselectionchange
38849 * Fires after the selection changes (eg. by key press or clicking)
38850 * @param {SelectionModel} this
38852 "afterselectionchange" : true,
38854 * @event beforerowselect
38855 * Fires when a row is selected being selected, return false to cancel.
38856 * @param {SelectionModel} this
38857 * @param {Number} rowIndex The selected index
38858 * @param {Boolean} keepExisting False if other selections will be cleared
38860 "beforerowselect" : true,
38863 * Fires when a row is selected.
38864 * @param {SelectionModel} this
38865 * @param {Number} rowIndex The selected index
38866 * @param {Roo.data.Record} r The record
38868 "rowselect" : true,
38870 * @event rowdeselect
38871 * Fires when a row is deselected.
38872 * @param {SelectionModel} this
38873 * @param {Number} rowIndex The selected index
38875 "rowdeselect" : true
38877 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
38878 this.locked = false;
38881 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
38883 * @cfg {Boolean} singleSelect
38884 * True to allow selection of only one row at a time (defaults to false)
38886 singleSelect : false,
38889 initEvents : function(){
38891 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
38892 this.grid.on("mousedown", this.handleMouseDown, this);
38893 }else{ // allow click to work like normal
38894 this.grid.on("rowclick", this.handleDragableRowClick, this);
38897 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
38898 "up" : function(e){
38900 this.selectPrevious(e.shiftKey);
38901 }else if(this.last !== false && this.lastActive !== false){
38902 var last = this.last;
38903 this.selectRange(this.last, this.lastActive-1);
38904 this.grid.getView().focusRow(this.lastActive);
38905 if(last !== false){
38909 this.selectFirstRow();
38911 this.fireEvent("afterselectionchange", this);
38913 "down" : function(e){
38915 this.selectNext(e.shiftKey);
38916 }else if(this.last !== false && this.lastActive !== false){
38917 var last = this.last;
38918 this.selectRange(this.last, this.lastActive+1);
38919 this.grid.getView().focusRow(this.lastActive);
38920 if(last !== false){
38924 this.selectFirstRow();
38926 this.fireEvent("afterselectionchange", this);
38931 var view = this.grid.view;
38932 view.on("refresh", this.onRefresh, this);
38933 view.on("rowupdated", this.onRowUpdated, this);
38934 view.on("rowremoved", this.onRemove, this);
38938 onRefresh : function(){
38939 var ds = this.grid.dataSource, i, v = this.grid.view;
38940 var s = this.selections;
38941 s.each(function(r){
38942 if((i = ds.indexOfId(r.id)) != -1){
38951 onRemove : function(v, index, r){
38952 this.selections.remove(r);
38956 onRowUpdated : function(v, index, r){
38957 if(this.isSelected(r)){
38958 v.onRowSelect(index);
38964 * @param {Array} records The records to select
38965 * @param {Boolean} keepExisting (optional) True to keep existing selections
38967 selectRecords : function(records, keepExisting){
38969 this.clearSelections();
38971 var ds = this.grid.dataSource;
38972 for(var i = 0, len = records.length; i < len; i++){
38973 this.selectRow(ds.indexOf(records[i]), true);
38978 * Gets the number of selected rows.
38981 getCount : function(){
38982 return this.selections.length;
38986 * Selects the first row in the grid.
38988 selectFirstRow : function(){
38993 * Select the last row.
38994 * @param {Boolean} keepExisting (optional) True to keep existing selections
38996 selectLastRow : function(keepExisting){
38997 this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
39001 * Selects the row immediately following the last selected row.
39002 * @param {Boolean} keepExisting (optional) True to keep existing selections
39004 selectNext : function(keepExisting){
39005 if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
39006 this.selectRow(this.last+1, keepExisting);
39007 this.grid.getView().focusRow(this.last);
39012 * Selects the row that precedes the last selected row.
39013 * @param {Boolean} keepExisting (optional) True to keep existing selections
39015 selectPrevious : function(keepExisting){
39017 this.selectRow(this.last-1, keepExisting);
39018 this.grid.getView().focusRow(this.last);
39023 * Returns the selected records
39024 * @return {Array} Array of selected records
39026 getSelections : function(){
39027 return [].concat(this.selections.items);
39031 * Returns the first selected record.
39034 getSelected : function(){
39035 return this.selections.itemAt(0);
39040 * Clears all selections.
39042 clearSelections : function(fast){
39043 if(this.locked) return;
39045 var ds = this.grid.dataSource;
39046 var s = this.selections;
39047 s.each(function(r){
39048 this.deselectRow(ds.indexOfId(r.id));
39052 this.selections.clear();
39059 * Selects all rows.
39061 selectAll : function(){
39062 if(this.locked) return;
39063 this.selections.clear();
39064 for(var i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
39065 this.selectRow(i, true);
39070 * Returns True if there is a selection.
39071 * @return {Boolean}
39073 hasSelection : function(){
39074 return this.selections.length > 0;
39078 * Returns True if the specified row is selected.
39079 * @param {Number/Record} record The record or index of the record to check
39080 * @return {Boolean}
39082 isSelected : function(index){
39083 var r = typeof index == "number" ? this.grid.dataSource.getAt(index) : index;
39084 return (r && this.selections.key(r.id) ? true : false);
39088 * Returns True if the specified record id is selected.
39089 * @param {String} id The id of record to check
39090 * @return {Boolean}
39092 isIdSelected : function(id){
39093 return (this.selections.key(id) ? true : false);
39097 handleMouseDown : function(e, t){
39098 var view = this.grid.getView(), rowIndex;
39099 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
39102 if(e.shiftKey && this.last !== false){
39103 var last = this.last;
39104 this.selectRange(last, rowIndex, e.ctrlKey);
39105 this.last = last; // reset the last
39106 view.focusRow(rowIndex);
39108 var isSelected = this.isSelected(rowIndex);
39109 if(e.button !== 0 && isSelected){
39110 view.focusRow(rowIndex);
39111 }else if(e.ctrlKey && isSelected){
39112 this.deselectRow(rowIndex);
39113 }else if(!isSelected){
39114 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
39115 view.focusRow(rowIndex);
39118 this.fireEvent("afterselectionchange", this);
39121 handleDragableRowClick : function(grid, rowIndex, e)
39123 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
39124 this.selectRow(rowIndex, false);
39125 grid.view.focusRow(rowIndex);
39126 this.fireEvent("afterselectionchange", this);
39131 * Selects multiple rows.
39132 * @param {Array} rows Array of the indexes of the row to select
39133 * @param {Boolean} keepExisting (optional) True to keep existing selections
39135 selectRows : function(rows, keepExisting){
39137 this.clearSelections();
39139 for(var i = 0, len = rows.length; i < len; i++){
39140 this.selectRow(rows[i], true);
39145 * Selects a range of rows. All rows in between startRow and endRow are also selected.
39146 * @param {Number} startRow The index of the first row in the range
39147 * @param {Number} endRow The index of the last row in the range
39148 * @param {Boolean} keepExisting (optional) True to retain existing selections
39150 selectRange : function(startRow, endRow, keepExisting){
39151 if(this.locked) return;
39153 this.clearSelections();
39155 if(startRow <= endRow){
39156 for(var i = startRow; i <= endRow; i++){
39157 this.selectRow(i, true);
39160 for(var i = startRow; i >= endRow; i--){
39161 this.selectRow(i, true);
39167 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
39168 * @param {Number} startRow The index of the first row in the range
39169 * @param {Number} endRow The index of the last row in the range
39171 deselectRange : function(startRow, endRow, preventViewNotify){
39172 if(this.locked) return;
39173 for(var i = startRow; i <= endRow; i++){
39174 this.deselectRow(i, preventViewNotify);
39180 * @param {Number} row The index of the row to select
39181 * @param {Boolean} keepExisting (optional) True to keep existing selections
39183 selectRow : function(index, keepExisting, preventViewNotify){
39184 if(this.locked || (index < 0 || index >= this.grid.dataSource.getCount())) return;
39185 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
39186 if(!keepExisting || this.singleSelect){
39187 this.clearSelections();
39189 var r = this.grid.dataSource.getAt(index);
39190 this.selections.add(r);
39191 this.last = this.lastActive = index;
39192 if(!preventViewNotify){
39193 this.grid.getView().onRowSelect(index);
39195 this.fireEvent("rowselect", this, index, r);
39196 this.fireEvent("selectionchange", this);
39202 * @param {Number} row The index of the row to deselect
39204 deselectRow : function(index, preventViewNotify){
39205 if(this.locked) return;
39206 if(this.last == index){
39209 if(this.lastActive == index){
39210 this.lastActive = false;
39212 var r = this.grid.dataSource.getAt(index);
39213 this.selections.remove(r);
39214 if(!preventViewNotify){
39215 this.grid.getView().onRowDeselect(index);
39217 this.fireEvent("rowdeselect", this, index);
39218 this.fireEvent("selectionchange", this);
39222 restoreLast : function(){
39224 this.last = this._last;
39229 acceptsNav : function(row, col, cm){
39230 return !cm.isHidden(col) && cm.isCellEditable(col, row);
39234 onEditorKey : function(field, e){
39235 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
39240 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
39242 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
39244 }else if(k == e.ENTER && !e.ctrlKey){
39248 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
39250 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
39252 }else if(k == e.ESC){
39256 g.startEditing(newCell[0], newCell[1]);
39261 * Ext JS Library 1.1.1
39262 * Copyright(c) 2006-2007, Ext JS, LLC.
39264 * Originally Released Under LGPL - original licence link has changed is not relivant.
39267 * <script type="text/javascript">
39270 * @class Roo.grid.CellSelectionModel
39271 * @extends Roo.grid.AbstractSelectionModel
39272 * This class provides the basic implementation for cell selection in a grid.
39274 * @param {Object} config The object containing the configuration of this model.
39275 * @cfg {Boolean} enter_is_tab Enter behaves the same as tab. (eg. goes to next cell) default: false
39277 Roo.grid.CellSelectionModel = function(config){
39278 Roo.apply(this, config);
39280 this.selection = null;
39284 * @event beforerowselect
39285 * Fires before a cell is selected.
39286 * @param {SelectionModel} this
39287 * @param {Number} rowIndex The selected row index
39288 * @param {Number} colIndex The selected cell index
39290 "beforecellselect" : true,
39292 * @event cellselect
39293 * Fires when a cell is selected.
39294 * @param {SelectionModel} this
39295 * @param {Number} rowIndex The selected row index
39296 * @param {Number} colIndex The selected cell index
39298 "cellselect" : true,
39300 * @event selectionchange
39301 * Fires when the active selection changes.
39302 * @param {SelectionModel} this
39303 * @param {Object} selection null for no selection or an object (o) with two properties
39305 <li>o.record: the record object for the row the selection is in</li>
39306 <li>o.cell: An array of [rowIndex, columnIndex]</li>
39309 "selectionchange" : true,
39312 * Fires when the tab (or enter) was pressed on the last editable cell
39313 * You can use this to trigger add new row.
39314 * @param {SelectionModel} this
39318 * @event beforeeditnext
39319 * Fires before the next editable sell is made active
39320 * You can use this to skip to another cell or fire the tabend
39321 * if you set cell to false
39322 * @param {Object} eventdata object : { cell : [ row, col ] }
39324 "beforeeditnext" : true
39326 Roo.grid.CellSelectionModel.superclass.constructor.call(this);
39329 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel, {
39331 enter_is_tab: false,
39334 initEvents : function(){
39335 this.grid.on("mousedown", this.handleMouseDown, this);
39336 this.grid.getGridEl().on(Roo.isIE ? "keydown" : "keypress", this.handleKeyDown, this);
39337 var view = this.grid.view;
39338 view.on("refresh", this.onViewChange, this);
39339 view.on("rowupdated", this.onRowUpdated, this);
39340 view.on("beforerowremoved", this.clearSelections, this);
39341 view.on("beforerowsinserted", this.clearSelections, this);
39342 if(this.grid.isEditor){
39343 this.grid.on("beforeedit", this.beforeEdit, this);
39348 beforeEdit : function(e){
39349 this.select(e.row, e.column, false, true, e.record);
39353 onRowUpdated : function(v, index, r){
39354 if(this.selection && this.selection.record == r){
39355 v.onCellSelect(index, this.selection.cell[1]);
39360 onViewChange : function(){
39361 this.clearSelections(true);
39365 * Returns the currently selected cell,.
39366 * @return {Array} The selected cell (row, column) or null if none selected.
39368 getSelectedCell : function(){
39369 return this.selection ? this.selection.cell : null;
39373 * Clears all selections.
39374 * @param {Boolean} true to prevent the gridview from being notified about the change.
39376 clearSelections : function(preventNotify){
39377 var s = this.selection;
39379 if(preventNotify !== true){
39380 this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
39382 this.selection = null;
39383 this.fireEvent("selectionchange", this, null);
39388 * Returns true if there is a selection.
39389 * @return {Boolean}
39391 hasSelection : function(){
39392 return this.selection ? true : false;
39396 handleMouseDown : function(e, t){
39397 var v = this.grid.getView();
39398 if(this.isLocked()){
39401 var row = v.findRowIndex(t);
39402 var cell = v.findCellIndex(t);
39403 if(row !== false && cell !== false){
39404 this.select(row, cell);
39410 * @param {Number} rowIndex
39411 * @param {Number} collIndex
39413 select : function(rowIndex, colIndex, preventViewNotify, preventFocus, /*internal*/ r){
39414 if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
39415 this.clearSelections();
39416 r = r || this.grid.dataSource.getAt(rowIndex);
39419 cell : [rowIndex, colIndex]
39421 if(!preventViewNotify){
39422 var v = this.grid.getView();
39423 v.onCellSelect(rowIndex, colIndex);
39424 if(preventFocus !== true){
39425 v.focusCell(rowIndex, colIndex);
39428 this.fireEvent("cellselect", this, rowIndex, colIndex);
39429 this.fireEvent("selectionchange", this, this.selection);
39434 isSelectable : function(rowIndex, colIndex, cm){
39435 return !cm.isHidden(colIndex);
39439 handleKeyDown : function(e){
39440 //Roo.log('Cell Sel Model handleKeyDown');
39441 if(!e.isNavKeyPress()){
39444 var g = this.grid, s = this.selection;
39447 var cell = g.walkCells(0, 0, 1, this.isSelectable, this);
39449 this.select(cell[0], cell[1]);
39454 var walk = function(row, col, step){
39455 return g.walkCells(row, col, step, sm.isSelectable, sm);
39457 var k = e.getKey(), r = s.cell[0], c = s.cell[1];
39464 // handled by onEditorKey
39465 if (g.isEditor && g.editing) {
39469 newCell = walk(r, c-1, -1);
39471 newCell = walk(r, c+1, 1);
39476 newCell = walk(r+1, c, 1);
39480 newCell = walk(r-1, c, -1);
39484 newCell = walk(r, c+1, 1);
39488 newCell = walk(r, c-1, -1);
39493 if(g.isEditor && !g.editing){
39494 g.startEditing(r, c);
39503 this.select(newCell[0], newCell[1]);
39509 acceptsNav : function(row, col, cm){
39510 return !cm.isHidden(col) && cm.isCellEditable(col, row);
39514 * @param {Number} field (not used) - as it's normally used as a listener
39515 * @param {Number} e - event - fake it by using
39517 * var e = Roo.EventObjectImpl.prototype;
39518 * e.keyCode = e.TAB
39522 onEditorKey : function(field, e){
39524 var k = e.getKey(),
39527 ed = g.activeEditor,
39529 ///Roo.log('onEditorKey' + k);
39532 if (this.enter_is_tab && k == e.ENTER) {
39538 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
39540 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
39546 } else if(k == e.ENTER && !e.ctrlKey){
39549 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
39551 } else if(k == e.ESC){
39556 var ecall = { cell : newCell, forward : forward };
39557 this.fireEvent('beforeeditnext', ecall );
39558 newCell = ecall.cell;
39559 forward = ecall.forward;
39563 //Roo.log('next cell after edit');
39564 g.startEditing.defer(100, g, [newCell[0], newCell[1]]);
39565 } else if (forward) {
39566 // tabbed past last
39567 this.fireEvent.defer(100, this, ['tabend',this]);
39572 * Ext JS Library 1.1.1
39573 * Copyright(c) 2006-2007, Ext JS, LLC.
39575 * Originally Released Under LGPL - original licence link has changed is not relivant.
39578 * <script type="text/javascript">
39582 * @class Roo.grid.EditorGrid
39583 * @extends Roo.grid.Grid
39584 * Class for creating and editable grid.
39585 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
39586 * The container MUST have some type of size defined for the grid to fill. The container will be
39587 * automatically set to position relative if it isn't already.
39588 * @param {Object} dataSource The data model to bind to
39589 * @param {Object} colModel The column model with info about this grid's columns
39591 Roo.grid.EditorGrid = function(container, config){
39592 Roo.grid.EditorGrid.superclass.constructor.call(this, container, config);
39593 this.getGridEl().addClass("xedit-grid");
39595 if(!this.selModel){
39596 this.selModel = new Roo.grid.CellSelectionModel();
39599 this.activeEditor = null;
39603 * @event beforeedit
39604 * Fires before cell editing is triggered. The edit event object has the following properties <br />
39605 * <ul style="padding:5px;padding-left:16px;">
39606 * <li>grid - This grid</li>
39607 * <li>record - The record being edited</li>
39608 * <li>field - The field name being edited</li>
39609 * <li>value - The value for the field being edited.</li>
39610 * <li>row - The grid row index</li>
39611 * <li>column - The grid column index</li>
39612 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
39614 * @param {Object} e An edit event (see above for description)
39616 "beforeedit" : true,
39619 * Fires after a cell is edited. <br />
39620 * <ul style="padding:5px;padding-left:16px;">
39621 * <li>grid - This grid</li>
39622 * <li>record - The record being edited</li>
39623 * <li>field - The field name being edited</li>
39624 * <li>value - The value being set</li>
39625 * <li>originalValue - The original value for the field, before the edit.</li>
39626 * <li>row - The grid row index</li>
39627 * <li>column - The grid column index</li>
39629 * @param {Object} e An edit event (see above for description)
39631 "afteredit" : true,
39633 * @event validateedit
39634 * Fires after a cell is edited, but before the value is set in the record.
39635 * You can use this to modify the value being set in the field, Return false
39636 * to cancel the change. The edit event object has the following properties <br />
39637 * <ul style="padding:5px;padding-left:16px;">
39638 * <li>editor - This editor</li>
39639 * <li>grid - This grid</li>
39640 * <li>record - The record being edited</li>
39641 * <li>field - The field name being edited</li>
39642 * <li>value - The value being set</li>
39643 * <li>originalValue - The original value for the field, before the edit.</li>
39644 * <li>row - The grid row index</li>
39645 * <li>column - The grid column index</li>
39646 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
39648 * @param {Object} e An edit event (see above for description)
39650 "validateedit" : true
39652 this.on("bodyscroll", this.stopEditing, this);
39653 this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick, this);
39656 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
39658 * @cfg {Number} clicksToEdit
39659 * The number of clicks on a cell required to display the cell's editor (defaults to 2)
39666 trackMouseOver: false, // causes very odd FF errors
39668 onCellDblClick : function(g, row, col){
39669 this.startEditing(row, col);
39672 onEditComplete : function(ed, value, startValue){
39673 this.editing = false;
39674 this.activeEditor = null;
39675 ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
39677 var field = this.colModel.getDataIndex(ed.col);
39682 originalValue: startValue,
39689 var cell = Roo.get(this.view.getCell(ed.row,ed.col))
39692 if(String(value) !== String(startValue)){
39694 if(this.fireEvent("validateedit", e) !== false && !e.cancel){
39695 r.set(field, e.value);
39696 // if we are dealing with a combo box..
39697 // then we also set the 'name' colum to be the displayField
39698 if (ed.field.displayField && ed.field.name) {
39699 r.set(ed.field.name, ed.field.el.dom.value);
39702 delete e.cancel; //?? why!!!
39703 this.fireEvent("afteredit", e);
39706 this.fireEvent("afteredit", e); // always fire it!
39708 this.view.focusCell(ed.row, ed.col);
39712 * Starts editing the specified for the specified row/column
39713 * @param {Number} rowIndex
39714 * @param {Number} colIndex
39716 startEditing : function(row, col){
39717 this.stopEditing();
39718 if(this.colModel.isCellEditable(col, row)){
39719 this.view.ensureVisible(row, col, true);
39721 var r = this.dataSource.getAt(row);
39722 var field = this.colModel.getDataIndex(col);
39723 var cell = Roo.get(this.view.getCell(row,col));
39728 value: r.data[field],
39733 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
39734 this.editing = true;
39735 var ed = this.colModel.getCellEditor(col, row);
39741 ed.render(ed.parentEl || document.body);
39747 (function(){ // complex but required for focus issues in safari, ie and opera
39751 ed.on("complete", this.onEditComplete, this, {single: true});
39752 ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
39753 this.activeEditor = ed;
39754 var v = r.data[field];
39755 ed.startEdit(this.view.getCell(row, col), v);
39756 // combo's with 'displayField and name set
39757 if (ed.field.displayField && ed.field.name) {
39758 ed.field.el.dom.value = r.data[ed.field.name];
39762 }).defer(50, this);
39768 * Stops any active editing
39770 stopEditing : function(){
39771 if(this.activeEditor){
39772 this.activeEditor.completeEdit();
39774 this.activeEditor = null;
39778 * Called to get grid's drag proxy text, by default returns this.ddText.
39781 getDragDropText : function(){
39782 var count = this.selModel.getSelectedCell() ? 1 : 0;
39783 return String.format(this.ddText, count, count == 1 ? '' : 's');
39788 * Ext JS Library 1.1.1
39789 * Copyright(c) 2006-2007, Ext JS, LLC.
39791 * Originally Released Under LGPL - original licence link has changed is not relivant.
39794 * <script type="text/javascript">
39797 // private - not really -- you end up using it !
39798 // This is a support class used internally by the Grid components
39801 * @class Roo.grid.GridEditor
39802 * @extends Roo.Editor
39803 * Class for creating and editable grid elements.
39804 * @param {Object} config any settings (must include field)
39806 Roo.grid.GridEditor = function(field, config){
39807 if (!config && field.field) {
39809 field = Roo.factory(config.field, Roo.form);
39811 Roo.grid.GridEditor.superclass.constructor.call(this, field, config);
39812 field.monitorTab = false;
39815 Roo.extend(Roo.grid.GridEditor, Roo.Editor, {
39818 * @cfg {Roo.form.Field} field Field to wrap (or xtyped)
39821 alignment: "tl-tl",
39824 cls: "x-small-editor x-grid-editor",
39829 * Ext JS Library 1.1.1
39830 * Copyright(c) 2006-2007, Ext JS, LLC.
39832 * Originally Released Under LGPL - original licence link has changed is not relivant.
39835 * <script type="text/javascript">
39840 Roo.grid.PropertyRecord = Roo.data.Record.create([
39841 {name:'name',type:'string'}, 'value'
39845 Roo.grid.PropertyStore = function(grid, source){
39847 this.store = new Roo.data.Store({
39848 recordType : Roo.grid.PropertyRecord
39850 this.store.on('update', this.onUpdate, this);
39852 this.setSource(source);
39854 Roo.grid.PropertyStore.superclass.constructor.call(this);
39859 Roo.extend(Roo.grid.PropertyStore, Roo.util.Observable, {
39860 setSource : function(o){
39862 this.store.removeAll();
39865 if(this.isEditableValue(o[k])){
39866 data.push(new Roo.grid.PropertyRecord({name: k, value: o[k]}, k));
39869 this.store.loadRecords({records: data}, {}, true);
39872 onUpdate : function(ds, record, type){
39873 if(type == Roo.data.Record.EDIT){
39874 var v = record.data['value'];
39875 var oldValue = record.modified['value'];
39876 if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
39877 this.source[record.id] = v;
39879 this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
39886 getProperty : function(row){
39887 return this.store.getAt(row);
39890 isEditableValue: function(val){
39891 if(val && val instanceof Date){
39893 }else if(typeof val == 'object' || typeof val == 'function'){
39899 setValue : function(prop, value){
39900 this.source[prop] = value;
39901 this.store.getById(prop).set('value', value);
39904 getSource : function(){
39905 return this.source;
39909 Roo.grid.PropertyColumnModel = function(grid, store){
39912 g.PropertyColumnModel.superclass.constructor.call(this, [
39913 {header: this.nameText, sortable: true, dataIndex:'name', id: 'name'},
39914 {header: this.valueText, resizable:false, dataIndex: 'value', id: 'value'}
39916 this.store = store;
39917 this.bselect = Roo.DomHelper.append(document.body, {
39918 tag: 'select', style:'display:none', cls: 'x-grid-editor', children: [
39919 {tag: 'option', value: 'true', html: 'true'},
39920 {tag: 'option', value: 'false', html: 'false'}
39923 Roo.id(this.bselect);
39926 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
39927 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
39928 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
39929 'int' : new g.GridEditor(new f.NumberField({selectOnFocus:true, allowDecimals:false, style:'text-align:left;'})),
39930 'boolean' : new g.GridEditor(new f.Field({el:this.bselect,selectOnFocus:true}))
39932 this.renderCellDelegate = this.renderCell.createDelegate(this);
39933 this.renderPropDelegate = this.renderProp.createDelegate(this);
39936 Roo.extend(Roo.grid.PropertyColumnModel, Roo.grid.ColumnModel, {
39940 valueText : 'Value',
39942 dateFormat : 'm/j/Y',
39945 renderDate : function(dateVal){
39946 return dateVal.dateFormat(this.dateFormat);
39949 renderBool : function(bVal){
39950 return bVal ? 'true' : 'false';
39953 isCellEditable : function(colIndex, rowIndex){
39954 return colIndex == 1;
39957 getRenderer : function(col){
39959 this.renderCellDelegate : this.renderPropDelegate;
39962 renderProp : function(v){
39963 return this.getPropertyName(v);
39966 renderCell : function(val){
39968 if(val instanceof Date){
39969 rv = this.renderDate(val);
39970 }else if(typeof val == 'boolean'){
39971 rv = this.renderBool(val);
39973 return Roo.util.Format.htmlEncode(rv);
39976 getPropertyName : function(name){
39977 var pn = this.grid.propertyNames;
39978 return pn && pn[name] ? pn[name] : name;
39981 getCellEditor : function(colIndex, rowIndex){
39982 var p = this.store.getProperty(rowIndex);
39983 var n = p.data['name'], val = p.data['value'];
39985 if(typeof(this.grid.customEditors[n]) == 'string'){
39986 return this.editors[this.grid.customEditors[n]];
39988 if(typeof(this.grid.customEditors[n]) != 'undefined'){
39989 return this.grid.customEditors[n];
39991 if(val instanceof Date){
39992 return this.editors['date'];
39993 }else if(typeof val == 'number'){
39994 return this.editors['number'];
39995 }else if(typeof val == 'boolean'){
39996 return this.editors['boolean'];
39998 return this.editors['string'];
40004 * @class Roo.grid.PropertyGrid
40005 * @extends Roo.grid.EditorGrid
40006 * This class represents the interface of a component based property grid control.
40007 * <br><br>Usage:<pre><code>
40008 var grid = new Roo.grid.PropertyGrid("my-container-id", {
40016 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
40017 * The container MUST have some type of size defined for the grid to fill. The container will be
40018 * automatically set to position relative if it isn't already.
40019 * @param {Object} config A config object that sets properties on this grid.
40021 Roo.grid.PropertyGrid = function(container, config){
40022 config = config || {};
40023 var store = new Roo.grid.PropertyStore(this);
40024 this.store = store;
40025 var cm = new Roo.grid.PropertyColumnModel(this, store);
40026 store.store.sort('name', 'ASC');
40027 Roo.grid.PropertyGrid.superclass.constructor.call(this, container, Roo.apply({
40030 enableColLock:false,
40031 enableColumnMove:false,
40033 trackMouseOver: false,
40036 this.getGridEl().addClass('x-props-grid');
40037 this.lastEditRow = null;
40038 this.on('columnresize', this.onColumnResize, this);
40041 * @event beforepropertychange
40042 * Fires before a property changes (return false to stop?)
40043 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
40044 * @param {String} id Record Id
40045 * @param {String} newval New Value
40046 * @param {String} oldval Old Value
40048 "beforepropertychange": true,
40050 * @event propertychange
40051 * Fires after a property changes
40052 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
40053 * @param {String} id Record Id
40054 * @param {String} newval New Value
40055 * @param {String} oldval Old Value
40057 "propertychange": true
40059 this.customEditors = this.customEditors || {};
40061 Roo.extend(Roo.grid.PropertyGrid, Roo.grid.EditorGrid, {
40064 * @cfg {Object} customEditors map of colnames=> custom editors.
40065 * the custom editor can be one of the standard ones (date|string|number|int|boolean), or a
40066 * grid editor eg. Roo.grid.GridEditor(new Roo.form.TextArea({selectOnFocus:true})),
40067 * false disables editing of the field.
40071 * @cfg {Object} propertyNames map of property Names to their displayed value
40074 render : function(){
40075 Roo.grid.PropertyGrid.superclass.render.call(this);
40076 this.autoSize.defer(100, this);
40079 autoSize : function(){
40080 Roo.grid.PropertyGrid.superclass.autoSize.call(this);
40082 this.view.fitColumns();
40086 onColumnResize : function(){
40087 this.colModel.setColumnWidth(1, this.container.getWidth(true)-this.colModel.getColumnWidth(0));
40091 * Sets the data for the Grid
40092 * accepts a Key => Value object of all the elements avaiable.
40093 * @param {Object} data to appear in grid.
40095 setSource : function(source){
40096 this.store.setSource(source);
40100 * Gets all the data from the grid.
40101 * @return {Object} data data stored in grid
40103 getSource : function(){
40104 return this.store.getSource();
40108 * Ext JS Library 1.1.1
40109 * Copyright(c) 2006-2007, Ext JS, LLC.
40111 * Originally Released Under LGPL - original licence link has changed is not relivant.
40114 * <script type="text/javascript">
40118 * @class Roo.LoadMask
40119 * A simple utility class for generically masking elements while loading data. If the element being masked has
40120 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
40121 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
40122 * element's UpdateManager load indicator and will be destroyed after the initial load.
40124 * Create a new LoadMask
40125 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
40126 * @param {Object} config The config object
40128 Roo.LoadMask = function(el, config){
40129 this.el = Roo.get(el);
40130 Roo.apply(this, config);
40132 this.store.on('beforeload', this.onBeforeLoad, this);
40133 this.store.on('load', this.onLoad, this);
40134 this.store.on('loadexception', this.onLoadException, this);
40135 this.removeMask = false;
40137 var um = this.el.getUpdateManager();
40138 um.showLoadIndicator = false; // disable the default indicator
40139 um.on('beforeupdate', this.onBeforeLoad, this);
40140 um.on('update', this.onLoad, this);
40141 um.on('failure', this.onLoad, this);
40142 this.removeMask = true;
40146 Roo.LoadMask.prototype = {
40148 * @cfg {Boolean} removeMask
40149 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
40150 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
40153 * @cfg {String} msg
40154 * The text to display in a centered loading message box (defaults to 'Loading...')
40156 msg : 'Loading...',
40158 * @cfg {String} msgCls
40159 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
40161 msgCls : 'x-mask-loading',
40164 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
40170 * Disables the mask to prevent it from being displayed
40172 disable : function(){
40173 this.disabled = true;
40177 * Enables the mask so that it can be displayed
40179 enable : function(){
40180 this.disabled = false;
40183 onLoadException : function()
40185 Roo.log(arguments);
40187 if (typeof(arguments[3]) != 'undefined') {
40188 Roo.MessageBox.alert("Error loading",arguments[3]);
40192 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
40193 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
40202 this.el.unmask(this.removeMask);
40205 onLoad : function()
40207 this.el.unmask(this.removeMask);
40211 onBeforeLoad : function(){
40212 if(!this.disabled){
40213 this.el.mask(this.msg, this.msgCls);
40218 destroy : function(){
40220 this.store.un('beforeload', this.onBeforeLoad, this);
40221 this.store.un('load', this.onLoad, this);
40222 this.store.un('loadexception', this.onLoadException, this);
40224 var um = this.el.getUpdateManager();
40225 um.un('beforeupdate', this.onBeforeLoad, this);
40226 um.un('update', this.onLoad, this);
40227 um.un('failure', this.onLoad, this);
40232 * Ext JS Library 1.1.1
40233 * Copyright(c) 2006-2007, Ext JS, LLC.
40235 * Originally Released Under LGPL - original licence link has changed is not relivant.
40238 * <script type="text/javascript">
40243 * @class Roo.XTemplate
40244 * @extends Roo.Template
40245 * Provides a template that can have nested templates for loops or conditionals. The syntax is:
40247 var t = new Roo.XTemplate(
40248 '<select name="{name}">',
40249 '<tpl for="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
40253 // then append, applying the master template values
40256 * Supported features:
40261 {a_variable} - output encoded.
40262 {a_variable.format:("Y-m-d")} - call a method on the variable
40263 {a_variable:raw} - unencoded output
40264 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
40265 {a_variable:this.method_on_template(...)} - call a method on the template object.
40270 <tpl for="a_variable or condition.."></tpl>
40271 <tpl if="a_variable or condition"></tpl>
40272 <tpl exec="some javascript"></tpl>
40273 <tpl name="named_template"></tpl> (experimental)
40275 <tpl for="."></tpl> - just iterate the property..
40276 <tpl for=".."></tpl> - iterates with the parent (probably the template)
40280 Roo.XTemplate = function()
40282 Roo.XTemplate.superclass.constructor.apply(this, arguments);
40289 Roo.extend(Roo.XTemplate, Roo.Template, {
40292 * The various sub templates
40297 * basic tag replacing syntax
40300 * // you can fake an object call by doing this
40304 re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
40307 * compile the template
40309 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
40312 compile: function()
40316 s = ['<tpl>', s, '</tpl>'].join('');
40318 var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
40319 nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
40320 ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
40321 execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
40322 namedRe = /^<tpl\b[^>]*?name="(\w+)"/, // named templates..
40327 while(true == !!(m = s.match(re))){
40328 var forMatch = m[0].match(nameRe),
40329 ifMatch = m[0].match(ifRe),
40330 execMatch = m[0].match(execRe),
40331 namedMatch = m[0].match(namedRe),
40336 name = forMatch && forMatch[1] ? forMatch[1] : '';
40339 // if - puts fn into test..
40340 exp = ifMatch && ifMatch[1] ? ifMatch[1] : null;
40342 fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
40347 // exec - calls a function... returns empty if true is returned.
40348 exp = execMatch && execMatch[1] ? execMatch[1] : null;
40350 exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
40358 case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
40359 case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
40360 default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
40363 var uid = namedMatch ? namedMatch[1] : id;
40367 id: namedMatch ? namedMatch[1] : id,
40374 s = s.replace(m[0], '');
40376 s = s.replace(m[0], '{xtpl'+ id + '}');
40381 for(var i = tpls.length-1; i >= 0; --i){
40382 this.compileTpl(tpls[i]);
40383 this.tpls[tpls[i].id] = tpls[i];
40385 this.master = tpls[tpls.length-1];
40389 * same as applyTemplate, except it's done to one of the subTemplates
40390 * when using named templates, you can do:
40392 * var str = pl.applySubTemplate('your-name', values);
40395 * @param {Number} id of the template
40396 * @param {Object} values to apply to template
40397 * @param {Object} parent (normaly the instance of this object)
40399 applySubTemplate : function(id, values, parent)
40403 var t = this.tpls[id];
40407 if(t.test && !t.test.call(this, values, parent)){
40411 Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");
40412 Roo.log(e.toString());
40418 if(t.exec && t.exec.call(this, values, parent)){
40422 Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");
40423 Roo.log(e.toString());
40428 var vs = t.target ? t.target.call(this, values, parent) : values;
40429 parent = t.target ? values : parent;
40430 if(t.target && vs instanceof Array){
40432 for(var i = 0, len = vs.length; i < len; i++){
40433 buf[buf.length] = t.compiled.call(this, vs[i], parent);
40435 return buf.join('');
40437 return t.compiled.call(this, vs, parent);
40439 Roo.log("Xtemplate.applySubTemplate : Exception thrown");
40440 Roo.log(e.toString());
40441 Roo.log(t.compiled);
40446 compileTpl : function(tpl)
40448 var fm = Roo.util.Format;
40449 var useF = this.disableFormats !== true;
40450 var sep = Roo.isGecko ? "+" : ",";
40451 var undef = function(str) {
40452 Roo.log("Property not found :" + str);
40456 var fn = function(m, name, format, args)
40458 //Roo.log(arguments);
40459 args = args ? args.replace(/\\'/g,"'") : args;
40460 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
40461 if (typeof(format) == 'undefined') {
40462 format= 'htmlEncode';
40464 if (format == 'raw' ) {
40468 if(name.substr(0, 4) == 'xtpl'){
40469 return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent)'+sep+"'";
40472 // build an array of options to determine if value is undefined..
40474 // basically get 'xxxx.yyyy' then do
40475 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
40476 // (function () { Roo.log("Property not found"); return ''; })() :
40481 Roo.each(name.split('.'), function(st) {
40482 lookfor += (lookfor.length ? '.': '') + st;
40483 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
40486 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
40489 if(format && useF){
40491 args = args ? ',' + args : "";
40493 if(format.substr(0, 5) != "this."){
40494 format = "fm." + format + '(';
40496 format = 'this.call("'+ format.substr(5) + '", ';
40500 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
40504 // called with xxyx.yuu:(test,test)
40506 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
40508 // raw.. - :raw modifier..
40509 return "'"+ sep + udef_st + name + ")"+sep+"'";
40513 // branched to use + in gecko and [].join() in others
40515 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
40516 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
40519 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
40520 body.push(tpl.body.replace(/(\r\n|\n)/g,
40521 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
40522 body.push("'].join('');};};");
40523 body = body.join('');
40526 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
40528 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
40534 applyTemplate : function(values){
40535 return this.master.compiled.call(this, values, {});
40536 //var s = this.subs;
40539 apply : function(){
40540 return this.applyTemplate.apply(this, arguments);
40545 Roo.XTemplate.from = function(el){
40546 el = Roo.getDom(el);
40547 return new Roo.XTemplate(el.value || el.innerHTML);
40549 * Original code for Roojs - LGPL
40550 * <script type="text/javascript">
40554 * @class Roo.XComponent
40555 * A delayed Element creator...
40556 * Or a way to group chunks of interface together.
40558 * Mypart.xyx = new Roo.XComponent({
40560 parent : 'Mypart.xyz', // empty == document.element.!!
40564 disabled : function() {}
40566 tree : function() { // return an tree of xtype declared components
40570 xtype : 'NestedLayoutPanel',
40577 * It can be used to build a big heiracy, with parent etc.
40578 * or you can just use this to render a single compoent to a dom element
40579 * MYPART.render(Roo.Element | String(id) | dom_element )
40581 * @extends Roo.util.Observable
40583 * @param cfg {Object} configuration of component
40586 Roo.XComponent = function(cfg) {
40587 Roo.apply(this, cfg);
40591 * Fires when this the componnt is built
40592 * @param {Roo.XComponent} c the component
40597 this.region = this.region || 'center'; // default..
40598 Roo.XComponent.register(this);
40599 this.modules = false;
40600 this.el = false; // where the layout goes..
40604 Roo.extend(Roo.XComponent, Roo.util.Observable, {
40607 * The created element (with Roo.factory())
40608 * @type {Roo.Layout}
40614 * for BC - use el in new code
40615 * @type {Roo.Layout}
40621 * for BC - use el in new code
40622 * @type {Roo.Layout}
40627 * @cfg {Function|boolean} disabled
40628 * If this module is disabled by some rule, return true from the funtion
40633 * @cfg {String} parent
40634 * Name of parent element which it get xtype added to..
40639 * @cfg {String} order
40640 * Used to set the order in which elements are created (usefull for multiple tabs)
40645 * @cfg {String} name
40646 * String to display while loading.
40650 * @cfg {String} region
40651 * Region to render component to (defaults to center)
40656 * @cfg {Array} items
40657 * A single item array - the first element is the root of the tree..
40658 * It's done this way to stay compatible with the Xtype system...
40664 * The method that retuns the tree of parts that make up this compoennt
40671 * render element to dom or tree
40672 * @param {Roo.Element|String|DomElement} optional render to if parent is not set.
40675 render : function(el)
40679 var hp = this.parent ? 1 : 0;
40681 if (!el && typeof(this.parent) == 'string' && this.parent.substring(0,1) == '#') {
40682 // if parent is a '#.....' string, then let's use that..
40683 var ename = this.parent.substr(1)
40684 this.parent = false;
40685 el = Roo.get(ename);
40687 Roo.log("Warning - element can not be found :#" + ename );
40693 if (!this.parent) {
40695 el = el ? Roo.get(el) : false;
40697 // it's a top level one..
40699 el : new Roo.BorderLayout(el || document.body, {
40705 tabPosition: 'top',
40706 //resizeTabs: true,
40707 alwaysShowTabs: el && hp? false : true,
40708 hideTabs: el || !hp ? true : false,
40715 if (!this.parent.el) {
40716 // probably an old style ctor, which has been disabled.
40720 // The 'tree' method is '_tree now'
40722 var tree = this._tree ? this._tree() : this.tree();
40723 tree.region = tree.region || this.region;
40724 this.el = this.parent.el.addxtype(tree);
40725 this.fireEvent('built', this);
40727 this.panel = this.el;
40728 this.layout = this.panel.layout;
40729 this.parentLayout = this.parent.layout || false;
40735 Roo.apply(Roo.XComponent, {
40737 * @property hideProgress
40738 * true to disable the building progress bar.. usefull on single page renders.
40741 hideProgress : false,
40743 * @property buildCompleted
40744 * True when the builder has completed building the interface.
40747 buildCompleted : false,
40750 * @property topModule
40751 * the upper most module - uses document.element as it's constructor.
40758 * @property modules
40759 * array of modules to be created by registration system.
40760 * @type {Array} of Roo.XComponent
40765 * @property elmodules
40766 * array of modules to be created by which use #ID
40767 * @type {Array} of Roo.XComponent
40774 * Register components to be built later.
40776 * This solves the following issues
40777 * - Building is not done on page load, but after an authentication process has occured.
40778 * - Interface elements are registered on page load
40779 * - Parent Interface elements may not be loaded before child, so this handles that..
40786 module : 'Pman.Tab.projectMgr',
40788 parent : 'Pman.layout',
40789 disabled : false, // or use a function..
40792 * * @param {Object} details about module
40794 register : function(obj) {
40796 Roo.XComponent.event.fireEvent('register', obj);
40797 switch(typeof(obj.disabled) ) {
40803 if ( obj.disabled() ) {
40809 if (obj.disabled) {
40815 this.modules.push(obj);
40819 * convert a string to an object..
40820 * eg. 'AAA.BBB' -> finds AAA.BBB
40824 toObject : function(str)
40826 if (!str || typeof(str) == 'object') {
40829 if (str.substring(0,1) == '#') {
40833 var ar = str.split('.');
40838 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
40840 throw "Module not found : " + str;
40844 throw "Module not found : " + str;
40846 Roo.each(ar, function(e) {
40847 if (typeof(o[e]) == 'undefined') {
40848 throw "Module not found : " + str;
40859 * move modules into their correct place in the tree..
40862 preBuild : function ()
40865 Roo.each(this.modules , function (obj)
40867 Roo.XComponent.event.fireEvent('beforebuild', obj);
40869 var opar = obj.parent;
40871 obj.parent = this.toObject(opar);
40873 Roo.log("parent:toObject failed: " + e.toString());
40878 Roo.debug && Roo.log("GOT top level module");
40879 Roo.debug && Roo.log(obj);
40880 obj.modules = new Roo.util.MixedCollection(false,
40881 function(o) { return o.order + '' }
40883 this.topModule = obj;
40886 // parent is a string (usually a dom element name..)
40887 if (typeof(obj.parent) == 'string') {
40888 this.elmodules.push(obj);
40891 if (obj.parent.constructor != Roo.XComponent) {
40892 Roo.log("Warning : Object Parent is not instance of XComponent:" + obj.name)
40894 if (!obj.parent.modules) {
40895 obj.parent.modules = new Roo.util.MixedCollection(false,
40896 function(o) { return o.order + '' }
40899 if (obj.parent.disabled) {
40900 obj.disabled = true;
40902 obj.parent.modules.add(obj);
40907 * make a list of modules to build.
40908 * @return {Array} list of modules.
40911 buildOrder : function()
40914 var cmp = function(a,b) {
40915 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
40917 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
40918 throw "No top level modules to build";
40921 // make a flat list in order of modules to build.
40922 var mods = this.topModule ? [ this.topModule ] : [];
40925 // elmodules (is a list of DOM based modules )
40926 Roo.each(this.elmodules, function(e) {
40928 if (!this.topModule &&
40929 typeof(e.parent) == 'string' &&
40930 e.parent.substring(0,1) == '#' &&
40931 Roo.get(e.parent.substr(1))
40934 _this.topModule = e;
40940 // add modules to their parents..
40941 var addMod = function(m) {
40942 Roo.debug && Roo.log("build Order: add: " + m.name);
40945 if (m.modules && !m.disabled) {
40946 Roo.debug && Roo.log("build Order: " + m.modules.length + " child modules");
40947 m.modules.keySort('ASC', cmp );
40948 Roo.debug && Roo.log("build Order: " + m.modules.length + " child modules (after sort)");
40950 m.modules.each(addMod);
40952 Roo.debug && Roo.log("build Order: no child modules");
40954 // not sure if this is used any more..
40956 m.finalize.name = m.name + " (clean up) ";
40957 mods.push(m.finalize);
40961 if (this.topModule && this.topModule.modules) {
40962 this.topModule.modules.keySort('ASC', cmp );
40963 this.topModule.modules.each(addMod);
40969 * Build the registered modules.
40970 * @param {Object} parent element.
40971 * @param {Function} optional method to call after module has been added.
40979 var mods = this.buildOrder();
40981 //this.allmods = mods;
40982 //Roo.debug && Roo.log(mods);
40984 if (!mods.length) { // should not happen
40985 throw "NO modules!!!";
40989 var msg = "Building Interface...";
40990 // flash it up as modal - so we store the mask!?
40991 if (!this.hideProgress) {
40992 Roo.MessageBox.show({ title: 'loading' });
40993 Roo.MessageBox.show({
40994 title: "Please wait...",
41003 var total = mods.length;
41006 var progressRun = function() {
41007 if (!mods.length) {
41008 Roo.debug && Roo.log('hide?');
41009 if (!this.hideProgress) {
41010 Roo.MessageBox.hide();
41012 Roo.XComponent.event.fireEvent('buildcomplete', _this.topModule);
41018 var m = mods.shift();
41021 Roo.debug && Roo.log(m);
41022 // not sure if this is supported any more.. - modules that are are just function
41023 if (typeof(m) == 'function') {
41025 return progressRun.defer(10, _this);
41029 msg = "Building Interface " + (total - mods.length) +
41031 (m.name ? (' - ' + m.name) : '');
41032 Roo.debug && Roo.log(msg);
41033 if (!this.hideProgress) {
41034 Roo.MessageBox.updateProgress( (total - mods.length)/total, msg );
41038 // is the module disabled?
41039 var disabled = (typeof(m.disabled) == 'function') ?
41040 m.disabled.call(m.module.disabled) : m.disabled;
41044 return progressRun(); // we do not update the display!
41052 // it's 10 on top level, and 1 on others??? why...
41053 return progressRun.defer(10, _this);
41056 progressRun.defer(1, _this);
41070 * wrapper for event.on - aliased later..
41071 * Typically use to register a event handler for register:
41073 * eg. Roo.XComponent.on('register', function(comp) { comp.disable = true } );
41082 Roo.XComponent.event = new Roo.util.Observable({
41086 * Fires when an Component is registered,
41087 * set the disable property on the Component to stop registration.
41088 * @param {Roo.XComponent} c the component being registerd.
41093 * @event beforebuild
41094 * Fires before each Component is built
41095 * can be used to apply permissions.
41096 * @param {Roo.XComponent} c the component being registerd.
41099 'beforebuild' : true,
41101 * @event buildcomplete
41102 * Fires on the top level element when all elements have been built
41103 * @param {Roo.XComponent} the top level component.
41105 'buildcomplete' : true
41110 Roo.XComponent.on = Roo.XComponent.event.on.createDelegate(Roo.XComponent.event);