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">
17 window["undefined"] = window["undefined"];
21 * Roo core utilities and functions.
26 * Copies all the properties of config to obj.
27 * @param {Object} obj The receiver of the properties
28 * @param {Object} config The source of the properties
29 * @param {Object} defaults A different object that will also be applied for default values
30 * @return {Object} returns obj
35 Roo.apply = function(o, c, defaults){
37 // no "this" reference for friendly out of scope calls
38 Roo.apply(o, defaults);
40 if(o && c && typeof c == 'object'){
51 var ua = navigator.userAgent.toLowerCase();
53 var isStrict = document.compatMode == "CSS1Compat",
54 isOpera = ua.indexOf("opera") > -1,
55 isSafari = (/webkit|khtml/).test(ua),
56 isIE = ua.indexOf("msie") > -1,
57 isIE7 = ua.indexOf("msie 7") > -1,
58 isGecko = !isSafari && ua.indexOf("gecko") > -1,
59 isBorderBox = isIE && !isStrict,
60 isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
61 isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
62 isLinux = (ua.indexOf("linux") != -1),
63 isSecure = window.location.href.toLowerCase().indexOf("https") === 0;
65 // remove css image flicker
68 document.execCommand("BackgroundImageCache", false, true);
74 * True if the browser is in strict mode
79 * True if the page is running over SSL
84 * True when the document is fully initialized and ready for action
89 * Turn on debugging output (currently only the factory uses this)
96 * True to automatically uncache orphaned Roo.Elements periodically (defaults to true)
99 enableGarbageCollector : true,
102 * True to automatically purge event listeners after uncaching an element (defaults to false).
103 * Note: this only happens if enableGarbageCollector is true.
106 enableListenerCollection:false,
109 * URL to a blank file used by Roo when in secure mode for iframe src and onReady src to prevent
110 * the IE insecure content warning (defaults to javascript:false).
113 SSL_SECURE_URL : "javascript:false",
116 * URL to a 1x1 transparent gif image used by Roo to create inline icons with CSS background images. (Defaults to
117 * "http://Roojs.com/s.gif" and you should change this to a URL on your server).
120 BLANK_IMAGE_URL : "http:/"+"/localhost/s.gif",
122 emptyFn : function(){},
125 * Copies all the properties of config to obj if they don't already exist.
126 * @param {Object} obj The receiver of the properties
127 * @param {Object} config The source of the properties
128 * @return {Object} returns obj
130 applyIf : function(o, c){
133 if(typeof o[p] == "undefined"){ o[p] = c[p]; }
140 * Applies event listeners to elements by selectors when the document is ready.
141 * The event name is specified with an @ suffix.
144 // add a listener for click on all anchors in element with id foo
145 '#foo a@click' : function(e, t){
149 // add the same listener to multiple selectors (separated by comma BEFORE the @)
150 '#foo a, #bar span.some-class@mouseover' : function(){
155 * @param {Object} obj The list of behaviors to apply
157 addBehaviors : function(o){
159 Roo.onReady(function(){
164 var cache = {}; // simple cache for applying multiple behaviors to same selector does query multiple times
166 var parts = b.split('@');
167 if(parts[1]){ // for Object prototype breakers
170 cache[s] = Roo.select(s);
172 cache[s].on(parts[1], o[b]);
179 * Generates unique ids. If the element already has an id, it is unchanged
180 * @param {String/HTMLElement/Element} el (optional) The element to generate an id for
181 * @param {String} prefix (optional) Id prefix (defaults "Roo-gen")
182 * @return {String} The generated Id.
184 id : function(el, prefix){
185 prefix = prefix || "roo-gen";
187 var id = prefix + (++idSeed);
188 return el ? (el.id ? el.id : (el.id = id)) : id;
193 * Extends one class with another class and optionally overrides members with the passed literal. This class
194 * also adds the function "override()" to the class that can be used to override
195 * members on an instance.
196 * @param {Object} subclass The class inheriting the functionality
197 * @param {Object} superclass The class being extended
198 * @param {Object} overrides (optional) A literal with members
203 var io = function(o){
208 return function(sb, sp, overrides){
209 if(typeof sp == 'object'){ // eg. prototype, rather than function constructor..
212 sb = function(){sp.apply(this, arguments);};
214 var F = function(){}, sbp, spp = sp.prototype;
216 sbp = sb.prototype = new F();
220 if(spp.constructor == Object.prototype.constructor){
225 sb.override = function(o){
229 Roo.override(sb, overrides);
235 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
237 Roo.override(MyClass, {
238 newMethod1: function(){
241 newMethod2: function(foo){
246 * @param {Object} origclass The class to override
247 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
248 * containing one or more methods.
251 override : function(origclass, overrides){
253 var p = origclass.prototype;
254 for(var method in overrides){
255 p[method] = overrides[method];
260 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
262 Roo.namespace('Company', 'Company.data');
263 Company.Widget = function() { ... }
264 Company.data.CustomStore = function(config) { ... }
266 * @param {String} namespace1
267 * @param {String} namespace2
268 * @param {String} etc
271 namespace : function(){
272 var a=arguments, o=null, i, j, d, rt;
273 for (i=0; i<a.length; ++i) {
277 eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
278 for (j=1; j<d.length; ++j) {
279 o[d[j]]=o[d[j]] || {};
285 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
287 Roo.factory({ xns: Roo.data, xtype : 'Store', .....});
288 Roo.factory(conf, Roo.data);
290 * @param {String} classname
291 * @param {String} namespace (optional)
295 factory : function(c, ns)
297 // no xtype, no ns or c.xns - or forced off by c.xns
298 if (!c.xtype || (!ns && !c.xns) || (c.xns === false)) { // not enough info...
301 ns = c.xns ? c.xns : ns; // if c.xns is set, then use that..
302 if (c.constructor == ns[c.xtype]) {// already created...
306 if (Roo.debug) Roo.log("Roo.Factory(" + c.xtype + ")");
307 var ret = new ns[c.xtype](c);
311 c.xns = false; // prevent recursion..
315 * Logs to console if it can.
317 * @param {String|Object} string
322 if ((typeof(console) == 'undefined') || (typeof(console.log) == 'undefined')) {
329 * Takes an object and converts it to an encoded URL. e.g. Roo.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2". Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value.
333 urlEncode : function(o){
339 var ov = o[key], k = encodeURIComponent(key);
340 var type = typeof ov;
341 if(type == 'undefined'){
343 }else if(type != "function" && type != "object"){
344 buf.push(k, "=", encodeURIComponent(ov), "&");
345 }else if(ov instanceof Array){
347 for(var i = 0, len = ov.length; i < len; i++) {
348 buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
360 * Takes an encoded URL and and converts it to an object. e.g. Roo.urlDecode("foo=1&bar=2"); would return {foo: 1, bar: 2} or Roo.urlDecode("foo=1&bar=2&bar=3&bar=4", true); would return {foo: 1, bar: [2, 3, 4]}.
361 * @param {String} string
362 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
363 * @return {Object} A literal with members
365 urlDecode : function(string, overwrite){
366 if(!string || !string.length){
370 var pairs = string.split('&');
371 var pair, name, value;
372 for(var i = 0, len = pairs.length; i < len; i++){
373 pair = pairs[i].split('=');
374 name = decodeURIComponent(pair[0]);
375 value = decodeURIComponent(pair[1]);
376 if(overwrite !== true){
377 if(typeof obj[name] == "undefined"){
379 }else if(typeof obj[name] == "string"){
380 obj[name] = [obj[name]];
381 obj[name].push(value);
383 obj[name].push(value);
393 * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
394 * passed array is not really an array, your function is called once with it.
395 * The supplied function is called with (Object item, Number index, Array allItems).
396 * @param {Array/NodeList/Mixed} array
397 * @param {Function} fn
398 * @param {Object} scope
400 each : function(array, fn, scope){
401 if(typeof array.length == "undefined" || typeof array == "string"){
404 for(var i = 0, len = array.length; i < len; i++){
405 if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
410 combine : function(){
411 var as = arguments, l = as.length, r = [];
412 for(var i = 0; i < l; i++){
414 if(a instanceof Array){
416 }else if(a.length !== undefined && !a.substr){
417 r = r.concat(Array.prototype.slice.call(a, 0));
426 * Escapes the passed string for use in a regular expression
427 * @param {String} str
430 escapeRe : function(s) {
431 return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
435 callback : function(cb, scope, args, delay){
436 if(typeof cb == "function"){
438 cb.defer(delay, scope, args || []);
440 cb.apply(scope, args || []);
446 * Return the dom node for the passed string (id), dom node, or Roo.Element
447 * @param {String/HTMLElement/Roo.Element} el
448 * @return HTMLElement
450 getDom : function(el){
454 return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
458 * Shorthand for {@link Roo.ComponentMgr#get}
460 * @return Roo.Component
462 getCmp : function(id){
463 return Roo.ComponentMgr.get(id);
466 num : function(v, defaultValue){
467 if(typeof v != 'number'){
473 destroy : function(){
474 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
478 as.removeAllListeners();
482 if(typeof as.purgeListeners == 'function'){
485 if(typeof as.destroy == 'function'){
492 // inpired by a similar function in mootools library
494 * Returns the type of object that is passed in. If the object passed in is null or undefined it
495 * return false otherwise it returns one of the following values:<ul>
496 * <li><b>string</b>: If the object passed is a string</li>
497 * <li><b>number</b>: If the object passed is a number</li>
498 * <li><b>boolean</b>: If the object passed is a boolean value</li>
499 * <li><b>function</b>: If the object passed is a function reference</li>
500 * <li><b>object</b>: If the object passed is an object</li>
501 * <li><b>array</b>: If the object passed is an array</li>
502 * <li><b>regexp</b>: If the object passed is a regular expression</li>
503 * <li><b>element</b>: If the object passed is a DOM Element</li>
504 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
505 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
506 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
507 * @param {Mixed} object
511 if(o === undefined || o === null){
518 if(t == 'object' && o.nodeName) {
520 case 1: return 'element';
521 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
524 if(t == 'object' || t == 'function') {
525 switch(o.constructor) {
526 case Array: return 'array';
527 case RegExp: return 'regexp';
529 if(typeof o.length == 'number' && typeof o.item == 'function') {
537 * Returns true if the passed value is null, undefined or an empty string (optional).
538 * @param {Mixed} value The value to test
539 * @param {Boolean} allowBlank (optional) Pass true if an empty string is not considered empty
542 isEmpty : function(v, allowBlank){
543 return v === null || v === undefined || (!allowBlank ? v === '' : false);
557 isBorderBox : isBorderBox,
559 isWindows : isWindows,
566 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
567 * you may want to set this to true.
570 useShims : ((isIE && !isIE7) || (isGecko && isMac))
576 Roo.namespace("Roo", "Roo.util", "Roo.grid", "Roo.dd", "Roo.tree", "Roo.data",
577 "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout", "Roo.app", "Roo.ux");
580 * Ext JS Library 1.1.1
581 * Copyright(c) 2006-2007, Ext JS, LLC.
583 * Originally Released Under LGPL - original licence link has changed is not relivant.
586 * <script type="text/javascript">
590 // wrappedn so fnCleanup is not in global scope...
592 function fnCleanUp() {
593 var p = Function.prototype;
594 delete p.createSequence;
596 delete p.createDelegate;
597 delete p.createCallback;
598 delete p.createInterceptor;
600 window.detachEvent("onunload", fnCleanUp);
602 window.attachEvent("onunload", fnCleanUp);
609 * These functions are available on every Function object (any JavaScript function).
611 Roo.apply(Function.prototype, {
613 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
614 * Call directly on any function. Example: <code>myFunction.createCallback(myarg, myarg2)</code>
615 * Will create a function that is bound to those 2 args.
616 * @return {Function} The new function
618 createCallback : function(/*args...*/){
619 // make args available, in function below
620 var args = arguments;
623 return method.apply(window, args);
628 * Creates a delegate (callback) that sets the scope to obj.
629 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this)</code>
630 * Will create a function that is automatically scoped to this.
631 * @param {Object} obj (optional) The object for which the scope is set
632 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
633 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
634 * if a number the args are inserted at the specified position
635 * @return {Function} The new function
637 createDelegate : function(obj, args, appendArgs){
640 var callArgs = args || arguments;
641 if(appendArgs === true){
642 callArgs = Array.prototype.slice.call(arguments, 0);
643 callArgs = callArgs.concat(args);
644 }else if(typeof appendArgs == "number"){
645 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
646 var applyArgs = [appendArgs, 0].concat(args); // create method call params
647 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
649 return method.apply(obj || window, callArgs);
654 * Calls this function after the number of millseconds specified.
655 * @param {Number} millis The number of milliseconds for the setTimeout call (if 0 the function is executed immediately)
656 * @param {Object} obj (optional) The object for which the scope is set
657 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
658 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
659 * if a number the args are inserted at the specified position
660 * @return {Number} The timeout id that can be used with clearTimeout
662 defer : function(millis, obj, args, appendArgs){
663 var fn = this.createDelegate(obj, args, appendArgs);
665 return setTimeout(fn, millis);
671 * Create a combined function call sequence of the original function + the passed function.
672 * The resulting function returns the results of the original function.
673 * The passed fcn is called with the parameters of the original function
674 * @param {Function} fcn The function to sequence
675 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
676 * @return {Function} The new function
678 createSequence : function(fcn, scope){
679 if(typeof fcn != "function"){
684 var retval = method.apply(this || window, arguments);
685 fcn.apply(scope || this || window, arguments);
691 * Creates an interceptor function. The passed fcn is called before the original one. If it returns false, the original one is not called.
692 * The resulting function returns the results of the original function.
693 * The passed fcn is called with the parameters of the original function.
695 * @param {Function} fcn The function to call before the original
696 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
697 * @return {Function} The new function
699 createInterceptor : function(fcn, scope){
700 if(typeof fcn != "function"){
707 if(fcn.apply(scope || this || window, arguments) === false){
710 return method.apply(this || window, arguments);
716 * Ext JS Library 1.1.1
717 * Copyright(c) 2006-2007, Ext JS, LLC.
719 * Originally Released Under LGPL - original licence link has changed is not relivant.
722 * <script type="text/javascript">
725 Roo.applyIf(String, {
730 * Escapes the passed string for ' and \
731 * @param {String} string The string to escape
732 * @return {String} The escaped string
735 escape : function(string) {
736 return string.replace(/('|\\)/g, "\\$1");
740 * Pads the left side of a string with a specified character. This is especially useful
741 * for normalizing number and date strings. Example usage:
743 var s = String.leftPad('123', 5, '0');
744 // s now contains the string: '00123'
746 * @param {String} string The original string
747 * @param {Number} size The total length of the output string
748 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
749 * @return {String} The padded string
752 leftPad : function (val, size, ch) {
753 var result = new String(val);
754 if(ch === null || ch === undefined || ch === '') {
757 while (result.length < size) {
758 result = ch + result;
764 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
765 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
767 var cls = 'my-class', text = 'Some text';
768 var s = String.format('<div class="{0}">{1}</div>', cls, text);
769 // s now contains the string: '<div class="my-class">Some text</div>'
771 * @param {String} string The tokenized string to be formatted
772 * @param {String} value1 The value to replace token {0}
773 * @param {String} value2 Etc...
774 * @return {String} The formatted string
777 format : function(format){
778 var args = Array.prototype.slice.call(arguments, 1);
779 return format.replace(/\{(\d+)\}/g, function(m, i){
780 return Roo.util.Format.htmlEncode(args[i]);
786 * Utility function that allows you to easily switch a string between two alternating values. The passed value
787 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
788 * they are already different, the first value passed in is returned. Note that this method returns the new value
789 * but does not change the current string.
791 // alternate sort directions
792 sort = sort.toggle('ASC', 'DESC');
794 // instead of conditional logic:
795 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
797 * @param {String} value The value to compare to the current string
798 * @param {String} other The new value to use if the string already equals the first value passed in
799 * @return {String} The new value
802 String.prototype.toggle = function(value, other){
803 return this == value ? other : value;
806 * Ext JS Library 1.1.1
807 * Copyright(c) 2006-2007, Ext JS, LLC.
809 * Originally Released Under LGPL - original licence link has changed is not relivant.
812 * <script type="text/javascript">
818 Roo.applyIf(Number.prototype, {
820 * Checks whether or not the current number is within a desired range. If the number is already within the
821 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
822 * exceeded. Note that this method returns the constrained value but does not change the current number.
823 * @param {Number} min The minimum number in the range
824 * @param {Number} max The maximum number in the range
825 * @return {Number} The constrained value if outside the range, otherwise the current value
827 constrain : function(min, max){
828 return Math.min(Math.max(this, min), max);
832 * Ext JS Library 1.1.1
833 * Copyright(c) 2006-2007, Ext JS, LLC.
835 * Originally Released Under LGPL - original licence link has changed is not relivant.
838 * <script type="text/javascript">
843 Roo.applyIf(Array.prototype, {
845 * Checks whether or not the specified object exists in the array.
846 * @param {Object} o The object to check for
847 * @return {Number} The index of o in the array (or -1 if it is not found)
849 indexOf : function(o){
850 for (var i = 0, len = this.length; i < len; i++){
851 if(this[i] == o) return i;
857 * Removes the specified object from the array. If the object is not found nothing happens.
858 * @param {Object} o The object to remove
860 remove : function(o){
861 var index = this.indexOf(o);
863 this.splice(index, 1);
867 * Map (JS 1.6 compatibility)
868 * @param {Function} function to call
872 var len = this.length >>> 0;
873 if (typeof fun != "function")
874 throw new TypeError();
876 var res = new Array(len);
877 var thisp = arguments[1];
878 for (var i = 0; i < len; i++)
881 res[i] = fun.call(thisp, this[i], i, this);
892 * Ext JS Library 1.1.1
893 * Copyright(c) 2006-2007, Ext JS, LLC.
895 * Originally Released Under LGPL - original licence link has changed is not relivant.
898 * <script type="text/javascript">
904 * The date parsing and format syntax is a subset of
905 * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
906 * supported will provide results equivalent to their PHP versions.
908 * Following is the list of all currently supported formats:
911 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
913 Format Output Description
914 ------ ---------- --------------------------------------------------------------
915 d 10 Day of the month, 2 digits with leading zeros
916 D Wed A textual representation of a day, three letters
917 j 10 Day of the month without leading zeros
918 l Wednesday A full textual representation of the day of the week
919 S th English ordinal day of month suffix, 2 chars (use with j)
920 w 3 Numeric representation of the day of the week
921 z 9 The julian date, or day of the year (0-365)
922 W 01 ISO-8601 2-digit week number of year, weeks starting on Monday (00-52)
923 F January A full textual representation of the month
924 m 01 Numeric representation of a month, with leading zeros
925 M Jan Month name abbreviation, three letters
926 n 1 Numeric representation of a month, without leading zeros
927 t 31 Number of days in the given month
928 L 0 Whether it's a leap year (1 if it is a leap year, else 0)
929 Y 2007 A full numeric representation of a year, 4 digits
930 y 07 A two digit representation of a year
931 a pm Lowercase Ante meridiem and Post meridiem
932 A PM Uppercase Ante meridiem and Post meridiem
933 g 3 12-hour format of an hour without leading zeros
934 G 15 24-hour format of an hour without leading zeros
935 h 03 12-hour format of an hour with leading zeros
936 H 15 24-hour format of an hour with leading zeros
937 i 05 Minutes with leading zeros
938 s 01 Seconds, with leading zeros
939 O -0600 Difference to Greenwich time (GMT) in hours
940 T CST Timezone setting of the machine running the code
941 Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east)
944 * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
946 var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
947 document.write(dt.format('Y-m-d')); //2007-01-10
948 document.write(dt.format('F j, Y, g:i a')); //January 10, 2007, 3:05 pm
949 document.write(dt.format('l, \\t\\he dS of F Y h:i:s A')); //Wednesday, the 10th of January 2007 03:05:01 PM
952 * Here are some standard date/time patterns that you might find helpful. They
953 * are not part of the source of Date.js, but to use them you can simply copy this
954 * block of code into any script that is included after Date.js and they will also become
955 * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
958 ISO8601Long:"Y-m-d H:i:s",
959 ISO8601Short:"Y-m-d",
961 LongDate: "l, F d, Y",
962 FullDateTime: "l, F d, Y g:i:s A",
966 SortableDateTime: "Y-m-d\\TH:i:s",
967 UniversalSortableDateTime: "Y-m-d H:i:sO",
975 document.write(dt.format(Date.patterns.ShortDate));
980 * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
981 * They generate precompiled functions from date formats instead of parsing and
982 * processing the pattern every time you format a date. These functions are available
983 * on every Date object (any javascript function).
985 * The original article and download are here:
986 * http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
993 Returns the number of milliseconds between this date and date
994 @param {Date} date (optional) Defaults to now
995 @return {Number} The diff in milliseconds
996 @member Date getElapsed
998 Date.prototype.getElapsed = function(date) {
999 return Math.abs((date || new Date()).getTime()-this.getTime());
1001 // was in date file..
1005 Date.parseFunctions = {count:0};
1007 Date.parseRegexes = [];
1009 Date.formatFunctions = {count:0};
1012 Date.prototype.dateFormat = function(format) {
1013 if (Date.formatFunctions[format] == null) {
1014 Date.createNewFormat(format);
1016 var func = Date.formatFunctions[format];
1017 return this[func]();
1022 * Formats a date given the supplied format string
1023 * @param {String} format The format string
1024 * @return {String} The formatted date
1027 Date.prototype.format = Date.prototype.dateFormat;
1030 Date.createNewFormat = function(format) {
1031 var funcName = "format" + Date.formatFunctions.count++;
1032 Date.formatFunctions[format] = funcName;
1033 var code = "Date.prototype." + funcName + " = function(){return ";
1034 var special = false;
1036 for (var i = 0; i < format.length; ++i) {
1037 ch = format.charAt(i);
1038 if (!special && ch == "\\") {
1043 code += "'" + String.escape(ch) + "' + ";
1046 code += Date.getFormatCode(ch);
1049 /** eval:var:zzzzzzzzzzzzz */
1050 eval(code.substring(0, code.length - 3) + ";}");
1054 Date.getFormatCode = function(character) {
1055 switch (character) {
1057 return "String.leftPad(this.getDate(), 2, '0') + ";
1059 return "Date.dayNames[this.getDay()].substring(0, 3) + ";
1061 return "this.getDate() + ";
1063 return "Date.dayNames[this.getDay()] + ";
1065 return "this.getSuffix() + ";
1067 return "this.getDay() + ";
1069 return "this.getDayOfYear() + ";
1071 return "this.getWeekOfYear() + ";
1073 return "Date.monthNames[this.getMonth()] + ";
1075 return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
1077 return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
1079 return "(this.getMonth() + 1) + ";
1081 return "this.getDaysInMonth() + ";
1083 return "(this.isLeapYear() ? 1 : 0) + ";
1085 return "this.getFullYear() + ";
1087 return "('' + this.getFullYear()).substring(2, 4) + ";
1089 return "(this.getHours() < 12 ? 'am' : 'pm') + ";
1091 return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
1093 return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";
1095 return "this.getHours() + ";
1097 return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
1099 return "String.leftPad(this.getHours(), 2, '0') + ";
1101 return "String.leftPad(this.getMinutes(), 2, '0') + ";
1103 return "String.leftPad(this.getSeconds(), 2, '0') + ";
1105 return "this.getGMTOffset() + ";
1107 return "this.getTimezone() + ";
1109 return "(this.getTimezoneOffset() * -60) + ";
1111 return "'" + String.escape(character) + "' + ";
1116 * Parses the passed string using the specified format. Note that this function expects dates in normal calendar
1117 * format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of
1118 * the date format that is not specified will default to the current date value for that part. Time parts can also
1119 * be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format
1120 * string or the parse operation will fail.
1123 //dt = Fri May 25 2007 (current date)
1124 var dt = new Date();
1126 //dt = Thu May 25 2006 (today's month/day in 2006)
1127 dt = Date.parseDate("2006", "Y");
1129 //dt = Sun Jan 15 2006 (all date parts specified)
1130 dt = Date.parseDate("2006-1-15", "Y-m-d");
1132 //dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)
1133 dt = Date.parseDate("2006-1-15 3:20:01 PM", "Y-m-d h:i:s A" );
1135 * @param {String} input The unparsed date as a string
1136 * @param {String} format The format the date is in
1137 * @return {Date} The parsed date
1140 Date.parseDate = function(input, format) {
1141 if (Date.parseFunctions[format] == null) {
1142 Date.createParser(format);
1144 var func = Date.parseFunctions[format];
1145 return Date[func](input);
1150 Date.createParser = function(format) {
1151 var funcName = "parse" + Date.parseFunctions.count++;
1152 var regexNum = Date.parseRegexes.length;
1153 var currentGroup = 1;
1154 Date.parseFunctions[format] = funcName;
1156 var code = "Date." + funcName + " = function(input){\n"
1157 + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, o, z, v;\n"
1158 + "var d = new Date();\n"
1159 + "y = d.getFullYear();\n"
1160 + "m = d.getMonth();\n"
1161 + "d = d.getDate();\n"
1162 + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
1163 + "if (results && results.length > 0) {";
1166 var special = false;
1168 for (var i = 0; i < format.length; ++i) {
1169 ch = format.charAt(i);
1170 if (!special && ch == "\\") {
1175 regex += String.escape(ch);
1178 var obj = Date.formatCodeToRegex(ch, currentGroup);
1179 currentGroup += obj.g;
1181 if (obj.g && obj.c) {
1187 code += "if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
1188 + "{v = new Date(y, m, d, h, i, s);}\n"
1189 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
1190 + "{v = new Date(y, m, d, h, i);}\n"
1191 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
1192 + "{v = new Date(y, m, d, h);}\n"
1193 + "else if (y >= 0 && m >= 0 && d > 0)\n"
1194 + "{v = new Date(y, m, d);}\n"
1195 + "else if (y >= 0 && m >= 0)\n"
1196 + "{v = new Date(y, m);}\n"
1197 + "else if (y >= 0)\n"
1198 + "{v = new Date(y);}\n"
1199 + "}return (v && (z || o))?\n" // favour UTC offset over GMT offset
1200 + " ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset
1201 + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset
1204 Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
1205 /** eval:var:zzzzzzzzzzzzz */
1210 Date.formatCodeToRegex = function(character, currentGroup) {
1211 switch (character) {
1215 s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
1218 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1219 s:"(\\d{1,2})"}; // day of month without leading zeroes
1222 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1223 s:"(\\d{2})"}; // day of month with leading zeroes
1227 s:"(?:" + Date.dayNames.join("|") + ")"};
1231 s:"(?:st|nd|rd|th)"};
1246 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
1247 s:"(" + Date.monthNames.join("|") + ")"};
1250 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
1251 s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
1254 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1255 s:"(\\d{1,2})"}; // Numeric representation of a month, without leading zeros
1258 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1259 s:"(\\d{2})"}; // Numeric representation of a month, with leading zeros
1270 c:"y = parseInt(results[" + currentGroup + "], 10);\n",
1274 c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
1275 + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
1279 c:"if (results[" + currentGroup + "] == 'am') {\n"
1280 + "if (h == 12) { h = 0; }\n"
1281 + "} else { if (h < 12) { h += 12; }}",
1285 c:"if (results[" + currentGroup + "] == 'AM') {\n"
1286 + "if (h == 12) { h = 0; }\n"
1287 + "} else { if (h < 12) { h += 12; }}",
1292 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1293 s:"(\\d{1,2})"}; // 12/24-hr format format of an hour without leading zeroes
1297 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1298 s:"(\\d{2})"}; // 12/24-hr format format of an hour with leading zeroes
1301 c:"i = parseInt(results[" + currentGroup + "], 10);\n",
1305 c:"s = parseInt(results[" + currentGroup + "], 10);\n",
1310 "o = results[", currentGroup, "];\n",
1311 "var sn = o.substring(0,1);\n", // get + / - sign
1312 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n", // get hours (performs minutes-to-hour conversion also)
1313 "var mn = o.substring(3,5) % 60;\n", // get minutes
1314 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
1315 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1321 s:"[A-Z]{1,4}"}; // timezone abbrev. may be between 1 - 4 chars
1324 c:"z = results[" + currentGroup + "];\n" // -43200 <= UTC offset <= 50400
1325 + "z = (-43200 <= z*1 && z*1 <= 50400)? z : null;\n",
1326 s:"([+\-]?\\d{1,5})"}; // leading '+' sign is optional for UTC offset
1330 s:String.escape(character)};
1335 * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1336 * @return {String} The abbreviated timezone name (e.g. 'CST')
1338 Date.prototype.getTimezone = function() {
1339 return this.toString().replace(/^.*? ([A-Z]{1,4})[\-+][0-9]{4} .*$/, "$1");
1343 * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
1344 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600')
1346 Date.prototype.getGMTOffset = function() {
1347 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1348 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1349 + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
1353 * Get the numeric day number of the year, adjusted for leap year.
1354 * @return {Number} 0 through 364 (365 in leap years)
1356 Date.prototype.getDayOfYear = function() {
1358 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1359 for (var i = 0; i < this.getMonth(); ++i) {
1360 num += Date.daysInMonth[i];
1362 return num + this.getDate() - 1;
1366 * Get the string representation of the numeric week number of the year
1367 * (equivalent to the format specifier 'W').
1368 * @return {String} '00' through '52'
1370 Date.prototype.getWeekOfYear = function() {
1371 // Skip to Thursday of this week
1372 var now = this.getDayOfYear() + (4 - this.getDay());
1373 // Find the first Thursday of the year
1374 var jan1 = new Date(this.getFullYear(), 0, 1);
1375 var then = (7 - jan1.getDay() + 4);
1376 return String.leftPad(((now - then) / 7) + 1, 2, "0");
1380 * Whether or not the current date is in a leap year.
1381 * @return {Boolean} True if the current date is in a leap year, else false
1383 Date.prototype.isLeapYear = function() {
1384 var year = this.getFullYear();
1385 return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
1389 * Get the first day of the current month, adjusted for leap year. The returned value
1390 * is the numeric day index within the week (0-6) which can be used in conjunction with
1391 * the {@link #monthNames} array to retrieve the textual day name.
1394 var dt = new Date('1/10/2007');
1395 document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
1397 * @return {Number} The day number (0-6)
1399 Date.prototype.getFirstDayOfMonth = function() {
1400 var day = (this.getDay() - (this.getDate() - 1)) % 7;
1401 return (day < 0) ? (day + 7) : day;
1405 * Get the last day of the current month, adjusted for leap year. The returned value
1406 * is the numeric day index within the week (0-6) which can be used in conjunction with
1407 * the {@link #monthNames} array to retrieve the textual day name.
1410 var dt = new Date('1/10/2007');
1411 document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
1413 * @return {Number} The day number (0-6)
1415 Date.prototype.getLastDayOfMonth = function() {
1416 var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
1417 return (day < 0) ? (day + 7) : day;
1422 * Get the first date of this date's month
1425 Date.prototype.getFirstDateOfMonth = function() {
1426 return new Date(this.getFullYear(), this.getMonth(), 1);
1430 * Get the last date of this date's month
1433 Date.prototype.getLastDateOfMonth = function() {
1434 return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
1437 * Get the number of days in the current month, adjusted for leap year.
1438 * @return {Number} The number of days in the month
1440 Date.prototype.getDaysInMonth = function() {
1441 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1442 return Date.daysInMonth[this.getMonth()];
1446 * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
1447 * @return {String} 'st, 'nd', 'rd' or 'th'
1449 Date.prototype.getSuffix = function() {
1450 switch (this.getDate()) {
1467 Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
1470 * An array of textual month names.
1471 * Override these values for international dates, for example...
1472 * Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...];
1491 * An array of textual day names.
1492 * Override these values for international dates, for example...
1493 * Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...];
1509 Date.monthNumbers = {
1524 * Creates and returns a new Date instance with the exact same date value as the called instance.
1525 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
1526 * variable will also be changed. When the intention is to create a new variable that will not
1527 * modify the original instance, you should create a clone.
1529 * Example of correctly cloning a date:
1532 var orig = new Date('10/1/2006');
1535 document.write(orig); //returns 'Thu Oct 05 2006'!
1538 var orig = new Date('10/1/2006');
1539 var copy = orig.clone();
1541 document.write(orig); //returns 'Thu Oct 01 2006'
1543 * @return {Date} The new Date instance
1545 Date.prototype.clone = function() {
1546 return new Date(this.getTime());
1550 * Clears any time information from this date
1551 @param {Boolean} clone true to create a clone of this date, clear the time and return it
1552 @return {Date} this or the clone
1554 Date.prototype.clearTime = function(clone){
1556 return this.clone().clearTime();
1561 this.setMilliseconds(0);
1566 // safari setMonth is broken
1568 Date.brokenSetMonth = Date.prototype.setMonth;
1569 Date.prototype.setMonth = function(num){
1571 var n = Math.ceil(-num);
1572 var back_year = Math.ceil(n/12);
1573 var month = (n % 12) ? 12 - n % 12 : 0 ;
1574 this.setFullYear(this.getFullYear() - back_year);
1575 return Date.brokenSetMonth.call(this, month);
1577 return Date.brokenSetMonth.apply(this, arguments);
1582 /** Date interval constant
1586 /** Date interval constant
1590 /** Date interval constant
1594 /** Date interval constant
1598 /** Date interval constant
1602 /** Date interval constant
1606 /** Date interval constant
1612 * Provides a convenient method of performing basic date arithmetic. This method
1613 * does not modify the Date instance being called - it creates and returns
1614 * a new Date instance containing the resulting date value.
1619 var dt = new Date('10/29/2006').add(Date.DAY, 5);
1620 document.write(dt); //returns 'Fri Oct 06 2006 00:00:00'
1622 //Negative values will subtract correctly:
1623 var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
1624 document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
1626 //You can even chain several calls together in one line!
1627 var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
1628 document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
1631 * @param {String} interval A valid date interval enum value
1632 * @param {Number} value The amount to add to the current date
1633 * @return {Date} The new Date instance
1635 Date.prototype.add = function(interval, value){
1636 var d = this.clone();
1637 if (!interval || value === 0) return d;
1638 switch(interval.toLowerCase()){
1640 d.setMilliseconds(this.getMilliseconds() + value);
1643 d.setSeconds(this.getSeconds() + value);
1646 d.setMinutes(this.getMinutes() + value);
1649 d.setHours(this.getHours() + value);
1652 d.setDate(this.getDate() + value);
1655 var day = this.getDate();
1657 day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
1660 d.setMonth(this.getMonth() + value);
1663 d.setFullYear(this.getFullYear() + value);
1669 * Ext JS Library 1.1.1
1670 * Copyright(c) 2006-2007, Ext JS, LLC.
1672 * Originally Released Under LGPL - original licence link has changed is not relivant.
1675 * <script type="text/javascript">
1679 getViewWidth : function(full) {
1680 return full ? this.getDocumentWidth() : this.getViewportWidth();
1683 getViewHeight : function(full) {
1684 return full ? this.getDocumentHeight() : this.getViewportHeight();
1687 getDocumentHeight: function() {
1688 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
1689 return Math.max(scrollHeight, this.getViewportHeight());
1692 getDocumentWidth: function() {
1693 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
1694 return Math.max(scrollWidth, this.getViewportWidth());
1697 getViewportHeight: function() {
1698 var height = self.innerHeight;
1699 var mode = document.compatMode;
1701 if ((mode || Roo.isIE) && !Roo.isOpera) {
1702 height = (mode == "CSS1Compat") ?
1703 document.documentElement.clientHeight :
1704 document.body.clientHeight;
1710 getViewportWidth: function() {
1711 var width = self.innerWidth;
1712 var mode = document.compatMode;
1714 if (mode || Roo.isIE) {
1715 width = (mode == "CSS1Compat") ?
1716 document.documentElement.clientWidth :
1717 document.body.clientWidth;
1722 isAncestor : function(p, c) {
1729 if (p.contains && !Roo.isSafari) {
1730 return p.contains(c);
1731 } else if (p.compareDocumentPosition) {
1732 return !!(p.compareDocumentPosition(c) & 16);
1734 var parent = c.parentNode;
1739 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
1742 parent = parent.parentNode;
1748 getRegion : function(el) {
1749 return Roo.lib.Region.getRegion(el);
1752 getY : function(el) {
1753 return this.getXY(el)[1];
1756 getX : function(el) {
1757 return this.getXY(el)[0];
1760 getXY : function(el) {
1761 var p, pe, b, scroll, bd = document.body;
1762 el = Roo.getDom(el);
1763 var fly = Roo.lib.AnimBase.fly;
1764 if (el.getBoundingClientRect) {
1765 b = el.getBoundingClientRect();
1766 scroll = fly(document).getScroll();
1767 return [b.left + scroll.left, b.top + scroll.top];
1773 var hasAbsolute = fly(el).getStyle("position") == "absolute";
1780 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
1787 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1788 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1795 if (p != el && pe.getStyle('overflow') != 'visible') {
1803 if (Roo.isSafari && hasAbsolute) {
1808 if (Roo.isGecko && !hasAbsolute) {
1810 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1811 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1815 while (p && p != bd) {
1816 if (!Roo.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
1828 setXY : function(el, xy) {
1829 el = Roo.fly(el, '_setXY');
1831 var pts = el.translatePoints(xy);
1832 if (xy[0] !== false) {
1833 el.dom.style.left = pts.left + "px";
1835 if (xy[1] !== false) {
1836 el.dom.style.top = pts.top + "px";
1840 setX : function(el, x) {
1841 this.setXY(el, [x, false]);
1844 setY : function(el, y) {
1845 this.setXY(el, [false, y]);
1849 * Portions of this file are based on pieces of Yahoo User Interface Library
1850 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
1851 * YUI licensed under the BSD License:
1852 * http://developer.yahoo.net/yui/license.txt
1853 * <script type="text/javascript">
1857 Roo.lib.Event = function() {
1858 var loadComplete = false;
1860 var unloadListeners = [];
1862 var onAvailStack = [];
1864 var lastError = null;
1877 startInterval: function() {
1878 if (!this._interval) {
1880 var callback = function() {
1881 self._tryPreloadAttach();
1883 this._interval = setInterval(callback, this.POLL_INTERVAL);
1888 onAvailable: function(p_id, p_fn, p_obj, p_override) {
1889 onAvailStack.push({ id: p_id,
1892 override: p_override,
1893 checkReady: false });
1895 retryCount = this.POLL_RETRYS;
1896 this.startInterval();
1900 addListener: function(el, eventName, fn) {
1901 el = Roo.getDom(el);
1906 if ("unload" == eventName) {
1907 unloadListeners[unloadListeners.length] =
1908 [el, eventName, fn];
1912 var wrappedFn = function(e) {
1913 return fn(Roo.lib.Event.getEvent(e));
1916 var li = [el, eventName, fn, wrappedFn];
1918 var index = listeners.length;
1919 listeners[index] = li;
1921 this.doAdd(el, eventName, wrappedFn, false);
1927 removeListener: function(el, eventName, fn) {
1930 el = Roo.getDom(el);
1933 return this.purgeElement(el, false, eventName);
1937 if ("unload" == eventName) {
1939 for (i = 0,len = unloadListeners.length; i < len; i++) {
1940 var li = unloadListeners[i];
1943 li[1] == eventName &&
1945 unloadListeners.splice(i, 1);
1953 var cacheItem = null;
1956 var index = arguments[3];
1958 if ("undefined" == typeof index) {
1959 index = this._getCacheIndex(el, eventName, fn);
1963 cacheItem = listeners[index];
1966 if (!el || !cacheItem) {
1970 this.doRemove(el, eventName, cacheItem[this.WFN], false);
1972 delete listeners[index][this.WFN];
1973 delete listeners[index][this.FN];
1974 listeners.splice(index, 1);
1981 getTarget: function(ev, resolveTextNode) {
1982 ev = ev.browserEvent || ev;
1983 var t = ev.target || ev.srcElement;
1984 return this.resolveTextNode(t);
1988 resolveTextNode: function(node) {
1989 if (Roo.isSafari && node && 3 == node.nodeType) {
1990 return node.parentNode;
1997 getPageX: function(ev) {
1998 ev = ev.browserEvent || ev;
2000 if (!x && 0 !== x) {
2001 x = ev.clientX || 0;
2004 x += this.getScroll()[1];
2012 getPageY: function(ev) {
2013 ev = ev.browserEvent || ev;
2015 if (!y && 0 !== y) {
2016 y = ev.clientY || 0;
2019 y += this.getScroll()[0];
2028 getXY: function(ev) {
2029 ev = ev.browserEvent || ev;
2030 return [this.getPageX(ev), this.getPageY(ev)];
2034 getRelatedTarget: function(ev) {
2035 ev = ev.browserEvent || ev;
2036 var t = ev.relatedTarget;
2038 if (ev.type == "mouseout") {
2040 } else if (ev.type == "mouseover") {
2045 return this.resolveTextNode(t);
2049 getTime: function(ev) {
2050 ev = ev.browserEvent || ev;
2052 var t = new Date().getTime();
2056 this.lastError = ex;
2065 stopEvent: function(ev) {
2066 this.stopPropagation(ev);
2067 this.preventDefault(ev);
2071 stopPropagation: function(ev) {
2072 ev = ev.browserEvent || ev;
2073 if (ev.stopPropagation) {
2074 ev.stopPropagation();
2076 ev.cancelBubble = true;
2081 preventDefault: function(ev) {
2082 ev = ev.browserEvent || ev;
2083 if(ev.preventDefault) {
2084 ev.preventDefault();
2086 ev.returnValue = false;
2091 getEvent: function(e) {
2092 var ev = e || window.event;
2094 var c = this.getEvent.caller;
2096 ev = c.arguments[0];
2097 if (ev && Event == ev.constructor) {
2107 getCharCode: function(ev) {
2108 ev = ev.browserEvent || ev;
2109 return ev.charCode || ev.keyCode || 0;
2113 _getCacheIndex: function(el, eventName, fn) {
2114 for (var i = 0,len = listeners.length; i < len; ++i) {
2115 var li = listeners[i];
2117 li[this.FN] == fn &&
2118 li[this.EL] == el &&
2119 li[this.TYPE] == eventName) {
2131 getEl: function(id) {
2132 return document.getElementById(id);
2136 clearCache: function() {
2140 _load: function(e) {
2141 loadComplete = true;
2142 var EU = Roo.lib.Event;
2146 EU.doRemove(window, "load", EU._load);
2151 _tryPreloadAttach: function() {
2160 var tryAgain = !loadComplete;
2162 tryAgain = (retryCount > 0);
2167 for (var i = 0,len = onAvailStack.length; i < len; ++i) {
2168 var item = onAvailStack[i];
2170 var el = this.getEl(item.id);
2173 if (!item.checkReady ||
2176 (document && document.body)) {
2179 if (item.override) {
2180 if (item.override === true) {
2183 scope = item.override;
2186 item.fn.call(scope, item.obj);
2187 onAvailStack[i] = null;
2190 notAvail.push(item);
2195 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2199 this.startInterval();
2201 clearInterval(this._interval);
2202 this._interval = null;
2205 this.locked = false;
2212 purgeElement: function(el, recurse, eventName) {
2213 var elListeners = this.getListeners(el, eventName);
2215 for (var i = 0,len = elListeners.length; i < len; ++i) {
2216 var l = elListeners[i];
2217 this.removeListener(el, l.type, l.fn);
2221 if (recurse && el && el.childNodes) {
2222 for (i = 0,len = el.childNodes.length; i < len; ++i) {
2223 this.purgeElement(el.childNodes[i], recurse, eventName);
2229 getListeners: function(el, eventName) {
2230 var results = [], searchLists;
2232 searchLists = [listeners, unloadListeners];
2233 } else if (eventName == "unload") {
2234 searchLists = [unloadListeners];
2236 searchLists = [listeners];
2239 for (var j = 0; j < searchLists.length; ++j) {
2240 var searchList = searchLists[j];
2241 if (searchList && searchList.length > 0) {
2242 for (var i = 0,len = searchList.length; i < len; ++i) {
2243 var l = searchList[i];
2244 if (l && l[this.EL] === el &&
2245 (!eventName || eventName === l[this.TYPE])) {
2250 adjust: l[this.ADJ_SCOPE],
2258 return (results.length) ? results : null;
2262 _unload: function(e) {
2264 var EU = Roo.lib.Event, i, j, l, len, index;
2266 for (i = 0,len = unloadListeners.length; i < len; ++i) {
2267 l = unloadListeners[i];
2270 if (l[EU.ADJ_SCOPE]) {
2271 if (l[EU.ADJ_SCOPE] === true) {
2274 scope = l[EU.ADJ_SCOPE];
2277 l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
2278 unloadListeners[i] = null;
2284 unloadListeners = null;
2286 if (listeners && listeners.length > 0) {
2287 j = listeners.length;
2290 l = listeners[index];
2292 EU.removeListener(l[EU.EL], l[EU.TYPE],
2302 EU.doRemove(window, "unload", EU._unload);
2307 getScroll: function() {
2308 var dd = document.documentElement, db = document.body;
2309 if (dd && (dd.scrollTop || dd.scrollLeft)) {
2310 return [dd.scrollTop, dd.scrollLeft];
2312 return [db.scrollTop, db.scrollLeft];
2319 doAdd: function () {
2320 if (window.addEventListener) {
2321 return function(el, eventName, fn, capture) {
2322 el.addEventListener(eventName, fn, (capture));
2324 } else if (window.attachEvent) {
2325 return function(el, eventName, fn, capture) {
2326 el.attachEvent("on" + eventName, fn);
2335 doRemove: function() {
2336 if (window.removeEventListener) {
2337 return function (el, eventName, fn, capture) {
2338 el.removeEventListener(eventName, fn, (capture));
2340 } else if (window.detachEvent) {
2341 return function (el, eventName, fn) {
2342 el.detachEvent("on" + eventName, fn);
2354 var E = Roo.lib.Event;
2355 E.on = E.addListener;
2356 E.un = E.removeListener;
2358 if (document && document.body) {
2361 E.doAdd(window, "load", E._load);
2363 E.doAdd(window, "unload", E._unload);
2364 E._tryPreloadAttach();
2368 * Portions of this file are based on pieces of Yahoo User Interface Library
2369 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2370 * YUI licensed under the BSD License:
2371 * http://developer.yahoo.net/yui/license.txt
2372 * <script type="text/javascript">
2379 request : function(method, uri, cb, data, options) {
2381 var hs = options.headers;
2384 if(hs.hasOwnProperty(h)){
2385 this.initHeader(h, hs[h], false);
2389 if(options.xmlData){
2390 this.initHeader('Content-Type', 'text/xml', false);
2392 data = options.xmlData;
2396 return this.asyncRequest(method, uri, cb, data);
2399 serializeForm : function(form) {
2400 if(typeof form == 'string') {
2401 form = (document.getElementById(form) || document.forms[form]);
2404 var el, name, val, disabled, data = '', hasSubmit = false;
2405 for (var i = 0; i < form.elements.length; i++) {
2406 el = form.elements[i];
2407 disabled = form.elements[i].disabled;
2408 name = form.elements[i].name;
2409 val = form.elements[i].value;
2411 if (!disabled && name){
2415 case 'select-multiple':
2416 for (var j = 0; j < el.options.length; j++) {
2417 if (el.options[j].selected) {
2419 data += encodeURIComponent(name) + '=' + encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
2422 data += encodeURIComponent(name) + '=' + encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
2430 data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
2443 if(hasSubmit == false) {
2444 data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
2449 data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
2454 data = data.substr(0, data.length - 1);
2462 useDefaultHeader:true,
2464 defaultPostHeader:'application/x-www-form-urlencoded',
2466 useDefaultXhrHeader:true,
2468 defaultXhrHeader:'XMLHttpRequest',
2470 hasDefaultHeaders:true,
2482 setProgId:function(id)
2484 this.activeX.unshift(id);
2487 setDefaultPostHeader:function(b)
2489 this.useDefaultHeader = b;
2492 setDefaultXhrHeader:function(b)
2494 this.useDefaultXhrHeader = b;
2497 setPollingInterval:function(i)
2499 if (typeof i == 'number' && isFinite(i)) {
2500 this.pollInterval = i;
2504 createXhrObject:function(transactionId)
2510 http = new XMLHttpRequest();
2512 obj = { conn:http, tId:transactionId };
2516 for (var i = 0; i < this.activeX.length; ++i) {
2520 http = new ActiveXObject(this.activeX[i]);
2522 obj = { conn:http, tId:transactionId };
2535 getConnectionObject:function()
2538 var tId = this.transactionId;
2542 o = this.createXhrObject(tId);
2544 this.transactionId++;
2555 asyncRequest:function(method, uri, callback, postData)
2557 var o = this.getConnectionObject();
2563 o.conn.open(method, uri, true);
2565 if (this.useDefaultXhrHeader) {
2566 if (!this.defaultHeaders['X-Requested-With']) {
2567 this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
2571 if(postData && this.useDefaultHeader){
2572 this.initHeader('Content-Type', this.defaultPostHeader);
2575 if (this.hasDefaultHeaders || this.hasHeaders) {
2579 this.handleReadyState(o, callback);
2580 o.conn.send(postData || null);
2586 handleReadyState:function(o, callback)
2590 if (callback && callback.timeout) {
2591 this.timeout[o.tId] = window.setTimeout(function() {
2592 oConn.abort(o, callback, true);
2593 }, callback.timeout);
2596 this.poll[o.tId] = window.setInterval(
2598 if (o.conn && o.conn.readyState == 4) {
2599 window.clearInterval(oConn.poll[o.tId]);
2600 delete oConn.poll[o.tId];
2602 if(callback && callback.timeout) {
2603 window.clearTimeout(oConn.timeout[o.tId]);
2604 delete oConn.timeout[o.tId];
2607 oConn.handleTransactionResponse(o, callback);
2610 , this.pollInterval);
2613 handleTransactionResponse:function(o, callback, isAbort)
2617 this.releaseObject(o);
2621 var httpStatus, responseObject;
2625 if (o.conn.status !== undefined && o.conn.status != 0) {
2626 httpStatus = o.conn.status;
2638 if (httpStatus >= 200 && httpStatus < 300) {
2639 responseObject = this.createResponseObject(o, callback.argument);
2640 if (callback.success) {
2641 if (!callback.scope) {
2642 callback.success(responseObject);
2647 callback.success.apply(callback.scope, [responseObject]);
2652 switch (httpStatus) {
2660 responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
2661 if (callback.failure) {
2662 if (!callback.scope) {
2663 callback.failure(responseObject);
2666 callback.failure.apply(callback.scope, [responseObject]);
2671 responseObject = this.createResponseObject(o, callback.argument);
2672 if (callback.failure) {
2673 if (!callback.scope) {
2674 callback.failure(responseObject);
2677 callback.failure.apply(callback.scope, [responseObject]);
2683 this.releaseObject(o);
2684 responseObject = null;
2687 createResponseObject:function(o, callbackArg)
2694 var headerStr = o.conn.getAllResponseHeaders();
2695 var header = headerStr.split('\n');
2696 for (var i = 0; i < header.length; i++) {
2697 var delimitPos = header[i].indexOf(':');
2698 if (delimitPos != -1) {
2699 headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
2707 obj.status = o.conn.status;
2708 obj.statusText = o.conn.statusText;
2709 obj.getResponseHeader = headerObj;
2710 obj.getAllResponseHeaders = headerStr;
2711 obj.responseText = o.conn.responseText;
2712 obj.responseXML = o.conn.responseXML;
2714 if (typeof callbackArg !== undefined) {
2715 obj.argument = callbackArg;
2721 createExceptionObject:function(tId, callbackArg, isAbort)
2724 var COMM_ERROR = 'communication failure';
2725 var ABORT_CODE = -1;
2726 var ABORT_ERROR = 'transaction aborted';
2732 obj.status = ABORT_CODE;
2733 obj.statusText = ABORT_ERROR;
2736 obj.status = COMM_CODE;
2737 obj.statusText = COMM_ERROR;
2741 obj.argument = callbackArg;
2747 initHeader:function(label, value, isDefault)
2749 var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
2751 if (headerObj[label] === undefined) {
2752 headerObj[label] = value;
2757 headerObj[label] = value + "," + headerObj[label];
2761 this.hasDefaultHeaders = true;
2764 this.hasHeaders = true;
2769 setHeader:function(o)
2771 if (this.hasDefaultHeaders) {
2772 for (var prop in this.defaultHeaders) {
2773 if (this.defaultHeaders.hasOwnProperty(prop)) {
2774 o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
2779 if (this.hasHeaders) {
2780 for (var prop in this.headers) {
2781 if (this.headers.hasOwnProperty(prop)) {
2782 o.conn.setRequestHeader(prop, this.headers[prop]);
2786 this.hasHeaders = false;
2790 resetDefaultHeaders:function() {
2791 delete this.defaultHeaders;
2792 this.defaultHeaders = {};
2793 this.hasDefaultHeaders = false;
2796 abort:function(o, callback, isTimeout)
2798 if(this.isCallInProgress(o)) {
2800 window.clearInterval(this.poll[o.tId]);
2801 delete this.poll[o.tId];
2803 delete this.timeout[o.tId];
2806 this.handleTransactionResponse(o, callback, true);
2816 isCallInProgress:function(o)
2819 return o.conn.readyState != 4 && o.conn.readyState != 0;
2828 releaseObject:function(o)
2837 'MSXML2.XMLHTTP.3.0',
2845 * Portions of this file are based on pieces of Yahoo User Interface Library
2846 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2847 * YUI licensed under the BSD License:
2848 * http://developer.yahoo.net/yui/license.txt
2849 * <script type="text/javascript">
2853 Roo.lib.Region = function(t, r, b, l) {
2863 Roo.lib.Region.prototype = {
2864 contains : function(region) {
2865 return ( region.left >= this.left &&
2866 region.right <= this.right &&
2867 region.top >= this.top &&
2868 region.bottom <= this.bottom );
2872 getArea : function() {
2873 return ( (this.bottom - this.top) * (this.right - this.left) );
2876 intersect : function(region) {
2877 var t = Math.max(this.top, region.top);
2878 var r = Math.min(this.right, region.right);
2879 var b = Math.min(this.bottom, region.bottom);
2880 var l = Math.max(this.left, region.left);
2882 if (b >= t && r >= l) {
2883 return new Roo.lib.Region(t, r, b, l);
2888 union : function(region) {
2889 var t = Math.min(this.top, region.top);
2890 var r = Math.max(this.right, region.right);
2891 var b = Math.max(this.bottom, region.bottom);
2892 var l = Math.min(this.left, region.left);
2894 return new Roo.lib.Region(t, r, b, l);
2897 adjust : function(t, l, b, r) {
2906 Roo.lib.Region.getRegion = function(el) {
2907 var p = Roo.lib.Dom.getXY(el);
2910 var r = p[0] + el.offsetWidth;
2911 var b = p[1] + el.offsetHeight;
2914 return new Roo.lib.Region(t, r, b, l);
2917 * Portions of this file are based on pieces of Yahoo User Interface Library
2918 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2919 * YUI licensed under the BSD License:
2920 * http://developer.yahoo.net/yui/license.txt
2921 * <script type="text/javascript">
2924 //@@dep Roo.lib.Region
2927 Roo.lib.Point = function(x, y) {
2928 if (x instanceof Array) {
2932 this.x = this.right = this.left = this[0] = x;
2933 this.y = this.top = this.bottom = this[1] = y;
2936 Roo.lib.Point.prototype = new Roo.lib.Region();
2938 * Portions of this file are based on pieces of Yahoo User Interface Library
2939 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2940 * YUI licensed under the BSD License:
2941 * http://developer.yahoo.net/yui/license.txt
2942 * <script type="text/javascript">
2949 scroll : function(el, args, duration, easing, cb, scope) {
2950 this.run(el, args, duration, easing, cb, scope, Roo.lib.Scroll);
2953 motion : function(el, args, duration, easing, cb, scope) {
2954 this.run(el, args, duration, easing, cb, scope, Roo.lib.Motion);
2957 color : function(el, args, duration, easing, cb, scope) {
2958 this.run(el, args, duration, easing, cb, scope, Roo.lib.ColorAnim);
2961 run : function(el, args, duration, easing, cb, scope, type) {
2962 type = type || Roo.lib.AnimBase;
2963 if (typeof easing == "string") {
2964 easing = Roo.lib.Easing[easing];
2966 var anim = new type(el, args, duration, easing);
2967 anim.animateX(function() {
2968 Roo.callback(cb, scope);
2974 * Portions of this file are based on pieces of Yahoo User Interface Library
2975 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2976 * YUI licensed under the BSD License:
2977 * http://developer.yahoo.net/yui/license.txt
2978 * <script type="text/javascript">
2986 if (!libFlyweight) {
2987 libFlyweight = new Roo.Element.Flyweight();
2989 libFlyweight.dom = el;
2990 return libFlyweight;
2993 // since this uses fly! - it cant be in DOM (which does not have fly yet..)
2997 Roo.lib.AnimBase = function(el, attributes, duration, method) {
2999 this.init(el, attributes, duration, method);
3003 Roo.lib.AnimBase.fly = fly;
3007 Roo.lib.AnimBase.prototype = {
3009 toString: function() {
3010 var el = this.getEl();
3011 var id = el.id || el.tagName;
3012 return ("Anim " + id);
3016 noNegatives: /width|height|opacity|padding/i,
3017 offsetAttribute: /^((width|height)|(top|left))$/,
3018 defaultUnit: /width|height|top$|bottom$|left$|right$/i,
3019 offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i
3023 doMethod: function(attr, start, end) {
3024 return this.method(this.currentFrame, start, end - start, this.totalFrames);
3028 setAttribute: function(attr, val, unit) {
3029 if (this.patterns.noNegatives.test(attr)) {
3030 val = (val > 0) ? val : 0;
3033 Roo.fly(this.getEl(), '_anim').setStyle(attr, val + unit);
3037 getAttribute: function(attr) {
3038 var el = this.getEl();
3039 var val = fly(el).getStyle(attr);
3041 if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) {
3042 return parseFloat(val);
3045 var a = this.patterns.offsetAttribute.exec(attr) || [];
3046 var pos = !!( a[3] );
3047 var box = !!( a[2] );
3050 if (box || (fly(el).getStyle('position') == 'absolute' && pos)) {
3051 val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];
3060 getDefaultUnit: function(attr) {
3061 if (this.patterns.defaultUnit.test(attr)) {
3068 animateX : function(callback, scope) {
3069 var f = function() {
3070 this.onComplete.removeListener(f);
3071 if (typeof callback == "function") {
3072 callback.call(scope || this, this);
3075 this.onComplete.addListener(f, this);
3080 setRuntimeAttribute: function(attr) {
3083 var attributes = this.attributes;
3085 this.runtimeAttributes[attr] = {};
3087 var isset = function(prop) {
3088 return (typeof prop !== 'undefined');
3091 if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) {
3095 start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr);
3098 if (isset(attributes[attr]['to'])) {
3099 end = attributes[attr]['to'];
3100 } else if (isset(attributes[attr]['by'])) {
3101 if (start.constructor == Array) {
3103 for (var i = 0, len = start.length; i < len; ++i) {
3104 end[i] = start[i] + attributes[attr]['by'][i];
3107 end = start + attributes[attr]['by'];
3111 this.runtimeAttributes[attr].start = start;
3112 this.runtimeAttributes[attr].end = end;
3115 this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr);
3119 init: function(el, attributes, duration, method) {
3121 var isAnimated = false;
3124 var startTime = null;
3127 var actualFrames = 0;
3130 el = Roo.getDom(el);
3133 this.attributes = attributes || {};
3136 this.duration = duration || 1;
3139 this.method = method || Roo.lib.Easing.easeNone;
3142 this.useSeconds = true;
3145 this.currentFrame = 0;
3148 this.totalFrames = Roo.lib.AnimMgr.fps;
3151 this.getEl = function() {
3156 this.isAnimated = function() {
3161 this.getStartTime = function() {
3165 this.runtimeAttributes = {};
3168 this.animate = function() {
3169 if (this.isAnimated()) {
3173 this.currentFrame = 0;
3175 this.totalFrames = ( this.useSeconds ) ? Math.ceil(Roo.lib.AnimMgr.fps * this.duration) : this.duration;
3177 Roo.lib.AnimMgr.registerElement(this);
3181 this.stop = function(finish) {
3183 this.currentFrame = this.totalFrames;
3184 this._onTween.fire();
3186 Roo.lib.AnimMgr.stop(this);
3189 var onStart = function() {
3190 this.onStart.fire();
3192 this.runtimeAttributes = {};
3193 for (var attr in this.attributes) {
3194 this.setRuntimeAttribute(attr);
3199 startTime = new Date();
3203 var onTween = function() {
3205 duration: new Date() - this.getStartTime(),
3206 currentFrame: this.currentFrame
3209 data.toString = function() {
3211 'duration: ' + data.duration +
3212 ', currentFrame: ' + data.currentFrame
3216 this.onTween.fire(data);
3218 var runtimeAttributes = this.runtimeAttributes;
3220 for (var attr in runtimeAttributes) {
3221 this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit);
3227 var onComplete = function() {
3228 var actual_duration = (new Date() - startTime) / 1000 ;
3231 duration: actual_duration,
3232 frames: actualFrames,
3233 fps: actualFrames / actual_duration
3236 data.toString = function() {
3238 'duration: ' + data.duration +
3239 ', frames: ' + data.frames +
3240 ', fps: ' + data.fps
3246 this.onComplete.fire(data);
3250 this._onStart = new Roo.util.Event(this);
3251 this.onStart = new Roo.util.Event(this);
3252 this.onTween = new Roo.util.Event(this);
3253 this._onTween = new Roo.util.Event(this);
3254 this.onComplete = new Roo.util.Event(this);
3255 this._onComplete = new Roo.util.Event(this);
3256 this._onStart.addListener(onStart);
3257 this._onTween.addListener(onTween);
3258 this._onComplete.addListener(onComplete);
3263 * Portions of this file are based on pieces of Yahoo User Interface Library
3264 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3265 * YUI licensed under the BSD License:
3266 * http://developer.yahoo.net/yui/license.txt
3267 * <script type="text/javascript">
3271 Roo.lib.AnimMgr = new function() {
3288 this.registerElement = function(tween) {
3289 queue[queue.length] = tween;
3291 tween._onStart.fire();
3296 this.unRegister = function(tween, index) {
3297 tween._onComplete.fire();
3298 index = index || getIndex(tween);
3300 queue.splice(index, 1);
3304 if (tweenCount <= 0) {
3310 this.start = function() {
3311 if (thread === null) {
3312 thread = setInterval(this.run, this.delay);
3317 this.stop = function(tween) {
3319 clearInterval(thread);
3321 for (var i = 0, len = queue.length; i < len; ++i) {
3322 if (queue[0].isAnimated()) {
3323 this.unRegister(queue[0], 0);
3332 this.unRegister(tween);
3337 this.run = function() {
3338 for (var i = 0, len = queue.length; i < len; ++i) {
3339 var tween = queue[i];
3340 if (!tween || !tween.isAnimated()) {
3344 if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)
3346 tween.currentFrame += 1;
3348 if (tween.useSeconds) {
3349 correctFrame(tween);
3351 tween._onTween.fire();
3354 Roo.lib.AnimMgr.stop(tween, i);
3359 var getIndex = function(anim) {
3360 for (var i = 0, len = queue.length; i < len; ++i) {
3361 if (queue[i] == anim) {
3369 var correctFrame = function(tween) {
3370 var frames = tween.totalFrames;
3371 var frame = tween.currentFrame;
3372 var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames);
3373 var elapsed = (new Date() - tween.getStartTime());
3376 if (elapsed < tween.duration * 1000) {
3377 tweak = Math.round((elapsed / expected - 1) * tween.currentFrame);
3379 tweak = frames - (frame + 1);
3381 if (tweak > 0 && isFinite(tweak)) {
3382 if (tween.currentFrame + tweak >= frames) {
3383 tweak = frames - (frame + 1);
3386 tween.currentFrame += tweak;
3390 * Portions of this file are based on pieces of Yahoo User Interface Library
3391 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3392 * YUI licensed under the BSD License:
3393 * http://developer.yahoo.net/yui/license.txt
3394 * <script type="text/javascript">
3397 Roo.lib.Bezier = new function() {
3399 this.getPosition = function(points, t) {
3400 var n = points.length;
3403 for (var i = 0; i < n; ++i) {
3404 tmp[i] = [points[i][0], points[i][1]];
3407 for (var j = 1; j < n; ++j) {
3408 for (i = 0; i < n - j; ++i) {
3409 tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
3410 tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
3414 return [ tmp[0][0], tmp[0][1] ];
3418 * Portions of this file are based on pieces of Yahoo User Interface Library
3419 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3420 * YUI licensed under the BSD License:
3421 * http://developer.yahoo.net/yui/license.txt
3422 * <script type="text/javascript">
3427 Roo.lib.ColorAnim = function(el, attributes, duration, method) {
3428 Roo.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
3431 Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase);
3433 var fly = Roo.lib.AnimBase.fly;
3435 var superclass = Y.ColorAnim.superclass;
3436 var proto = Y.ColorAnim.prototype;
3438 proto.toString = function() {
3439 var el = this.getEl();
3440 var id = el.id || el.tagName;
3441 return ("ColorAnim " + id);
3444 proto.patterns.color = /color$/i;
3445 proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
3446 proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
3447 proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
3448 proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
3451 proto.parseColor = function(s) {
3452 if (s.length == 3) {
3456 var c = this.patterns.hex.exec(s);
3457 if (c && c.length == 4) {
3458 return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
3461 c = this.patterns.rgb.exec(s);
3462 if (c && c.length == 4) {
3463 return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
3466 c = this.patterns.hex3.exec(s);
3467 if (c && c.length == 4) {
3468 return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
3473 // since this uses fly! - it cant be in ColorAnim (which does not have fly yet..)
3474 proto.getAttribute = function(attr) {
3475 var el = this.getEl();
3476 if (this.patterns.color.test(attr)) {
3477 var val = fly(el).getStyle(attr);
3479 if (this.patterns.transparent.test(val)) {
3480 var parent = el.parentNode;
3481 val = fly(parent).getStyle(attr);
3483 while (parent && this.patterns.transparent.test(val)) {
3484 parent = parent.parentNode;
3485 val = fly(parent).getStyle(attr);
3486 if (parent.tagName.toUpperCase() == 'HTML') {
3492 val = superclass.getAttribute.call(this, attr);
3497 proto.getAttribute = function(attr) {
3498 var el = this.getEl();
3499 if (this.patterns.color.test(attr)) {
3500 var val = fly(el).getStyle(attr);
3502 if (this.patterns.transparent.test(val)) {
3503 var parent = el.parentNode;
3504 val = fly(parent).getStyle(attr);
3506 while (parent && this.patterns.transparent.test(val)) {
3507 parent = parent.parentNode;
3508 val = fly(parent).getStyle(attr);
3509 if (parent.tagName.toUpperCase() == 'HTML') {
3515 val = superclass.getAttribute.call(this, attr);
3521 proto.doMethod = function(attr, start, end) {
3524 if (this.patterns.color.test(attr)) {
3526 for (var i = 0, len = start.length; i < len; ++i) {
3527 val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
3530 val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')';
3533 val = superclass.doMethod.call(this, attr, start, end);
3539 proto.setRuntimeAttribute = function(attr) {
3540 superclass.setRuntimeAttribute.call(this, attr);
3542 if (this.patterns.color.test(attr)) {
3543 var attributes = this.attributes;
3544 var start = this.parseColor(this.runtimeAttributes[attr].start);
3545 var end = this.parseColor(this.runtimeAttributes[attr].end);
3547 if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') {
3548 end = this.parseColor(attributes[attr].by);
3550 for (var i = 0, len = start.length; i < len; ++i) {
3551 end[i] = start[i] + end[i];
3555 this.runtimeAttributes[attr].start = start;
3556 this.runtimeAttributes[attr].end = end;
3562 * Portions of this file are based on pieces of Yahoo User Interface Library
3563 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3564 * YUI licensed under the BSD License:
3565 * http://developer.yahoo.net/yui/license.txt
3566 * <script type="text/javascript">
3572 easeNone: function (t, b, c, d) {
3573 return c * t / d + b;
3577 easeIn: function (t, b, c, d) {
3578 return c * (t /= d) * t + b;
3582 easeOut: function (t, b, c, d) {
3583 return -c * (t /= d) * (t - 2) + b;
3587 easeBoth: function (t, b, c, d) {
3588 if ((t /= d / 2) < 1) {
3589 return c / 2 * t * t + b;
3592 return -c / 2 * ((--t) * (t - 2) - 1) + b;
3596 easeInStrong: function (t, b, c, d) {
3597 return c * (t /= d) * t * t * t + b;
3601 easeOutStrong: function (t, b, c, d) {
3602 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
3606 easeBothStrong: function (t, b, c, d) {
3607 if ((t /= d / 2) < 1) {
3608 return c / 2 * t * t * t * t + b;
3611 return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
3616 elasticIn: function (t, b, c, d, a, p) {
3620 if ((t /= d) == 1) {
3627 if (!a || a < Math.abs(c)) {
3632 var s = p / (2 * Math.PI) * Math.asin(c / a);
3635 return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3639 elasticOut: function (t, b, c, d, a, p) {
3643 if ((t /= d) == 1) {
3650 if (!a || a < Math.abs(c)) {
3655 var s = p / (2 * Math.PI) * Math.asin(c / a);
3658 return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
3662 elasticBoth: function (t, b, c, d, a, p) {
3667 if ((t /= d / 2) == 2) {
3675 if (!a || a < Math.abs(c)) {
3680 var s = p / (2 * Math.PI) * Math.asin(c / a);
3684 return -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
3685 Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3687 return a * Math.pow(2, -10 * (t -= 1)) *
3688 Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
3693 backIn: function (t, b, c, d, s) {
3694 if (typeof s == 'undefined') {
3697 return c * (t /= d) * t * ((s + 1) * t - s) + b;
3701 backOut: function (t, b, c, d, s) {
3702 if (typeof s == 'undefined') {
3705 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
3709 backBoth: function (t, b, c, d, s) {
3710 if (typeof s == 'undefined') {
3714 if ((t /= d / 2 ) < 1) {
3715 return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
3717 return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
3721 bounceIn: function (t, b, c, d) {
3722 return c - Roo.lib.Easing.bounceOut(d - t, 0, c, d) + b;
3726 bounceOut: function (t, b, c, d) {
3727 if ((t /= d) < (1 / 2.75)) {
3728 return c * (7.5625 * t * t) + b;
3729 } else if (t < (2 / 2.75)) {
3730 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
3731 } else if (t < (2.5 / 2.75)) {
3732 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
3734 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
3738 bounceBoth: function (t, b, c, d) {
3740 return Roo.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
3742 return Roo.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
3745 * Portions of this file are based on pieces of Yahoo User Interface Library
3746 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3747 * YUI licensed under the BSD License:
3748 * http://developer.yahoo.net/yui/license.txt
3749 * <script type="text/javascript">
3753 Roo.lib.Motion = function(el, attributes, duration, method) {
3755 Roo.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method);
3759 Roo.extend(Roo.lib.Motion, Roo.lib.ColorAnim);
3763 var superclass = Y.Motion.superclass;
3764 var proto = Y.Motion.prototype;
3766 proto.toString = function() {
3767 var el = this.getEl();
3768 var id = el.id || el.tagName;
3769 return ("Motion " + id);
3772 proto.patterns.points = /^points$/i;
3774 proto.setAttribute = function(attr, val, unit) {
3775 if (this.patterns.points.test(attr)) {
3776 unit = unit || 'px';
3777 superclass.setAttribute.call(this, 'left', val[0], unit);
3778 superclass.setAttribute.call(this, 'top', val[1], unit);
3780 superclass.setAttribute.call(this, attr, val, unit);
3784 proto.getAttribute = function(attr) {
3785 if (this.patterns.points.test(attr)) {
3787 superclass.getAttribute.call(this, 'left'),
3788 superclass.getAttribute.call(this, 'top')
3791 val = superclass.getAttribute.call(this, attr);
3797 proto.doMethod = function(attr, start, end) {
3800 if (this.patterns.points.test(attr)) {
3801 var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
3802 val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
3804 val = superclass.doMethod.call(this, attr, start, end);
3809 proto.setRuntimeAttribute = function(attr) {
3810 if (this.patterns.points.test(attr)) {
3811 var el = this.getEl();
3812 var attributes = this.attributes;
3814 var control = attributes['points']['control'] || [];
3818 if (control.length > 0 && !(control[0] instanceof Array)) {
3819 control = [control];
3822 for (i = 0,len = control.length; i < len; ++i) {
3823 tmp[i] = control[i];
3828 Roo.fly(el).position();
3830 if (isset(attributes['points']['from'])) {
3831 Roo.lib.Dom.setXY(el, attributes['points']['from']);
3834 Roo.lib.Dom.setXY(el, Roo.lib.Dom.getXY(el));
3837 start = this.getAttribute('points');
3840 if (isset(attributes['points']['to'])) {
3841 end = translateValues.call(this, attributes['points']['to'], start);
3843 var pageXY = Roo.lib.Dom.getXY(this.getEl());
3844 for (i = 0,len = control.length; i < len; ++i) {
3845 control[i] = translateValues.call(this, control[i], start);
3849 } else if (isset(attributes['points']['by'])) {
3850 end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
3852 for (i = 0,len = control.length; i < len; ++i) {
3853 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
3857 this.runtimeAttributes[attr] = [start];
3859 if (control.length > 0) {
3860 this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
3863 this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
3866 superclass.setRuntimeAttribute.call(this, attr);
3870 var translateValues = function(val, start) {
3871 var pageXY = Roo.lib.Dom.getXY(this.getEl());
3872 val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
3877 var isset = function(prop) {
3878 return (typeof prop !== 'undefined');
3882 * Portions of this file are based on pieces of Yahoo User Interface Library
3883 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3884 * YUI licensed under the BSD License:
3885 * http://developer.yahoo.net/yui/license.txt
3886 * <script type="text/javascript">
3890 Roo.lib.Scroll = function(el, attributes, duration, method) {
3892 Roo.lib.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
3896 Roo.extend(Roo.lib.Scroll, Roo.lib.ColorAnim);
3900 var superclass = Y.Scroll.superclass;
3901 var proto = Y.Scroll.prototype;
3903 proto.toString = function() {
3904 var el = this.getEl();
3905 var id = el.id || el.tagName;
3906 return ("Scroll " + id);
3909 proto.doMethod = function(attr, start, end) {
3912 if (attr == 'scroll') {
3914 this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames),
3915 this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames)
3919 val = superclass.doMethod.call(this, attr, start, end);
3924 proto.getAttribute = function(attr) {
3926 var el = this.getEl();
3928 if (attr == 'scroll') {
3929 val = [ el.scrollLeft, el.scrollTop ];
3931 val = superclass.getAttribute.call(this, attr);
3937 proto.setAttribute = function(attr, val, unit) {
3938 var el = this.getEl();
3940 if (attr == 'scroll') {
3941 el.scrollLeft = val[0];
3942 el.scrollTop = val[1];
3944 superclass.setAttribute.call(this, attr, val, unit);
3950 * Ext JS Library 1.1.1
3951 * Copyright(c) 2006-2007, Ext JS, LLC.
3953 * Originally Released Under LGPL - original licence link has changed is not relivant.
3956 * <script type="text/javascript">
3961 * @class Roo.DomHelper
3962 * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.
3963 * For more information see <a href="http://www.jackslocum.com/yui/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">this blog post with examples</a>.
3966 Roo.DomHelper = function(){
3967 var tempTableEl = null;
3968 var emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i;
3969 var tableRe = /^table|tbody|tr|td$/i;
3971 // build as innerHTML where available
3973 var createHtml = function(o){
3974 if(typeof o == 'string'){
3983 if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") continue;
3984 if(attr == "style"){
3986 if(typeof s == "function"){
3989 if(typeof s == "string"){
3990 b += ' style="' + s + '"';
3991 }else if(typeof s == "object"){
3994 if(typeof s[key] != "function"){
3995 b += key + ":" + s[key] + ";";
4002 b += ' class="' + o["cls"] + '"';
4003 }else if(attr == "htmlFor"){
4004 b += ' for="' + o["htmlFor"] + '"';
4006 b += " " + attr + '="' + o[attr] + '"';
4010 if(emptyTags.test(o.tag)){
4014 var cn = o.children || o.cn;
4016 //http://bugs.kde.org/show_bug.cgi?id=71506
4017 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4018 for(var i = 0, len = cn.length; i < len; i++) {
4019 b += createHtml(cn[i], b);
4022 b += createHtml(cn, b);
4028 b += "</" + o.tag + ">";
4035 var createDom = function(o, parentNode){
4037 // defininition craeted..
4039 if (o.ns && o.ns != 'html') {
4041 if (o.xmlns && typeof(xmlns[o.ns]) == 'undefined') {
4042 xmlns[o.ns] = o.xmlns;
4045 if (typeof(xmlns[o.ns]) == 'undefined') {
4046 console.log("Trying to create namespace element " + o.ns + ", however no xmlns was sent to builder previously");
4052 if (typeof(o) == 'string') {
4053 return parentNode.appendChild(document.createTextNode(o));
4055 o.tag = o.tag || div;
4056 if (o.ns && Roo.isIE) {
4058 o.tag = o.ns + ':' + o.tag;
4061 var el = ns ? document.createElementNS( ns, o.tag||'div') : document.createElement(o.tag||'div');
4062 var useSet = el.setAttribute ? true : false; // In IE some elements don't have setAttribute
4065 if(attr == "tag" || attr == "ns" ||attr == "xmlns" ||attr == "children" || attr == "cn" || attr == "html" ||
4066 attr == "style" || typeof o[attr] == "function") continue;
4068 if(attr=="cls" && Roo.isIE){
4069 el.className = o["cls"];
4071 if(useSet) el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]);
4072 else el[attr] = o[attr];
4075 Roo.DomHelper.applyStyles(el, o.style);
4076 var cn = o.children || o.cn;
4078 //http://bugs.kde.org/show_bug.cgi?id=71506
4079 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4080 for(var i = 0, len = cn.length; i < len; i++) {
4081 createDom(cn[i], el);
4088 el.innerHTML = o.html;
4091 parentNode.appendChild(el);
4096 var ieTable = function(depth, s, h, e){
4097 tempTableEl.innerHTML = [s, h, e].join('');
4098 var i = -1, el = tempTableEl;
4105 // kill repeat to save bytes
4109 tbe = '</tbody>'+te,
4115 * Nasty code for IE's broken table implementation
4117 var insertIntoTable = function(tag, where, el, html){
4119 tempTableEl = document.createElement('div');
4124 if(where == 'afterbegin' || where == 'beforeend'){ // INTO a TD
4127 if(where == 'beforebegin'){
4131 before = el.nextSibling;
4134 node = ieTable(4, trs, html, tre);
4136 else if(tag == 'tr'){
4137 if(where == 'beforebegin'){
4140 node = ieTable(3, tbs, html, tbe);
4141 } else if(where == 'afterend'){
4142 before = el.nextSibling;
4144 node = ieTable(3, tbs, html, tbe);
4145 } else{ // INTO a TR
4146 if(where == 'afterbegin'){
4147 before = el.firstChild;
4149 node = ieTable(4, trs, html, tre);
4151 } else if(tag == 'tbody'){
4152 if(where == 'beforebegin'){
4155 node = ieTable(2, ts, html, te);
4156 } else if(where == 'afterend'){
4157 before = el.nextSibling;
4159 node = ieTable(2, ts, html, te);
4161 if(where == 'afterbegin'){
4162 before = el.firstChild;
4164 node = ieTable(3, tbs, html, tbe);
4167 if(where == 'beforebegin' || where == 'afterend'){ // OUTSIDE the table
4170 if(where == 'afterbegin'){
4171 before = el.firstChild;
4173 node = ieTable(2, ts, html, te);
4175 el.insertBefore(node, before);
4180 /** True to force the use of DOM instead of html fragments @type Boolean */
4184 * Returns the markup for the passed Element(s) config
4185 * @param {Object} o The Dom object spec (and children)
4188 markup : function(o){
4189 return createHtml(o);
4193 * Applies a style specification to an element
4194 * @param {String/HTMLElement} el The element to apply styles to
4195 * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or
4196 * a function which returns such a specification.
4198 applyStyles : function(el, styles){
4201 if(typeof styles == "string"){
4202 var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;
4204 while ((matches = re.exec(styles)) != null){
4205 el.setStyle(matches[1], matches[2]);
4207 }else if (typeof styles == "object"){
4208 for (var style in styles){
4209 el.setStyle(style, styles[style]);
4211 }else if (typeof styles == "function"){
4212 Roo.DomHelper.applyStyles(el, styles.call());
4218 * Inserts an HTML fragment into the Dom
4219 * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
4220 * @param {HTMLElement} el The context element
4221 * @param {String} html The HTML fragmenet
4222 * @return {HTMLElement} The new node
4224 insertHtml : function(where, el, html){
4225 where = where.toLowerCase();
4226 if(el.insertAdjacentHTML){
4227 if(tableRe.test(el.tagName)){
4229 if(rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html)){
4235 el.insertAdjacentHTML('BeforeBegin', html);
4236 return el.previousSibling;
4238 el.insertAdjacentHTML('AfterBegin', html);
4239 return el.firstChild;
4241 el.insertAdjacentHTML('BeforeEnd', html);
4242 return el.lastChild;
4244 el.insertAdjacentHTML('AfterEnd', html);
4245 return el.nextSibling;
4247 throw 'Illegal insertion point -> "' + where + '"';
4249 var range = el.ownerDocument.createRange();
4253 range.setStartBefore(el);
4254 frag = range.createContextualFragment(html);
4255 el.parentNode.insertBefore(frag, el);
4256 return el.previousSibling;
4259 range.setStartBefore(el.firstChild);
4260 frag = range.createContextualFragment(html);
4261 el.insertBefore(frag, el.firstChild);
4262 return el.firstChild;
4264 el.innerHTML = html;
4265 return el.firstChild;
4269 range.setStartAfter(el.lastChild);
4270 frag = range.createContextualFragment(html);
4271 el.appendChild(frag);
4272 return el.lastChild;
4274 el.innerHTML = html;
4275 return el.lastChild;
4278 range.setStartAfter(el);
4279 frag = range.createContextualFragment(html);
4280 el.parentNode.insertBefore(frag, el.nextSibling);
4281 return el.nextSibling;
4283 throw 'Illegal insertion point -> "' + where + '"';
4287 * Creates new Dom element(s) and inserts them before el
4288 * @param {String/HTMLElement/Element} el The context element
4289 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4290 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4291 * @return {HTMLElement/Roo.Element} The new node
4293 insertBefore : function(el, o, returnElement){
4294 return this.doInsert(el, o, returnElement, "beforeBegin");
4298 * Creates new Dom element(s) and inserts them after el
4299 * @param {String/HTMLElement/Element} el The context element
4300 * @param {Object} o The Dom object spec (and children)
4301 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4302 * @return {HTMLElement/Roo.Element} The new node
4304 insertAfter : function(el, o, returnElement){
4305 return this.doInsert(el, o, returnElement, "afterEnd", "nextSibling");
4309 * Creates new Dom element(s) and inserts them as the first child of el
4310 * @param {String/HTMLElement/Element} el The context element
4311 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4312 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4313 * @return {HTMLElement/Roo.Element} The new node
4315 insertFirst : function(el, o, returnElement){
4316 return this.doInsert(el, o, returnElement, "afterBegin");
4320 doInsert : function(el, o, returnElement, pos, sibling){
4321 el = Roo.getDom(el);
4323 if(this.useDom || o.ns){
4324 newNode = createDom(o, null);
4325 el.parentNode.insertBefore(newNode, sibling ? el[sibling] : el);
4327 var html = createHtml(o);
4328 newNode = this.insertHtml(pos, el, html);
4330 return returnElement ? Roo.get(newNode, true) : newNode;
4334 * Creates new Dom element(s) and appends them to el
4335 * @param {String/HTMLElement/Element} el The context element
4336 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4337 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4338 * @return {HTMLElement/Roo.Element} The new node
4340 append : function(el, o, returnElement){
4341 el = Roo.getDom(el);
4343 if(this.useDom || o.ns){
4344 newNode = createDom(o, null);
4345 el.appendChild(newNode);
4347 var html = createHtml(o);
4348 newNode = this.insertHtml("beforeEnd", el, html);
4350 return returnElement ? Roo.get(newNode, true) : newNode;
4354 * Creates new Dom element(s) and overwrites the contents of el with them
4355 * @param {String/HTMLElement/Element} el The context element
4356 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4357 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4358 * @return {HTMLElement/Roo.Element} The new node
4360 overwrite : function(el, o, returnElement){
4361 el = Roo.getDom(el);
4364 while (el.childNodes.length) {
4365 el.removeChild(el.firstChild);
4369 el.innerHTML = createHtml(o);
4372 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4376 * Creates a new Roo.DomHelper.Template from the Dom object spec
4377 * @param {Object} o The Dom object spec (and children)
4378 * @return {Roo.DomHelper.Template} The new template
4380 createTemplate : function(o){
4381 var html = createHtml(o);
4382 return new Roo.Template(html);
4388 * Ext JS Library 1.1.1
4389 * Copyright(c) 2006-2007, Ext JS, LLC.
4391 * Originally Released Under LGPL - original licence link has changed is not relivant.
4394 * <script type="text/javascript">
4398 * @class Roo.Template
4399 * Represents an HTML fragment template. Templates can be precompiled for greater performance.
4400 * For a list of available format functions, see {@link Roo.util.Format}.<br />
4403 var t = new Roo.Template({
4404 html : '<div name="{id}">' +
4405 '<span class="{cls}">{name:trim} {someval:this.myformat}{value:ellipsis(10)}</span>' +
4407 myformat: function (value, allValues) {
4408 return 'XX' + value;
4411 t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
4413 * For more information see this blog post with examples: <a href="http://www.jackslocum.com/yui/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">DomHelper - Create Elements using DOM, HTML fragments and Templates</a>.
4415 * @param {Object} cfg - Configuration object.
4417 Roo.Template = function(cfg){
4419 if(cfg instanceof Array){
4421 }else if(arguments.length > 1){
4422 cfg = Array.prototype.join.call(arguments, "");
4426 if (typeof(cfg) == 'object') {
4435 Roo.Template.prototype = {
4438 * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")
4442 * Returns an HTML fragment of this template with the specified values applied.
4443 * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
4444 * @return {String} The HTML fragment
4446 applyTemplate : function(values){
4450 return this.compiled(values);
4452 var useF = this.disableFormats !== true;
4453 var fm = Roo.util.Format, tpl = this;
4454 var fn = function(m, name, format, args){
4456 if(format.substr(0, 5) == "this."){
4457 return tpl.call(format.substr(5), values[name], values);
4460 // quoted values are required for strings in compiled templates,
4461 // but for non compiled we need to strip them
4462 // quoted reversed for jsmin
4463 var re = /^\s*['"](.*)["']\s*$/;
4464 args = args.split(',');
4465 for(var i = 0, len = args.length; i < len; i++){
4466 args[i] = args[i].replace(re, "$1");
4468 args = [values[name]].concat(args);
4470 args = [values[name]];
4472 return fm[format].apply(fm, args);
4475 return values[name] !== undefined ? values[name] : "";
4478 return this.html.replace(this.re, fn);
4487 * Sets the HTML used as the template and optionally compiles it.
4488 * @param {String} html
4489 * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
4490 * @return {Roo.Template} this
4492 set : function(html, compile){
4494 this.compiled = null;
4502 * True to disable format functions (defaults to false)
4505 disableFormats : false,
4508 * The regular expression used to match template variables
4512 re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
4515 * Compiles the template into an internal function, eliminating the RegEx overhead.
4516 * @return {Roo.Template} this
4518 compile : function(){
4519 var fm = Roo.util.Format;
4520 var useF = this.disableFormats !== true;
4521 var sep = Roo.isGecko ? "+" : ",";
4522 var fn = function(m, name, format, args){
4524 args = args ? ',' + args : "";
4525 if(format.substr(0, 5) != "this."){
4526 format = "fm." + format + '(';
4528 format = 'this.call("'+ format.substr(5) + '", ';
4532 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
4534 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
4537 // branched to use + in gecko and [].join() in others
4539 body = "this.compiled = function(values){ return '" +
4540 this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
4543 body = ["this.compiled = function(values){ return ['"];
4544 body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
4545 body.push("'].join('');};");
4546 body = body.join('');
4556 // private function used to call members
4557 call : function(fnName, value, allValues){
4558 return this[fnName](value, allValues);
4562 * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
4563 * @param {String/HTMLElement/Roo.Element} el The context element
4564 * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
4565 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4566 * @return {HTMLElement/Roo.Element} The new node or Element
4568 insertFirst: function(el, values, returnElement){
4569 return this.doInsert('afterBegin', el, values, returnElement);
4573 * Applies the supplied values to the template and inserts the new node(s) before el.
4574 * @param {String/HTMLElement/Roo.Element} el The context element
4575 * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
4576 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4577 * @return {HTMLElement/Roo.Element} The new node or Element
4579 insertBefore: function(el, values, returnElement){
4580 return this.doInsert('beforeBegin', el, values, returnElement);
4584 * Applies the supplied values to the template and inserts the new node(s) after el.
4585 * @param {String/HTMLElement/Roo.Element} el The context element
4586 * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
4587 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4588 * @return {HTMLElement/Roo.Element} The new node or Element
4590 insertAfter : function(el, values, returnElement){
4591 return this.doInsert('afterEnd', el, values, returnElement);
4595 * Applies the supplied values to the template and appends the new node(s) to el.
4596 * @param {String/HTMLElement/Roo.Element} el The context element
4597 * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
4598 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4599 * @return {HTMLElement/Roo.Element} The new node or Element
4601 append : function(el, values, returnElement){
4602 return this.doInsert('beforeEnd', el, values, returnElement);
4605 doInsert : function(where, el, values, returnEl){
4606 el = Roo.getDom(el);
4607 var newNode = Roo.DomHelper.insertHtml(where, el, this.applyTemplate(values));
4608 return returnEl ? Roo.get(newNode, true) : newNode;
4612 * Applies the supplied values to the template and overwrites the content of el with the new node(s).
4613 * @param {String/HTMLElement/Roo.Element} el The context element
4614 * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
4615 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4616 * @return {HTMLElement/Roo.Element} The new node or Element
4618 overwrite : function(el, values, returnElement){
4619 el = Roo.getDom(el);
4620 el.innerHTML = this.applyTemplate(values);
4621 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4625 * Alias for {@link #applyTemplate}
4628 Roo.Template.prototype.apply = Roo.Template.prototype.applyTemplate;
4631 Roo.DomHelper.Template = Roo.Template;
4634 * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
4635 * @param {String/HTMLElement} el A DOM element or its id
4636 * @returns {Roo.Template} The created template
4639 Roo.Template.from = function(el){
4640 el = Roo.getDom(el);
4641 return new Roo.Template(el.value || el.innerHTML);
4644 * Ext JS Library 1.1.1
4645 * Copyright(c) 2006-2007, Ext JS, LLC.
4647 * Originally Released Under LGPL - original licence link has changed is not relivant.
4650 * <script type="text/javascript">
4655 * This is code is also distributed under MIT license for use
4656 * with jQuery and prototype JavaScript libraries.
4659 * @class Roo.DomQuery
4660 Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
4662 DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p>
4665 All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
4667 <h4>Element Selectors:</h4>
4669 <li> <b>*</b> any element</li>
4670 <li> <b>E</b> an element with the tag E</li>
4671 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
4672 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
4673 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
4674 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
4676 <h4>Attribute Selectors:</h4>
4677 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
4679 <li> <b>E[foo]</b> has an attribute "foo"</li>
4680 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
4681 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
4682 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
4683 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
4684 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
4685 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
4687 <h4>Pseudo Classes:</h4>
4689 <li> <b>E:first-child</b> E is the first child of its parent</li>
4690 <li> <b>E:last-child</b> E is the last child of its parent</li>
4691 <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li>
4692 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
4693 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
4694 <li> <b>E:only-child</b> E is the only child of its parent</li>
4695 <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li>
4696 <li> <b>E:first</b> the first E in the resultset</li>
4697 <li> <b>E:last</b> the last E in the resultset</li>
4698 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
4699 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
4700 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
4701 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
4702 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
4703 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
4704 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
4705 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
4706 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
4708 <h4>CSS Value Selectors:</h4>
4710 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
4711 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
4712 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
4713 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
4714 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
4715 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
4719 Roo.DomQuery = function(){
4720 var cache = {}, simpleCache = {}, valueCache = {};
4721 var nonSpace = /\S/;
4722 var trimRe = /^\s+|\s+$/g;
4723 var tplRe = /\{(\d+)\}/g;
4724 var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
4725 var tagTokenRe = /^(#)?([\w-\*]+)/;
4726 var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/;
4728 function child(p, index){
4730 var n = p.firstChild;
4732 if(n.nodeType == 1){
4743 while((n = n.nextSibling) && n.nodeType != 1);
4748 while((n = n.previousSibling) && n.nodeType != 1);
4752 function children(d){
4753 var n = d.firstChild, ni = -1;
4755 var nx = n.nextSibling;
4756 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
4766 function byClassName(c, a, v){
4770 var r = [], ri = -1, cn;
4771 for(var i = 0, ci; ci = c[i]; i++){
4772 if((' '+ci.className+' ').indexOf(v) != -1){
4779 function attrValue(n, attr){
4780 if(!n.tagName && typeof n.length != "undefined"){
4789 if(attr == "class" || attr == "className"){
4792 return n.getAttribute(attr) || n[attr];
4796 function getNodes(ns, mode, tagName){
4797 var result = [], ri = -1, cs;
4801 tagName = tagName || "*";
4802 if(typeof ns.getElementsByTagName != "undefined"){
4806 for(var i = 0, ni; ni = ns[i]; i++){
4807 cs = ni.getElementsByTagName(tagName);
4808 for(var j = 0, ci; ci = cs[j]; j++){
4812 }else if(mode == "/" || mode == ">"){
4813 var utag = tagName.toUpperCase();
4814 for(var i = 0, ni, cn; ni = ns[i]; i++){
4815 cn = ni.children || ni.childNodes;
4816 for(var j = 0, cj; cj = cn[j]; j++){
4817 if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
4822 }else if(mode == "+"){
4823 var utag = tagName.toUpperCase();
4824 for(var i = 0, n; n = ns[i]; i++){
4825 while((n = n.nextSibling) && n.nodeType != 1);
4826 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
4830 }else if(mode == "~"){
4831 for(var i = 0, n; n = ns[i]; i++){
4832 while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName)));
4841 function concat(a, b){
4845 for(var i = 0, l = b.length; i < l; i++){
4851 function byTag(cs, tagName){
4852 if(cs.tagName || cs == document){
4858 var r = [], ri = -1;
4859 tagName = tagName.toLowerCase();
4860 for(var i = 0, ci; ci = cs[i]; i++){
4861 if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
4868 function byId(cs, attr, id){
4869 if(cs.tagName || cs == document){
4875 var r = [], ri = -1;
4876 for(var i = 0,ci; ci = cs[i]; i++){
4877 if(ci && ci.id == id){
4885 function byAttribute(cs, attr, value, op, custom){
4886 var r = [], ri = -1, st = custom=="{";
4887 var f = Roo.DomQuery.operators[op];
4888 for(var i = 0, ci; ci = cs[i]; i++){
4891 a = Roo.DomQuery.getStyle(ci, attr);
4893 else if(attr == "class" || attr == "className"){
4895 }else if(attr == "for"){
4897 }else if(attr == "href"){
4898 a = ci.getAttribute("href", 2);
4900 a = ci.getAttribute(attr);
4902 if((f && f(a, value)) || (!f && a)){
4909 function byPseudo(cs, name, value){
4910 return Roo.DomQuery.pseudos[name](cs, value);
4913 // This is for IE MSXML which does not support expandos.
4914 // IE runs the same speed using setAttribute, however FF slows way down
4915 // and Safari completely fails so they need to continue to use expandos.
4916 var isIE = window.ActiveXObject ? true : false;
4918 // this eval is stop the compressor from
4919 // renaming the variable to something shorter
4921 /** eval:var:batch */
4926 function nodupIEXml(cs){
4928 cs[0].setAttribute("_nodup", d);
4930 for(var i = 1, len = cs.length; i < len; i++){
4932 if(!c.getAttribute("_nodup") != d){
4933 c.setAttribute("_nodup", d);
4937 for(var i = 0, len = cs.length; i < len; i++){
4938 cs[i].removeAttribute("_nodup");
4947 var len = cs.length, c, i, r = cs, cj, ri = -1;
4948 if(!len || typeof cs.nodeType != "undefined" || len == 1){
4951 if(isIE && typeof cs[0].selectSingleNode != "undefined"){
4952 return nodupIEXml(cs);
4956 for(i = 1; c = cs[i]; i++){
4961 for(var j = 0; j < i; j++){
4964 for(j = i+1; cj = cs[j]; j++){
4976 function quickDiffIEXml(c1, c2){
4978 for(var i = 0, len = c1.length; i < len; i++){
4979 c1[i].setAttribute("_qdiff", d);
4982 for(var i = 0, len = c2.length; i < len; i++){
4983 if(c2[i].getAttribute("_qdiff") != d){
4984 r[r.length] = c2[i];
4987 for(var i = 0, len = c1.length; i < len; i++){
4988 c1[i].removeAttribute("_qdiff");
4993 function quickDiff(c1, c2){
4994 var len1 = c1.length;
4998 if(isIE && c1[0].selectSingleNode){
4999 return quickDiffIEXml(c1, c2);
5002 for(var i = 0; i < len1; i++){
5006 for(var i = 0, len = c2.length; i < len; i++){
5007 if(c2[i]._qdiff != d){
5008 r[r.length] = c2[i];
5014 function quickId(ns, mode, root, id){
5016 var d = root.ownerDocument || root;
5017 return d.getElementById(id);
5019 ns = getNodes(ns, mode, "*");
5020 return byId(ns, null, id);
5024 getStyle : function(el, name){
5025 return Roo.fly(el).getStyle(name);
5028 * Compiles a selector/xpath query into a reusable function. The returned function
5029 * takes one parameter "root" (optional), which is the context node from where the query should start.
5030 * @param {String} selector The selector/xpath query
5031 * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
5032 * @return {Function}
5034 compile : function(path, type){
5035 type = type || "select";
5037 var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"];
5038 var q = path, mode, lq;
5039 var tk = Roo.DomQuery.matchers;
5040 var tklen = tk.length;
5043 // accept leading mode switch
5044 var lmode = q.match(modeRe);
5045 if(lmode && lmode[1]){
5046 fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
5047 q = q.replace(lmode[1], "");
5049 // strip leading slashes
5050 while(path.substr(0, 1)=="/"){
5051 path = path.substr(1);
5054 while(q && lq != q){
5056 var tm = q.match(tagTokenRe);
5057 if(type == "select"){
5060 fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';
5062 fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';
5064 q = q.replace(tm[0], "");
5065 }else if(q.substr(0, 1) != '@'){
5066 fn[fn.length] = 'n = getNodes(n, mode, "*");';
5071 fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';
5073 fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';
5075 q = q.replace(tm[0], "");
5078 while(!(mm = q.match(modeRe))){
5079 var matched = false;
5080 for(var j = 0; j < tklen; j++){
5082 var m = q.match(t.re);
5084 fn[fn.length] = t.select.replace(tplRe, function(x, i){
5087 q = q.replace(m[0], "");
5092 // prevent infinite loop on bad selector
5094 throw 'Error parsing selector, parsing failed at "' + q + '"';
5098 fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";';
5099 q = q.replace(mm[1], "");
5102 fn[fn.length] = "return nodup(n);\n}";
5105 * list of variables that need from compression as they are used by eval.
5115 * eval:var:byClassName
5117 * eval:var:byAttribute
5118 * eval:var:attrValue
5126 * Selects a group of elements.
5127 * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
5128 * @param {Node} root (optional) The start of the query (defaults to document).
5131 select : function(path, root, type){
5132 if(!root || root == document){
5135 if(typeof root == "string"){
5136 root = document.getElementById(root);
5138 var paths = path.split(",");
5140 for(var i = 0, len = paths.length; i < len; i++){
5141 var p = paths[i].replace(trimRe, "");
5143 cache[p] = Roo.DomQuery.compile(p);
5145 throw p + " is not a valid selector";
5148 var result = cache[p](root);
5149 if(result && result != document){
5150 results = results.concat(result);
5153 if(paths.length > 1){
5154 return nodup(results);
5160 * Selects a single element.
5161 * @param {String} selector The selector/xpath query
5162 * @param {Node} root (optional) The start of the query (defaults to document).
5165 selectNode : function(path, root){
5166 return Roo.DomQuery.select(path, root)[0];
5170 * Selects the value of a node, optionally replacing null with the defaultValue.
5171 * @param {String} selector The selector/xpath query
5172 * @param {Node} root (optional) The start of the query (defaults to document).
5173 * @param {String} defaultValue
5175 selectValue : function(path, root, defaultValue){
5176 path = path.replace(trimRe, "");
5177 if(!valueCache[path]){
5178 valueCache[path] = Roo.DomQuery.compile(path, "select");
5180 var n = valueCache[path](root);
5181 n = n[0] ? n[0] : n;
5182 var v = (n && n.firstChild ? n.firstChild.nodeValue : null);
5183 return ((v === null||v === undefined||v==='') ? defaultValue : v);
5187 * Selects the value of a node, parsing integers and floats.
5188 * @param {String} selector The selector/xpath query
5189 * @param {Node} root (optional) The start of the query (defaults to document).
5190 * @param {Number} defaultValue
5193 selectNumber : function(path, root, defaultValue){
5194 var v = Roo.DomQuery.selectValue(path, root, defaultValue || 0);
5195 return parseFloat(v);
5199 * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
5200 * @param {String/HTMLElement/Array} el An element id, element or array of elements
5201 * @param {String} selector The simple selector to test
5204 is : function(el, ss){
5205 if(typeof el == "string"){
5206 el = document.getElementById(el);
5208 var isArray = (el instanceof Array);
5209 var result = Roo.DomQuery.filter(isArray ? el : [el], ss);
5210 return isArray ? (result.length == el.length) : (result.length > 0);
5214 * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
5215 * @param {Array} el An array of elements to filter
5216 * @param {String} selector The simple selector to test
5217 * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
5218 * the selector instead of the ones that match
5221 filter : function(els, ss, nonMatches){
5222 ss = ss.replace(trimRe, "");
5223 if(!simpleCache[ss]){
5224 simpleCache[ss] = Roo.DomQuery.compile(ss, "simple");
5226 var result = simpleCache[ss](els);
5227 return nonMatches ? quickDiff(result, els) : result;
5231 * Collection of matching regular expressions and code snippets.
5235 select: 'n = byClassName(n, null, " {1} ");'
5237 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
5238 select: 'n = byPseudo(n, "{1}", "{2}");'
5240 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
5241 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
5244 select: 'n = byId(n, null, "{1}");'
5247 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
5252 * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
5253 * New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, > <.
5256 "=" : function(a, v){
5259 "!=" : function(a, v){
5262 "^=" : function(a, v){
5263 return a && a.substr(0, v.length) == v;
5265 "$=" : function(a, v){
5266 return a && a.substr(a.length-v.length) == v;
5268 "*=" : function(a, v){
5269 return a && a.indexOf(v) !== -1;
5271 "%=" : function(a, v){
5272 return (a % v) == 0;
5274 "|=" : function(a, v){
5275 return a && (a == v || a.substr(0, v.length+1) == v+'-');
5277 "~=" : function(a, v){
5278 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
5283 * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
5284 * and the argument (if any) supplied in the selector.
5287 "first-child" : function(c){
5288 var r = [], ri = -1, n;
5289 for(var i = 0, ci; ci = n = c[i]; i++){
5290 while((n = n.previousSibling) && n.nodeType != 1);
5298 "last-child" : function(c){
5299 var r = [], ri = -1, n;
5300 for(var i = 0, ci; ci = n = c[i]; i++){
5301 while((n = n.nextSibling) && n.nodeType != 1);
5309 "nth-child" : function(c, a) {
5310 var r = [], ri = -1;
5311 var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a);
5312 var f = (m[1] || 1) - 0, l = m[2] - 0;
5313 for(var i = 0, n; n = c[i]; i++){
5314 var pn = n.parentNode;
5315 if (batch != pn._batch) {
5317 for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
5318 if(cn.nodeType == 1){
5325 if (l == 0 || n.nodeIndex == l){
5328 } else if ((n.nodeIndex + l) % f == 0){
5336 "only-child" : function(c){
5337 var r = [], ri = -1;;
5338 for(var i = 0, ci; ci = c[i]; i++){
5339 if(!prev(ci) && !next(ci)){
5346 "empty" : function(c){
5347 var r = [], ri = -1;
5348 for(var i = 0, ci; ci = c[i]; i++){
5349 var cns = ci.childNodes, j = 0, cn, empty = true;
5352 if(cn.nodeType == 1 || cn.nodeType == 3){
5364 "contains" : function(c, v){
5365 var r = [], ri = -1;
5366 for(var i = 0, ci; ci = c[i]; i++){
5367 if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
5374 "nodeValue" : function(c, v){
5375 var r = [], ri = -1;
5376 for(var i = 0, ci; ci = c[i]; i++){
5377 if(ci.firstChild && ci.firstChild.nodeValue == v){
5384 "checked" : function(c){
5385 var r = [], ri = -1;
5386 for(var i = 0, ci; ci = c[i]; i++){
5387 if(ci.checked == true){
5394 "not" : function(c, ss){
5395 return Roo.DomQuery.filter(c, ss, true);
5398 "odd" : function(c){
5399 return this["nth-child"](c, "odd");
5402 "even" : function(c){
5403 return this["nth-child"](c, "even");
5406 "nth" : function(c, a){
5407 return c[a-1] || [];
5410 "first" : function(c){
5414 "last" : function(c){
5415 return c[c.length-1] || [];
5418 "has" : function(c, ss){
5419 var s = Roo.DomQuery.select;
5420 var r = [], ri = -1;
5421 for(var i = 0, ci; ci = c[i]; i++){
5422 if(s(ss, ci).length > 0){
5429 "next" : function(c, ss){
5430 var is = Roo.DomQuery.is;
5431 var r = [], ri = -1;
5432 for(var i = 0, ci; ci = c[i]; i++){
5441 "prev" : function(c, ss){
5442 var is = Roo.DomQuery.is;
5443 var r = [], ri = -1;
5444 for(var i = 0, ci; ci = c[i]; i++){
5457 * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Roo.DomQuery#select}
5458 * @param {String} path The selector/xpath query
5459 * @param {Node} root (optional) The start of the query (defaults to document).
5464 Roo.query = Roo.DomQuery.select;
5467 * Ext JS Library 1.1.1
5468 * Copyright(c) 2006-2007, Ext JS, LLC.
5470 * Originally Released Under LGPL - original licence link has changed is not relivant.
5473 * <script type="text/javascript">
5477 * @class Roo.util.Observable
5478 * Base class that provides a common interface for publishing events. Subclasses are expected to
5479 * to have a property "events" with all the events defined.<br>
5482 Employee = function(name){
5489 Roo.extend(Employee, Roo.util.Observable);
5491 * @param {Object} config properties to use (incuding events / listeners)
5494 Roo.util.Observable = function(cfg){
5497 this.addEvents(cfg.events || {});
5499 delete cfg.events; // make sure
5502 Roo.apply(this, cfg);
5505 this.on(this.listeners);
5506 delete this.listeners;
5509 Roo.util.Observable.prototype = {
5511 * @cfg {Object} listeners list of events and functions to call for this object,
5515 'click' : function(e) {
5525 * Fires the specified event with the passed parameters (minus the event name).
5526 * @param {String} eventName
5527 * @param {Object...} args Variable number of parameters are passed to handlers
5528 * @return {Boolean} returns false if any of the handlers return false otherwise it returns true
5530 fireEvent : function(){
5531 var ce = this.events[arguments[0].toLowerCase()];
5532 if(typeof ce == "object"){
5533 return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
5540 filterOptRe : /^(?:scope|delay|buffer|single)$/,
5543 * Appends an event handler to this component
5544 * @param {String} eventName The type of event to listen for
5545 * @param {Function} handler The method the event invokes
5546 * @param {Object} scope (optional) The scope in which to execute the handler
5547 * function. The handler function's "this" context.
5548 * @param {Object} options (optional) An object containing handler configuration
5549 * properties. This may contain any of the following properties:<ul>
5550 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
5551 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
5552 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
5553 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
5554 * by the specified number of milliseconds. If the event fires again within that time, the original
5555 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
5558 * <b>Combining Options</b><br>
5559 * Using the options argument, it is possible to combine different types of listeners:<br>
5561 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
5563 el.on('click', this.onClick, this, {
5570 * <b>Attaching multiple handlers in 1 call</b><br>
5571 * The method also allows for a single argument to be passed which is a config object containing properties
5572 * which specify multiple handlers.
5581 fn: this.onMouseOver,
5585 fn: this.onMouseOut,
5591 * Or a shorthand syntax which passes the same scope object to all handlers:
5594 'click': this.onClick,
5595 'mouseover': this.onMouseOver,
5596 'mouseout': this.onMouseOut,
5601 addListener : function(eventName, fn, scope, o){
5602 if(typeof eventName == "object"){
5605 if(this.filterOptRe.test(e)){
5608 if(typeof o[e] == "function"){
5610 this.addListener(e, o[e], o.scope, o);
5612 // individual options
5613 this.addListener(e, o[e].fn, o[e].scope, o[e]);
5618 o = (!o || typeof o == "boolean") ? {} : o;
5619 eventName = eventName.toLowerCase();
5620 var ce = this.events[eventName] || true;
5621 if(typeof ce == "boolean"){
5622 ce = new Roo.util.Event(this, eventName);
5623 this.events[eventName] = ce;
5625 ce.addListener(fn, scope, o);
5629 * Removes a listener
5630 * @param {String} eventName The type of event to listen for
5631 * @param {Function} handler The handler to remove
5632 * @param {Object} scope (optional) The scope (this object) for the handler
5634 removeListener : function(eventName, fn, scope){
5635 var ce = this.events[eventName.toLowerCase()];
5636 if(typeof ce == "object"){
5637 ce.removeListener(fn, scope);
5642 * Removes all listeners for this object
5644 purgeListeners : function(){
5645 for(var evt in this.events){
5646 if(typeof this.events[evt] == "object"){
5647 this.events[evt].clearListeners();
5652 relayEvents : function(o, events){
5653 var createHandler = function(ename){
5655 return this.fireEvent.apply(this, Roo.combine(ename, Array.prototype.slice.call(arguments, 0)));
5658 for(var i = 0, len = events.length; i < len; i++){
5659 var ename = events[i];
5660 if(!this.events[ename]){ this.events[ename] = true; };
5661 o.on(ename, createHandler(ename), this);
5666 * Used to define events on this Observable
5667 * @param {Object} object The object with the events defined
5669 addEvents : function(o){
5673 Roo.applyIf(this.events, o);
5677 * Checks to see if this object has any listeners for a specified event
5678 * @param {String} eventName The name of the event to check for
5679 * @return {Boolean} True if the event is being listened for, else false
5681 hasListener : function(eventName){
5682 var e = this.events[eventName];
5683 return typeof e == "object" && e.listeners.length > 0;
5687 * Appends an event handler to this element (shorthand for addListener)
5688 * @param {String} eventName The type of event to listen for
5689 * @param {Function} handler The method the event invokes
5690 * @param {Object} scope (optional) The scope in which to execute the handler
5691 * function. The handler function's "this" context.
5692 * @param {Object} options (optional)
5695 Roo.util.Observable.prototype.on = Roo.util.Observable.prototype.addListener;
5697 * Removes a listener (shorthand for removeListener)
5698 * @param {String} eventName The type of event to listen for
5699 * @param {Function} handler The handler to remove
5700 * @param {Object} scope (optional) The scope (this object) for the handler
5703 Roo.util.Observable.prototype.un = Roo.util.Observable.prototype.removeListener;
5706 * Starts capture on the specified Observable. All events will be passed
5707 * to the supplied function with the event name + standard signature of the event
5708 * <b>before</b> the event is fired. If the supplied function returns false,
5709 * the event will not fire.
5710 * @param {Observable} o The Observable to capture
5711 * @param {Function} fn The function to call
5712 * @param {Object} scope (optional) The scope (this object) for the fn
5715 Roo.util.Observable.capture = function(o, fn, scope){
5716 o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
5720 * Removes <b>all</b> added captures from the Observable.
5721 * @param {Observable} o The Observable to release
5724 Roo.util.Observable.releaseCapture = function(o){
5725 o.fireEvent = Roo.util.Observable.prototype.fireEvent;
5730 var createBuffered = function(h, o, scope){
5731 var task = new Roo.util.DelayedTask();
5733 task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0));
5737 var createSingle = function(h, e, fn, scope){
5739 e.removeListener(fn, scope);
5740 return h.apply(scope, arguments);
5744 var createDelayed = function(h, o, scope){
5746 var args = Array.prototype.slice.call(arguments, 0);
5747 setTimeout(function(){
5748 h.apply(scope, args);
5753 Roo.util.Event = function(obj, name){
5756 this.listeners = [];
5759 Roo.util.Event.prototype = {
5760 addListener : function(fn, scope, options){
5761 var o = options || {};
5762 scope = scope || this.obj;
5763 if(!this.isListening(fn, scope)){
5764 var l = {fn: fn, scope: scope, options: o};
5767 h = createDelayed(h, o, scope);
5770 h = createSingle(h, this, fn, scope);
5773 h = createBuffered(h, o, scope);
5776 if(!this.firing){ // if we are currently firing this event, don't disturb the listener loop
5777 this.listeners.push(l);
5779 this.listeners = this.listeners.slice(0);
5780 this.listeners.push(l);
5785 findListener : function(fn, scope){
5786 scope = scope || this.obj;
5787 var ls = this.listeners;
5788 for(var i = 0, len = ls.length; i < len; i++){
5790 if(l.fn == fn && l.scope == scope){
5797 isListening : function(fn, scope){
5798 return this.findListener(fn, scope) != -1;
5801 removeListener : function(fn, scope){
5803 if((index = this.findListener(fn, scope)) != -1){
5805 this.listeners.splice(index, 1);
5807 this.listeners = this.listeners.slice(0);
5808 this.listeners.splice(index, 1);
5815 clearListeners : function(){
5816 this.listeners = [];
5820 var ls = this.listeners, scope, len = ls.length;
5823 var args = Array.prototype.slice.call(arguments, 0);
5824 for(var i = 0; i < len; i++){
5826 if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
5827 this.firing = false;
5831 this.firing = false;
5838 * Ext JS Library 1.1.1
5839 * Copyright(c) 2006-2007, Ext JS, LLC.
5841 * Originally Released Under LGPL - original licence link has changed is not relivant.
5844 * <script type="text/javascript">
5848 * @class Roo.EventManager
5849 * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
5850 * several useful events directly.
5851 * See {@link Roo.EventObject} for more details on normalized event objects.
5854 Roo.EventManager = function(){
5855 var docReadyEvent, docReadyProcId, docReadyState = false;
5856 var resizeEvent, resizeTask, textEvent, textSize;
5857 var E = Roo.lib.Event;
5858 var D = Roo.lib.Dom;
5861 var fireDocReady = function(){
5863 docReadyState = true;
5866 clearInterval(docReadyProcId);
5868 if(Roo.isGecko || Roo.isOpera) {
5869 document.removeEventListener("DOMContentLoaded", fireDocReady, false);
5872 var defer = document.getElementById("ie-deferred-loader");
5874 defer.onreadystatechange = null;
5875 defer.parentNode.removeChild(defer);
5879 docReadyEvent.fire();
5880 docReadyEvent.clearListeners();
5885 var initDocReady = function(){
5886 docReadyEvent = new Roo.util.Event();
5887 if(Roo.isGecko || Roo.isOpera) {
5888 document.addEventListener("DOMContentLoaded", fireDocReady, false);
5890 document.write("<s"+'cript id="ie-deferred-loader" defer="defer" src="/'+'/:"></s'+"cript>");
5891 var defer = document.getElementById("ie-deferred-loader");
5892 defer.onreadystatechange = function(){
5893 if(this.readyState == "complete"){
5897 }else if(Roo.isSafari){
5898 docReadyProcId = setInterval(function(){
5899 var rs = document.readyState;
5900 if(rs == "complete") {
5905 // no matter what, make sure it fires on load
5906 E.on(window, "load", fireDocReady);
5909 var createBuffered = function(h, o){
5910 var task = new Roo.util.DelayedTask(h);
5912 // create new event object impl so new events don't wipe out properties
5913 e = new Roo.EventObjectImpl(e);
5914 task.delay(o.buffer, h, null, [e]);
5918 var createSingle = function(h, el, ename, fn){
5920 Roo.EventManager.removeListener(el, ename, fn);
5925 var createDelayed = function(h, o){
5927 // create new event object impl so new events don't wipe out properties
5928 e = new Roo.EventObjectImpl(e);
5929 setTimeout(function(){
5935 var listen = function(element, ename, opt, fn, scope){
5936 var o = (!opt || typeof opt == "boolean") ? {} : opt;
5937 fn = fn || o.fn; scope = scope || o.scope;
5938 var el = Roo.getDom(element);
5940 throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
5942 var h = function(e){
5943 e = Roo.EventObject.setEvent(e);
5946 t = e.getTarget(o.delegate, el);
5953 if(o.stopEvent === true){
5956 if(o.preventDefault === true){
5959 if(o.stopPropagation === true){
5960 e.stopPropagation();
5963 if(o.normalized === false){
5967 fn.call(scope || el, e, t, o);
5970 h = createDelayed(h, o);
5973 h = createSingle(h, el, ename, fn);
5976 h = createBuffered(h, o);
5978 fn._handlers = fn._handlers || [];
5979 fn._handlers.push([Roo.id(el), ename, h]);
5982 if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery
5983 el.addEventListener("DOMMouseScroll", h, false);
5984 E.on(window, 'unload', function(){
5985 el.removeEventListener("DOMMouseScroll", h, false);
5988 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
5989 Roo.EventManager.stoppedMouseDownEvent.addListener(h);
5994 var stopListening = function(el, ename, fn){
5995 var id = Roo.id(el), hds = fn._handlers, hd = fn;
5997 for(var i = 0, len = hds.length; i < len; i++){
5999 if(h[0] == id && h[1] == ename){
6006 E.un(el, ename, hd);
6007 el = Roo.getDom(el);
6008 if(ename == "mousewheel" && el.addEventListener){
6009 el.removeEventListener("DOMMouseScroll", hd, false);
6011 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6012 Roo.EventManager.stoppedMouseDownEvent.removeListener(hd);
6016 var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
6023 * @scope Roo.EventManager
6028 * This is no longer needed and is deprecated. Places a simple wrapper around an event handler to override the browser event
6029 * object with a Roo.EventObject
6030 * @param {Function} fn The method the event invokes
6031 * @param {Object} scope An object that becomes the scope of the handler
6032 * @param {boolean} override If true, the obj passed in becomes
6033 * the execution scope of the listener
6034 * @return {Function} The wrapped function
6037 wrap : function(fn, scope, override){
6039 Roo.EventObject.setEvent(e);
6040 fn.call(override ? scope || window : window, Roo.EventObject, scope);
6045 * Appends an event handler to an element (shorthand for addListener)
6046 * @param {String/HTMLElement} element The html element or id to assign the
6047 * @param {String} eventName The type of event to listen for
6048 * @param {Function} handler The method the event invokes
6049 * @param {Object} scope (optional) The scope in which to execute the handler
6050 * function. The handler function's "this" context.
6051 * @param {Object} options (optional) An object containing handler configuration
6052 * properties. This may contain any of the following properties:<ul>
6053 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6054 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6055 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6056 * <li>preventDefault {Boolean} True to prevent the default action</li>
6057 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6058 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6059 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6060 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6061 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6062 * by the specified number of milliseconds. If the event fires again within that time, the original
6063 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6066 * <b>Combining Options</b><br>
6067 * Using the options argument, it is possible to combine different types of listeners:<br>
6069 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6071 el.on('click', this.onClick, this, {
6078 * <b>Attaching multiple handlers in 1 call</b><br>
6079 * The method also allows for a single argument to be passed which is a config object containing properties
6080 * which specify multiple handlers.
6090 fn: this.onMouseOver
6099 * Or a shorthand syntax:<br>
6102 'click' : this.onClick,
6103 'mouseover' : this.onMouseOver,
6104 'mouseout' : this.onMouseOut
6108 addListener : function(element, eventName, fn, scope, options){
6109 if(typeof eventName == "object"){
6115 if(typeof o[e] == "function"){
6117 listen(element, e, o, o[e], o.scope);
6119 // individual options
6120 listen(element, e, o[e]);
6125 return listen(element, eventName, options, fn, scope);
6129 * Removes an event handler
6131 * @param {String/HTMLElement} element The id or html element to remove the
6133 * @param {String} eventName The type of event
6134 * @param {Function} fn
6135 * @return {Boolean} True if a listener was actually removed
6137 removeListener : function(element, eventName, fn){
6138 return stopListening(element, eventName, fn);
6142 * Fires when the document is ready (before onload and before images are loaded). Can be
6143 * accessed shorthanded Roo.onReady().
6144 * @param {Function} fn The method the event invokes
6145 * @param {Object} scope An object that becomes the scope of the handler
6146 * @param {boolean} options
6148 onDocumentReady : function(fn, scope, options){
6149 if(docReadyState){ // if it already fired
6150 docReadyEvent.addListener(fn, scope, options);
6151 docReadyEvent.fire();
6152 docReadyEvent.clearListeners();
6158 docReadyEvent.addListener(fn, scope, options);
6162 * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers.
6163 * @param {Function} fn The method the event invokes
6164 * @param {Object} scope An object that becomes the scope of the handler
6165 * @param {boolean} options
6167 onWindowResize : function(fn, scope, options){
6169 resizeEvent = new Roo.util.Event();
6170 resizeTask = new Roo.util.DelayedTask(function(){
6171 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6173 E.on(window, "resize", function(){
6175 resizeTask.delay(50);
6177 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6181 resizeEvent.addListener(fn, scope, options);
6185 * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
6186 * @param {Function} fn The method the event invokes
6187 * @param {Object} scope An object that becomes the scope of the handler
6188 * @param {boolean} options
6190 onTextResize : function(fn, scope, options){
6192 textEvent = new Roo.util.Event();
6193 var textEl = new Roo.Element(document.createElement('div'));
6194 textEl.dom.className = 'x-text-resize';
6195 textEl.dom.innerHTML = 'X';
6196 textEl.appendTo(document.body);
6197 textSize = textEl.dom.offsetHeight;
6198 setInterval(function(){
6199 if(textEl.dom.offsetHeight != textSize){
6200 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
6202 }, this.textResizeInterval);
6204 textEvent.addListener(fn, scope, options);
6208 * Removes the passed window resize listener.
6209 * @param {Function} fn The method the event invokes
6210 * @param {Object} scope The scope of handler
6212 removeResizeListener : function(fn, scope){
6214 resizeEvent.removeListener(fn, scope);
6219 fireResize : function(){
6221 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6225 * Url used for onDocumentReady with using SSL (defaults to Roo.SSL_SECURE_URL)
6229 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
6231 textResizeInterval : 50
6236 * @scopeAlias pub=Roo.EventManager
6240 * Appends an event handler to an element (shorthand for addListener)
6241 * @param {String/HTMLElement} element The html element or id to assign the
6242 * @param {String} eventName The type of event to listen for
6243 * @param {Function} handler The method the event invokes
6244 * @param {Object} scope (optional) The scope in which to execute the handler
6245 * function. The handler function's "this" context.
6246 * @param {Object} options (optional) An object containing handler configuration
6247 * properties. This may contain any of the following properties:<ul>
6248 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6249 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6250 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6251 * <li>preventDefault {Boolean} True to prevent the default action</li>
6252 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6253 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6254 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6255 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6256 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6257 * by the specified number of milliseconds. If the event fires again within that time, the original
6258 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6261 * <b>Combining Options</b><br>
6262 * Using the options argument, it is possible to combine different types of listeners:<br>
6264 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6266 el.on('click', this.onClick, this, {
6273 * <b>Attaching multiple handlers in 1 call</b><br>
6274 * The method also allows for a single argument to be passed which is a config object containing properties
6275 * which specify multiple handlers.
6285 fn: this.onMouseOver
6294 * Or a shorthand syntax:<br>
6297 'click' : this.onClick,
6298 'mouseover' : this.onMouseOver,
6299 'mouseout' : this.onMouseOut
6303 pub.on = pub.addListener;
6304 pub.un = pub.removeListener;
6306 pub.stoppedMouseDownEvent = new Roo.util.Event();
6310 * Fires when the document is ready (before onload and before images are loaded). Shorthand of {@link Roo.EventManager#onDocumentReady}.
6311 * @param {Function} fn The method the event invokes
6312 * @param {Object} scope An object that becomes the scope of the handler
6313 * @param {boolean} override If true, the obj passed in becomes
6314 * the execution scope of the listener
6318 Roo.onReady = Roo.EventManager.onDocumentReady;
6320 Roo.onReady(function(){
6321 var bd = Roo.get(document.body);
6326 : Roo.isGecko ? "roo-gecko"
6327 : Roo.isOpera ? "roo-opera"
6328 : Roo.isSafari ? "roo-safari" : ""];
6331 cls.push("roo-mac");
6334 cls.push("roo-linux");
6336 if(Roo.isBorderBox){
6337 cls.push('roo-border-box');
6339 if(Roo.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"
6340 var p = bd.dom.parentNode;
6342 p.className += ' roo-strict';
6345 bd.addClass(cls.join(' '));
6349 * @class Roo.EventObject
6350 * EventObject exposes the Yahoo! UI Event functionality directly on the object
6351 * passed to your event handler. It exists mostly for convenience. It also fixes the annoying null checks automatically to cleanup your code
6354 function handleClick(e){ // e is not a standard event object, it is a Roo.EventObject
6356 var target = e.getTarget();
6359 var myDiv = Roo.get("myDiv");
6360 myDiv.on("click", handleClick);
6362 Roo.EventManager.on("myDiv", 'click', handleClick);
6363 Roo.EventManager.addListener("myDiv", 'click', handleClick);
6367 Roo.EventObject = function(){
6369 var E = Roo.lib.Event;
6371 // safari keypress events for special keys return bad keycodes
6374 63235 : 39, // right
6377 63276 : 33, // page up
6378 63277 : 34, // page down
6379 63272 : 46, // delete
6384 // normalize button clicks
6385 var btnMap = Roo.isIE ? {1:0,4:1,2:2} :
6386 (Roo.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
6388 Roo.EventObjectImpl = function(e){
6390 this.setEvent(e.browserEvent || e);
6393 Roo.EventObjectImpl.prototype = {
6395 * Used to fix doc tools.
6396 * @scope Roo.EventObject.prototype
6402 /** The normal browser event */
6403 browserEvent : null,
6404 /** The button pressed in a mouse event */
6406 /** True if the shift key was down during the event */
6408 /** True if the control key was down during the event */
6410 /** True if the alt key was down during the event */
6469 setEvent : function(e){
6470 if(e == this || (e && e.browserEvent)){ // already wrapped
6473 this.browserEvent = e;
6475 // normalize buttons
6476 this.button = e.button ? btnMap[e.button] : (e.which ? e.which-1 : -1);
6477 if(e.type == 'click' && this.button == -1){
6481 this.shiftKey = e.shiftKey;
6482 // mac metaKey behaves like ctrlKey
6483 this.ctrlKey = e.ctrlKey || e.metaKey;
6484 this.altKey = e.altKey;
6485 // in getKey these will be normalized for the mac
6486 this.keyCode = e.keyCode;
6487 // keyup warnings on firefox.
6488 this.charCode = (e.type == 'keyup' || e.type == 'keydown') ? 0 : e.charCode;
6489 // cache the target for the delayed and or buffered events
6490 this.target = E.getTarget(e);
6492 this.xy = E.getXY(e);
6495 this.shiftKey = false;
6496 this.ctrlKey = false;
6497 this.altKey = false;
6507 * Stop the event (preventDefault and stopPropagation)
6509 stopEvent : function(){
6510 if(this.browserEvent){
6511 if(this.browserEvent.type == 'mousedown'){
6512 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6514 E.stopEvent(this.browserEvent);
6519 * Prevents the browsers default handling of the event.
6521 preventDefault : function(){
6522 if(this.browserEvent){
6523 E.preventDefault(this.browserEvent);
6528 isNavKeyPress : function(){
6529 var k = this.keyCode;
6530 k = Roo.isSafari ? (safariKeys[k] || k) : k;
6531 return (k >= 33 && k <= 40) || k == this.RETURN || k == this.TAB || k == this.ESC;
6534 isSpecialKey : function(){
6535 var k = this.keyCode;
6536 return (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13 || k == 40 || k == 27 ||
6537 (k == 16) || (k == 17) ||
6538 (k >= 18 && k <= 20) ||
6539 (k >= 33 && k <= 35) ||
6540 (k >= 36 && k <= 39) ||
6541 (k >= 44 && k <= 45);
6544 * Cancels bubbling of the event.
6546 stopPropagation : function(){
6547 if(this.browserEvent){
6548 if(this.type == 'mousedown'){
6549 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6551 E.stopPropagation(this.browserEvent);
6556 * Gets the key code for the event.
6559 getCharCode : function(){
6560 return this.charCode || this.keyCode;
6564 * Returns a normalized keyCode for the event.
6565 * @return {Number} The key code
6567 getKey : function(){
6568 var k = this.keyCode || this.charCode;
6569 return Roo.isSafari ? (safariKeys[k] || k) : k;
6573 * Gets the x coordinate of the event.
6576 getPageX : function(){
6581 * Gets the y coordinate of the event.
6584 getPageY : function(){
6589 * Gets the time of the event.
6592 getTime : function(){
6593 if(this.browserEvent){
6594 return E.getTime(this.browserEvent);
6600 * Gets the page coordinates of the event.
6601 * @return {Array} The xy values like [x, y]
6608 * Gets the target for the event.
6609 * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
6610 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6611 search as a number or element (defaults to 10 || document.body)
6612 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6613 * @return {HTMLelement}
6615 getTarget : function(selector, maxDepth, returnEl){
6616 return selector ? Roo.fly(this.target).findParent(selector, maxDepth, returnEl) : this.target;
6619 * Gets the related target.
6620 * @return {HTMLElement}
6622 getRelatedTarget : function(){
6623 if(this.browserEvent){
6624 return E.getRelatedTarget(this.browserEvent);
6630 * Normalizes mouse wheel delta across browsers
6631 * @return {Number} The delta
6633 getWheelDelta : function(){
6634 var e = this.browserEvent;
6636 if(e.wheelDelta){ /* IE/Opera. */
6637 delta = e.wheelDelta/120;
6638 }else if(e.detail){ /* Mozilla case. */
6639 delta = -e.detail/3;
6645 * Returns true if the control, meta, shift or alt key was pressed during this event.
6648 hasModifier : function(){
6649 return !!((this.ctrlKey || this.altKey) || this.shiftKey);
6653 * Returns true if the target of this event equals el or is a child of el
6654 * @param {String/HTMLElement/Element} el
6655 * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
6658 within : function(el, related){
6659 var t = this[related ? "getRelatedTarget" : "getTarget"]();
6660 return t && Roo.fly(el).contains(t);
6663 getPoint : function(){
6664 return new Roo.lib.Point(this.xy[0], this.xy[1]);
6668 return new Roo.EventObjectImpl();
6673 * Ext JS Library 1.1.1
6674 * Copyright(c) 2006-2007, Ext JS, LLC.
6676 * Originally Released Under LGPL - original licence link has changed is not relivant.
6679 * <script type="text/javascript">
6683 // was in Composite Element!??!?!
6686 var D = Roo.lib.Dom;
6687 var E = Roo.lib.Event;
6688 var A = Roo.lib.Anim;
6690 // local style camelizing for speed
6692 var camelRe = /(-[a-z])/gi;
6693 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
6694 var view = document.defaultView;
6697 * @class Roo.Element
6698 * Represents an Element in the DOM.<br><br>
6701 var el = Roo.get("my-div");
6704 var el = getEl("my-div");
6706 // or with a DOM element
6707 var el = Roo.get(myDivElement);
6709 * Using Roo.get() or getEl() instead of calling the constructor directly ensures you get the same object
6710 * each call instead of constructing a new one.<br><br>
6711 * <b>Animations</b><br />
6712 * Many of the functions for manipulating an element have an optional "animate" parameter. The animate parameter
6713 * should either be a boolean (true) or an object literal with animation options. The animation options are:
6715 Option Default Description
6716 --------- -------- ---------------------------------------------
6717 duration .35 The duration of the animation in seconds
6718 easing easeOut The YUI easing method
6719 callback none A function to execute when the anim completes
6720 scope this The scope (this) of the callback function
6722 * Also, the Anim object being used for the animation will be set on your options object as "anim", which allows you to stop or
6723 * manipulate the animation. Here's an example:
6725 var el = Roo.get("my-div");
6730 // default animation
6731 el.setWidth(100, true);
6733 // animation with some options set
6740 // using the "anim" property to get the Anim object
6746 el.setWidth(100, opt);
6748 if(opt.anim.isAnimated()){
6752 * <b> Composite (Collections of) Elements</b><br />
6753 * For working with collections of Elements, see <a href="Roo.CompositeElement.html">Roo.CompositeElement</a>
6754 * @constructor Create a new Element directly.
6755 * @param {String/HTMLElement} element
6756 * @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class).
6758 Roo.Element = function(element, forceNew){
6759 var dom = typeof element == "string" ?
6760 document.getElementById(element) : element;
6761 if(!dom){ // invalid id/element
6765 if(forceNew !== true && id && Roo.Element.cache[id]){ // element object already exists
6766 return Roo.Element.cache[id];
6776 * The DOM element ID
6779 this.id = id || Roo.id(dom);
6782 var El = Roo.Element;
6786 * The element's default display mode (defaults to "")
6789 originalDisplay : "",
6793 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
6798 * Sets the element's visibility mode. When setVisible() is called it
6799 * will use this to determine whether to set the visibility or the display property.
6800 * @param visMode Element.VISIBILITY or Element.DISPLAY
6801 * @return {Roo.Element} this
6803 setVisibilityMode : function(visMode){
6804 this.visibilityMode = visMode;
6808 * Convenience method for setVisibilityMode(Element.DISPLAY)
6809 * @param {String} display (optional) What to set display to when visible
6810 * @return {Roo.Element} this
6812 enableDisplayMode : function(display){
6813 this.setVisibilityMode(El.DISPLAY);
6814 if(typeof display != "undefined") this.originalDisplay = display;
6819 * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
6820 * @param {String} selector The simple selector to test
6821 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6822 search as a number or element (defaults to 10 || document.body)
6823 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6824 * @return {HTMLElement} The matching DOM node (or null if no match was found)
6826 findParent : function(simpleSelector, maxDepth, returnEl){
6827 var p = this.dom, b = document.body, depth = 0, dq = Roo.DomQuery, stopEl;
6828 maxDepth = maxDepth || 50;
6829 if(typeof maxDepth != "number"){
6830 stopEl = Roo.getDom(maxDepth);
6833 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
6834 if(dq.is(p, simpleSelector)){
6835 return returnEl ? Roo.get(p) : p;
6845 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
6846 * @param {String} selector The simple selector to test
6847 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6848 search as a number or element (defaults to 10 || document.body)
6849 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6850 * @return {HTMLElement} The matching DOM node (or null if no match was found)
6852 findParentNode : function(simpleSelector, maxDepth, returnEl){
6853 var p = Roo.fly(this.dom.parentNode, '_internal');
6854 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
6858 * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
6859 * This is a shortcut for findParentNode() that always returns an Roo.Element.
6860 * @param {String} selector The simple selector to test
6861 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6862 search as a number or element (defaults to 10 || document.body)
6863 * @return {Roo.Element} The matching DOM node (or null if no match was found)
6865 up : function(simpleSelector, maxDepth){
6866 return this.findParentNode(simpleSelector, maxDepth, true);
6872 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
6873 * @param {String} selector The simple selector to test
6874 * @return {Boolean} True if this element matches the selector, else false
6876 is : function(simpleSelector){
6877 return Roo.DomQuery.is(this.dom, simpleSelector);
6881 * Perform animation on this element.
6882 * @param {Object} args The YUI animation control args
6883 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to .35)
6884 * @param {Function} onComplete (optional) Function to call when animation completes
6885 * @param {String} easing (optional) Easing method to use (defaults to 'easeOut')
6886 * @param {String} animType (optional) 'run' is the default. Can also be 'color', 'motion', or 'scroll'
6887 * @return {Roo.Element} this
6889 animate : function(args, duration, onComplete, easing, animType){
6890 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
6895 * @private Internal animation call
6897 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
6898 animType = animType || 'run';
6900 var anim = Roo.lib.Anim[animType](
6902 (opt.duration || defaultDur) || .35,
6903 (opt.easing || defaultEase) || 'easeOut',
6905 Roo.callback(cb, this);
6906 Roo.callback(opt.callback, opt.scope || this, [this, opt]);
6914 // private legacy anim prep
6915 preanim : function(a, i){
6916 return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
6920 * Removes worthless text nodes
6921 * @param {Boolean} forceReclean (optional) By default the element
6922 * keeps track if it has been cleaned already so
6923 * you can call this over and over. However, if you update the element and
6924 * need to force a reclean, you can pass true.
6926 clean : function(forceReclean){
6927 if(this.isCleaned && forceReclean !== true){
6931 var d = this.dom, n = d.firstChild, ni = -1;
6933 var nx = n.nextSibling;
6934 if(n.nodeType == 3 && !ns.test(n.nodeValue)){
6941 this.isCleaned = true;
6946 calcOffsetsTo : function(el){
6949 var restorePos = false;
6950 if(el.getStyle('position') == 'static'){
6951 el.position('relative');
6956 while(op && op != d && op.tagName != 'HTML'){
6959 op = op.offsetParent;
6962 el.position('static');
6968 * Scrolls this element into view within the passed container.
6969 * @param {String/HTMLElement/Element} container (optional) The container element to scroll (defaults to document.body)
6970 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
6971 * @return {Roo.Element} this
6973 scrollIntoView : function(container, hscroll){
6974 var c = Roo.getDom(container) || document.body;
6977 var o = this.calcOffsetsTo(c),
6980 b = t+el.offsetHeight,
6981 r = l+el.offsetWidth;
6983 var ch = c.clientHeight;
6984 var ct = parseInt(c.scrollTop, 10);
6985 var cl = parseInt(c.scrollLeft, 10);
6987 var cr = cl + c.clientWidth;
6995 if(hscroll !== false){
6999 c.scrollLeft = r-c.clientWidth;
7006 scrollChildIntoView : function(child, hscroll){
7007 Roo.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
7011 * Measures the element's content height and updates height to match. Note: this function uses setTimeout so
7012 * the new height may not be available immediately.
7013 * @param {Boolean} animate (optional) Animate the transition (defaults to false)
7014 * @param {Float} duration (optional) Length of the animation in seconds (defaults to .35)
7015 * @param {Function} onComplete (optional) Function to call when animation completes
7016 * @param {String} easing (optional) Easing method to use (defaults to easeOut)
7017 * @return {Roo.Element} this
7019 autoHeight : function(animate, duration, onComplete, easing){
7020 var oldHeight = this.getHeight();
7022 this.setHeight(1); // force clipping
7023 setTimeout(function(){
7024 var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari
7026 this.setHeight(height);
7028 if(typeof onComplete == "function"){
7032 this.setHeight(oldHeight); // restore original height
7033 this.setHeight(height, animate, duration, function(){
7035 if(typeof onComplete == "function") onComplete();
7036 }.createDelegate(this), easing);
7038 }.createDelegate(this), 0);
7043 * Returns true if this element is an ancestor of the passed element
7044 * @param {HTMLElement/String} el The element to check
7045 * @return {Boolean} True if this element is an ancestor of el, else false
7047 contains : function(el){
7048 if(!el){return false;}
7049 return D.isAncestor(this.dom, el.dom ? el.dom : el);
7053 * Checks whether the element is currently visible using both visibility and display properties.
7054 * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
7055 * @return {Boolean} True if the element is currently visible, else false
7057 isVisible : function(deep) {
7058 var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
7059 if(deep !== true || !vis){
7062 var p = this.dom.parentNode;
7063 while(p && p.tagName.toLowerCase() != "body"){
7064 if(!Roo.fly(p, '_isVisible').isVisible()){
7073 * Creates a {@link Roo.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
7074 * @param {String} selector The CSS selector
7075 * @param {Boolean} unique (optional) True to create a unique Roo.Element for each child (defaults to false, which creates a single shared flyweight object)
7076 * @return {CompositeElement/CompositeElementLite} The composite element
7078 select : function(selector, unique){
7079 return El.select(selector, unique, this.dom);
7083 * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
7084 * @param {String} selector The CSS selector
7085 * @return {Array} An array of the matched nodes
7087 query : function(selector, unique){
7088 return Roo.DomQuery.select(selector, this.dom);
7092 * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
7093 * @param {String} selector The CSS selector
7094 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7095 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7097 child : function(selector, returnDom){
7098 var n = Roo.DomQuery.selectNode(selector, this.dom);
7099 return returnDom ? n : Roo.get(n);
7103 * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
7104 * @param {String} selector The CSS selector
7105 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7106 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7108 down : function(selector, returnDom){
7109 var n = Roo.DomQuery.selectNode(" > " + selector, this.dom);
7110 return returnDom ? n : Roo.get(n);
7114 * Initializes a {@link Roo.dd.DD} drag drop object for this element.
7115 * @param {String} group The group the DD object is member of
7116 * @param {Object} config The DD config object
7117 * @param {Object} overrides An object containing methods to override/implement on the DD object
7118 * @return {Roo.dd.DD} The DD object
7120 initDD : function(group, config, overrides){
7121 var dd = new Roo.dd.DD(Roo.id(this.dom), group, config);
7122 return Roo.apply(dd, overrides);
7126 * Initializes a {@link Roo.dd.DDProxy} object for this element.
7127 * @param {String} group The group the DDProxy object is member of
7128 * @param {Object} config The DDProxy config object
7129 * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
7130 * @return {Roo.dd.DDProxy} The DDProxy object
7132 initDDProxy : function(group, config, overrides){
7133 var dd = new Roo.dd.DDProxy(Roo.id(this.dom), group, config);
7134 return Roo.apply(dd, overrides);
7138 * Initializes a {@link Roo.dd.DDTarget} object for this element.
7139 * @param {String} group The group the DDTarget object is member of
7140 * @param {Object} config The DDTarget config object
7141 * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
7142 * @return {Roo.dd.DDTarget} The DDTarget object
7144 initDDTarget : function(group, config, overrides){
7145 var dd = new Roo.dd.DDTarget(Roo.id(this.dom), group, config);
7146 return Roo.apply(dd, overrides);
7150 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
7151 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
7152 * @param {Boolean} visible Whether the element is visible
7153 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7154 * @return {Roo.Element} this
7156 setVisible : function(visible, animate){
7158 if(this.visibilityMode == El.DISPLAY){
7159 this.setDisplayed(visible);
7162 this.dom.style.visibility = visible ? "visible" : "hidden";
7165 // closure for composites
7167 var visMode = this.visibilityMode;
7169 this.setOpacity(.01);
7170 this.setVisible(true);
7172 this.anim({opacity: { to: (visible?1:0) }},
7173 this.preanim(arguments, 1),
7174 null, .35, 'easeIn', function(){
7176 if(visMode == El.DISPLAY){
7177 dom.style.display = "none";
7179 dom.style.visibility = "hidden";
7181 Roo.get(dom).setOpacity(1);
7189 * Returns true if display is not "none"
7192 isDisplayed : function() {
7193 return this.getStyle("display") != "none";
7197 * Toggles the element's visibility or display, depending on visibility mode.
7198 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7199 * @return {Roo.Element} this
7201 toggle : function(animate){
7202 this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
7207 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
7208 * @param {Boolean} value Boolean value to display the element using its default display, or a string to set the display directly
7209 * @return {Roo.Element} this
7211 setDisplayed : function(value) {
7212 if(typeof value == "boolean"){
7213 value = value ? this.originalDisplay : "none";
7215 this.setStyle("display", value);
7220 * Tries to focus the element. Any exceptions are caught and ignored.
7221 * @return {Roo.Element} this
7223 focus : function() {
7231 * Tries to blur the element. Any exceptions are caught and ignored.
7232 * @return {Roo.Element} this
7242 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
7243 * @param {String/Array} className The CSS class to add, or an array of classes
7244 * @return {Roo.Element} this
7246 addClass : function(className){
7247 if(className instanceof Array){
7248 for(var i = 0, len = className.length; i < len; i++) {
7249 this.addClass(className[i]);
7252 if(className && !this.hasClass(className)){
7253 this.dom.className = this.dom.className + " " + className;
7260 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
7261 * @param {String/Array} className The CSS class to add, or an array of classes
7262 * @return {Roo.Element} this
7264 radioClass : function(className){
7265 var siblings = this.dom.parentNode.childNodes;
7266 for(var i = 0; i < siblings.length; i++) {
7267 var s = siblings[i];
7268 if(s.nodeType == 1){
7269 Roo.get(s).removeClass(className);
7272 this.addClass(className);
7277 * Removes one or more CSS classes from the element.
7278 * @param {String/Array} className The CSS class to remove, or an array of classes
7279 * @return {Roo.Element} this
7281 removeClass : function(className){
7282 if(!className || !this.dom.className){
7285 if(className instanceof Array){
7286 for(var i = 0, len = className.length; i < len; i++) {
7287 this.removeClass(className[i]);
7290 if(this.hasClass(className)){
7291 var re = this.classReCache[className];
7293 re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
7294 this.classReCache[className] = re;
7296 this.dom.className =
7297 this.dom.className.replace(re, " ");
7307 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
7308 * @param {String} className The CSS class to toggle
7309 * @return {Roo.Element} this
7311 toggleClass : function(className){
7312 if(this.hasClass(className)){
7313 this.removeClass(className);
7315 this.addClass(className);
7321 * Checks if the specified CSS class exists on this element's DOM node.
7322 * @param {String} className The CSS class to check for
7323 * @return {Boolean} True if the class exists, else false
7325 hasClass : function(className){
7326 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
7330 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
7331 * @param {String} oldClassName The CSS class to replace
7332 * @param {String} newClassName The replacement CSS class
7333 * @return {Roo.Element} this
7335 replaceClass : function(oldClassName, newClassName){
7336 this.removeClass(oldClassName);
7337 this.addClass(newClassName);
7342 * Returns an object with properties matching the styles requested.
7343 * For example, el.getStyles('color', 'font-size', 'width') might return
7344 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
7345 * @param {String} style1 A style name
7346 * @param {String} style2 A style name
7347 * @param {String} etc.
7348 * @return {Object} The style object
7350 getStyles : function(){
7351 var a = arguments, len = a.length, r = {};
7352 for(var i = 0; i < len; i++){
7353 r[a[i]] = this.getStyle(a[i]);
7359 * Normalizes currentStyle and computedStyle. This is not YUI getStyle, it is an optimised version.
7360 * @param {String} property The style property whose value is returned.
7361 * @return {String} The current value of the style property for this element.
7363 getStyle : function(){
7364 return view && view.getComputedStyle ?
7366 var el = this.dom, v, cs, camel;
7367 if(prop == 'float'){
7370 if(el.style && (v = el.style[prop])){
7373 if(cs = view.getComputedStyle(el, "")){
7374 if(!(camel = propCache[prop])){
7375 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7382 var el = this.dom, v, cs, camel;
7383 if(prop == 'opacity'){
7384 if(typeof el.style.filter == 'string'){
7385 var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i);
7387 var fv = parseFloat(m[1]);
7389 return fv ? fv / 100 : 0;
7394 }else if(prop == 'float'){
7395 prop = "styleFloat";
7397 if(!(camel = propCache[prop])){
7398 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7400 if(v = el.style[camel]){
7403 if(cs = el.currentStyle){
7411 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
7412 * @param {String/Object} property The style property to be set, or an object of multiple styles.
7413 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
7414 * @return {Roo.Element} this
7416 setStyle : function(prop, value){
7417 if(typeof prop == "string"){
7419 if (prop == 'float') {
7420 this.setStyle(Roo.isIE ? 'styleFloat' : 'cssFloat', value);
7425 if(!(camel = propCache[prop])){
7426 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7429 if(camel == 'opacity') {
7430 this.setOpacity(value);
7432 this.dom.style[camel] = value;
7435 for(var style in prop){
7436 if(typeof prop[style] != "function"){
7437 this.setStyle(style, prop[style]);
7445 * More flexible version of {@link #setStyle} for setting style properties.
7446 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
7447 * a function which returns such a specification.
7448 * @return {Roo.Element} this
7450 applyStyles : function(style){
7451 Roo.DomHelper.applyStyles(this.dom, style);
7456 * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7457 * @return {Number} The X position of the element
7460 return D.getX(this.dom);
7464 * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7465 * @return {Number} The Y position of the element
7468 return D.getY(this.dom);
7472 * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7473 * @return {Array} The XY position of the element
7476 return D.getXY(this.dom);
7480 * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7481 * @param {Number} The X position of the element
7482 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7483 * @return {Roo.Element} this
7485 setX : function(x, animate){
7487 D.setX(this.dom, x);
7489 this.setXY([x, this.getY()], this.preanim(arguments, 1));
7495 * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7496 * @param {Number} The Y position of the element
7497 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7498 * @return {Roo.Element} this
7500 setY : function(y, animate){
7502 D.setY(this.dom, y);
7504 this.setXY([this.getX(), y], this.preanim(arguments, 1));
7510 * Sets the element's left position directly using CSS style (instead of {@link #setX}).
7511 * @param {String} left The left CSS property value
7512 * @return {Roo.Element} this
7514 setLeft : function(left){
7515 this.setStyle("left", this.addUnits(left));
7520 * Sets the element's top position directly using CSS style (instead of {@link #setY}).
7521 * @param {String} top The top CSS property value
7522 * @return {Roo.Element} this
7524 setTop : function(top){
7525 this.setStyle("top", this.addUnits(top));
7530 * Sets the element's CSS right style.
7531 * @param {String} right The right CSS property value
7532 * @return {Roo.Element} this
7534 setRight : function(right){
7535 this.setStyle("right", this.addUnits(right));
7540 * Sets the element's CSS bottom style.
7541 * @param {String} bottom The bottom CSS property value
7542 * @return {Roo.Element} this
7544 setBottom : function(bottom){
7545 this.setStyle("bottom", this.addUnits(bottom));
7550 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7551 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7552 * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
7553 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7554 * @return {Roo.Element} this
7556 setXY : function(pos, animate){
7558 D.setXY(this.dom, pos);
7560 this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion');
7566 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7567 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7568 * @param {Number} x X value for new position (coordinates are page-based)
7569 * @param {Number} y Y value for new position (coordinates are page-based)
7570 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7571 * @return {Roo.Element} this
7573 setLocation : function(x, y, animate){
7574 this.setXY([x, y], this.preanim(arguments, 2));
7579 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7580 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7581 * @param {Number} x X value for new position (coordinates are page-based)
7582 * @param {Number} y Y value for new position (coordinates are page-based)
7583 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7584 * @return {Roo.Element} this
7586 moveTo : function(x, y, animate){
7587 this.setXY([x, y], this.preanim(arguments, 2));
7592 * Returns the region of the given element.
7593 * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
7594 * @return {Region} A Roo.lib.Region containing "top, left, bottom, right" member data.
7596 getRegion : function(){
7597 return D.getRegion(this.dom);
7601 * Returns the offset height of the element
7602 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
7603 * @return {Number} The element's height
7605 getHeight : function(contentHeight){
7606 var h = this.dom.offsetHeight || 0;
7607 return contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
7611 * Returns the offset width of the element
7612 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
7613 * @return {Number} The element's width
7615 getWidth : function(contentWidth){
7616 var w = this.dom.offsetWidth || 0;
7617 return contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
7621 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
7622 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
7623 * if a height has not been set using CSS.
7626 getComputedHeight : function(){
7627 var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight);
7629 h = parseInt(this.getStyle('height'), 10) || 0;
7630 if(!this.isBorderBox()){
7631 h += this.getFrameWidth('tb');
7638 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
7639 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
7640 * if a width has not been set using CSS.
7643 getComputedWidth : function(){
7644 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
7646 w = parseInt(this.getStyle('width'), 10) || 0;
7647 if(!this.isBorderBox()){
7648 w += this.getFrameWidth('lr');
7655 * Returns the size of the element.
7656 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
7657 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
7659 getSize : function(contentSize){
7660 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
7664 * Returns the width and height of the viewport.
7665 * @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)}
7667 getViewSize : function(){
7668 var d = this.dom, doc = document, aw = 0, ah = 0;
7669 if(d == doc || d == doc.body){
7670 return {width : D.getViewWidth(), height: D.getViewHeight()};
7673 width : d.clientWidth,
7674 height: d.clientHeight
7680 * Returns the value of the "value" attribute
7681 * @param {Boolean} asNumber true to parse the value as a number
7682 * @return {String/Number}
7684 getValue : function(asNumber){
7685 return asNumber ? parseInt(this.dom.value, 10) : this.dom.value;
7689 adjustWidth : function(width){
7690 if(typeof width == "number"){
7691 if(this.autoBoxAdjust && !this.isBorderBox()){
7692 width -= (this.getBorderWidth("lr") + this.getPadding("lr"));
7702 adjustHeight : function(height){
7703 if(typeof height == "number"){
7704 if(this.autoBoxAdjust && !this.isBorderBox()){
7705 height -= (this.getBorderWidth("tb") + this.getPadding("tb"));
7715 * Set the width of the element
7716 * @param {Number} width The new width
7717 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7718 * @return {Roo.Element} this
7720 setWidth : function(width, animate){
7721 width = this.adjustWidth(width);
7723 this.dom.style.width = this.addUnits(width);
7725 this.anim({width: {to: width}}, this.preanim(arguments, 1));
7731 * Set the height of the element
7732 * @param {Number} height The new height
7733 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7734 * @return {Roo.Element} this
7736 setHeight : function(height, animate){
7737 height = this.adjustHeight(height);
7739 this.dom.style.height = this.addUnits(height);
7741 this.anim({height: {to: height}}, this.preanim(arguments, 1));
7747 * Set the size of the element. If animation is true, both width an height will be animated concurrently.
7748 * @param {Number} width The new width
7749 * @param {Number} height The new height
7750 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7751 * @return {Roo.Element} this
7753 setSize : function(width, height, animate){
7754 if(typeof width == "object"){ // in case of object from getSize()
7755 height = width.height; width = width.width;
7757 width = this.adjustWidth(width); height = this.adjustHeight(height);
7759 this.dom.style.width = this.addUnits(width);
7760 this.dom.style.height = this.addUnits(height);
7762 this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2));
7768 * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
7769 * @param {Number} x X value for new position (coordinates are page-based)
7770 * @param {Number} y Y value for new position (coordinates are page-based)
7771 * @param {Number} width The new width
7772 * @param {Number} height The new height
7773 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7774 * @return {Roo.Element} this
7776 setBounds : function(x, y, width, height, animate){
7778 this.setSize(width, height);
7779 this.setLocation(x, y);
7781 width = this.adjustWidth(width); height = this.adjustHeight(height);
7782 this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}},
7783 this.preanim(arguments, 4), 'motion');
7789 * Sets the element's position and size the the specified region. If animation is true then width, height, x and y will be animated concurrently.
7790 * @param {Roo.lib.Region} region The region to fill
7791 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7792 * @return {Roo.Element} this
7794 setRegion : function(region, animate){
7795 this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1));
7800 * Appends an event handler
7802 * @param {String} eventName The type of event to append
7803 * @param {Function} fn The method the event invokes
7804 * @param {Object} scope (optional) The scope (this object) of the fn
7805 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
7807 addListener : function(eventName, fn, scope, options){
7808 Roo.EventManager.on(this.dom, eventName, fn, scope || this, options);
7812 * Removes an event handler from this element
7813 * @param {String} eventName the type of event to remove
7814 * @param {Function} fn the method the event invokes
7815 * @return {Roo.Element} this
7817 removeListener : function(eventName, fn){
7818 Roo.EventManager.removeListener(this.dom, eventName, fn);
7823 * Removes all previous added listeners from this element
7824 * @return {Roo.Element} this
7826 removeAllListeners : function(){
7827 E.purgeElement(this.dom);
7831 relayEvent : function(eventName, observable){
7832 this.on(eventName, function(e){
7833 observable.fireEvent(eventName, e);
7838 * Set the opacity of the element
7839 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
7840 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7841 * @return {Roo.Element} this
7843 setOpacity : function(opacity, animate){
7845 var s = this.dom.style;
7848 s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
7849 (opacity == 1 ? "" : "alpha(opacity=" + opacity * 100 + ")");
7851 s.opacity = opacity;
7854 this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn');
7860 * Gets the left X coordinate
7861 * @param {Boolean} local True to get the local css position instead of page coordinate
7864 getLeft : function(local){
7868 return parseInt(this.getStyle("left"), 10) || 0;
7873 * Gets the right X coordinate of the element (element X position + element width)
7874 * @param {Boolean} local True to get the local css position instead of page coordinate
7877 getRight : function(local){
7879 return this.getX() + this.getWidth();
7881 return (this.getLeft(true) + this.getWidth()) || 0;
7886 * Gets the top Y coordinate
7887 * @param {Boolean} local True to get the local css position instead of page coordinate
7890 getTop : function(local) {
7894 return parseInt(this.getStyle("top"), 10) || 0;
7899 * Gets the bottom Y coordinate of the element (element Y position + element height)
7900 * @param {Boolean} local True to get the local css position instead of page coordinate
7903 getBottom : function(local){
7905 return this.getY() + this.getHeight();
7907 return (this.getTop(true) + this.getHeight()) || 0;
7912 * Initializes positioning on this element. If a desired position is not passed, it will make the
7913 * the element positioned relative IF it is not already positioned.
7914 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
7915 * @param {Number} zIndex (optional) The zIndex to apply
7916 * @param {Number} x (optional) Set the page X position
7917 * @param {Number} y (optional) Set the page Y position
7919 position : function(pos, zIndex, x, y){
7921 if(this.getStyle('position') == 'static'){
7922 this.setStyle('position', 'relative');
7925 this.setStyle("position", pos);
7928 this.setStyle("z-index", zIndex);
7930 if(x !== undefined && y !== undefined){
7932 }else if(x !== undefined){
7934 }else if(y !== undefined){
7940 * Clear positioning back to the default when the document was loaded
7941 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
7942 * @return {Roo.Element} this
7944 clearPositioning : function(value){
7952 "position" : "static"
7958 * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
7959 * snapshot before performing an update and then restoring the element.
7962 getPositioning : function(){
7963 var l = this.getStyle("left");
7964 var t = this.getStyle("top");
7966 "position" : this.getStyle("position"),
7968 "right" : l ? "" : this.getStyle("right"),
7970 "bottom" : t ? "" : this.getStyle("bottom"),
7971 "z-index" : this.getStyle("z-index")
7976 * Gets the width of the border(s) for the specified side(s)
7977 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
7978 * passing lr would get the border (l)eft width + the border (r)ight width.
7979 * @return {Number} The width of the sides passed added together
7981 getBorderWidth : function(side){
7982 return this.addStyles(side, El.borders);
7986 * Gets the width of the padding(s) for the specified side(s)
7987 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
7988 * passing lr would get the padding (l)eft + the padding (r)ight.
7989 * @return {Number} The padding of the sides passed added together
7991 getPadding : function(side){
7992 return this.addStyles(side, El.paddings);
7996 * Set positioning with an object returned by getPositioning().
7997 * @param {Object} posCfg
7998 * @return {Roo.Element} this
8000 setPositioning : function(pc){
8001 this.applyStyles(pc);
8002 if(pc.right == "auto"){
8003 this.dom.style.right = "";
8005 if(pc.bottom == "auto"){
8006 this.dom.style.bottom = "";
8012 fixDisplay : function(){
8013 if(this.getStyle("display") == "none"){
8014 this.setStyle("visibility", "hidden");
8015 this.setStyle("display", this.originalDisplay); // first try reverting to default
8016 if(this.getStyle("display") == "none"){ // if that fails, default to block
8017 this.setStyle("display", "block");
8023 * Quick set left and top adding default units
8024 * @param {String} left The left CSS property value
8025 * @param {String} top The top CSS property value
8026 * @return {Roo.Element} this
8028 setLeftTop : function(left, top){
8029 this.dom.style.left = this.addUnits(left);
8030 this.dom.style.top = this.addUnits(top);
8035 * Move this element relative to its current position.
8036 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
8037 * @param {Number} distance How far to move the element in pixels
8038 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8039 * @return {Roo.Element} this
8041 move : function(direction, distance, animate){
8042 var xy = this.getXY();
8043 direction = direction.toLowerCase();
8047 this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2));
8051 this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2));
8056 this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2));
8061 this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2));
8068 * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
8069 * @return {Roo.Element} this
8072 if(!this.isClipped){
8073 this.isClipped = true;
8074 this.originalClip = {
8075 "o": this.getStyle("overflow"),
8076 "x": this.getStyle("overflow-x"),
8077 "y": this.getStyle("overflow-y")
8079 this.setStyle("overflow", "hidden");
8080 this.setStyle("overflow-x", "hidden");
8081 this.setStyle("overflow-y", "hidden");
8087 * Return clipping (overflow) to original clipping before clip() was called
8088 * @return {Roo.Element} this
8090 unclip : function(){
8092 this.isClipped = false;
8093 var o = this.originalClip;
8094 if(o.o){this.setStyle("overflow", o.o);}
8095 if(o.x){this.setStyle("overflow-x", o.x);}
8096 if(o.y){this.setStyle("overflow-y", o.y);}
8103 * Gets the x,y coordinates specified by the anchor position on the element.
8104 * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo} for details on supported anchor positions.
8105 * @param {Object} size (optional) An object containing the size to use for calculating anchor position
8106 * {width: (target width), height: (target height)} (defaults to the element's current size)
8107 * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead of page coordinates
8108 * @return {Array} [x, y] An array containing the element's x and y coordinates
8110 getAnchorXY : function(anchor, local, s){
8111 //Passing a different size is useful for pre-calculating anchors,
8112 //especially for anchored animations that change the el size.
8114 var w, h, vp = false;
8117 if(d == document.body || d == document){
8119 w = D.getViewWidth(); h = D.getViewHeight();
8121 w = this.getWidth(); h = this.getHeight();
8124 w = s.width; h = s.height;
8126 var x = 0, y = 0, r = Math.round;
8127 switch((anchor || "tl").toLowerCase()){
8169 var sc = this.getScroll();
8170 return [x + sc.left, y + sc.top];
8172 //Add the element's offset xy
8173 var o = this.getXY();
8174 return [x+o[0], y+o[1]];
8178 * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
8179 * supported position values.
8180 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8181 * @param {String} position The position to align to.
8182 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8183 * @return {Array} [x, y]
8185 getAlignToXY : function(el, p, o){
8189 throw "Element.alignTo with an element that doesn't exist";
8191 var c = false; //constrain to viewport
8192 var p1 = "", p2 = "";
8199 }else if(p.indexOf("-") == -1){
8202 p = p.toLowerCase();
8203 var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
8205 throw "Element.alignTo with an invalid alignment " + p;
8207 p1 = m[1]; p2 = m[2]; c = !!m[3];
8209 //Subtract the aligned el's internal xy from the target's offset xy
8210 //plus custom offset to get the aligned el's new offset xy
8211 var a1 = this.getAnchorXY(p1, true);
8212 var a2 = el.getAnchorXY(p2, false);
8213 var x = a2[0] - a1[0] + o[0];
8214 var y = a2[1] - a1[1] + o[1];
8216 //constrain the aligned el to viewport if necessary
8217 var w = this.getWidth(), h = this.getHeight(), r = el.getRegion();
8218 // 5px of margin for ie
8219 var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;
8221 //If we are at a viewport boundary and the aligned el is anchored on a target border that is
8222 //perpendicular to the vp border, allow the aligned el to slide on that border,
8223 //otherwise swap the aligned el to the opposite border of the target.
8224 var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);
8225 var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);
8226 var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
8227 var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
8230 var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5;
8231 var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5;
8233 if((x+w) > dw + scrollX){
8234 x = swapX ? r.left-w : dw+scrollX-w;
8237 x = swapX ? r.right : scrollX;
8239 if((y+h) > dh + scrollY){
8240 y = swapY ? r.top-h : dh+scrollY-h;
8243 y = swapY ? r.bottom : scrollY;
8250 getConstrainToXY : function(){
8251 var os = {top:0, left:0, bottom:0, right: 0};
8253 return function(el, local, offsets, proposedXY){
8255 offsets = offsets ? Roo.applyIf(offsets, os) : os;
8257 var vw, vh, vx = 0, vy = 0;
8258 if(el.dom == document.body || el.dom == document){
8259 vw = Roo.lib.Dom.getViewWidth();
8260 vh = Roo.lib.Dom.getViewHeight();
8262 vw = el.dom.clientWidth;
8263 vh = el.dom.clientHeight;
8265 var vxy = el.getXY();
8271 var s = el.getScroll();
8273 vx += offsets.left + s.left;
8274 vy += offsets.top + s.top;
8276 vw -= offsets.right;
8277 vh -= offsets.bottom;
8282 var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
8283 var x = xy[0], y = xy[1];
8284 var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
8286 // only move it if it needs it
8289 // first validate right/bottom
8298 // then make sure top/left isn't negative
8307 return moved ? [x, y] : false;
8312 adjustForConstraints : function(xy, parent, offsets){
8313 return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
8317 * Aligns this element with another element relative to the specified anchor points. If the other element is the
8318 * document it aligns it to the viewport.
8319 * The position parameter is optional, and can be specified in any one of the following formats:
8321 * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
8322 * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
8323 * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
8324 * deprecated in favor of the newer two anchor syntax below</i>.</li>
8325 * <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the
8326 * element's anchor point, and the second value is used as the target's anchor point.</li>
8328 * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
8329 * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
8330 * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
8331 * that specified in order to enforce the viewport constraints.
8332 * Following are all of the supported anchor positions:
8335 ----- -----------------------------
8336 tl The top left corner (default)
8337 t The center of the top edge
8338 tr The top right corner
8339 l The center of the left edge
8340 c In the center of the element
8341 r The center of the right edge
8342 bl The bottom left corner
8343 b The center of the bottom edge
8344 br The bottom right corner
8348 // align el to other-el using the default positioning ("tl-bl", non-constrained)
8349 el.alignTo("other-el");
8351 // align the top left corner of el with the top right corner of other-el (constrained to viewport)
8352 el.alignTo("other-el", "tr?");
8354 // align the bottom right corner of el with the center left edge of other-el
8355 el.alignTo("other-el", "br-l?");
8357 // align the center of el with the bottom left corner of other-el and
8358 // adjust the x position by -6 pixels (and the y position by 0)
8359 el.alignTo("other-el", "c-bl", [-6, 0]);
8361 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8362 * @param {String} position The position to align to.
8363 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8364 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8365 * @return {Roo.Element} this
8367 alignTo : function(element, position, offsets, animate){
8368 var xy = this.getAlignToXY(element, position, offsets);
8369 this.setXY(xy, this.preanim(arguments, 3));
8374 * Anchors an element to another element and realigns it when the window is resized.
8375 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8376 * @param {String} position The position to align to.
8377 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8378 * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
8379 * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
8380 * is a number, it is used as the buffer delay (defaults to 50ms).
8381 * @param {Function} callback The function to call after the animation finishes
8382 * @return {Roo.Element} this
8384 anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
8385 var action = function(){
8386 this.alignTo(el, alignment, offsets, animate);
8387 Roo.callback(callback, this);
8389 Roo.EventManager.onWindowResize(action, this);
8390 var tm = typeof monitorScroll;
8391 if(tm != 'undefined'){
8392 Roo.EventManager.on(window, 'scroll', action, this,
8393 {buffer: tm == 'number' ? monitorScroll : 50});
8395 action.call(this); // align immediately
8399 * Clears any opacity settings from this element. Required in some cases for IE.
8400 * @return {Roo.Element} this
8402 clearOpacity : function(){
8403 if (window.ActiveXObject) {
8404 if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){
8405 this.dom.style.filter = "";
8408 this.dom.style.opacity = "";
8409 this.dom.style["-moz-opacity"] = "";
8410 this.dom.style["-khtml-opacity"] = "";
8416 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8417 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8418 * @return {Roo.Element} this
8420 hide : function(animate){
8421 this.setVisible(false, this.preanim(arguments, 0));
8426 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8427 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8428 * @return {Roo.Element} this
8430 show : function(animate){
8431 this.setVisible(true, this.preanim(arguments, 0));
8436 * @private Test if size has a unit, otherwise appends the default
8438 addUnits : function(size){
8439 return Roo.Element.addUnits(size, this.defaultUnit);
8443 * Temporarily enables offsets (width,height,x,y) for an element with display:none, use endMeasure() when done.
8444 * @return {Roo.Element} this
8446 beginMeasure : function(){
8448 if(el.offsetWidth || el.offsetHeight){
8449 return this; // offsets work already
8452 var p = this.dom, b = document.body; // start with this element
8453 while((!el.offsetWidth && !el.offsetHeight) && p && p.tagName && p != b){
8454 var pe = Roo.get(p);
8455 if(pe.getStyle('display') == 'none'){
8456 changed.push({el: p, visibility: pe.getStyle("visibility")});
8457 p.style.visibility = "hidden";
8458 p.style.display = "block";
8462 this._measureChanged = changed;
8468 * Restores displays to before beginMeasure was called
8469 * @return {Roo.Element} this
8471 endMeasure : function(){
8472 var changed = this._measureChanged;
8474 for(var i = 0, len = changed.length; i < len; i++) {
8476 r.el.style.visibility = r.visibility;
8477 r.el.style.display = "none";
8479 this._measureChanged = null;
8485 * Update the innerHTML of this element, optionally searching for and processing scripts
8486 * @param {String} html The new HTML
8487 * @param {Boolean} loadScripts (optional) true to look for and process scripts
8488 * @param {Function} callback For async script loading you can be noticed when the update completes
8489 * @return {Roo.Element} this
8491 update : function(html, loadScripts, callback){
8492 if(typeof html == "undefined"){
8495 if(loadScripts !== true){
8496 this.dom.innerHTML = html;
8497 if(typeof callback == "function"){
8505 html += '<span id="' + id + '"></span>';
8507 E.onAvailable(id, function(){
8508 var hd = document.getElementsByTagName("head")[0];
8509 var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
8510 var srcRe = /\ssrc=([\'\"])(.*?)\1/i;
8511 var typeRe = /\stype=([\'\"])(.*?)\1/i;
8514 while(match = re.exec(html)){
8515 var attrs = match[1];
8516 var srcMatch = attrs ? attrs.match(srcRe) : false;
8517 if(srcMatch && srcMatch[2]){
8518 var s = document.createElement("script");
8519 s.src = srcMatch[2];
8520 var typeMatch = attrs.match(typeRe);
8521 if(typeMatch && typeMatch[2]){
8522 s.type = typeMatch[2];
8525 }else if(match[2] && match[2].length > 0){
8526 if(window.execScript) {
8527 window.execScript(match[2]);
8535 window.eval(match[2]);
8539 var el = document.getElementById(id);
8540 if(el){el.parentNode.removeChild(el);}
8541 if(typeof callback == "function"){
8545 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
8550 * Direct access to the UpdateManager update() method (takes the same parameters).
8551 * @param {String/Function} url The url for this request or a function to call to get the url
8552 * @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}
8553 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
8554 * @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.
8555 * @return {Roo.Element} this
8558 var um = this.getUpdateManager();
8559 um.update.apply(um, arguments);
8564 * Gets this element's UpdateManager
8565 * @return {Roo.UpdateManager} The UpdateManager
8567 getUpdateManager : function(){
8568 if(!this.updateManager){
8569 this.updateManager = new Roo.UpdateManager(this);
8571 return this.updateManager;
8575 * Disables text selection for this element (normalized across browsers)
8576 * @return {Roo.Element} this
8578 unselectable : function(){
8579 this.dom.unselectable = "on";
8580 this.swallowEvent("selectstart", true);
8581 this.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
8582 this.addClass("x-unselectable");
8587 * Calculates the x, y to center this element on the screen
8588 * @return {Array} The x, y values [x, y]
8590 getCenterXY : function(){
8591 return this.getAlignToXY(document, 'c-c');
8595 * Centers the Element in either the viewport, or another Element.
8596 * @param {String/HTMLElement/Roo.Element} centerIn (optional) The element in which to center the element.
8598 center : function(centerIn){
8599 this.alignTo(centerIn || document, 'c-c');
8604 * Tests various css rules/browsers to determine if this element uses a border box
8607 isBorderBox : function(){
8608 return noBoxAdjust[this.dom.tagName.toLowerCase()] || Roo.isBorderBox;
8612 * Return a box {x, y, width, height} that can be used to set another elements
8613 * size/location to match this element.
8614 * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
8615 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
8616 * @return {Object} box An object in the format {x, y, width, height}
8618 getBox : function(contentBox, local){
8623 var left = parseInt(this.getStyle("left"), 10) || 0;
8624 var top = parseInt(this.getStyle("top"), 10) || 0;
8627 var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
8629 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
8631 var l = this.getBorderWidth("l")+this.getPadding("l");
8632 var r = this.getBorderWidth("r")+this.getPadding("r");
8633 var t = this.getBorderWidth("t")+this.getPadding("t");
8634 var b = this.getBorderWidth("b")+this.getPadding("b");
8635 bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)};
8637 bx.right = bx.x + bx.width;
8638 bx.bottom = bx.y + bx.height;
8643 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
8644 for more information about the sides.
8645 * @param {String} sides
8648 getFrameWidth : function(sides, onlyContentBox){
8649 return onlyContentBox && Roo.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
8653 * Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently.
8654 * @param {Object} box The box to fill {x, y, width, height}
8655 * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
8656 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8657 * @return {Roo.Element} this
8659 setBox : function(box, adjust, animate){
8660 var w = box.width, h = box.height;
8661 if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){
8662 w -= (this.getBorderWidth("lr") + this.getPadding("lr"));
8663 h -= (this.getBorderWidth("tb") + this.getPadding("tb"));
8665 this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2));
8670 * Forces the browser to repaint this element
8671 * @return {Roo.Element} this
8673 repaint : function(){
8675 this.addClass("x-repaint");
8676 setTimeout(function(){
8677 Roo.get(dom).removeClass("x-repaint");
8683 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
8684 * then it returns the calculated width of the sides (see getPadding)
8685 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
8686 * @return {Object/Number}
8688 getMargins : function(side){
8691 top: parseInt(this.getStyle("margin-top"), 10) || 0,
8692 left: parseInt(this.getStyle("margin-left"), 10) || 0,
8693 bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0,
8694 right: parseInt(this.getStyle("margin-right"), 10) || 0
8697 return this.addStyles(side, El.margins);
8702 addStyles : function(sides, styles){
8704 for(var i = 0, len = sides.length; i < len; i++){
8705 v = this.getStyle(styles[sides.charAt(i)]);
8707 w = parseInt(v, 10);
8715 * Creates a proxy element of this element
8716 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
8717 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
8718 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
8719 * @return {Roo.Element} The new proxy element
8721 createProxy : function(config, renderTo, matchBox){
8723 renderTo = Roo.getDom(renderTo);
8725 renderTo = document.body;
8727 config = typeof config == "object" ?
8728 config : {tag : "div", cls: config};
8729 var proxy = Roo.DomHelper.append(renderTo, config, true);
8731 proxy.setBox(this.getBox());
8737 * Puts a mask over this element to disable user interaction. Requires core.css.
8738 * This method can only be applied to elements which accept child nodes.
8739 * @param {String} msg (optional) A message to display in the mask
8740 * @param {String} msgCls (optional) A css class to apply to the msg element
8741 * @return {Element} The mask element
8743 mask : function(msg, msgCls){
8744 if(this.getStyle("position") == "static"){
8745 this.setStyle("position", "relative");
8748 this._mask = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask"}, true);
8750 this.addClass("x-masked");
8751 this._mask.setDisplayed(true);
8752 if(typeof msg == 'string'){
8754 this._maskMsg = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask-msg", cn:{tag:'div'}}, true);
8756 var mm = this._maskMsg;
8757 mm.dom.className = msgCls ? "roo-el-mask-msg " + msgCls : "roo-el-mask-msg";
8758 mm.dom.firstChild.innerHTML = msg;
8759 mm.setDisplayed(true);
8762 if(Roo.isIE && !(Roo.isIE7 && Roo.isStrict) && this.getStyle('height') == 'auto'){ // ie will not expand full height automatically
8763 this._mask.setHeight(this.getHeight());
8769 * Removes a previously applied mask. If removeEl is true the mask overlay is destroyed, otherwise
8770 * it is cached for reuse.
8772 unmask : function(removeEl){
8774 if(removeEl === true){
8775 this._mask.remove();
8778 this._maskMsg.remove();
8779 delete this._maskMsg;
8782 this._mask.setDisplayed(false);
8784 this._maskMsg.setDisplayed(false);
8788 this.removeClass("x-masked");
8792 * Returns true if this element is masked
8795 isMasked : function(){
8796 return this._mask && this._mask.isVisible();
8800 * Creates an iframe shim for this element to keep selects and other windowed objects from
8802 * @return {Roo.Element} The new shim element
8804 createShim : function(){
8805 var el = document.createElement('iframe');
8806 el.frameBorder = 'no';
8807 el.className = 'roo-shim';
8808 if(Roo.isIE && Roo.isSecure){
8809 el.src = Roo.SSL_SECURE_URL;
8811 var shim = Roo.get(this.dom.parentNode.insertBefore(el, this.dom));
8812 shim.autoBoxAdjust = false;
8817 * Removes this element from the DOM and deletes it from the cache
8819 remove : function(){
8820 if(this.dom.parentNode){
8821 this.dom.parentNode.removeChild(this.dom);
8823 delete El.cache[this.dom.id];
8827 * Sets up event handlers to add and remove a css class when the mouse is over this element
8828 * @param {String} className
8829 * @param {Boolean} preventFlicker (optional) If set to true, it prevents flickering by filtering
8830 * mouseout events for children elements
8831 * @return {Roo.Element} this
8833 addClassOnOver : function(className, preventFlicker){
8834 this.on("mouseover", function(){
8835 Roo.fly(this, '_internal').addClass(className);
8837 var removeFn = function(e){
8838 if(preventFlicker !== true || !e.within(this, true)){
8839 Roo.fly(this, '_internal').removeClass(className);
8842 this.on("mouseout", removeFn, this.dom);
8847 * Sets up event handlers to add and remove a css class when this element has the focus
8848 * @param {String} className
8849 * @return {Roo.Element} this
8851 addClassOnFocus : function(className){
8852 this.on("focus", function(){
8853 Roo.fly(this, '_internal').addClass(className);
8855 this.on("blur", function(){
8856 Roo.fly(this, '_internal').removeClass(className);
8861 * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
8862 * @param {String} className
8863 * @return {Roo.Element} this
8865 addClassOnClick : function(className){
8867 this.on("mousedown", function(){
8868 Roo.fly(dom, '_internal').addClass(className);
8869 var d = Roo.get(document);
8870 var fn = function(){
8871 Roo.fly(dom, '_internal').removeClass(className);
8872 d.removeListener("mouseup", fn);
8874 d.on("mouseup", fn);
8880 * Stops the specified event from bubbling and optionally prevents the default action
8881 * @param {String} eventName
8882 * @param {Boolean} preventDefault (optional) true to prevent the default action too
8883 * @return {Roo.Element} this
8885 swallowEvent : function(eventName, preventDefault){
8886 var fn = function(e){
8887 e.stopPropagation();
8892 if(eventName instanceof Array){
8893 for(var i = 0, len = eventName.length; i < len; i++){
8894 this.on(eventName[i], fn);
8898 this.on(eventName, fn);
8905 fitToParentDelegate : Roo.emptyFn, // keep a reference to the fitToParent delegate
8908 * Sizes this element to its parent element's dimensions performing
8909 * neccessary box adjustments.
8910 * @param {Boolean} monitorResize (optional) If true maintains the fit when the browser window is resized.
8911 * @param {String/HTMLElment/Element} targetParent (optional) The target parent, default to the parentNode.
8912 * @return {Roo.Element} this
8914 fitToParent : function(monitorResize, targetParent) {
8915 Roo.EventManager.removeResizeListener(this.fitToParentDelegate); // always remove previous fitToParent delegate from onWindowResize
8916 this.fitToParentDelegate = Roo.emptyFn; // remove reference to previous delegate
8917 if (monitorResize === true && !this.dom.parentNode) { // check if this Element still exists
8920 var p = Roo.get(targetParent || this.dom.parentNode);
8921 this.setSize(p.getComputedWidth() - p.getFrameWidth('lr'), p.getComputedHeight() - p.getFrameWidth('tb'));
8922 if (monitorResize === true) {
8923 this.fitToParentDelegate = this.fitToParent.createDelegate(this, [true, targetParent]);
8924 Roo.EventManager.onWindowResize(this.fitToParentDelegate);
8930 * Gets the next sibling, skipping text nodes
8931 * @return {HTMLElement} The next sibling or null
8933 getNextSibling : function(){
8934 var n = this.dom.nextSibling;
8935 while(n && n.nodeType != 1){
8942 * Gets the previous sibling, skipping text nodes
8943 * @return {HTMLElement} The previous sibling or null
8945 getPrevSibling : function(){
8946 var n = this.dom.previousSibling;
8947 while(n && n.nodeType != 1){
8948 n = n.previousSibling;
8955 * Appends the passed element(s) to this element
8956 * @param {String/HTMLElement/Array/Element/CompositeElement} el
8957 * @return {Roo.Element} this
8959 appendChild: function(el){
8966 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
8967 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
8968 * automatically generated with the specified attributes.
8969 * @param {HTMLElement} insertBefore (optional) a child element of this element
8970 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
8971 * @return {Roo.Element} The new child element
8973 createChild: function(config, insertBefore, returnDom){
8974 config = config || {tag:'div'};
8976 return Roo.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
8978 return Roo.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
8982 * Appends this element to the passed element
8983 * @param {String/HTMLElement/Element} el The new parent element
8984 * @return {Roo.Element} this
8986 appendTo: function(el){
8987 el = Roo.getDom(el);
8988 el.appendChild(this.dom);
8993 * Inserts this element before the passed element in the DOM
8994 * @param {String/HTMLElement/Element} el The element to insert before
8995 * @return {Roo.Element} this
8997 insertBefore: function(el){
8998 el = Roo.getDom(el);
8999 el.parentNode.insertBefore(this.dom, el);
9004 * Inserts this element after the passed element in the DOM
9005 * @param {String/HTMLElement/Element} el The element to insert after
9006 * @return {Roo.Element} this
9008 insertAfter: function(el){
9009 el = Roo.getDom(el);
9010 el.parentNode.insertBefore(this.dom, el.nextSibling);
9015 * Inserts (or creates) an element (or DomHelper config) as the first child of the this element
9016 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9017 * @return {Roo.Element} The new child
9019 insertFirst: function(el, returnDom){
9021 if(typeof el == 'object' && !el.nodeType){ // dh config
9022 return this.createChild(el, this.dom.firstChild, returnDom);
9024 el = Roo.getDom(el);
9025 this.dom.insertBefore(el, this.dom.firstChild);
9026 return !returnDom ? Roo.get(el) : el;
9031 * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
9032 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9033 * @param {String} where (optional) 'before' or 'after' defaults to before
9034 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9035 * @return {Roo.Element} the inserted Element
9037 insertSibling: function(el, where, returnDom){
9038 where = where ? where.toLowerCase() : 'before';
9040 var rt, refNode = where == 'before' ? this.dom : this.dom.nextSibling;
9042 if(typeof el == 'object' && !el.nodeType){ // dh config
9043 if(where == 'after' && !this.dom.nextSibling){
9044 rt = Roo.DomHelper.append(this.dom.parentNode, el, !returnDom);
9046 rt = Roo.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom);
9050 rt = this.dom.parentNode.insertBefore(Roo.getDom(el),
9051 where == 'before' ? this.dom : this.dom.nextSibling);
9060 * Creates and wraps this element with another element
9061 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
9062 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9063 * @return {HTMLElement/Element} The newly created wrapper element
9065 wrap: function(config, returnDom){
9067 config = {tag: "div"};
9069 var newEl = Roo.DomHelper.insertBefore(this.dom, config, !returnDom);
9070 newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
9075 * Replaces the passed element with this element
9076 * @param {String/HTMLElement/Element} el The element to replace
9077 * @return {Roo.Element} this
9079 replace: function(el){
9081 this.insertBefore(el);
9087 * Inserts an html fragment into this element
9088 * @param {String} where Where to insert the html in relation to the this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
9089 * @param {String} html The HTML fragment
9090 * @param {Boolean} returnEl True to return an Roo.Element
9091 * @return {HTMLElement/Roo.Element} The inserted node (or nearest related if more than 1 inserted)
9093 insertHtml : function(where, html, returnEl){
9094 var el = Roo.DomHelper.insertHtml(where, this.dom, html);
9095 return returnEl ? Roo.get(el) : el;
9099 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
9100 * @param {Object} o The object with the attributes
9101 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
9102 * @return {Roo.Element} this
9104 set : function(o, useSet){
9106 useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet;
9108 if(attr == "style" || typeof o[attr] == "function") continue;
9110 el.className = o["cls"];
9112 if(useSet) el.setAttribute(attr, o[attr]);
9113 else el[attr] = o[attr];
9117 Roo.DomHelper.applyStyles(el, o.style);
9123 * Convenience method for constructing a KeyMap
9124 * @param {Number/Array/Object/String} key Either a string with the keys to listen for, the numeric key code, array of key codes or an object with the following options:
9125 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9126 * @param {Function} fn The function to call
9127 * @param {Object} scope (optional) The scope of the function
9128 * @return {Roo.KeyMap} The KeyMap created
9130 addKeyListener : function(key, fn, scope){
9132 if(typeof key != "object" || key instanceof Array){
9148 return new Roo.KeyMap(this, config);
9152 * Creates a KeyMap for this element
9153 * @param {Object} config The KeyMap config. See {@link Roo.KeyMap} for more details
9154 * @return {Roo.KeyMap} The KeyMap created
9156 addKeyMap : function(config){
9157 return new Roo.KeyMap(this, config);
9161 * Returns true if this element is scrollable.
9164 isScrollable : function(){
9166 return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
9170 * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
9171 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
9172 * @param {Number} value The new scroll value
9173 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9174 * @return {Element} this
9177 scrollTo : function(side, value, animate){
9178 var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop";
9180 this.dom[prop] = value;
9182 var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value];
9183 this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
9189 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
9190 * within this element's scrollable range.
9191 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
9192 * @param {Number} distance How far to scroll the element in pixels
9193 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9194 * @return {Boolean} Returns true if a scroll was triggered or false if the element
9195 * was scrolled as far as it could go.
9197 scroll : function(direction, distance, animate){
9198 if(!this.isScrollable()){
9202 var l = el.scrollLeft, t = el.scrollTop;
9203 var w = el.scrollWidth, h = el.scrollHeight;
9204 var cw = el.clientWidth, ch = el.clientHeight;
9205 direction = direction.toLowerCase();
9206 var scrolled = false;
9207 var a = this.preanim(arguments, 2);
9212 var v = Math.min(l + distance, w-cw);
9213 this.scrollTo("left", v, a);
9220 var v = Math.max(l - distance, 0);
9221 this.scrollTo("left", v, a);
9229 var v = Math.max(t - distance, 0);
9230 this.scrollTo("top", v, a);
9238 var v = Math.min(t + distance, h-ch);
9239 this.scrollTo("top", v, a);
9248 * Translates the passed page coordinates into left/top css values for this element
9249 * @param {Number/Array} x The page x or an array containing [x, y]
9250 * @param {Number} y The page y
9251 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
9253 translatePoints : function(x, y){
9254 if(typeof x == 'object' || x instanceof Array){
9257 var p = this.getStyle('position');
9258 var o = this.getXY();
9260 var l = parseInt(this.getStyle('left'), 10);
9261 var t = parseInt(this.getStyle('top'), 10);
9264 l = (p == "relative") ? 0 : this.dom.offsetLeft;
9267 t = (p == "relative") ? 0 : this.dom.offsetTop;
9270 return {left: (x - o[0] + l), top: (y - o[1] + t)};
9274 * Returns the current scroll position of the element.
9275 * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
9277 getScroll : function(){
9278 var d = this.dom, doc = document;
9279 if(d == doc || d == doc.body){
9280 var l = window.pageXOffset || doc.documentElement.scrollLeft || doc.body.scrollLeft || 0;
9281 var t = window.pageYOffset || doc.documentElement.scrollTop || doc.body.scrollTop || 0;
9282 return {left: l, top: t};
9284 return {left: d.scrollLeft, top: d.scrollTop};
9289 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
9290 * are convert to standard 6 digit hex color.
9291 * @param {String} attr The css attribute
9292 * @param {String} defaultValue The default value to use when a valid color isn't found
9293 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
9296 getColor : function(attr, defaultValue, prefix){
9297 var v = this.getStyle(attr);
9298 if(!v || v == "transparent" || v == "inherit") {
9299 return defaultValue;
9301 var color = typeof prefix == "undefined" ? "#" : prefix;
9302 if(v.substr(0, 4) == "rgb("){
9303 var rvs = v.slice(4, v.length -1).split(",");
9304 for(var i = 0; i < 3; i++){
9305 var h = parseInt(rvs[i]).toString(16);
9312 if(v.substr(0, 1) == "#"){
9314 for(var i = 1; i < 4; i++){
9315 var c = v.charAt(i);
9318 }else if(v.length == 7){
9319 color += v.substr(1);
9323 return(color.length > 5 ? color.toLowerCase() : defaultValue);
9327 * Wraps the specified element with a special markup/CSS block that renders by default as a gray container with a
9328 * gradient background, rounded corners and a 4-way shadow.
9329 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element (defaults to 'x-box').
9330 * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
9331 * so if you supply an alternate base class, make sure you also supply all of the necessary rules.
9332 * @return {Roo.Element} this
9334 boxWrap : function(cls){
9335 cls = cls || 'x-box';
9336 var el = Roo.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', cls)));
9337 el.child('.'+cls+'-mc').dom.appendChild(this.dom);
9342 * Returns the value of a namespaced attribute from the element's underlying DOM node.
9343 * @param {String} namespace The namespace in which to look for the attribute
9344 * @param {String} name The attribute name
9345 * @return {String} The attribute value
9347 getAttributeNS : Roo.isIE ? function(ns, name){
9349 var type = typeof d[ns+":"+name];
9350 if(type != 'undefined' && type != 'unknown'){
9351 return d[ns+":"+name];
9354 } : function(ns, name){
9356 return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
9360 var ep = El.prototype;
9363 * Appends an event handler (Shorthand for addListener)
9364 * @param {String} eventName The type of event to append
9365 * @param {Function} fn The method the event invokes
9366 * @param {Object} scope (optional) The scope (this object) of the fn
9367 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
9370 ep.on = ep.addListener;
9372 ep.mon = ep.addListener;
9375 * Removes an event handler from this element (shorthand for removeListener)
9376 * @param {String} eventName the type of event to remove
9377 * @param {Function} fn the method the event invokes
9378 * @return {Roo.Element} this
9381 ep.un = ep.removeListener;
9384 * true to automatically adjust width and height settings for box-model issues (default to true)
9386 ep.autoBoxAdjust = true;
9389 El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;
9392 El.addUnits = function(v, defaultUnit){
9393 if(v === "" || v == "auto"){
9396 if(v === undefined){
9399 if(typeof v == "number" || !El.unitPattern.test(v)){
9400 return v + (defaultUnit || 'px');
9405 // special markup used throughout Roo when box wrapping elements
9406 El.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
9408 * Visibility mode constant - Use visibility to hide element
9414 * Visibility mode constant - Use display to hide element
9420 El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
9421 El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
9422 El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
9434 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9435 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9436 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9437 * @return {Element} The Element object
9440 El.get = function(el){
9442 if(!el){ return null; }
9443 if(typeof el == "string"){ // element id
9444 if(!(elm = document.getElementById(el))){
9447 if(ex = El.cache[el]){
9450 ex = El.cache[el] = new El(elm);
9453 }else if(el.tagName){ // dom element
9457 if(ex = El.cache[id]){
9460 ex = El.cache[id] = new El(el);
9463 }else if(el instanceof El){
9465 el.dom = document.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
9466 // catch case where it hasn't been appended
9467 El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
9470 }else if(el.isComposite){
9472 }else if(el instanceof Array){
9473 return El.select(el);
9474 }else if(el == document){
9475 // create a bogus element object representing the document object
9477 var f = function(){};
9478 f.prototype = El.prototype;
9480 docEl.dom = document;
9488 El.uncache = function(el){
9489 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
9491 delete El.cache[a[i].id || a[i]];
9497 // Garbage collection - uncache elements/purge listeners on orphaned elements
9498 // so we don't hold a reference and cause the browser to retain them
9499 El.garbageCollect = function(){
9500 if(!Roo.enableGarbageCollector){
9501 clearInterval(El.collectorThread);
9504 for(var eid in El.cache){
9505 var el = El.cache[eid], d = el.dom;
9506 // -------------------------------------------------------
9507 // Determining what is garbage:
9508 // -------------------------------------------------------
9510 // dom node is null, definitely garbage
9511 // -------------------------------------------------------
9513 // no parentNode == direct orphan, definitely garbage
9514 // -------------------------------------------------------
9515 // !d.offsetParent && !document.getElementById(eid)
9516 // display none elements have no offsetParent so we will
9517 // also try to look it up by it's id. However, check
9518 // offsetParent first so we don't do unneeded lookups.
9519 // This enables collection of elements that are not orphans
9520 // directly, but somewhere up the line they have an orphan
9522 // -------------------------------------------------------
9523 if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){
9524 delete El.cache[eid];
9525 if(d && Roo.enableListenerCollection){
9531 El.collectorThreadId = setInterval(El.garbageCollect, 30000);
9535 El.Flyweight = function(dom){
9538 El.Flyweight.prototype = El.prototype;
9540 El._flyweights = {};
9542 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9543 * the dom node can be overwritten by other code.
9544 * @param {String/HTMLElement} el The dom node or id
9545 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9546 * prevent conflicts (e.g. internally Roo uses "_internal")
9548 * @return {Element} The shared Element object
9550 El.fly = function(el, named){
9551 named = named || '_global';
9552 el = Roo.getDom(el);
9556 if(!El._flyweights[named]){
9557 El._flyweights[named] = new El.Flyweight();
9559 El._flyweights[named].dom = el;
9560 return El._flyweights[named];
9564 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9565 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9566 * Shorthand of {@link Roo.Element#get}
9567 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9568 * @return {Element} The Element object
9574 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9575 * the dom node can be overwritten by other code.
9576 * Shorthand of {@link Roo.Element#fly}
9577 * @param {String/HTMLElement} el The dom node or id
9578 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9579 * prevent conflicts (e.g. internally Roo uses "_internal")
9581 * @return {Element} The shared Element object
9587 // speedy lookup for elements never to box adjust
9588 var noBoxAdjust = Roo.isStrict ? {
9591 input:1, select:1, textarea:1
9593 if(Roo.isIE || Roo.isGecko){
9594 noBoxAdjust['button'] = 1;
9598 Roo.EventManager.on(window, 'unload', function(){
9600 delete El._flyweights;
9608 Roo.Element.selectorFunction = Roo.DomQuery.select;
9611 Roo.Element.select = function(selector, unique, root){
9613 if(typeof selector == "string"){
9614 els = Roo.Element.selectorFunction(selector, root);
9615 }else if(selector.length !== undefined){
9618 throw "Invalid selector";
9620 if(unique === true){
9621 return new Roo.CompositeElement(els);
9623 return new Roo.CompositeElementLite(els);
9627 * Selects elements based on the passed CSS selector to enable working on them as 1.
9628 * @param {String/Array} selector The CSS selector or an array of elements
9629 * @param {Boolean} unique (optional) true to create a unique Roo.Element for each element (defaults to a shared flyweight object)
9630 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
9631 * @return {CompositeElementLite/CompositeElement}
9635 Roo.select = Roo.Element.select;
9652 * Ext JS Library 1.1.1
9653 * Copyright(c) 2006-2007, Ext JS, LLC.
9655 * Originally Released Under LGPL - original licence link has changed is not relivant.
9658 * <script type="text/javascript">
9663 //Notifies Element that fx methods are available
9664 Roo.enableFx = true;
9668 * <p>A class to provide basic animation and visual effects support. <b>Note:</b> This class is automatically applied
9669 * to the {@link Roo.Element} interface when included, so all effects calls should be performed via Element.
9670 * Conversely, since the effects are not actually defined in Element, Roo.Fx <b>must</b> be included in order for the
9671 * Element effects to work.</p><br/>
9673 * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that
9674 * they return the Element object itself as the method return value, it is not always possible to mix the two in a single
9675 * method chain. The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced.
9676 * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately. For this reason,
9677 * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the
9678 * expected results and should be done with care.</p><br/>
9680 * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element
9681 * that will serve as either the start or end point of the animation. Following are all of the supported anchor positions:</p>
9684 ----- -----------------------------
9685 tl The top left corner
9686 t The center of the top edge
9687 tr The top right corner
9688 l The center of the left edge
9689 r The center of the right edge
9690 bl The bottom left corner
9691 b The center of the bottom edge
9692 br The bottom right corner
9694 * <b>Although some Fx methods accept specific custom config parameters, the ones shown in the Config Options section
9695 * below are common options that can be passed to any Fx method.</b>
9696 * @cfg {Function} callback A function called when the effect is finished
9697 * @cfg {Object} scope The scope of the effect function
9698 * @cfg {String} easing A valid Easing value for the effect
9699 * @cfg {String} afterCls A css class to apply after the effect
9700 * @cfg {Number} duration The length of time (in seconds) that the effect should last
9701 * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes
9702 * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to
9703 * effects that end with the element being visually hidden, ignored otherwise)
9704 * @cfg {String/Object/Function} afterStyle A style specification string, e.g. "width:100px", or an object in the form {width:"100px"}, or
9705 * a function which returns such a specification that will be applied to the Element after the effect finishes
9706 * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs
9707 * @cfg {Boolean} concurrent Whether to allow subsequently-queued effects to run at the same time as the current effect, or to ensure that they run in sequence
9708 * @cfg {Boolean} stopFx Whether subsequent effects should be stopped and removed after the current effect finishes
9712 * Slides the element into view. An anchor point can be optionally passed to set the point of
9713 * origin for the slide effect. This function automatically handles wrapping the element with
9714 * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
9717 // default: slide the element in from the top
9720 // custom: slide the element in from the right with a 2-second duration
9721 el.slideIn('r', { duration: 2 });
9723 // common config options shown with default values
9729 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
9730 * @param {Object} options (optional) Object literal with any of the Fx config options
9731 * @return {Roo.Element} The Element
9733 slideIn : function(anchor, o){
9734 var el = this.getFxEl();
9737 el.queueFx(o, function(){
9739 anchor = anchor || "t";
9741 // fix display to visibility
9744 // restore values after effect
9745 var r = this.getFxRestore();
9746 var b = this.getBox();
9747 // fixed size for slide
9751 var wrap = this.fxWrap(r.pos, o, "hidden");
9753 var st = this.dom.style;
9754 st.visibility = "visible";
9755 st.position = "absolute";
9757 // clear out temp styles after slide and unwrap
9758 var after = function(){
9759 el.fxUnwrap(wrap, r.pos, o);
9761 st.height = r.height;
9764 // time to calc the positions
9765 var a, pt = {to: [b.x, b.y]}, bw = {to: b.width}, bh = {to: b.height};
9767 switch(anchor.toLowerCase()){
9769 wrap.setSize(b.width, 0);
9770 st.left = st.bottom = "0";
9774 wrap.setSize(0, b.height);
9775 st.right = st.top = "0";
9779 wrap.setSize(0, b.height);
9781 st.left = st.top = "0";
9782 a = {width: bw, points: pt};
9785 wrap.setSize(b.width, 0);
9786 wrap.setY(b.bottom);
9787 st.left = st.top = "0";
9788 a = {height: bh, points: pt};
9792 st.right = st.bottom = "0";
9793 a = {width: bw, height: bh};
9797 wrap.setY(b.y+b.height);
9798 st.right = st.top = "0";
9799 a = {width: bw, height: bh, points: pt};
9803 wrap.setXY([b.right, b.bottom]);
9804 st.left = st.top = "0";
9805 a = {width: bw, height: bh, points: pt};
9809 wrap.setX(b.x+b.width);
9810 st.left = st.bottom = "0";
9811 a = {width: bw, height: bh, points: pt};
9814 this.dom.style.visibility = "visible";
9817 arguments.callee.anim = wrap.fxanim(a,
9827 * Slides the element out of view. An anchor point can be optionally passed to set the end point
9828 * for the slide effect. When the effect is completed, the element will be hidden (visibility =
9829 * 'hidden') but block elements will still take up space in the document. The element must be removed
9830 * from the DOM using the 'remove' config option if desired. This function automatically handles
9831 * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
9834 // default: slide the element out to the top
9837 // custom: slide the element out to the right with a 2-second duration
9838 el.slideOut('r', { duration: 2 });
9840 // common config options shown with default values
9848 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
9849 * @param {Object} options (optional) Object literal with any of the Fx config options
9850 * @return {Roo.Element} The Element
9852 slideOut : function(anchor, o){
9853 var el = this.getFxEl();
9856 el.queueFx(o, function(){
9858 anchor = anchor || "t";
9860 // restore values after effect
9861 var r = this.getFxRestore();
9863 var b = this.getBox();
9864 // fixed size for slide
9868 var wrap = this.fxWrap(r.pos, o, "visible");
9870 var st = this.dom.style;
9871 st.visibility = "visible";
9872 st.position = "absolute";
9876 var after = function(){
9878 el.setDisplayed(false);
9883 el.fxUnwrap(wrap, r.pos, o);
9886 st.height = r.height;
9891 var a, zero = {to: 0};
9892 switch(anchor.toLowerCase()){
9894 st.left = st.bottom = "0";
9898 st.right = st.top = "0";
9902 st.left = st.top = "0";
9903 a = {width: zero, points: {to:[b.right, b.y]}};
9906 st.left = st.top = "0";
9907 a = {height: zero, points: {to:[b.x, b.bottom]}};
9910 st.right = st.bottom = "0";
9911 a = {width: zero, height: zero};
9914 st.right = st.top = "0";
9915 a = {width: zero, height: zero, points: {to:[b.x, b.bottom]}};
9918 st.left = st.top = "0";
9919 a = {width: zero, height: zero, points: {to:[b.x+b.width, b.bottom]}};
9922 st.left = st.bottom = "0";
9923 a = {width: zero, height: zero, points: {to:[b.right, b.y]}};
9927 arguments.callee.anim = wrap.fxanim(a,
9937 * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
9938 * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
9939 * The element must be removed from the DOM using the 'remove' config option if desired.
9945 // common config options shown with default values
9953 * @param {Object} options (optional) Object literal with any of the Fx config options
9954 * @return {Roo.Element} The Element
9957 var el = this.getFxEl();
9960 el.queueFx(o, function(){
9961 this.clearOpacity();
9964 // restore values after effect
9965 var r = this.getFxRestore();
9966 var st = this.dom.style;
9968 var after = function(){
9970 el.setDisplayed(false);
9977 el.setPositioning(r.pos);
9979 st.height = r.height;
9984 var width = this.getWidth();
9985 var height = this.getHeight();
9987 arguments.callee.anim = this.fxanim({
9988 width : {to: this.adjustWidth(width * 2)},
9989 height : {to: this.adjustHeight(height * 2)},
9990 points : {by: [-(width * .5), -(height * .5)]},
9992 fontSize: {to:200, unit: "%"}
10003 * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
10004 * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
10005 * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
10011 // all config options shown with default values
10019 * @param {Object} options (optional) Object literal with any of the Fx config options
10020 * @return {Roo.Element} The Element
10022 switchOff : function(o){
10023 var el = this.getFxEl();
10026 el.queueFx(o, function(){
10027 this.clearOpacity();
10030 // restore values after effect
10031 var r = this.getFxRestore();
10032 var st = this.dom.style;
10034 var after = function(){
10036 el.setDisplayed(false);
10042 el.setPositioning(r.pos);
10043 st.width = r.width;
10044 st.height = r.height;
10049 this.fxanim({opacity:{to:0.3}}, null, null, .1, null, function(){
10050 this.clearOpacity();
10054 points:{by:[0, this.getHeight() * .5]}
10055 }, o, 'motion', 0.3, 'easeIn', after);
10056 }).defer(100, this);
10063 * Highlights the Element by setting a color (applies to the background-color by default, but can be
10064 * changed using the "attr" config option) and then fading back to the original color. If no original
10065 * color is available, you should provide the "endColor" config option which will be cleared after the animation.
10068 // default: highlight background to yellow
10071 // custom: highlight foreground text to blue for 2 seconds
10072 el.highlight("0000ff", { attr: 'color', duration: 2 });
10074 // common config options shown with default values
10075 el.highlight("ffff9c", {
10076 attr: "background-color", //can be any valid CSS property (attribute) that supports a color value
10077 endColor: (current color) or "ffffff",
10082 * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
10083 * @param {Object} options (optional) Object literal with any of the Fx config options
10084 * @return {Roo.Element} The Element
10086 highlight : function(color, o){
10087 var el = this.getFxEl();
10090 el.queueFx(o, function(){
10091 color = color || "ffff9c";
10092 attr = o.attr || "backgroundColor";
10094 this.clearOpacity();
10097 var origColor = this.getColor(attr);
10098 var restoreColor = this.dom.style[attr];
10099 endColor = (o.endColor || origColor) || "ffffff";
10101 var after = function(){
10102 el.dom.style[attr] = restoreColor;
10107 a[attr] = {from: color, to: endColor};
10108 arguments.callee.anim = this.fxanim(a,
10118 * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
10121 // default: a single light blue ripple
10124 // custom: 3 red ripples lasting 3 seconds total
10125 el.frame("ff0000", 3, { duration: 3 });
10127 // common config options shown with default values
10128 el.frame("C3DAF9", 1, {
10129 duration: 1 //duration of entire animation (not each individual ripple)
10130 // Note: Easing is not configurable and will be ignored if included
10133 * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
10134 * @param {Number} count (optional) The number of ripples to display (defaults to 1)
10135 * @param {Object} options (optional) Object literal with any of the Fx config options
10136 * @return {Roo.Element} The Element
10138 frame : function(color, count, o){
10139 var el = this.getFxEl();
10142 el.queueFx(o, function(){
10143 color = color || "#C3DAF9";
10144 if(color.length == 6){
10145 color = "#" + color;
10147 count = count || 1;
10148 duration = o.duration || 1;
10151 var b = this.getBox();
10152 var animFn = function(){
10153 var proxy = this.createProxy({
10156 visbility:"hidden",
10157 position:"absolute",
10158 "z-index":"35000", // yee haw
10159 border:"0px solid " + color
10162 var scale = Roo.isBorderBox ? 2 : 1;
10164 top:{from:b.y, to:b.y - 20},
10165 left:{from:b.x, to:b.x - 20},
10166 borderWidth:{from:0, to:10},
10167 opacity:{from:1, to:0},
10168 height:{from:b.height, to:(b.height + (20*scale))},
10169 width:{from:b.width, to:(b.width + (20*scale))}
10170 }, duration, function(){
10174 animFn.defer((duration/2)*1000, this);
10185 * Creates a pause before any subsequent queued effects begin. If there are
10186 * no effects queued after the pause it will have no effect.
10191 * @param {Number} seconds The length of time to pause (in seconds)
10192 * @return {Roo.Element} The Element
10194 pause : function(seconds){
10195 var el = this.getFxEl();
10198 el.queueFx(o, function(){
10199 setTimeout(function(){
10201 }, seconds * 1000);
10207 * Fade an element in (from transparent to opaque). The ending opacity can be specified
10208 * using the "endOpacity" config option.
10211 // default: fade in from opacity 0 to 100%
10214 // custom: fade in from opacity 0 to 75% over 2 seconds
10215 el.fadeIn({ endOpacity: .75, duration: 2});
10217 // common config options shown with default values
10219 endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
10224 * @param {Object} options (optional) Object literal with any of the Fx config options
10225 * @return {Roo.Element} The Element
10227 fadeIn : function(o){
10228 var el = this.getFxEl();
10230 el.queueFx(o, function(){
10231 this.setOpacity(0);
10233 this.dom.style.visibility = 'visible';
10234 var to = o.endOpacity || 1;
10235 arguments.callee.anim = this.fxanim({opacity:{to:to}},
10236 o, null, .5, "easeOut", function(){
10238 this.clearOpacity();
10247 * Fade an element out (from opaque to transparent). The ending opacity can be specified
10248 * using the "endOpacity" config option.
10251 // default: fade out from the element's current opacity to 0
10254 // custom: fade out from the element's current opacity to 25% over 2 seconds
10255 el.fadeOut({ endOpacity: .25, duration: 2});
10257 // common config options shown with default values
10259 endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
10266 * @param {Object} options (optional) Object literal with any of the Fx config options
10267 * @return {Roo.Element} The Element
10269 fadeOut : function(o){
10270 var el = this.getFxEl();
10272 el.queueFx(o, function(){
10273 arguments.callee.anim = this.fxanim({opacity:{to:o.endOpacity || 0}},
10274 o, null, .5, "easeOut", function(){
10275 if(this.visibilityMode == Roo.Element.DISPLAY || o.useDisplay){
10276 this.dom.style.display = "none";
10278 this.dom.style.visibility = "hidden";
10280 this.clearOpacity();
10288 * Animates the transition of an element's dimensions from a starting height/width
10289 * to an ending height/width.
10292 // change height and width to 100x100 pixels
10293 el.scale(100, 100);
10295 // common config options shown with default values. The height and width will default to
10296 // the element's existing values if passed as null.
10299 [element's height], {
10304 * @param {Number} width The new width (pass undefined to keep the original width)
10305 * @param {Number} height The new height (pass undefined to keep the original height)
10306 * @param {Object} options (optional) Object literal with any of the Fx config options
10307 * @return {Roo.Element} The Element
10309 scale : function(w, h, o){
10310 this.shift(Roo.apply({}, o, {
10318 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
10319 * Any of these properties not specified in the config object will not be changed. This effect
10320 * requires that at least one new dimension, position or opacity setting must be passed in on
10321 * the config object in order for the function to have any effect.
10324 // slide the element horizontally to x position 200 while changing the height and opacity
10325 el.shift({ x: 200, height: 50, opacity: .8 });
10327 // common config options shown with default values.
10329 width: [element's width],
10330 height: [element's height],
10331 x: [element's x position],
10332 y: [element's y position],
10333 opacity: [element's opacity],
10338 * @param {Object} options Object literal with any of the Fx config options
10339 * @return {Roo.Element} The Element
10341 shift : function(o){
10342 var el = this.getFxEl();
10344 el.queueFx(o, function(){
10345 var a = {}, w = o.width, h = o.height, x = o.x, y = o.y, op = o.opacity;
10346 if(w !== undefined){
10347 a.width = {to: this.adjustWidth(w)};
10349 if(h !== undefined){
10350 a.height = {to: this.adjustHeight(h)};
10352 if(x !== undefined || y !== undefined){
10354 x !== undefined ? x : this.getX(),
10355 y !== undefined ? y : this.getY()
10358 if(op !== undefined){
10359 a.opacity = {to: op};
10361 if(o.xy !== undefined){
10362 a.points = {to: o.xy};
10364 arguments.callee.anim = this.fxanim(a,
10365 o, 'motion', .35, "easeOut", function(){
10373 * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
10374 * ending point of the effect.
10377 // default: slide the element downward while fading out
10380 // custom: slide the element out to the right with a 2-second duration
10381 el.ghost('r', { duration: 2 });
10383 // common config options shown with default values
10391 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
10392 * @param {Object} options (optional) Object literal with any of the Fx config options
10393 * @return {Roo.Element} The Element
10395 ghost : function(anchor, o){
10396 var el = this.getFxEl();
10399 el.queueFx(o, function(){
10400 anchor = anchor || "b";
10402 // restore values after effect
10403 var r = this.getFxRestore();
10404 var w = this.getWidth(),
10405 h = this.getHeight();
10407 var st = this.dom.style;
10409 var after = function(){
10411 el.setDisplayed(false);
10417 el.setPositioning(r.pos);
10418 st.width = r.width;
10419 st.height = r.height;
10424 var a = {opacity: {to: 0}, points: {}}, pt = a.points;
10425 switch(anchor.toLowerCase()){
10452 arguments.callee.anim = this.fxanim(a,
10462 * Ensures that all effects queued after syncFx is called on the element are
10463 * run concurrently. This is the opposite of {@link #sequenceFx}.
10464 * @return {Roo.Element} The Element
10466 syncFx : function(){
10467 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10476 * Ensures that all effects queued after sequenceFx is called on the element are
10477 * run in sequence. This is the opposite of {@link #syncFx}.
10478 * @return {Roo.Element} The Element
10480 sequenceFx : function(){
10481 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10483 concurrent : false,
10490 nextFx : function(){
10491 var ef = this.fxQueue[0];
10498 * Returns true if the element has any effects actively running or queued, else returns false.
10499 * @return {Boolean} True if element has active effects, else false
10501 hasActiveFx : function(){
10502 return this.fxQueue && this.fxQueue[0];
10506 * Stops any running effects and clears the element's internal effects queue if it contains
10507 * any additional effects that haven't started yet.
10508 * @return {Roo.Element} The Element
10510 stopFx : function(){
10511 if(this.hasActiveFx()){
10512 var cur = this.fxQueue[0];
10513 if(cur && cur.anim && cur.anim.isAnimated()){
10514 this.fxQueue = [cur]; // clear out others
10515 cur.anim.stop(true);
10522 beforeFx : function(o){
10523 if(this.hasActiveFx() && !o.concurrent){
10534 * Returns true if the element is currently blocking so that no other effect can be queued
10535 * until this effect is finished, else returns false if blocking is not set. This is commonly
10536 * used to ensure that an effect initiated by a user action runs to completion prior to the
10537 * same effect being restarted (e.g., firing only one effect even if the user clicks several times).
10538 * @return {Boolean} True if blocking, else false
10540 hasFxBlock : function(){
10541 var q = this.fxQueue;
10542 return q && q[0] && q[0].block;
10546 queueFx : function(o, fn){
10550 if(!this.hasFxBlock()){
10551 Roo.applyIf(o, this.fxDefaults);
10553 var run = this.beforeFx(o);
10554 fn.block = o.block;
10555 this.fxQueue.push(fn);
10567 fxWrap : function(pos, o, vis){
10569 if(!o.wrap || !(wrap = Roo.get(o.wrap))){
10572 wrapXY = this.getXY();
10574 var div = document.createElement("div");
10575 div.style.visibility = vis;
10576 wrap = Roo.get(this.dom.parentNode.insertBefore(div, this.dom));
10577 wrap.setPositioning(pos);
10578 if(wrap.getStyle("position") == "static"){
10579 wrap.position("relative");
10581 this.clearPositioning('auto');
10583 wrap.dom.appendChild(this.dom);
10585 wrap.setXY(wrapXY);
10592 fxUnwrap : function(wrap, pos, o){
10593 this.clearPositioning();
10594 this.setPositioning(pos);
10596 wrap.dom.parentNode.insertBefore(this.dom, wrap.dom);
10602 getFxRestore : function(){
10603 var st = this.dom.style;
10604 return {pos: this.getPositioning(), width: st.width, height : st.height};
10608 afterFx : function(o){
10610 this.applyStyles(o.afterStyle);
10613 this.addClass(o.afterCls);
10615 if(o.remove === true){
10618 Roo.callback(o.callback, o.scope, [this]);
10620 this.fxQueue.shift();
10626 getFxEl : function(){ // support for composite element fx
10627 return Roo.get(this.dom);
10631 fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){
10632 animType = animType || 'run';
10634 var anim = Roo.lib.Anim[animType](
10636 (opt.duration || defaultDur) || .35,
10637 (opt.easing || defaultEase) || 'easeOut',
10639 Roo.callback(cb, this);
10648 // backwords compat
10649 Roo.Fx.resize = Roo.Fx.scale;
10651 //When included, Roo.Fx is automatically applied to Element so that all basic
10652 //effects are available directly via the Element API
10653 Roo.apply(Roo.Element.prototype, Roo.Fx);/*
10655 * Ext JS Library 1.1.1
10656 * Copyright(c) 2006-2007, Ext JS, LLC.
10658 * Originally Released Under LGPL - original licence link has changed is not relivant.
10661 * <script type="text/javascript">
10666 * @class Roo.CompositeElement
10667 * Standard composite class. Creates a Roo.Element for every element in the collection.
10669 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
10670 * actions will be performed on all the elements in this collection.</b>
10672 * All methods return <i>this</i> and can be chained.
10674 var els = Roo.select("#some-el div.some-class", true);
10675 // or select directly from an existing element
10676 var el = Roo.get('some-el');
10677 el.select('div.some-class', true);
10679 els.setWidth(100); // all elements become 100 width
10680 els.hide(true); // all elements fade out and hide
10682 els.setWidth(100).hide(true);
10685 Roo.CompositeElement = function(els){
10686 this.elements = [];
10687 this.addElements(els);
10689 Roo.CompositeElement.prototype = {
10691 addElements : function(els){
10692 if(!els) return this;
10693 if(typeof els == "string"){
10694 els = Roo.Element.selectorFunction(els);
10696 var yels = this.elements;
10697 var index = yels.length-1;
10698 for(var i = 0, len = els.length; i < len; i++) {
10699 yels[++index] = Roo.get(els[i]);
10705 * Clears this composite and adds the elements returned by the passed selector.
10706 * @param {String/Array} els A string CSS selector, an array of elements or an element
10707 * @return {CompositeElement} this
10709 fill : function(els){
10710 this.elements = [];
10716 * Filters this composite to only elements that match the passed selector.
10717 * @param {String} selector A string CSS selector
10718 * @return {CompositeElement} this
10720 filter : function(selector){
10722 this.each(function(el){
10723 if(el.is(selector)){
10724 els[els.length] = el.dom;
10731 invoke : function(fn, args){
10732 var els = this.elements;
10733 for(var i = 0, len = els.length; i < len; i++) {
10734 Roo.Element.prototype[fn].apply(els[i], args);
10739 * Adds elements to this composite.
10740 * @param {String/Array} els A string CSS selector, an array of elements or an element
10741 * @return {CompositeElement} this
10743 add : function(els){
10744 if(typeof els == "string"){
10745 this.addElements(Roo.Element.selectorFunction(els));
10746 }else if(els.length !== undefined){
10747 this.addElements(els);
10749 this.addElements([els]);
10754 * Calls the passed function passing (el, this, index) for each element in this composite.
10755 * @param {Function} fn The function to call
10756 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
10757 * @return {CompositeElement} this
10759 each : function(fn, scope){
10760 var els = this.elements;
10761 for(var i = 0, len = els.length; i < len; i++){
10762 if(fn.call(scope || els[i], els[i], this, i) === false) {
10770 * Returns the Element object at the specified index
10771 * @param {Number} index
10772 * @return {Roo.Element}
10774 item : function(index){
10775 return this.elements[index] || null;
10779 * Returns the first Element
10780 * @return {Roo.Element}
10782 first : function(){
10783 return this.item(0);
10787 * Returns the last Element
10788 * @return {Roo.Element}
10791 return this.item(this.elements.length-1);
10795 * Returns the number of elements in this composite
10798 getCount : function(){
10799 return this.elements.length;
10803 * Returns true if this composite contains the passed element
10806 contains : function(el){
10807 return this.indexOf(el) !== -1;
10811 * Returns true if this composite contains the passed element
10814 indexOf : function(el){
10815 return this.elements.indexOf(Roo.get(el));
10820 * Removes the specified element(s).
10821 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
10822 * or an array of any of those.
10823 * @param {Boolean} removeDom (optional) True to also remove the element from the document
10824 * @return {CompositeElement} this
10826 removeElement : function(el, removeDom){
10827 if(el instanceof Array){
10828 for(var i = 0, len = el.length; i < len; i++){
10829 this.removeElement(el[i]);
10833 var index = typeof el == 'number' ? el : this.indexOf(el);
10836 var d = this.elements[index];
10840 d.parentNode.removeChild(d);
10843 this.elements.splice(index, 1);
10849 * Replaces the specified element with the passed element.
10850 * @param {String/HTMLElement/Element/Number} el The id of an element, the Element itself, the index of the element in this composite
10852 * @param {String/HTMLElement/Element} replacement The id of an element or the Element itself.
10853 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
10854 * @return {CompositeElement} this
10856 replaceElement : function(el, replacement, domReplace){
10857 var index = typeof el == 'number' ? el : this.indexOf(el);
10860 this.elements[index].replaceWith(replacement);
10862 this.elements.splice(index, 1, Roo.get(replacement))
10869 * Removes all elements.
10871 clear : function(){
10872 this.elements = [];
10876 Roo.CompositeElement.createCall = function(proto, fnName){
10877 if(!proto[fnName]){
10878 proto[fnName] = function(){
10879 return this.invoke(fnName, arguments);
10883 for(var fnName in Roo.Element.prototype){
10884 if(typeof Roo.Element.prototype[fnName] == "function"){
10885 Roo.CompositeElement.createCall(Roo.CompositeElement.prototype, fnName);
10891 * Ext JS Library 1.1.1
10892 * Copyright(c) 2006-2007, Ext JS, LLC.
10894 * Originally Released Under LGPL - original licence link has changed is not relivant.
10897 * <script type="text/javascript">
10901 * @class Roo.CompositeElementLite
10902 * @extends Roo.CompositeElement
10903 * Flyweight composite class. Reuses the same Roo.Element for element operations.
10905 var els = Roo.select("#some-el div.some-class");
10906 // or select directly from an existing element
10907 var el = Roo.get('some-el');
10908 el.select('div.some-class');
10910 els.setWidth(100); // all elements become 100 width
10911 els.hide(true); // all elements fade out and hide
10913 els.setWidth(100).hide(true);
10914 </code></pre><br><br>
10915 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
10916 * actions will be performed on all the elements in this collection.</b>
10918 Roo.CompositeElementLite = function(els){
10919 Roo.CompositeElementLite.superclass.constructor.call(this, els);
10920 this.el = new Roo.Element.Flyweight();
10922 Roo.extend(Roo.CompositeElementLite, Roo.CompositeElement, {
10923 addElements : function(els){
10925 if(els instanceof Array){
10926 this.elements = this.elements.concat(els);
10928 var yels = this.elements;
10929 var index = yels.length-1;
10930 for(var i = 0, len = els.length; i < len; i++) {
10931 yels[++index] = els[i];
10937 invoke : function(fn, args){
10938 var els = this.elements;
10940 for(var i = 0, len = els.length; i < len; i++) {
10942 Roo.Element.prototype[fn].apply(el, args);
10947 * Returns a flyweight Element of the dom element object at the specified index
10948 * @param {Number} index
10949 * @return {Roo.Element}
10951 item : function(index){
10952 if(!this.elements[index]){
10955 this.el.dom = this.elements[index];
10959 // fixes scope with flyweight
10960 addListener : function(eventName, handler, scope, opt){
10961 var els = this.elements;
10962 for(var i = 0, len = els.length; i < len; i++) {
10963 Roo.EventManager.on(els[i], eventName, handler, scope || els[i], opt);
10969 * Calls the passed function passing (el, this, index) for each element in this composite. <b>The element
10970 * passed is the flyweight (shared) Roo.Element instance, so if you require a
10971 * a reference to the dom node, use el.dom.</b>
10972 * @param {Function} fn The function to call
10973 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
10974 * @return {CompositeElement} this
10976 each : function(fn, scope){
10977 var els = this.elements;
10979 for(var i = 0, len = els.length; i < len; i++){
10981 if(fn.call(scope || el, el, this, i) === false){
10988 indexOf : function(el){
10989 return this.elements.indexOf(Roo.getDom(el));
10992 replaceElement : function(el, replacement, domReplace){
10993 var index = typeof el == 'number' ? el : this.indexOf(el);
10995 replacement = Roo.getDom(replacement);
10997 var d = this.elements[index];
10998 d.parentNode.insertBefore(replacement, d);
10999 d.parentNode.removeChild(d);
11001 this.elements.splice(index, 1, replacement);
11006 Roo.CompositeElementLite.prototype.on = Roo.CompositeElementLite.prototype.addListener;
11010 * Ext JS Library 1.1.1
11011 * Copyright(c) 2006-2007, Ext JS, LLC.
11013 * Originally Released Under LGPL - original licence link has changed is not relivant.
11016 * <script type="text/javascript">
11022 * @class Roo.data.Connection
11023 * @extends Roo.util.Observable
11024 * The class encapsulates a connection to the page's originating domain, allowing requests to be made
11025 * either to a configured URL, or to a URL specified at request time.<br><br>
11027 * Requests made by this class are asynchronous, and will return immediately. No data from
11028 * the server will be available to the statement immediately following the {@link #request} call.
11029 * To process returned data, use a callback in the request options object, or an event listener.</p><br>
11031 * Note: If you are doing a file upload, you will not get a normal response object sent back to
11032 * your callback or event handler. Since the upload is handled via in IFRAME, there is no XMLHttpRequest.
11033 * The response object is created using the innerHTML of the IFRAME's document as the responseText
11034 * property and, if present, the IFRAME's XML document as the responseXML property.</p><br>
11035 * This means that a valid XML or HTML document must be returned. If JSON data is required, it is suggested
11036 * that it be placed either inside a <textarea> in an HTML document and retrieved from the responseText
11037 * using a regex, or inside a CDATA section in an XML document and retrieved from the responseXML using
11038 * standard DOM methods.
11040 * @param {Object} config a configuration object.
11042 Roo.data.Connection = function(config){
11043 Roo.apply(this, config);
11046 * @event beforerequest
11047 * Fires before a network request is made to retrieve a data object.
11048 * @param {Connection} conn This Connection object.
11049 * @param {Object} options The options config object passed to the {@link #request} method.
11051 "beforerequest" : true,
11053 * @event requestcomplete
11054 * Fires if the request was successfully completed.
11055 * @param {Connection} conn This Connection object.
11056 * @param {Object} response The XHR object containing the response data.
11057 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11058 * @param {Object} options The options config object passed to the {@link #request} method.
11060 "requestcomplete" : true,
11062 * @event requestexception
11063 * Fires if an error HTTP status was returned from the server.
11064 * See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html} for details of HTTP status codes.
11065 * @param {Connection} conn This Connection object.
11066 * @param {Object} response The XHR object containing the response data.
11067 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11068 * @param {Object} options The options config object passed to the {@link #request} method.
11070 "requestexception" : true
11072 Roo.data.Connection.superclass.constructor.call(this);
11075 Roo.extend(Roo.data.Connection, Roo.util.Observable, {
11077 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11080 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11081 * extra parameters to each request made by this object. (defaults to undefined)
11084 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11085 * to each request made by this object. (defaults to undefined)
11088 * @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)
11091 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11095 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11101 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11104 disableCaching: true,
11107 * Sends an HTTP request to a remote server.
11108 * @param {Object} options An object which may contain the following properties:<ul>
11109 * <li><b>url</b> {String} (Optional) The URL to which to send the request. Defaults to configured URL</li>
11110 * <li><b>params</b> {Object/String/Function} (Optional) An object containing properties which are used as parameters to the
11111 * request, a url encoded string or a function to call to get either.</li>
11112 * <li><b>method</b> {String} (Optional) The HTTP method to use for the request. Defaults to the configured method, or
11113 * if no method was configured, "GET" if no parameters are being sent, and "POST" if parameters are being sent.</li>
11114 * <li><b>callback</b> {Function} (Optional) The function to be called upon receipt of the HTTP response.
11115 * The callback is called regardless of success or failure and is passed the following parameters:<ul>
11116 * <li>options {Object} The parameter to the request call.</li>
11117 * <li>success {Boolean} True if the request succeeded.</li>
11118 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11120 * <li><b>success</b> {Function} (Optional) The function to be called upon success of the request.
11121 * The callback is passed the following parameters:<ul>
11122 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11123 * <li>options {Object} The parameter to the request call.</li>
11125 * <li><b>failure</b> {Function} (Optional) The function to be called upon failure of the request.
11126 * The callback is passed the following parameters:<ul>
11127 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11128 * <li>options {Object} The parameter to the request call.</li>
11130 * <li><b>scope</b> {Object} (Optional) The scope in which to execute the callbacks: The "this" object
11131 * for the callback function. Defaults to the browser window.</li>
11132 * <li><b>form</b> {Object/String} (Optional) A form object or id to pull parameters from.</li>
11133 * <li><b>isUpload</b> {Boolean} (Optional) True if the form object is a file upload (will usually be automatically detected).</li>
11134 * <li><b>headers</b> {Object} (Optional) Request headers to set for the request.</li>
11135 * <li><b>xmlData</b> {Object} (Optional) XML document to use for the post. Note: This will be used instead of
11136 * params for the post data. Any params will be appended to the URL.</li>
11137 * <li><b>disableCaching</b> {Boolean} (Optional) True to add a unique cache-buster param to GET requests.</li>
11139 * @return {Number} transactionId
11141 request : function(o){
11142 if(this.fireEvent("beforerequest", this, o) !== false){
11145 if(typeof p == "function"){
11146 p = p.call(o.scope||window, o);
11148 if(typeof p == "object"){
11149 p = Roo.urlEncode(o.params);
11151 if(this.extraParams){
11152 var extras = Roo.urlEncode(this.extraParams);
11153 p = p ? (p + '&' + extras) : extras;
11156 var url = o.url || this.url;
11157 if(typeof url == 'function'){
11158 url = url.call(o.scope||window, o);
11162 var form = Roo.getDom(o.form);
11163 url = url || form.action;
11165 var enctype = form.getAttribute("enctype");
11166 if(o.isUpload || (enctype && enctype.toLowerCase() == 'multipart/form-data')){
11167 return this.doFormUpload(o, p, url);
11169 var f = Roo.lib.Ajax.serializeForm(form);
11170 p = p ? (p + '&' + f) : f;
11173 var hs = o.headers;
11174 if(this.defaultHeaders){
11175 hs = Roo.apply(hs || {}, this.defaultHeaders);
11182 success: this.handleResponse,
11183 failure: this.handleFailure,
11185 argument: {options: o},
11186 timeout : this.timeout
11189 var method = o.method||this.method||(p ? "POST" : "GET");
11191 if(method == 'GET' && (this.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
11192 url += (url.indexOf('?') != -1 ? '&' : '?') + '_dc=' + (new Date().getTime());
11195 if(typeof o.autoAbort == 'boolean'){ // options gets top priority
11199 }else if(this.autoAbort !== false){
11203 if((method == 'GET' && p) || o.xmlData){
11204 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
11207 this.transId = Roo.lib.Ajax.request(method, url, cb, p, o);
11208 return this.transId;
11210 Roo.callback(o.callback, o.scope, [o, null, null]);
11216 * Determine whether this object has a request outstanding.
11217 * @param {Number} transactionId (Optional) defaults to the last transaction
11218 * @return {Boolean} True if there is an outstanding request.
11220 isLoading : function(transId){
11222 return Roo.lib.Ajax.isCallInProgress(transId);
11224 return this.transId ? true : false;
11229 * Aborts any outstanding request.
11230 * @param {Number} transactionId (Optional) defaults to the last transaction
11232 abort : function(transId){
11233 if(transId || this.isLoading()){
11234 Roo.lib.Ajax.abort(transId || this.transId);
11239 handleResponse : function(response){
11240 this.transId = false;
11241 var options = response.argument.options;
11242 response.argument = options ? options.argument : null;
11243 this.fireEvent("requestcomplete", this, response, options);
11244 Roo.callback(options.success, options.scope, [response, options]);
11245 Roo.callback(options.callback, options.scope, [options, true, response]);
11249 handleFailure : function(response, e){
11250 this.transId = false;
11251 var options = response.argument.options;
11252 response.argument = options ? options.argument : null;
11253 this.fireEvent("requestexception", this, response, options, e);
11254 Roo.callback(options.failure, options.scope, [response, options]);
11255 Roo.callback(options.callback, options.scope, [options, false, response]);
11259 doFormUpload : function(o, ps, url){
11261 var frame = document.createElement('iframe');
11264 frame.className = 'x-hidden';
11266 frame.src = Roo.SSL_SECURE_URL;
11268 document.body.appendChild(frame);
11271 document.frames[id].name = id;
11274 var form = Roo.getDom(o.form);
11276 form.method = 'POST';
11277 form.enctype = form.encoding = 'multipart/form-data';
11283 if(ps){ // add dynamic params
11285 ps = Roo.urlDecode(ps, false);
11287 if(ps.hasOwnProperty(k)){
11288 hd = document.createElement('input');
11289 hd.type = 'hidden';
11292 form.appendChild(hd);
11299 var r = { // bogus response object
11304 r.argument = o ? o.argument : null;
11309 doc = frame.contentWindow.document;
11311 doc = (frame.contentDocument || window.frames[id].document);
11313 if(doc && doc.body){
11314 r.responseText = doc.body.innerHTML;
11316 if(doc && doc.XMLDocument){
11317 r.responseXML = doc.XMLDocument;
11319 r.responseXML = doc;
11326 Roo.EventManager.removeListener(frame, 'load', cb, this);
11328 this.fireEvent("requestcomplete", this, r, o);
11329 Roo.callback(o.success, o.scope, [r, o]);
11330 Roo.callback(o.callback, o.scope, [o, true, r]);
11332 setTimeout(function(){document.body.removeChild(frame);}, 100);
11335 Roo.EventManager.on(frame, 'load', cb, this);
11338 if(hiddens){ // remove dynamic params
11339 for(var i = 0, len = hiddens.length; i < len; i++){
11340 form.removeChild(hiddens[i]);
11348 * @extends Roo.data.Connection
11349 * Global Ajax request class.
11353 Roo.Ajax = new Roo.data.Connection({
11356 * @cfg {String} url @hide
11359 * @cfg {Object} extraParams @hide
11362 * @cfg {Object} defaultHeaders @hide
11365 * @cfg {String} method (Optional) @hide
11368 * @cfg {Number} timeout (Optional) @hide
11371 * @cfg {Boolean} autoAbort (Optional) @hide
11375 * @cfg {Boolean} disableCaching (Optional) @hide
11379 * @property disableCaching
11380 * True to add a unique cache-buster param to GET requests. (defaults to true)
11385 * The default URL to be used for requests to the server. (defaults to undefined)
11389 * @property extraParams
11390 * An object containing properties which are used as
11391 * extra parameters to each request made by this object. (defaults to undefined)
11395 * @property defaultHeaders
11396 * An object containing request headers which are added to each request made by this object. (defaults to undefined)
11401 * The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
11405 * @property timeout
11406 * The timeout in milliseconds to be used for requests. (defaults to 30000)
11411 * @property autoAbort
11412 * Whether a new request should abort any pending requests. (defaults to false)
11418 * Serialize the passed form into a url encoded string
11419 * @param {String/HTMLElement} form
11422 serializeForm : function(form){
11423 return Roo.lib.Ajax.serializeForm(form);
11427 * Ext JS Library 1.1.1
11428 * Copyright(c) 2006-2007, Ext JS, LLC.
11430 * Originally Released Under LGPL - original licence link has changed is not relivant.
11433 * <script type="text/javascript">
11438 * @extends Roo.data.Connection
11439 * Global Ajax request class.
11441 * @instanceOf Roo.data.Connection
11443 Roo.Ajax = new Roo.data.Connection({
11452 * @cfg {String} url @hide
11455 * @cfg {Object} extraParams @hide
11458 * @cfg {Object} defaultHeaders @hide
11461 * @cfg {String} method (Optional) @hide
11464 * @cfg {Number} timeout (Optional) @hide
11467 * @cfg {Boolean} autoAbort (Optional) @hide
11471 * @cfg {Boolean} disableCaching (Optional) @hide
11475 * @property disableCaching
11476 * True to add a unique cache-buster param to GET requests. (defaults to true)
11481 * The default URL to be used for requests to the server. (defaults to undefined)
11485 * @property extraParams
11486 * An object containing properties which are used as
11487 * extra parameters to each request made by this object. (defaults to undefined)
11491 * @property defaultHeaders
11492 * An object containing request headers which are added to each request made by this object. (defaults to undefined)
11497 * The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
11501 * @property timeout
11502 * The timeout in milliseconds to be used for requests. (defaults to 30000)
11507 * @property autoAbort
11508 * Whether a new request should abort any pending requests. (defaults to false)
11514 * Serialize the passed form into a url encoded string
11515 * @param {String/HTMLElement} form
11518 serializeForm : function(form){
11519 return Roo.lib.Ajax.serializeForm(form);
11523 * Ext JS Library 1.1.1
11524 * Copyright(c) 2006-2007, Ext JS, LLC.
11526 * Originally Released Under LGPL - original licence link has changed is not relivant.
11529 * <script type="text/javascript">
11534 * @class Roo.UpdateManager
11535 * @extends Roo.util.Observable
11536 * Provides AJAX-style update for Element object.<br><br>
11539 * // Get it from a Roo.Element object
11540 * var el = Roo.get("foo");
11541 * var mgr = el.getUpdateManager();
11542 * mgr.update("http://myserver.com/index.php", "param1=1&param2=2");
11544 * mgr.formUpdate("myFormId", "http://myserver.com/index.php");
11546 * // or directly (returns the same UpdateManager instance)
11547 * var mgr = new Roo.UpdateManager("myElementId");
11548 * mgr.startAutoRefresh(60, "http://myserver.com/index.php");
11549 * mgr.on("update", myFcnNeedsToKnow);
11551 // short handed call directly from the element object
11552 Roo.get("foo").load({
11556 text: "Loading Foo..."
11560 * Create new UpdateManager directly.
11561 * @param {String/HTMLElement/Roo.Element} el The element to update
11562 * @param {Boolean} forceNew (optional) By default the constructor checks to see if the passed element already has an UpdateManager and if it does it returns the same instance. This will skip that check (useful for extending this class).
11564 Roo.UpdateManager = function(el, forceNew){
11566 if(!forceNew && el.updateManager){
11567 return el.updateManager;
11570 * The Element object
11571 * @type Roo.Element
11575 * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.
11578 this.defaultUrl = null;
11582 * @event beforeupdate
11583 * Fired before an update is made, return false from your handler and the update is cancelled.
11584 * @param {Roo.Element} el
11585 * @param {String/Object/Function} url
11586 * @param {String/Object} params
11588 "beforeupdate": true,
11591 * Fired after successful update is made.
11592 * @param {Roo.Element} el
11593 * @param {Object} oResponseObject The response Object
11598 * Fired on update failure.
11599 * @param {Roo.Element} el
11600 * @param {Object} oResponseObject The response Object
11604 var d = Roo.UpdateManager.defaults;
11606 * Blank page URL to use with SSL file uploads (Defaults to Roo.UpdateManager.defaults.sslBlankUrl or "about:blank").
11609 this.sslBlankUrl = d.sslBlankUrl;
11611 * Whether to append unique parameter on get request to disable caching (Defaults to Roo.UpdateManager.defaults.disableCaching or false).
11614 this.disableCaching = d.disableCaching;
11616 * Text for loading indicator (Defaults to Roo.UpdateManager.defaults.indicatorText or '<div class="loading-indicator">Loading...</div>').
11619 this.indicatorText = d.indicatorText;
11621 * Whether to show indicatorText when loading (Defaults to Roo.UpdateManager.defaults.showLoadIndicator or true).
11624 this.showLoadIndicator = d.showLoadIndicator;
11626 * Timeout for requests or form posts in seconds (Defaults to Roo.UpdateManager.defaults.timeout or 30 seconds).
11629 this.timeout = d.timeout;
11632 * True to process scripts in the output (Defaults to Roo.UpdateManager.defaults.loadScripts (false)).
11635 this.loadScripts = d.loadScripts;
11638 * Transaction object of current executing transaction
11640 this.transaction = null;
11645 this.autoRefreshProcId = null;
11647 * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
11650 this.refreshDelegate = this.refresh.createDelegate(this);
11652 * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
11655 this.updateDelegate = this.update.createDelegate(this);
11657 * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
11660 this.formUpdateDelegate = this.formUpdate.createDelegate(this);
11664 this.successDelegate = this.processSuccess.createDelegate(this);
11668 this.failureDelegate = this.processFailure.createDelegate(this);
11670 if(!this.renderer){
11672 * The renderer for this UpdateManager. Defaults to {@link Roo.UpdateManager.BasicRenderer}.
11674 this.renderer = new Roo.UpdateManager.BasicRenderer();
11677 Roo.UpdateManager.superclass.constructor.call(this);
11680 Roo.extend(Roo.UpdateManager, Roo.util.Observable, {
11682 * Get the Element this UpdateManager is bound to
11683 * @return {Roo.Element} The element
11685 getEl : function(){
11689 * Performs an async request, updating this element with the response. If params are specified it uses POST, otherwise it uses GET.
11690 * @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:
11693 url: "your-url.php",<br/>
11694 params: {param1: "foo", param2: "bar"}, // or a URL encoded string<br/>
11695 callback: yourFunction,<br/>
11696 scope: yourObject, //(optional scope) <br/>
11697 discardUrl: false, <br/>
11698 nocache: false,<br/>
11699 text: "Loading...",<br/>
11701 scripts: false<br/>
11704 * The only required property is url. The optional properties nocache, text and scripts
11705 * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their associated property on this UpdateManager instance.
11706 * @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}
11707 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11708 * @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.
11710 update : function(url, params, callback, discardUrl){
11711 if(this.fireEvent("beforeupdate", this.el, url, params) !== false){
11712 var method = this.method, cfg;
11713 if(typeof url == "object"){ // must be config object
11716 params = params || cfg.params;
11717 callback = callback || cfg.callback;
11718 discardUrl = discardUrl || cfg.discardUrl;
11719 if(callback && cfg.scope){
11720 callback = callback.createDelegate(cfg.scope);
11722 if(typeof cfg.method != "undefined"){method = cfg.method;};
11723 if(typeof cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;};
11724 if(typeof cfg.text != "undefined"){this.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};
11725 if(typeof cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;};
11726 if(typeof cfg.timeout != "undefined"){this.timeout = cfg.timeout;};
11728 this.showLoading();
11730 this.defaultUrl = url;
11732 if(typeof url == "function"){
11733 url = url.call(this);
11736 method = method || (params ? "POST" : "GET");
11737 if(method == "GET"){
11738 url = this.prepareUrl(url);
11741 var o = Roo.apply(cfg ||{}, {
11744 success: this.successDelegate,
11745 failure: this.failureDelegate,
11746 callback: undefined,
11747 timeout: (this.timeout*1000),
11748 argument: {"url": url, "form": null, "callback": callback, "params": params}
11751 this.transaction = Roo.Ajax.request(o);
11756 * Performs an async form post, updating this element with the response. If the form has the attribute enctype="multipart/form-data", it assumes it's a file upload.
11757 * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.
11758 * @param {String/HTMLElement} form The form Id or form element
11759 * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
11760 * @param {Boolean} reset (optional) Whether to try to reset the form after the update
11761 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11763 formUpdate : function(form, url, reset, callback){
11764 if(this.fireEvent("beforeupdate", this.el, form, url) !== false){
11765 if(typeof url == "function"){
11766 url = url.call(this);
11768 form = Roo.getDom(form);
11769 this.transaction = Roo.Ajax.request({
11772 success: this.successDelegate,
11773 failure: this.failureDelegate,
11774 timeout: (this.timeout*1000),
11775 argument: {"url": url, "form": form, "callback": callback, "reset": reset}
11777 this.showLoading.defer(1, this);
11782 * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
11783 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
11785 refresh : function(callback){
11786 if(this.defaultUrl == null){
11789 this.update(this.defaultUrl, null, callback, true);
11793 * Set this element to auto refresh.
11794 * @param {Number} interval How often to update (in seconds).
11795 * @param {String/Function} url (optional) The url for this request or a function to call to get the url (Defaults to the last used url)
11796 * @param {String/Object} params (optional) The parameters to pass as either a url encoded string "¶m1=1¶m2=2" or as an object {param1: 1, param2: 2}
11797 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
11798 * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
11800 startAutoRefresh : function(interval, url, params, callback, refreshNow){
11802 this.update(url || this.defaultUrl, params, callback, true);
11804 if(this.autoRefreshProcId){
11805 clearInterval(this.autoRefreshProcId);
11807 this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [url || this.defaultUrl, params, callback, true]), interval*1000);
11811 * Stop auto refresh on this element.
11813 stopAutoRefresh : function(){
11814 if(this.autoRefreshProcId){
11815 clearInterval(this.autoRefreshProcId);
11816 delete this.autoRefreshProcId;
11820 isAutoRefreshing : function(){
11821 return this.autoRefreshProcId ? true : false;
11824 * Called to update the element to "Loading" state. Override to perform custom action.
11826 showLoading : function(){
11827 if(this.showLoadIndicator){
11828 this.el.update(this.indicatorText);
11833 * Adds unique parameter to query string if disableCaching = true
11836 prepareUrl : function(url){
11837 if(this.disableCaching){
11838 var append = "_dc=" + (new Date().getTime());
11839 if(url.indexOf("?") !== -1){
11840 url += "&" + append;
11842 url += "?" + append;
11851 processSuccess : function(response){
11852 this.transaction = null;
11853 if(response.argument.form && response.argument.reset){
11854 try{ // put in try/catch since some older FF releases had problems with this
11855 response.argument.form.reset();
11858 if(this.loadScripts){
11859 this.renderer.render(this.el, response, this,
11860 this.updateComplete.createDelegate(this, [response]));
11862 this.renderer.render(this.el, response, this);
11863 this.updateComplete(response);
11867 updateComplete : function(response){
11868 this.fireEvent("update", this.el, response);
11869 if(typeof response.argument.callback == "function"){
11870 response.argument.callback(this.el, true, response);
11877 processFailure : function(response){
11878 this.transaction = null;
11879 this.fireEvent("failure", this.el, response);
11880 if(typeof response.argument.callback == "function"){
11881 response.argument.callback(this.el, false, response);
11886 * Set the content renderer for this UpdateManager. See {@link Roo.UpdateManager.BasicRenderer#render} for more details.
11887 * @param {Object} renderer The object implementing the render() method
11889 setRenderer : function(renderer){
11890 this.renderer = renderer;
11893 getRenderer : function(){
11894 return this.renderer;
11898 * Set the defaultUrl used for updates
11899 * @param {String/Function} defaultUrl The url or a function to call to get the url
11901 setDefaultUrl : function(defaultUrl){
11902 this.defaultUrl = defaultUrl;
11906 * Aborts the executing transaction
11908 abort : function(){
11909 if(this.transaction){
11910 Roo.Ajax.abort(this.transaction);
11915 * Returns true if an update is in progress
11916 * @return {Boolean}
11918 isUpdating : function(){
11919 if(this.transaction){
11920 return Roo.Ajax.isLoading(this.transaction);
11927 * @class Roo.UpdateManager.defaults
11928 * @static (not really - but it helps the doc tool)
11929 * The defaults collection enables customizing the default properties of UpdateManager
11931 Roo.UpdateManager.defaults = {
11933 * Timeout for requests or form posts in seconds (Defaults 30 seconds).
11939 * True to process scripts by default (Defaults to false).
11942 loadScripts : false,
11945 * Blank page URL to use with SSL file uploads (Defaults to "javascript:false").
11948 sslBlankUrl : (Roo.SSL_SECURE_URL || "javascript:false"),
11950 * Whether to append unique parameter on get request to disable caching (Defaults to false).
11953 disableCaching : false,
11955 * Whether to show indicatorText when loading (Defaults to true).
11958 showLoadIndicator : true,
11960 * Text for loading indicator (Defaults to '<div class="loading-indicator">Loading...</div>').
11963 indicatorText : '<div class="loading-indicator">Loading...</div>'
11967 * Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', ...}).
11969 * <pre><code>Roo.UpdateManager.updateElement("my-div", "stuff.php");</code></pre>
11970 * @param {String/HTMLElement/Roo.Element} el The element to update
11971 * @param {String} url The url
11972 * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
11973 * @param {Object} options (optional) A config object with any of the UpdateManager properties you want to set - for example: {disableCaching:true, indicatorText: "Loading data..."}
11976 * @member Roo.UpdateManager
11978 Roo.UpdateManager.updateElement = function(el, url, params, options){
11979 var um = Roo.get(el, true).getUpdateManager();
11980 Roo.apply(um, options);
11981 um.update(url, params, options ? options.callback : null);
11983 // alias for backwards compat
11984 Roo.UpdateManager.update = Roo.UpdateManager.updateElement;
11986 * @class Roo.UpdateManager.BasicRenderer
11987 * Default Content renderer. Updates the elements innerHTML with the responseText.
11989 Roo.UpdateManager.BasicRenderer = function(){};
11991 Roo.UpdateManager.BasicRenderer.prototype = {
11993 * This is called when the transaction is completed and it's time to update the element - The BasicRenderer
11994 * updates the elements innerHTML with the responseText - To perform a custom render (i.e. XML or JSON processing),
11995 * create an object with a "render(el, response)" method and pass it to setRenderer on the UpdateManager.
11996 * @param {Roo.Element} el The element being rendered
11997 * @param {Object} response The YUI Connect response object
11998 * @param {UpdateManager} updateManager The calling update manager
11999 * @param {Function} callback A callback that will need to be called if loadScripts is true on the UpdateManager
12001 render : function(el, response, updateManager, callback){
12002 el.update(response.responseText, updateManager.loadScripts, callback);
12007 * Ext JS Library 1.1.1
12008 * Copyright(c) 2006-2007, Ext JS, LLC.
12010 * Originally Released Under LGPL - original licence link has changed is not relivant.
12013 * <script type="text/javascript">
12017 * @class Roo.util.DelayedTask
12018 * Provides a convenient method of performing setTimeout where a new
12019 * timeout cancels the old timeout. An example would be performing validation on a keypress.
12020 * You can use this class to buffer
12021 * the keypress events for a certain number of milliseconds, and perform only if they stop
12022 * for that amount of time.
12023 * @constructor The parameters to this constructor serve as defaults and are not required.
12024 * @param {Function} fn (optional) The default function to timeout
12025 * @param {Object} scope (optional) The default scope of that timeout
12026 * @param {Array} args (optional) The default Array of arguments
12028 Roo.util.DelayedTask = function(fn, scope, args){
12029 var id = null, d, t;
12031 var call = function(){
12032 var now = new Date().getTime();
12036 fn.apply(scope, args || []);
12040 * Cancels any pending timeout and queues a new one
12041 * @param {Number} delay The milliseconds to delay
12042 * @param {Function} newFn (optional) Overrides function passed to constructor
12043 * @param {Object} newScope (optional) Overrides scope passed to constructor
12044 * @param {Array} newArgs (optional) Overrides args passed to constructor
12046 this.delay = function(delay, newFn, newScope, newArgs){
12047 if(id && delay != d){
12051 t = new Date().getTime();
12053 scope = newScope || scope;
12054 args = newArgs || args;
12056 id = setInterval(call, d);
12061 * Cancel the last queued timeout
12063 this.cancel = function(){
12071 * Ext JS Library 1.1.1
12072 * Copyright(c) 2006-2007, Ext JS, LLC.
12074 * Originally Released Under LGPL - original licence link has changed is not relivant.
12077 * <script type="text/javascript">
12081 Roo.util.TaskRunner = function(interval){
12082 interval = interval || 10;
12083 var tasks = [], removeQueue = [];
12085 var running = false;
12087 var stopThread = function(){
12093 var startThread = function(){
12096 id = setInterval(runTasks, interval);
12100 var removeTask = function(task){
12101 removeQueue.push(task);
12107 var runTasks = function(){
12108 if(removeQueue.length > 0){
12109 for(var i = 0, len = removeQueue.length; i < len; i++){
12110 tasks.remove(removeQueue[i]);
12113 if(tasks.length < 1){
12118 var now = new Date().getTime();
12119 for(var i = 0, len = tasks.length; i < len; ++i){
12121 var itime = now - t.taskRunTime;
12122 if(t.interval <= itime){
12123 var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
12124 t.taskRunTime = now;
12125 if(rt === false || t.taskRunCount === t.repeat){
12130 if(t.duration && t.duration <= (now - t.taskStartTime)){
12137 * Queues a new task.
12138 * @param {Object} task
12140 this.start = function(task){
12142 task.taskStartTime = new Date().getTime();
12143 task.taskRunTime = 0;
12144 task.taskRunCount = 0;
12149 this.stop = function(task){
12154 this.stopAll = function(){
12156 for(var i = 0, len = tasks.length; i < len; i++){
12157 if(tasks[i].onStop){
12166 Roo.TaskMgr = new Roo.util.TaskRunner();/*
12168 * Ext JS Library 1.1.1
12169 * Copyright(c) 2006-2007, Ext JS, LLC.
12171 * Originally Released Under LGPL - original licence link has changed is not relivant.
12174 * <script type="text/javascript">
12179 * @class Roo.util.MixedCollection
12180 * @extends Roo.util.Observable
12181 * A Collection class that maintains both numeric indexes and keys and exposes events.
12183 * @param {Boolean} allowFunctions True if the addAll function should add function references to the
12184 * collection (defaults to false)
12185 * @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
12186 * and return the key value for that item. This is used when available to look up the key on items that
12187 * were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
12188 * equivalent to providing an implementation for the {@link #getKey} method.
12190 Roo.util.MixedCollection = function(allowFunctions, keyFn){
12198 * Fires when the collection is cleared.
12203 * Fires when an item is added to the collection.
12204 * @param {Number} index The index at which the item was added.
12205 * @param {Object} o The item added.
12206 * @param {String} key The key associated with the added item.
12211 * Fires when an item is replaced in the collection.
12212 * @param {String} key he key associated with the new added.
12213 * @param {Object} old The item being replaced.
12214 * @param {Object} new The new item.
12219 * Fires when an item is removed from the collection.
12220 * @param {Object} o The item being removed.
12221 * @param {String} key (optional) The key associated with the removed item.
12226 this.allowFunctions = allowFunctions === true;
12228 this.getKey = keyFn;
12230 Roo.util.MixedCollection.superclass.constructor.call(this);
12233 Roo.extend(Roo.util.MixedCollection, Roo.util.Observable, {
12234 allowFunctions : false,
12237 * Adds an item to the collection.
12238 * @param {String} key The key to associate with the item
12239 * @param {Object} o The item to add.
12240 * @return {Object} The item added.
12242 add : function(key, o){
12243 if(arguments.length == 1){
12245 key = this.getKey(o);
12247 if(typeof key == "undefined" || key === null){
12249 this.items.push(o);
12250 this.keys.push(null);
12252 var old = this.map[key];
12254 return this.replace(key, o);
12257 this.items.push(o);
12259 this.keys.push(key);
12261 this.fireEvent("add", this.length-1, o, key);
12266 * MixedCollection has a generic way to fetch keys if you implement getKey.
12269 var mc = new Roo.util.MixedCollection();
12270 mc.add(someEl.dom.id, someEl);
12271 mc.add(otherEl.dom.id, otherEl);
12275 var mc = new Roo.util.MixedCollection();
12276 mc.getKey = function(el){
12282 // or via the constructor
12283 var mc = new Roo.util.MixedCollection(false, function(el){
12289 * @param o {Object} The item for which to find the key.
12290 * @return {Object} The key for the passed item.
12292 getKey : function(o){
12297 * Replaces an item in the collection.
12298 * @param {String} key The key associated with the item to replace, or the item to replace.
12299 * @param o {Object} o (optional) If the first parameter passed was a key, the item to associate with that key.
12300 * @return {Object} The new item.
12302 replace : function(key, o){
12303 if(arguments.length == 1){
12305 key = this.getKey(o);
12307 var old = this.item(key);
12308 if(typeof key == "undefined" || key === null || typeof old == "undefined"){
12309 return this.add(key, o);
12311 var index = this.indexOfKey(key);
12312 this.items[index] = o;
12314 this.fireEvent("replace", key, old, o);
12319 * Adds all elements of an Array or an Object to the collection.
12320 * @param {Object/Array} objs An Object containing properties which will be added to the collection, or
12321 * an Array of values, each of which are added to the collection.
12323 addAll : function(objs){
12324 if(arguments.length > 1 || objs instanceof Array){
12325 var args = arguments.length > 1 ? arguments : objs;
12326 for(var i = 0, len = args.length; i < len; i++){
12330 for(var key in objs){
12331 if(this.allowFunctions || typeof objs[key] != "function"){
12332 this.add(key, objs[key]);
12339 * Executes the specified function once for every item in the collection, passing each
12340 * item as the first and only parameter. returning false from the function will stop the iteration.
12341 * @param {Function} fn The function to execute for each item.
12342 * @param {Object} scope (optional) The scope in which to execute the function.
12344 each : function(fn, scope){
12345 var items = [].concat(this.items); // each safe for removal
12346 for(var i = 0, len = items.length; i < len; i++){
12347 if(fn.call(scope || items[i], items[i], i, len) === false){
12354 * Executes the specified function once for every key in the collection, passing each
12355 * key, and its associated item as the first two parameters.
12356 * @param {Function} fn The function to execute for each item.
12357 * @param {Object} scope (optional) The scope in which to execute the function.
12359 eachKey : function(fn, scope){
12360 for(var i = 0, len = this.keys.length; i < len; i++){
12361 fn.call(scope || window, this.keys[i], this.items[i], i, len);
12366 * Returns the first item in the collection which elicits a true return value from the
12367 * passed selection function.
12368 * @param {Function} fn The selection function to execute for each item.
12369 * @param {Object} scope (optional) The scope in which to execute the function.
12370 * @return {Object} The first item in the collection which returned true from the selection function.
12372 find : function(fn, scope){
12373 for(var i = 0, len = this.items.length; i < len; i++){
12374 if(fn.call(scope || window, this.items[i], this.keys[i])){
12375 return this.items[i];
12382 * Inserts an item at the specified index in the collection.
12383 * @param {Number} index The index to insert the item at.
12384 * @param {String} key The key to associate with the new item, or the item itself.
12385 * @param {Object} o (optional) If the second parameter was a key, the new item.
12386 * @return {Object} The item inserted.
12388 insert : function(index, key, o){
12389 if(arguments.length == 2){
12391 key = this.getKey(o);
12393 if(index >= this.length){
12394 return this.add(key, o);
12397 this.items.splice(index, 0, o);
12398 if(typeof key != "undefined" && key != null){
12401 this.keys.splice(index, 0, key);
12402 this.fireEvent("add", index, o, key);
12407 * Removed an item from the collection.
12408 * @param {Object} o The item to remove.
12409 * @return {Object} The item removed.
12411 remove : function(o){
12412 return this.removeAt(this.indexOf(o));
12416 * Remove an item from a specified index in the collection.
12417 * @param {Number} index The index within the collection of the item to remove.
12419 removeAt : function(index){
12420 if(index < this.length && index >= 0){
12422 var o = this.items[index];
12423 this.items.splice(index, 1);
12424 var key = this.keys[index];
12425 if(typeof key != "undefined"){
12426 delete this.map[key];
12428 this.keys.splice(index, 1);
12429 this.fireEvent("remove", o, key);
12434 * Removed an item associated with the passed key fom the collection.
12435 * @param {String} key The key of the item to remove.
12437 removeKey : function(key){
12438 return this.removeAt(this.indexOfKey(key));
12442 * Returns the number of items in the collection.
12443 * @return {Number} the number of items in the collection.
12445 getCount : function(){
12446 return this.length;
12450 * Returns index within the collection of the passed Object.
12451 * @param {Object} o The item to find the index of.
12452 * @return {Number} index of the item.
12454 indexOf : function(o){
12455 if(!this.items.indexOf){
12456 for(var i = 0, len = this.items.length; i < len; i++){
12457 if(this.items[i] == o) return i;
12461 return this.items.indexOf(o);
12466 * Returns index within the collection of the passed key.
12467 * @param {String} key The key to find the index of.
12468 * @return {Number} index of the key.
12470 indexOfKey : function(key){
12471 if(!this.keys.indexOf){
12472 for(var i = 0, len = this.keys.length; i < len; i++){
12473 if(this.keys[i] == key) return i;
12477 return this.keys.indexOf(key);
12482 * Returns the item associated with the passed key OR index. Key has priority over index.
12483 * @param {String/Number} key The key or index of the item.
12484 * @return {Object} The item associated with the passed key.
12486 item : function(key){
12487 var item = typeof this.map[key] != "undefined" ? this.map[key] : this.items[key];
12488 return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype!
12492 * Returns the item at the specified index.
12493 * @param {Number} index The index of the item.
12496 itemAt : function(index){
12497 return this.items[index];
12501 * Returns the item associated with the passed key.
12502 * @param {String/Number} key The key of the item.
12503 * @return {Object} The item associated with the passed key.
12505 key : function(key){
12506 return this.map[key];
12510 * Returns true if the collection contains the passed Object as an item.
12511 * @param {Object} o The Object to look for in the collection.
12512 * @return {Boolean} True if the collection contains the Object as an item.
12514 contains : function(o){
12515 return this.indexOf(o) != -1;
12519 * Returns true if the collection contains the passed Object as a key.
12520 * @param {String} key The key to look for in the collection.
12521 * @return {Boolean} True if the collection contains the Object as a key.
12523 containsKey : function(key){
12524 return typeof this.map[key] != "undefined";
12528 * Removes all items from the collection.
12530 clear : function(){
12535 this.fireEvent("clear");
12539 * Returns the first item in the collection.
12540 * @return {Object} the first item in the collection..
12542 first : function(){
12543 return this.items[0];
12547 * Returns the last item in the collection.
12548 * @return {Object} the last item in the collection..
12551 return this.items[this.length-1];
12554 _sort : function(property, dir, fn){
12555 var dsc = String(dir).toUpperCase() == "DESC" ? -1 : 1;
12556 fn = fn || function(a, b){
12559 var c = [], k = this.keys, items = this.items;
12560 for(var i = 0, len = items.length; i < len; i++){
12561 c[c.length] = {key: k[i], value: items[i], index: i};
12563 c.sort(function(a, b){
12564 var v = fn(a[property], b[property]) * dsc;
12566 v = (a.index < b.index ? -1 : 1);
12570 for(var i = 0, len = c.length; i < len; i++){
12571 items[i] = c[i].value;
12574 this.fireEvent("sort", this);
12578 * Sorts this collection with the passed comparison function
12579 * @param {String} direction (optional) "ASC" or "DESC"
12580 * @param {Function} fn (optional) comparison function
12582 sort : function(dir, fn){
12583 this._sort("value", dir, fn);
12587 * Sorts this collection by keys
12588 * @param {String} direction (optional) "ASC" or "DESC"
12589 * @param {Function} fn (optional) a comparison function (defaults to case insensitive string)
12591 keySort : function(dir, fn){
12592 this._sort("key", dir, fn || function(a, b){
12593 return String(a).toUpperCase()-String(b).toUpperCase();
12598 * Returns a range of items in this collection
12599 * @param {Number} startIndex (optional) defaults to 0
12600 * @param {Number} endIndex (optional) default to the last item
12601 * @return {Array} An array of items
12603 getRange : function(start, end){
12604 var items = this.items;
12605 if(items.length < 1){
12608 start = start || 0;
12609 end = Math.min(typeof end == "undefined" ? this.length-1 : end, this.length-1);
12612 for(var i = start; i <= end; i++) {
12613 r[r.length] = items[i];
12616 for(var i = start; i >= end; i--) {
12617 r[r.length] = items[i];
12624 * Filter the <i>objects</i> in this collection by a specific property.
12625 * Returns a new collection that has been filtered.
12626 * @param {String} property A property on your objects
12627 * @param {String/RegExp} value Either string that the property values
12628 * should start with or a RegExp to test against the property
12629 * @return {MixedCollection} The new filtered collection
12631 filter : function(property, value){
12632 if(!value.exec){ // not a regex
12633 value = String(value);
12634 if(value.length == 0){
12635 return this.clone();
12637 value = new RegExp("^" + Roo.escapeRe(value), "i");
12639 return this.filterBy(function(o){
12640 return o && value.test(o[property]);
12645 * Filter by a function. * Returns a new collection that has been filtered.
12646 * The passed function will be called with each
12647 * object in the collection. If the function returns true, the value is included
12648 * otherwise it is filtered.
12649 * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
12650 * @param {Object} scope (optional) The scope of the function (defaults to this)
12651 * @return {MixedCollection} The new filtered collection
12653 filterBy : function(fn, scope){
12654 var r = new Roo.util.MixedCollection();
12655 r.getKey = this.getKey;
12656 var k = this.keys, it = this.items;
12657 for(var i = 0, len = it.length; i < len; i++){
12658 if(fn.call(scope||this, it[i], k[i])){
12659 r.add(k[i], it[i]);
12666 * Creates a duplicate of this collection
12667 * @return {MixedCollection}
12669 clone : function(){
12670 var r = new Roo.util.MixedCollection();
12671 var k = this.keys, it = this.items;
12672 for(var i = 0, len = it.length; i < len; i++){
12673 r.add(k[i], it[i]);
12675 r.getKey = this.getKey;
12680 * Returns the item associated with the passed key or index.
12682 * @param {String/Number} key The key or index of the item.
12683 * @return {Object} The item associated with the passed key.
12685 Roo.util.MixedCollection.prototype.get = Roo.util.MixedCollection.prototype.item;/*
12687 * Ext JS Library 1.1.1
12688 * Copyright(c) 2006-2007, Ext JS, LLC.
12690 * Originally Released Under LGPL - original licence link has changed is not relivant.
12693 * <script type="text/javascript">
12696 * @class Roo.util.JSON
12697 * Modified version of Douglas Crockford"s json.js that doesn"t
12698 * mess with the Object prototype
12699 * http://www.json.org/js.html
12702 Roo.util.JSON = new (function(){
12703 var useHasOwn = {}.hasOwnProperty ? true : false;
12705 // crashes Safari in some instances
12706 //var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
12708 var pad = function(n) {
12709 return n < 10 ? "0" + n : n;
12722 var encodeString = function(s){
12723 if (/["\\\x00-\x1f]/.test(s)) {
12724 return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
12729 c = b.charCodeAt();
12731 Math.floor(c / 16).toString(16) +
12732 (c % 16).toString(16);
12735 return '"' + s + '"';
12738 var encodeArray = function(o){
12739 var a = ["["], b, i, l = o.length, v;
12740 for (i = 0; i < l; i += 1) {
12742 switch (typeof v) {
12751 a.push(v === null ? "null" : Roo.util.JSON.encode(v));
12759 var encodeDate = function(o){
12760 return '"' + o.getFullYear() + "-" +
12761 pad(o.getMonth() + 1) + "-" +
12762 pad(o.getDate()) + "T" +
12763 pad(o.getHours()) + ":" +
12764 pad(o.getMinutes()) + ":" +
12765 pad(o.getSeconds()) + '"';
12769 * Encodes an Object, Array or other value
12770 * @param {Mixed} o The variable to encode
12771 * @return {String} The JSON string
12773 this.encode = function(o){
12774 if(typeof o == "undefined" || o === null){
12776 }else if(o instanceof Array){
12777 return encodeArray(o);
12778 }else if(o instanceof Date){
12779 return encodeDate(o);
12780 }else if(typeof o == "string"){
12781 return encodeString(o);
12782 }else if(typeof o == "number"){
12783 return isFinite(o) ? String(o) : "null";
12784 }else if(typeof o == "boolean"){
12787 var a = ["{"], b, i, v;
12789 if(!useHasOwn || o.hasOwnProperty(i)) {
12791 switch (typeof v) {
12800 a.push(this.encode(i), ":",
12801 v === null ? "null" : this.encode(v));
12812 * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError.
12813 * @param {String} json The JSON string
12814 * @return {Object} The resulting object
12816 this.decode = function(json){
12818 return /** eval:var:json */ eval("(" + json + ')');
12822 * Shorthand for {@link Roo.util.JSON#encode}
12823 * @member Roo encode
12825 Roo.encode = Roo.util.JSON.encode;
12827 * Shorthand for {@link Roo.util.JSON#decode}
12828 * @member Roo decode
12830 Roo.decode = Roo.util.JSON.decode;
12833 * Ext JS Library 1.1.1
12834 * Copyright(c) 2006-2007, Ext JS, LLC.
12836 * Originally Released Under LGPL - original licence link has changed is not relivant.
12839 * <script type="text/javascript">
12843 * @class Roo.util.Format
12844 * Reusable data formatting functions
12847 Roo.util.Format = function(){
12848 var trimRe = /^\s+|\s+$/g;
12851 * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
12852 * @param {String} value The string to truncate
12853 * @param {Number} length The maximum length to allow before truncating
12854 * @return {String} The converted text
12856 ellipsis : function(value, len){
12857 if(value && value.length > len){
12858 return value.substr(0, len-3)+"...";
12864 * Checks a reference and converts it to empty string if it is undefined
12865 * @param {Mixed} value Reference to check
12866 * @return {Mixed} Empty string if converted, otherwise the original value
12868 undef : function(value){
12869 return typeof value != "undefined" ? value : "";
12873 * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
12874 * @param {String} value The string to encode
12875 * @return {String} The encoded text
12877 htmlEncode : function(value){
12878 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
12882 * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
12883 * @param {String} value The string to decode
12884 * @return {String} The decoded text
12886 htmlDecode : function(value){
12887 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"');
12891 * Trims any whitespace from either side of a string
12892 * @param {String} value The text to trim
12893 * @return {String} The trimmed text
12895 trim : function(value){
12896 return String(value).replace(trimRe, "");
12900 * Returns a substring from within an original string
12901 * @param {String} value The original text
12902 * @param {Number} start The start index of the substring
12903 * @param {Number} length The length of the substring
12904 * @return {String} The substring
12906 substr : function(value, start, length){
12907 return String(value).substr(start, length);
12911 * Converts a string to all lower case letters
12912 * @param {String} value The text to convert
12913 * @return {String} The converted text
12915 lowercase : function(value){
12916 return String(value).toLowerCase();
12920 * Converts a string to all upper case letters
12921 * @param {String} value The text to convert
12922 * @return {String} The converted text
12924 uppercase : function(value){
12925 return String(value).toUpperCase();
12929 * Converts the first character only of a string to upper case
12930 * @param {String} value The text to convert
12931 * @return {String} The converted text
12933 capitalize : function(value){
12934 return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
12938 call : function(value, fn){
12939 if(arguments.length > 2){
12940 var args = Array.prototype.slice.call(arguments, 2);
12941 args.unshift(value);
12943 return /** eval:var:value */ eval(fn).apply(window, args);
12945 /** eval:var:value */
12946 return /** eval:var:value */ eval(fn).call(window, value);
12951 * Format a number as US currency
12952 * @param {Number/String} value The numeric value to format
12953 * @return {String} The formatted currency string
12955 usMoney : function(v){
12956 v = (Math.round((v-0)*100))/100;
12957 v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
12959 var ps = v.split('.');
12961 var sub = ps[1] ? '.'+ ps[1] : '.00';
12962 var r = /(\d+)(\d{3})/;
12963 while (r.test(whole)) {
12964 whole = whole.replace(r, '$1' + ',' + '$2');
12966 return "$" + whole + sub ;
12970 * Parse a value into a formatted date using the specified format pattern.
12971 * @param {Mixed} value The value to format
12972 * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
12973 * @return {String} The formatted date string
12975 date : function(v, format){
12979 if(!(v instanceof Date)){
12980 v = new Date(Date.parse(v));
12982 return v.dateFormat(format || "m/d/Y");
12986 * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
12987 * @param {String} format Any valid date format string
12988 * @return {Function} The date formatting function
12990 dateRenderer : function(format){
12991 return function(v){
12992 return Roo.util.Format.date(v, format);
12997 stripTagsRE : /<\/?[^>]+>/gi,
13000 * Strips all HTML tags
13001 * @param {Mixed} value The text from which to strip tags
13002 * @return {String} The stripped text
13004 stripTags : function(v){
13005 return !v ? v : String(v).replace(this.stripTagsRE, "");
13010 * Ext JS Library 1.1.1
13011 * Copyright(c) 2006-2007, Ext JS, LLC.
13013 * Originally Released Under LGPL - original licence link has changed is not relivant.
13016 * <script type="text/javascript">
13023 * @class Roo.MasterTemplate
13024 * @extends Roo.Template
13025 * Provides a template that can have child templates. The syntax is:
13027 var t = new Roo.MasterTemplate(
13028 '<select name="{name}">',
13029 '<tpl name="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
13032 t.add('options', {value: 'foo', text: 'bar'});
13033 // or you can add multiple child elements in one shot
13034 t.addAll('options', [
13035 {value: 'foo', text: 'bar'},
13036 {value: 'foo2', text: 'bar2'},
13037 {value: 'foo3', text: 'bar3'}
13039 // then append, applying the master template values
13040 t.append('my-form', {name: 'my-select'});
13042 * A name attribute for the child template is not required if you have only one child
13043 * template or you want to refer to them by index.
13045 Roo.MasterTemplate = function(){
13046 Roo.MasterTemplate.superclass.constructor.apply(this, arguments);
13047 this.originalHtml = this.html;
13049 var m, re = this.subTemplateRe;
13052 while(m = re.exec(this.html)){
13053 var name = m[1], content = m[2];
13058 tpl : new Roo.Template(content)
13061 st[name] = st[subIndex];
13063 st[subIndex].tpl.compile();
13064 st[subIndex].tpl.call = this.call.createDelegate(this);
13067 this.subCount = subIndex;
13070 Roo.extend(Roo.MasterTemplate, Roo.Template, {
13072 * The regular expression used to match sub templates
13076 subTemplateRe : /<tpl(?:\sname="([\w-]+)")?>((?:.|\n)*?)<\/tpl>/gi,
13079 * Applies the passed values to a child template.
13080 * @param {String/Number} name (optional) The name or index of the child template
13081 * @param {Array/Object} values The values to be applied to the template
13082 * @return {MasterTemplate} this
13084 add : function(name, values){
13085 if(arguments.length == 1){
13086 values = arguments[0];
13089 var s = this.subs[name];
13090 s.buffer[s.buffer.length] = s.tpl.apply(values);
13095 * Applies all the passed values to a child template.
13096 * @param {String/Number} name (optional) The name or index of the child template
13097 * @param {Array} values The values to be applied to the template, this should be an array of objects.
13098 * @param {Boolean} reset (optional) True to reset the template first
13099 * @return {MasterTemplate} this
13101 fill : function(name, values, reset){
13103 if(a.length == 1 || (a.length == 2 && typeof a[1] == "boolean")){
13111 for(var i = 0, len = values.length; i < len; i++){
13112 this.add(name, values[i]);
13118 * Resets the template for reuse
13119 * @return {MasterTemplate} this
13121 reset : function(){
13123 for(var i = 0; i < this.subCount; i++){
13129 applyTemplate : function(values){
13131 var replaceIndex = -1;
13132 this.html = this.originalHtml.replace(this.subTemplateRe, function(m, name){
13133 return s[++replaceIndex].buffer.join("");
13135 return Roo.MasterTemplate.superclass.applyTemplate.call(this, values);
13138 apply : function(){
13139 return this.applyTemplate.apply(this, arguments);
13142 compile : function(){return this;}
13146 * Alias for fill().
13149 Roo.MasterTemplate.prototype.addAll = Roo.MasterTemplate.prototype.fill;
13151 * Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML. e.g.
13152 * var tpl = Roo.MasterTemplate.from('element-id');
13153 * @param {String/HTMLElement} el
13154 * @param {Object} config
13157 Roo.MasterTemplate.from = function(el, config){
13158 el = Roo.getDom(el);
13159 return new Roo.MasterTemplate(el.value || el.innerHTML, config || '');
13162 * Ext JS Library 1.1.1
13163 * Copyright(c) 2006-2007, Ext JS, LLC.
13165 * Originally Released Under LGPL - original licence link has changed is not relivant.
13168 * <script type="text/javascript">
13173 * @class Roo.util.CSS
13174 * Utility class for manipulating CSS rules
13177 Roo.util.CSS = function(){
13179 var doc = document;
13181 var camelRe = /(-[a-z])/gi;
13182 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
13186 * Very simple dynamic creation of stylesheets from a text blob of rules. The text will wrapped in a style
13187 * tag and appended to the HEAD of the document.
13188 * @param {String|Object} cssText The text containing the css rules
13189 * @param {String} id An id to add to the stylesheet for later removal
13190 * @return {StyleSheet}
13192 createStyleSheet : function(cssText, id){
13194 var head = doc.getElementsByTagName("head")[0];
13195 var nrules = doc.createElement("style");
13196 nrules.setAttribute("type", "text/css");
13198 nrules.setAttribute("id", id);
13200 if (typeof(cssText) != 'string') {
13201 // support object maps..
13202 // not sure if this a good idea..
13203 // perhaps it should be merged with the general css handling
13204 // and handle js style props.
13205 var cssTextNew = [];
13206 for(var n in cssText) {
13208 for(var k in cssText[n]) {
13209 citems.push( k + ' : ' +cssText[n][k] + ';' );
13211 cssTextNew.push( n + ' { ' + citems.join(' ') + '} ');
13214 cssText = cssTextNew.join("\n");
13220 head.appendChild(nrules);
13221 ss = nrules.styleSheet;
13222 ss.cssText = cssText;
13225 nrules.appendChild(doc.createTextNode(cssText));
13227 nrules.cssText = cssText;
13229 head.appendChild(nrules);
13230 ss = nrules.styleSheet ? nrules.styleSheet : (nrules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
13232 this.cacheStyleSheet(ss);
13237 * Removes a style or link tag by id
13238 * @param {String} id The id of the tag
13240 removeStyleSheet : function(id){
13241 var existing = doc.getElementById(id);
13243 existing.parentNode.removeChild(existing);
13248 * Dynamically swaps an existing stylesheet reference for a new one
13249 * @param {String} id The id of an existing link tag to remove
13250 * @param {String} url The href of the new stylesheet to include
13252 swapStyleSheet : function(id, url){
13253 this.removeStyleSheet(id);
13254 var ss = doc.createElement("link");
13255 ss.setAttribute("rel", "stylesheet");
13256 ss.setAttribute("type", "text/css");
13257 ss.setAttribute("id", id);
13258 ss.setAttribute("href", url);
13259 doc.getElementsByTagName("head")[0].appendChild(ss);
13263 * Refresh the rule cache if you have dynamically added stylesheets
13264 * @return {Object} An object (hash) of rules indexed by selector
13266 refreshCache : function(){
13267 return this.getRules(true);
13271 cacheStyleSheet : function(stylesheet){
13275 try{// try catch for cross domain access issue
13276 var ssRules = stylesheet.cssRules || stylesheet.rules;
13277 for(var j = ssRules.length-1; j >= 0; --j){
13278 rules[ssRules[j].selectorText] = ssRules[j];
13284 * Gets all css rules for the document
13285 * @param {Boolean} refreshCache true to refresh the internal cache
13286 * @return {Object} An object (hash) of rules indexed by selector
13288 getRules : function(refreshCache){
13289 if(rules == null || refreshCache){
13291 var ds = doc.styleSheets;
13292 for(var i =0, len = ds.length; i < len; i++){
13294 this.cacheStyleSheet(ds[i]);
13302 * Gets an an individual CSS rule by selector(s)
13303 * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
13304 * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
13305 * @return {CSSRule} The CSS rule or null if one is not found
13307 getRule : function(selector, refreshCache){
13308 var rs = this.getRules(refreshCache);
13309 if(!(selector instanceof Array)){
13310 return rs[selector];
13312 for(var i = 0; i < selector.length; i++){
13313 if(rs[selector[i]]){
13314 return rs[selector[i]];
13322 * Updates a rule property
13323 * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
13324 * @param {String} property The css property
13325 * @param {String} value The new value for the property
13326 * @return {Boolean} true If a rule was found and updated
13328 updateRule : function(selector, property, value){
13329 if(!(selector instanceof Array)){
13330 var rule = this.getRule(selector);
13332 rule.style[property.replace(camelRe, camelFn)] = value;
13336 for(var i = 0; i < selector.length; i++){
13337 if(this.updateRule(selector[i], property, value)){
13347 * Ext JS Library 1.1.1
13348 * Copyright(c) 2006-2007, Ext JS, LLC.
13350 * Originally Released Under LGPL - original licence link has changed is not relivant.
13353 * <script type="text/javascript">
13359 * @class Roo.util.ClickRepeater
13360 * @extends Roo.util.Observable
13362 * A wrapper class which can be applied to any element. Fires a "click" event while the
13363 * mouse is pressed. The interval between firings may be specified in the config but
13364 * defaults to 10 milliseconds.
13366 * Optionally, a CSS class may be applied to the element during the time it is pressed.
13368 * @cfg {String/HTMLElement/Element} el The element to act as a button.
13369 * @cfg {Number} delay The initial delay before the repeating event begins firing.
13370 * Similar to an autorepeat key delay.
13371 * @cfg {Number} interval The interval between firings of the "click" event. Default 10 ms.
13372 * @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
13373 * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
13374 * "interval" and "delay" are ignored. "immediate" is honored.
13375 * @cfg {Boolean} preventDefault True to prevent the default click event
13376 * @cfg {Boolean} stopDefault True to stop the default click event
13379 * 2007-02-02 jvs Original code contributed by Nige "Animal" White
13380 * 2007-02-02 jvs Renamed to ClickRepeater
13381 * 2007-02-03 jvs Modifications for FF Mac and Safari
13384 * @param {String/HTMLElement/Element} el The element to listen on
13385 * @param {Object} config
13387 Roo.util.ClickRepeater = function(el, config)
13389 this.el = Roo.get(el);
13390 this.el.unselectable();
13392 Roo.apply(this, config);
13397 * Fires when the mouse button is depressed.
13398 * @param {Roo.util.ClickRepeater} this
13400 "mousedown" : true,
13403 * Fires on a specified interval during the time the element is pressed.
13404 * @param {Roo.util.ClickRepeater} this
13409 * Fires when the mouse key is released.
13410 * @param {Roo.util.ClickRepeater} this
13415 this.el.on("mousedown", this.handleMouseDown, this);
13416 if(this.preventDefault || this.stopDefault){
13417 this.el.on("click", function(e){
13418 if(this.preventDefault){
13419 e.preventDefault();
13421 if(this.stopDefault){
13427 // allow inline handler
13429 this.on("click", this.handler, this.scope || this);
13432 Roo.util.ClickRepeater.superclass.constructor.call(this);
13435 Roo.extend(Roo.util.ClickRepeater, Roo.util.Observable, {
13438 preventDefault : true,
13439 stopDefault : false,
13443 handleMouseDown : function(){
13444 clearTimeout(this.timer);
13446 if(this.pressClass){
13447 this.el.addClass(this.pressClass);
13449 this.mousedownTime = new Date();
13451 Roo.get(document).on("mouseup", this.handleMouseUp, this);
13452 this.el.on("mouseout", this.handleMouseOut, this);
13454 this.fireEvent("mousedown", this);
13455 this.fireEvent("click", this);
13457 this.timer = this.click.defer(this.delay || this.interval, this);
13461 click : function(){
13462 this.fireEvent("click", this);
13463 this.timer = this.click.defer(this.getInterval(), this);
13467 getInterval: function(){
13468 if(!this.accelerate){
13469 return this.interval;
13471 var pressTime = this.mousedownTime.getElapsed();
13472 if(pressTime < 500){
13474 }else if(pressTime < 1700){
13476 }else if(pressTime < 2600){
13478 }else if(pressTime < 3500){
13480 }else if(pressTime < 4400){
13482 }else if(pressTime < 5300){
13484 }else if(pressTime < 6200){
13492 handleMouseOut : function(){
13493 clearTimeout(this.timer);
13494 if(this.pressClass){
13495 this.el.removeClass(this.pressClass);
13497 this.el.on("mouseover", this.handleMouseReturn, this);
13501 handleMouseReturn : function(){
13502 this.el.un("mouseover", this.handleMouseReturn);
13503 if(this.pressClass){
13504 this.el.addClass(this.pressClass);
13510 handleMouseUp : function(){
13511 clearTimeout(this.timer);
13512 this.el.un("mouseover", this.handleMouseReturn);
13513 this.el.un("mouseout", this.handleMouseOut);
13514 Roo.get(document).un("mouseup", this.handleMouseUp);
13515 this.el.removeClass(this.pressClass);
13516 this.fireEvent("mouseup", this);
13520 * Ext JS Library 1.1.1
13521 * Copyright(c) 2006-2007, Ext JS, LLC.
13523 * Originally Released Under LGPL - original licence link has changed is not relivant.
13526 * <script type="text/javascript">
13531 * @class Roo.KeyNav
13532 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
13533 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
13534 * way to implement custom navigation schemes for any UI component.</p>
13535 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
13536 * pageUp, pageDown, del, home, end. Usage:</p>
13538 var nav = new Roo.KeyNav("my-element", {
13539 "left" : function(e){
13540 this.moveLeft(e.ctrlKey);
13542 "right" : function(e){
13543 this.moveRight(e.ctrlKey);
13545 "enter" : function(e){
13552 * @param {String/HTMLElement/Roo.Element} el The element to bind to
13553 * @param {Object} config The config
13555 Roo.KeyNav = function(el, config){
13556 this.el = Roo.get(el);
13557 Roo.apply(this, config);
13558 if(!this.disabled){
13559 this.disabled = true;
13564 Roo.KeyNav.prototype = {
13566 * @cfg {Boolean} disabled
13567 * True to disable this KeyNav instance (defaults to false)
13571 * @cfg {String} defaultEventAction
13572 * The method to call on the {@link Roo.EventObject} after this KeyNav intercepts a key. Valid values are
13573 * {@link Roo.EventObject#stopEvent}, {@link Roo.EventObject#preventDefault} and
13574 * {@link Roo.EventObject#stopPropagation} (defaults to 'stopEvent')
13576 defaultEventAction: "stopEvent",
13578 * @cfg {Boolean} forceKeyDown
13579 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
13580 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
13581 * handle keydown instead of keypress.
13583 forceKeyDown : false,
13586 prepareEvent : function(e){
13587 var k = e.getKey();
13588 var h = this.keyToHandler[k];
13589 //if(h && this[h]){
13590 // e.stopPropagation();
13592 if(Roo.isSafari && h && k >= 37 && k <= 40){
13598 relay : function(e){
13599 var k = e.getKey();
13600 var h = this.keyToHandler[k];
13602 if(this.doRelay(e, this[h], h) !== true){
13603 e[this.defaultEventAction]();
13609 doRelay : function(e, h, hname){
13610 return h.call(this.scope || this, e);
13613 // possible handlers
13627 // quick lookup hash
13644 * Enable this KeyNav
13646 enable: function(){
13648 // ie won't do special keys on keypress, no one else will repeat keys with keydown
13649 // the EventObject will normalize Safari automatically
13650 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
13651 this.el.on("keydown", this.relay, this);
13653 this.el.on("keydown", this.prepareEvent, this);
13654 this.el.on("keypress", this.relay, this);
13656 this.disabled = false;
13661 * Disable this KeyNav
13663 disable: function(){
13664 if(!this.disabled){
13665 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
13666 this.el.un("keydown", this.relay);
13668 this.el.un("keydown", this.prepareEvent);
13669 this.el.un("keypress", this.relay);
13671 this.disabled = true;
13676 * Ext JS Library 1.1.1
13677 * Copyright(c) 2006-2007, Ext JS, LLC.
13679 * Originally Released Under LGPL - original licence link has changed is not relivant.
13682 * <script type="text/javascript">
13687 * @class Roo.KeyMap
13688 * Handles mapping keys to actions for an element. One key map can be used for multiple actions.
13689 * The constructor accepts the same config object as defined by {@link #addBinding}.
13690 * If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
13691 * combination it will call the function with this signature (if the match is a multi-key
13692 * combination the callback will still be called only once): (String key, Roo.EventObject e)
13693 * A KeyMap can also handle a string representation of keys.<br />
13696 // map one key by key code
13697 var map = new Roo.KeyMap("my-element", {
13698 key: 13, // or Roo.EventObject.ENTER
13703 // map multiple keys to one action by string
13704 var map = new Roo.KeyMap("my-element", {
13710 // map multiple keys to multiple actions by strings and array of codes
13711 var map = new Roo.KeyMap("my-element", [
13714 fn: function(){ alert("Return was pressed"); }
13717 fn: function(){ alert('a, b or c was pressed'); }
13722 fn: function(){ alert('Control + shift + tab was pressed.'); }
13726 * <b>Note: A KeyMap starts enabled</b>
13728 * @param {String/HTMLElement/Roo.Element} el The element to bind to
13729 * @param {Object} config The config (see {@link #addBinding})
13730 * @param {String} eventName (optional) The event to bind to (defaults to "keydown")
13732 Roo.KeyMap = function(el, config, eventName){
13733 this.el = Roo.get(el);
13734 this.eventName = eventName || "keydown";
13735 this.bindings = [];
13737 this.addBinding(config);
13742 Roo.KeyMap.prototype = {
13744 * True to stop the event from bubbling and prevent the default browser action if the
13745 * key was handled by the KeyMap (defaults to false)
13751 * Add a new binding to this KeyMap. The following config object properties are supported:
13753 Property Type Description
13754 ---------- --------------- ----------------------------------------------------------------------
13755 key String/Array A single keycode or an array of keycodes to handle
13756 shift Boolean True to handle key only when shift is pressed (defaults to false)
13757 ctrl Boolean True to handle key only when ctrl is pressed (defaults to false)
13758 alt Boolean True to handle key only when alt is pressed (defaults to false)
13759 fn Function The function to call when KeyMap finds the expected key combination
13760 scope Object The scope of the callback function
13766 var map = new Roo.KeyMap(document, {
13767 key: Roo.EventObject.ENTER,
13772 //Add a new binding to the existing KeyMap later
13780 * @param {Object/Array} config A single KeyMap config or an array of configs
13782 addBinding : function(config){
13783 if(config instanceof Array){
13784 for(var i = 0, len = config.length; i < len; i++){
13785 this.addBinding(config[i]);
13789 var keyCode = config.key,
13790 shift = config.shift,
13791 ctrl = config.ctrl,
13794 scope = config.scope;
13795 if(typeof keyCode == "string"){
13797 var keyString = keyCode.toUpperCase();
13798 for(var j = 0, len = keyString.length; j < len; j++){
13799 ks.push(keyString.charCodeAt(j));
13803 var keyArray = keyCode instanceof Array;
13804 var handler = function(e){
13805 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
13806 var k = e.getKey();
13808 for(var i = 0, len = keyCode.length; i < len; i++){
13809 if(keyCode[i] == k){
13810 if(this.stopEvent){
13813 fn.call(scope || window, k, e);
13819 if(this.stopEvent){
13822 fn.call(scope || window, k, e);
13827 this.bindings.push(handler);
13831 * Shorthand for adding a single key listener
13832 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the
13833 * following options:
13834 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
13835 * @param {Function} fn The function to call
13836 * @param {Object} scope (optional) The scope of the function
13838 on : function(key, fn, scope){
13839 var keyCode, shift, ctrl, alt;
13840 if(typeof key == "object" && !(key instanceof Array)){
13859 handleKeyDown : function(e){
13860 if(this.enabled){ //just in case
13861 var b = this.bindings;
13862 for(var i = 0, len = b.length; i < len; i++){
13863 b[i].call(this, e);
13869 * Returns true if this KeyMap is enabled
13870 * @return {Boolean}
13872 isEnabled : function(){
13873 return this.enabled;
13877 * Enables this KeyMap
13879 enable: function(){
13881 this.el.on(this.eventName, this.handleKeyDown, this);
13882 this.enabled = true;
13887 * Disable this KeyMap
13889 disable: function(){
13891 this.el.removeListener(this.eventName, this.handleKeyDown, this);
13892 this.enabled = false;
13897 * Ext JS Library 1.1.1
13898 * Copyright(c) 2006-2007, Ext JS, LLC.
13900 * Originally Released Under LGPL - original licence link has changed is not relivant.
13903 * <script type="text/javascript">
13908 * @class Roo.util.TextMetrics
13909 * Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
13910 * wide, in pixels, a given block of text will be.
13913 Roo.util.TextMetrics = function(){
13917 * Measures the size of the specified text
13918 * @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
13919 * that can affect the size of the rendered text
13920 * @param {String} text The text to measure
13921 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
13922 * in order to accurately measure the text height
13923 * @return {Object} An object containing the text's size {width: (width), height: (height)}
13925 measure : function(el, text, fixedWidth){
13927 shared = Roo.util.TextMetrics.Instance(el, fixedWidth);
13930 shared.setFixedWidth(fixedWidth || 'auto');
13931 return shared.getSize(text);
13935 * Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
13936 * the overhead of multiple calls to initialize the style properties on each measurement.
13937 * @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
13938 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
13939 * in order to accurately measure the text height
13940 * @return {Roo.util.TextMetrics.Instance} instance The new instance
13942 createInstance : function(el, fixedWidth){
13943 return Roo.util.TextMetrics.Instance(el, fixedWidth);
13950 Roo.util.TextMetrics.Instance = function(bindTo, fixedWidth){
13951 var ml = new Roo.Element(document.createElement('div'));
13952 document.body.appendChild(ml.dom);
13953 ml.position('absolute');
13954 ml.setLeftTop(-1000, -1000);
13958 ml.setWidth(fixedWidth);
13963 * Returns the size of the specified text based on the internal element's style and width properties
13964 * @memberOf Roo.util.TextMetrics.Instance#
13965 * @param {String} text The text to measure
13966 * @return {Object} An object containing the text's size {width: (width), height: (height)}
13968 getSize : function(text){
13970 var s = ml.getSize();
13976 * Binds this TextMetrics instance to an element from which to copy existing CSS styles
13977 * that can affect the size of the rendered text
13978 * @memberOf Roo.util.TextMetrics.Instance#
13979 * @param {String/HTMLElement} el The element, dom node or id
13981 bind : function(el){
13983 Roo.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height')
13988 * Sets a fixed width on the internal measurement element. If the text will be multiline, you have
13989 * to set a fixed width in order to accurately measure the text height.
13990 * @memberOf Roo.util.TextMetrics.Instance#
13991 * @param {Number} width The width to set on the element
13993 setFixedWidth : function(width){
13994 ml.setWidth(width);
13998 * Returns the measured width of the specified text
13999 * @memberOf Roo.util.TextMetrics.Instance#
14000 * @param {String} text The text to measure
14001 * @return {Number} width The width in pixels
14003 getWidth : function(text){
14004 ml.dom.style.width = 'auto';
14005 return this.getSize(text).width;
14009 * Returns the measured height of the specified text. For multiline text, be sure to call
14010 * {@link #setFixedWidth} if necessary.
14011 * @memberOf Roo.util.TextMetrics.Instance#
14012 * @param {String} text The text to measure
14013 * @return {Number} height The height in pixels
14015 getHeight : function(text){
14016 return this.getSize(text).height;
14020 instance.bind(bindTo);
14025 // backwards compat
14026 Roo.Element.measureText = Roo.util.TextMetrics.measure;/*
14028 * Ext JS Library 1.1.1
14029 * Copyright(c) 2006-2007, Ext JS, LLC.
14031 * Originally Released Under LGPL - original licence link has changed is not relivant.
14034 * <script type="text/javascript">
14038 * @class Roo.state.Provider
14039 * Abstract base class for state provider implementations. This class provides methods
14040 * for encoding and decoding <b>typed</b> variables including dates and defines the
14041 * Provider interface.
14043 Roo.state.Provider = function(){
14045 * @event statechange
14046 * Fires when a state change occurs.
14047 * @param {Provider} this This state provider
14048 * @param {String} key The state key which was changed
14049 * @param {String} value The encoded value for the state
14052 "statechange": true
14055 Roo.state.Provider.superclass.constructor.call(this);
14057 Roo.extend(Roo.state.Provider, Roo.util.Observable, {
14059 * Returns the current value for a key
14060 * @param {String} name The key name
14061 * @param {Mixed} defaultValue A default value to return if the key's value is not found
14062 * @return {Mixed} The state data
14064 get : function(name, defaultValue){
14065 return typeof this.state[name] == "undefined" ?
14066 defaultValue : this.state[name];
14070 * Clears a value from the state
14071 * @param {String} name The key name
14073 clear : function(name){
14074 delete this.state[name];
14075 this.fireEvent("statechange", this, name, null);
14079 * Sets the value for a key
14080 * @param {String} name The key name
14081 * @param {Mixed} value The value to set
14083 set : function(name, value){
14084 this.state[name] = value;
14085 this.fireEvent("statechange", this, name, value);
14089 * Decodes a string previously encoded with {@link #encodeValue}.
14090 * @param {String} value The value to decode
14091 * @return {Mixed} The decoded value
14093 decodeValue : function(cookie){
14094 var re = /^(a|n|d|b|s|o)\:(.*)$/;
14095 var matches = re.exec(unescape(cookie));
14096 if(!matches || !matches[1]) return; // non state cookie
14097 var type = matches[1];
14098 var v = matches[2];
14101 return parseFloat(v);
14103 return new Date(Date.parse(v));
14108 var values = v.split("^");
14109 for(var i = 0, len = values.length; i < len; i++){
14110 all.push(this.decodeValue(values[i]));
14115 var values = v.split("^");
14116 for(var i = 0, len = values.length; i < len; i++){
14117 var kv = values[i].split("=");
14118 all[kv[0]] = this.decodeValue(kv[1]);
14127 * Encodes a value including type information. Decode with {@link #decodeValue}.
14128 * @param {Mixed} value The value to encode
14129 * @return {String} The encoded value
14131 encodeValue : function(v){
14133 if(typeof v == "number"){
14135 }else if(typeof v == "boolean"){
14136 enc = "b:" + (v ? "1" : "0");
14137 }else if(v instanceof Date){
14138 enc = "d:" + v.toGMTString();
14139 }else if(v instanceof Array){
14141 for(var i = 0, len = v.length; i < len; i++){
14142 flat += this.encodeValue(v[i]);
14143 if(i != len-1) flat += "^";
14146 }else if(typeof v == "object"){
14149 if(typeof v[key] != "function"){
14150 flat += key + "=" + this.encodeValue(v[key]) + "^";
14153 enc = "o:" + flat.substring(0, flat.length-1);
14157 return escape(enc);
14163 * Ext JS Library 1.1.1
14164 * Copyright(c) 2006-2007, Ext JS, LLC.
14166 * Originally Released Under LGPL - original licence link has changed is not relivant.
14169 * <script type="text/javascript">
14172 * @class Roo.state.Manager
14173 * This is the global state manager. By default all components that are "state aware" check this class
14174 * for state information if you don't pass them a custom state provider. In order for this class
14175 * to be useful, it must be initialized with a provider when your application initializes.
14177 // in your initialization function
14179 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
14181 // supposed you have a {@link Roo.BorderLayout}
14182 var layout = new Roo.BorderLayout(...);
14183 layout.restoreState();
14184 // or a {Roo.BasicDialog}
14185 var dialog = new Roo.BasicDialog(...);
14186 dialog.restoreState();
14190 Roo.state.Manager = function(){
14191 var provider = new Roo.state.Provider();
14195 * Configures the default state provider for your application
14196 * @param {Provider} stateProvider The state provider to set
14198 setProvider : function(stateProvider){
14199 provider = stateProvider;
14203 * Returns the current value for a key
14204 * @param {String} name The key name
14205 * @param {Mixed} defaultValue The default value to return if the key lookup does not match
14206 * @return {Mixed} The state data
14208 get : function(key, defaultValue){
14209 return provider.get(key, defaultValue);
14213 * Sets the value for a key
14214 * @param {String} name The key name
14215 * @param {Mixed} value The state data
14217 set : function(key, value){
14218 provider.set(key, value);
14222 * Clears a value from the state
14223 * @param {String} name The key name
14225 clear : function(key){
14226 provider.clear(key);
14230 * Gets the currently configured state provider
14231 * @return {Provider} The state provider
14233 getProvider : function(){
14240 * Ext JS Library 1.1.1
14241 * Copyright(c) 2006-2007, Ext JS, LLC.
14243 * Originally Released Under LGPL - original licence link has changed is not relivant.
14246 * <script type="text/javascript">
14249 * @class Roo.state.CookieProvider
14250 * @extends Roo.state.Provider
14251 * The default Provider implementation which saves state via cookies.
14254 var cp = new Roo.state.CookieProvider({
14256 expires: new Date(new Date().getTime()+(1000*60*60*24*30)); //30 days
14257 domain: "roojs.com"
14259 Roo.state.Manager.setProvider(cp);
14261 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
14262 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
14263 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
14264 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'roojs.com' to include
14265 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
14266 * domain the page is running on including the 'www' like 'www.roojs.com')
14267 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
14269 * Create a new CookieProvider
14270 * @param {Object} config The configuration object
14272 Roo.state.CookieProvider = function(config){
14273 Roo.state.CookieProvider.superclass.constructor.call(this);
14275 this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
14276 this.domain = null;
14277 this.secure = false;
14278 Roo.apply(this, config);
14279 this.state = this.readCookies();
14282 Roo.extend(Roo.state.CookieProvider, Roo.state.Provider, {
14284 set : function(name, value){
14285 if(typeof value == "undefined" || value === null){
14289 this.setCookie(name, value);
14290 Roo.state.CookieProvider.superclass.set.call(this, name, value);
14294 clear : function(name){
14295 this.clearCookie(name);
14296 Roo.state.CookieProvider.superclass.clear.call(this, name);
14300 readCookies : function(){
14302 var c = document.cookie + ";";
14303 var re = /\s?(.*?)=(.*?);/g;
14305 while((matches = re.exec(c)) != null){
14306 var name = matches[1];
14307 var value = matches[2];
14308 if(name && name.substring(0,3) == "ys-"){
14309 cookies[name.substr(3)] = this.decodeValue(value);
14316 setCookie : function(name, value){
14317 document.cookie = "ys-"+ name + "=" + this.encodeValue(value) +
14318 ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
14319 ((this.path == null) ? "" : ("; path=" + this.path)) +
14320 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
14321 ((this.secure == true) ? "; secure" : "");
14325 clearCookie : function(name){
14326 document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
14327 ((this.path == null) ? "" : ("; path=" + this.path)) +
14328 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
14329 ((this.secure == true) ? "; secure" : "");
14333 * Ext JS Library 1.1.1
14334 * Copyright(c) 2006-2007, Ext JS, LLC.
14336 * Originally Released Under LGPL - original licence link has changed is not relivant.
14339 * <script type="text/javascript">
14345 * These classes are derivatives of the similarly named classes in the YUI Library.
14346 * The original license:
14347 * Copyright (c) 2006, Yahoo! Inc. All rights reserved.
14348 * Code licensed under the BSD License:
14349 * http://developer.yahoo.net/yui/license.txt
14354 var Event=Roo.EventManager;
14355 var Dom=Roo.lib.Dom;
14358 * @class Roo.dd.DragDrop
14359 * Defines the interface and base operation of items that that can be
14360 * dragged or can be drop targets. It was designed to be extended, overriding
14361 * the event handlers for startDrag, onDrag, onDragOver and onDragOut.
14362 * Up to three html elements can be associated with a DragDrop instance:
14364 * <li>linked element: the element that is passed into the constructor.
14365 * This is the element which defines the boundaries for interaction with
14366 * other DragDrop objects.</li>
14367 * <li>handle element(s): The drag operation only occurs if the element that
14368 * was clicked matches a handle element. By default this is the linked
14369 * element, but there are times that you will want only a portion of the
14370 * linked element to initiate the drag operation, and the setHandleElId()
14371 * method provides a way to define this.</li>
14372 * <li>drag element: this represents the element that would be moved along
14373 * with the cursor during a drag operation. By default, this is the linked
14374 * element itself as in {@link Roo.dd.DD}. setDragElId() lets you define
14375 * a separate element that would be moved, as in {@link Roo.dd.DDProxy}.
14378 * This class should not be instantiated until the onload event to ensure that
14379 * the associated elements are available.
14380 * The following would define a DragDrop obj that would interact with any
14381 * other DragDrop obj in the "group1" group:
14383 * dd = new Roo.dd.DragDrop("div1", "group1");
14385 * Since none of the event handlers have been implemented, nothing would
14386 * actually happen if you were to run the code above. Normally you would
14387 * override this class or one of the default implementations, but you can
14388 * also override the methods you want on an instance of the class...
14390 * dd.onDragDrop = function(e, id) {
14391 * alert("dd was dropped on " + id);
14395 * @param {String} id of the element that is linked to this instance
14396 * @param {String} sGroup the group of related DragDrop objects
14397 * @param {object} config an object containing configurable attributes
14398 * Valid properties for DragDrop:
14399 * padding, isTarget, maintainOffset, primaryButtonOnly
14401 Roo.dd.DragDrop = function(id, sGroup, config) {
14403 this.init(id, sGroup, config);
14407 Roo.dd.DragDrop.prototype = {
14410 * The id of the element associated with this object. This is what we
14411 * refer to as the "linked element" because the size and position of
14412 * this element is used to determine when the drag and drop objects have
14420 * Configuration attributes passed into the constructor
14427 * The id of the element that will be dragged. By default this is same
14428 * as the linked element , but could be changed to another element. Ex:
14430 * @property dragElId
14437 * the id of the element that initiates the drag operation. By default
14438 * this is the linked element, but could be changed to be a child of this
14439 * element. This lets us do things like only starting the drag when the
14440 * header element within the linked html element is clicked.
14441 * @property handleElId
14448 * An associative array of HTML tags that will be ignored if clicked.
14449 * @property invalidHandleTypes
14450 * @type {string: string}
14452 invalidHandleTypes: null,
14455 * An associative array of ids for elements that will be ignored if clicked
14456 * @property invalidHandleIds
14457 * @type {string: string}
14459 invalidHandleIds: null,
14462 * An indexted array of css class names for elements that will be ignored
14464 * @property invalidHandleClasses
14467 invalidHandleClasses: null,
14470 * The linked element's absolute X position at the time the drag was
14472 * @property startPageX
14479 * The linked element's absolute X position at the time the drag was
14481 * @property startPageY
14488 * The group defines a logical collection of DragDrop objects that are
14489 * related. Instances only get events when interacting with other
14490 * DragDrop object in the same group. This lets us define multiple
14491 * groups using a single DragDrop subclass if we want.
14493 * @type {string: string}
14498 * Individual drag/drop instances can be locked. This will prevent
14499 * onmousedown start drag.
14507 * Lock this instance
14510 lock: function() { this.locked = true; },
14513 * Unlock this instace
14516 unlock: function() { this.locked = false; },
14519 * By default, all insances can be a drop target. This can be disabled by
14520 * setting isTarget to false.
14527 * The padding configured for this drag and drop object for calculating
14528 * the drop zone intersection with this object.
14535 * Cached reference to the linked element
14536 * @property _domRef
14542 * Internal typeof flag
14543 * @property __ygDragDrop
14546 __ygDragDrop: true,
14549 * Set to true when horizontal contraints are applied
14550 * @property constrainX
14557 * Set to true when vertical contraints are applied
14558 * @property constrainY
14565 * The left constraint
14573 * The right constraint
14581 * The up constraint
14590 * The down constraint
14598 * Maintain offsets when we resetconstraints. Set to true when you want
14599 * the position of the element relative to its parent to stay the same
14600 * when the page changes
14602 * @property maintainOffset
14605 maintainOffset: false,
14608 * Array of pixel locations the element will snap to if we specified a
14609 * horizontal graduation/interval. This array is generated automatically
14610 * when you define a tick interval.
14617 * Array of pixel locations the element will snap to if we specified a
14618 * vertical graduation/interval. This array is generated automatically
14619 * when you define a tick interval.
14626 * By default the drag and drop instance will only respond to the primary
14627 * button click (left button for a right-handed mouse). Set to true to
14628 * allow drag and drop to start with any mouse click that is propogated
14630 * @property primaryButtonOnly
14633 primaryButtonOnly: true,
14636 * The availabe property is false until the linked dom element is accessible.
14637 * @property available
14643 * By default, drags can only be initiated if the mousedown occurs in the
14644 * region the linked element is. This is done in part to work around a
14645 * bug in some browsers that mis-report the mousedown if the previous
14646 * mouseup happened outside of the window. This property is set to true
14647 * if outer handles are defined.
14649 * @property hasOuterHandles
14653 hasOuterHandles: false,
14656 * Code that executes immediately before the startDrag event
14657 * @method b4StartDrag
14660 b4StartDrag: function(x, y) { },
14663 * Abstract method called after a drag/drop object is clicked
14664 * and the drag or mousedown time thresholds have beeen met.
14665 * @method startDrag
14666 * @param {int} X click location
14667 * @param {int} Y click location
14669 startDrag: function(x, y) { /* override this */ },
14672 * Code that executes immediately before the onDrag event
14676 b4Drag: function(e) { },
14679 * Abstract method called during the onMouseMove event while dragging an
14682 * @param {Event} e the mousemove event
14684 onDrag: function(e) { /* override this */ },
14687 * Abstract method called when this element fist begins hovering over
14688 * another DragDrop obj
14689 * @method onDragEnter
14690 * @param {Event} e the mousemove event
14691 * @param {String|DragDrop[]} id In POINT mode, the element
14692 * id this is hovering over. In INTERSECT mode, an array of one or more
14693 * dragdrop items being hovered over.
14695 onDragEnter: function(e, id) { /* override this */ },
14698 * Code that executes immediately before the onDragOver event
14699 * @method b4DragOver
14702 b4DragOver: function(e) { },
14705 * Abstract method called when this element is hovering over another
14707 * @method onDragOver
14708 * @param {Event} e the mousemove event
14709 * @param {String|DragDrop[]} id In POINT mode, the element
14710 * id this is hovering over. In INTERSECT mode, an array of dd items
14711 * being hovered over.
14713 onDragOver: function(e, id) { /* override this */ },
14716 * Code that executes immediately before the onDragOut event
14717 * @method b4DragOut
14720 b4DragOut: function(e) { },
14723 * Abstract method called when we are no longer hovering over an element
14724 * @method onDragOut
14725 * @param {Event} e the mousemove event
14726 * @param {String|DragDrop[]} id In POINT mode, the element
14727 * id this was hovering over. In INTERSECT mode, an array of dd items
14728 * that the mouse is no longer over.
14730 onDragOut: function(e, id) { /* override this */ },
14733 * Code that executes immediately before the onDragDrop event
14734 * @method b4DragDrop
14737 b4DragDrop: function(e) { },
14740 * Abstract method called when this item is dropped on another DragDrop
14742 * @method onDragDrop
14743 * @param {Event} e the mouseup event
14744 * @param {String|DragDrop[]} id In POINT mode, the element
14745 * id this was dropped on. In INTERSECT mode, an array of dd items this
14748 onDragDrop: function(e, id) { /* override this */ },
14751 * Abstract method called when this item is dropped on an area with no
14753 * @method onInvalidDrop
14754 * @param {Event} e the mouseup event
14756 onInvalidDrop: function(e) { /* override this */ },
14759 * Code that executes immediately before the endDrag event
14760 * @method b4EndDrag
14763 b4EndDrag: function(e) { },
14766 * Fired when we are done dragging the object
14768 * @param {Event} e the mouseup event
14770 endDrag: function(e) { /* override this */ },
14773 * Code executed immediately before the onMouseDown event
14774 * @method b4MouseDown
14775 * @param {Event} e the mousedown event
14778 b4MouseDown: function(e) { },
14781 * Event handler that fires when a drag/drop obj gets a mousedown
14782 * @method onMouseDown
14783 * @param {Event} e the mousedown event
14785 onMouseDown: function(e) { /* override this */ },
14788 * Event handler that fires when a drag/drop obj gets a mouseup
14789 * @method onMouseUp
14790 * @param {Event} e the mouseup event
14792 onMouseUp: function(e) { /* override this */ },
14795 * Override the onAvailable method to do what is needed after the initial
14796 * position was determined.
14797 * @method onAvailable
14799 onAvailable: function () {
14803 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
14806 defaultPadding : {left:0, right:0, top:0, bottom:0},
14809 * Initializes the drag drop object's constraints to restrict movement to a certain element.
14813 var dd = new Roo.dd.DDProxy("dragDiv1", "proxytest",
14814 { dragElId: "existingProxyDiv" });
14815 dd.startDrag = function(){
14816 this.constrainTo("parent-id");
14819 * Or you can initalize it using the {@link Roo.Element} object:
14821 Roo.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
14822 startDrag : function(){
14823 this.constrainTo("parent-id");
14827 * @param {String/HTMLElement/Element} constrainTo The element to constrain to.
14828 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
14829 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
14830 * an object containing the sides to pad. For example: {right:10, bottom:10}
14831 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
14833 constrainTo : function(constrainTo, pad, inContent){
14834 if(typeof pad == "number"){
14835 pad = {left: pad, right:pad, top:pad, bottom:pad};
14837 pad = pad || this.defaultPadding;
14838 var b = Roo.get(this.getEl()).getBox();
14839 var ce = Roo.get(constrainTo);
14840 var s = ce.getScroll();
14841 var c, cd = ce.dom;
14842 if(cd == document.body){
14843 c = { x: s.left, y: s.top, width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
14846 c = {x : xy[0]+s.left, y: xy[1]+s.top, width: cd.clientWidth, height: cd.clientHeight};
14850 var topSpace = b.y - c.y;
14851 var leftSpace = b.x - c.x;
14853 this.resetConstraints();
14854 this.setXConstraint(leftSpace - (pad.left||0), // left
14855 c.width - leftSpace - b.width - (pad.right||0) //right
14857 this.setYConstraint(topSpace - (pad.top||0), //top
14858 c.height - topSpace - b.height - (pad.bottom||0) //bottom
14863 * Returns a reference to the linked element
14865 * @return {HTMLElement} the html element
14867 getEl: function() {
14868 if (!this._domRef) {
14869 this._domRef = Roo.getDom(this.id);
14872 return this._domRef;
14876 * Returns a reference to the actual element to drag. By default this is
14877 * the same as the html element, but it can be assigned to another
14878 * element. An example of this can be found in Roo.dd.DDProxy
14879 * @method getDragEl
14880 * @return {HTMLElement} the html element
14882 getDragEl: function() {
14883 return Roo.getDom(this.dragElId);
14887 * Sets up the DragDrop object. Must be called in the constructor of any
14888 * Roo.dd.DragDrop subclass
14890 * @param id the id of the linked element
14891 * @param {String} sGroup the group of related items
14892 * @param {object} config configuration attributes
14894 init: function(id, sGroup, config) {
14895 this.initTarget(id, sGroup, config);
14896 Event.on(this.id, "mousedown", this.handleMouseDown, this);
14897 // Event.on(this.id, "selectstart", Event.preventDefault);
14901 * Initializes Targeting functionality only... the object does not
14902 * get a mousedown handler.
14903 * @method initTarget
14904 * @param id the id of the linked element
14905 * @param {String} sGroup the group of related items
14906 * @param {object} config configuration attributes
14908 initTarget: function(id, sGroup, config) {
14910 // configuration attributes
14911 this.config = config || {};
14913 // create a local reference to the drag and drop manager
14914 this.DDM = Roo.dd.DDM;
14915 // initialize the groups array
14918 // assume that we have an element reference instead of an id if the
14919 // parameter is not a string
14920 if (typeof id !== "string") {
14927 // add to an interaction group
14928 this.addToGroup((sGroup) ? sGroup : "default");
14930 // We don't want to register this as the handle with the manager
14931 // so we just set the id rather than calling the setter.
14932 this.handleElId = id;
14934 // the linked element is the element that gets dragged by default
14935 this.setDragElId(id);
14937 // by default, clicked anchors will not start drag operations.
14938 this.invalidHandleTypes = { A: "A" };
14939 this.invalidHandleIds = {};
14940 this.invalidHandleClasses = [];
14942 this.applyConfig();
14944 this.handleOnAvailable();
14948 * Applies the configuration parameters that were passed into the constructor.
14949 * This is supposed to happen at each level through the inheritance chain. So
14950 * a DDProxy implentation will execute apply config on DDProxy, DD, and
14951 * DragDrop in order to get all of the parameters that are available in
14953 * @method applyConfig
14955 applyConfig: function() {
14957 // configurable properties:
14958 // padding, isTarget, maintainOffset, primaryButtonOnly
14959 this.padding = this.config.padding || [0, 0, 0, 0];
14960 this.isTarget = (this.config.isTarget !== false);
14961 this.maintainOffset = (this.config.maintainOffset);
14962 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
14967 * Executed when the linked element is available
14968 * @method handleOnAvailable
14971 handleOnAvailable: function() {
14972 this.available = true;
14973 this.resetConstraints();
14974 this.onAvailable();
14978 * Configures the padding for the target zone in px. Effectively expands
14979 * (or reduces) the virtual object size for targeting calculations.
14980 * Supports css-style shorthand; if only one parameter is passed, all sides
14981 * will have that padding, and if only two are passed, the top and bottom
14982 * will have the first param, the left and right the second.
14983 * @method setPadding
14984 * @param {int} iTop Top pad
14985 * @param {int} iRight Right pad
14986 * @param {int} iBot Bot pad
14987 * @param {int} iLeft Left pad
14989 setPadding: function(iTop, iRight, iBot, iLeft) {
14990 // this.padding = [iLeft, iRight, iTop, iBot];
14991 if (!iRight && 0 !== iRight) {
14992 this.padding = [iTop, iTop, iTop, iTop];
14993 } else if (!iBot && 0 !== iBot) {
14994 this.padding = [iTop, iRight, iTop, iRight];
14996 this.padding = [iTop, iRight, iBot, iLeft];
15001 * Stores the initial placement of the linked element.
15002 * @method setInitialPosition
15003 * @param {int} diffX the X offset, default 0
15004 * @param {int} diffY the Y offset, default 0
15006 setInitPosition: function(diffX, diffY) {
15007 var el = this.getEl();
15009 if (!this.DDM.verifyEl(el)) {
15013 var dx = diffX || 0;
15014 var dy = diffY || 0;
15016 var p = Dom.getXY( el );
15018 this.initPageX = p[0] - dx;
15019 this.initPageY = p[1] - dy;
15021 this.lastPageX = p[0];
15022 this.lastPageY = p[1];
15025 this.setStartPosition(p);
15029 * Sets the start position of the element. This is set when the obj
15030 * is initialized, the reset when a drag is started.
15031 * @method setStartPosition
15032 * @param pos current position (from previous lookup)
15035 setStartPosition: function(pos) {
15036 var p = pos || Dom.getXY( this.getEl() );
15037 this.deltaSetXY = null;
15039 this.startPageX = p[0];
15040 this.startPageY = p[1];
15044 * Add this instance to a group of related drag/drop objects. All
15045 * instances belong to at least one group, and can belong to as many
15046 * groups as needed.
15047 * @method addToGroup
15048 * @param sGroup {string} the name of the group
15050 addToGroup: function(sGroup) {
15051 this.groups[sGroup] = true;
15052 this.DDM.regDragDrop(this, sGroup);
15056 * Remove's this instance from the supplied interaction group
15057 * @method removeFromGroup
15058 * @param {string} sGroup The group to drop
15060 removeFromGroup: function(sGroup) {
15061 if (this.groups[sGroup]) {
15062 delete this.groups[sGroup];
15065 this.DDM.removeDDFromGroup(this, sGroup);
15069 * Allows you to specify that an element other than the linked element
15070 * will be moved with the cursor during a drag
15071 * @method setDragElId
15072 * @param id {string} the id of the element that will be used to initiate the drag
15074 setDragElId: function(id) {
15075 this.dragElId = id;
15079 * Allows you to specify a child of the linked element that should be
15080 * used to initiate the drag operation. An example of this would be if
15081 * you have a content div with text and links. Clicking anywhere in the
15082 * content area would normally start the drag operation. Use this method
15083 * to specify that an element inside of the content div is the element
15084 * that starts the drag operation.
15085 * @method setHandleElId
15086 * @param id {string} the id of the element that will be used to
15087 * initiate the drag.
15089 setHandleElId: function(id) {
15090 if (typeof id !== "string") {
15093 this.handleElId = id;
15094 this.DDM.regHandle(this.id, id);
15098 * Allows you to set an element outside of the linked element as a drag
15100 * @method setOuterHandleElId
15101 * @param id the id of the element that will be used to initiate the drag
15103 setOuterHandleElId: function(id) {
15104 if (typeof id !== "string") {
15107 Event.on(id, "mousedown",
15108 this.handleMouseDown, this);
15109 this.setHandleElId(id);
15111 this.hasOuterHandles = true;
15115 * Remove all drag and drop hooks for this element
15118 unreg: function() {
15119 Event.un(this.id, "mousedown",
15120 this.handleMouseDown);
15121 this._domRef = null;
15122 this.DDM._remove(this);
15125 destroy : function(){
15130 * Returns true if this instance is locked, or the drag drop mgr is locked
15131 * (meaning that all drag/drop is disabled on the page.)
15133 * @return {boolean} true if this obj or all drag/drop is locked, else
15136 isLocked: function() {
15137 return (this.DDM.isLocked() || this.locked);
15141 * Fired when this object is clicked
15142 * @method handleMouseDown
15144 * @param {Roo.dd.DragDrop} oDD the clicked dd object (this dd obj)
15147 handleMouseDown: function(e, oDD){
15148 if (this.primaryButtonOnly && e.button != 0) {
15152 if (this.isLocked()) {
15156 this.DDM.refreshCache(this.groups);
15158 var pt = new Roo.lib.Point(Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e));
15159 if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
15161 if (this.clickValidator(e)) {
15163 // set the initial element position
15164 this.setStartPosition();
15167 this.b4MouseDown(e);
15168 this.onMouseDown(e);
15170 this.DDM.handleMouseDown(e, this);
15172 this.DDM.stopEvent(e);
15180 clickValidator: function(e) {
15181 var target = e.getTarget();
15182 return ( this.isValidHandleChild(target) &&
15183 (this.id == this.handleElId ||
15184 this.DDM.handleWasClicked(target, this.id)) );
15188 * Allows you to specify a tag name that should not start a drag operation
15189 * when clicked. This is designed to facilitate embedding links within a
15190 * drag handle that do something other than start the drag.
15191 * @method addInvalidHandleType
15192 * @param {string} tagName the type of element to exclude
15194 addInvalidHandleType: function(tagName) {
15195 var type = tagName.toUpperCase();
15196 this.invalidHandleTypes[type] = type;
15200 * Lets you to specify an element id for a child of a drag handle
15201 * that should not initiate a drag
15202 * @method addInvalidHandleId
15203 * @param {string} id the element id of the element you wish to ignore
15205 addInvalidHandleId: function(id) {
15206 if (typeof id !== "string") {
15209 this.invalidHandleIds[id] = id;
15213 * Lets you specify a css class of elements that will not initiate a drag
15214 * @method addInvalidHandleClass
15215 * @param {string} cssClass the class of the elements you wish to ignore
15217 addInvalidHandleClass: function(cssClass) {
15218 this.invalidHandleClasses.push(cssClass);
15222 * Unsets an excluded tag name set by addInvalidHandleType
15223 * @method removeInvalidHandleType
15224 * @param {string} tagName the type of element to unexclude
15226 removeInvalidHandleType: function(tagName) {
15227 var type = tagName.toUpperCase();
15228 // this.invalidHandleTypes[type] = null;
15229 delete this.invalidHandleTypes[type];
15233 * Unsets an invalid handle id
15234 * @method removeInvalidHandleId
15235 * @param {string} id the id of the element to re-enable
15237 removeInvalidHandleId: function(id) {
15238 if (typeof id !== "string") {
15241 delete this.invalidHandleIds[id];
15245 * Unsets an invalid css class
15246 * @method removeInvalidHandleClass
15247 * @param {string} cssClass the class of the element(s) you wish to
15250 removeInvalidHandleClass: function(cssClass) {
15251 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
15252 if (this.invalidHandleClasses[i] == cssClass) {
15253 delete this.invalidHandleClasses[i];
15259 * Checks the tag exclusion list to see if this click should be ignored
15260 * @method isValidHandleChild
15261 * @param {HTMLElement} node the HTMLElement to evaluate
15262 * @return {boolean} true if this is a valid tag type, false if not
15264 isValidHandleChild: function(node) {
15267 // var n = (node.nodeName == "#text") ? node.parentNode : node;
15270 nodeName = node.nodeName.toUpperCase();
15272 nodeName = node.nodeName;
15274 valid = valid && !this.invalidHandleTypes[nodeName];
15275 valid = valid && !this.invalidHandleIds[node.id];
15277 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
15278 valid = !Dom.hasClass(node, this.invalidHandleClasses[i]);
15287 * Create the array of horizontal tick marks if an interval was specified
15288 * in setXConstraint().
15289 * @method setXTicks
15292 setXTicks: function(iStartX, iTickSize) {
15294 this.xTickSize = iTickSize;
15298 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
15300 this.xTicks[this.xTicks.length] = i;
15305 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
15307 this.xTicks[this.xTicks.length] = i;
15312 this.xTicks.sort(this.DDM.numericSort) ;
15316 * Create the array of vertical tick marks if an interval was specified in
15317 * setYConstraint().
15318 * @method setYTicks
15321 setYTicks: function(iStartY, iTickSize) {
15323 this.yTickSize = iTickSize;
15327 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
15329 this.yTicks[this.yTicks.length] = i;
15334 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
15336 this.yTicks[this.yTicks.length] = i;
15341 this.yTicks.sort(this.DDM.numericSort) ;
15345 * By default, the element can be dragged any place on the screen. Use
15346 * this method to limit the horizontal travel of the element. Pass in
15347 * 0,0 for the parameters if you want to lock the drag to the y axis.
15348 * @method setXConstraint
15349 * @param {int} iLeft the number of pixels the element can move to the left
15350 * @param {int} iRight the number of pixels the element can move to the
15352 * @param {int} iTickSize optional parameter for specifying that the
15354 * should move iTickSize pixels at a time.
15356 setXConstraint: function(iLeft, iRight, iTickSize) {
15357 this.leftConstraint = iLeft;
15358 this.rightConstraint = iRight;
15360 this.minX = this.initPageX - iLeft;
15361 this.maxX = this.initPageX + iRight;
15362 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
15364 this.constrainX = true;
15368 * Clears any constraints applied to this instance. Also clears ticks
15369 * since they can't exist independent of a constraint at this time.
15370 * @method clearConstraints
15372 clearConstraints: function() {
15373 this.constrainX = false;
15374 this.constrainY = false;
15379 * Clears any tick interval defined for this instance
15380 * @method clearTicks
15382 clearTicks: function() {
15383 this.xTicks = null;
15384 this.yTicks = null;
15385 this.xTickSize = 0;
15386 this.yTickSize = 0;
15390 * By default, the element can be dragged any place on the screen. Set
15391 * this to limit the vertical travel of the element. Pass in 0,0 for the
15392 * parameters if you want to lock the drag to the x axis.
15393 * @method setYConstraint
15394 * @param {int} iUp the number of pixels the element can move up
15395 * @param {int} iDown the number of pixels the element can move down
15396 * @param {int} iTickSize optional parameter for specifying that the
15397 * element should move iTickSize pixels at a time.
15399 setYConstraint: function(iUp, iDown, iTickSize) {
15400 this.topConstraint = iUp;
15401 this.bottomConstraint = iDown;
15403 this.minY = this.initPageY - iUp;
15404 this.maxY = this.initPageY + iDown;
15405 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
15407 this.constrainY = true;
15412 * resetConstraints must be called if you manually reposition a dd element.
15413 * @method resetConstraints
15414 * @param {boolean} maintainOffset
15416 resetConstraints: function() {
15419 // Maintain offsets if necessary
15420 if (this.initPageX || this.initPageX === 0) {
15421 // figure out how much this thing has moved
15422 var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
15423 var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
15425 this.setInitPosition(dx, dy);
15427 // This is the first time we have detected the element's position
15429 this.setInitPosition();
15432 if (this.constrainX) {
15433 this.setXConstraint( this.leftConstraint,
15434 this.rightConstraint,
15438 if (this.constrainY) {
15439 this.setYConstraint( this.topConstraint,
15440 this.bottomConstraint,
15446 * Normally the drag element is moved pixel by pixel, but we can specify
15447 * that it move a number of pixels at a time. This method resolves the
15448 * location when we have it set up like this.
15450 * @param {int} val where we want to place the object
15451 * @param {int[]} tickArray sorted array of valid points
15452 * @return {int} the closest tick
15455 getTick: function(val, tickArray) {
15458 // If tick interval is not defined, it is effectively 1 pixel,
15459 // so we return the value passed to us.
15461 } else if (tickArray[0] >= val) {
15462 // The value is lower than the first tick, so we return the first
15464 return tickArray[0];
15466 for (var i=0, len=tickArray.length; i<len; ++i) {
15468 if (tickArray[next] && tickArray[next] >= val) {
15469 var diff1 = val - tickArray[i];
15470 var diff2 = tickArray[next] - val;
15471 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
15475 // The value is larger than the last tick, so we return the last
15477 return tickArray[tickArray.length - 1];
15484 * @return {string} string representation of the dd obj
15486 toString: function() {
15487 return ("DragDrop " + this.id);
15495 * Ext JS Library 1.1.1
15496 * Copyright(c) 2006-2007, Ext JS, LLC.
15498 * Originally Released Under LGPL - original licence link has changed is not relivant.
15501 * <script type="text/javascript">
15506 * The drag and drop utility provides a framework for building drag and drop
15507 * applications. In addition to enabling drag and drop for specific elements,
15508 * the drag and drop elements are tracked by the manager class, and the
15509 * interactions between the various elements are tracked during the drag and
15510 * the implementing code is notified about these important moments.
15513 // Only load the library once. Rewriting the manager class would orphan
15514 // existing drag and drop instances.
15515 if (!Roo.dd.DragDropMgr) {
15518 * @class Roo.dd.DragDropMgr
15519 * DragDropMgr is a singleton that tracks the element interaction for
15520 * all DragDrop items in the window. Generally, you will not call
15521 * this class directly, but it does have helper methods that could
15522 * be useful in your DragDrop implementations.
15525 Roo.dd.DragDropMgr = function() {
15527 var Event = Roo.EventManager;
15532 * Two dimensional Array of registered DragDrop objects. The first
15533 * dimension is the DragDrop item group, the second the DragDrop
15536 * @type {string: string}
15543 * Array of element ids defined as drag handles. Used to determine
15544 * if the element that generated the mousedown event is actually the
15545 * handle and not the html element itself.
15546 * @property handleIds
15547 * @type {string: string}
15554 * the DragDrop object that is currently being dragged
15555 * @property dragCurrent
15563 * the DragDrop object(s) that are being hovered over
15564 * @property dragOvers
15572 * the X distance between the cursor and the object being dragged
15581 * the Y distance between the cursor and the object being dragged
15590 * Flag to determine if we should prevent the default behavior of the
15591 * events we define. By default this is true, but this can be set to
15592 * false if you need the default behavior (not recommended)
15593 * @property preventDefault
15597 preventDefault: true,
15600 * Flag to determine if we should stop the propagation of the events
15601 * we generate. This is true by default but you may want to set it to
15602 * false if the html element contains other features that require the
15604 * @property stopPropagation
15608 stopPropagation: true,
15611 * Internal flag that is set to true when drag and drop has been
15613 * @property initialized
15620 * All drag and drop can be disabled.
15628 * Called the first time an element is registered.
15634 this.initialized = true;
15638 * In point mode, drag and drop interaction is defined by the
15639 * location of the cursor during the drag/drop
15647 * In intersect mode, drag and drop interactio nis defined by the
15648 * overlap of two or more drag and drop objects.
15649 * @property INTERSECT
15656 * The current drag and drop mode. Default: POINT
15664 * Runs method on all drag and drop objects
15665 * @method _execOnAll
15669 _execOnAll: function(sMethod, args) {
15670 for (var i in this.ids) {
15671 for (var j in this.ids[i]) {
15672 var oDD = this.ids[i][j];
15673 if (! this.isTypeOfDD(oDD)) {
15676 oDD[sMethod].apply(oDD, args);
15682 * Drag and drop initialization. Sets up the global event handlers
15687 _onLoad: function() {
15692 Event.on(document, "mouseup", this.handleMouseUp, this, true);
15693 Event.on(document, "mousemove", this.handleMouseMove, this, true);
15694 Event.on(window, "unload", this._onUnload, this, true);
15695 Event.on(window, "resize", this._onResize, this, true);
15696 // Event.on(window, "mouseout", this._test);
15701 * Reset constraints on all drag and drop objs
15702 * @method _onResize
15706 _onResize: function(e) {
15707 this._execOnAll("resetConstraints", []);
15711 * Lock all drag and drop functionality
15715 lock: function() { this.locked = true; },
15718 * Unlock all drag and drop functionality
15722 unlock: function() { this.locked = false; },
15725 * Is drag and drop locked?
15727 * @return {boolean} True if drag and drop is locked, false otherwise.
15730 isLocked: function() { return this.locked; },
15733 * Location cache that is set for all drag drop objects when a drag is
15734 * initiated, cleared when the drag is finished.
15735 * @property locationCache
15742 * Set useCache to false if you want to force object the lookup of each
15743 * drag and drop linked element constantly during a drag.
15744 * @property useCache
15751 * The number of pixels that the mouse needs to move after the
15752 * mousedown before the drag is initiated. Default=3;
15753 * @property clickPixelThresh
15757 clickPixelThresh: 3,
15760 * The number of milliseconds after the mousedown event to initiate the
15761 * drag if we don't get a mouseup event. Default=1000
15762 * @property clickTimeThresh
15766 clickTimeThresh: 350,
15769 * Flag that indicates that either the drag pixel threshold or the
15770 * mousdown time threshold has been met
15771 * @property dragThreshMet
15776 dragThreshMet: false,
15779 * Timeout used for the click time threshold
15780 * @property clickTimeout
15785 clickTimeout: null,
15788 * The X position of the mousedown event stored for later use when a
15789 * drag threshold is met.
15798 * The Y position of the mousedown event stored for later use when a
15799 * drag threshold is met.
15808 * Each DragDrop instance must be registered with the DragDropMgr.
15809 * This is executed in DragDrop.init()
15810 * @method regDragDrop
15811 * @param {DragDrop} oDD the DragDrop object to register
15812 * @param {String} sGroup the name of the group this element belongs to
15815 regDragDrop: function(oDD, sGroup) {
15816 if (!this.initialized) { this.init(); }
15818 if (!this.ids[sGroup]) {
15819 this.ids[sGroup] = {};
15821 this.ids[sGroup][oDD.id] = oDD;
15825 * Removes the supplied dd instance from the supplied group. Executed
15826 * by DragDrop.removeFromGroup, so don't call this function directly.
15827 * @method removeDDFromGroup
15831 removeDDFromGroup: function(oDD, sGroup) {
15832 if (!this.ids[sGroup]) {
15833 this.ids[sGroup] = {};
15836 var obj = this.ids[sGroup];
15837 if (obj && obj[oDD.id]) {
15838 delete obj[oDD.id];
15843 * Unregisters a drag and drop item. This is executed in
15844 * DragDrop.unreg, use that method instead of calling this directly.
15849 _remove: function(oDD) {
15850 for (var g in oDD.groups) {
15851 if (g && this.ids[g][oDD.id]) {
15852 delete this.ids[g][oDD.id];
15855 delete this.handleIds[oDD.id];
15859 * Each DragDrop handle element must be registered. This is done
15860 * automatically when executing DragDrop.setHandleElId()
15861 * @method regHandle
15862 * @param {String} sDDId the DragDrop id this element is a handle for
15863 * @param {String} sHandleId the id of the element that is the drag
15867 regHandle: function(sDDId, sHandleId) {
15868 if (!this.handleIds[sDDId]) {
15869 this.handleIds[sDDId] = {};
15871 this.handleIds[sDDId][sHandleId] = sHandleId;
15875 * Utility function to determine if a given element has been
15876 * registered as a drag drop item.
15877 * @method isDragDrop
15878 * @param {String} id the element id to check
15879 * @return {boolean} true if this element is a DragDrop item,
15883 isDragDrop: function(id) {
15884 return ( this.getDDById(id) ) ? true : false;
15888 * Returns the drag and drop instances that are in all groups the
15889 * passed in instance belongs to.
15890 * @method getRelated
15891 * @param {DragDrop} p_oDD the obj to get related data for
15892 * @param {boolean} bTargetsOnly if true, only return targetable objs
15893 * @return {DragDrop[]} the related instances
15896 getRelated: function(p_oDD, bTargetsOnly) {
15898 for (var i in p_oDD.groups) {
15899 for (j in this.ids[i]) {
15900 var dd = this.ids[i][j];
15901 if (! this.isTypeOfDD(dd)) {
15904 if (!bTargetsOnly || dd.isTarget) {
15905 oDDs[oDDs.length] = dd;
15914 * Returns true if the specified dd target is a legal target for
15915 * the specifice drag obj
15916 * @method isLegalTarget
15917 * @param {DragDrop} the drag obj
15918 * @param {DragDrop} the target
15919 * @return {boolean} true if the target is a legal target for the
15923 isLegalTarget: function (oDD, oTargetDD) {
15924 var targets = this.getRelated(oDD, true);
15925 for (var i=0, len=targets.length;i<len;++i) {
15926 if (targets[i].id == oTargetDD.id) {
15935 * My goal is to be able to transparently determine if an object is
15936 * typeof DragDrop, and the exact subclass of DragDrop. typeof
15937 * returns "object", oDD.constructor.toString() always returns
15938 * "DragDrop" and not the name of the subclass. So for now it just
15939 * evaluates a well-known variable in DragDrop.
15940 * @method isTypeOfDD
15941 * @param {Object} the object to evaluate
15942 * @return {boolean} true if typeof oDD = DragDrop
15945 isTypeOfDD: function (oDD) {
15946 return (oDD && oDD.__ygDragDrop);
15950 * Utility function to determine if a given element has been
15951 * registered as a drag drop handle for the given Drag Drop object.
15953 * @param {String} id the element id to check
15954 * @return {boolean} true if this element is a DragDrop handle, false
15958 isHandle: function(sDDId, sHandleId) {
15959 return ( this.handleIds[sDDId] &&
15960 this.handleIds[sDDId][sHandleId] );
15964 * Returns the DragDrop instance for a given id
15965 * @method getDDById
15966 * @param {String} id the id of the DragDrop object
15967 * @return {DragDrop} the drag drop object, null if it is not found
15970 getDDById: function(id) {
15971 for (var i in this.ids) {
15972 if (this.ids[i][id]) {
15973 return this.ids[i][id];
15980 * Fired after a registered DragDrop object gets the mousedown event.
15981 * Sets up the events required to track the object being dragged
15982 * @method handleMouseDown
15983 * @param {Event} e the event
15984 * @param oDD the DragDrop object being dragged
15988 handleMouseDown: function(e, oDD) {
15990 Roo.QuickTips.disable();
15992 this.currentTarget = e.getTarget();
15994 this.dragCurrent = oDD;
15996 var el = oDD.getEl();
15998 // track start position
15999 this.startX = e.getPageX();
16000 this.startY = e.getPageY();
16002 this.deltaX = this.startX - el.offsetLeft;
16003 this.deltaY = this.startY - el.offsetTop;
16005 this.dragThreshMet = false;
16007 this.clickTimeout = setTimeout(
16009 var DDM = Roo.dd.DDM;
16010 DDM.startDrag(DDM.startX, DDM.startY);
16012 this.clickTimeThresh );
16016 * Fired when either the drag pixel threshol or the mousedown hold
16017 * time threshold has been met.
16018 * @method startDrag
16019 * @param x {int} the X position of the original mousedown
16020 * @param y {int} the Y position of the original mousedown
16023 startDrag: function(x, y) {
16024 clearTimeout(this.clickTimeout);
16025 if (this.dragCurrent) {
16026 this.dragCurrent.b4StartDrag(x, y);
16027 this.dragCurrent.startDrag(x, y);
16029 this.dragThreshMet = true;
16033 * Internal function to handle the mouseup event. Will be invoked
16034 * from the context of the document.
16035 * @method handleMouseUp
16036 * @param {Event} e the event
16040 handleMouseUp: function(e) {
16043 Roo.QuickTips.enable();
16045 if (! this.dragCurrent) {
16049 clearTimeout(this.clickTimeout);
16051 if (this.dragThreshMet) {
16052 this.fireEvents(e, true);
16062 * Utility to stop event propagation and event default, if these
16063 * features are turned on.
16064 * @method stopEvent
16065 * @param {Event} e the event as returned by this.getEvent()
16068 stopEvent: function(e){
16069 if(this.stopPropagation) {
16070 e.stopPropagation();
16073 if (this.preventDefault) {
16074 e.preventDefault();
16079 * Internal function to clean up event handlers after the drag
16080 * operation is complete
16082 * @param {Event} e the event
16086 stopDrag: function(e) {
16087 // Fire the drag end event for the item that was dragged
16088 if (this.dragCurrent) {
16089 if (this.dragThreshMet) {
16090 this.dragCurrent.b4EndDrag(e);
16091 this.dragCurrent.endDrag(e);
16094 this.dragCurrent.onMouseUp(e);
16097 this.dragCurrent = null;
16098 this.dragOvers = {};
16102 * Internal function to handle the mousemove event. Will be invoked
16103 * from the context of the html element.
16105 * @TODO figure out what we can do about mouse events lost when the
16106 * user drags objects beyond the window boundary. Currently we can
16107 * detect this in internet explorer by verifying that the mouse is
16108 * down during the mousemove event. Firefox doesn't give us the
16109 * button state on the mousemove event.
16110 * @method handleMouseMove
16111 * @param {Event} e the event
16115 handleMouseMove: function(e) {
16116 if (! this.dragCurrent) {
16120 // var button = e.which || e.button;
16122 // check for IE mouseup outside of page boundary
16123 if (Roo.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
16125 return this.handleMouseUp(e);
16128 if (!this.dragThreshMet) {
16129 var diffX = Math.abs(this.startX - e.getPageX());
16130 var diffY = Math.abs(this.startY - e.getPageY());
16131 if (diffX > this.clickPixelThresh ||
16132 diffY > this.clickPixelThresh) {
16133 this.startDrag(this.startX, this.startY);
16137 if (this.dragThreshMet) {
16138 this.dragCurrent.b4Drag(e);
16139 this.dragCurrent.onDrag(e);
16140 if(!this.dragCurrent.moveOnly){
16141 this.fireEvents(e, false);
16151 * Iterates over all of the DragDrop elements to find ones we are
16152 * hovering over or dropping on
16153 * @method fireEvents
16154 * @param {Event} e the event
16155 * @param {boolean} isDrop is this a drop op or a mouseover op?
16159 fireEvents: function(e, isDrop) {
16160 var dc = this.dragCurrent;
16162 // If the user did the mouse up outside of the window, we could
16163 // get here even though we have ended the drag.
16164 if (!dc || dc.isLocked()) {
16168 var pt = e.getPoint();
16170 // cache the previous dragOver array
16176 var enterEvts = [];
16178 // Check to see if the object(s) we were hovering over is no longer
16179 // being hovered over so we can fire the onDragOut event
16180 for (var i in this.dragOvers) {
16182 var ddo = this.dragOvers[i];
16184 if (! this.isTypeOfDD(ddo)) {
16188 if (! this.isOverTarget(pt, ddo, this.mode)) {
16189 outEvts.push( ddo );
16192 oldOvers[i] = true;
16193 delete this.dragOvers[i];
16196 for (var sGroup in dc.groups) {
16198 if ("string" != typeof sGroup) {
16202 for (i in this.ids[sGroup]) {
16203 var oDD = this.ids[sGroup][i];
16204 if (! this.isTypeOfDD(oDD)) {
16208 if (oDD.isTarget && !oDD.isLocked() && oDD != dc) {
16209 if (this.isOverTarget(pt, oDD, this.mode)) {
16210 // look for drop interactions
16212 dropEvts.push( oDD );
16213 // look for drag enter and drag over interactions
16216 // initial drag over: dragEnter fires
16217 if (!oldOvers[oDD.id]) {
16218 enterEvts.push( oDD );
16219 // subsequent drag overs: dragOver fires
16221 overEvts.push( oDD );
16224 this.dragOvers[oDD.id] = oDD;
16232 if (outEvts.length) {
16233 dc.b4DragOut(e, outEvts);
16234 dc.onDragOut(e, outEvts);
16237 if (enterEvts.length) {
16238 dc.onDragEnter(e, enterEvts);
16241 if (overEvts.length) {
16242 dc.b4DragOver(e, overEvts);
16243 dc.onDragOver(e, overEvts);
16246 if (dropEvts.length) {
16247 dc.b4DragDrop(e, dropEvts);
16248 dc.onDragDrop(e, dropEvts);
16252 // fire dragout events
16254 for (i=0, len=outEvts.length; i<len; ++i) {
16255 dc.b4DragOut(e, outEvts[i].id);
16256 dc.onDragOut(e, outEvts[i].id);
16259 // fire enter events
16260 for (i=0,len=enterEvts.length; i<len; ++i) {
16261 // dc.b4DragEnter(e, oDD.id);
16262 dc.onDragEnter(e, enterEvts[i].id);
16265 // fire over events
16266 for (i=0,len=overEvts.length; i<len; ++i) {
16267 dc.b4DragOver(e, overEvts[i].id);
16268 dc.onDragOver(e, overEvts[i].id);
16271 // fire drop events
16272 for (i=0, len=dropEvts.length; i<len; ++i) {
16273 dc.b4DragDrop(e, dropEvts[i].id);
16274 dc.onDragDrop(e, dropEvts[i].id);
16279 // notify about a drop that did not find a target
16280 if (isDrop && !dropEvts.length) {
16281 dc.onInvalidDrop(e);
16287 * Helper function for getting the best match from the list of drag
16288 * and drop objects returned by the drag and drop events when we are
16289 * in INTERSECT mode. It returns either the first object that the
16290 * cursor is over, or the object that has the greatest overlap with
16291 * the dragged element.
16292 * @method getBestMatch
16293 * @param {DragDrop[]} dds The array of drag and drop objects
16295 * @return {DragDrop} The best single match
16298 getBestMatch: function(dds) {
16300 // Return null if the input is not what we expect
16301 //if (!dds || !dds.length || dds.length == 0) {
16303 // If there is only one item, it wins
16304 //} else if (dds.length == 1) {
16306 var len = dds.length;
16311 // Loop through the targeted items
16312 for (var i=0; i<len; ++i) {
16314 // If the cursor is over the object, it wins. If the
16315 // cursor is over multiple matches, the first one we come
16317 if (dd.cursorIsOver) {
16320 // Otherwise the object with the most overlap wins
16323 winner.overlap.getArea() < dd.overlap.getArea()) {
16334 * Refreshes the cache of the top-left and bottom-right points of the
16335 * drag and drop objects in the specified group(s). This is in the
16336 * format that is stored in the drag and drop instance, so typical
16339 * Roo.dd.DragDropMgr.refreshCache(ddinstance.groups);
16343 * Roo.dd.DragDropMgr.refreshCache({group1:true, group2:true});
16345 * @TODO this really should be an indexed array. Alternatively this
16346 * method could accept both.
16347 * @method refreshCache
16348 * @param {Object} groups an associative array of groups to refresh
16351 refreshCache: function(groups) {
16352 for (var sGroup in groups) {
16353 if ("string" != typeof sGroup) {
16356 for (var i in this.ids[sGroup]) {
16357 var oDD = this.ids[sGroup][i];
16359 if (this.isTypeOfDD(oDD)) {
16360 // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
16361 var loc = this.getLocation(oDD);
16363 this.locationCache[oDD.id] = loc;
16365 delete this.locationCache[oDD.id];
16366 // this will unregister the drag and drop object if
16367 // the element is not in a usable state
16376 * This checks to make sure an element exists and is in the DOM. The
16377 * main purpose is to handle cases where innerHTML is used to remove
16378 * drag and drop objects from the DOM. IE provides an 'unspecified
16379 * error' when trying to access the offsetParent of such an element
16381 * @param {HTMLElement} el the element to check
16382 * @return {boolean} true if the element looks usable
16385 verifyEl: function(el) {
16390 parent = el.offsetParent;
16393 parent = el.offsetParent;
16404 * Returns a Region object containing the drag and drop element's position
16405 * and size, including the padding configured for it
16406 * @method getLocation
16407 * @param {DragDrop} oDD the drag and drop object to get the
16409 * @return {Roo.lib.Region} a Region object representing the total area
16410 * the element occupies, including any padding
16411 * the instance is configured for.
16414 getLocation: function(oDD) {
16415 if (! this.isTypeOfDD(oDD)) {
16419 var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
16422 pos= Roo.lib.Dom.getXY(el);
16430 x2 = x1 + el.offsetWidth;
16432 y2 = y1 + el.offsetHeight;
16434 t = y1 - oDD.padding[0];
16435 r = x2 + oDD.padding[1];
16436 b = y2 + oDD.padding[2];
16437 l = x1 - oDD.padding[3];
16439 return new Roo.lib.Region( t, r, b, l );
16443 * Checks the cursor location to see if it over the target
16444 * @method isOverTarget
16445 * @param {Roo.lib.Point} pt The point to evaluate
16446 * @param {DragDrop} oTarget the DragDrop object we are inspecting
16447 * @return {boolean} true if the mouse is over the target
16451 isOverTarget: function(pt, oTarget, intersect) {
16452 // use cache if available
16453 var loc = this.locationCache[oTarget.id];
16454 if (!loc || !this.useCache) {
16455 loc = this.getLocation(oTarget);
16456 this.locationCache[oTarget.id] = loc;
16464 oTarget.cursorIsOver = loc.contains( pt );
16466 // DragDrop is using this as a sanity check for the initial mousedown
16467 // in this case we are done. In POINT mode, if the drag obj has no
16468 // contraints, we are also done. Otherwise we need to evaluate the
16469 // location of the target as related to the actual location of the
16470 // dragged element.
16471 var dc = this.dragCurrent;
16472 if (!dc || !dc.getTargetCoord ||
16473 (!intersect && !dc.constrainX && !dc.constrainY)) {
16474 return oTarget.cursorIsOver;
16477 oTarget.overlap = null;
16479 // Get the current location of the drag element, this is the
16480 // location of the mouse event less the delta that represents
16481 // where the original mousedown happened on the element. We
16482 // need to consider constraints and ticks as well.
16483 var pos = dc.getTargetCoord(pt.x, pt.y);
16485 var el = dc.getDragEl();
16486 var curRegion = new Roo.lib.Region( pos.y,
16487 pos.x + el.offsetWidth,
16488 pos.y + el.offsetHeight,
16491 var overlap = curRegion.intersect(loc);
16494 oTarget.overlap = overlap;
16495 return (intersect) ? true : oTarget.cursorIsOver;
16502 * unload event handler
16503 * @method _onUnload
16507 _onUnload: function(e, me) {
16508 Roo.dd.DragDropMgr.unregAll();
16512 * Cleans up the drag and drop events and objects.
16517 unregAll: function() {
16519 if (this.dragCurrent) {
16521 this.dragCurrent = null;
16524 this._execOnAll("unreg", []);
16526 for (i in this.elementCache) {
16527 delete this.elementCache[i];
16530 this.elementCache = {};
16535 * A cache of DOM elements
16536 * @property elementCache
16543 * Get the wrapper for the DOM element specified
16544 * @method getElWrapper
16545 * @param {String} id the id of the element to get
16546 * @return {Roo.dd.DDM.ElementWrapper} the wrapped element
16548 * @deprecated This wrapper isn't that useful
16551 getElWrapper: function(id) {
16552 var oWrapper = this.elementCache[id];
16553 if (!oWrapper || !oWrapper.el) {
16554 oWrapper = this.elementCache[id] =
16555 new this.ElementWrapper(Roo.getDom(id));
16561 * Returns the actual DOM element
16562 * @method getElement
16563 * @param {String} id the id of the elment to get
16564 * @return {Object} The element
16565 * @deprecated use Roo.getDom instead
16568 getElement: function(id) {
16569 return Roo.getDom(id);
16573 * Returns the style property for the DOM element (i.e.,
16574 * document.getElById(id).style)
16576 * @param {String} id the id of the elment to get
16577 * @return {Object} The style property of the element
16578 * @deprecated use Roo.getDom instead
16581 getCss: function(id) {
16582 var el = Roo.getDom(id);
16583 return (el) ? el.style : null;
16587 * Inner class for cached elements
16588 * @class DragDropMgr.ElementWrapper
16593 ElementWrapper: function(el) {
16598 this.el = el || null;
16603 this.id = this.el && el.id;
16605 * A reference to the style property
16608 this.css = this.el && el.style;
16612 * Returns the X position of an html element
16614 * @param el the element for which to get the position
16615 * @return {int} the X coordinate
16617 * @deprecated use Roo.lib.Dom.getX instead
16620 getPosX: function(el) {
16621 return Roo.lib.Dom.getX(el);
16625 * Returns the Y position of an html element
16627 * @param el the element for which to get the position
16628 * @return {int} the Y coordinate
16629 * @deprecated use Roo.lib.Dom.getY instead
16632 getPosY: function(el) {
16633 return Roo.lib.Dom.getY(el);
16637 * Swap two nodes. In IE, we use the native method, for others we
16638 * emulate the IE behavior
16640 * @param n1 the first node to swap
16641 * @param n2 the other node to swap
16644 swapNode: function(n1, n2) {
16648 var p = n2.parentNode;
16649 var s = n2.nextSibling;
16652 p.insertBefore(n1, n2);
16653 } else if (n2 == n1.nextSibling) {
16654 p.insertBefore(n2, n1);
16656 n1.parentNode.replaceChild(n2, n1);
16657 p.insertBefore(n1, s);
16663 * Returns the current scroll position
16664 * @method getScroll
16668 getScroll: function () {
16669 var t, l, dde=document.documentElement, db=document.body;
16670 if (dde && (dde.scrollTop || dde.scrollLeft)) {
16672 l = dde.scrollLeft;
16679 return { top: t, left: l };
16683 * Returns the specified element style property
16685 * @param {HTMLElement} el the element
16686 * @param {string} styleProp the style property
16687 * @return {string} The value of the style property
16688 * @deprecated use Roo.lib.Dom.getStyle
16691 getStyle: function(el, styleProp) {
16692 return Roo.fly(el).getStyle(styleProp);
16696 * Gets the scrollTop
16697 * @method getScrollTop
16698 * @return {int} the document's scrollTop
16701 getScrollTop: function () { return this.getScroll().top; },
16704 * Gets the scrollLeft
16705 * @method getScrollLeft
16706 * @return {int} the document's scrollTop
16709 getScrollLeft: function () { return this.getScroll().left; },
16712 * Sets the x/y position of an element to the location of the
16715 * @param {HTMLElement} moveEl The element to move
16716 * @param {HTMLElement} targetEl The position reference element
16719 moveToEl: function (moveEl, targetEl) {
16720 var aCoord = Roo.lib.Dom.getXY(targetEl);
16721 Roo.lib.Dom.setXY(moveEl, aCoord);
16725 * Numeric array sort function
16726 * @method numericSort
16729 numericSort: function(a, b) { return (a - b); },
16733 * @property _timeoutCount
16740 * Trying to make the load order less important. Without this we get
16741 * an error if this file is loaded before the Event Utility.
16742 * @method _addListeners
16746 _addListeners: function() {
16747 var DDM = Roo.dd.DDM;
16748 if ( Roo.lib.Event && document ) {
16751 if (DDM._timeoutCount > 2000) {
16753 setTimeout(DDM._addListeners, 10);
16754 if (document && document.body) {
16755 DDM._timeoutCount += 1;
16762 * Recursively searches the immediate parent and all child nodes for
16763 * the handle element in order to determine wheter or not it was
16765 * @method handleWasClicked
16766 * @param node the html element to inspect
16769 handleWasClicked: function(node, id) {
16770 if (this.isHandle(id, node.id)) {
16773 // check to see if this is a text node child of the one we want
16774 var p = node.parentNode;
16777 if (this.isHandle(id, p.id)) {
16792 // shorter alias, save a few bytes
16793 Roo.dd.DDM = Roo.dd.DragDropMgr;
16794 Roo.dd.DDM._addListeners();
16798 * Ext JS Library 1.1.1
16799 * Copyright(c) 2006-2007, Ext JS, LLC.
16801 * Originally Released Under LGPL - original licence link has changed is not relivant.
16804 * <script type="text/javascript">
16809 * A DragDrop implementation where the linked element follows the
16810 * mouse cursor during a drag.
16811 * @extends Roo.dd.DragDrop
16813 * @param {String} id the id of the linked element
16814 * @param {String} sGroup the group of related DragDrop items
16815 * @param {object} config an object containing configurable attributes
16816 * Valid properties for DD:
16819 Roo.dd.DD = function(id, sGroup, config) {
16821 this.init(id, sGroup, config);
16825 Roo.extend(Roo.dd.DD, Roo.dd.DragDrop, {
16828 * When set to true, the utility automatically tries to scroll the browser
16829 * window wehn a drag and drop element is dragged near the viewport boundary.
16830 * Defaults to true.
16837 * Sets the pointer offset to the distance between the linked element's top
16838 * left corner and the location the element was clicked
16839 * @method autoOffset
16840 * @param {int} iPageX the X coordinate of the click
16841 * @param {int} iPageY the Y coordinate of the click
16843 autoOffset: function(iPageX, iPageY) {
16844 var x = iPageX - this.startPageX;
16845 var y = iPageY - this.startPageY;
16846 this.setDelta(x, y);
16850 * Sets the pointer offset. You can call this directly to force the
16851 * offset to be in a particular location (e.g., pass in 0,0 to set it
16852 * to the center of the object)
16854 * @param {int} iDeltaX the distance from the left
16855 * @param {int} iDeltaY the distance from the top
16857 setDelta: function(iDeltaX, iDeltaY) {
16858 this.deltaX = iDeltaX;
16859 this.deltaY = iDeltaY;
16863 * Sets the drag element to the location of the mousedown or click event,
16864 * maintaining the cursor location relative to the location on the element
16865 * that was clicked. Override this if you want to place the element in a
16866 * location other than where the cursor is.
16867 * @method setDragElPos
16868 * @param {int} iPageX the X coordinate of the mousedown or drag event
16869 * @param {int} iPageY the Y coordinate of the mousedown or drag event
16871 setDragElPos: function(iPageX, iPageY) {
16872 // the first time we do this, we are going to check to make sure
16873 // the element has css positioning
16875 var el = this.getDragEl();
16876 this.alignElWithMouse(el, iPageX, iPageY);
16880 * Sets the element to the location of the mousedown or click event,
16881 * maintaining the cursor location relative to the location on the element
16882 * that was clicked. Override this if you want to place the element in a
16883 * location other than where the cursor is.
16884 * @method alignElWithMouse
16885 * @param {HTMLElement} el the element to move
16886 * @param {int} iPageX the X coordinate of the mousedown or drag event
16887 * @param {int} iPageY the Y coordinate of the mousedown or drag event
16889 alignElWithMouse: function(el, iPageX, iPageY) {
16890 var oCoord = this.getTargetCoord(iPageX, iPageY);
16891 var fly = el.dom ? el : Roo.fly(el);
16892 if (!this.deltaSetXY) {
16893 var aCoord = [oCoord.x, oCoord.y];
16895 var newLeft = fly.getLeft(true);
16896 var newTop = fly.getTop(true);
16897 this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
16899 fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
16902 this.cachePosition(oCoord.x, oCoord.y);
16903 this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
16908 * Saves the most recent position so that we can reset the constraints and
16909 * tick marks on-demand. We need to know this so that we can calculate the
16910 * number of pixels the element is offset from its original position.
16911 * @method cachePosition
16912 * @param iPageX the current x position (optional, this just makes it so we
16913 * don't have to look it up again)
16914 * @param iPageY the current y position (optional, this just makes it so we
16915 * don't have to look it up again)
16917 cachePosition: function(iPageX, iPageY) {
16919 this.lastPageX = iPageX;
16920 this.lastPageY = iPageY;
16922 var aCoord = Roo.lib.Dom.getXY(this.getEl());
16923 this.lastPageX = aCoord[0];
16924 this.lastPageY = aCoord[1];
16929 * Auto-scroll the window if the dragged object has been moved beyond the
16930 * visible window boundary.
16931 * @method autoScroll
16932 * @param {int} x the drag element's x position
16933 * @param {int} y the drag element's y position
16934 * @param {int} h the height of the drag element
16935 * @param {int} w the width of the drag element
16938 autoScroll: function(x, y, h, w) {
16941 // The client height
16942 var clientH = Roo.lib.Dom.getViewWidth();
16944 // The client width
16945 var clientW = Roo.lib.Dom.getViewHeight();
16947 // The amt scrolled down
16948 var st = this.DDM.getScrollTop();
16950 // The amt scrolled right
16951 var sl = this.DDM.getScrollLeft();
16953 // Location of the bottom of the element
16956 // Location of the right of the element
16959 // The distance from the cursor to the bottom of the visible area,
16960 // adjusted so that we don't scroll if the cursor is beyond the
16961 // element drag constraints
16962 var toBot = (clientH + st - y - this.deltaY);
16964 // The distance from the cursor to the right of the visible area
16965 var toRight = (clientW + sl - x - this.deltaX);
16968 // How close to the edge the cursor must be before we scroll
16969 // var thresh = (document.all) ? 100 : 40;
16972 // How many pixels to scroll per autoscroll op. This helps to reduce
16973 // clunky scrolling. IE is more sensitive about this ... it needs this
16974 // value to be higher.
16975 var scrAmt = (document.all) ? 80 : 30;
16977 // Scroll down if we are near the bottom of the visible page and the
16978 // obj extends below the crease
16979 if ( bot > clientH && toBot < thresh ) {
16980 window.scrollTo(sl, st + scrAmt);
16983 // Scroll up if the window is scrolled down and the top of the object
16984 // goes above the top border
16985 if ( y < st && st > 0 && y - st < thresh ) {
16986 window.scrollTo(sl, st - scrAmt);
16989 // Scroll right if the obj is beyond the right border and the cursor is
16990 // near the border.
16991 if ( right > clientW && toRight < thresh ) {
16992 window.scrollTo(sl + scrAmt, st);
16995 // Scroll left if the window has been scrolled to the right and the obj
16996 // extends past the left border
16997 if ( x < sl && sl > 0 && x - sl < thresh ) {
16998 window.scrollTo(sl - scrAmt, st);
17004 * Finds the location the element should be placed if we want to move
17005 * it to where the mouse location less the click offset would place us.
17006 * @method getTargetCoord
17007 * @param {int} iPageX the X coordinate of the click
17008 * @param {int} iPageY the Y coordinate of the click
17009 * @return an object that contains the coordinates (Object.x and Object.y)
17012 getTargetCoord: function(iPageX, iPageY) {
17015 var x = iPageX - this.deltaX;
17016 var y = iPageY - this.deltaY;
17018 if (this.constrainX) {
17019 if (x < this.minX) { x = this.minX; }
17020 if (x > this.maxX) { x = this.maxX; }
17023 if (this.constrainY) {
17024 if (y < this.minY) { y = this.minY; }
17025 if (y > this.maxY) { y = this.maxY; }
17028 x = this.getTick(x, this.xTicks);
17029 y = this.getTick(y, this.yTicks);
17036 * Sets up config options specific to this class. Overrides
17037 * Roo.dd.DragDrop, but all versions of this method through the
17038 * inheritance chain are called
17040 applyConfig: function() {
17041 Roo.dd.DD.superclass.applyConfig.call(this);
17042 this.scroll = (this.config.scroll !== false);
17046 * Event that fires prior to the onMouseDown event. Overrides
17049 b4MouseDown: function(e) {
17050 // this.resetConstraints();
17051 this.autoOffset(e.getPageX(),
17056 * Event that fires prior to the onDrag event. Overrides
17059 b4Drag: function(e) {
17060 this.setDragElPos(e.getPageX(),
17064 toString: function() {
17065 return ("DD " + this.id);
17068 //////////////////////////////////////////////////////////////////////////
17069 // Debugging ygDragDrop events that can be overridden
17070 //////////////////////////////////////////////////////////////////////////
17072 startDrag: function(x, y) {
17075 onDrag: function(e) {
17078 onDragEnter: function(e, id) {
17081 onDragOver: function(e, id) {
17084 onDragOut: function(e, id) {
17087 onDragDrop: function(e, id) {
17090 endDrag: function(e) {
17097 * Ext JS Library 1.1.1
17098 * Copyright(c) 2006-2007, Ext JS, LLC.
17100 * Originally Released Under LGPL - original licence link has changed is not relivant.
17103 * <script type="text/javascript">
17107 * @class Roo.dd.DDProxy
17108 * A DragDrop implementation that inserts an empty, bordered div into
17109 * the document that follows the cursor during drag operations. At the time of
17110 * the click, the frame div is resized to the dimensions of the linked html
17111 * element, and moved to the exact location of the linked element.
17113 * References to the "frame" element refer to the single proxy element that
17114 * was created to be dragged in place of all DDProxy elements on the
17117 * @extends Roo.dd.DD
17119 * @param {String} id the id of the linked html element
17120 * @param {String} sGroup the group of related DragDrop objects
17121 * @param {object} config an object containing configurable attributes
17122 * Valid properties for DDProxy in addition to those in DragDrop:
17123 * resizeFrame, centerFrame, dragElId
17125 Roo.dd.DDProxy = function(id, sGroup, config) {
17127 this.init(id, sGroup, config);
17133 * The default drag frame div id
17134 * @property Roo.dd.DDProxy.dragElId
17138 Roo.dd.DDProxy.dragElId = "ygddfdiv";
17140 Roo.extend(Roo.dd.DDProxy, Roo.dd.DD, {
17143 * By default we resize the drag frame to be the same size as the element
17144 * we want to drag (this is to get the frame effect). We can turn it off
17145 * if we want a different behavior.
17146 * @property resizeFrame
17152 * By default the frame is positioned exactly where the drag element is, so
17153 * we use the cursor offset provided by Roo.dd.DD. Another option that works only if
17154 * you do not have constraints on the obj is to have the drag frame centered
17155 * around the cursor. Set centerFrame to true for this effect.
17156 * @property centerFrame
17159 centerFrame: false,
17162 * Creates the proxy element if it does not yet exist
17163 * @method createFrame
17165 createFrame: function() {
17167 var body = document.body;
17169 if (!body || !body.firstChild) {
17170 setTimeout( function() { self.createFrame(); }, 50 );
17174 var div = this.getDragEl();
17177 div = document.createElement("div");
17178 div.id = this.dragElId;
17181 s.position = "absolute";
17182 s.visibility = "hidden";
17184 s.border = "2px solid #aaa";
17187 // appendChild can blow up IE if invoked prior to the window load event
17188 // while rendering a table. It is possible there are other scenarios
17189 // that would cause this to happen as well.
17190 body.insertBefore(div, body.firstChild);
17195 * Initialization for the drag frame element. Must be called in the
17196 * constructor of all subclasses
17197 * @method initFrame
17199 initFrame: function() {
17200 this.createFrame();
17203 applyConfig: function() {
17204 Roo.dd.DDProxy.superclass.applyConfig.call(this);
17206 this.resizeFrame = (this.config.resizeFrame !== false);
17207 this.centerFrame = (this.config.centerFrame);
17208 this.setDragElId(this.config.dragElId || Roo.dd.DDProxy.dragElId);
17212 * Resizes the drag frame to the dimensions of the clicked object, positions
17213 * it over the object, and finally displays it
17214 * @method showFrame
17215 * @param {int} iPageX X click position
17216 * @param {int} iPageY Y click position
17219 showFrame: function(iPageX, iPageY) {
17220 var el = this.getEl();
17221 var dragEl = this.getDragEl();
17222 var s = dragEl.style;
17224 this._resizeProxy();
17226 if (this.centerFrame) {
17227 this.setDelta( Math.round(parseInt(s.width, 10)/2),
17228 Math.round(parseInt(s.height, 10)/2) );
17231 this.setDragElPos(iPageX, iPageY);
17233 Roo.fly(dragEl).show();
17237 * The proxy is automatically resized to the dimensions of the linked
17238 * element when a drag is initiated, unless resizeFrame is set to false
17239 * @method _resizeProxy
17242 _resizeProxy: function() {
17243 if (this.resizeFrame) {
17244 var el = this.getEl();
17245 Roo.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
17249 // overrides Roo.dd.DragDrop
17250 b4MouseDown: function(e) {
17251 var x = e.getPageX();
17252 var y = e.getPageY();
17253 this.autoOffset(x, y);
17254 this.setDragElPos(x, y);
17257 // overrides Roo.dd.DragDrop
17258 b4StartDrag: function(x, y) {
17259 // show the drag frame
17260 this.showFrame(x, y);
17263 // overrides Roo.dd.DragDrop
17264 b4EndDrag: function(e) {
17265 Roo.fly(this.getDragEl()).hide();
17268 // overrides Roo.dd.DragDrop
17269 // By default we try to move the element to the last location of the frame.
17270 // This is so that the default behavior mirrors that of Roo.dd.DD.
17271 endDrag: function(e) {
17273 var lel = this.getEl();
17274 var del = this.getDragEl();
17276 // Show the drag frame briefly so we can get its position
17277 del.style.visibility = "";
17280 // Hide the linked element before the move to get around a Safari
17282 lel.style.visibility = "hidden";
17283 Roo.dd.DDM.moveToEl(lel, del);
17284 del.style.visibility = "hidden";
17285 lel.style.visibility = "";
17290 beforeMove : function(){
17294 afterDrag : function(){
17298 toString: function() {
17299 return ("DDProxy " + this.id);
17305 * Ext JS Library 1.1.1
17306 * Copyright(c) 2006-2007, Ext JS, LLC.
17308 * Originally Released Under LGPL - original licence link has changed is not relivant.
17311 * <script type="text/javascript">
17315 * @class Roo.dd.DDTarget
17316 * A DragDrop implementation that does not move, but can be a drop
17317 * target. You would get the same result by simply omitting implementation
17318 * for the event callbacks, but this way we reduce the processing cost of the
17319 * event listener and the callbacks.
17320 * @extends Roo.dd.DragDrop
17322 * @param {String} id the id of the element that is a drop target
17323 * @param {String} sGroup the group of related DragDrop objects
17324 * @param {object} config an object containing configurable attributes
17325 * Valid properties for DDTarget in addition to those in
17329 Roo.dd.DDTarget = function(id, sGroup, config) {
17331 this.initTarget(id, sGroup, config);
17335 // Roo.dd.DDTarget.prototype = new Roo.dd.DragDrop();
17336 Roo.extend(Roo.dd.DDTarget, Roo.dd.DragDrop, {
17337 toString: function() {
17338 return ("DDTarget " + this.id);
17343 * Ext JS Library 1.1.1
17344 * Copyright(c) 2006-2007, Ext JS, LLC.
17346 * Originally Released Under LGPL - original licence link has changed is not relivant.
17349 * <script type="text/javascript">
17354 * @class Roo.dd.ScrollManager
17355 * Provides automatic scrolling of overflow regions in the page during drag operations.<br><br>
17356 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
17359 Roo.dd.ScrollManager = function(){
17360 var ddm = Roo.dd.DragDropMgr;
17365 var onStop = function(e){
17370 var triggerRefresh = function(){
17371 if(ddm.dragCurrent){
17372 ddm.refreshCache(ddm.dragCurrent.groups);
17376 var doScroll = function(){
17377 if(ddm.dragCurrent){
17378 var dds = Roo.dd.ScrollManager;
17380 if(proc.el.scroll(proc.dir, dds.increment)){
17384 proc.el.scroll(proc.dir, dds.increment, true, dds.animDuration, triggerRefresh);
17389 var clearProc = function(){
17391 clearInterval(proc.id);
17398 var startProc = function(el, dir){
17402 proc.id = setInterval(doScroll, Roo.dd.ScrollManager.frequency);
17405 var onFire = function(e, isDrop){
17406 if(isDrop || !ddm.dragCurrent){ return; }
17407 var dds = Roo.dd.ScrollManager;
17408 if(!dragEl || dragEl != ddm.dragCurrent){
17409 dragEl = ddm.dragCurrent;
17410 // refresh regions on drag start
17411 dds.refreshCache();
17414 var xy = Roo.lib.Event.getXY(e);
17415 var pt = new Roo.lib.Point(xy[0], xy[1]);
17416 for(var id in els){
17417 var el = els[id], r = el._region;
17418 if(r && r.contains(pt) && el.isScrollable()){
17419 if(r.bottom - pt.y <= dds.thresh){
17421 startProc(el, "down");
17424 }else if(r.right - pt.x <= dds.thresh){
17426 startProc(el, "left");
17429 }else if(pt.y - r.top <= dds.thresh){
17431 startProc(el, "up");
17434 }else if(pt.x - r.left <= dds.thresh){
17436 startProc(el, "right");
17445 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
17446 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
17450 * Registers new overflow element(s) to auto scroll
17451 * @param {String/HTMLElement/Element/Array} el The id of or the element to be scrolled or an array of either
17453 register : function(el){
17454 if(el instanceof Array){
17455 for(var i = 0, len = el.length; i < len; i++) {
17456 this.register(el[i]);
17465 * Unregisters overflow element(s) so they are no longer scrolled
17466 * @param {String/HTMLElement/Element/Array} el The id of or the element to be removed or an array of either
17468 unregister : function(el){
17469 if(el instanceof Array){
17470 for(var i = 0, len = el.length; i < len; i++) {
17471 this.unregister(el[i]);
17480 * The number of pixels from the edge of a container the pointer needs to be to
17481 * trigger scrolling (defaults to 25)
17487 * The number of pixels to scroll in each scroll increment (defaults to 50)
17493 * The frequency of scrolls in milliseconds (defaults to 500)
17499 * True to animate the scroll (defaults to true)
17505 * The animation duration in seconds -
17506 * MUST BE less than Roo.dd.ScrollManager.frequency! (defaults to .4)
17512 * Manually trigger a cache refresh.
17514 refreshCache : function(){
17515 for(var id in els){
17516 if(typeof els[id] == 'object'){ // for people extending the object prototype
17517 els[id]._region = els[id].getRegion();
17524 * Ext JS Library 1.1.1
17525 * Copyright(c) 2006-2007, Ext JS, LLC.
17527 * Originally Released Under LGPL - original licence link has changed is not relivant.
17530 * <script type="text/javascript">
17535 * @class Roo.dd.Registry
17536 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
17537 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
17540 Roo.dd.Registry = function(){
17543 var autoIdSeed = 0;
17545 var getId = function(el, autogen){
17546 if(typeof el == "string"){
17550 if(!id && autogen !== false){
17551 id = "roodd-" + (++autoIdSeed);
17559 * Register a drag drop element
17560 * @param {String|HTMLElement} element The id or DOM node to register
17561 * @param {Object} data (optional) A custom data object that will be passed between the elements that are involved
17562 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
17563 * knows how to interpret, plus there are some specific properties known to the Registry that should be
17564 * populated in the data object (if applicable):
17566 Value Description<br />
17567 --------- ------------------------------------------<br />
17568 handles Array of DOM nodes that trigger dragging<br />
17569 for the element being registered<br />
17570 isHandle True if the element passed in triggers<br />
17571 dragging itself, else false
17574 register : function(el, data){
17576 if(typeof el == "string"){
17577 el = document.getElementById(el);
17580 elements[getId(el)] = data;
17581 if(data.isHandle !== false){
17582 handles[data.ddel.id] = data;
17585 var hs = data.handles;
17586 for(var i = 0, len = hs.length; i < len; i++){
17587 handles[getId(hs[i])] = data;
17593 * Unregister a drag drop element
17594 * @param {String|HTMLElement} element The id or DOM node to unregister
17596 unregister : function(el){
17597 var id = getId(el, false);
17598 var data = elements[id];
17600 delete elements[id];
17602 var hs = data.handles;
17603 for(var i = 0, len = hs.length; i < len; i++){
17604 delete handles[getId(hs[i], false)];
17611 * Returns the handle registered for a DOM Node by id
17612 * @param {String|HTMLElement} id The DOM node or id to look up
17613 * @return {Object} handle The custom handle data
17615 getHandle : function(id){
17616 if(typeof id != "string"){ // must be element?
17619 return handles[id];
17623 * Returns the handle that is registered for the DOM node that is the target of the event
17624 * @param {Event} e The event
17625 * @return {Object} handle The custom handle data
17627 getHandleFromEvent : function(e){
17628 var t = Roo.lib.Event.getTarget(e);
17629 return t ? handles[t.id] : null;
17633 * Returns a custom data object that is registered for a DOM node by id
17634 * @param {String|HTMLElement} id The DOM node or id to look up
17635 * @return {Object} data The custom data
17637 getTarget : function(id){
17638 if(typeof id != "string"){ // must be element?
17641 return elements[id];
17645 * Returns a custom data object that is registered for the DOM node that is the target of the event
17646 * @param {Event} e The event
17647 * @return {Object} data The custom data
17649 getTargetFromEvent : function(e){
17650 var t = Roo.lib.Event.getTarget(e);
17651 return t ? elements[t.id] || handles[t.id] : null;
17656 * Ext JS Library 1.1.1
17657 * Copyright(c) 2006-2007, Ext JS, LLC.
17659 * Originally Released Under LGPL - original licence link has changed is not relivant.
17662 * <script type="text/javascript">
17667 * @class Roo.dd.StatusProxy
17668 * A specialized drag proxy that supports a drop status icon, {@link Roo.Layer} styles and auto-repair. This is the
17669 * default drag proxy used by all Roo.dd components.
17671 * @param {Object} config
17673 Roo.dd.StatusProxy = function(config){
17674 Roo.apply(this, config);
17675 this.id = this.id || Roo.id();
17676 this.el = new Roo.Layer({
17678 id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
17679 {tag: "div", cls: "x-dd-drop-icon"},
17680 {tag: "div", cls: "x-dd-drag-ghost"}
17683 shadow: !config || config.shadow !== false
17685 this.ghost = Roo.get(this.el.dom.childNodes[1]);
17686 this.dropStatus = this.dropNotAllowed;
17689 Roo.dd.StatusProxy.prototype = {
17691 * @cfg {String} dropAllowed
17692 * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
17694 dropAllowed : "x-dd-drop-ok",
17696 * @cfg {String} dropNotAllowed
17697 * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
17699 dropNotAllowed : "x-dd-drop-nodrop",
17702 * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
17703 * over the current target element.
17704 * @param {String} cssClass The css class for the new drop status indicator image
17706 setStatus : function(cssClass){
17707 cssClass = cssClass || this.dropNotAllowed;
17708 if(this.dropStatus != cssClass){
17709 this.el.replaceClass(this.dropStatus, cssClass);
17710 this.dropStatus = cssClass;
17715 * Resets the status indicator to the default dropNotAllowed value
17716 * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
17718 reset : function(clearGhost){
17719 this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
17720 this.dropStatus = this.dropNotAllowed;
17722 this.ghost.update("");
17727 * Updates the contents of the ghost element
17728 * @param {String} html The html that will replace the current innerHTML of the ghost element
17730 update : function(html){
17731 if(typeof html == "string"){
17732 this.ghost.update(html);
17734 this.ghost.update("");
17735 html.style.margin = "0";
17736 this.ghost.dom.appendChild(html);
17738 // ensure float = none set?? cant remember why though.
17739 var el = this.ghost.dom.firstChild;
17741 Roo.fly(el).setStyle('float', 'none');
17746 * Returns the underlying proxy {@link Roo.Layer}
17747 * @return {Roo.Layer} el
17749 getEl : function(){
17754 * Returns the ghost element
17755 * @return {Roo.Element} el
17757 getGhost : function(){
17763 * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
17765 hide : function(clear){
17773 * Stops the repair animation if it's currently running
17776 if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
17782 * Displays this proxy
17789 * Force the Layer to sync its shadow and shim positions to the element
17796 * Causes the proxy to return to its position of origin via an animation. Should be called after an
17797 * invalid drop operation by the item being dragged.
17798 * @param {Array} xy The XY position of the element ([x, y])
17799 * @param {Function} callback The function to call after the repair is complete
17800 * @param {Object} scope The scope in which to execute the callback
17802 repair : function(xy, callback, scope){
17803 this.callback = callback;
17804 this.scope = scope;
17805 if(xy && this.animRepair !== false){
17806 this.el.addClass("x-dd-drag-repair");
17807 this.el.hideUnders(true);
17808 this.anim = this.el.shift({
17809 duration: this.repairDuration || .5,
17813 callback: this.afterRepair,
17817 this.afterRepair();
17822 afterRepair : function(){
17824 if(typeof this.callback == "function"){
17825 this.callback.call(this.scope || this);
17827 this.callback = null;
17832 * Ext JS Library 1.1.1
17833 * Copyright(c) 2006-2007, Ext JS, LLC.
17835 * Originally Released Under LGPL - original licence link has changed is not relivant.
17838 * <script type="text/javascript">
17842 * @class Roo.dd.DragSource
17843 * @extends Roo.dd.DDProxy
17844 * A simple class that provides the basic implementation needed to make any element draggable.
17846 * @param {String/HTMLElement/Element} el The container element
17847 * @param {Object} config
17849 Roo.dd.DragSource = function(el, config){
17850 this.el = Roo.get(el);
17851 this.dragData = {};
17853 Roo.apply(this, config);
17856 this.proxy = new Roo.dd.StatusProxy();
17859 Roo.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
17860 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
17862 this.dragging = false;
17865 Roo.extend(Roo.dd.DragSource, Roo.dd.DDProxy, {
17867 * @cfg {String} dropAllowed
17868 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
17870 dropAllowed : "x-dd-drop-ok",
17872 * @cfg {String} dropNotAllowed
17873 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
17875 dropNotAllowed : "x-dd-drop-nodrop",
17878 * Returns the data object associated with this drag source
17879 * @return {Object} data An object containing arbitrary data
17881 getDragData : function(e){
17882 return this.dragData;
17886 onDragEnter : function(e, id){
17887 var target = Roo.dd.DragDropMgr.getDDById(id);
17888 this.cachedTarget = target;
17889 if(this.beforeDragEnter(target, e, id) !== false){
17890 if(target.isNotifyTarget){
17891 var status = target.notifyEnter(this, e, this.dragData);
17892 this.proxy.setStatus(status);
17894 this.proxy.setStatus(this.dropAllowed);
17897 if(this.afterDragEnter){
17899 * An empty function by default, but provided so that you can perform a custom action
17900 * when the dragged item enters the drop target by providing an implementation.
17901 * @param {Roo.dd.DragDrop} target The drop target
17902 * @param {Event} e The event object
17903 * @param {String} id The id of the dragged element
17904 * @method afterDragEnter
17906 this.afterDragEnter(target, e, id);
17912 * An empty function by default, but provided so that you can perform a custom action
17913 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
17914 * @param {Roo.dd.DragDrop} target The drop target
17915 * @param {Event} e The event object
17916 * @param {String} id The id of the dragged element
17917 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
17919 beforeDragEnter : function(target, e, id){
17924 alignElWithMouse: function() {
17925 Roo.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
17930 onDragOver : function(e, id){
17931 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
17932 if(this.beforeDragOver(target, e, id) !== false){
17933 if(target.isNotifyTarget){
17934 var status = target.notifyOver(this, e, this.dragData);
17935 this.proxy.setStatus(status);
17938 if(this.afterDragOver){
17940 * An empty function by default, but provided so that you can perform a custom action
17941 * while the dragged item is over the drop target by providing an implementation.
17942 * @param {Roo.dd.DragDrop} target The drop target
17943 * @param {Event} e The event object
17944 * @param {String} id The id of the dragged element
17945 * @method afterDragOver
17947 this.afterDragOver(target, e, id);
17953 * An empty function by default, but provided so that you can perform a custom action
17954 * while the dragged item is over the drop target and optionally cancel the onDragOver.
17955 * @param {Roo.dd.DragDrop} target The drop target
17956 * @param {Event} e The event object
17957 * @param {String} id The id of the dragged element
17958 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
17960 beforeDragOver : function(target, e, id){
17965 onDragOut : function(e, id){
17966 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
17967 if(this.beforeDragOut(target, e, id) !== false){
17968 if(target.isNotifyTarget){
17969 target.notifyOut(this, e, this.dragData);
17971 this.proxy.reset();
17972 if(this.afterDragOut){
17974 * An empty function by default, but provided so that you can perform a custom action
17975 * after the dragged item is dragged out of the target without dropping.
17976 * @param {Roo.dd.DragDrop} target The drop target
17977 * @param {Event} e The event object
17978 * @param {String} id The id of the dragged element
17979 * @method afterDragOut
17981 this.afterDragOut(target, e, id);
17984 this.cachedTarget = null;
17988 * An empty function by default, but provided so that you can perform a custom action before the dragged
17989 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
17990 * @param {Roo.dd.DragDrop} target The drop target
17991 * @param {Event} e The event object
17992 * @param {String} id The id of the dragged element
17993 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
17995 beforeDragOut : function(target, e, id){
18000 onDragDrop : function(e, id){
18001 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
18002 if(this.beforeDragDrop(target, e, id) !== false){
18003 if(target.isNotifyTarget){
18004 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
18005 this.onValidDrop(target, e, id);
18007 this.onInvalidDrop(target, e, id);
18010 this.onValidDrop(target, e, id);
18013 if(this.afterDragDrop){
18015 * An empty function by default, but provided so that you can perform a custom action
18016 * after a valid drag drop has occurred by providing an implementation.
18017 * @param {Roo.dd.DragDrop} target The drop target
18018 * @param {Event} e The event object
18019 * @param {String} id The id of the dropped element
18020 * @method afterDragDrop
18022 this.afterDragDrop(target, e, id);
18025 delete this.cachedTarget;
18029 * An empty function by default, but provided so that you can perform a custom action before the dragged
18030 * item is dropped onto the target and optionally cancel the onDragDrop.
18031 * @param {Roo.dd.DragDrop} target The drop target
18032 * @param {Event} e The event object
18033 * @param {String} id The id of the dragged element
18034 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
18036 beforeDragDrop : function(target, e, id){
18041 onValidDrop : function(target, e, id){
18043 if(this.afterValidDrop){
18045 * An empty function by default, but provided so that you can perform a custom action
18046 * after a valid drop has occurred by providing an implementation.
18047 * @param {Object} target The target DD
18048 * @param {Event} e The event object
18049 * @param {String} id The id of the dropped element
18050 * @method afterInvalidDrop
18052 this.afterValidDrop(target, e, id);
18057 getRepairXY : function(e, data){
18058 return this.el.getXY();
18062 onInvalidDrop : function(target, e, id){
18063 this.beforeInvalidDrop(target, e, id);
18064 if(this.cachedTarget){
18065 if(this.cachedTarget.isNotifyTarget){
18066 this.cachedTarget.notifyOut(this, e, this.dragData);
18068 this.cacheTarget = null;
18070 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
18072 if(this.afterInvalidDrop){
18074 * An empty function by default, but provided so that you can perform a custom action
18075 * after an invalid drop has occurred by providing an implementation.
18076 * @param {Event} e The event object
18077 * @param {String} id The id of the dropped element
18078 * @method afterInvalidDrop
18080 this.afterInvalidDrop(e, id);
18085 afterRepair : function(){
18087 this.el.highlight(this.hlColor || "c3daf9");
18089 this.dragging = false;
18093 * An empty function by default, but provided so that you can perform a custom action after an invalid
18094 * drop has occurred.
18095 * @param {Roo.dd.DragDrop} target The drop target
18096 * @param {Event} e The event object
18097 * @param {String} id The id of the dragged element
18098 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
18100 beforeInvalidDrop : function(target, e, id){
18105 handleMouseDown : function(e){
18106 if(this.dragging) {
18109 var data = this.getDragData(e);
18110 if(data && this.onBeforeDrag(data, e) !== false){
18111 this.dragData = data;
18113 Roo.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
18118 * An empty function by default, but provided so that you can perform a custom action before the initial
18119 * drag event begins and optionally cancel it.
18120 * @param {Object} data An object containing arbitrary data to be shared with drop targets
18121 * @param {Event} e The event object
18122 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
18124 onBeforeDrag : function(data, e){
18129 * An empty function by default, but provided so that you can perform a custom action once the initial
18130 * drag event has begun. The drag cannot be canceled from this function.
18131 * @param {Number} x The x position of the click on the dragged object
18132 * @param {Number} y The y position of the click on the dragged object
18134 onStartDrag : Roo.emptyFn,
18136 // private - YUI override
18137 startDrag : function(x, y){
18138 this.proxy.reset();
18139 this.dragging = true;
18140 this.proxy.update("");
18141 this.onInitDrag(x, y);
18146 onInitDrag : function(x, y){
18147 var clone = this.el.dom.cloneNode(true);
18148 clone.id = Roo.id(); // prevent duplicate ids
18149 this.proxy.update(clone);
18150 this.onStartDrag(x, y);
18155 * Returns the drag source's underlying {@link Roo.dd.StatusProxy}
18156 * @return {Roo.dd.StatusProxy} proxy The StatusProxy
18158 getProxy : function(){
18163 * Hides the drag source's {@link Roo.dd.StatusProxy}
18165 hideProxy : function(){
18167 this.proxy.reset(true);
18168 this.dragging = false;
18172 triggerCacheRefresh : function(){
18173 Roo.dd.DDM.refreshCache(this.groups);
18176 // private - override to prevent hiding
18177 b4EndDrag: function(e) {
18180 // private - override to prevent moving
18181 endDrag : function(e){
18182 this.onEndDrag(this.dragData, e);
18186 onEndDrag : function(data, e){
18189 // private - pin to cursor
18190 autoOffset : function(x, y) {
18191 this.setDelta(-12, -20);
18195 * Ext JS Library 1.1.1
18196 * Copyright(c) 2006-2007, Ext JS, LLC.
18198 * Originally Released Under LGPL - original licence link has changed is not relivant.
18201 * <script type="text/javascript">
18206 * @class Roo.dd.DropTarget
18207 * @extends Roo.dd.DDTarget
18208 * A simple class that provides the basic implementation needed to make any element a drop target that can have
18209 * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
18211 * @param {String/HTMLElement/Element} el The container element
18212 * @param {Object} config
18214 Roo.dd.DropTarget = function(el, config){
18215 this.el = Roo.get(el);
18217 Roo.apply(this, config);
18219 if(this.containerScroll){
18220 Roo.dd.ScrollManager.register(this.el);
18223 Roo.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
18228 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
18230 * @cfg {String} overClass
18231 * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
18234 * @cfg {String} dropAllowed
18235 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
18237 dropAllowed : "x-dd-drop-ok",
18239 * @cfg {String} dropNotAllowed
18240 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
18242 dropNotAllowed : "x-dd-drop-nodrop",
18248 isNotifyTarget : true,
18251 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
18252 * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
18253 * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
18254 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
18255 * @param {Event} e The event
18256 * @param {Object} data An object containing arbitrary data supplied by the drag source
18257 * @return {String} status The CSS class that communicates the drop status back to the source so that the
18258 * underlying {@link Roo.dd.StatusProxy} can be updated
18260 notifyEnter : function(dd, e, data){
18261 if(this.overClass){
18262 this.el.addClass(this.overClass);
18264 return this.dropAllowed;
18268 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the target.
18269 * This method will be called on every mouse movement while the drag source is over the drop target.
18270 * This default implementation simply returns the dropAllowed config value.
18271 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
18272 * @param {Event} e The event
18273 * @param {Object} data An object containing arbitrary data supplied by the drag source
18274 * @return {String} status The CSS class that communicates the drop status back to the source so that the
18275 * underlying {@link Roo.dd.StatusProxy} can be updated
18277 notifyOver : function(dd, e, data){
18278 return this.dropAllowed;
18282 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source has been dragged
18283 * out of the target without dropping. This default implementation simply removes the CSS class specified by
18284 * overClass (if any) from the drop element.
18285 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
18286 * @param {Event} e The event
18287 * @param {Object} data An object containing arbitrary data supplied by the drag source
18289 notifyOut : function(dd, e, data){
18290 if(this.overClass){
18291 this.el.removeClass(this.overClass);
18296 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the dragged item has
18297 * been dropped on it. This method has no default implementation and returns false, so you must provide an
18298 * implementation that does something to process the drop event and returns true so that the drag source's
18299 * repair action does not run.
18300 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
18301 * @param {Event} e The event
18302 * @param {Object} data An object containing arbitrary data supplied by the drag source
18303 * @return {Boolean} True if the drop was valid, else false
18305 notifyDrop : function(dd, e, data){
18310 * Ext JS Library 1.1.1
18311 * Copyright(c) 2006-2007, Ext JS, LLC.
18313 * Originally Released Under LGPL - original licence link has changed is not relivant.
18316 * <script type="text/javascript">
18321 * @class Roo.dd.DragZone
18322 * @extends Roo.dd.DragSource
18323 * This class provides a container DD instance that proxies for multiple child node sources.<br />
18324 * By default, this class requires that draggable child nodes are registered with {@link Roo.dd.Registry}.
18326 * @param {String/HTMLElement/Element} el The container element
18327 * @param {Object} config
18329 Roo.dd.DragZone = function(el, config){
18330 Roo.dd.DragZone.superclass.constructor.call(this, el, config);
18331 if(this.containerScroll){
18332 Roo.dd.ScrollManager.register(this.el);
18336 Roo.extend(Roo.dd.DragZone, Roo.dd.DragSource, {
18338 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
18339 * for auto scrolling during drag operations.
18342 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
18343 * method after a failed drop (defaults to "c3daf9" - light blue)
18347 * Called when a mousedown occurs in this container. Looks in {@link Roo.dd.Registry}
18348 * for a valid target to drag based on the mouse down. Override this method
18349 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
18350 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
18351 * @param {EventObject} e The mouse down event
18352 * @return {Object} The dragData
18354 getDragData : function(e){
18355 return Roo.dd.Registry.getHandleFromEvent(e);
18359 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
18360 * this.dragData.ddel
18361 * @param {Number} x The x position of the click on the dragged object
18362 * @param {Number} y The y position of the click on the dragged object
18363 * @return {Boolean} true to continue the drag, false to cancel
18365 onInitDrag : function(x, y){
18366 this.proxy.update(this.dragData.ddel.cloneNode(true));
18367 this.onStartDrag(x, y);
18372 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
18374 afterRepair : function(){
18376 Roo.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
18378 this.dragging = false;
18382 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
18383 * the XY of this.dragData.ddel
18384 * @param {EventObject} e The mouse up event
18385 * @return {Array} The xy location (e.g. [100, 200])
18387 getRepairXY : function(e){
18388 return Roo.Element.fly(this.dragData.ddel).getXY();
18392 * Ext JS Library 1.1.1
18393 * Copyright(c) 2006-2007, Ext JS, LLC.
18395 * Originally Released Under LGPL - original licence link has changed is not relivant.
18398 * <script type="text/javascript">
18401 * @class Roo.dd.DropZone
18402 * @extends Roo.dd.DropTarget
18403 * This class provides a container DD instance that proxies for multiple child node targets.<br />
18404 * By default, this class requires that child nodes accepting drop are registered with {@link Roo.dd.Registry}.
18406 * @param {String/HTMLElement/Element} el The container element
18407 * @param {Object} config
18409 Roo.dd.DropZone = function(el, config){
18410 Roo.dd.DropZone.superclass.constructor.call(this, el, config);
18413 Roo.extend(Roo.dd.DropZone, Roo.dd.DropTarget, {
18415 * Returns a custom data object associated with the DOM node that is the target of the event. By default
18416 * this looks up the event target in the {@link Roo.dd.Registry}, although you can override this method to
18417 * provide your own custom lookup.
18418 * @param {Event} e The event
18419 * @return {Object} data The custom data
18421 getTargetFromEvent : function(e){
18422 return Roo.dd.Registry.getTargetFromEvent(e);
18426 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has entered a drop node
18427 * that it has registered. This method has no default implementation and should be overridden to provide
18428 * node-specific processing if necessary.
18429 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
18430 * {@link #getTargetFromEvent} for this node)
18431 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18432 * @param {Event} e The event
18433 * @param {Object} data An object containing arbitrary data supplied by the drag source
18435 onNodeEnter : function(n, dd, e, data){
18440 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is over a drop node
18441 * that it has registered. The default implementation returns this.dropNotAllowed, so it should be
18442 * overridden to provide the proper feedback.
18443 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
18444 * {@link #getTargetFromEvent} for this node)
18445 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18446 * @param {Event} e The event
18447 * @param {Object} data An object containing arbitrary data supplied by the drag source
18448 * @return {String} status The CSS class that communicates the drop status back to the source so that the
18449 * underlying {@link Roo.dd.StatusProxy} can be updated
18451 onNodeOver : function(n, dd, e, data){
18452 return this.dropAllowed;
18456 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dragged out of
18457 * the drop node without dropping. This method has no default implementation and should be overridden to provide
18458 * node-specific processing if necessary.
18459 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
18460 * {@link #getTargetFromEvent} for this node)
18461 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18462 * @param {Event} e The event
18463 * @param {Object} data An object containing arbitrary data supplied by the drag source
18465 onNodeOut : function(n, dd, e, data){
18470 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped onto
18471 * the drop node. The default implementation returns false, so it should be overridden to provide the
18472 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
18473 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
18474 * {@link #getTargetFromEvent} for this node)
18475 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18476 * @param {Event} e The event
18477 * @param {Object} data An object containing arbitrary data supplied by the drag source
18478 * @return {Boolean} True if the drop was valid, else false
18480 onNodeDrop : function(n, dd, e, data){
18485 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is being dragged over it,
18486 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
18487 * it should be overridden to provide the proper feedback if necessary.
18488 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18489 * @param {Event} e The event
18490 * @param {Object} data An object containing arbitrary data supplied by the drag source
18491 * @return {String} status The CSS class that communicates the drop status back to the source so that the
18492 * underlying {@link Roo.dd.StatusProxy} can be updated
18494 onContainerOver : function(dd, e, data){
18495 return this.dropNotAllowed;
18499 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped on it,
18500 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
18501 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
18502 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
18503 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18504 * @param {Event} e The event
18505 * @param {Object} data An object containing arbitrary data supplied by the drag source
18506 * @return {Boolean} True if the drop was valid, else false
18508 onContainerDrop : function(dd, e, data){
18513 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source is now over
18514 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
18515 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
18516 * you should override this method and provide a custom implementation.
18517 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18518 * @param {Event} e The event
18519 * @param {Object} data An object containing arbitrary data supplied by the drag source
18520 * @return {String} status The CSS class that communicates the drop status back to the source so that the
18521 * underlying {@link Roo.dd.StatusProxy} can be updated
18523 notifyEnter : function(dd, e, data){
18524 return this.dropNotAllowed;
18528 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the drop zone.
18529 * This method will be called on every mouse movement while the drag source is over the drop zone.
18530 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
18531 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
18532 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
18533 * registered node, it will call {@link #onContainerOver}.
18534 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18535 * @param {Event} e The event
18536 * @param {Object} data An object containing arbitrary data supplied by the drag source
18537 * @return {String} status The CSS class that communicates the drop status back to the source so that the
18538 * underlying {@link Roo.dd.StatusProxy} can be updated
18540 notifyOver : function(dd, e, data){
18541 var n = this.getTargetFromEvent(e);
18542 if(!n){ // not over valid drop target
18543 if(this.lastOverNode){
18544 this.onNodeOut(this.lastOverNode, dd, e, data);
18545 this.lastOverNode = null;
18547 return this.onContainerOver(dd, e, data);
18549 if(this.lastOverNode != n){
18550 if(this.lastOverNode){
18551 this.onNodeOut(this.lastOverNode, dd, e, data);
18553 this.onNodeEnter(n, dd, e, data);
18554 this.lastOverNode = n;
18556 return this.onNodeOver(n, dd, e, data);
18560 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source has been dragged
18561 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
18562 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
18563 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
18564 * @param {Event} e The event
18565 * @param {Object} data An object containing arbitrary data supplied by the drag zone
18567 notifyOut : function(dd, e, data){
18568 if(this.lastOverNode){
18569 this.onNodeOut(this.lastOverNode, dd, e, data);
18570 this.lastOverNode = null;
18575 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the dragged item has
18576 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
18577 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
18578 * otherwise it will call {@link #onContainerDrop}.
18579 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
18580 * @param {Event} e The event
18581 * @param {Object} data An object containing arbitrary data supplied by the drag source
18582 * @return {Boolean} True if the drop was valid, else false
18584 notifyDrop : function(dd, e, data){
18585 if(this.lastOverNode){
18586 this.onNodeOut(this.lastOverNode, dd, e, data);
18587 this.lastOverNode = null;
18589 var n = this.getTargetFromEvent(e);
18591 this.onNodeDrop(n, dd, e, data) :
18592 this.onContainerDrop(dd, e, data);
18596 triggerCacheRefresh : function(){
18597 Roo.dd.DDM.refreshCache(this.groups);
18601 * Ext JS Library 1.1.1
18602 * Copyright(c) 2006-2007, Ext JS, LLC.
18604 * Originally Released Under LGPL - original licence link has changed is not relivant.
18607 * <script type="text/javascript">
18612 * @class Roo.data.SortTypes
18614 * Defines the default sorting (casting?) comparison functions used when sorting data.
18616 Roo.data.SortTypes = {
18618 * Default sort that does nothing
18619 * @param {Mixed} s The value being converted
18620 * @return {Mixed} The comparison value
18622 none : function(s){
18627 * The regular expression used to strip tags
18631 stripTagsRE : /<\/?[^>]+>/gi,
18634 * Strips all HTML tags to sort on text only
18635 * @param {Mixed} s The value being converted
18636 * @return {String} The comparison value
18638 asText : function(s){
18639 return String(s).replace(this.stripTagsRE, "");
18643 * Strips all HTML tags to sort on text only - Case insensitive
18644 * @param {Mixed} s The value being converted
18645 * @return {String} The comparison value
18647 asUCText : function(s){
18648 return String(s).toUpperCase().replace(this.stripTagsRE, "");
18652 * Case insensitive string
18653 * @param {Mixed} s The value being converted
18654 * @return {String} The comparison value
18656 asUCString : function(s) {
18657 return String(s).toUpperCase();
18662 * @param {Mixed} s The value being converted
18663 * @return {Number} The comparison value
18665 asDate : function(s) {
18669 if(s instanceof Date){
18670 return s.getTime();
18672 return Date.parse(String(s));
18677 * @param {Mixed} s The value being converted
18678 * @return {Float} The comparison value
18680 asFloat : function(s) {
18681 var val = parseFloat(String(s).replace(/,/g, ""));
18682 if(isNaN(val)) val = 0;
18688 * @param {Mixed} s The value being converted
18689 * @return {Number} The comparison value
18691 asInt : function(s) {
18692 var val = parseInt(String(s).replace(/,/g, ""));
18693 if(isNaN(val)) val = 0;
18698 * Ext JS Library 1.1.1
18699 * Copyright(c) 2006-2007, Ext JS, LLC.
18701 * Originally Released Under LGPL - original licence link has changed is not relivant.
18704 * <script type="text/javascript">
18708 * @class Roo.data.Record
18709 * Instances of this class encapsulate both record <em>definition</em> information, and record
18710 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
18711 * to access Records cached in an {@link Roo.data.Store} object.<br>
18713 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
18714 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
18717 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
18719 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
18720 * {@link #create}. The parameters are the same.
18721 * @param {Array} data An associative Array of data values keyed by the field name.
18722 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
18723 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
18724 * not specified an integer id is generated.
18726 Roo.data.Record = function(data, id){
18727 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
18732 * Generate a constructor for a specific record layout.
18733 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
18734 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
18735 * Each field definition object may contain the following properties: <ul>
18736 * <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,
18737 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
18738 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
18739 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
18740 * is being used, then this is a string containing the javascript expression to reference the data relative to
18741 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
18742 * to the data item relative to the record element. If the mapping expression is the same as the field name,
18743 * this may be omitted.</p></li>
18744 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
18745 * <ul><li>auto (Default, implies no conversion)</li>
18750 * <li>date</li></ul></p></li>
18751 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
18752 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
18753 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
18754 * by the Reader into an object that will be stored in the Record. It is passed the
18755 * following parameters:<ul>
18756 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
18758 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
18760 * <br>usage:<br><pre><code>
18761 var TopicRecord = Roo.data.Record.create(
18762 {name: 'title', mapping: 'topic_title'},
18763 {name: 'author', mapping: 'username'},
18764 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
18765 {name: 'lastPost', mapping: 'post_time', type: 'date'},
18766 {name: 'lastPoster', mapping: 'user2'},
18767 {name: 'excerpt', mapping: 'post_text'}
18770 var myNewRecord = new TopicRecord({
18771 title: 'Do my job please',
18774 lastPost: new Date(),
18775 lastPoster: 'Animal',
18776 excerpt: 'No way dude!'
18778 myStore.add(myNewRecord);
18783 Roo.data.Record.create = function(o){
18784 var f = function(){
18785 f.superclass.constructor.apply(this, arguments);
18787 Roo.extend(f, Roo.data.Record);
18788 var p = f.prototype;
18789 p.fields = new Roo.util.MixedCollection(false, function(field){
18792 for(var i = 0, len = o.length; i < len; i++){
18793 p.fields.add(new Roo.data.Field(o[i]));
18795 f.getField = function(name){
18796 return p.fields.get(name);
18801 Roo.data.Record.AUTO_ID = 1000;
18802 Roo.data.Record.EDIT = 'edit';
18803 Roo.data.Record.REJECT = 'reject';
18804 Roo.data.Record.COMMIT = 'commit';
18806 Roo.data.Record.prototype = {
18808 * Readonly flag - true if this record has been modified.
18817 join : function(store){
18818 this.store = store;
18822 * Set the named field to the specified value.
18823 * @param {String} name The name of the field to set.
18824 * @param {Object} value The value to set the field to.
18826 set : function(name, value){
18827 if(this.data[name] == value){
18831 if(!this.modified){
18832 this.modified = {};
18834 if(typeof this.modified[name] == 'undefined'){
18835 this.modified[name] = this.data[name];
18837 this.data[name] = value;
18839 this.store.afterEdit(this);
18844 * Get the value of the named field.
18845 * @param {String} name The name of the field to get the value of.
18846 * @return {Object} The value of the field.
18848 get : function(name){
18849 return this.data[name];
18853 beginEdit : function(){
18854 this.editing = true;
18855 this.modified = {};
18859 cancelEdit : function(){
18860 this.editing = false;
18861 delete this.modified;
18865 endEdit : function(){
18866 this.editing = false;
18867 if(this.dirty && this.store){
18868 this.store.afterEdit(this);
18873 * Usually called by the {@link Roo.data.Store} which owns the Record.
18874 * Rejects all changes made to the Record since either creation, or the last commit operation.
18875 * Modified fields are reverted to their original values.
18877 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
18878 * of reject operations.
18880 reject : function(){
18881 var m = this.modified;
18883 if(typeof m[n] != "function"){
18884 this.data[n] = m[n];
18887 this.dirty = false;
18888 delete this.modified;
18889 this.editing = false;
18891 this.store.afterReject(this);
18896 * Usually called by the {@link Roo.data.Store} which owns the Record.
18897 * Commits all changes made to the Record since either creation, or the last commit operation.
18899 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
18900 * of commit operations.
18902 commit : function(){
18903 this.dirty = false;
18904 delete this.modified;
18905 this.editing = false;
18907 this.store.afterCommit(this);
18912 hasError : function(){
18913 return this.error != null;
18917 clearError : function(){
18922 * Creates a copy of this record.
18923 * @param {String} id (optional) A new record id if you don't want to use this record's id
18926 copy : function(newId) {
18927 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
18931 * Ext JS Library 1.1.1
18932 * Copyright(c) 2006-2007, Ext JS, LLC.
18934 * Originally Released Under LGPL - original licence link has changed is not relivant.
18937 * <script type="text/javascript">
18943 * @class Roo.data.Store
18944 * @extends Roo.util.Observable
18945 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
18946 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
18948 * 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
18949 * has no knowledge of the format of the data returned by the Proxy.<br>
18951 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
18952 * instances from the data object. These records are cached and made available through accessor functions.
18954 * Creates a new Store.
18955 * @param {Object} config A config object containing the objects needed for the Store to access data,
18956 * and read the data into Records.
18958 Roo.data.Store = function(config){
18959 this.data = new Roo.util.MixedCollection(false);
18960 this.data.getKey = function(o){
18963 this.baseParams = {};
18965 this.paramNames = {
18972 if(config && config.data){
18973 this.inlineData = config.data;
18974 delete config.data;
18977 Roo.apply(this, config);
18979 if(this.reader){ // reader passed
18980 this.reader = Roo.factory(this.reader, Roo.data);
18981 this.reader.xmodule = this.xmodule || false;
18982 if(!this.recordType){
18983 this.recordType = this.reader.recordType;
18985 if(this.reader.onMetaChange){
18986 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
18990 if(this.recordType){
18991 this.fields = this.recordType.prototype.fields;
18993 this.modified = [];
18997 * @event datachanged
18998 * Fires when the data cache has changed, and a widget which is using this Store
18999 * as a Record cache should refresh its view.
19000 * @param {Store} this
19002 datachanged : true,
19004 * @event metachange
19005 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
19006 * @param {Store} this
19007 * @param {Object} meta The JSON metadata
19012 * Fires when Records have been added to the Store
19013 * @param {Store} this
19014 * @param {Roo.data.Record[]} records The array of Records added
19015 * @param {Number} index The index at which the record(s) were added
19020 * Fires when a Record has been removed from the Store
19021 * @param {Store} this
19022 * @param {Roo.data.Record} record The Record that was removed
19023 * @param {Number} index The index at which the record was removed
19028 * Fires when a Record has been updated
19029 * @param {Store} this
19030 * @param {Roo.data.Record} record The Record that was updated
19031 * @param {String} operation The update operation being performed. Value may be one of:
19033 Roo.data.Record.EDIT
19034 Roo.data.Record.REJECT
19035 Roo.data.Record.COMMIT
19041 * Fires when the data cache has been cleared.
19042 * @param {Store} this
19046 * @event beforeload
19047 * Fires before a request is made for a new data object. If the beforeload handler returns false
19048 * the load action will be canceled.
19049 * @param {Store} this
19050 * @param {Object} options The loading options that were specified (see {@link #load} for details)
19055 * Fires after a new set of Records has been loaded.
19056 * @param {Store} this
19057 * @param {Roo.data.Record[]} records The Records that were loaded
19058 * @param {Object} options The loading options that were specified (see {@link #load} for details)
19062 * @event loadexception
19063 * Fires if an exception occurs in the Proxy during loading.
19064 * Called with the signature of the Proxy's "loadexception" event.
19065 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
19068 * @param {Object} return from JsonData.reader() - success, totalRecords, records
19069 * @param {Object} load options
19070 * @param {Object} jsonData from your request (normally this contains the Exception)
19072 loadexception : true
19076 this.proxy = Roo.factory(this.proxy, Roo.data);
19077 this.proxy.xmodule = this.xmodule || false;
19078 this.relayEvents(this.proxy, ["loadexception"]);
19080 this.sortToggle = {};
19082 Roo.data.Store.superclass.constructor.call(this);
19084 if(this.inlineData){
19085 this.loadData(this.inlineData);
19086 delete this.inlineData;
19089 Roo.extend(Roo.data.Store, Roo.util.Observable, {
19091 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
19092 * without a remote query - used by combo/forms at present.
19096 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
19099 * @cfg {Array} data Inline data to be loaded when the store is initialized.
19102 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
19103 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
19106 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
19107 * on any HTTP request
19110 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
19113 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
19114 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
19116 remoteSort : false,
19119 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
19120 * loaded or when a record is removed. (defaults to false).
19122 pruneModifiedRecords : false,
19125 lastOptions : null,
19128 * Add Records to the Store and fires the add event.
19129 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
19131 add : function(records){
19132 records = [].concat(records);
19133 for(var i = 0, len = records.length; i < len; i++){
19134 records[i].join(this);
19136 var index = this.data.length;
19137 this.data.addAll(records);
19138 this.fireEvent("add", this, records, index);
19142 * Remove a Record from the Store and fires the remove event.
19143 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
19145 remove : function(record){
19146 var index = this.data.indexOf(record);
19147 this.data.removeAt(index);
19148 if(this.pruneModifiedRecords){
19149 this.modified.remove(record);
19151 this.fireEvent("remove", this, record, index);
19155 * Remove all Records from the Store and fires the clear event.
19157 removeAll : function(){
19159 if(this.pruneModifiedRecords){
19160 this.modified = [];
19162 this.fireEvent("clear", this);
19166 * Inserts Records to the Store at the given index and fires the add event.
19167 * @param {Number} index The start index at which to insert the passed Records.
19168 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
19170 insert : function(index, records){
19171 records = [].concat(records);
19172 for(var i = 0, len = records.length; i < len; i++){
19173 this.data.insert(index, records[i]);
19174 records[i].join(this);
19176 this.fireEvent("add", this, records, index);
19180 * Get the index within the cache of the passed Record.
19181 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
19182 * @return {Number} The index of the passed Record. Returns -1 if not found.
19184 indexOf : function(record){
19185 return this.data.indexOf(record);
19189 * Get the index within the cache of the Record with the passed id.
19190 * @param {String} id The id of the Record to find.
19191 * @return {Number} The index of the Record. Returns -1 if not found.
19193 indexOfId : function(id){
19194 return this.data.indexOfKey(id);
19198 * Get the Record with the specified id.
19199 * @param {String} id The id of the Record to find.
19200 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
19202 getById : function(id){
19203 return this.data.key(id);
19207 * Get the Record at the specified index.
19208 * @param {Number} index The index of the Record to find.
19209 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
19211 getAt : function(index){
19212 return this.data.itemAt(index);
19216 * Returns a range of Records between specified indices.
19217 * @param {Number} startIndex (optional) The starting index (defaults to 0)
19218 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
19219 * @return {Roo.data.Record[]} An array of Records
19221 getRange : function(start, end){
19222 return this.data.getRange(start, end);
19226 storeOptions : function(o){
19227 o = Roo.apply({}, o);
19230 this.lastOptions = o;
19234 * Loads the Record cache from the configured Proxy using the configured Reader.
19236 * If using remote paging, then the first load call must specify the <em>start</em>
19237 * and <em>limit</em> properties in the options.params property to establish the initial
19238 * position within the dataset, and the number of Records to cache on each read from the Proxy.
19240 * <strong>It is important to note that for remote data sources, loading is asynchronous,
19241 * and this call will return before the new data has been loaded. Perform any post-processing
19242 * in a callback function, or in a "load" event handler.</strong>
19244 * @param {Object} options An object containing properties which control loading options:<ul>
19245 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
19246 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
19247 * passed the following arguments:<ul>
19248 * <li>r : Roo.data.Record[]</li>
19249 * <li>options: Options object from the load call</li>
19250 * <li>success: Boolean success indicator</li></ul></li>
19251 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
19252 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
19255 load : function(options){
19256 options = options || {};
19257 if(this.fireEvent("beforeload", this, options) !== false){
19258 this.storeOptions(options);
19259 var p = Roo.apply(options.params || {}, this.baseParams);
19260 // if meta was not loaded from remote source.. try requesting it.
19261 if (!this.reader.metaFromRemote) {
19262 p._requestMeta = 1;
19264 if(this.sortInfo && this.remoteSort){
19265 var pn = this.paramNames;
19266 p[pn["sort"]] = this.sortInfo.field;
19267 p[pn["dir"]] = this.sortInfo.direction;
19269 this.proxy.load(p, this.reader, this.loadRecords, this, options);
19274 * Reloads the Record cache from the configured Proxy using the configured Reader and
19275 * the options from the last load operation performed.
19276 * @param {Object} options (optional) An object containing properties which may override the options
19277 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
19278 * the most recently used options are reused).
19280 reload : function(options){
19281 this.load(Roo.applyIf(options||{}, this.lastOptions));
19285 // Called as a callback by the Reader during a load operation.
19286 loadRecords : function(o, options, success){
19287 if(!o || success === false){
19288 if(success !== false){
19289 this.fireEvent("load", this, [], options);
19291 if(options.callback){
19292 options.callback.call(options.scope || this, [], options, false);
19296 // if data returned failure - throw an exception.
19297 if (o.success === false) {
19298 this.fireEvent("loadexception", this, o, options, this.reader.jsonData);
19301 var r = o.records, t = o.totalRecords || r.length;
19302 if(!options || options.add !== true){
19303 if(this.pruneModifiedRecords){
19304 this.modified = [];
19306 for(var i = 0, len = r.length; i < len; i++){
19310 this.data = this.snapshot;
19311 delete this.snapshot;
19314 this.data.addAll(r);
19315 this.totalLength = t;
19317 this.fireEvent("datachanged", this);
19319 this.totalLength = Math.max(t, this.data.length+r.length);
19322 this.fireEvent("load", this, r, options);
19323 if(options.callback){
19324 options.callback.call(options.scope || this, r, options, true);
19329 * Loads data from a passed data block. A Reader which understands the format of the data
19330 * must have been configured in the constructor.
19331 * @param {Object} data The data block from which to read the Records. The format of the data expected
19332 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
19333 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
19335 loadData : function(o, append){
19336 var r = this.reader.readRecords(o);
19337 this.loadRecords(r, {add: append}, true);
19341 * Gets the number of cached records.
19343 * <em>If using paging, this may not be the total size of the dataset. If the data object
19344 * used by the Reader contains the dataset size, then the getTotalCount() function returns
19345 * the data set size</em>
19347 getCount : function(){
19348 return this.data.length || 0;
19352 * Gets the total number of records in the dataset as returned by the server.
19354 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
19355 * the dataset size</em>
19357 getTotalCount : function(){
19358 return this.totalLength || 0;
19362 * Returns the sort state of the Store as an object with two properties:
19364 field {String} The name of the field by which the Records are sorted
19365 direction {String} The sort order, "ASC" or "DESC"
19368 getSortState : function(){
19369 return this.sortInfo;
19373 applySort : function(){
19374 if(this.sortInfo && !this.remoteSort){
19375 var s = this.sortInfo, f = s.field;
19376 var st = this.fields.get(f).sortType;
19377 var fn = function(r1, r2){
19378 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
19379 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
19381 this.data.sort(s.direction, fn);
19382 if(this.snapshot && this.snapshot != this.data){
19383 this.snapshot.sort(s.direction, fn);
19389 * Sets the default sort column and order to be used by the next load operation.
19390 * @param {String} fieldName The name of the field to sort by.
19391 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
19393 setDefaultSort : function(field, dir){
19394 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
19398 * Sort the Records.
19399 * If remote sorting is used, the sort is performed on the server, and the cache is
19400 * reloaded. If local sorting is used, the cache is sorted internally.
19401 * @param {String} fieldName The name of the field to sort by.
19402 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
19404 sort : function(fieldName, dir){
19405 var f = this.fields.get(fieldName);
19407 if(this.sortInfo && this.sortInfo.field == f.name){ // toggle sort dir
19408 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
19413 this.sortToggle[f.name] = dir;
19414 this.sortInfo = {field: f.name, direction: dir};
19415 if(!this.remoteSort){
19417 this.fireEvent("datachanged", this);
19419 this.load(this.lastOptions);
19424 * Calls the specified function for each of the Records in the cache.
19425 * @param {Function} fn The function to call. The Record is passed as the first parameter.
19426 * Returning <em>false</em> aborts and exits the iteration.
19427 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
19429 each : function(fn, scope){
19430 this.data.each(fn, scope);
19434 * Gets all records modified since the last commit. Modified records are persisted across load operations
19435 * (e.g., during paging).
19436 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
19438 getModifiedRecords : function(){
19439 return this.modified;
19443 createFilterFn : function(property, value, anyMatch){
19444 if(!value.exec){ // not a regex
19445 value = String(value);
19446 if(value.length == 0){
19449 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
19451 return function(r){
19452 return value.test(r.data[property]);
19457 * Sums the value of <i>property</i> for each record between start and end and returns the result.
19458 * @param {String} property A field on your records
19459 * @param {Number} start The record index to start at (defaults to 0)
19460 * @param {Number} end The last record index to include (defaults to length - 1)
19461 * @return {Number} The sum
19463 sum : function(property, start, end){
19464 var rs = this.data.items, v = 0;
19465 start = start || 0;
19466 end = (end || end === 0) ? end : rs.length-1;
19468 for(var i = start; i <= end; i++){
19469 v += (rs[i].data[property] || 0);
19475 * Filter the records by a specified property.
19476 * @param {String} field A field on your records
19477 * @param {String/RegExp} value Either a string that the field
19478 * should start with or a RegExp to test against the field
19479 * @param {Boolean} anyMatch True to match any part not just the beginning
19481 filter : function(property, value, anyMatch){
19482 var fn = this.createFilterFn(property, value, anyMatch);
19483 return fn ? this.filterBy(fn) : this.clearFilter();
19487 * Filter by a function. The specified function will be called with each
19488 * record in this data source. If the function returns true the record is included,
19489 * otherwise it is filtered.
19490 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
19491 * @param {Object} scope (optional) The scope of the function (defaults to this)
19493 filterBy : function(fn, scope){
19494 this.snapshot = this.snapshot || this.data;
19495 this.data = this.queryBy(fn, scope||this);
19496 this.fireEvent("datachanged", this);
19500 * Query the records by a specified property.
19501 * @param {String} field A field on your records
19502 * @param {String/RegExp} value Either a string that the field
19503 * should start with or a RegExp to test against the field
19504 * @param {Boolean} anyMatch True to match any part not just the beginning
19505 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
19507 query : function(property, value, anyMatch){
19508 var fn = this.createFilterFn(property, value, anyMatch);
19509 return fn ? this.queryBy(fn) : this.data.clone();
19513 * Query by a function. The specified function will be called with each
19514 * record in this data source. If the function returns true the record is included
19516 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
19517 * @param {Object} scope (optional) The scope of the function (defaults to this)
19518 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
19520 queryBy : function(fn, scope){
19521 var data = this.snapshot || this.data;
19522 return data.filterBy(fn, scope||this);
19526 * Collects unique values for a particular dataIndex from this store.
19527 * @param {String} dataIndex The property to collect
19528 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
19529 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
19530 * @return {Array} An array of the unique values
19532 collect : function(dataIndex, allowNull, bypassFilter){
19533 var d = (bypassFilter === true && this.snapshot) ?
19534 this.snapshot.items : this.data.items;
19535 var v, sv, r = [], l = {};
19536 for(var i = 0, len = d.length; i < len; i++){
19537 v = d[i].data[dataIndex];
19539 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
19548 * Revert to a view of the Record cache with no filtering applied.
19549 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
19551 clearFilter : function(suppressEvent){
19552 if(this.snapshot && this.snapshot != this.data){
19553 this.data = this.snapshot;
19554 delete this.snapshot;
19555 if(suppressEvent !== true){
19556 this.fireEvent("datachanged", this);
19562 afterEdit : function(record){
19563 if(this.modified.indexOf(record) == -1){
19564 this.modified.push(record);
19566 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
19570 afterReject : function(record){
19571 this.modified.remove(record);
19572 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
19576 afterCommit : function(record){
19577 this.modified.remove(record);
19578 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
19582 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
19583 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
19585 commitChanges : function(){
19586 var m = this.modified.slice(0);
19587 this.modified = [];
19588 for(var i = 0, len = m.length; i < len; i++){
19594 * Cancel outstanding changes on all changed records.
19596 rejectChanges : function(){
19597 var m = this.modified.slice(0);
19598 this.modified = [];
19599 for(var i = 0, len = m.length; i < len; i++){
19604 onMetaChange : function(meta, rtype, o){
19605 this.recordType = rtype;
19606 this.fields = rtype.prototype.fields;
19607 delete this.snapshot;
19608 this.sortInfo = meta.sortInfo || this.sortInfo;
19609 this.modified = [];
19610 this.fireEvent('metachange', this, this.reader.meta);
19614 * Ext JS Library 1.1.1
19615 * Copyright(c) 2006-2007, Ext JS, LLC.
19617 * Originally Released Under LGPL - original licence link has changed is not relivant.
19620 * <script type="text/javascript">
19624 * @class Roo.data.SimpleStore
19625 * @extends Roo.data.Store
19626 * Small helper class to make creating Stores from Array data easier.
19627 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
19628 * @cfg {Array} fields An array of field definition objects, or field name strings.
19629 * @cfg {Array} data The multi-dimensional array of data
19631 * @param {Object} config
19633 Roo.data.SimpleStore = function(config){
19634 Roo.data.SimpleStore.superclass.constructor.call(this, {
19636 reader: new Roo.data.ArrayReader({
19639 Roo.data.Record.create(config.fields)
19641 proxy : new Roo.data.MemoryProxy(config.data)
19645 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
19647 * Ext JS Library 1.1.1
19648 * Copyright(c) 2006-2007, Ext JS, LLC.
19650 * Originally Released Under LGPL - original licence link has changed is not relivant.
19653 * <script type="text/javascript">
19658 * @extends Roo.data.Store
19659 * @class Roo.data.JsonStore
19660 * Small helper class to make creating Stores for JSON data easier. <br/>
19662 var store = new Roo.data.JsonStore({
19663 url: 'get-images.php',
19665 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
19668 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
19669 * JsonReader and HttpProxy (unless inline data is provided).</b>
19670 * @cfg {Array} fields An array of field definition objects, or field name strings.
19672 * @param {Object} config
19674 Roo.data.JsonStore = function(c){
19675 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
19676 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
19677 reader: new Roo.data.JsonReader(c, c.fields)
19680 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
19682 * Ext JS Library 1.1.1
19683 * Copyright(c) 2006-2007, Ext JS, LLC.
19685 * Originally Released Under LGPL - original licence link has changed is not relivant.
19688 * <script type="text/javascript">
19692 Roo.data.Field = function(config){
19693 if(typeof config == "string"){
19694 config = {name: config};
19696 Roo.apply(this, config);
19699 this.type = "auto";
19702 var st = Roo.data.SortTypes;
19703 // named sortTypes are supported, here we look them up
19704 if(typeof this.sortType == "string"){
19705 this.sortType = st[this.sortType];
19708 // set default sortType for strings and dates
19709 if(!this.sortType){
19712 this.sortType = st.asUCString;
19715 this.sortType = st.asDate;
19718 this.sortType = st.none;
19723 var stripRe = /[\$,%]/g;
19725 // prebuilt conversion function for this field, instead of
19726 // switching every time we're reading a value
19728 var cv, dateFormat = this.dateFormat;
19733 cv = function(v){ return v; };
19736 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
19740 return v !== undefined && v !== null && v !== '' ?
19741 parseInt(String(v).replace(stripRe, ""), 10) : '';
19746 return v !== undefined && v !== null && v !== '' ?
19747 parseFloat(String(v).replace(stripRe, ""), 10) : '';
19752 cv = function(v){ return v === true || v === "true" || v == 1; };
19759 if(v instanceof Date){
19763 if(dateFormat == "timestamp"){
19764 return new Date(v*1000);
19766 return Date.parseDate(v, dateFormat);
19768 var parsed = Date.parse(v);
19769 return parsed ? new Date(parsed) : null;
19778 Roo.data.Field.prototype = {
19786 * Ext JS Library 1.1.1
19787 * Copyright(c) 2006-2007, Ext JS, LLC.
19789 * Originally Released Under LGPL - original licence link has changed is not relivant.
19792 * <script type="text/javascript">
19795 // Base class for reading structured data from a data source. This class is intended to be
19796 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
19799 * @class Roo.data.DataReader
19800 * Base class for reading structured data from a data source. This class is intended to be
19801 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
19804 Roo.data.DataReader = function(meta, recordType){
19808 this.recordType = recordType instanceof Array ?
19809 Roo.data.Record.create(recordType) : recordType;
19812 Roo.data.DataReader.prototype = {
19814 * Create an empty record
19815 * @param {Object} data (optional) - overlay some values
19816 * @return {Roo.data.Record} record created.
19818 newRow : function(d) {
19820 this.recordType.prototype.fields.each(function(c) {
19822 case 'int' : da[c.name] = 0; break;
19823 case 'date' : da[c.name] = new Date(); break;
19824 case 'float' : da[c.name] = 0.0; break;
19825 case 'boolean' : da[c.name] = false; break;
19826 default : da[c.name] = ""; break;
19830 return new this.recordType(Roo.apply(da, d));
19835 * Ext JS Library 1.1.1
19836 * Copyright(c) 2006-2007, Ext JS, LLC.
19838 * Originally Released Under LGPL - original licence link has changed is not relivant.
19841 * <script type="text/javascript">
19845 * @class Roo.data.DataProxy
19846 * @extends Roo.data.Observable
19847 * This class is an abstract base class for implementations which provide retrieval of
19848 * unformatted data objects.<br>
19850 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
19851 * (of the appropriate type which knows how to parse the data object) to provide a block of
19852 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
19854 * Custom implementations must implement the load method as described in
19855 * {@link Roo.data.HttpProxy#load}.
19857 Roo.data.DataProxy = function(){
19860 * @event beforeload
19861 * Fires before a network request is made to retrieve a data object.
19862 * @param {Object} This DataProxy object.
19863 * @param {Object} params The params parameter to the load function.
19868 * Fires before the load method's callback is called.
19869 * @param {Object} This DataProxy object.
19870 * @param {Object} o The data object.
19871 * @param {Object} arg The callback argument object passed to the load function.
19875 * @event loadexception
19876 * Fires if an Exception occurs during data retrieval.
19877 * @param {Object} This DataProxy object.
19878 * @param {Object} o The data object.
19879 * @param {Object} arg The callback argument object passed to the load function.
19880 * @param {Object} e The Exception.
19882 loadexception : true
19884 Roo.data.DataProxy.superclass.constructor.call(this);
19887 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
19890 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
19894 * Ext JS Library 1.1.1
19895 * Copyright(c) 2006-2007, Ext JS, LLC.
19897 * Originally Released Under LGPL - original licence link has changed is not relivant.
19900 * <script type="text/javascript">
19903 * @class Roo.data.MemoryProxy
19904 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
19905 * to the Reader when its load method is called.
19907 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
19909 Roo.data.MemoryProxy = function(data){
19913 Roo.data.MemoryProxy.superclass.constructor.call(this);
19917 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
19919 * Load data from the requested source (in this case an in-memory
19920 * data object passed to the constructor), read the data object into
19921 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
19922 * process that block using the passed callback.
19923 * @param {Object} params This parameter is not used by the MemoryProxy class.
19924 * @param {Roo.data.DataReader} reader The Reader object which converts the data
19925 * object into a block of Roo.data.Records.
19926 * @param {Function} callback The function into which to pass the block of Roo.data.records.
19927 * The function must be passed <ul>
19928 * <li>The Record block object</li>
19929 * <li>The "arg" argument from the load function</li>
19930 * <li>A boolean success indicator</li>
19932 * @param {Object} scope The scope in which to call the callback
19933 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
19935 load : function(params, reader, callback, scope, arg){
19936 params = params || {};
19939 result = reader.readRecords(this.data);
19941 this.fireEvent("loadexception", this, arg, null, e);
19942 callback.call(scope, null, arg, false);
19945 callback.call(scope, result, arg, true);
19949 update : function(params, records){
19954 * Ext JS Library 1.1.1
19955 * Copyright(c) 2006-2007, Ext JS, LLC.
19957 * Originally Released Under LGPL - original licence link has changed is not relivant.
19960 * <script type="text/javascript">
19963 * @class Roo.data.HttpProxy
19964 * @extends Roo.data.DataProxy
19965 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
19966 * configured to reference a certain URL.<br><br>
19968 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
19969 * from which the running page was served.<br><br>
19971 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
19973 * Be aware that to enable the browser to parse an XML document, the server must set
19974 * the Content-Type header in the HTTP response to "text/xml".
19976 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
19977 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
19978 * will be used to make the request.
19980 Roo.data.HttpProxy = function(conn){
19981 Roo.data.HttpProxy.superclass.constructor.call(this);
19982 // is conn a conn config or a real conn?
19984 this.useAjax = !conn || !conn.events;
19988 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
19989 // thse are take from connection...
19992 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
19995 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
19996 * extra parameters to each request made by this object. (defaults to undefined)
19999 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
20000 * to each request made by this object. (defaults to undefined)
20003 * @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)
20006 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
20009 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
20015 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
20019 * Return the {@link Roo.data.Connection} object being used by this Proxy.
20020 * @return {Connection} The Connection object. This object may be used to subscribe to events on
20021 * a finer-grained basis than the DataProxy events.
20023 getConnection : function(){
20024 return this.useAjax ? Roo.Ajax : this.conn;
20028 * Load data from the configured {@link Roo.data.Connection}, read the data object into
20029 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
20030 * process that block using the passed callback.
20031 * @param {Object} params An object containing properties which are to be used as HTTP parameters
20032 * for the request to the remote server.
20033 * @param {Roo.data.DataReader} reader The Reader object which converts the data
20034 * object into a block of Roo.data.Records.
20035 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
20036 * The function must be passed <ul>
20037 * <li>The Record block object</li>
20038 * <li>The "arg" argument from the load function</li>
20039 * <li>A boolean success indicator</li>
20041 * @param {Object} scope The scope in which to call the callback
20042 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
20044 load : function(params, reader, callback, scope, arg){
20045 if(this.fireEvent("beforeload", this, params) !== false){
20047 params : params || {},
20049 callback : callback,
20054 callback : this.loadResponse,
20058 Roo.applyIf(o, this.conn);
20059 if(this.activeRequest){
20060 Roo.Ajax.abort(this.activeRequest);
20062 this.activeRequest = Roo.Ajax.request(o);
20064 this.conn.request(o);
20067 callback.call(scope||this, null, arg, false);
20072 loadResponse : function(o, success, response){
20073 delete this.activeRequest;
20075 this.fireEvent("loadexception", this, o, response);
20076 o.request.callback.call(o.request.scope, null, o.request.arg, false);
20081 result = o.reader.read(response);
20083 this.fireEvent("loadexception", this, o, response, e);
20084 o.request.callback.call(o.request.scope, null, o.request.arg, false);
20088 this.fireEvent("load", this, o, o.request.arg);
20089 o.request.callback.call(o.request.scope, result, o.request.arg, true);
20093 update : function(dataSet){
20098 updateResponse : function(dataSet){
20103 * Ext JS Library 1.1.1
20104 * Copyright(c) 2006-2007, Ext JS, LLC.
20106 * Originally Released Under LGPL - original licence link has changed is not relivant.
20109 * <script type="text/javascript">
20113 * @class Roo.data.ScriptTagProxy
20114 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
20115 * other than the originating domain of the running page.<br><br>
20117 * <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
20118 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
20120 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
20121 * source code that is used as the source inside a <script> tag.<br><br>
20123 * In order for the browser to process the returned data, the server must wrap the data object
20124 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
20125 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
20126 * depending on whether the callback name was passed:
20129 boolean scriptTag = false;
20130 String cb = request.getParameter("callback");
20133 response.setContentType("text/javascript");
20135 response.setContentType("application/x-json");
20137 Writer out = response.getWriter();
20139 out.write(cb + "(");
20141 out.print(dataBlock.toJsonString());
20148 * @param {Object} config A configuration object.
20150 Roo.data.ScriptTagProxy = function(config){
20151 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
20152 Roo.apply(this, config);
20153 this.head = document.getElementsByTagName("head")[0];
20156 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
20158 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
20160 * @cfg {String} url The URL from which to request the data object.
20163 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
20167 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
20168 * the server the name of the callback function set up by the load call to process the returned data object.
20169 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
20170 * javascript output which calls this named function passing the data object as its only parameter.
20172 callbackParam : "callback",
20174 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
20175 * name to the request.
20180 * Load data from the configured URL, read the data object into
20181 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
20182 * process that block using the passed callback.
20183 * @param {Object} params An object containing properties which are to be used as HTTP parameters
20184 * for the request to the remote server.
20185 * @param {Roo.data.DataReader} reader The Reader object which converts the data
20186 * object into a block of Roo.data.Records.
20187 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
20188 * The function must be passed <ul>
20189 * <li>The Record block object</li>
20190 * <li>The "arg" argument from the load function</li>
20191 * <li>A boolean success indicator</li>
20193 * @param {Object} scope The scope in which to call the callback
20194 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
20196 load : function(params, reader, callback, scope, arg){
20197 if(this.fireEvent("beforeload", this, params) !== false){
20199 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
20201 var url = this.url;
20202 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
20204 url += "&_dc=" + (new Date().getTime());
20206 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
20209 cb : "stcCallback"+transId,
20210 scriptId : "stcScript"+transId,
20214 callback : callback,
20220 window[trans.cb] = function(o){
20221 conn.handleResponse(o, trans);
20224 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
20226 if(this.autoAbort !== false){
20230 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
20232 var script = document.createElement("script");
20233 script.setAttribute("src", url);
20234 script.setAttribute("type", "text/javascript");
20235 script.setAttribute("id", trans.scriptId);
20236 this.head.appendChild(script);
20238 this.trans = trans;
20240 callback.call(scope||this, null, arg, false);
20245 isLoading : function(){
20246 return this.trans ? true : false;
20250 * Abort the current server request.
20252 abort : function(){
20253 if(this.isLoading()){
20254 this.destroyTrans(this.trans);
20259 destroyTrans : function(trans, isLoaded){
20260 this.head.removeChild(document.getElementById(trans.scriptId));
20261 clearTimeout(trans.timeoutId);
20263 window[trans.cb] = undefined;
20265 delete window[trans.cb];
20268 // if hasn't been loaded, wait for load to remove it to prevent script error
20269 window[trans.cb] = function(){
20270 window[trans.cb] = undefined;
20272 delete window[trans.cb];
20279 handleResponse : function(o, trans){
20280 this.trans = false;
20281 this.destroyTrans(trans, true);
20284 result = trans.reader.readRecords(o);
20286 this.fireEvent("loadexception", this, o, trans.arg, e);
20287 trans.callback.call(trans.scope||window, null, trans.arg, false);
20290 this.fireEvent("load", this, o, trans.arg);
20291 trans.callback.call(trans.scope||window, result, trans.arg, true);
20295 handleFailure : function(trans){
20296 this.trans = false;
20297 this.destroyTrans(trans, false);
20298 this.fireEvent("loadexception", this, null, trans.arg);
20299 trans.callback.call(trans.scope||window, null, trans.arg, false);
20303 * Ext JS Library 1.1.1
20304 * Copyright(c) 2006-2007, Ext JS, LLC.
20306 * Originally Released Under LGPL - original licence link has changed is not relivant.
20309 * <script type="text/javascript">
20313 * @class Roo.data.JsonReader
20314 * @extends Roo.data.DataReader
20315 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
20316 * based on mappings in a provided Roo.data.Record constructor.
20318 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
20319 * in the reply previously.
20324 var RecordDef = Roo.data.Record.create([
20325 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
20326 {name: 'occupation'} // This field will use "occupation" as the mapping.
20328 var myReader = new Roo.data.JsonReader({
20329 totalProperty: "results", // The property which contains the total dataset size (optional)
20330 root: "rows", // The property which contains an Array of row objects
20331 id: "id" // The property within each row object that provides an ID for the record (optional)
20335 * This would consume a JSON file like this:
20337 { 'results': 2, 'rows': [
20338 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
20339 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
20342 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
20343 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
20344 * paged from the remote server.
20345 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
20346 * @cfg {String} root name of the property which contains the Array of row objects.
20347 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
20349 * Create a new JsonReader
20350 * @param {Object} meta Metadata configuration options
20351 * @param {Object} recordType Either an Array of field definition objects,
20352 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
20354 Roo.data.JsonReader = function(meta, recordType){
20357 // set some defaults:
20358 Roo.applyIf(meta, {
20359 totalProperty: 'total',
20360 successProperty : 'success',
20365 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
20367 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
20370 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
20371 * Used by Store query builder to append _requestMeta to params.
20374 metaFromRemote : false,
20376 * This method is only used by a DataProxy which has retrieved data from a remote server.
20377 * @param {Object} response The XHR object which contains the JSON data in its responseText.
20378 * @return {Object} data A data block which is used by an Roo.data.Store object as
20379 * a cache of Roo.data.Records.
20381 read : function(response){
20382 var json = response.responseText;
20384 var o = /* eval:var:o */ eval("("+json+")");
20386 throw {message: "JsonReader.read: Json object not found"};
20392 this.metaFromRemote = true;
20393 this.meta = o.metaData;
20394 this.recordType = Roo.data.Record.create(o.metaData.fields);
20395 this.onMetaChange(this.meta, this.recordType, o);
20397 return this.readRecords(o);
20400 // private function a store will implement
20401 onMetaChange : function(meta, recordType, o){
20408 simpleAccess: function(obj, subsc) {
20415 getJsonAccessor: function(){
20417 return function(expr) {
20419 return(re.test(expr))
20420 ? new Function("obj", "return obj." + expr)
20425 return Roo.emptyFn;
20430 * Create a data block containing Roo.data.Records from an XML document.
20431 * @param {Object} o An object which contains an Array of row objects in the property specified
20432 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
20433 * which contains the total size of the dataset.
20434 * @return {Object} data A data block which is used by an Roo.data.Store object as
20435 * a cache of Roo.data.Records.
20437 readRecords : function(o){
20439 * After any data loads, the raw JSON data is available for further custom processing.
20443 var s = this.meta, Record = this.recordType,
20444 f = Record.prototype.fields, fi = f.items, fl = f.length;
20446 // Generate extraction functions for the totalProperty, the root, the id, and for each field
20448 if(s.totalProperty) {
20449 this.getTotal = this.getJsonAccessor(s.totalProperty);
20451 if(s.successProperty) {
20452 this.getSuccess = this.getJsonAccessor(s.successProperty);
20454 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
20456 var g = this.getJsonAccessor(s.id);
20457 this.getId = function(rec) {
20459 return (r === undefined || r === "") ? null : r;
20462 this.getId = function(){return null;};
20465 for(var jj = 0; jj < fl; jj++){
20467 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
20468 this.ef[jj] = this.getJsonAccessor(map);
20472 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
20473 if(s.totalProperty){
20474 var vt = parseInt(this.getTotal(o), 10);
20479 if(s.successProperty){
20480 var vs = this.getSuccess(o);
20481 if(vs === false || vs === 'false'){
20486 for(var i = 0; i < c; i++){
20489 var id = this.getId(n);
20490 for(var j = 0; j < fl; j++){
20492 var v = this.ef[j](n);
20494 Roo.log('missing convert for ' + f.name);
20498 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
20500 var record = new Record(values, id);
20502 records[i] = record;
20507 totalRecords : totalRecords
20512 * Ext JS Library 1.1.1
20513 * Copyright(c) 2006-2007, Ext JS, LLC.
20515 * Originally Released Under LGPL - original licence link has changed is not relivant.
20518 * <script type="text/javascript">
20522 * @class Roo.data.XmlReader
20523 * @extends Roo.data.DataReader
20524 * Data reader class to create an Array of {@link Roo.data.Record} objects from an XML document
20525 * based on mappings in a provided Roo.data.Record constructor.<br><br>
20527 * <em>Note that in order for the browser to parse a returned XML document, the Content-Type
20528 * header in the HTTP response must be set to "text/xml".</em>
20532 var RecordDef = Roo.data.Record.create([
20533 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
20534 {name: 'occupation'} // This field will use "occupation" as the mapping.
20536 var myReader = new Roo.data.XmlReader({
20537 totalRecords: "results", // The element which contains the total dataset size (optional)
20538 record: "row", // The repeated element which contains row information
20539 id: "id" // The element within the row that provides an ID for the record (optional)
20543 * This would consume an XML file like this:
20547 <results>2</results>
20550 <name>Bill</name>
20551 <occupation>Gardener</occupation>
20555 <name>Ben</name>
20556 <occupation>Horticulturalist</occupation>
20560 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
20561 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
20562 * paged from the remote server.
20563 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
20564 * @cfg {String} success The DomQuery path to the success attribute used by forms.
20565 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
20566 * a record identifier value.
20568 * Create a new XmlReader
20569 * @param {Object} meta Metadata configuration options
20570 * @param {Mixed} recordType The definition of the data record type to produce. This can be either a valid
20571 * Record subclass created with {@link Roo.data.Record#create}, or an array of objects with which to call
20572 * Roo.data.Record.create. See the {@link Roo.data.Record} class for more details.
20574 Roo.data.XmlReader = function(meta, recordType){
20576 Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields);
20578 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
20580 * This method is only used by a DataProxy which has retrieved data from a remote server.
20581 * @param {Object} response The XHR object which contains the parsed XML document. The response is expected
20582 * to contain a method called 'responseXML' that returns an XML document object.
20583 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
20584 * a cache of Roo.data.Records.
20586 read : function(response){
20587 var doc = response.responseXML;
20589 throw {message: "XmlReader.read: XML Document not available"};
20591 return this.readRecords(doc);
20595 * Create a data block containing Roo.data.Records from an XML document.
20596 * @param {Object} doc A parsed XML document.
20597 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
20598 * a cache of Roo.data.Records.
20600 readRecords : function(doc){
20602 * After any data loads/reads, the raw XML Document is available for further custom processing.
20603 * @type XMLDocument
20605 this.xmlData = doc;
20606 var root = doc.documentElement || doc;
20607 var q = Roo.DomQuery;
20608 var recordType = this.recordType, fields = recordType.prototype.fields;
20609 var sid = this.meta.id;
20610 var totalRecords = 0, success = true;
20611 if(this.meta.totalRecords){
20612 totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
20615 if(this.meta.success){
20616 var sv = q.selectValue(this.meta.success, root, true);
20617 success = sv !== false && sv !== 'false';
20620 var ns = q.select(this.meta.record, root);
20621 for(var i = 0, len = ns.length; i < len; i++) {
20624 var id = sid ? q.selectValue(sid, n) : undefined;
20625 for(var j = 0, jlen = fields.length; j < jlen; j++){
20626 var f = fields.items[j];
20627 var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
20629 values[f.name] = v;
20631 var record = new recordType(values, id);
20633 records[records.length] = record;
20639 totalRecords : totalRecords || records.length
20644 * Ext JS Library 1.1.1
20645 * Copyright(c) 2006-2007, Ext JS, LLC.
20647 * Originally Released Under LGPL - original licence link has changed is not relivant.
20650 * <script type="text/javascript">
20654 * @class Roo.data.ArrayReader
20655 * @extends Roo.data.DataReader
20656 * Data reader class to create an Array of Roo.data.Record objects from an Array.
20657 * Each element of that Array represents a row of data fields. The
20658 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
20659 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
20663 var RecordDef = Roo.data.Record.create([
20664 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
20665 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
20667 var myReader = new Roo.data.ArrayReader({
20668 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
20672 * This would consume an Array like this:
20674 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
20676 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
20678 * Create a new JsonReader
20679 * @param {Object} meta Metadata configuration options.
20680 * @param {Object} recordType Either an Array of field definition objects
20681 * as specified to {@link Roo.data.Record#create},
20682 * or an {@link Roo.data.Record} object
20683 * created using {@link Roo.data.Record#create}.
20685 Roo.data.ArrayReader = function(meta, recordType){
20686 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
20689 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
20691 * Create a data block containing Roo.data.Records from an XML document.
20692 * @param {Object} o An Array of row objects which represents the dataset.
20693 * @return {Object} data A data block which is used by an Roo.data.Store object as
20694 * a cache of Roo.data.Records.
20696 readRecords : function(o){
20697 var sid = this.meta ? this.meta.id : null;
20698 var recordType = this.recordType, fields = recordType.prototype.fields;
20701 for(var i = 0; i < root.length; i++){
20704 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
20705 for(var j = 0, jlen = fields.length; j < jlen; j++){
20706 var f = fields.items[j];
20707 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
20708 var v = n[k] !== undefined ? n[k] : f.defaultValue;
20710 values[f.name] = v;
20712 var record = new recordType(values, id);
20714 records[records.length] = record;
20718 totalRecords : records.length
20723 * Ext JS Library 1.1.1
20724 * Copyright(c) 2006-2007, Ext JS, LLC.
20726 * Originally Released Under LGPL - original licence link has changed is not relivant.
20729 * <script type="text/javascript">
20734 * @class Roo.data.Tree
20735 * @extends Roo.util.Observable
20736 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
20737 * in the tree have most standard DOM functionality.
20739 * @param {Node} root (optional) The root node
20741 Roo.data.Tree = function(root){
20742 this.nodeHash = {};
20744 * The root node for this tree
20749 this.setRootNode(root);
20754 * Fires when a new child node is appended to a node in this tree.
20755 * @param {Tree} tree The owner tree
20756 * @param {Node} parent The parent node
20757 * @param {Node} node The newly appended node
20758 * @param {Number} index The index of the newly appended node
20763 * Fires when a child node is removed from a node in this tree.
20764 * @param {Tree} tree The owner tree
20765 * @param {Node} parent The parent node
20766 * @param {Node} node The child node removed
20771 * Fires when a node is moved to a new location in the tree
20772 * @param {Tree} tree The owner tree
20773 * @param {Node} node The node moved
20774 * @param {Node} oldParent The old parent of this node
20775 * @param {Node} newParent The new parent of this node
20776 * @param {Number} index The index it was moved to
20781 * Fires when a new child node is inserted in a node in this tree.
20782 * @param {Tree} tree The owner tree
20783 * @param {Node} parent The parent node
20784 * @param {Node} node The child node inserted
20785 * @param {Node} refNode The child node the node was inserted before
20789 * @event beforeappend
20790 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
20791 * @param {Tree} tree The owner tree
20792 * @param {Node} parent The parent node
20793 * @param {Node} node The child node to be appended
20795 "beforeappend" : true,
20797 * @event beforeremove
20798 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
20799 * @param {Tree} tree The owner tree
20800 * @param {Node} parent The parent node
20801 * @param {Node} node The child node to be removed
20803 "beforeremove" : true,
20805 * @event beforemove
20806 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
20807 * @param {Tree} tree The owner tree
20808 * @param {Node} node The node being moved
20809 * @param {Node} oldParent The parent of the node
20810 * @param {Node} newParent The new parent the node is moving to
20811 * @param {Number} index The index it is being moved to
20813 "beforemove" : true,
20815 * @event beforeinsert
20816 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
20817 * @param {Tree} tree The owner tree
20818 * @param {Node} parent The parent node
20819 * @param {Node} node The child node to be inserted
20820 * @param {Node} refNode The child node the node is being inserted before
20822 "beforeinsert" : true
20825 Roo.data.Tree.superclass.constructor.call(this);
20828 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
20829 pathSeparator: "/",
20831 proxyNodeEvent : function(){
20832 return this.fireEvent.apply(this, arguments);
20836 * Returns the root node for this tree.
20839 getRootNode : function(){
20844 * Sets the root node for this tree.
20845 * @param {Node} node
20848 setRootNode : function(node){
20850 node.ownerTree = this;
20851 node.isRoot = true;
20852 this.registerNode(node);
20857 * Gets a node in this tree by its id.
20858 * @param {String} id
20861 getNodeById : function(id){
20862 return this.nodeHash[id];
20865 registerNode : function(node){
20866 this.nodeHash[node.id] = node;
20869 unregisterNode : function(node){
20870 delete this.nodeHash[node.id];
20873 toString : function(){
20874 return "[Tree"+(this.id?" "+this.id:"")+"]";
20879 * @class Roo.data.Node
20880 * @extends Roo.util.Observable
20881 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
20882 * @cfg {String} id The id for this node. If one is not specified, one is generated.
20884 * @param {Object} attributes The attributes/config for the node
20886 Roo.data.Node = function(attributes){
20888 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
20891 this.attributes = attributes || {};
20892 this.leaf = this.attributes.leaf;
20894 * The node id. @type String
20896 this.id = this.attributes.id;
20898 this.id = Roo.id(null, "ynode-");
20899 this.attributes.id = this.id;
20902 * All child nodes of this node. @type Array
20904 this.childNodes = [];
20905 if(!this.childNodes.indexOf){ // indexOf is a must
20906 this.childNodes.indexOf = function(o){
20907 for(var i = 0, len = this.length; i < len; i++){
20916 * The parent node for this node. @type Node
20918 this.parentNode = null;
20920 * The first direct child node of this node, or null if this node has no child nodes. @type Node
20922 this.firstChild = null;
20924 * The last direct child node of this node, or null if this node has no child nodes. @type Node
20926 this.lastChild = null;
20928 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
20930 this.previousSibling = null;
20932 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
20934 this.nextSibling = null;
20939 * Fires when a new child node is appended
20940 * @param {Tree} tree The owner tree
20941 * @param {Node} this This node
20942 * @param {Node} node The newly appended node
20943 * @param {Number} index The index of the newly appended node
20948 * Fires when a child node is removed
20949 * @param {Tree} tree The owner tree
20950 * @param {Node} this This node
20951 * @param {Node} node The removed node
20956 * Fires when this node is moved to a new location in the tree
20957 * @param {Tree} tree The owner tree
20958 * @param {Node} this This node
20959 * @param {Node} oldParent The old parent of this node
20960 * @param {Node} newParent The new parent of this node
20961 * @param {Number} index The index it was moved to
20966 * Fires when a new child node is inserted.
20967 * @param {Tree} tree The owner tree
20968 * @param {Node} this This node
20969 * @param {Node} node The child node inserted
20970 * @param {Node} refNode The child node the node was inserted before
20974 * @event beforeappend
20975 * Fires before a new child is appended, return false to cancel the append.
20976 * @param {Tree} tree The owner tree
20977 * @param {Node} this This node
20978 * @param {Node} node The child node to be appended
20980 "beforeappend" : true,
20982 * @event beforeremove
20983 * Fires before a child is removed, return false to cancel the remove.
20984 * @param {Tree} tree The owner tree
20985 * @param {Node} this This node
20986 * @param {Node} node The child node to be removed
20988 "beforeremove" : true,
20990 * @event beforemove
20991 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
20992 * @param {Tree} tree The owner tree
20993 * @param {Node} this This node
20994 * @param {Node} oldParent The parent of this node
20995 * @param {Node} newParent The new parent this node is moving to
20996 * @param {Number} index The index it is being moved to
20998 "beforemove" : true,
21000 * @event beforeinsert
21001 * Fires before a new child is inserted, return false to cancel the insert.
21002 * @param {Tree} tree The owner tree
21003 * @param {Node} this This node
21004 * @param {Node} node The child node to be inserted
21005 * @param {Node} refNode The child node the node is being inserted before
21007 "beforeinsert" : true
21009 this.listeners = this.attributes.listeners;
21010 Roo.data.Node.superclass.constructor.call(this);
21013 Roo.extend(Roo.data.Node, Roo.util.Observable, {
21014 fireEvent : function(evtName){
21015 // first do standard event for this node
21016 if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
21019 // then bubble it up to the tree if the event wasn't cancelled
21020 var ot = this.getOwnerTree();
21022 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
21030 * Returns true if this node is a leaf
21031 * @return {Boolean}
21033 isLeaf : function(){
21034 return this.leaf === true;
21038 setFirstChild : function(node){
21039 this.firstChild = node;
21043 setLastChild : function(node){
21044 this.lastChild = node;
21049 * Returns true if this node is the last child of its parent
21050 * @return {Boolean}
21052 isLast : function(){
21053 return (!this.parentNode ? true : this.parentNode.lastChild == this);
21057 * Returns true if this node is the first child of its parent
21058 * @return {Boolean}
21060 isFirst : function(){
21061 return (!this.parentNode ? true : this.parentNode.firstChild == this);
21064 hasChildNodes : function(){
21065 return !this.isLeaf() && this.childNodes.length > 0;
21069 * Insert node(s) as the last child node of this node.
21070 * @param {Node/Array} node The node or Array of nodes to append
21071 * @return {Node} The appended node if single append, or null if an array was passed
21073 appendChild : function(node){
21075 if(node instanceof Array){
21077 }else if(arguments.length > 1){
21080 // if passed an array or multiple args do them one by one
21082 for(var i = 0, len = multi.length; i < len; i++) {
21083 this.appendChild(multi[i]);
21086 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
21089 var index = this.childNodes.length;
21090 var oldParent = node.parentNode;
21091 // it's a move, make sure we move it cleanly
21093 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
21096 oldParent.removeChild(node);
21098 index = this.childNodes.length;
21100 this.setFirstChild(node);
21102 this.childNodes.push(node);
21103 node.parentNode = this;
21104 var ps = this.childNodes[index-1];
21106 node.previousSibling = ps;
21107 ps.nextSibling = node;
21109 node.previousSibling = null;
21111 node.nextSibling = null;
21112 this.setLastChild(node);
21113 node.setOwnerTree(this.getOwnerTree());
21114 this.fireEvent("append", this.ownerTree, this, node, index);
21116 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
21123 * Removes a child node from this node.
21124 * @param {Node} node The node to remove
21125 * @return {Node} The removed node
21127 removeChild : function(node){
21128 var index = this.childNodes.indexOf(node);
21132 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
21136 // remove it from childNodes collection
21137 this.childNodes.splice(index, 1);
21140 if(node.previousSibling){
21141 node.previousSibling.nextSibling = node.nextSibling;
21143 if(node.nextSibling){
21144 node.nextSibling.previousSibling = node.previousSibling;
21147 // update child refs
21148 if(this.firstChild == node){
21149 this.setFirstChild(node.nextSibling);
21151 if(this.lastChild == node){
21152 this.setLastChild(node.previousSibling);
21155 node.setOwnerTree(null);
21156 // clear any references from the node
21157 node.parentNode = null;
21158 node.previousSibling = null;
21159 node.nextSibling = null;
21160 this.fireEvent("remove", this.ownerTree, this, node);
21165 * Inserts the first node before the second node in this nodes childNodes collection.
21166 * @param {Node} node The node to insert
21167 * @param {Node} refNode The node to insert before (if null the node is appended)
21168 * @return {Node} The inserted node
21170 insertBefore : function(node, refNode){
21171 if(!refNode){ // like standard Dom, refNode can be null for append
21172 return this.appendChild(node);
21175 if(node == refNode){
21179 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
21182 var index = this.childNodes.indexOf(refNode);
21183 var oldParent = node.parentNode;
21184 var refIndex = index;
21186 // when moving internally, indexes will change after remove
21187 if(oldParent == this && this.childNodes.indexOf(node) < index){
21191 // it's a move, make sure we move it cleanly
21193 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
21196 oldParent.removeChild(node);
21199 this.setFirstChild(node);
21201 this.childNodes.splice(refIndex, 0, node);
21202 node.parentNode = this;
21203 var ps = this.childNodes[refIndex-1];
21205 node.previousSibling = ps;
21206 ps.nextSibling = node;
21208 node.previousSibling = null;
21210 node.nextSibling = refNode;
21211 refNode.previousSibling = node;
21212 node.setOwnerTree(this.getOwnerTree());
21213 this.fireEvent("insert", this.ownerTree, this, node, refNode);
21215 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
21221 * Returns the child node at the specified index.
21222 * @param {Number} index
21225 item : function(index){
21226 return this.childNodes[index];
21230 * Replaces one child node in this node with another.
21231 * @param {Node} newChild The replacement node
21232 * @param {Node} oldChild The node to replace
21233 * @return {Node} The replaced node
21235 replaceChild : function(newChild, oldChild){
21236 this.insertBefore(newChild, oldChild);
21237 this.removeChild(oldChild);
21242 * Returns the index of a child node
21243 * @param {Node} node
21244 * @return {Number} The index of the node or -1 if it was not found
21246 indexOf : function(child){
21247 return this.childNodes.indexOf(child);
21251 * Returns the tree this node is in.
21254 getOwnerTree : function(){
21255 // if it doesn't have one, look for one
21256 if(!this.ownerTree){
21260 this.ownerTree = p.ownerTree;
21266 return this.ownerTree;
21270 * Returns depth of this node (the root node has a depth of 0)
21273 getDepth : function(){
21276 while(p.parentNode){
21284 setOwnerTree : function(tree){
21285 // if it's move, we need to update everyone
21286 if(tree != this.ownerTree){
21287 if(this.ownerTree){
21288 this.ownerTree.unregisterNode(this);
21290 this.ownerTree = tree;
21291 var cs = this.childNodes;
21292 for(var i = 0, len = cs.length; i < len; i++) {
21293 cs[i].setOwnerTree(tree);
21296 tree.registerNode(this);
21302 * Returns the path for this node. The path can be used to expand or select this node programmatically.
21303 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
21304 * @return {String} The path
21306 getPath : function(attr){
21307 attr = attr || "id";
21308 var p = this.parentNode;
21309 var b = [this.attributes[attr]];
21311 b.unshift(p.attributes[attr]);
21314 var sep = this.getOwnerTree().pathSeparator;
21315 return sep + b.join(sep);
21319 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
21320 * function call will be the scope provided or the current node. The arguments to the function
21321 * will be the args provided or the current node. If the function returns false at any point,
21322 * the bubble is stopped.
21323 * @param {Function} fn The function to call
21324 * @param {Object} scope (optional) The scope of the function (defaults to current node)
21325 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
21327 bubble : function(fn, scope, args){
21330 if(fn.call(scope || p, args || p) === false){
21338 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
21339 * function call will be the scope provided or the current node. The arguments to the function
21340 * will be the args provided or the current node. If the function returns false at any point,
21341 * the cascade is stopped on that branch.
21342 * @param {Function} fn The function to call
21343 * @param {Object} scope (optional) The scope of the function (defaults to current node)
21344 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
21346 cascade : function(fn, scope, args){
21347 if(fn.call(scope || this, args || this) !== false){
21348 var cs = this.childNodes;
21349 for(var i = 0, len = cs.length; i < len; i++) {
21350 cs[i].cascade(fn, scope, args);
21356 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
21357 * function call will be the scope provided or the current node. The arguments to the function
21358 * will be the args provided or the current node. If the function returns false at any point,
21359 * the iteration stops.
21360 * @param {Function} fn The function to call
21361 * @param {Object} scope (optional) The scope of the function (defaults to current node)
21362 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
21364 eachChild : function(fn, scope, args){
21365 var cs = this.childNodes;
21366 for(var i = 0, len = cs.length; i < len; i++) {
21367 if(fn.call(scope || this, args || cs[i]) === false){
21374 * Finds the first child that has the attribute with the specified value.
21375 * @param {String} attribute The attribute name
21376 * @param {Mixed} value The value to search for
21377 * @return {Node} The found child or null if none was found
21379 findChild : function(attribute, value){
21380 var cs = this.childNodes;
21381 for(var i = 0, len = cs.length; i < len; i++) {
21382 if(cs[i].attributes[attribute] == value){
21390 * Finds the first child by a custom function. The child matches if the function passed
21392 * @param {Function} fn
21393 * @param {Object} scope (optional)
21394 * @return {Node} The found child or null if none was found
21396 findChildBy : function(fn, scope){
21397 var cs = this.childNodes;
21398 for(var i = 0, len = cs.length; i < len; i++) {
21399 if(fn.call(scope||cs[i], cs[i]) === true){
21407 * Sorts this nodes children using the supplied sort function
21408 * @param {Function} fn
21409 * @param {Object} scope (optional)
21411 sort : function(fn, scope){
21412 var cs = this.childNodes;
21413 var len = cs.length;
21415 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
21417 for(var i = 0; i < len; i++){
21419 n.previousSibling = cs[i-1];
21420 n.nextSibling = cs[i+1];
21422 this.setFirstChild(n);
21425 this.setLastChild(n);
21432 * Returns true if this node is an ancestor (at any point) of the passed node.
21433 * @param {Node} node
21434 * @return {Boolean}
21436 contains : function(node){
21437 return node.isAncestor(this);
21441 * Returns true if the passed node is an ancestor (at any point) of this node.
21442 * @param {Node} node
21443 * @return {Boolean}
21445 isAncestor : function(node){
21446 var p = this.parentNode;
21456 toString : function(){
21457 return "[Node"+(this.id?" "+this.id:"")+"]";
21461 * Ext JS Library 1.1.1
21462 * Copyright(c) 2006-2007, Ext JS, LLC.
21464 * Originally Released Under LGPL - original licence link has changed is not relivant.
21467 * <script type="text/javascript">
21472 * @class Roo.ComponentMgr
21473 * Provides a common registry of all components on a page so that they can be easily accessed by component id (see {@link Roo.getCmp}).
21476 Roo.ComponentMgr = function(){
21477 var all = new Roo.util.MixedCollection();
21481 * Registers a component.
21482 * @param {Roo.Component} c The component
21484 register : function(c){
21489 * Unregisters a component.
21490 * @param {Roo.Component} c The component
21492 unregister : function(c){
21497 * Returns a component by id
21498 * @param {String} id The component id
21500 get : function(id){
21501 return all.get(id);
21505 * Registers a function that will be called when a specified component is added to ComponentMgr
21506 * @param {String} id The component id
21507 * @param {Funtction} fn The callback function
21508 * @param {Object} scope The scope of the callback
21510 onAvailable : function(id, fn, scope){
21511 all.on("add", function(index, o){
21513 fn.call(scope || o, o);
21514 all.un("add", fn, scope);
21521 * Ext JS Library 1.1.1
21522 * Copyright(c) 2006-2007, Ext JS, LLC.
21524 * Originally Released Under LGPL - original licence link has changed is not relivant.
21527 * <script type="text/javascript">
21531 * @class Roo.Component
21532 * @extends Roo.util.Observable
21533 * Base class for all major Roo components. All subclasses of Component can automatically participate in the standard
21534 * Roo component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show
21535 * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Roo.Container} and
21536 * to be automatically registered with the {@link Roo.ComponentMgr} so that it can be referenced at any time via {@link Roo.getCmp}.
21537 * All visual components (widgets) that require rendering into a layout should subclass Component.
21539 * @param {Roo.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
21540 * 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
21541 * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
21543 Roo.Component = function(config){
21544 config = config || {};
21545 if(config.tagName || config.dom || typeof config == "string"){ // element object
21546 config = {el: config, id: config.id || config};
21548 this.initialConfig = config;
21550 Roo.apply(this, config);
21554 * Fires after the component is disabled.
21555 * @param {Roo.Component} this
21560 * Fires after the component is enabled.
21561 * @param {Roo.Component} this
21565 * @event beforeshow
21566 * Fires before the component is shown. Return false to stop the show.
21567 * @param {Roo.Component} this
21572 * Fires after the component is shown.
21573 * @param {Roo.Component} this
21577 * @event beforehide
21578 * Fires before the component is hidden. Return false to stop the hide.
21579 * @param {Roo.Component} this
21584 * Fires after the component is hidden.
21585 * @param {Roo.Component} this
21589 * @event beforerender
21590 * Fires before the component is rendered. Return false to stop the render.
21591 * @param {Roo.Component} this
21593 beforerender : true,
21596 * Fires after the component is rendered.
21597 * @param {Roo.Component} this
21601 * @event beforedestroy
21602 * Fires before the component is destroyed. Return false to stop the destroy.
21603 * @param {Roo.Component} this
21605 beforedestroy : true,
21608 * Fires after the component is destroyed.
21609 * @param {Roo.Component} this
21614 this.id = "ext-comp-" + (++Roo.Component.AUTO_ID);
21616 Roo.ComponentMgr.register(this);
21617 Roo.Component.superclass.constructor.call(this);
21618 this.initComponent();
21619 if(this.renderTo){ // not supported by all components yet. use at your own risk!
21620 this.render(this.renderTo);
21621 delete this.renderTo;
21626 Roo.Component.AUTO_ID = 1000;
21628 Roo.extend(Roo.Component, Roo.util.Observable, {
21630 * @property {Boolean} hidden
21631 * true if this component is hidden. Read-only.
21635 * true if this component is disabled. Read-only.
21639 * true if this component has been rendered. Read-only.
21643 /** @cfg {String} disableClass
21644 * CSS class added to the component when it is disabled (defaults to "x-item-disabled").
21646 disabledClass : "x-item-disabled",
21647 /** @cfg {Boolean} allowDomMove
21648 * Whether the component can move the Dom node when rendering (defaults to true).
21650 allowDomMove : true,
21651 /** @cfg {String} hideMode
21652 * How this component should hidden. Supported values are
21653 * "visibility" (css visibility), "offsets" (negative offset position) and
21654 * "display" (css display) - defaults to "display".
21656 hideMode: 'display',
21659 ctype : "Roo.Component",
21661 /** @cfg {String} actionMode
21662 * which property holds the element that used for hide() / show() / disable() / enable()
21668 getActionEl : function(){
21669 return this[this.actionMode];
21672 initComponent : Roo.emptyFn,
21674 * If this is a lazy rendering component, render it to its container element.
21675 * @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.
21677 render : function(container, position){
21678 if(!this.rendered && this.fireEvent("beforerender", this) !== false){
21679 if(!container && this.el){
21680 this.el = Roo.get(this.el);
21681 container = this.el.dom.parentNode;
21682 this.allowDomMove = false;
21684 this.container = Roo.get(container);
21685 this.rendered = true;
21686 if(position !== undefined){
21687 if(typeof position == 'number'){
21688 position = this.container.dom.childNodes[position];
21690 position = Roo.getDom(position);
21693 this.onRender(this.container, position || null);
21695 this.el.addClass(this.cls);
21699 this.el.applyStyles(this.style);
21702 this.fireEvent("render", this);
21703 this.afterRender(this.container);
21715 // default function is not really useful
21716 onRender : function(ct, position){
21718 this.el = Roo.get(this.el);
21719 if(this.allowDomMove !== false){
21720 ct.dom.insertBefore(this.el.dom, position);
21726 getAutoCreate : function(){
21727 var cfg = typeof this.autoCreate == "object" ?
21728 this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
21729 if(this.id && !cfg.id){
21736 afterRender : Roo.emptyFn,
21739 * Destroys this component by purging any event listeners, removing the component's element from the DOM,
21740 * removing the component from its {@link Roo.Container} (if applicable) and unregistering it from {@link Roo.ComponentMgr}.
21742 destroy : function(){
21743 if(this.fireEvent("beforedestroy", this) !== false){
21744 this.purgeListeners();
21745 this.beforeDestroy();
21747 this.el.removeAllListeners();
21749 if(this.actionMode == "container"){
21750 this.container.remove();
21754 Roo.ComponentMgr.unregister(this);
21755 this.fireEvent("destroy", this);
21760 beforeDestroy : function(){
21765 onDestroy : function(){
21770 * Returns the underlying {@link Roo.Element}.
21771 * @return {Roo.Element} The element
21773 getEl : function(){
21778 * Returns the id of this component.
21781 getId : function(){
21786 * Try to focus this component.
21787 * @param {Boolean} selectText True to also select the text in this component (if applicable)
21788 * @return {Roo.Component} this
21790 focus : function(selectText){
21793 if(selectText === true){
21794 this.el.dom.select();
21809 * Disable this component.
21810 * @return {Roo.Component} this
21812 disable : function(){
21816 this.disabled = true;
21817 this.fireEvent("disable", this);
21822 onDisable : function(){
21823 this.getActionEl().addClass(this.disabledClass);
21824 this.el.dom.disabled = true;
21828 * Enable this component.
21829 * @return {Roo.Component} this
21831 enable : function(){
21835 this.disabled = false;
21836 this.fireEvent("enable", this);
21841 onEnable : function(){
21842 this.getActionEl().removeClass(this.disabledClass);
21843 this.el.dom.disabled = false;
21847 * Convenience function for setting disabled/enabled by boolean.
21848 * @param {Boolean} disabled
21850 setDisabled : function(disabled){
21851 this[disabled ? "disable" : "enable"]();
21855 * Show this component.
21856 * @return {Roo.Component} this
21859 if(this.fireEvent("beforeshow", this) !== false){
21860 this.hidden = false;
21864 this.fireEvent("show", this);
21870 onShow : function(){
21871 var ae = this.getActionEl();
21872 if(this.hideMode == 'visibility'){
21873 ae.dom.style.visibility = "visible";
21874 }else if(this.hideMode == 'offsets'){
21875 ae.removeClass('x-hidden');
21877 ae.dom.style.display = "";
21882 * Hide this component.
21883 * @return {Roo.Component} this
21886 if(this.fireEvent("beforehide", this) !== false){
21887 this.hidden = true;
21891 this.fireEvent("hide", this);
21897 onHide : function(){
21898 var ae = this.getActionEl();
21899 if(this.hideMode == 'visibility'){
21900 ae.dom.style.visibility = "hidden";
21901 }else if(this.hideMode == 'offsets'){
21902 ae.addClass('x-hidden');
21904 ae.dom.style.display = "none";
21909 * Convenience function to hide or show this component by boolean.
21910 * @param {Boolean} visible True to show, false to hide
21911 * @return {Roo.Component} this
21913 setVisible: function(visible){
21923 * Returns true if this component is visible.
21925 isVisible : function(){
21926 return this.getActionEl().isVisible();
21929 cloneConfig : function(overrides){
21930 overrides = overrides || {};
21931 var id = overrides.id || Roo.id();
21932 var cfg = Roo.applyIf(overrides, this.initialConfig);
21933 cfg.id = id; // prevent dup id
21934 return new this.constructor(cfg);
21938 * Ext JS Library 1.1.1
21939 * Copyright(c) 2006-2007, Ext JS, LLC.
21941 * Originally Released Under LGPL - original licence link has changed is not relivant.
21944 * <script type="text/javascript">
21949 * @extends Roo.Element
21950 * An extended {@link Roo.Element} object that supports a shadow and shim, constrain to viewport and
21951 * automatic maintaining of shadow/shim positions.
21952 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
21953 * @cfg {String/Boolean} shadow True to create a shadow element with default class "x-layer-shadow", or
21954 * you can pass a string with a CSS class name. False turns off the shadow.
21955 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: "div", cls: "x-layer"}).
21956 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
21957 * @cfg {String} cls CSS class to add to the element
21958 * @cfg {Number} zindex Starting z-index (defaults to 11000)
21959 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 3)
21961 * @param {Object} config An object with config options.
21962 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
21965 Roo.Layer = function(config, existingEl){
21966 config = config || {};
21967 var dh = Roo.DomHelper;
21968 var cp = config.parentEl, pel = cp ? Roo.getDom(cp) : document.body;
21970 this.dom = Roo.getDom(existingEl);
21973 var o = config.dh || {tag: "div", cls: "x-layer"};
21974 this.dom = dh.append(pel, o);
21977 this.addClass(config.cls);
21979 this.constrain = config.constrain !== false;
21980 this.visibilityMode = Roo.Element.VISIBILITY;
21982 this.id = this.dom.id = config.id;
21984 this.id = Roo.id(this.dom);
21986 this.zindex = config.zindex || this.getZIndex();
21987 this.position("absolute", this.zindex);
21989 this.shadowOffset = config.shadowOffset || 4;
21990 this.shadow = new Roo.Shadow({
21991 offset : this.shadowOffset,
21992 mode : config.shadow
21995 this.shadowOffset = 0;
21997 this.useShim = config.shim !== false && Roo.useShims;
21998 this.useDisplay = config.useDisplay;
22002 var supr = Roo.Element.prototype;
22004 // shims are shared among layer to keep from having 100 iframes
22007 Roo.extend(Roo.Layer, Roo.Element, {
22009 getZIndex : function(){
22010 return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
22013 getShim : function(){
22020 var shim = shims.shift();
22022 shim = this.createShim();
22023 shim.enableDisplayMode('block');
22024 shim.dom.style.display = 'none';
22025 shim.dom.style.visibility = 'visible';
22027 var pn = this.dom.parentNode;
22028 if(shim.dom.parentNode != pn){
22029 pn.insertBefore(shim.dom, this.dom);
22031 shim.setStyle('z-index', this.getZIndex()-2);
22036 hideShim : function(){
22038 this.shim.setDisplayed(false);
22039 shims.push(this.shim);
22044 disableShadow : function(){
22046 this.shadowDisabled = true;
22047 this.shadow.hide();
22048 this.lastShadowOffset = this.shadowOffset;
22049 this.shadowOffset = 0;
22053 enableShadow : function(show){
22055 this.shadowDisabled = false;
22056 this.shadowOffset = this.lastShadowOffset;
22057 delete this.lastShadowOffset;
22065 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
22066 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
22067 sync : function(doShow){
22068 var sw = this.shadow;
22069 if(!this.updating && this.isVisible() && (sw || this.useShim)){
22070 var sh = this.getShim();
22072 var w = this.getWidth(),
22073 h = this.getHeight();
22075 var l = this.getLeft(true),
22076 t = this.getTop(true);
22078 if(sw && !this.shadowDisabled){
22079 if(doShow && !sw.isVisible()){
22082 sw.realign(l, t, w, h);
22088 // fit the shim behind the shadow, so it is shimmed too
22089 var a = sw.adjusts, s = sh.dom.style;
22090 s.left = (Math.min(l, l+a.l))+"px";
22091 s.top = (Math.min(t, t+a.t))+"px";
22092 s.width = (w+a.w)+"px";
22093 s.height = (h+a.h)+"px";
22100 sh.setLeftTop(l, t);
22107 destroy : function(){
22110 this.shadow.hide();
22112 this.removeAllListeners();
22113 var pn = this.dom.parentNode;
22115 pn.removeChild(this.dom);
22117 Roo.Element.uncache(this.id);
22120 remove : function(){
22125 beginUpdate : function(){
22126 this.updating = true;
22130 endUpdate : function(){
22131 this.updating = false;
22136 hideUnders : function(negOffset){
22138 this.shadow.hide();
22144 constrainXY : function(){
22145 if(this.constrain){
22146 var vw = Roo.lib.Dom.getViewWidth(),
22147 vh = Roo.lib.Dom.getViewHeight();
22148 var s = Roo.get(document).getScroll();
22150 var xy = this.getXY();
22151 var x = xy[0], y = xy[1];
22152 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
22153 // only move it if it needs it
22155 // first validate right/bottom
22156 if((x + w) > vw+s.left){
22157 x = vw - w - this.shadowOffset;
22160 if((y + h) > vh+s.top){
22161 y = vh - h - this.shadowOffset;
22164 // then make sure top/left isn't negative
22175 var ay = this.avoidY;
22176 if(y <= ay && (y+h) >= ay){
22182 supr.setXY.call(this, xy);
22188 isVisible : function(){
22189 return this.visible;
22193 showAction : function(){
22194 this.visible = true; // track visibility to prevent getStyle calls
22195 if(this.useDisplay === true){
22196 this.setDisplayed("");
22197 }else if(this.lastXY){
22198 supr.setXY.call(this, this.lastXY);
22199 }else if(this.lastLT){
22200 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
22205 hideAction : function(){
22206 this.visible = false;
22207 if(this.useDisplay === true){
22208 this.setDisplayed(false);
22210 this.setLeftTop(-10000,-10000);
22214 // overridden Element method
22215 setVisible : function(v, a, d, c, e){
22220 var cb = function(){
22225 }.createDelegate(this);
22226 supr.setVisible.call(this, true, true, d, cb, e);
22229 this.hideUnders(true);
22238 }.createDelegate(this);
22240 supr.setVisible.call(this, v, a, d, cb, e);
22249 storeXY : function(xy){
22250 delete this.lastLT;
22254 storeLeftTop : function(left, top){
22255 delete this.lastXY;
22256 this.lastLT = [left, top];
22260 beforeFx : function(){
22261 this.beforeAction();
22262 return Roo.Layer.superclass.beforeFx.apply(this, arguments);
22266 afterFx : function(){
22267 Roo.Layer.superclass.afterFx.apply(this, arguments);
22268 this.sync(this.isVisible());
22272 beforeAction : function(){
22273 if(!this.updating && this.shadow){
22274 this.shadow.hide();
22278 // overridden Element method
22279 setLeft : function(left){
22280 this.storeLeftTop(left, this.getTop(true));
22281 supr.setLeft.apply(this, arguments);
22285 setTop : function(top){
22286 this.storeLeftTop(this.getLeft(true), top);
22287 supr.setTop.apply(this, arguments);
22291 setLeftTop : function(left, top){
22292 this.storeLeftTop(left, top);
22293 supr.setLeftTop.apply(this, arguments);
22297 setXY : function(xy, a, d, c, e){
22299 this.beforeAction();
22301 var cb = this.createCB(c);
22302 supr.setXY.call(this, xy, a, d, cb, e);
22309 createCB : function(c){
22320 // overridden Element method
22321 setX : function(x, a, d, c, e){
22322 this.setXY([x, this.getY()], a, d, c, e);
22325 // overridden Element method
22326 setY : function(y, a, d, c, e){
22327 this.setXY([this.getX(), y], a, d, c, e);
22330 // overridden Element method
22331 setSize : function(w, h, a, d, c, e){
22332 this.beforeAction();
22333 var cb = this.createCB(c);
22334 supr.setSize.call(this, w, h, a, d, cb, e);
22340 // overridden Element method
22341 setWidth : function(w, a, d, c, e){
22342 this.beforeAction();
22343 var cb = this.createCB(c);
22344 supr.setWidth.call(this, w, a, d, cb, e);
22350 // overridden Element method
22351 setHeight : function(h, a, d, c, e){
22352 this.beforeAction();
22353 var cb = this.createCB(c);
22354 supr.setHeight.call(this, h, a, d, cb, e);
22360 // overridden Element method
22361 setBounds : function(x, y, w, h, a, d, c, e){
22362 this.beforeAction();
22363 var cb = this.createCB(c);
22365 this.storeXY([x, y]);
22366 supr.setXY.call(this, [x, y]);
22367 supr.setSize.call(this, w, h, a, d, cb, e);
22370 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
22376 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
22377 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
22378 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
22379 * @param {Number} zindex The new z-index to set
22380 * @return {this} The Layer
22382 setZIndex : function(zindex){
22383 this.zindex = zindex;
22384 this.setStyle("z-index", zindex + 2);
22386 this.shadow.setZIndex(zindex + 1);
22389 this.shim.setStyle("z-index", zindex);
22395 * Ext JS Library 1.1.1
22396 * Copyright(c) 2006-2007, Ext JS, LLC.
22398 * Originally Released Under LGPL - original licence link has changed is not relivant.
22401 * <script type="text/javascript">
22406 * @class Roo.Shadow
22407 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
22408 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
22409 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
22411 * Create a new Shadow
22412 * @param {Object} config The config object
22414 Roo.Shadow = function(config){
22415 Roo.apply(this, config);
22416 if(typeof this.mode != "string"){
22417 this.mode = this.defaultMode;
22419 var o = this.offset, a = {h: 0};
22420 var rad = Math.floor(this.offset/2);
22421 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
22427 a.l -= this.offset + rad;
22428 a.t -= this.offset + rad;
22439 a.l -= (this.offset - rad);
22440 a.t -= this.offset + rad;
22442 a.w -= (this.offset - rad)*2;
22453 a.l -= (this.offset - rad);
22454 a.t -= (this.offset - rad);
22456 a.w -= (this.offset + rad + 1);
22457 a.h -= (this.offset + rad);
22466 Roo.Shadow.prototype = {
22468 * @cfg {String} mode
22469 * The shadow display mode. Supports the following options:<br />
22470 * sides: Shadow displays on both sides and bottom only<br />
22471 * frame: Shadow displays equally on all four sides<br />
22472 * drop: Traditional bottom-right drop shadow (default)
22475 * @cfg {String} offset
22476 * The number of pixels to offset the shadow from the element (defaults to 4)
22481 defaultMode: "drop",
22484 * Displays the shadow under the target element
22485 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
22487 show : function(target){
22488 target = Roo.get(target);
22490 this.el = Roo.Shadow.Pool.pull();
22491 if(this.el.dom.nextSibling != target.dom){
22492 this.el.insertBefore(target);
22495 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
22497 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
22500 target.getLeft(true),
22501 target.getTop(true),
22505 this.el.dom.style.display = "block";
22509 * Returns true if the shadow is visible, else false
22511 isVisible : function(){
22512 return this.el ? true : false;
22516 * Direct alignment when values are already available. Show must be called at least once before
22517 * calling this method to ensure it is initialized.
22518 * @param {Number} left The target element left position
22519 * @param {Number} top The target element top position
22520 * @param {Number} width The target element width
22521 * @param {Number} height The target element height
22523 realign : function(l, t, w, h){
22527 var a = this.adjusts, d = this.el.dom, s = d.style;
22529 s.left = (l+a.l)+"px";
22530 s.top = (t+a.t)+"px";
22531 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
22532 if(s.width != sws || s.height != shs){
22536 var cn = d.childNodes;
22537 var sww = Math.max(0, (sw-12))+"px";
22538 cn[0].childNodes[1].style.width = sww;
22539 cn[1].childNodes[1].style.width = sww;
22540 cn[2].childNodes[1].style.width = sww;
22541 cn[1].style.height = Math.max(0, (sh-12))+"px";
22547 * Hides this shadow
22551 this.el.dom.style.display = "none";
22552 Roo.Shadow.Pool.push(this.el);
22558 * Adjust the z-index of this shadow
22559 * @param {Number} zindex The new z-index
22561 setZIndex : function(z){
22564 this.el.setStyle("z-index", z);
22569 // Private utility class that manages the internal Shadow cache
22570 Roo.Shadow.Pool = function(){
22572 var markup = Roo.isIE ?
22573 '<div class="x-ie-shadow"></div>' :
22574 '<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>';
22577 var sh = p.shift();
22579 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
22580 sh.autoBoxAdjust = false;
22585 push : function(sh){
22591 * Ext JS Library 1.1.1
22592 * Copyright(c) 2006-2007, Ext JS, LLC.
22594 * Originally Released Under LGPL - original licence link has changed is not relivant.
22597 * <script type="text/javascript">
22601 * @class Roo.BoxComponent
22602 * @extends Roo.Component
22603 * Base class for any visual {@link Roo.Component} that uses a box container. BoxComponent provides automatic box
22604 * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model. All
22605 * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext
22606 * layout containers.
22608 * @param {Roo.Element/String/Object} config The configuration options.
22610 Roo.BoxComponent = function(config){
22611 Roo.Component.call(this, config);
22615 * Fires after the component is resized.
22616 * @param {Roo.Component} this
22617 * @param {Number} adjWidth The box-adjusted width that was set
22618 * @param {Number} adjHeight The box-adjusted height that was set
22619 * @param {Number} rawWidth The width that was originally specified
22620 * @param {Number} rawHeight The height that was originally specified
22625 * Fires after the component is moved.
22626 * @param {Roo.Component} this
22627 * @param {Number} x The new x position
22628 * @param {Number} y The new y position
22634 Roo.extend(Roo.BoxComponent, Roo.Component, {
22635 // private, set in afterRender to signify that the component has been rendered
22637 // private, used to defer height settings to subclasses
22638 deferHeight: false,
22639 /** @cfg {Number} width
22640 * width (optional) size of component
22642 /** @cfg {Number} height
22643 * height (optional) size of component
22647 * Sets the width and height of the component. This method fires the resize event. This method can accept
22648 * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.
22649 * @param {Number/Object} width The new width to set, or a size object in the format {width, height}
22650 * @param {Number} height The new height to set (not required if a size object is passed as the first arg)
22651 * @return {Roo.BoxComponent} this
22653 setSize : function(w, h){
22654 // support for standard size objects
22655 if(typeof w == 'object'){
22660 if(!this.boxReady){
22666 // prevent recalcs when not needed
22667 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
22670 this.lastSize = {width: w, height: h};
22672 var adj = this.adjustSize(w, h);
22673 var aw = adj.width, ah = adj.height;
22674 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
22675 var rz = this.getResizeEl();
22676 if(!this.deferHeight && aw !== undefined && ah !== undefined){
22677 rz.setSize(aw, ah);
22678 }else if(!this.deferHeight && ah !== undefined){
22680 }else if(aw !== undefined){
22683 this.onResize(aw, ah, w, h);
22684 this.fireEvent('resize', this, aw, ah, w, h);
22690 * Gets the current size of the component's underlying element.
22691 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
22693 getSize : function(){
22694 return this.el.getSize();
22698 * Gets the current XY position of the component's underlying element.
22699 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
22700 * @return {Array} The XY position of the element (e.g., [100, 200])
22702 getPosition : function(local){
22703 if(local === true){
22704 return [this.el.getLeft(true), this.el.getTop(true)];
22706 return this.xy || this.el.getXY();
22710 * Gets the current box measurements of the component's underlying element.
22711 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
22712 * @returns {Object} box An object in the format {x, y, width, height}
22714 getBox : function(local){
22715 var s = this.el.getSize();
22717 s.x = this.el.getLeft(true);
22718 s.y = this.el.getTop(true);
22720 var xy = this.xy || this.el.getXY();
22728 * Sets the current box measurements of the component's underlying element.
22729 * @param {Object} box An object in the format {x, y, width, height}
22730 * @returns {Roo.BoxComponent} this
22732 updateBox : function(box){
22733 this.setSize(box.width, box.height);
22734 this.setPagePosition(box.x, box.y);
22739 getResizeEl : function(){
22740 return this.resizeEl || this.el;
22744 getPositionEl : function(){
22745 return this.positionEl || this.el;
22749 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
22750 * This method fires the move event.
22751 * @param {Number} left The new left
22752 * @param {Number} top The new top
22753 * @returns {Roo.BoxComponent} this
22755 setPosition : function(x, y){
22758 if(!this.boxReady){
22761 var adj = this.adjustPosition(x, y);
22762 var ax = adj.x, ay = adj.y;
22764 var el = this.getPositionEl();
22765 if(ax !== undefined || ay !== undefined){
22766 if(ax !== undefined && ay !== undefined){
22767 el.setLeftTop(ax, ay);
22768 }else if(ax !== undefined){
22770 }else if(ay !== undefined){
22773 this.onPosition(ax, ay);
22774 this.fireEvent('move', this, ax, ay);
22780 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
22781 * This method fires the move event.
22782 * @param {Number} x The new x position
22783 * @param {Number} y The new y position
22784 * @returns {Roo.BoxComponent} this
22786 setPagePosition : function(x, y){
22789 if(!this.boxReady){
22792 if(x === undefined || y === undefined){ // cannot translate undefined points
22795 var p = this.el.translatePoints(x, y);
22796 this.setPosition(p.left, p.top);
22801 onRender : function(ct, position){
22802 Roo.BoxComponent.superclass.onRender.call(this, ct, position);
22804 this.resizeEl = Roo.get(this.resizeEl);
22806 if(this.positionEl){
22807 this.positionEl = Roo.get(this.positionEl);
22812 afterRender : function(){
22813 Roo.BoxComponent.superclass.afterRender.call(this);
22814 this.boxReady = true;
22815 this.setSize(this.width, this.height);
22816 if(this.x || this.y){
22817 this.setPosition(this.x, this.y);
22819 if(this.pageX || this.pageY){
22820 this.setPagePosition(this.pageX, this.pageY);
22825 * Force the component's size to recalculate based on the underlying element's current height and width.
22826 * @returns {Roo.BoxComponent} this
22828 syncSize : function(){
22829 delete this.lastSize;
22830 this.setSize(this.el.getWidth(), this.el.getHeight());
22835 * Called after the component is resized, this method is empty by default but can be implemented by any
22836 * subclass that needs to perform custom logic after a resize occurs.
22837 * @param {Number} adjWidth The box-adjusted width that was set
22838 * @param {Number} adjHeight The box-adjusted height that was set
22839 * @param {Number} rawWidth The width that was originally specified
22840 * @param {Number} rawHeight The height that was originally specified
22842 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
22847 * Called after the component is moved, this method is empty by default but can be implemented by any
22848 * subclass that needs to perform custom logic after a move occurs.
22849 * @param {Number} x The new x position
22850 * @param {Number} y The new y position
22852 onPosition : function(x, y){
22857 adjustSize : function(w, h){
22858 if(this.autoWidth){
22861 if(this.autoHeight){
22864 return {width : w, height: h};
22868 adjustPosition : function(x, y){
22869 return {x : x, y: y};
22873 * Ext JS Library 1.1.1
22874 * Copyright(c) 2006-2007, Ext JS, LLC.
22876 * Originally Released Under LGPL - original licence link has changed is not relivant.
22879 * <script type="text/javascript">
22884 * @class Roo.SplitBar
22885 * @extends Roo.util.Observable
22886 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
22890 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
22891 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
22892 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
22893 split.minSize = 100;
22894 split.maxSize = 600;
22895 split.animate = true;
22896 split.on('moved', splitterMoved);
22899 * Create a new SplitBar
22900 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
22901 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
22902 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
22903 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
22904 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
22905 position of the SplitBar).
22907 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
22910 this.el = Roo.get(dragElement, true);
22911 this.el.dom.unselectable = "on";
22913 this.resizingEl = Roo.get(resizingElement, true);
22917 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
22918 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
22921 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
22924 * The minimum size of the resizing element. (Defaults to 0)
22930 * The maximum size of the resizing element. (Defaults to 2000)
22933 this.maxSize = 2000;
22936 * Whether to animate the transition to the new size
22939 this.animate = false;
22942 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
22945 this.useShim = false;
22950 if(!existingProxy){
22952 this.proxy = Roo.SplitBar.createProxy(this.orientation);
22954 this.proxy = Roo.get(existingProxy).dom;
22957 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
22960 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
22963 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
22966 this.dragSpecs = {};
22969 * @private The adapter to use to positon and resize elements
22971 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
22972 this.adapter.init(this);
22974 if(this.orientation == Roo.SplitBar.HORIZONTAL){
22976 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
22977 this.el.addClass("x-splitbar-h");
22980 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
22981 this.el.addClass("x-splitbar-v");
22987 * Fires when the splitter is moved (alias for {@link #event-moved})
22988 * @param {Roo.SplitBar} this
22989 * @param {Number} newSize the new width or height
22994 * Fires when the splitter is moved
22995 * @param {Roo.SplitBar} this
22996 * @param {Number} newSize the new width or height
23000 * @event beforeresize
23001 * Fires before the splitter is dragged
23002 * @param {Roo.SplitBar} this
23004 "beforeresize" : true,
23006 "beforeapply" : true
23009 Roo.util.Observable.call(this);
23012 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
23013 onStartProxyDrag : function(x, y){
23014 this.fireEvent("beforeresize", this);
23016 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
23018 o.enableDisplayMode("block");
23019 // all splitbars share the same overlay
23020 Roo.SplitBar.prototype.overlay = o;
23022 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
23023 this.overlay.show();
23024 Roo.get(this.proxy).setDisplayed("block");
23025 var size = this.adapter.getElementSize(this);
23026 this.activeMinSize = this.getMinimumSize();;
23027 this.activeMaxSize = this.getMaximumSize();;
23028 var c1 = size - this.activeMinSize;
23029 var c2 = Math.max(this.activeMaxSize - size, 0);
23030 if(this.orientation == Roo.SplitBar.HORIZONTAL){
23031 this.dd.resetConstraints();
23032 this.dd.setXConstraint(
23033 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
23034 this.placement == Roo.SplitBar.LEFT ? c2 : c1
23036 this.dd.setYConstraint(0, 0);
23038 this.dd.resetConstraints();
23039 this.dd.setXConstraint(0, 0);
23040 this.dd.setYConstraint(
23041 this.placement == Roo.SplitBar.TOP ? c1 : c2,
23042 this.placement == Roo.SplitBar.TOP ? c2 : c1
23045 this.dragSpecs.startSize = size;
23046 this.dragSpecs.startPoint = [x, y];
23047 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
23051 * @private Called after the drag operation by the DDProxy
23053 onEndProxyDrag : function(e){
23054 Roo.get(this.proxy).setDisplayed(false);
23055 var endPoint = Roo.lib.Event.getXY(e);
23057 this.overlay.hide();
23060 if(this.orientation == Roo.SplitBar.HORIZONTAL){
23061 newSize = this.dragSpecs.startSize +
23062 (this.placement == Roo.SplitBar.LEFT ?
23063 endPoint[0] - this.dragSpecs.startPoint[0] :
23064 this.dragSpecs.startPoint[0] - endPoint[0]
23067 newSize = this.dragSpecs.startSize +
23068 (this.placement == Roo.SplitBar.TOP ?
23069 endPoint[1] - this.dragSpecs.startPoint[1] :
23070 this.dragSpecs.startPoint[1] - endPoint[1]
23073 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
23074 if(newSize != this.dragSpecs.startSize){
23075 if(this.fireEvent('beforeapply', this, newSize) !== false){
23076 this.adapter.setElementSize(this, newSize);
23077 this.fireEvent("moved", this, newSize);
23078 this.fireEvent("resize", this, newSize);
23084 * Get the adapter this SplitBar uses
23085 * @return The adapter object
23087 getAdapter : function(){
23088 return this.adapter;
23092 * Set the adapter this SplitBar uses
23093 * @param {Object} adapter A SplitBar adapter object
23095 setAdapter : function(adapter){
23096 this.adapter = adapter;
23097 this.adapter.init(this);
23101 * Gets the minimum size for the resizing element
23102 * @return {Number} The minimum size
23104 getMinimumSize : function(){
23105 return this.minSize;
23109 * Sets the minimum size for the resizing element
23110 * @param {Number} minSize The minimum size
23112 setMinimumSize : function(minSize){
23113 this.minSize = minSize;
23117 * Gets the maximum size for the resizing element
23118 * @return {Number} The maximum size
23120 getMaximumSize : function(){
23121 return this.maxSize;
23125 * Sets the maximum size for the resizing element
23126 * @param {Number} maxSize The maximum size
23128 setMaximumSize : function(maxSize){
23129 this.maxSize = maxSize;
23133 * Sets the initialize size for the resizing element
23134 * @param {Number} size The initial size
23136 setCurrentSize : function(size){
23137 var oldAnimate = this.animate;
23138 this.animate = false;
23139 this.adapter.setElementSize(this, size);
23140 this.animate = oldAnimate;
23144 * Destroy this splitbar.
23145 * @param {Boolean} removeEl True to remove the element
23147 destroy : function(removeEl){
23149 this.shim.remove();
23152 this.proxy.parentNode.removeChild(this.proxy);
23160 * @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.
23162 Roo.SplitBar.createProxy = function(dir){
23163 var proxy = new Roo.Element(document.createElement("div"));
23164 proxy.unselectable();
23165 var cls = 'x-splitbar-proxy';
23166 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
23167 document.body.appendChild(proxy.dom);
23172 * @class Roo.SplitBar.BasicLayoutAdapter
23173 * Default Adapter. It assumes the splitter and resizing element are not positioned
23174 * elements and only gets/sets the width of the element. Generally used for table based layouts.
23176 Roo.SplitBar.BasicLayoutAdapter = function(){
23179 Roo.SplitBar.BasicLayoutAdapter.prototype = {
23180 // do nothing for now
23181 init : function(s){
23185 * Called before drag operations to get the current size of the resizing element.
23186 * @param {Roo.SplitBar} s The SplitBar using this adapter
23188 getElementSize : function(s){
23189 if(s.orientation == Roo.SplitBar.HORIZONTAL){
23190 return s.resizingEl.getWidth();
23192 return s.resizingEl.getHeight();
23197 * Called after drag operations to set the size of the resizing element.
23198 * @param {Roo.SplitBar} s The SplitBar using this adapter
23199 * @param {Number} newSize The new size to set
23200 * @param {Function} onComplete A function to be invoked when resizing is complete
23202 setElementSize : function(s, newSize, onComplete){
23203 if(s.orientation == Roo.SplitBar.HORIZONTAL){
23205 s.resizingEl.setWidth(newSize);
23207 onComplete(s, newSize);
23210 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
23215 s.resizingEl.setHeight(newSize);
23217 onComplete(s, newSize);
23220 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
23227 *@class Roo.SplitBar.AbsoluteLayoutAdapter
23228 * @extends Roo.SplitBar.BasicLayoutAdapter
23229 * Adapter that moves the splitter element to align with the resized sizing element.
23230 * Used with an absolute positioned SplitBar.
23231 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
23232 * document.body, make sure you assign an id to the body element.
23234 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
23235 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
23236 this.container = Roo.get(container);
23239 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
23240 init : function(s){
23241 this.basic.init(s);
23244 getElementSize : function(s){
23245 return this.basic.getElementSize(s);
23248 setElementSize : function(s, newSize, onComplete){
23249 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
23252 moveSplitter : function(s){
23253 var yes = Roo.SplitBar;
23254 switch(s.placement){
23256 s.el.setX(s.resizingEl.getRight());
23259 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
23262 s.el.setY(s.resizingEl.getBottom());
23265 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
23272 * Orientation constant - Create a vertical SplitBar
23276 Roo.SplitBar.VERTICAL = 1;
23279 * Orientation constant - Create a horizontal SplitBar
23283 Roo.SplitBar.HORIZONTAL = 2;
23286 * Placement constant - The resizing element is to the left of the splitter element
23290 Roo.SplitBar.LEFT = 1;
23293 * Placement constant - The resizing element is to the right of the splitter element
23297 Roo.SplitBar.RIGHT = 2;
23300 * Placement constant - The resizing element is positioned above the splitter element
23304 Roo.SplitBar.TOP = 3;
23307 * Placement constant - The resizing element is positioned under splitter element
23311 Roo.SplitBar.BOTTOM = 4;
23314 * Ext JS Library 1.1.1
23315 * Copyright(c) 2006-2007, Ext JS, LLC.
23317 * Originally Released Under LGPL - original licence link has changed is not relivant.
23320 * <script type="text/javascript">
23325 * @extends Roo.util.Observable
23326 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
23327 * This class also supports single and multi selection modes. <br>
23328 * Create a data model bound view:
23330 var store = new Roo.data.Store(...);
23332 var view = new Roo.View({
23334 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
23336 singleSelect: true,
23337 selectedClass: "ydataview-selected",
23341 // listen for node click?
23342 view.on("click", function(vw, index, node, e){
23343 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
23347 dataModel.load("foobar.xml");
23349 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
23351 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
23352 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
23354 * Note: old style constructor is still suported (container, template, config)
23357 * Create a new View
23358 * @param {Object} config The config object
23361 Roo.View = function(config, depreciated_tpl, depreciated_config){
23363 if (typeof(depreciated_tpl) == 'undefined') {
23364 // new way.. - universal constructor.
23365 Roo.apply(this, config);
23366 this.el = Roo.get(this.el);
23369 this.el = Roo.get(config);
23370 this.tpl = depreciated_tpl;
23371 Roo.apply(this, depreciated_config);
23375 if(typeof(this.tpl) == "string"){
23376 this.tpl = new Roo.Template(this.tpl);
23378 // support xtype ctors..
23379 this.tpl = new Roo.factory(this.tpl, Roo);
23383 this.tpl.compile();
23390 * @event beforeclick
23391 * Fires before a click is processed. Returns false to cancel the default action.
23392 * @param {Roo.View} this
23393 * @param {Number} index The index of the target node
23394 * @param {HTMLElement} node The target node
23395 * @param {Roo.EventObject} e The raw event object
23397 "beforeclick" : true,
23400 * Fires when a template node is clicked.
23401 * @param {Roo.View} this
23402 * @param {Number} index The index of the target node
23403 * @param {HTMLElement} node The target node
23404 * @param {Roo.EventObject} e The raw event object
23409 * Fires when a template node is double clicked.
23410 * @param {Roo.View} this
23411 * @param {Number} index The index of the target node
23412 * @param {HTMLElement} node The target node
23413 * @param {Roo.EventObject} e The raw event object
23417 * @event contextmenu
23418 * Fires when a template node is right clicked.
23419 * @param {Roo.View} this
23420 * @param {Number} index The index of the target node
23421 * @param {HTMLElement} node The target node
23422 * @param {Roo.EventObject} e The raw event object
23424 "contextmenu" : true,
23426 * @event selectionchange
23427 * Fires when the selected nodes change.
23428 * @param {Roo.View} this
23429 * @param {Array} selections Array of the selected nodes
23431 "selectionchange" : true,
23434 * @event beforeselect
23435 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
23436 * @param {Roo.View} this
23437 * @param {HTMLElement} node The node to be selected
23438 * @param {Array} selections Array of currently selected nodes
23440 "beforeselect" : true
23444 "click": this.onClick,
23445 "dblclick": this.onDblClick,
23446 "contextmenu": this.onContextMenu,
23450 this.selections = [];
23452 this.cmp = new Roo.CompositeElementLite([]);
23454 this.store = Roo.factory(this.store, Roo.data);
23455 this.setStore(this.store, true);
23457 Roo.View.superclass.constructor.call(this);
23460 Roo.extend(Roo.View, Roo.util.Observable, {
23463 * @cfg {Roo.data.Store} store Data store to load data from.
23468 * @cfg {String|Roo.Element} el The container element.
23473 * @cfg {String|Roo.Template} tpl The template used by this View
23478 * @cfg {String} selectedClass The css class to add to selected nodes
23480 selectedClass : "x-view-selected",
23482 * @cfg {String} emptyText The empty text to show when nothing is loaded.
23486 * @cfg {Boolean} multiSelect Allow multiple selection
23489 multiSelect : false,
23491 * @cfg {Boolean} singleSelect Allow single selection
23493 singleSelect: false,
23496 * Returns the element this view is bound to.
23497 * @return {Roo.Element}
23499 getEl : function(){
23504 * Refreshes the view.
23506 refresh : function(){
23508 this.clearSelections();
23509 this.el.update("");
23511 var records = this.store.getRange();
23512 if(records.length < 1){
23513 this.el.update(this.emptyText);
23516 for(var i = 0, len = records.length; i < len; i++){
23517 var data = this.prepareData(records[i].data, i, records[i]);
23518 html[html.length] = t.apply(data);
23520 this.el.update(html.join(""));
23521 this.nodes = this.el.dom.childNodes;
23522 this.updateIndexes(0);
23526 * Function to override to reformat the data that is sent to
23527 * the template for each node.
23528 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
23529 * a JSON object for an UpdateManager bound view).
23531 prepareData : function(data){
23535 onUpdate : function(ds, record){
23536 this.clearSelections();
23537 var index = this.store.indexOf(record);
23538 var n = this.nodes[index];
23539 this.tpl.insertBefore(n, this.prepareData(record.data));
23540 n.parentNode.removeChild(n);
23541 this.updateIndexes(index, index);
23544 onAdd : function(ds, records, index){
23545 this.clearSelections();
23546 if(this.nodes.length == 0){
23550 var n = this.nodes[index];
23551 for(var i = 0, len = records.length; i < len; i++){
23552 var d = this.prepareData(records[i].data);
23554 this.tpl.insertBefore(n, d);
23556 this.tpl.append(this.el, d);
23559 this.updateIndexes(index);
23562 onRemove : function(ds, record, index){
23563 this.clearSelections();
23564 this.el.dom.removeChild(this.nodes[index]);
23565 this.updateIndexes(index);
23569 * Refresh an individual node.
23570 * @param {Number} index
23572 refreshNode : function(index){
23573 this.onUpdate(this.store, this.store.getAt(index));
23576 updateIndexes : function(startIndex, endIndex){
23577 var ns = this.nodes;
23578 startIndex = startIndex || 0;
23579 endIndex = endIndex || ns.length - 1;
23580 for(var i = startIndex; i <= endIndex; i++){
23581 ns[i].nodeIndex = i;
23586 * Changes the data store this view uses and refresh the view.
23587 * @param {Store} store
23589 setStore : function(store, initial){
23590 if(!initial && this.store){
23591 this.store.un("datachanged", this.refresh);
23592 this.store.un("add", this.onAdd);
23593 this.store.un("remove", this.onRemove);
23594 this.store.un("update", this.onUpdate);
23595 this.store.un("clear", this.refresh);
23599 store.on("datachanged", this.refresh, this);
23600 store.on("add", this.onAdd, this);
23601 store.on("remove", this.onRemove, this);
23602 store.on("update", this.onUpdate, this);
23603 store.on("clear", this.refresh, this);
23612 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
23613 * @param {HTMLElement} node
23614 * @return {HTMLElement} The template node
23616 findItemFromChild : function(node){
23617 var el = this.el.dom;
23618 if(!node || node.parentNode == el){
23621 var p = node.parentNode;
23622 while(p && p != el){
23623 if(p.parentNode == el){
23632 onClick : function(e){
23633 var item = this.findItemFromChild(e.getTarget());
23635 var index = this.indexOf(item);
23636 if(this.onItemClick(item, index, e) !== false){
23637 this.fireEvent("click", this, index, item, e);
23640 this.clearSelections();
23645 onContextMenu : function(e){
23646 var item = this.findItemFromChild(e.getTarget());
23648 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
23653 onDblClick : function(e){
23654 var item = this.findItemFromChild(e.getTarget());
23656 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
23660 onItemClick : function(item, index, e){
23661 if(this.fireEvent("beforeclick", this, index, item, e) === false){
23664 if(this.multiSelect || this.singleSelect){
23665 if(this.multiSelect && e.shiftKey && this.lastSelection){
23666 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
23668 this.select(item, this.multiSelect && e.ctrlKey);
23669 this.lastSelection = item;
23671 e.preventDefault();
23677 * Get the number of selected nodes.
23680 getSelectionCount : function(){
23681 return this.selections.length;
23685 * Get the currently selected nodes.
23686 * @return {Array} An array of HTMLElements
23688 getSelectedNodes : function(){
23689 return this.selections;
23693 * Get the indexes of the selected nodes.
23696 getSelectedIndexes : function(){
23697 var indexes = [], s = this.selections;
23698 for(var i = 0, len = s.length; i < len; i++){
23699 indexes.push(s[i].nodeIndex);
23705 * Clear all selections
23706 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
23708 clearSelections : function(suppressEvent){
23709 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
23710 this.cmp.elements = this.selections;
23711 this.cmp.removeClass(this.selectedClass);
23712 this.selections = [];
23713 if(!suppressEvent){
23714 this.fireEvent("selectionchange", this, this.selections);
23720 * Returns true if the passed node is selected
23721 * @param {HTMLElement/Number} node The node or node index
23722 * @return {Boolean}
23724 isSelected : function(node){
23725 var s = this.selections;
23729 node = this.getNode(node);
23730 return s.indexOf(node) !== -1;
23735 * @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
23736 * @param {Boolean} keepExisting (optional) true to keep existing selections
23737 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
23739 select : function(nodeInfo, keepExisting, suppressEvent){
23740 if(nodeInfo instanceof Array){
23742 this.clearSelections(true);
23744 for(var i = 0, len = nodeInfo.length; i < len; i++){
23745 this.select(nodeInfo[i], true, true);
23748 var node = this.getNode(nodeInfo);
23749 if(node && !this.isSelected(node)){
23751 this.clearSelections(true);
23753 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
23754 Roo.fly(node).addClass(this.selectedClass);
23755 this.selections.push(node);
23756 if(!suppressEvent){
23757 this.fireEvent("selectionchange", this, this.selections);
23765 * Gets a template node.
23766 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
23767 * @return {HTMLElement} The node or null if it wasn't found
23769 getNode : function(nodeInfo){
23770 if(typeof nodeInfo == "string"){
23771 return document.getElementById(nodeInfo);
23772 }else if(typeof nodeInfo == "number"){
23773 return this.nodes[nodeInfo];
23779 * Gets a range template nodes.
23780 * @param {Number} startIndex
23781 * @param {Number} endIndex
23782 * @return {Array} An array of nodes
23784 getNodes : function(start, end){
23785 var ns = this.nodes;
23786 start = start || 0;
23787 end = typeof end == "undefined" ? ns.length - 1 : end;
23790 for(var i = start; i <= end; i++){
23794 for(var i = start; i >= end; i--){
23802 * Finds the index of the passed node
23803 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
23804 * @return {Number} The index of the node or -1
23806 indexOf : function(node){
23807 node = this.getNode(node);
23808 if(typeof node.nodeIndex == "number"){
23809 return node.nodeIndex;
23811 var ns = this.nodes;
23812 for(var i = 0, len = ns.length; i < len; i++){
23822 * Ext JS Library 1.1.1
23823 * Copyright(c) 2006-2007, Ext JS, LLC.
23825 * Originally Released Under LGPL - original licence link has changed is not relivant.
23828 * <script type="text/javascript">
23832 * @class Roo.JsonView
23833 * @extends Roo.View
23834 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
23836 var view = new Roo.JsonView({
23837 container: "my-element",
23838 tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
23843 // listen for node click?
23844 view.on("click", function(vw, index, node, e){
23845 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
23848 // direct load of JSON data
23849 view.load("foobar.php");
23851 // Example from my blog list
23852 var tpl = new Roo.Template(
23853 '<div class="entry">' +
23854 '<a class="entry-title" href="{link}">{title}</a>' +
23855 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
23856 "</div><hr />"
23859 var moreView = new Roo.JsonView({
23860 container : "entry-list",
23864 moreView.on("beforerender", this.sortEntries, this);
23866 url: "/blog/get-posts.php",
23867 params: "allposts=true",
23868 text: "Loading Blog Entries..."
23872 * Note: old code is supported with arguments : (container, template, config)
23876 * Create a new JsonView
23878 * @param {Object} config The config object
23881 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
23884 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
23886 var um = this.el.getUpdateManager();
23887 um.setRenderer(this);
23888 um.on("update", this.onLoad, this);
23889 um.on("failure", this.onLoadException, this);
23892 * @event beforerender
23893 * Fires before rendering of the downloaded JSON data.
23894 * @param {Roo.JsonView} this
23895 * @param {Object} data The JSON data loaded
23899 * Fires when data is loaded.
23900 * @param {Roo.JsonView} this
23901 * @param {Object} data The JSON data loaded
23902 * @param {Object} response The raw Connect response object
23905 * @event loadexception
23906 * Fires when loading fails.
23907 * @param {Roo.JsonView} this
23908 * @param {Object} response The raw Connect response object
23911 'beforerender' : true,
23913 'loadexception' : true
23916 Roo.extend(Roo.JsonView, Roo.View, {
23918 * @type {String} The root property in the loaded JSON object that contains the data
23923 * Refreshes the view.
23925 refresh : function(){
23926 this.clearSelections();
23927 this.el.update("");
23929 var o = this.jsonData;
23930 if(o && o.length > 0){
23931 for(var i = 0, len = o.length; i < len; i++){
23932 var data = this.prepareData(o[i], i, o);
23933 html[html.length] = this.tpl.apply(data);
23936 html.push(this.emptyText);
23938 this.el.update(html.join(""));
23939 this.nodes = this.el.dom.childNodes;
23940 this.updateIndexes(0);
23944 * 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.
23945 * @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:
23948 url: "your-url.php",
23949 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
23950 callback: yourFunction,
23951 scope: yourObject, //(optional scope)
23954 text: "Loading...",
23959 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
23960 * 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.
23961 * @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}
23962 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
23963 * @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.
23966 var um = this.el.getUpdateManager();
23967 um.update.apply(um, arguments);
23970 render : function(el, response){
23971 this.clearSelections();
23972 this.el.update("");
23975 o = Roo.util.JSON.decode(response.responseText);
23978 o = o[this.jsonRoot];
23983 * The current JSON data or null
23986 this.beforeRender();
23991 * Get the number of records in the current JSON dataset
23994 getCount : function(){
23995 return this.jsonData ? this.jsonData.length : 0;
23999 * Returns the JSON object for the specified node(s)
24000 * @param {HTMLElement/Array} node The node or an array of nodes
24001 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
24002 * you get the JSON object for the node
24004 getNodeData : function(node){
24005 if(node instanceof Array){
24007 for(var i = 0, len = node.length; i < len; i++){
24008 data.push(this.getNodeData(node[i]));
24012 return this.jsonData[this.indexOf(node)] || null;
24015 beforeRender : function(){
24016 this.snapshot = this.jsonData;
24018 this.sort.apply(this, this.sortInfo);
24020 this.fireEvent("beforerender", this, this.jsonData);
24023 onLoad : function(el, o){
24024 this.fireEvent("load", this, this.jsonData, o);
24027 onLoadException : function(el, o){
24028 this.fireEvent("loadexception", this, o);
24032 * Filter the data by a specific property.
24033 * @param {String} property A property on your JSON objects
24034 * @param {String/RegExp} value Either string that the property values
24035 * should start with, or a RegExp to test against the property
24037 filter : function(property, value){
24040 var ss = this.snapshot;
24041 if(typeof value == "string"){
24042 var vlen = value.length;
24044 this.clearFilter();
24047 value = value.toLowerCase();
24048 for(var i = 0, len = ss.length; i < len; i++){
24050 if(o[property].substr(0, vlen).toLowerCase() == value){
24054 } else if(value.exec){ // regex?
24055 for(var i = 0, len = ss.length; i < len; i++){
24057 if(value.test(o[property])){
24064 this.jsonData = data;
24070 * Filter by a function. The passed function will be called with each
24071 * object in the current dataset. If the function returns true the value is kept,
24072 * otherwise it is filtered.
24073 * @param {Function} fn
24074 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
24076 filterBy : function(fn, scope){
24079 var ss = this.snapshot;
24080 for(var i = 0, len = ss.length; i < len; i++){
24082 if(fn.call(scope || this, o)){
24086 this.jsonData = data;
24092 * Clears the current filter.
24094 clearFilter : function(){
24095 if(this.snapshot && this.jsonData != this.snapshot){
24096 this.jsonData = this.snapshot;
24103 * Sorts the data for this view and refreshes it.
24104 * @param {String} property A property on your JSON objects to sort on
24105 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
24106 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
24108 sort : function(property, dir, sortType){
24109 this.sortInfo = Array.prototype.slice.call(arguments, 0);
24112 var dsc = dir && dir.toLowerCase() == "desc";
24113 var f = function(o1, o2){
24114 var v1 = sortType ? sortType(o1[p]) : o1[p];
24115 var v2 = sortType ? sortType(o2[p]) : o2[p];
24118 return dsc ? +1 : -1;
24119 } else if(v1 > v2){
24120 return dsc ? -1 : +1;
24125 this.jsonData.sort(f);
24127 if(this.jsonData != this.snapshot){
24128 this.snapshot.sort(f);
24134 * Ext JS Library 1.1.1
24135 * Copyright(c) 2006-2007, Ext JS, LLC.
24137 * Originally Released Under LGPL - original licence link has changed is not relivant.
24140 * <script type="text/javascript">
24145 * @class Roo.ColorPalette
24146 * @extends Roo.Component
24147 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
24148 * Here's an example of typical usage:
24150 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
24151 cp.render('my-div');
24153 cp.on('select', function(palette, selColor){
24154 // do something with selColor
24158 * Create a new ColorPalette
24159 * @param {Object} config The config object
24161 Roo.ColorPalette = function(config){
24162 Roo.ColorPalette.superclass.constructor.call(this, config);
24166 * Fires when a color is selected
24167 * @param {ColorPalette} this
24168 * @param {String} color The 6-digit color hex code (without the # symbol)
24174 this.on("select", this.handler, this.scope, true);
24177 Roo.extend(Roo.ColorPalette, Roo.Component, {
24179 * @cfg {String} itemCls
24180 * The CSS class to apply to the containing element (defaults to "x-color-palette")
24182 itemCls : "x-color-palette",
24184 * @cfg {String} value
24185 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
24186 * the hex codes are case-sensitive.
24189 clickEvent:'click',
24191 ctype: "Roo.ColorPalette",
24194 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
24196 allowReselect : false,
24199 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
24200 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
24201 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
24202 * of colors with the width setting until the box is symmetrical.</p>
24203 * <p>You can override individual colors if needed:</p>
24205 var cp = new Roo.ColorPalette();
24206 cp.colors[0] = "FF0000"; // change the first box to red
24209 Or you can provide a custom array of your own for complete control:
24211 var cp = new Roo.ColorPalette();
24212 cp.colors = ["000000", "993300", "333300"];
24217 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
24218 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
24219 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
24220 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
24221 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
24225 onRender : function(container, position){
24226 var t = new Roo.MasterTemplate(
24227 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
24229 var c = this.colors;
24230 for(var i = 0, len = c.length; i < len; i++){
24233 var el = document.createElement("div");
24234 el.className = this.itemCls;
24236 container.dom.insertBefore(el, position);
24237 this.el = Roo.get(el);
24238 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
24239 if(this.clickEvent != 'click'){
24240 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
24245 afterRender : function(){
24246 Roo.ColorPalette.superclass.afterRender.call(this);
24248 var s = this.value;
24255 handleClick : function(e, t){
24256 e.preventDefault();
24257 if(!this.disabled){
24258 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
24259 this.select(c.toUpperCase());
24264 * Selects the specified color in the palette (fires the select event)
24265 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
24267 select : function(color){
24268 color = color.replace("#", "");
24269 if(color != this.value || this.allowReselect){
24272 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
24274 el.child("a.color-"+color).addClass("x-color-palette-sel");
24275 this.value = color;
24276 this.fireEvent("select", this, color);
24281 * Ext JS Library 1.1.1
24282 * Copyright(c) 2006-2007, Ext JS, LLC.
24284 * Originally Released Under LGPL - original licence link has changed is not relivant.
24287 * <script type="text/javascript">
24291 * @class Roo.DatePicker
24292 * @extends Roo.Component
24293 * Simple date picker class.
24295 * Create a new DatePicker
24296 * @param {Object} config The config object
24298 Roo.DatePicker = function(config){
24299 Roo.DatePicker.superclass.constructor.call(this, config);
24301 this.value = config && config.value ?
24302 config.value.clearTime() : new Date().clearTime();
24307 * Fires when a date is selected
24308 * @param {DatePicker} this
24309 * @param {Date} date The selected date
24315 this.on("select", this.handler, this.scope || this);
24317 // build the disabledDatesRE
24318 if(!this.disabledDatesRE && this.disabledDates){
24319 var dd = this.disabledDates;
24321 for(var i = 0; i < dd.length; i++){
24323 if(i != dd.length-1) re += "|";
24325 this.disabledDatesRE = new RegExp(re + ")");
24329 Roo.extend(Roo.DatePicker, Roo.Component, {
24331 * @cfg {String} todayText
24332 * The text to display on the button that selects the current date (defaults to "Today")
24334 todayText : "Today",
24336 * @cfg {String} okText
24337 * The text to display on the ok button
24339 okText : " OK ", //   to give the user extra clicking room
24341 * @cfg {String} cancelText
24342 * The text to display on the cancel button
24344 cancelText : "Cancel",
24346 * @cfg {String} todayTip
24347 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
24349 todayTip : "{0} (Spacebar)",
24351 * @cfg {Date} minDate
24352 * Minimum allowable date (JavaScript date object, defaults to null)
24356 * @cfg {Date} maxDate
24357 * Maximum allowable date (JavaScript date object, defaults to null)
24361 * @cfg {String} minText
24362 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
24364 minText : "This date is before the minimum date",
24366 * @cfg {String} maxText
24367 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
24369 maxText : "This date is after the maximum date",
24371 * @cfg {String} format
24372 * The default date format string which can be overriden for localization support. The format must be
24373 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
24377 * @cfg {Array} disabledDays
24378 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
24380 disabledDays : null,
24382 * @cfg {String} disabledDaysText
24383 * The tooltip to display when the date falls on a disabled day (defaults to "")
24385 disabledDaysText : "",
24387 * @cfg {RegExp} disabledDatesRE
24388 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
24390 disabledDatesRE : null,
24392 * @cfg {String} disabledDatesText
24393 * The tooltip text to display when the date falls on a disabled date (defaults to "")
24395 disabledDatesText : "",
24397 * @cfg {Boolean} constrainToViewport
24398 * True to constrain the date picker to the viewport (defaults to true)
24400 constrainToViewport : true,
24402 * @cfg {Array} monthNames
24403 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
24405 monthNames : Date.monthNames,
24407 * @cfg {Array} dayNames
24408 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
24410 dayNames : Date.dayNames,
24412 * @cfg {String} nextText
24413 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
24415 nextText: 'Next Month (Control+Right)',
24417 * @cfg {String} prevText
24418 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
24420 prevText: 'Previous Month (Control+Left)',
24422 * @cfg {String} monthYearText
24423 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
24425 monthYearText: 'Choose a month (Control+Up/Down to move years)',
24427 * @cfg {Number} startDay
24428 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
24432 * @cfg {Bool} showClear
24433 * Show a clear button (usefull for date form elements that can be blank.)
24439 * Sets the value of the date field
24440 * @param {Date} value The date to set
24442 setValue : function(value){
24443 var old = this.value;
24444 this.value = value.clearTime(true);
24446 this.update(this.value);
24451 * Gets the current selected value of the date field
24452 * @return {Date} The selected date
24454 getValue : function(){
24459 focus : function(){
24461 this.update(this.activeDate);
24466 onRender : function(container, position){
24468 '<table cellspacing="0">',
24469 '<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>',
24470 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
24471 var dn = this.dayNames;
24472 for(var i = 0; i < 7; i++){
24473 var d = this.startDay+i;
24477 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
24479 m[m.length] = "</tr></thead><tbody><tr>";
24480 for(var i = 0; i < 42; i++) {
24481 if(i % 7 == 0 && i != 0){
24482 m[m.length] = "</tr><tr>";
24484 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
24486 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
24487 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
24489 var el = document.createElement("div");
24490 el.className = "x-date-picker";
24491 el.innerHTML = m.join("");
24493 container.dom.insertBefore(el, position);
24495 this.el = Roo.get(el);
24496 this.eventEl = Roo.get(el.firstChild);
24498 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
24499 handler: this.showPrevMonth,
24501 preventDefault:true,
24505 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
24506 handler: this.showNextMonth,
24508 preventDefault:true,
24512 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
24514 this.monthPicker = this.el.down('div.x-date-mp');
24515 this.monthPicker.enableDisplayMode('block');
24517 var kn = new Roo.KeyNav(this.eventEl, {
24518 "left" : function(e){
24520 this.showPrevMonth() :
24521 this.update(this.activeDate.add("d", -1));
24524 "right" : function(e){
24526 this.showNextMonth() :
24527 this.update(this.activeDate.add("d", 1));
24530 "up" : function(e){
24532 this.showNextYear() :
24533 this.update(this.activeDate.add("d", -7));
24536 "down" : function(e){
24538 this.showPrevYear() :
24539 this.update(this.activeDate.add("d", 7));
24542 "pageUp" : function(e){
24543 this.showNextMonth();
24546 "pageDown" : function(e){
24547 this.showPrevMonth();
24550 "enter" : function(e){
24551 e.stopPropagation();
24558 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
24560 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
24562 this.el.unselectable();
24564 this.cells = this.el.select("table.x-date-inner tbody td");
24565 this.textNodes = this.el.query("table.x-date-inner tbody span");
24567 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
24569 tooltip: this.monthYearText
24572 this.mbtn.on('click', this.showMonthPicker, this);
24573 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
24576 var today = (new Date()).dateFormat(this.format);
24578 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
24580 text: String.format(this.todayText, today),
24581 tooltip: String.format(this.todayTip, today),
24582 handler: this.selectToday,
24586 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
24589 if (this.showClear) {
24591 baseTb.add( new Roo.Toolbar.Fill());
24594 cls: 'x-btn-icon x-btn-clear',
24595 handler: function() {
24597 this.fireEvent("select", this, '');
24607 this.update(this.value);
24610 createMonthPicker : function(){
24611 if(!this.monthPicker.dom.firstChild){
24612 var buf = ['<table border="0" cellspacing="0">'];
24613 for(var i = 0; i < 6; i++){
24615 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
24616 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
24618 '<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>' :
24619 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
24623 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
24625 '</button><button type="button" class="x-date-mp-cancel">',
24627 '</button></td></tr>',
24630 this.monthPicker.update(buf.join(''));
24631 this.monthPicker.on('click', this.onMonthClick, this);
24632 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
24634 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
24635 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
24637 this.mpMonths.each(function(m, a, i){
24640 m.dom.xmonth = 5 + Math.round(i * .5);
24642 m.dom.xmonth = Math.round((i-1) * .5);
24648 showMonthPicker : function(){
24649 this.createMonthPicker();
24650 var size = this.el.getSize();
24651 this.monthPicker.setSize(size);
24652 this.monthPicker.child('table').setSize(size);
24654 this.mpSelMonth = (this.activeDate || this.value).getMonth();
24655 this.updateMPMonth(this.mpSelMonth);
24656 this.mpSelYear = (this.activeDate || this.value).getFullYear();
24657 this.updateMPYear(this.mpSelYear);
24659 this.monthPicker.slideIn('t', {duration:.2});
24662 updateMPYear : function(y){
24664 var ys = this.mpYears.elements;
24665 for(var i = 1; i <= 10; i++){
24666 var td = ys[i-1], y2;
24668 y2 = y + Math.round(i * .5);
24669 td.firstChild.innerHTML = y2;
24672 y2 = y - (5-Math.round(i * .5));
24673 td.firstChild.innerHTML = y2;
24676 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
24680 updateMPMonth : function(sm){
24681 this.mpMonths.each(function(m, a, i){
24682 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
24686 selectMPMonth: function(m){
24690 onMonthClick : function(e, t){
24692 var el = new Roo.Element(t), pn;
24693 if(el.is('button.x-date-mp-cancel')){
24694 this.hideMonthPicker();
24696 else if(el.is('button.x-date-mp-ok')){
24697 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
24698 this.hideMonthPicker();
24700 else if(pn = el.up('td.x-date-mp-month', 2)){
24701 this.mpMonths.removeClass('x-date-mp-sel');
24702 pn.addClass('x-date-mp-sel');
24703 this.mpSelMonth = pn.dom.xmonth;
24705 else if(pn = el.up('td.x-date-mp-year', 2)){
24706 this.mpYears.removeClass('x-date-mp-sel');
24707 pn.addClass('x-date-mp-sel');
24708 this.mpSelYear = pn.dom.xyear;
24710 else if(el.is('a.x-date-mp-prev')){
24711 this.updateMPYear(this.mpyear-10);
24713 else if(el.is('a.x-date-mp-next')){
24714 this.updateMPYear(this.mpyear+10);
24718 onMonthDblClick : function(e, t){
24720 var el = new Roo.Element(t), pn;
24721 if(pn = el.up('td.x-date-mp-month', 2)){
24722 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
24723 this.hideMonthPicker();
24725 else if(pn = el.up('td.x-date-mp-year', 2)){
24726 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
24727 this.hideMonthPicker();
24731 hideMonthPicker : function(disableAnim){
24732 if(this.monthPicker){
24733 if(disableAnim === true){
24734 this.monthPicker.hide();
24736 this.monthPicker.slideOut('t', {duration:.2});
24742 showPrevMonth : function(e){
24743 this.update(this.activeDate.add("mo", -1));
24747 showNextMonth : function(e){
24748 this.update(this.activeDate.add("mo", 1));
24752 showPrevYear : function(){
24753 this.update(this.activeDate.add("y", -1));
24757 showNextYear : function(){
24758 this.update(this.activeDate.add("y", 1));
24762 handleMouseWheel : function(e){
24763 var delta = e.getWheelDelta();
24765 this.showPrevMonth();
24767 } else if(delta < 0){
24768 this.showNextMonth();
24774 handleDateClick : function(e, t){
24776 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
24777 this.setValue(new Date(t.dateValue));
24778 this.fireEvent("select", this, this.value);
24783 selectToday : function(){
24784 this.setValue(new Date().clearTime());
24785 this.fireEvent("select", this, this.value);
24789 update : function(date){
24790 var vd = this.activeDate;
24791 this.activeDate = date;
24793 var t = date.getTime();
24794 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
24795 this.cells.removeClass("x-date-selected");
24796 this.cells.each(function(c){
24797 if(c.dom.firstChild.dateValue == t){
24798 c.addClass("x-date-selected");
24799 setTimeout(function(){
24800 try{c.dom.firstChild.focus();}catch(e){}
24808 var days = date.getDaysInMonth();
24809 var firstOfMonth = date.getFirstDateOfMonth();
24810 var startingPos = firstOfMonth.getDay()-this.startDay;
24812 if(startingPos <= this.startDay){
24816 var pm = date.add("mo", -1);
24817 var prevStart = pm.getDaysInMonth()-startingPos;
24819 var cells = this.cells.elements;
24820 var textEls = this.textNodes;
24821 days += startingPos;
24823 // convert everything to numbers so it's fast
24824 var day = 86400000;
24825 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
24826 var today = new Date().clearTime().getTime();
24827 var sel = date.clearTime().getTime();
24828 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
24829 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
24830 var ddMatch = this.disabledDatesRE;
24831 var ddText = this.disabledDatesText;
24832 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
24833 var ddaysText = this.disabledDaysText;
24834 var format = this.format;
24836 var setCellClass = function(cal, cell){
24838 var t = d.getTime();
24839 cell.firstChild.dateValue = t;
24841 cell.className += " x-date-today";
24842 cell.title = cal.todayText;
24845 cell.className += " x-date-selected";
24846 setTimeout(function(){
24847 try{cell.firstChild.focus();}catch(e){}
24852 cell.className = " x-date-disabled";
24853 cell.title = cal.minText;
24857 cell.className = " x-date-disabled";
24858 cell.title = cal.maxText;
24862 if(ddays.indexOf(d.getDay()) != -1){
24863 cell.title = ddaysText;
24864 cell.className = " x-date-disabled";
24867 if(ddMatch && format){
24868 var fvalue = d.dateFormat(format);
24869 if(ddMatch.test(fvalue)){
24870 cell.title = ddText.replace("%0", fvalue);
24871 cell.className = " x-date-disabled";
24877 for(; i < startingPos; i++) {
24878 textEls[i].innerHTML = (++prevStart);
24879 d.setDate(d.getDate()+1);
24880 cells[i].className = "x-date-prevday";
24881 setCellClass(this, cells[i]);
24883 for(; i < days; i++){
24884 intDay = i - startingPos + 1;
24885 textEls[i].innerHTML = (intDay);
24886 d.setDate(d.getDate()+1);
24887 cells[i].className = "x-date-active";
24888 setCellClass(this, cells[i]);
24891 for(; i < 42; i++) {
24892 textEls[i].innerHTML = (++extraDays);
24893 d.setDate(d.getDate()+1);
24894 cells[i].className = "x-date-nextday";
24895 setCellClass(this, cells[i]);
24898 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
24900 if(!this.internalRender){
24901 var main = this.el.dom.firstChild;
24902 var w = main.offsetWidth;
24903 this.el.setWidth(w + this.el.getBorderWidth("lr"));
24904 Roo.fly(main).setWidth(w);
24905 this.internalRender = true;
24906 // opera does not respect the auto grow header center column
24907 // then, after it gets a width opera refuses to recalculate
24908 // without a second pass
24909 if(Roo.isOpera && !this.secondPass){
24910 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
24911 this.secondPass = true;
24912 this.update.defer(10, this, [date]);
24918 * Ext JS Library 1.1.1
24919 * Copyright(c) 2006-2007, Ext JS, LLC.
24921 * Originally Released Under LGPL - original licence link has changed is not relivant.
24924 * <script type="text/javascript">
24927 * @class Roo.TabPanel
24928 * @extends Roo.util.Observable
24929 * A lightweight tab container.
24933 // basic tabs 1, built from existing content
24934 var tabs = new Roo.TabPanel("tabs1");
24935 tabs.addTab("script", "View Script");
24936 tabs.addTab("markup", "View Markup");
24937 tabs.activate("script");
24939 // more advanced tabs, built from javascript
24940 var jtabs = new Roo.TabPanel("jtabs");
24941 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
24943 // set up the UpdateManager
24944 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
24945 var updater = tab2.getUpdateManager();
24946 updater.setDefaultUrl("ajax1.htm");
24947 tab2.on('activate', updater.refresh, updater, true);
24949 // Use setUrl for Ajax loading
24950 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
24951 tab3.setUrl("ajax2.htm", null, true);
24954 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
24957 jtabs.activate("jtabs-1");
24960 * Create a new TabPanel.
24961 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
24962 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
24964 Roo.TabPanel = function(container, config){
24966 * The container element for this TabPanel.
24967 * @type Roo.Element
24969 this.el = Roo.get(container, true);
24971 if(typeof config == "boolean"){
24972 this.tabPosition = config ? "bottom" : "top";
24974 Roo.apply(this, config);
24977 if(this.tabPosition == "bottom"){
24978 this.bodyEl = Roo.get(this.createBody(this.el.dom));
24979 this.el.addClass("x-tabs-bottom");
24981 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
24982 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
24983 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
24985 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
24987 if(this.tabPosition != "bottom"){
24988 /** The body element that contains {@link Roo.TabPanelItem} bodies.
24989 * @type Roo.Element
24991 this.bodyEl = Roo.get(this.createBody(this.el.dom));
24992 this.el.addClass("x-tabs-top");
24996 this.bodyEl.setStyle("position", "relative");
24998 this.active = null;
24999 this.activateDelegate = this.activate.createDelegate(this);
25004 * Fires when the active tab changes
25005 * @param {Roo.TabPanel} this
25006 * @param {Roo.TabPanelItem} activePanel The new active tab
25010 * @event beforetabchange
25011 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
25012 * @param {Roo.TabPanel} this
25013 * @param {Object} e Set cancel to true on this object to cancel the tab change
25014 * @param {Roo.TabPanelItem} tab The tab being changed to
25016 "beforetabchange" : true
25019 Roo.EventManager.onWindowResize(this.onResize, this);
25020 this.cpad = this.el.getPadding("lr");
25021 this.hiddenCount = 0;
25023 Roo.TabPanel.superclass.constructor.call(this);
25026 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
25028 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
25030 tabPosition : "top",
25032 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
25034 currentTabWidth : 0,
25036 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
25040 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
25044 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
25046 preferredTabWidth : 175,
25048 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
25050 resizeTabs : false,
25052 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
25054 monitorResize : true,
25057 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
25058 * @param {String} id The id of the div to use <b>or create</b>
25059 * @param {String} text The text for the tab
25060 * @param {String} content (optional) Content to put in the TabPanelItem body
25061 * @param {Boolean} closable (optional) True to create a close icon on the tab
25062 * @return {Roo.TabPanelItem} The created TabPanelItem
25064 addTab : function(id, text, content, closable){
25065 var item = new Roo.TabPanelItem(this, id, text, closable);
25066 this.addTabItem(item);
25068 item.setContent(content);
25074 * Returns the {@link Roo.TabPanelItem} with the specified id/index
25075 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
25076 * @return {Roo.TabPanelItem}
25078 getTab : function(id){
25079 return this.items[id];
25083 * Hides the {@link Roo.TabPanelItem} with the specified id/index
25084 * @param {String/Number} id The id or index of the TabPanelItem to hide.
25086 hideTab : function(id){
25087 var t = this.items[id];
25090 this.hiddenCount++;
25091 this.autoSizeTabs();
25096 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
25097 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
25099 unhideTab : function(id){
25100 var t = this.items[id];
25102 t.setHidden(false);
25103 this.hiddenCount--;
25104 this.autoSizeTabs();
25109 * Adds an existing {@link Roo.TabPanelItem}.
25110 * @param {Roo.TabPanelItem} item The TabPanelItem to add
25112 addTabItem : function(item){
25113 this.items[item.id] = item;
25114 this.items.push(item);
25115 if(this.resizeTabs){
25116 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
25117 this.autoSizeTabs();
25124 * Removes a {@link Roo.TabPanelItem}.
25125 * @param {String/Number} id The id or index of the TabPanelItem to remove.
25127 removeTab : function(id){
25128 var items = this.items;
25129 var tab = items[id];
25130 if(!tab) { return; }
25131 var index = items.indexOf(tab);
25132 if(this.active == tab && items.length > 1){
25133 var newTab = this.getNextAvailable(index);
25138 this.stripEl.dom.removeChild(tab.pnode.dom);
25139 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
25140 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
25142 items.splice(index, 1);
25143 delete this.items[tab.id];
25144 tab.fireEvent("close", tab);
25145 tab.purgeListeners();
25146 this.autoSizeTabs();
25149 getNextAvailable : function(start){
25150 var items = this.items;
25152 // look for a next tab that will slide over to
25153 // replace the one being removed
25154 while(index < items.length){
25155 var item = items[++index];
25156 if(item && !item.isHidden()){
25160 // if one isn't found select the previous tab (on the left)
25163 var item = items[--index];
25164 if(item && !item.isHidden()){
25172 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
25173 * @param {String/Number} id The id or index of the TabPanelItem to disable.
25175 disableTab : function(id){
25176 var tab = this.items[id];
25177 if(tab && this.active != tab){
25183 * Enables a {@link Roo.TabPanelItem} that is disabled.
25184 * @param {String/Number} id The id or index of the TabPanelItem to enable.
25186 enableTab : function(id){
25187 var tab = this.items[id];
25192 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
25193 * @param {String/Number} id The id or index of the TabPanelItem to activate.
25194 * @return {Roo.TabPanelItem} The TabPanelItem.
25196 activate : function(id){
25197 var tab = this.items[id];
25201 if(tab == this.active || tab.disabled){
25205 this.fireEvent("beforetabchange", this, e, tab);
25206 if(e.cancel !== true && !tab.disabled){
25208 this.active.hide();
25210 this.active = this.items[id];
25211 this.active.show();
25212 this.fireEvent("tabchange", this, this.active);
25218 * Gets the active {@link Roo.TabPanelItem}.
25219 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
25221 getActiveTab : function(){
25222 return this.active;
25226 * Updates the tab body element to fit the height of the container element
25227 * for overflow scrolling
25228 * @param {Number} targetHeight (optional) Override the starting height from the elements height
25230 syncHeight : function(targetHeight){
25231 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
25232 var bm = this.bodyEl.getMargins();
25233 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
25234 this.bodyEl.setHeight(newHeight);
25238 onResize : function(){
25239 if(this.monitorResize){
25240 this.autoSizeTabs();
25245 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
25247 beginUpdate : function(){
25248 this.updating = true;
25252 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
25254 endUpdate : function(){
25255 this.updating = false;
25256 this.autoSizeTabs();
25260 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
25262 autoSizeTabs : function(){
25263 var count = this.items.length;
25264 var vcount = count - this.hiddenCount;
25265 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) return;
25266 var w = Math.max(this.el.getWidth() - this.cpad, 10);
25267 var availWidth = Math.floor(w / vcount);
25268 var b = this.stripBody;
25269 if(b.getWidth() > w){
25270 var tabs = this.items;
25271 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
25272 if(availWidth < this.minTabWidth){
25273 /*if(!this.sleft){ // incomplete scrolling code
25274 this.createScrollButtons();
25277 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
25280 if(this.currentTabWidth < this.preferredTabWidth){
25281 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
25287 * Returns the number of tabs in this TabPanel.
25290 getCount : function(){
25291 return this.items.length;
25295 * Resizes all the tabs to the passed width
25296 * @param {Number} The new width
25298 setTabWidth : function(width){
25299 this.currentTabWidth = width;
25300 for(var i = 0, len = this.items.length; i < len; i++) {
25301 if(!this.items[i].isHidden())this.items[i].setWidth(width);
25306 * Destroys this TabPanel
25307 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
25309 destroy : function(removeEl){
25310 Roo.EventManager.removeResizeListener(this.onResize, this);
25311 for(var i = 0, len = this.items.length; i < len; i++){
25312 this.items[i].purgeListeners();
25314 if(removeEl === true){
25315 this.el.update("");
25322 * @class Roo.TabPanelItem
25323 * @extends Roo.util.Observable
25324 * Represents an individual item (tab plus body) in a TabPanel.
25325 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
25326 * @param {String} id The id of this TabPanelItem
25327 * @param {String} text The text for the tab of this TabPanelItem
25328 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
25330 Roo.TabPanelItem = function(tabPanel, id, text, closable){
25332 * The {@link Roo.TabPanel} this TabPanelItem belongs to
25333 * @type Roo.TabPanel
25335 this.tabPanel = tabPanel;
25337 * The id for this TabPanelItem
25342 this.disabled = false;
25346 this.loaded = false;
25347 this.closable = closable;
25350 * The body element for this TabPanelItem.
25351 * @type Roo.Element
25353 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
25354 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
25355 this.bodyEl.setStyle("display", "block");
25356 this.bodyEl.setStyle("zoom", "1");
25359 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
25361 this.el = Roo.get(els.el, true);
25362 this.inner = Roo.get(els.inner, true);
25363 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
25364 this.pnode = Roo.get(els.el.parentNode, true);
25365 this.el.on("mousedown", this.onTabMouseDown, this);
25366 this.el.on("click", this.onTabClick, this);
25369 var c = Roo.get(els.close, true);
25370 c.dom.title = this.closeText;
25371 c.addClassOnOver("close-over");
25372 c.on("click", this.closeClick, this);
25378 * Fires when this tab becomes the active tab.
25379 * @param {Roo.TabPanel} tabPanel The parent TabPanel
25380 * @param {Roo.TabPanelItem} this
25384 * @event beforeclose
25385 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
25386 * @param {Roo.TabPanelItem} this
25387 * @param {Object} e Set cancel to true on this object to cancel the close.
25389 "beforeclose": true,
25392 * Fires when this tab is closed.
25393 * @param {Roo.TabPanelItem} this
25397 * @event deactivate
25398 * Fires when this tab is no longer the active tab.
25399 * @param {Roo.TabPanel} tabPanel The parent TabPanel
25400 * @param {Roo.TabPanelItem} this
25402 "deactivate" : true
25404 this.hidden = false;
25406 Roo.TabPanelItem.superclass.constructor.call(this);
25409 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
25410 purgeListeners : function(){
25411 Roo.util.Observable.prototype.purgeListeners.call(this);
25412 this.el.removeAllListeners();
25415 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
25418 this.pnode.addClass("on");
25421 this.tabPanel.stripWrap.repaint();
25423 this.fireEvent("activate", this.tabPanel, this);
25427 * Returns true if this tab is the active tab.
25428 * @return {Boolean}
25430 isActive : function(){
25431 return this.tabPanel.getActiveTab() == this;
25435 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
25438 this.pnode.removeClass("on");
25440 this.fireEvent("deactivate", this.tabPanel, this);
25443 hideAction : function(){
25444 this.bodyEl.hide();
25445 this.bodyEl.setStyle("position", "absolute");
25446 this.bodyEl.setLeft("-20000px");
25447 this.bodyEl.setTop("-20000px");
25450 showAction : function(){
25451 this.bodyEl.setStyle("position", "relative");
25452 this.bodyEl.setTop("");
25453 this.bodyEl.setLeft("");
25454 this.bodyEl.show();
25458 * Set the tooltip for the tab.
25459 * @param {String} tooltip The tab's tooltip
25461 setTooltip : function(text){
25462 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
25463 this.textEl.dom.qtip = text;
25464 this.textEl.dom.removeAttribute('title');
25466 this.textEl.dom.title = text;
25470 onTabClick : function(e){
25471 e.preventDefault();
25472 this.tabPanel.activate(this.id);
25475 onTabMouseDown : function(e){
25476 e.preventDefault();
25477 this.tabPanel.activate(this.id);
25480 getWidth : function(){
25481 return this.inner.getWidth();
25484 setWidth : function(width){
25485 var iwidth = width - this.pnode.getPadding("lr");
25486 this.inner.setWidth(iwidth);
25487 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
25488 this.pnode.setWidth(width);
25492 * Show or hide the tab
25493 * @param {Boolean} hidden True to hide or false to show.
25495 setHidden : function(hidden){
25496 this.hidden = hidden;
25497 this.pnode.setStyle("display", hidden ? "none" : "");
25501 * Returns true if this tab is "hidden"
25502 * @return {Boolean}
25504 isHidden : function(){
25505 return this.hidden;
25509 * Returns the text for this tab
25512 getText : function(){
25516 autoSize : function(){
25517 //this.el.beginMeasure();
25518 this.textEl.setWidth(1);
25519 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr"));
25520 //this.el.endMeasure();
25524 * Sets the text for the tab (Note: this also sets the tooltip text)
25525 * @param {String} text The tab's text and tooltip
25527 setText : function(text){
25529 this.textEl.update(text);
25530 this.setTooltip(text);
25531 if(!this.tabPanel.resizeTabs){
25536 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
25538 activate : function(){
25539 this.tabPanel.activate(this.id);
25543 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
25545 disable : function(){
25546 if(this.tabPanel.active != this){
25547 this.disabled = true;
25548 this.pnode.addClass("disabled");
25553 * Enables this TabPanelItem if it was previously disabled.
25555 enable : function(){
25556 this.disabled = false;
25557 this.pnode.removeClass("disabled");
25561 * Sets the content for this TabPanelItem.
25562 * @param {String} content The content
25563 * @param {Boolean} loadScripts true to look for and load scripts
25565 setContent : function(content, loadScripts){
25566 this.bodyEl.update(content, loadScripts);
25570 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
25571 * @return {Roo.UpdateManager} The UpdateManager
25573 getUpdateManager : function(){
25574 return this.bodyEl.getUpdateManager();
25578 * Set a URL to be used to load the content for this TabPanelItem.
25579 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
25580 * @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)
25581 * @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)
25582 * @return {Roo.UpdateManager} The UpdateManager
25584 setUrl : function(url, params, loadOnce){
25585 if(this.refreshDelegate){
25586 this.un('activate', this.refreshDelegate);
25588 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
25589 this.on("activate", this.refreshDelegate);
25590 return this.bodyEl.getUpdateManager();
25594 _handleRefresh : function(url, params, loadOnce){
25595 if(!loadOnce || !this.loaded){
25596 var updater = this.bodyEl.getUpdateManager();
25597 updater.update(url, params, this._setLoaded.createDelegate(this));
25602 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
25603 * Will fail silently if the setUrl method has not been called.
25604 * This does not activate the panel, just updates its content.
25606 refresh : function(){
25607 if(this.refreshDelegate){
25608 this.loaded = false;
25609 this.refreshDelegate();
25614 _setLoaded : function(){
25615 this.loaded = true;
25619 closeClick : function(e){
25622 this.fireEvent("beforeclose", this, o);
25623 if(o.cancel !== true){
25624 this.tabPanel.removeTab(this.id);
25628 * The text displayed in the tooltip for the close icon.
25631 closeText : "Close this tab"
25635 Roo.TabPanel.prototype.createStrip = function(container){
25636 var strip = document.createElement("div");
25637 strip.className = "x-tabs-wrap";
25638 container.appendChild(strip);
25642 Roo.TabPanel.prototype.createStripList = function(strip){
25643 // div wrapper for retard IE
25644 strip.innerHTML = '<div class="x-tabs-strip-wrap"><table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr></tr></tbody></table></div>';
25645 return strip.firstChild.firstChild.firstChild.firstChild;
25648 Roo.TabPanel.prototype.createBody = function(container){
25649 var body = document.createElement("div");
25650 Roo.id(body, "tab-body");
25651 Roo.fly(body).addClass("x-tabs-body");
25652 container.appendChild(body);
25656 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
25657 var body = Roo.getDom(id);
25659 body = document.createElement("div");
25662 Roo.fly(body).addClass("x-tabs-item-body");
25663 bodyEl.insertBefore(body, bodyEl.firstChild);
25667 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
25668 var td = document.createElement("td");
25669 stripEl.appendChild(td);
25671 td.className = "x-tabs-closable";
25672 if(!this.closeTpl){
25673 this.closeTpl = new Roo.Template(
25674 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
25675 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
25676 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
25679 var el = this.closeTpl.overwrite(td, {"text": text});
25680 var close = el.getElementsByTagName("div")[0];
25681 var inner = el.getElementsByTagName("em")[0];
25682 return {"el": el, "close": close, "inner": inner};
25685 this.tabTpl = new Roo.Template(
25686 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
25687 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
25690 var el = this.tabTpl.overwrite(td, {"text": text});
25691 var inner = el.getElementsByTagName("em")[0];
25692 return {"el": el, "inner": inner};
25696 * Ext JS Library 1.1.1
25697 * Copyright(c) 2006-2007, Ext JS, LLC.
25699 * Originally Released Under LGPL - original licence link has changed is not relivant.
25702 * <script type="text/javascript">
25706 * @class Roo.Button
25707 * @extends Roo.util.Observable
25708 * Simple Button class
25709 * @cfg {String} text The button text
25710 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
25711 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
25712 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
25713 * @cfg {Object} scope The scope of the handler
25714 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
25715 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
25716 * @cfg {Boolean} hidden True to start hidden (defaults to false)
25717 * @cfg {Boolean} disabled True to start disabled (defaults to false)
25718 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
25719 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
25720 applies if enableToggle = true)
25721 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
25722 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
25723 an {@link Roo.util.ClickRepeater} config object (defaults to false).
25725 * Create a new button
25726 * @param {Object} config The config object
25728 Roo.Button = function(renderTo, config)
25732 renderTo = config.renderTo || false;
25735 Roo.apply(this, config);
25739 * Fires when this button is clicked
25740 * @param {Button} this
25741 * @param {EventObject} e The click event
25746 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
25747 * @param {Button} this
25748 * @param {Boolean} pressed
25753 * Fires when the mouse hovers over the button
25754 * @param {Button} this
25755 * @param {Event} e The event object
25757 'mouseover' : true,
25760 * Fires when the mouse exits the button
25761 * @param {Button} this
25762 * @param {Event} e The event object
25767 * Fires when the button is rendered
25768 * @param {Button} this
25773 this.menu = Roo.menu.MenuMgr.get(this.menu);
25776 this.render(renderTo);
25779 Roo.util.Observable.call(this);
25782 Roo.extend(Roo.Button, Roo.util.Observable, {
25788 * Read-only. True if this button is hidden
25793 * Read-only. True if this button is disabled
25798 * Read-only. True if this button is pressed (only if enableToggle = true)
25804 * @cfg {Number} tabIndex
25805 * The DOM tabIndex for this button (defaults to undefined)
25807 tabIndex : undefined,
25810 * @cfg {Boolean} enableToggle
25811 * True to enable pressed/not pressed toggling (defaults to false)
25813 enableToggle: false,
25815 * @cfg {Mixed} menu
25816 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
25820 * @cfg {String} menuAlign
25821 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
25823 menuAlign : "tl-bl?",
25826 * @cfg {String} iconCls
25827 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
25829 iconCls : undefined,
25831 * @cfg {String} type
25832 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
25837 menuClassTarget: 'tr',
25840 * @cfg {String} clickEvent
25841 * The type of event to map to the button's event handler (defaults to 'click')
25843 clickEvent : 'click',
25846 * @cfg {Boolean} handleMouseEvents
25847 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
25849 handleMouseEvents : true,
25852 * @cfg {String} tooltipType
25853 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
25855 tooltipType : 'qtip',
25858 * @cfg {String} cls
25859 * A CSS class to apply to the button's main element.
25863 * @cfg {Roo.Template} template (Optional)
25864 * An {@link Roo.Template} with which to create the Button's main element. This Template must
25865 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
25866 * require code modifications if required elements (e.g. a button) aren't present.
25870 render : function(renderTo){
25872 if(this.hideParent){
25873 this.parentEl = Roo.get(renderTo);
25875 if(!this.dhconfig){
25876 if(!this.template){
25877 if(!Roo.Button.buttonTemplate){
25878 // hideous table template
25879 Roo.Button.buttonTemplate = new Roo.Template(
25880 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
25881 '<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>',
25882 "</tr></tbody></table>");
25884 this.template = Roo.Button.buttonTemplate;
25886 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
25887 var btnEl = btn.child("button:first");
25888 btnEl.on('focus', this.onFocus, this);
25889 btnEl.on('blur', this.onBlur, this);
25891 btn.addClass(this.cls);
25894 btnEl.setStyle('background-image', 'url(' +this.icon +')');
25897 btnEl.addClass(this.iconCls);
25899 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
25902 if(this.tabIndex !== undefined){
25903 btnEl.dom.tabIndex = this.tabIndex;
25906 if(typeof this.tooltip == 'object'){
25907 Roo.QuickTips.tips(Roo.apply({
25911 btnEl.dom[this.tooltipType] = this.tooltip;
25915 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
25919 this.el.dom.id = this.el.id = this.id;
25922 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
25923 this.menu.on("show", this.onMenuShow, this);
25924 this.menu.on("hide", this.onMenuHide, this);
25926 btn.addClass("x-btn");
25927 if(Roo.isIE && !Roo.isIE7){
25928 this.autoWidth.defer(1, this);
25932 if(this.handleMouseEvents){
25933 btn.on("mouseover", this.onMouseOver, this);
25934 btn.on("mouseout", this.onMouseOut, this);
25935 btn.on("mousedown", this.onMouseDown, this);
25937 btn.on(this.clickEvent, this.onClick, this);
25938 //btn.on("mouseup", this.onMouseUp, this);
25945 Roo.ButtonToggleMgr.register(this);
25947 this.el.addClass("x-btn-pressed");
25950 var repeater = new Roo.util.ClickRepeater(btn,
25951 typeof this.repeat == "object" ? this.repeat : {}
25953 repeater.on("click", this.onClick, this);
25955 this.fireEvent('render', this);
25959 * Returns the button's underlying element
25960 * @return {Roo.Element} The element
25962 getEl : function(){
25967 * Destroys this Button and removes any listeners.
25969 destroy : function(){
25970 Roo.ButtonToggleMgr.unregister(this);
25971 this.el.removeAllListeners();
25972 this.purgeListeners();
25977 autoWidth : function(){
25979 this.el.setWidth("auto");
25980 if(Roo.isIE7 && Roo.isStrict){
25981 var ib = this.el.child('button');
25982 if(ib && ib.getWidth() > 20){
25984 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
25989 this.el.beginMeasure();
25991 if(this.el.getWidth() < this.minWidth){
25992 this.el.setWidth(this.minWidth);
25995 this.el.endMeasure();
26002 * Assigns this button's click handler
26003 * @param {Function} handler The function to call when the button is clicked
26004 * @param {Object} scope (optional) Scope for the function passed in
26006 setHandler : function(handler, scope){
26007 this.handler = handler;
26008 this.scope = scope;
26012 * Sets this button's text
26013 * @param {String} text The button text
26015 setText : function(text){
26018 this.el.child("td.x-btn-center button.x-btn-text").update(text);
26024 * Gets the text for this button
26025 * @return {String} The button text
26027 getText : function(){
26035 this.hidden = false;
26037 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
26045 this.hidden = true;
26047 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
26052 * Convenience function for boolean show/hide
26053 * @param {Boolean} visible True to show, false to hide
26055 setVisible: function(visible){
26064 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
26065 * @param {Boolean} state (optional) Force a particular state
26067 toggle : function(state){
26068 state = state === undefined ? !this.pressed : state;
26069 if(state != this.pressed){
26071 this.el.addClass("x-btn-pressed");
26072 this.pressed = true;
26073 this.fireEvent("toggle", this, true);
26075 this.el.removeClass("x-btn-pressed");
26076 this.pressed = false;
26077 this.fireEvent("toggle", this, false);
26079 if(this.toggleHandler){
26080 this.toggleHandler.call(this.scope || this, this, state);
26088 focus : function(){
26089 this.el.child('button:first').focus();
26093 * Disable this button
26095 disable : function(){
26097 this.el.addClass("x-btn-disabled");
26099 this.disabled = true;
26103 * Enable this button
26105 enable : function(){
26107 this.el.removeClass("x-btn-disabled");
26109 this.disabled = false;
26113 * Convenience function for boolean enable/disable
26114 * @param {Boolean} enabled True to enable, false to disable
26116 setDisabled : function(v){
26117 this[v !== true ? "enable" : "disable"]();
26121 onClick : function(e){
26123 e.preventDefault();
26128 if(!this.disabled){
26129 if(this.enableToggle){
26132 if(this.menu && !this.menu.isVisible()){
26133 this.menu.show(this.el, this.menuAlign);
26135 this.fireEvent("click", this, e);
26137 this.el.removeClass("x-btn-over");
26138 this.handler.call(this.scope || this, this, e);
26143 onMouseOver : function(e){
26144 if(!this.disabled){
26145 this.el.addClass("x-btn-over");
26146 this.fireEvent('mouseover', this, e);
26150 onMouseOut : function(e){
26151 if(!e.within(this.el, true)){
26152 this.el.removeClass("x-btn-over");
26153 this.fireEvent('mouseout', this, e);
26157 onFocus : function(e){
26158 if(!this.disabled){
26159 this.el.addClass("x-btn-focus");
26163 onBlur : function(e){
26164 this.el.removeClass("x-btn-focus");
26167 onMouseDown : function(e){
26168 if(!this.disabled && e.button == 0){
26169 this.el.addClass("x-btn-click");
26170 Roo.get(document).on('mouseup', this.onMouseUp, this);
26174 onMouseUp : function(e){
26176 this.el.removeClass("x-btn-click");
26177 Roo.get(document).un('mouseup', this.onMouseUp, this);
26181 onMenuShow : function(e){
26182 this.el.addClass("x-btn-menu-active");
26185 onMenuHide : function(e){
26186 this.el.removeClass("x-btn-menu-active");
26190 // Private utility class used by Button
26191 Roo.ButtonToggleMgr = function(){
26194 function toggleGroup(btn, state){
26196 var g = groups[btn.toggleGroup];
26197 for(var i = 0, l = g.length; i < l; i++){
26199 g[i].toggle(false);
26206 register : function(btn){
26207 if(!btn.toggleGroup){
26210 var g = groups[btn.toggleGroup];
26212 g = groups[btn.toggleGroup] = [];
26215 btn.on("toggle", toggleGroup);
26218 unregister : function(btn){
26219 if(!btn.toggleGroup){
26222 var g = groups[btn.toggleGroup];
26225 btn.un("toggle", toggleGroup);
26231 * Ext JS Library 1.1.1
26232 * Copyright(c) 2006-2007, Ext JS, LLC.
26234 * Originally Released Under LGPL - original licence link has changed is not relivant.
26237 * <script type="text/javascript">
26241 * @class Roo.SplitButton
26242 * @extends Roo.Button
26243 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
26244 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
26245 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
26246 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
26247 * @cfg {String} arrowTooltip The title attribute of the arrow
26249 * Create a new menu button
26250 * @param {String/HTMLElement/Element} renderTo The element to append the button to
26251 * @param {Object} config The config object
26253 Roo.SplitButton = function(renderTo, config){
26254 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
26256 * @event arrowclick
26257 * Fires when this button's arrow is clicked
26258 * @param {SplitButton} this
26259 * @param {EventObject} e The click event
26261 this.addEvents({"arrowclick":true});
26264 Roo.extend(Roo.SplitButton, Roo.Button, {
26265 render : function(renderTo){
26266 // this is one sweet looking template!
26267 var tpl = new Roo.Template(
26268 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
26269 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
26270 '<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>',
26271 "</tbody></table></td><td>",
26272 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
26273 '<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>',
26274 "</tbody></table></td></tr></table>"
26276 var btn = tpl.append(renderTo, [this.text, this.type], true);
26277 var btnEl = btn.child("button");
26279 btn.addClass(this.cls);
26282 btnEl.setStyle('background-image', 'url(' +this.icon +')');
26285 btnEl.addClass(this.iconCls);
26287 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
26291 if(this.handleMouseEvents){
26292 btn.on("mouseover", this.onMouseOver, this);
26293 btn.on("mouseout", this.onMouseOut, this);
26294 btn.on("mousedown", this.onMouseDown, this);
26295 btn.on("mouseup", this.onMouseUp, this);
26297 btn.on(this.clickEvent, this.onClick, this);
26299 if(typeof this.tooltip == 'object'){
26300 Roo.QuickTips.tips(Roo.apply({
26304 btnEl.dom[this.tooltipType] = this.tooltip;
26307 if(this.arrowTooltip){
26308 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
26317 this.el.addClass("x-btn-pressed");
26319 if(Roo.isIE && !Roo.isIE7){
26320 this.autoWidth.defer(1, this);
26325 this.menu.on("show", this.onMenuShow, this);
26326 this.menu.on("hide", this.onMenuHide, this);
26328 this.fireEvent('render', this);
26332 autoWidth : function(){
26334 var tbl = this.el.child("table:first");
26335 var tbl2 = this.el.child("table:last");
26336 this.el.setWidth("auto");
26337 tbl.setWidth("auto");
26338 if(Roo.isIE7 && Roo.isStrict){
26339 var ib = this.el.child('button:first');
26340 if(ib && ib.getWidth() > 20){
26342 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
26347 this.el.beginMeasure();
26349 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
26350 tbl.setWidth(this.minWidth-tbl2.getWidth());
26353 this.el.endMeasure();
26356 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
26360 * Sets this button's click handler
26361 * @param {Function} handler The function to call when the button is clicked
26362 * @param {Object} scope (optional) Scope for the function passed above
26364 setHandler : function(handler, scope){
26365 this.handler = handler;
26366 this.scope = scope;
26370 * Sets this button's arrow click handler
26371 * @param {Function} handler The function to call when the arrow is clicked
26372 * @param {Object} scope (optional) Scope for the function passed above
26374 setArrowHandler : function(handler, scope){
26375 this.arrowHandler = handler;
26376 this.scope = scope;
26382 focus : function(){
26384 this.el.child("button:first").focus();
26389 onClick : function(e){
26390 e.preventDefault();
26391 if(!this.disabled){
26392 if(e.getTarget(".x-btn-menu-arrow-wrap")){
26393 if(this.menu && !this.menu.isVisible()){
26394 this.menu.show(this.el, this.menuAlign);
26396 this.fireEvent("arrowclick", this, e);
26397 if(this.arrowHandler){
26398 this.arrowHandler.call(this.scope || this, this, e);
26401 this.fireEvent("click", this, e);
26403 this.handler.call(this.scope || this, this, e);
26409 onMouseDown : function(e){
26410 if(!this.disabled){
26411 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
26415 onMouseUp : function(e){
26416 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
26421 // backwards compat
26422 Roo.MenuButton = Roo.SplitButton;/*
26424 * Ext JS Library 1.1.1
26425 * Copyright(c) 2006-2007, Ext JS, LLC.
26427 * Originally Released Under LGPL - original licence link has changed is not relivant.
26430 * <script type="text/javascript">
26434 * @class Roo.Toolbar
26435 * Basic Toolbar class.
26437 * Creates a new Toolbar
26438 * @param {Object} config The config object
26440 Roo.Toolbar = function(container, buttons, config)
26442 /// old consturctor format still supported..
26443 if(container instanceof Array){ // omit the container for later rendering
26444 buttons = container;
26448 if (typeof(container) == 'object' && container.xtype) {
26449 config = container;
26450 container = config.container;
26451 buttons = config.buttons; // not really - use items!!
26454 if (config && config.items) {
26455 xitems = config.items;
26456 delete config.items;
26458 Roo.apply(this, config);
26459 this.buttons = buttons;
26462 this.render(container);
26464 Roo.each(xitems, function(b) {
26470 Roo.Toolbar.prototype = {
26472 * @cfg {Roo.data.Store} items
26473 * array of button configs or elements to add
26477 * @cfg {String/HTMLElement/Element} container
26478 * The id or element that will contain the toolbar
26481 render : function(ct){
26482 this.el = Roo.get(ct);
26484 this.el.addClass(this.cls);
26486 // using a table allows for vertical alignment
26487 // 100% width is needed by Safari...
26488 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
26489 this.tr = this.el.child("tr", true);
26491 this.items = new Roo.util.MixedCollection(false, function(o){
26492 return o.id || ("item" + (++autoId));
26495 this.add.apply(this, this.buttons);
26496 delete this.buttons;
26501 * Adds element(s) to the toolbar -- this function takes a variable number of
26502 * arguments of mixed type and adds them to the toolbar.
26503 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
26505 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
26506 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
26507 * <li>Field: Any form field (equivalent to {@link #addField})</li>
26508 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
26509 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
26510 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
26511 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
26512 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
26513 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
26515 * @param {Mixed} arg2
26516 * @param {Mixed} etc.
26519 var a = arguments, l = a.length;
26520 for(var i = 0; i < l; i++){
26525 _add : function(el) {
26528 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
26531 if (el.applyTo){ // some kind of form field
26532 return this.addField(el);
26534 if (el.render){ // some kind of Toolbar.Item
26535 return this.addItem(el);
26537 if (typeof el == "string"){ // string
26538 if(el == "separator" || el == "-"){
26539 return this.addSeparator();
26542 return this.addSpacer();
26545 return this.addFill();
26547 return this.addText(el);
26550 if(el.tagName){ // element
26551 return this.addElement(el);
26553 if(typeof el == "object"){ // must be button config?
26554 return this.addButton(el);
26556 // and now what?!?!
26562 * Add an Xtype element
26563 * @param {Object} xtype Xtype Object
26564 * @return {Object} created Object
26566 addxtype : function(e){
26567 return this.add(e);
26571 * Returns the Element for this toolbar.
26572 * @return {Roo.Element}
26574 getEl : function(){
26580 * @return {Roo.Toolbar.Item} The separator item
26582 addSeparator : function(){
26583 return this.addItem(new Roo.Toolbar.Separator());
26587 * Adds a spacer element
26588 * @return {Roo.Toolbar.Spacer} The spacer item
26590 addSpacer : function(){
26591 return this.addItem(new Roo.Toolbar.Spacer());
26595 * Adds a fill element that forces subsequent additions to the right side of the toolbar
26596 * @return {Roo.Toolbar.Fill} The fill item
26598 addFill : function(){
26599 return this.addItem(new Roo.Toolbar.Fill());
26603 * Adds any standard HTML element to the toolbar
26604 * @param {String/HTMLElement/Element} el The element or id of the element to add
26605 * @return {Roo.Toolbar.Item} The element's item
26607 addElement : function(el){
26608 return this.addItem(new Roo.Toolbar.Item(el));
26611 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
26612 * @type Roo.util.MixedCollection
26617 * Adds any Toolbar.Item or subclass
26618 * @param {Roo.Toolbar.Item} item
26619 * @return {Roo.Toolbar.Item} The item
26621 addItem : function(item){
26622 var td = this.nextBlock();
26624 this.items.add(item);
26629 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
26630 * @param {Object/Array} config A button config or array of configs
26631 * @return {Roo.Toolbar.Button/Array}
26633 addButton : function(config){
26634 if(config instanceof Array){
26636 for(var i = 0, len = config.length; i < len; i++) {
26637 buttons.push(this.addButton(config[i]));
26642 if(!(config instanceof Roo.Toolbar.Button)){
26644 new Roo.Toolbar.SplitButton(config) :
26645 new Roo.Toolbar.Button(config);
26647 var td = this.nextBlock();
26654 * Adds text to the toolbar
26655 * @param {String} text The text to add
26656 * @return {Roo.Toolbar.Item} The element's item
26658 addText : function(text){
26659 return this.addItem(new Roo.Toolbar.TextItem(text));
26663 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
26664 * @param {Number} index The index where the item is to be inserted
26665 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
26666 * @return {Roo.Toolbar.Button/Item}
26668 insertButton : function(index, item){
26669 if(item instanceof Array){
26671 for(var i = 0, len = item.length; i < len; i++) {
26672 buttons.push(this.insertButton(index + i, item[i]));
26676 if (!(item instanceof Roo.Toolbar.Button)){
26677 item = new Roo.Toolbar.Button(item);
26679 var td = document.createElement("td");
26680 this.tr.insertBefore(td, this.tr.childNodes[index]);
26682 this.items.insert(index, item);
26687 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
26688 * @param {Object} config
26689 * @return {Roo.Toolbar.Item} The element's item
26691 addDom : function(config, returnEl){
26692 var td = this.nextBlock();
26693 Roo.DomHelper.overwrite(td, config);
26694 var ti = new Roo.Toolbar.Item(td.firstChild);
26696 this.items.add(ti);
26701 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
26702 * @type Roo.util.MixedCollection
26707 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc). Note: the field should not have
26708 * been rendered yet. For a field that has already been rendered, use {@link #addElement}.
26709 * @param {Roo.form.Field} field
26710 * @return {Roo.ToolbarItem}
26714 addField : function(field) {
26715 if (!this.fields) {
26717 this.fields = new Roo.util.MixedCollection(false, function(o){
26718 return o.id || ("item" + (++autoId));
26723 var td = this.nextBlock();
26725 var ti = new Roo.Toolbar.Item(td.firstChild);
26727 this.items.add(ti);
26728 this.fields.add(field);
26739 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
26740 this.el.child('div').hide();
26748 this.el.child('div').show();
26752 nextBlock : function(){
26753 var td = document.createElement("td");
26754 this.tr.appendChild(td);
26759 destroy : function(){
26760 if(this.items){ // rendered?
26761 Roo.destroy.apply(Roo, this.items.items);
26763 if(this.fields){ // rendered?
26764 Roo.destroy.apply(Roo, this.fields.items);
26766 Roo.Element.uncache(this.el, this.tr);
26771 * @class Roo.Toolbar.Item
26772 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
26774 * Creates a new Item
26775 * @param {HTMLElement} el
26777 Roo.Toolbar.Item = function(el){
26778 this.el = Roo.getDom(el);
26779 this.id = Roo.id(this.el);
26780 this.hidden = false;
26783 Roo.Toolbar.Item.prototype = {
26786 * Get this item's HTML Element
26787 * @return {HTMLElement}
26789 getEl : function(){
26794 render : function(td){
26796 td.appendChild(this.el);
26800 * Removes and destroys this item.
26802 destroy : function(){
26803 this.td.parentNode.removeChild(this.td);
26810 this.hidden = false;
26811 this.td.style.display = "";
26818 this.hidden = true;
26819 this.td.style.display = "none";
26823 * Convenience function for boolean show/hide.
26824 * @param {Boolean} visible true to show/false to hide
26826 setVisible: function(visible){
26835 * Try to focus this item.
26837 focus : function(){
26838 Roo.fly(this.el).focus();
26842 * Disables this item.
26844 disable : function(){
26845 Roo.fly(this.td).addClass("x-item-disabled");
26846 this.disabled = true;
26847 this.el.disabled = true;
26851 * Enables this item.
26853 enable : function(){
26854 Roo.fly(this.td).removeClass("x-item-disabled");
26855 this.disabled = false;
26856 this.el.disabled = false;
26862 * @class Roo.Toolbar.Separator
26863 * @extends Roo.Toolbar.Item
26864 * A simple toolbar separator class
26866 * Creates a new Separator
26868 Roo.Toolbar.Separator = function(){
26869 var s = document.createElement("span");
26870 s.className = "ytb-sep";
26871 Roo.Toolbar.Separator.superclass.constructor.call(this, s);
26873 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
26874 enable:Roo.emptyFn,
26875 disable:Roo.emptyFn,
26880 * @class Roo.Toolbar.Spacer
26881 * @extends Roo.Toolbar.Item
26882 * A simple element that adds extra horizontal space to a toolbar.
26884 * Creates a new Spacer
26886 Roo.Toolbar.Spacer = function(){
26887 var s = document.createElement("div");
26888 s.className = "ytb-spacer";
26889 Roo.Toolbar.Spacer.superclass.constructor.call(this, s);
26891 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
26892 enable:Roo.emptyFn,
26893 disable:Roo.emptyFn,
26898 * @class Roo.Toolbar.Fill
26899 * @extends Roo.Toolbar.Spacer
26900 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
26902 * Creates a new Spacer
26904 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
26906 render : function(td){
26907 td.style.width = '100%';
26908 Roo.Toolbar.Fill.superclass.render.call(this, td);
26913 * @class Roo.Toolbar.TextItem
26914 * @extends Roo.Toolbar.Item
26915 * A simple class that renders text directly into a toolbar.
26917 * Creates a new TextItem
26918 * @param {String} text
26920 Roo.Toolbar.TextItem = function(text){
26921 if (typeof(text) == 'object') {
26924 var s = document.createElement("span");
26925 s.className = "ytb-text";
26926 s.innerHTML = text;
26927 Roo.Toolbar.TextItem.superclass.constructor.call(this, s);
26929 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
26930 enable:Roo.emptyFn,
26931 disable:Roo.emptyFn,
26936 * @class Roo.Toolbar.Button
26937 * @extends Roo.Button
26938 * A button that renders into a toolbar.
26940 * Creates a new Button
26941 * @param {Object} config A standard {@link Roo.Button} config object
26943 Roo.Toolbar.Button = function(config){
26944 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
26946 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
26947 render : function(td){
26949 Roo.Toolbar.Button.superclass.render.call(this, td);
26953 * Removes and destroys this button
26955 destroy : function(){
26956 Roo.Toolbar.Button.superclass.destroy.call(this);
26957 this.td.parentNode.removeChild(this.td);
26961 * Shows this button
26964 this.hidden = false;
26965 this.td.style.display = "";
26969 * Hides this button
26972 this.hidden = true;
26973 this.td.style.display = "none";
26977 * Disables this item
26979 disable : function(){
26980 Roo.fly(this.td).addClass("x-item-disabled");
26981 this.disabled = true;
26985 * Enables this item
26987 enable : function(){
26988 Roo.fly(this.td).removeClass("x-item-disabled");
26989 this.disabled = false;
26992 // backwards compat
26993 Roo.ToolbarButton = Roo.Toolbar.Button;
26996 * @class Roo.Toolbar.SplitButton
26997 * @extends Roo.SplitButton
26998 * A menu button that renders into a toolbar.
27000 * Creates a new SplitButton
27001 * @param {Object} config A standard {@link Roo.SplitButton} config object
27003 Roo.Toolbar.SplitButton = function(config){
27004 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
27006 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
27007 render : function(td){
27009 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
27013 * Removes and destroys this button
27015 destroy : function(){
27016 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
27017 this.td.parentNode.removeChild(this.td);
27021 * Shows this button
27024 this.hidden = false;
27025 this.td.style.display = "";
27029 * Hides this button
27032 this.hidden = true;
27033 this.td.style.display = "none";
27037 // backwards compat
27038 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
27040 * Ext JS Library 1.1.1
27041 * Copyright(c) 2006-2007, Ext JS, LLC.
27043 * Originally Released Under LGPL - original licence link has changed is not relivant.
27046 * <script type="text/javascript">
27050 * @class Roo.PagingToolbar
27051 * @extends Roo.Toolbar
27052 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
27054 * Create a new PagingToolbar
27055 * @param {Object} config The config object
27057 Roo.PagingToolbar = function(el, ds, config)
27059 // old args format still supported... - xtype is prefered..
27060 if (typeof(el) == 'object' && el.xtype) {
27061 // created from xtype...
27063 ds = el.dataSource;
27064 el = config.container;
27068 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
27071 this.renderButtons(this.el);
27075 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
27077 * @cfg {Roo.data.Store} dataSource
27078 * The underlying data store providing the paged data
27081 * @cfg {String/HTMLElement/Element} container
27082 * container The id or element that will contain the toolbar
27085 * @cfg {Boolean} displayInfo
27086 * True to display the displayMsg (defaults to false)
27089 * @cfg {Number} pageSize
27090 * The number of records to display per page (defaults to 20)
27094 * @cfg {String} displayMsg
27095 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
27097 displayMsg : 'Displaying {0} - {1} of {2}',
27099 * @cfg {String} emptyMsg
27100 * The message to display when no records are found (defaults to "No data to display")
27102 emptyMsg : 'No data to display',
27104 * Customizable piece of the default paging text (defaults to "Page")
27107 beforePageText : "Page",
27109 * Customizable piece of the default paging text (defaults to "of %0")
27112 afterPageText : "of {0}",
27114 * Customizable piece of the default paging text (defaults to "First Page")
27117 firstText : "First Page",
27119 * Customizable piece of the default paging text (defaults to "Previous Page")
27122 prevText : "Previous Page",
27124 * Customizable piece of the default paging text (defaults to "Next Page")
27127 nextText : "Next Page",
27129 * Customizable piece of the default paging text (defaults to "Last Page")
27132 lastText : "Last Page",
27134 * Customizable piece of the default paging text (defaults to "Refresh")
27137 refreshText : "Refresh",
27140 renderButtons : function(el){
27141 Roo.PagingToolbar.superclass.render.call(this, el);
27142 this.first = this.addButton({
27143 tooltip: this.firstText,
27144 cls: "x-btn-icon x-grid-page-first",
27146 handler: this.onClick.createDelegate(this, ["first"])
27148 this.prev = this.addButton({
27149 tooltip: this.prevText,
27150 cls: "x-btn-icon x-grid-page-prev",
27152 handler: this.onClick.createDelegate(this, ["prev"])
27154 this.addSeparator();
27155 this.add(this.beforePageText);
27156 this.field = Roo.get(this.addDom({
27161 cls: "x-grid-page-number"
27163 this.field.on("keydown", this.onPagingKeydown, this);
27164 this.field.on("focus", function(){this.dom.select();});
27165 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
27166 this.field.setHeight(18);
27167 this.addSeparator();
27168 this.next = this.addButton({
27169 tooltip: this.nextText,
27170 cls: "x-btn-icon x-grid-page-next",
27172 handler: this.onClick.createDelegate(this, ["next"])
27174 this.last = this.addButton({
27175 tooltip: this.lastText,
27176 cls: "x-btn-icon x-grid-page-last",
27178 handler: this.onClick.createDelegate(this, ["last"])
27180 this.addSeparator();
27181 this.loading = this.addButton({
27182 tooltip: this.refreshText,
27183 cls: "x-btn-icon x-grid-loading",
27184 handler: this.onClick.createDelegate(this, ["refresh"])
27187 if(this.displayInfo){
27188 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
27193 updateInfo : function(){
27194 if(this.displayEl){
27195 var count = this.ds.getCount();
27196 var msg = count == 0 ?
27200 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
27202 this.displayEl.update(msg);
27207 onLoad : function(ds, r, o){
27208 this.cursor = o.params ? o.params.start : 0;
27209 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
27211 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
27212 this.field.dom.value = ap;
27213 this.first.setDisabled(ap == 1);
27214 this.prev.setDisabled(ap == 1);
27215 this.next.setDisabled(ap == ps);
27216 this.last.setDisabled(ap == ps);
27217 this.loading.enable();
27222 getPageData : function(){
27223 var total = this.ds.getTotalCount();
27226 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
27227 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
27232 onLoadError : function(){
27233 this.loading.enable();
27237 onPagingKeydown : function(e){
27238 var k = e.getKey();
27239 var d = this.getPageData();
27241 var v = this.field.dom.value, pageNum;
27242 if(!v || isNaN(pageNum = parseInt(v, 10))){
27243 this.field.dom.value = d.activePage;
27246 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
27247 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
27250 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))
27252 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
27253 this.field.dom.value = pageNum;
27254 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
27257 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
27259 var v = this.field.dom.value, pageNum;
27260 var increment = (e.shiftKey) ? 10 : 1;
27261 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
27263 if(!v || isNaN(pageNum = parseInt(v, 10))) {
27264 this.field.dom.value = d.activePage;
27267 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
27269 this.field.dom.value = parseInt(v, 10) + increment;
27270 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
27271 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
27278 beforeLoad : function(){
27280 this.loading.disable();
27285 onClick : function(which){
27289 ds.load({params:{start: 0, limit: this.pageSize}});
27292 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
27295 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
27298 var total = ds.getTotalCount();
27299 var extra = total % this.pageSize;
27300 var lastStart = extra ? (total - extra) : total-this.pageSize;
27301 ds.load({params:{start: lastStart, limit: this.pageSize}});
27304 ds.load({params:{start: this.cursor, limit: this.pageSize}});
27310 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
27311 * @param {Roo.data.Store} store The data store to unbind
27313 unbind : function(ds){
27314 ds.un("beforeload", this.beforeLoad, this);
27315 ds.un("load", this.onLoad, this);
27316 ds.un("loadexception", this.onLoadError, this);
27317 ds.un("remove", this.updateInfo, this);
27318 ds.un("add", this.updateInfo, this);
27319 this.ds = undefined;
27323 * Binds the paging toolbar to the specified {@link Roo.data.Store}
27324 * @param {Roo.data.Store} store The data store to bind
27326 bind : function(ds){
27327 ds.on("beforeload", this.beforeLoad, this);
27328 ds.on("load", this.onLoad, this);
27329 ds.on("loadexception", this.onLoadError, this);
27330 ds.on("remove", this.updateInfo, this);
27331 ds.on("add", this.updateInfo, this);
27336 * Ext JS Library 1.1.1
27337 * Copyright(c) 2006-2007, Ext JS, LLC.
27339 * Originally Released Under LGPL - original licence link has changed is not relivant.
27342 * <script type="text/javascript">
27346 * @class Roo.Resizable
27347 * @extends Roo.util.Observable
27348 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
27349 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
27350 * 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
27351 * the element will be wrapped for you automatically.</p>
27352 * <p>Here is the list of valid resize handles:</p>
27355 ------ -------------------
27366 * <p>Here's an example showing the creation of a typical Resizable:</p>
27368 var resizer = new Roo.Resizable("element-id", {
27376 resizer.on("resize", myHandler);
27378 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
27379 * resizer.east.setDisplayed(false);</p>
27380 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
27381 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
27382 * resize operation's new size (defaults to [0, 0])
27383 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
27384 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
27385 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
27386 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
27387 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
27388 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
27389 * @cfg {Number} width The width of the element in pixels (defaults to null)
27390 * @cfg {Number} height The height of the element in pixels (defaults to null)
27391 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
27392 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
27393 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
27394 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
27395 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
27396 * in favor of the handles config option (defaults to false)
27397 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
27398 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
27399 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
27400 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
27401 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
27402 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
27403 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
27404 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
27405 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
27406 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
27407 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
27409 * Create a new resizable component
27410 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
27411 * @param {Object} config configuration options
27413 Roo.Resizable = function(el, config){
27414 this.el = Roo.get(el);
27416 if(config && config.wrap){
27417 config.resizeChild = this.el;
27418 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
27419 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
27420 this.el.setStyle("overflow", "hidden");
27421 this.el.setPositioning(config.resizeChild.getPositioning());
27422 config.resizeChild.clearPositioning();
27423 if(!config.width || !config.height){
27424 var csize = config.resizeChild.getSize();
27425 this.el.setSize(csize.width, csize.height);
27427 if(config.pinned && !config.adjustments){
27428 config.adjustments = "auto";
27432 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
27433 this.proxy.unselectable();
27434 this.proxy.enableDisplayMode('block');
27436 Roo.apply(this, config);
27439 this.disableTrackOver = true;
27440 this.el.addClass("x-resizable-pinned");
27442 // if the element isn't positioned, make it relative
27443 var position = this.el.getStyle("position");
27444 if(position != "absolute" && position != "fixed"){
27445 this.el.setStyle("position", "relative");
27447 if(!this.handles){ // no handles passed, must be legacy style
27448 this.handles = 's,e,se';
27449 if(this.multiDirectional){
27450 this.handles += ',n,w';
27453 if(this.handles == "all"){
27454 this.handles = "n s e w ne nw se sw";
27456 var hs = this.handles.split(/\s*?[,;]\s*?| /);
27457 var ps = Roo.Resizable.positions;
27458 for(var i = 0, len = hs.length; i < len; i++){
27459 if(hs[i] && ps[hs[i]]){
27460 var pos = ps[hs[i]];
27461 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
27465 this.corner = this.southeast;
27467 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1){
27468 this.updateBox = true;
27471 this.activeHandle = null;
27473 if(this.resizeChild){
27474 if(typeof this.resizeChild == "boolean"){
27475 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
27477 this.resizeChild = Roo.get(this.resizeChild, true);
27481 if(this.adjustments == "auto"){
27482 var rc = this.resizeChild;
27483 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
27484 if(rc && (hw || hn)){
27485 rc.position("relative");
27486 rc.setLeft(hw ? hw.el.getWidth() : 0);
27487 rc.setTop(hn ? hn.el.getHeight() : 0);
27489 this.adjustments = [
27490 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
27491 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
27495 if(this.draggable){
27496 this.dd = this.dynamic ?
27497 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
27498 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
27504 * @event beforeresize
27505 * Fired before resize is allowed. Set enabled to false to cancel resize.
27506 * @param {Roo.Resizable} this
27507 * @param {Roo.EventObject} e The mousedown event
27509 "beforeresize" : true,
27512 * Fired after a resize.
27513 * @param {Roo.Resizable} this
27514 * @param {Number} width The new width
27515 * @param {Number} height The new height
27516 * @param {Roo.EventObject} e The mouseup event
27521 if(this.width !== null && this.height !== null){
27522 this.resizeTo(this.width, this.height);
27524 this.updateChildSize();
27527 this.el.dom.style.zoom = 1;
27529 Roo.Resizable.superclass.constructor.call(this);
27532 Roo.extend(Roo.Resizable, Roo.util.Observable, {
27533 resizeChild : false,
27534 adjustments : [0, 0],
27544 multiDirectional : false,
27545 disableTrackOver : false,
27546 easing : 'easeOutStrong',
27547 widthIncrement : 0,
27548 heightIncrement : 0,
27552 preserveRatio : false,
27553 transparent: false,
27559 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
27561 constrainTo: undefined,
27563 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
27565 resizeRegion: undefined,
27569 * Perform a manual resize
27570 * @param {Number} width
27571 * @param {Number} height
27573 resizeTo : function(width, height){
27574 this.el.setSize(width, height);
27575 this.updateChildSize();
27576 this.fireEvent("resize", this, width, height, null);
27580 startSizing : function(e, handle){
27581 this.fireEvent("beforeresize", this, e);
27582 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
27585 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
27586 this.overlay.unselectable();
27587 this.overlay.enableDisplayMode("block");
27588 this.overlay.on("mousemove", this.onMouseMove, this);
27589 this.overlay.on("mouseup", this.onMouseUp, this);
27591 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
27593 this.resizing = true;
27594 this.startBox = this.el.getBox();
27595 this.startPoint = e.getXY();
27596 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
27597 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
27599 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
27600 this.overlay.show();
27602 if(this.constrainTo) {
27603 var ct = Roo.get(this.constrainTo);
27604 this.resizeRegion = ct.getRegion().adjust(
27605 ct.getFrameWidth('t'),
27606 ct.getFrameWidth('l'),
27607 -ct.getFrameWidth('b'),
27608 -ct.getFrameWidth('r')
27612 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
27614 this.proxy.setBox(this.startBox);
27616 this.proxy.setStyle('visibility', 'visible');
27622 onMouseDown : function(handle, e){
27625 this.activeHandle = handle;
27626 this.startSizing(e, handle);
27631 onMouseUp : function(e){
27632 var size = this.resizeElement();
27633 this.resizing = false;
27635 this.overlay.hide();
27637 this.fireEvent("resize", this, size.width, size.height, e);
27641 updateChildSize : function(){
27642 if(this.resizeChild){
27644 var child = this.resizeChild;
27645 var adj = this.adjustments;
27646 if(el.dom.offsetWidth){
27647 var b = el.getSize(true);
27648 child.setSize(b.width+adj[0], b.height+adj[1]);
27650 // Second call here for IE
27651 // The first call enables instant resizing and
27652 // the second call corrects scroll bars if they
27655 setTimeout(function(){
27656 if(el.dom.offsetWidth){
27657 var b = el.getSize(true);
27658 child.setSize(b.width+adj[0], b.height+adj[1]);
27666 snap : function(value, inc, min){
27667 if(!inc || !value) return value;
27668 var newValue = value;
27669 var m = value % inc;
27672 newValue = value + (inc-m);
27674 newValue = value - m;
27677 return Math.max(min, newValue);
27681 resizeElement : function(){
27682 var box = this.proxy.getBox();
27683 if(this.updateBox){
27684 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
27686 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
27688 this.updateChildSize();
27696 constrain : function(v, diff, m, mx){
27699 }else if(v - diff > mx){
27706 onMouseMove : function(e){
27708 try{// try catch so if something goes wrong the user doesn't get hung
27710 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
27714 //var curXY = this.startPoint;
27715 var curSize = this.curSize || this.startBox;
27716 var x = this.startBox.x, y = this.startBox.y;
27717 var ox = x, oy = y;
27718 var w = curSize.width, h = curSize.height;
27719 var ow = w, oh = h;
27720 var mw = this.minWidth, mh = this.minHeight;
27721 var mxw = this.maxWidth, mxh = this.maxHeight;
27722 var wi = this.widthIncrement;
27723 var hi = this.heightIncrement;
27725 var eventXY = e.getXY();
27726 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
27727 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
27729 var pos = this.activeHandle.position;
27734 w = Math.min(Math.max(mw, w), mxw);
27738 h = Math.min(Math.max(mh, h), mxh);
27743 w = Math.min(Math.max(mw, w), mxw);
27744 h = Math.min(Math.max(mh, h), mxh);
27747 diffY = this.constrain(h, diffY, mh, mxh);
27752 diffX = this.constrain(w, diffX, mw, mxw);
27758 w = Math.min(Math.max(mw, w), mxw);
27759 diffY = this.constrain(h, diffY, mh, mxh);
27764 diffX = this.constrain(w, diffX, mw, mxw);
27765 diffY = this.constrain(h, diffY, mh, mxh);
27772 diffX = this.constrain(w, diffX, mw, mxw);
27774 h = Math.min(Math.max(mh, h), mxh);
27780 var sw = this.snap(w, wi, mw);
27781 var sh = this.snap(h, hi, mh);
27782 if(sw != w || sh != h){
27805 if(this.preserveRatio){
27810 h = Math.min(Math.max(mh, h), mxh);
27815 w = Math.min(Math.max(mw, w), mxw);
27820 w = Math.min(Math.max(mw, w), mxw);
27826 w = Math.min(Math.max(mw, w), mxw);
27832 h = Math.min(Math.max(mh, h), mxh);
27840 h = Math.min(Math.max(mh, h), mxh);
27850 h = Math.min(Math.max(mh, h), mxh);
27858 this.proxy.setBounds(x, y, w, h);
27860 this.resizeElement();
27867 handleOver : function(){
27869 this.el.addClass("x-resizable-over");
27874 handleOut : function(){
27875 if(!this.resizing){
27876 this.el.removeClass("x-resizable-over");
27881 * Returns the element this component is bound to.
27882 * @return {Roo.Element}
27884 getEl : function(){
27889 * Returns the resizeChild element (or null).
27890 * @return {Roo.Element}
27892 getResizeChild : function(){
27893 return this.resizeChild;
27897 * Destroys this resizable. If the element was wrapped and
27898 * removeEl is not true then the element remains.
27899 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
27901 destroy : function(removeEl){
27902 this.proxy.remove();
27904 this.overlay.removeAllListeners();
27905 this.overlay.remove();
27907 var ps = Roo.Resizable.positions;
27909 if(typeof ps[k] != "function" && this[ps[k]]){
27910 var h = this[ps[k]];
27911 h.el.removeAllListeners();
27916 this.el.update("");
27923 // hash to map config positions to true positions
27924 Roo.Resizable.positions = {
27925 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast"
27929 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
27931 // only initialize the template if resizable is used
27932 var tpl = Roo.DomHelper.createTemplate(
27933 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
27936 Roo.Resizable.Handle.prototype.tpl = tpl;
27938 this.position = pos;
27940 this.el = this.tpl.append(rz.el.dom, [this.position], true);
27941 this.el.unselectable();
27943 this.el.setOpacity(0);
27945 this.el.on("mousedown", this.onMouseDown, this);
27946 if(!disableTrackOver){
27947 this.el.on("mouseover", this.onMouseOver, this);
27948 this.el.on("mouseout", this.onMouseOut, this);
27953 Roo.Resizable.Handle.prototype = {
27954 afterResize : function(rz){
27958 onMouseDown : function(e){
27959 this.rz.onMouseDown(this, e);
27962 onMouseOver : function(e){
27963 this.rz.handleOver(this, e);
27966 onMouseOut : function(e){
27967 this.rz.handleOut(this, e);
27971 * Ext JS Library 1.1.1
27972 * Copyright(c) 2006-2007, Ext JS, LLC.
27974 * Originally Released Under LGPL - original licence link has changed is not relivant.
27977 * <script type="text/javascript">
27981 * @class Roo.Editor
27982 * @extends Roo.Component
27983 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
27985 * Create a new Editor
27986 * @param {Roo.form.Field} field The Field object (or descendant)
27987 * @param {Object} config The config object
27989 Roo.Editor = function(field, config){
27990 Roo.Editor.superclass.constructor.call(this, config);
27991 this.field = field;
27994 * @event beforestartedit
27995 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
27996 * false from the handler of this event.
27997 * @param {Editor} this
27998 * @param {Roo.Element} boundEl The underlying element bound to this editor
27999 * @param {Mixed} value The field value being set
28001 "beforestartedit" : true,
28004 * Fires when this editor is displayed
28005 * @param {Roo.Element} boundEl The underlying element bound to this editor
28006 * @param {Mixed} value The starting field value
28008 "startedit" : true,
28010 * @event beforecomplete
28011 * Fires after a change has been made to the field, but before the change is reflected in the underlying
28012 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
28013 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
28014 * event will not fire since no edit actually occurred.
28015 * @param {Editor} this
28016 * @param {Mixed} value The current field value
28017 * @param {Mixed} startValue The original field value
28019 "beforecomplete" : true,
28022 * Fires after editing is complete and any changed value has been written to the underlying field.
28023 * @param {Editor} this
28024 * @param {Mixed} value The current field value
28025 * @param {Mixed} startValue The original field value
28029 * @event specialkey
28030 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
28031 * {@link Roo.EventObject#getKey} to determine which key was pressed.
28032 * @param {Roo.form.Field} this
28033 * @param {Roo.EventObject} e The event object
28035 "specialkey" : true
28039 Roo.extend(Roo.Editor, Roo.Component, {
28041 * @cfg {Boolean/String} autosize
28042 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
28043 * or "height" to adopt the height only (defaults to false)
28046 * @cfg {Boolean} revertInvalid
28047 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
28048 * validation fails (defaults to true)
28051 * @cfg {Boolean} ignoreNoChange
28052 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
28053 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
28054 * will never be ignored.
28057 * @cfg {Boolean} hideEl
28058 * False to keep the bound element visible while the editor is displayed (defaults to true)
28061 * @cfg {Mixed} value
28062 * The data value of the underlying field (defaults to "")
28066 * @cfg {String} alignment
28067 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
28071 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
28072 * for bottom-right shadow (defaults to "frame")
28076 * @cfg {Boolean} constrain True to constrain the editor to the viewport
28080 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
28082 completeOnEnter : false,
28084 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
28086 cancelOnEsc : false,
28088 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
28093 onRender : function(ct, position){
28094 this.el = new Roo.Layer({
28095 shadow: this.shadow,
28101 constrain: this.constrain
28103 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
28104 if(this.field.msgTarget != 'title'){
28105 this.field.msgTarget = 'qtip';
28107 this.field.render(this.el);
28109 this.field.el.dom.setAttribute('autocomplete', 'off');
28111 this.field.on("specialkey", this.onSpecialKey, this);
28112 if(this.swallowKeys){
28113 this.field.el.swallowEvent(['keydown','keypress']);
28116 this.field.on("blur", this.onBlur, this);
28117 if(this.field.grow){
28118 this.field.on("autosize", this.el.sync, this.el, {delay:1});
28122 onSpecialKey : function(field, e){
28123 //Roo.log('editor onSpecialKey');
28124 if(this.completeOnEnter && e.getKey() == e.ENTER){
28126 this.completeEdit();
28127 }else if(this.cancelOnEsc && e.getKey() == e.ESC){
28130 this.fireEvent('specialkey', field, e);
28135 * Starts the editing process and shows the editor.
28136 * @param {String/HTMLElement/Element} el The element to edit
28137 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
28138 * to the innerHTML of el.
28140 startEdit : function(el, value){
28142 this.completeEdit();
28144 this.boundEl = Roo.get(el);
28145 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
28146 if(!this.rendered){
28147 this.render(this.parentEl || document.body);
28149 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
28152 this.startValue = v;
28153 this.field.setValue(v);
28155 var sz = this.boundEl.getSize();
28156 switch(this.autoSize){
28158 this.setSize(sz.width, "");
28161 this.setSize("", sz.height);
28164 this.setSize(sz.width, sz.height);
28167 this.el.alignTo(this.boundEl, this.alignment);
28168 this.editing = true;
28170 Roo.QuickTips.disable();
28176 * Sets the height and width of this editor.
28177 * @param {Number} width The new width
28178 * @param {Number} height The new height
28180 setSize : function(w, h){
28181 this.field.setSize(w, h);
28188 * Realigns the editor to the bound field based on the current alignment config value.
28190 realign : function(){
28191 this.el.alignTo(this.boundEl, this.alignment);
28195 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
28196 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
28198 completeEdit : function(remainVisible){
28202 var v = this.getValue();
28203 if(this.revertInvalid !== false && !this.field.isValid()){
28204 v = this.startValue;
28205 this.cancelEdit(true);
28207 if(String(v) === String(this.startValue) && this.ignoreNoChange){
28208 this.editing = false;
28212 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
28213 this.editing = false;
28214 if(this.updateEl && this.boundEl){
28215 this.boundEl.update(v);
28217 if(remainVisible !== true){
28220 this.fireEvent("complete", this, v, this.startValue);
28225 onShow : function(){
28227 if(this.hideEl !== false){
28228 this.boundEl.hide();
28231 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
28232 this.fixIEFocus = true;
28233 this.deferredFocus.defer(50, this);
28235 this.field.focus();
28237 this.fireEvent("startedit", this.boundEl, this.startValue);
28240 deferredFocus : function(){
28242 this.field.focus();
28247 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
28248 * reverted to the original starting value.
28249 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
28250 * cancel (defaults to false)
28252 cancelEdit : function(remainVisible){
28254 this.setValue(this.startValue);
28255 if(remainVisible !== true){
28262 onBlur : function(){
28263 if(this.allowBlur !== true && this.editing){
28264 this.completeEdit();
28269 onHide : function(){
28271 this.completeEdit();
28275 if(this.field.collapse){
28276 this.field.collapse();
28279 if(this.hideEl !== false){
28280 this.boundEl.show();
28283 Roo.QuickTips.enable();
28288 * Sets the data value of the editor
28289 * @param {Mixed} value Any valid value supported by the underlying field
28291 setValue : function(v){
28292 this.field.setValue(v);
28296 * Gets the data value of the editor
28297 * @return {Mixed} The data value
28299 getValue : function(){
28300 return this.field.getValue();
28304 * Ext JS Library 1.1.1
28305 * Copyright(c) 2006-2007, Ext JS, LLC.
28307 * Originally Released Under LGPL - original licence link has changed is not relivant.
28310 * <script type="text/javascript">
28314 * @class Roo.BasicDialog
28315 * @extends Roo.util.Observable
28316 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
28318 var dlg = new Roo.BasicDialog("my-dlg", {
28327 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
28328 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
28329 dlg.addButton('Cancel', dlg.hide, dlg);
28332 <b>A Dialog should always be a direct child of the body element.</b>
28333 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
28334 * @cfg {String} title Default text to display in the title bar (defaults to null)
28335 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
28336 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
28337 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
28338 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
28339 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
28340 * (defaults to null with no animation)
28341 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
28342 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
28343 * property for valid values (defaults to 'all')
28344 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
28345 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
28346 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
28347 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
28348 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
28349 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
28350 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
28351 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
28352 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
28353 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
28354 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
28355 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
28356 * draggable = true (defaults to false)
28357 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
28358 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
28359 * shadow (defaults to false)
28360 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
28361 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
28362 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
28363 * @cfg {Array} buttons Array of buttons
28364 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
28366 * Create a new BasicDialog.
28367 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
28368 * @param {Object} config Configuration options
28370 Roo.BasicDialog = function(el, config){
28371 this.el = Roo.get(el);
28372 var dh = Roo.DomHelper;
28373 if(!this.el && config && config.autoCreate){
28374 if(typeof config.autoCreate == "object"){
28375 if(!config.autoCreate.id){
28376 config.autoCreate.id = el;
28378 this.el = dh.append(document.body,
28379 config.autoCreate, true);
28381 this.el = dh.append(document.body,
28382 {tag: "div", id: el, style:'visibility:hidden;'}, true);
28386 el.setDisplayed(true);
28387 el.hide = this.hideAction;
28389 el.addClass("x-dlg");
28391 Roo.apply(this, config);
28393 this.proxy = el.createProxy("x-dlg-proxy");
28394 this.proxy.hide = this.hideAction;
28395 this.proxy.setOpacity(.5);
28399 el.setWidth(config.width);
28402 el.setHeight(config.height);
28404 this.size = el.getSize();
28405 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
28406 this.xy = [config.x,config.y];
28408 this.xy = el.getCenterXY(true);
28410 /** The header element @type Roo.Element */
28411 this.header = el.child("> .x-dlg-hd");
28412 /** The body element @type Roo.Element */
28413 this.body = el.child("> .x-dlg-bd");
28414 /** The footer element @type Roo.Element */
28415 this.footer = el.child("> .x-dlg-ft");
28418 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
28421 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
28424 this.header.unselectable();
28426 this.header.update(this.title);
28428 // this element allows the dialog to be focused for keyboard event
28429 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
28430 this.focusEl.swallowEvent("click", true);
28432 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
28434 // wrap the body and footer for special rendering
28435 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
28437 this.bwrap.dom.appendChild(this.footer.dom);
28440 this.bg = this.el.createChild({
28441 tag: "div", cls:"x-dlg-bg",
28442 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
28444 this.centerBg = this.bg.child("div.x-dlg-bg-center");
28447 if(this.autoScroll !== false && !this.autoTabs){
28448 this.body.setStyle("overflow", "auto");
28451 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
28453 if(this.closable !== false){
28454 this.el.addClass("x-dlg-closable");
28455 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
28456 this.close.on("click", this.closeClick, this);
28457 this.close.addClassOnOver("x-dlg-close-over");
28459 if(this.collapsible !== false){
28460 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
28461 this.collapseBtn.on("click", this.collapseClick, this);
28462 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
28463 this.header.on("dblclick", this.collapseClick, this);
28465 if(this.resizable !== false){
28466 this.el.addClass("x-dlg-resizable");
28467 this.resizer = new Roo.Resizable(el, {
28468 minWidth: this.minWidth || 80,
28469 minHeight:this.minHeight || 80,
28470 handles: this.resizeHandles || "all",
28473 this.resizer.on("beforeresize", this.beforeResize, this);
28474 this.resizer.on("resize", this.onResize, this);
28476 if(this.draggable !== false){
28477 el.addClass("x-dlg-draggable");
28478 if (!this.proxyDrag) {
28479 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
28482 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
28484 dd.setHandleElId(this.header.id);
28485 dd.endDrag = this.endMove.createDelegate(this);
28486 dd.startDrag = this.startMove.createDelegate(this);
28487 dd.onDrag = this.onDrag.createDelegate(this);
28492 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
28493 this.mask.enableDisplayMode("block");
28495 this.el.addClass("x-dlg-modal");
28498 this.shadow = new Roo.Shadow({
28499 mode : typeof this.shadow == "string" ? this.shadow : "sides",
28500 offset : this.shadowOffset
28503 this.shadowOffset = 0;
28505 if(Roo.useShims && this.shim !== false){
28506 this.shim = this.el.createShim();
28507 this.shim.hide = this.hideAction;
28515 if (this.buttons) {
28516 var bts= this.buttons;
28518 Roo.each(bts, function(b) {
28527 * Fires when a key is pressed
28528 * @param {Roo.BasicDialog} this
28529 * @param {Roo.EventObject} e
28534 * Fires when this dialog is moved by the user.
28535 * @param {Roo.BasicDialog} this
28536 * @param {Number} x The new page X
28537 * @param {Number} y The new page Y
28542 * Fires when this dialog is resized by the user.
28543 * @param {Roo.BasicDialog} this
28544 * @param {Number} width The new width
28545 * @param {Number} height The new height
28549 * @event beforehide
28550 * Fires before this dialog is hidden.
28551 * @param {Roo.BasicDialog} this
28553 "beforehide" : true,
28556 * Fires when this dialog is hidden.
28557 * @param {Roo.BasicDialog} this
28561 * @event beforeshow
28562 * Fires before this dialog is shown.
28563 * @param {Roo.BasicDialog} this
28565 "beforeshow" : true,
28568 * Fires when this dialog is shown.
28569 * @param {Roo.BasicDialog} this
28573 el.on("keydown", this.onKeyDown, this);
28574 el.on("mousedown", this.toFront, this);
28575 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
28577 Roo.DialogManager.register(this);
28578 Roo.BasicDialog.superclass.constructor.call(this);
28581 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
28582 shadowOffset: Roo.isIE ? 6 : 5,
28585 minButtonWidth: 75,
28586 defaultButton: null,
28587 buttonAlign: "right",
28592 * Sets the dialog title text
28593 * @param {String} text The title text to display
28594 * @return {Roo.BasicDialog} this
28596 setTitle : function(text){
28597 this.header.update(text);
28602 closeClick : function(){
28607 collapseClick : function(){
28608 this[this.collapsed ? "expand" : "collapse"]();
28612 * Collapses the dialog to its minimized state (only the title bar is visible).
28613 * Equivalent to the user clicking the collapse dialog button.
28615 collapse : function(){
28616 if(!this.collapsed){
28617 this.collapsed = true;
28618 this.el.addClass("x-dlg-collapsed");
28619 this.restoreHeight = this.el.getHeight();
28620 this.resizeTo(this.el.getWidth(), this.header.getHeight());
28625 * Expands a collapsed dialog back to its normal state. Equivalent to the user
28626 * clicking the expand dialog button.
28628 expand : function(){
28629 if(this.collapsed){
28630 this.collapsed = false;
28631 this.el.removeClass("x-dlg-collapsed");
28632 this.resizeTo(this.el.getWidth(), this.restoreHeight);
28637 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
28638 * @return {Roo.TabPanel} The tabs component
28640 initTabs : function(){
28641 var tabs = this.getTabs();
28642 while(tabs.getTab(0)){
28645 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
28647 tabs.addTab(Roo.id(dom), dom.title);
28655 beforeResize : function(){
28656 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
28660 onResize : function(){
28661 this.refreshSize();
28662 this.syncBodyHeight();
28663 this.adjustAssets();
28665 this.fireEvent("resize", this, this.size.width, this.size.height);
28669 onKeyDown : function(e){
28670 if(this.isVisible()){
28671 this.fireEvent("keydown", this, e);
28676 * Resizes the dialog.
28677 * @param {Number} width
28678 * @param {Number} height
28679 * @return {Roo.BasicDialog} this
28681 resizeTo : function(width, height){
28682 this.el.setSize(width, height);
28683 this.size = {width: width, height: height};
28684 this.syncBodyHeight();
28685 if(this.fixedcenter){
28688 if(this.isVisible()){
28689 this.constrainXY();
28690 this.adjustAssets();
28692 this.fireEvent("resize", this, width, height);
28698 * Resizes the dialog to fit the specified content size.
28699 * @param {Number} width
28700 * @param {Number} height
28701 * @return {Roo.BasicDialog} this
28703 setContentSize : function(w, h){
28704 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
28705 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
28706 //if(!this.el.isBorderBox()){
28707 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
28708 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
28711 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
28712 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
28714 this.resizeTo(w, h);
28719 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
28720 * executed in response to a particular key being pressed while the dialog is active.
28721 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
28722 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
28723 * @param {Function} fn The function to call
28724 * @param {Object} scope (optional) The scope of the function
28725 * @return {Roo.BasicDialog} this
28727 addKeyListener : function(key, fn, scope){
28728 var keyCode, shift, ctrl, alt;
28729 if(typeof key == "object" && !(key instanceof Array)){
28730 keyCode = key["key"];
28731 shift = key["shift"];
28732 ctrl = key["ctrl"];
28737 var handler = function(dlg, e){
28738 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
28739 var k = e.getKey();
28740 if(keyCode instanceof Array){
28741 for(var i = 0, len = keyCode.length; i < len; i++){
28742 if(keyCode[i] == k){
28743 fn.call(scope || window, dlg, k, e);
28749 fn.call(scope || window, dlg, k, e);
28754 this.on("keydown", handler);
28759 * Returns the TabPanel component (creates it if it doesn't exist).
28760 * Note: If you wish to simply check for the existence of tabs without creating them,
28761 * check for a null 'tabs' property.
28762 * @return {Roo.TabPanel} The tabs component
28764 getTabs : function(){
28766 this.el.addClass("x-dlg-auto-tabs");
28767 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
28768 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
28774 * Adds a button to the footer section of the dialog.
28775 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
28776 * object or a valid Roo.DomHelper element config
28777 * @param {Function} handler The function called when the button is clicked
28778 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
28779 * @return {Roo.Button} The new button
28781 addButton : function(config, handler, scope){
28782 var dh = Roo.DomHelper;
28784 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
28786 if(!this.btnContainer){
28787 var tb = this.footer.createChild({
28789 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
28790 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
28792 this.btnContainer = tb.firstChild.firstChild.firstChild;
28797 minWidth: this.minButtonWidth,
28800 if(typeof config == "string"){
28801 bconfig.text = config;
28804 bconfig.dhconfig = config;
28806 Roo.apply(bconfig, config);
28810 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
28811 bconfig.position = Math.max(0, bconfig.position);
28812 fc = this.btnContainer.childNodes[bconfig.position];
28815 var btn = new Roo.Button(
28817 this.btnContainer.insertBefore(document.createElement("td"),fc)
28818 : this.btnContainer.appendChild(document.createElement("td")),
28819 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
28822 this.syncBodyHeight();
28825 * Array of all the buttons that have been added to this dialog via addButton
28830 this.buttons.push(btn);
28835 * Sets the default button to be focused when the dialog is displayed.
28836 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
28837 * @return {Roo.BasicDialog} this
28839 setDefaultButton : function(btn){
28840 this.defaultButton = btn;
28845 getHeaderFooterHeight : function(safe){
28848 height += this.header.getHeight();
28851 var fm = this.footer.getMargins();
28852 height += (this.footer.getHeight()+fm.top+fm.bottom);
28854 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
28855 height += this.centerBg.getPadding("tb");
28860 syncBodyHeight : function(){
28861 var bd = this.body, cb = this.centerBg, bw = this.bwrap;
28862 var height = this.size.height - this.getHeaderFooterHeight(false);
28863 bd.setHeight(height-bd.getMargins("tb"));
28864 var hh = this.header.getHeight();
28865 var h = this.size.height-hh;
28867 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
28868 bw.setHeight(h-cb.getPadding("tb"));
28869 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
28870 bd.setWidth(bw.getWidth(true));
28872 this.tabs.syncHeight();
28874 this.tabs.el.repaint();
28880 * Restores the previous state of the dialog if Roo.state is configured.
28881 * @return {Roo.BasicDialog} this
28883 restoreState : function(){
28884 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
28885 if(box && box.width){
28886 this.xy = [box.x, box.y];
28887 this.resizeTo(box.width, box.height);
28893 beforeShow : function(){
28895 if(this.fixedcenter){
28896 this.xy = this.el.getCenterXY(true);
28899 Roo.get(document.body).addClass("x-body-masked");
28900 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
28903 this.constrainXY();
28907 animShow : function(){
28908 var b = Roo.get(this.animateTarget, true).getBox();
28909 this.proxy.setSize(b.width, b.height);
28910 this.proxy.setLocation(b.x, b.y);
28912 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
28913 true, .35, this.showEl.createDelegate(this));
28917 * Shows the dialog.
28918 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
28919 * @return {Roo.BasicDialog} this
28921 show : function(animateTarget){
28922 if (this.fireEvent("beforeshow", this) === false){
28925 if(this.syncHeightBeforeShow){
28926 this.syncBodyHeight();
28927 }else if(this.firstShow){
28928 this.firstShow = false;
28929 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
28931 this.animateTarget = animateTarget || this.animateTarget;
28932 if(!this.el.isVisible()){
28934 if(this.animateTarget){
28944 showEl : function(){
28946 this.el.setXY(this.xy);
28948 this.adjustAssets(true);
28951 // IE peekaboo bug - fix found by Dave Fenwick
28955 this.fireEvent("show", this);
28959 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
28960 * dialog itself will receive focus.
28962 focus : function(){
28963 if(this.defaultButton){
28964 this.defaultButton.focus();
28966 this.focusEl.focus();
28971 constrainXY : function(){
28972 if(this.constraintoviewport !== false){
28973 if(!this.viewSize){
28974 if(this.container){
28975 var s = this.container.getSize();
28976 this.viewSize = [s.width, s.height];
28978 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
28981 var s = Roo.get(this.container||document).getScroll();
28983 var x = this.xy[0], y = this.xy[1];
28984 var w = this.size.width, h = this.size.height;
28985 var vw = this.viewSize[0], vh = this.viewSize[1];
28986 // only move it if it needs it
28988 // first validate right/bottom
28989 if(x + w > vw+s.left){
28993 if(y + h > vh+s.top){
28997 // then make sure top/left isn't negative
29009 if(this.isVisible()){
29010 this.el.setLocation(x, y);
29011 this.adjustAssets();
29018 onDrag : function(){
29019 if(!this.proxyDrag){
29020 this.xy = this.el.getXY();
29021 this.adjustAssets();
29026 adjustAssets : function(doShow){
29027 var x = this.xy[0], y = this.xy[1];
29028 var w = this.size.width, h = this.size.height;
29029 if(doShow === true){
29031 this.shadow.show(this.el);
29037 if(this.shadow && this.shadow.isVisible()){
29038 this.shadow.show(this.el);
29040 if(this.shim && this.shim.isVisible()){
29041 this.shim.setBounds(x, y, w, h);
29046 adjustViewport : function(w, h){
29048 w = Roo.lib.Dom.getViewWidth();
29049 h = Roo.lib.Dom.getViewHeight();
29052 this.viewSize = [w, h];
29053 if(this.modal && this.mask.isVisible()){
29054 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
29055 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
29057 if(this.isVisible()){
29058 this.constrainXY();
29063 * Destroys this dialog and all its supporting elements (including any tabs, shim,
29064 * shadow, proxy, mask, etc.) Also removes all event listeners.
29065 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
29067 destroy : function(removeEl){
29068 if(this.isVisible()){
29069 this.animateTarget = null;
29072 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
29074 this.tabs.destroy(removeEl);
29087 for(var i = 0, len = this.buttons.length; i < len; i++){
29088 this.buttons[i].destroy();
29091 this.el.removeAllListeners();
29092 if(removeEl === true){
29093 this.el.update("");
29096 Roo.DialogManager.unregister(this);
29100 startMove : function(){
29101 if(this.proxyDrag){
29104 if(this.constraintoviewport !== false){
29105 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
29110 endMove : function(){
29111 if(!this.proxyDrag){
29112 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
29114 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
29117 this.refreshSize();
29118 this.adjustAssets();
29120 this.fireEvent("move", this, this.xy[0], this.xy[1]);
29124 * Brings this dialog to the front of any other visible dialogs
29125 * @return {Roo.BasicDialog} this
29127 toFront : function(){
29128 Roo.DialogManager.bringToFront(this);
29133 * Sends this dialog to the back (under) of any other visible dialogs
29134 * @return {Roo.BasicDialog} this
29136 toBack : function(){
29137 Roo.DialogManager.sendToBack(this);
29142 * Centers this dialog in the viewport
29143 * @return {Roo.BasicDialog} this
29145 center : function(){
29146 var xy = this.el.getCenterXY(true);
29147 this.moveTo(xy[0], xy[1]);
29152 * Moves the dialog's top-left corner to the specified point
29153 * @param {Number} x
29154 * @param {Number} y
29155 * @return {Roo.BasicDialog} this
29157 moveTo : function(x, y){
29159 if(this.isVisible()){
29160 this.el.setXY(this.xy);
29161 this.adjustAssets();
29167 * Aligns the dialog to the specified element
29168 * @param {String/HTMLElement/Roo.Element} element The element to align to.
29169 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
29170 * @param {Array} offsets (optional) Offset the positioning by [x, y]
29171 * @return {Roo.BasicDialog} this
29173 alignTo : function(element, position, offsets){
29174 this.xy = this.el.getAlignToXY(element, position, offsets);
29175 if(this.isVisible()){
29176 this.el.setXY(this.xy);
29177 this.adjustAssets();
29183 * Anchors an element to another element and realigns it when the window is resized.
29184 * @param {String/HTMLElement/Roo.Element} element The element to align to.
29185 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
29186 * @param {Array} offsets (optional) Offset the positioning by [x, y]
29187 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
29188 * is a number, it is used as the buffer delay (defaults to 50ms).
29189 * @return {Roo.BasicDialog} this
29191 anchorTo : function(el, alignment, offsets, monitorScroll){
29192 var action = function(){
29193 this.alignTo(el, alignment, offsets);
29195 Roo.EventManager.onWindowResize(action, this);
29196 var tm = typeof monitorScroll;
29197 if(tm != 'undefined'){
29198 Roo.EventManager.on(window, 'scroll', action, this,
29199 {buffer: tm == 'number' ? monitorScroll : 50});
29206 * Returns true if the dialog is visible
29207 * @return {Boolean}
29209 isVisible : function(){
29210 return this.el.isVisible();
29214 animHide : function(callback){
29215 var b = Roo.get(this.animateTarget).getBox();
29217 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
29219 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
29220 this.hideEl.createDelegate(this, [callback]));
29224 * Hides the dialog.
29225 * @param {Function} callback (optional) Function to call when the dialog is hidden
29226 * @return {Roo.BasicDialog} this
29228 hide : function(callback){
29229 if (this.fireEvent("beforehide", this) === false){
29233 this.shadow.hide();
29238 if(this.animateTarget){
29239 this.animHide(callback);
29242 this.hideEl(callback);
29248 hideEl : function(callback){
29252 Roo.get(document.body).removeClass("x-body-masked");
29254 this.fireEvent("hide", this);
29255 if(typeof callback == "function"){
29261 hideAction : function(){
29262 this.setLeft("-10000px");
29263 this.setTop("-10000px");
29264 this.setStyle("visibility", "hidden");
29268 refreshSize : function(){
29269 this.size = this.el.getSize();
29270 this.xy = this.el.getXY();
29271 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
29275 // z-index is managed by the DialogManager and may be overwritten at any time
29276 setZIndex : function(index){
29278 this.mask.setStyle("z-index", index);
29281 this.shim.setStyle("z-index", ++index);
29284 this.shadow.setZIndex(++index);
29286 this.el.setStyle("z-index", ++index);
29288 this.proxy.setStyle("z-index", ++index);
29291 this.resizer.proxy.setStyle("z-index", ++index);
29294 this.lastZIndex = index;
29298 * Returns the element for this dialog
29299 * @return {Roo.Element} The underlying dialog Element
29301 getEl : function(){
29307 * @class Roo.DialogManager
29308 * Provides global access to BasicDialogs that have been created and
29309 * support for z-indexing (layering) multiple open dialogs.
29311 Roo.DialogManager = function(){
29313 var accessList = [];
29317 var sortDialogs = function(d1, d2){
29318 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
29322 var orderDialogs = function(){
29323 accessList.sort(sortDialogs);
29324 var seed = Roo.DialogManager.zseed;
29325 for(var i = 0, len = accessList.length; i < len; i++){
29326 var dlg = accessList[i];
29328 dlg.setZIndex(seed + (i*10));
29335 * The starting z-index for BasicDialogs (defaults to 9000)
29336 * @type Number The z-index value
29341 register : function(dlg){
29342 list[dlg.id] = dlg;
29343 accessList.push(dlg);
29347 unregister : function(dlg){
29348 delete list[dlg.id];
29351 if(!accessList.indexOf){
29352 for( i = 0, len = accessList.length; i < len; i++){
29353 if(accessList[i] == dlg){
29354 accessList.splice(i, 1);
29359 i = accessList.indexOf(dlg);
29361 accessList.splice(i, 1);
29367 * Gets a registered dialog by id
29368 * @param {String/Object} id The id of the dialog or a dialog
29369 * @return {Roo.BasicDialog} this
29371 get : function(id){
29372 return typeof id == "object" ? id : list[id];
29376 * Brings the specified dialog to the front
29377 * @param {String/Object} dlg The id of the dialog or a dialog
29378 * @return {Roo.BasicDialog} this
29380 bringToFront : function(dlg){
29381 dlg = this.get(dlg);
29384 dlg._lastAccess = new Date().getTime();
29391 * Sends the specified dialog to the back
29392 * @param {String/Object} dlg The id of the dialog or a dialog
29393 * @return {Roo.BasicDialog} this
29395 sendToBack : function(dlg){
29396 dlg = this.get(dlg);
29397 dlg._lastAccess = -(new Date().getTime());
29403 * Hides all dialogs
29405 hideAll : function(){
29406 for(var id in list){
29407 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
29416 * @class Roo.LayoutDialog
29417 * @extends Roo.BasicDialog
29418 * Dialog which provides adjustments for working with a layout in a Dialog.
29419 * Add your necessary layout config options to the dialog's config.<br>
29420 * Example usage (including a nested layout):
29423 dialog = new Roo.LayoutDialog("download-dlg", {
29432 // layout config merges with the dialog config
29434 tabPosition: "top",
29435 alwaysShowTabs: true
29438 dialog.addKeyListener(27, dialog.hide, dialog);
29439 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
29440 dialog.addButton("Build It!", this.getDownload, this);
29442 // we can even add nested layouts
29443 var innerLayout = new Roo.BorderLayout("dl-inner", {
29453 innerLayout.beginUpdate();
29454 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
29455 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
29456 innerLayout.endUpdate(true);
29458 var layout = dialog.getLayout();
29459 layout.beginUpdate();
29460 layout.add("center", new Roo.ContentPanel("standard-panel",
29461 {title: "Download the Source", fitToFrame:true}));
29462 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
29463 {title: "Build your own roo.js"}));
29464 layout.getRegion("center").showPanel(sp);
29465 layout.endUpdate();
29469 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
29470 * @param {Object} config configuration options
29472 Roo.LayoutDialog = function(el, cfg){
29475 if (typeof(cfg) == 'undefined') {
29476 config = Roo.apply({}, el);
29477 el = Roo.get( document.documentElement || document.body).createChild();
29478 //config.autoCreate = true;
29482 config.autoTabs = false;
29483 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
29484 this.body.setStyle({overflow:"hidden", position:"relative"});
29485 this.layout = new Roo.BorderLayout(this.body.dom, config);
29486 this.layout.monitorWindowResize = false;
29487 this.el.addClass("x-dlg-auto-layout");
29488 // fix case when center region overwrites center function
29489 this.center = Roo.BasicDialog.prototype.center;
29490 this.on("show", this.layout.layout, this.layout, true);
29491 if (config.items) {
29492 var xitems = config.items;
29493 delete config.items;
29494 Roo.each(xitems, this.addxtype, this);
29499 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
29501 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
29504 endUpdate : function(){
29505 this.layout.endUpdate();
29509 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
29512 beginUpdate : function(){
29513 this.layout.beginUpdate();
29517 * Get the BorderLayout for this dialog
29518 * @return {Roo.BorderLayout}
29520 getLayout : function(){
29521 return this.layout;
29524 showEl : function(){
29525 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
29527 this.layout.layout();
29532 // Use the syncHeightBeforeShow config option to control this automatically
29533 syncBodyHeight : function(){
29534 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
29535 if(this.layout){this.layout.layout();}
29539 * Add an xtype element (actually adds to the layout.)
29540 * @return {Object} xdata xtype object data.
29543 addxtype : function(c) {
29544 return this.layout.addxtype(c);
29548 * Ext JS Library 1.1.1
29549 * Copyright(c) 2006-2007, Ext JS, LLC.
29551 * Originally Released Under LGPL - original licence link has changed is not relivant.
29554 * <script type="text/javascript">
29558 * @class Roo.MessageBox
29559 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
29563 Roo.Msg.alert('Status', 'Changes saved successfully.');
29565 // Prompt for user data:
29566 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
29568 // process text value...
29572 // Show a dialog using config options:
29574 title:'Save Changes?',
29575 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
29576 buttons: Roo.Msg.YESNOCANCEL,
29583 Roo.MessageBox = function(){
29584 var dlg, opt, mask, waitTimer;
29585 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
29586 var buttons, activeTextEl, bwidth;
29589 var handleButton = function(button){
29591 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
29595 var handleHide = function(){
29596 if(opt && opt.cls){
29597 dlg.el.removeClass(opt.cls);
29600 Roo.TaskMgr.stop(waitTimer);
29606 var updateButtons = function(b){
29609 buttons["ok"].hide();
29610 buttons["cancel"].hide();
29611 buttons["yes"].hide();
29612 buttons["no"].hide();
29613 dlg.footer.dom.style.display = 'none';
29616 dlg.footer.dom.style.display = '';
29617 for(var k in buttons){
29618 if(typeof buttons[k] != "function"){
29621 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
29622 width += buttons[k].el.getWidth()+15;
29632 var handleEsc = function(d, k, e){
29633 if(opt && opt.closable !== false){
29643 * Returns a reference to the underlying {@link Roo.BasicDialog} element
29644 * @return {Roo.BasicDialog} The BasicDialog element
29646 getDialog : function(){
29648 dlg = new Roo.BasicDialog("x-msg-box", {
29653 constraintoviewport:false,
29655 collapsible : false,
29658 width:400, height:100,
29659 buttonAlign:"center",
29660 closeClick : function(){
29661 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
29662 handleButton("no");
29664 handleButton("cancel");
29668 dlg.on("hide", handleHide);
29670 dlg.addKeyListener(27, handleEsc);
29672 var bt = this.buttonText;
29673 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
29674 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
29675 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
29676 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
29677 bodyEl = dlg.body.createChild({
29679 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>'
29681 msgEl = bodyEl.dom.firstChild;
29682 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
29683 textboxEl.enableDisplayMode();
29684 textboxEl.addKeyListener([10,13], function(){
29685 if(dlg.isVisible() && opt && opt.buttons){
29686 if(opt.buttons.ok){
29687 handleButton("ok");
29688 }else if(opt.buttons.yes){
29689 handleButton("yes");
29693 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
29694 textareaEl.enableDisplayMode();
29695 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
29696 progressEl.enableDisplayMode();
29697 var pf = progressEl.dom.firstChild;
29699 pp = Roo.get(pf.firstChild);
29700 pp.setHeight(pf.offsetHeight);
29708 * Updates the message box body text
29709 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
29710 * the XHTML-compliant non-breaking space character '&#160;')
29711 * @return {Roo.MessageBox} This message box
29713 updateText : function(text){
29714 if(!dlg.isVisible() && !opt.width){
29715 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
29717 msgEl.innerHTML = text || ' ';
29718 var w = Math.max(Math.min(opt.width || msgEl.offsetWidth, this.maxWidth),
29719 Math.max(opt.minWidth || this.minWidth, bwidth));
29721 activeTextEl.setWidth(w);
29723 if(dlg.isVisible()){
29724 dlg.fixedcenter = false;
29726 dlg.setContentSize(w, bodyEl.getHeight());
29727 if(dlg.isVisible()){
29728 dlg.fixedcenter = true;
29734 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
29735 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
29736 * @param {Number} value Any number between 0 and 1 (e.g., .5)
29737 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
29738 * @return {Roo.MessageBox} This message box
29740 updateProgress : function(value, text){
29742 this.updateText(text);
29744 if (pp) { // weird bug on my firefox - for some reason this is not defined
29745 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
29751 * Returns true if the message box is currently displayed
29752 * @return {Boolean} True if the message box is visible, else false
29754 isVisible : function(){
29755 return dlg && dlg.isVisible();
29759 * Hides the message box if it is displayed
29762 if(this.isVisible()){
29768 * Displays a new message box, or reinitializes an existing message box, based on the config options
29769 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
29770 * The following config object properties are supported:
29772 Property Type Description
29773 ---------- --------------- ------------------------------------------------------------------------------------
29774 animEl String/Element An id or Element from which the message box should animate as it opens and
29775 closes (defaults to undefined)
29776 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
29777 cancel:'Bar'}), or false to not show any buttons (defaults to false)
29778 closable Boolean False to hide the top-right close button (defaults to true). Note that
29779 progress and wait dialogs will ignore this property and always hide the
29780 close button as they can only be closed programmatically.
29781 cls String A custom CSS class to apply to the message box element
29782 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
29783 displayed (defaults to 75)
29784 fn Function A callback function to execute after closing the dialog. The arguments to the
29785 function will be btn (the name of the button that was clicked, if applicable,
29786 e.g. "ok"), and text (the value of the active text field, if applicable).
29787 Progress and wait dialogs will ignore this option since they do not respond to
29788 user actions and can only be closed programmatically, so any required function
29789 should be called by the same code after it closes the dialog.
29790 icon String A CSS class that provides a background image to be used as an icon for
29791 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
29792 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
29793 minWidth Number The minimum width in pixels of the message box (defaults to 100)
29794 modal Boolean False to allow user interaction with the page while the message box is
29795 displayed (defaults to true)
29796 msg String A string that will replace the existing message box body text (defaults
29797 to the XHTML-compliant non-breaking space character ' ')
29798 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
29799 progress Boolean True to display a progress bar (defaults to false)
29800 progressText String The text to display inside the progress bar if progress = true (defaults to '')
29801 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
29802 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
29803 title String The title text
29804 value String The string value to set into the active textbox element if displayed
29805 wait Boolean True to display a progress bar (defaults to false)
29806 width Number The width of the dialog in pixels
29813 msg: 'Please enter your address:',
29815 buttons: Roo.MessageBox.OKCANCEL,
29818 animEl: 'addAddressBtn'
29821 * @param {Object} config Configuration options
29822 * @return {Roo.MessageBox} This message box
29824 show : function(options){
29825 if(this.isVisible()){
29828 var d = this.getDialog();
29830 d.setTitle(opt.title || " ");
29831 d.close.setDisplayed(opt.closable !== false);
29832 activeTextEl = textboxEl;
29833 opt.prompt = opt.prompt || (opt.multiline ? true : false);
29838 textareaEl.setHeight(typeof opt.multiline == "number" ?
29839 opt.multiline : this.defaultTextHeight);
29840 activeTextEl = textareaEl;
29849 progressEl.setDisplayed(opt.progress === true);
29850 this.updateProgress(0);
29851 activeTextEl.dom.value = opt.value || "";
29853 dlg.setDefaultButton(activeTextEl);
29855 var bs = opt.buttons;
29858 db = buttons["ok"];
29859 }else if(bs && bs.yes){
29860 db = buttons["yes"];
29862 dlg.setDefaultButton(db);
29864 bwidth = updateButtons(opt.buttons);
29865 this.updateText(opt.msg);
29867 d.el.addClass(opt.cls);
29869 d.proxyDrag = opt.proxyDrag === true;
29870 d.modal = opt.modal !== false;
29871 d.mask = opt.modal !== false ? mask : false;
29872 if(!d.isVisible()){
29873 // force it to the end of the z-index stack so it gets a cursor in FF
29874 document.body.appendChild(dlg.el.dom);
29875 d.animateTarget = null;
29876 d.show(options.animEl);
29882 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
29883 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
29884 * and closing the message box when the process is complete.
29885 * @param {String} title The title bar text
29886 * @param {String} msg The message box body text
29887 * @return {Roo.MessageBox} This message box
29889 progress : function(title, msg){
29896 minWidth: this.minProgressWidth,
29903 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
29904 * If a callback function is passed it will be called after the user clicks the button, and the
29905 * id of the button that was clicked will be passed as the only parameter to the callback
29906 * (could also be the top-right close button).
29907 * @param {String} title The title bar text
29908 * @param {String} msg The message box body text
29909 * @param {Function} fn (optional) The callback function invoked after the message box is closed
29910 * @param {Object} scope (optional) The scope of the callback function
29911 * @return {Roo.MessageBox} This message box
29913 alert : function(title, msg, fn, scope){
29926 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
29927 * interaction while waiting for a long-running process to complete that does not have defined intervals.
29928 * You are responsible for closing the message box when the process is complete.
29929 * @param {String} msg The message box body text
29930 * @param {String} title (optional) The title bar text
29931 * @return {Roo.MessageBox} This message box
29933 wait : function(msg, title){
29944 waitTimer = Roo.TaskMgr.start({
29946 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
29954 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
29955 * If a callback function is passed it will be called after the user clicks either button, and the id of the
29956 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
29957 * @param {String} title The title bar text
29958 * @param {String} msg The message box body text
29959 * @param {Function} fn (optional) The callback function invoked after the message box is closed
29960 * @param {Object} scope (optional) The scope of the callback function
29961 * @return {Roo.MessageBox} This message box
29963 confirm : function(title, msg, fn, scope){
29967 buttons: this.YESNO,
29976 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
29977 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
29978 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
29979 * (could also be the top-right close button) and the text that was entered will be passed as the two
29980 * parameters to the callback.
29981 * @param {String} title The title bar text
29982 * @param {String} msg The message box body text
29983 * @param {Function} fn (optional) The callback function invoked after the message box is closed
29984 * @param {Object} scope (optional) The scope of the callback function
29985 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
29986 * property, or the height in pixels to create the textbox (defaults to false / single-line)
29987 * @return {Roo.MessageBox} This message box
29989 prompt : function(title, msg, fn, scope, multiline){
29993 buttons: this.OKCANCEL,
29998 multiline: multiline,
30005 * Button config that displays a single OK button
30010 * Button config that displays Yes and No buttons
30013 YESNO : {yes:true, no:true},
30015 * Button config that displays OK and Cancel buttons
30018 OKCANCEL : {ok:true, cancel:true},
30020 * Button config that displays Yes, No and Cancel buttons
30023 YESNOCANCEL : {yes:true, no:true, cancel:true},
30026 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
30029 defaultTextHeight : 75,
30031 * The maximum width in pixels of the message box (defaults to 600)
30036 * The minimum width in pixels of the message box (defaults to 100)
30041 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
30042 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
30045 minProgressWidth : 250,
30047 * An object containing the default button text strings that can be overriden for localized language support.
30048 * Supported properties are: ok, cancel, yes and no.
30049 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
30062 * Shorthand for {@link Roo.MessageBox}
30064 Roo.Msg = Roo.MessageBox;/*
30066 * Ext JS Library 1.1.1
30067 * Copyright(c) 2006-2007, Ext JS, LLC.
30069 * Originally Released Under LGPL - original licence link has changed is not relivant.
30072 * <script type="text/javascript">
30075 * @class Roo.QuickTips
30076 * Provides attractive and customizable tooltips for any element.
30079 Roo.QuickTips = function(){
30080 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
30081 var ce, bd, xy, dd;
30082 var visible = false, disabled = true, inited = false;
30083 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
30085 var onOver = function(e){
30089 var t = e.getTarget();
30090 if(!t || t.nodeType !== 1 || t == document || t == document.body){
30093 if(ce && t == ce.el){
30094 clearTimeout(hideProc);
30097 if(t && tagEls[t.id]){
30098 tagEls[t.id].el = t;
30099 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
30102 var ttp, et = Roo.fly(t);
30103 var ns = cfg.namespace;
30104 if(tm.interceptTitles && t.title){
30107 t.removeAttribute("title");
30108 e.preventDefault();
30110 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute);
30113 showProc = show.defer(tm.showDelay, tm, [{
30116 width: et.getAttributeNS(ns, cfg.width),
30117 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
30118 title: et.getAttributeNS(ns, cfg.title),
30119 cls: et.getAttributeNS(ns, cfg.cls)
30124 var onOut = function(e){
30125 clearTimeout(showProc);
30126 var t = e.getTarget();
30127 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
30128 hideProc = setTimeout(hide, tm.hideDelay);
30132 var onMove = function(e){
30138 if(tm.trackMouse && ce){
30143 var onDown = function(e){
30144 clearTimeout(showProc);
30145 clearTimeout(hideProc);
30147 if(tm.hideOnClick){
30150 tm.enable.defer(100, tm);
30155 var getPad = function(){
30156 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
30159 var show = function(o){
30163 clearTimeout(dismissProc);
30165 if(removeCls){ // in case manually hidden
30166 el.removeClass(removeCls);
30170 el.addClass(ce.cls);
30171 removeCls = ce.cls;
30174 tipTitle.update(ce.title);
30177 tipTitle.update('');
30180 el.dom.style.width = tm.maxWidth+'px';
30181 //tipBody.dom.style.width = '';
30182 tipBodyText.update(o.text);
30183 var p = getPad(), w = ce.width;
30185 var td = tipBodyText.dom;
30186 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
30187 if(aw > tm.maxWidth){
30189 }else if(aw < tm.minWidth){
30195 //tipBody.setWidth(w);
30196 el.setWidth(parseInt(w, 10) + p);
30197 if(ce.autoHide === false){
30198 close.setDisplayed(true);
30203 close.setDisplayed(false);
30209 el.avoidY = xy[1]-18;
30214 el.setStyle("visibility", "visible");
30215 el.fadeIn({callback: afterShow});
30221 var afterShow = function(){
30225 if(tm.autoDismiss && ce.autoHide !== false){
30226 dismissProc = setTimeout(hide, tm.autoDismissDelay);
30231 var hide = function(noanim){
30232 clearTimeout(dismissProc);
30233 clearTimeout(hideProc);
30235 if(el.isVisible()){
30237 if(noanim !== true && tm.animate){
30238 el.fadeOut({callback: afterHide});
30245 var afterHide = function(){
30248 el.removeClass(removeCls);
30255 * @cfg {Number} minWidth
30256 * The minimum width of the quick tip (defaults to 40)
30260 * @cfg {Number} maxWidth
30261 * The maximum width of the quick tip (defaults to 300)
30265 * @cfg {Boolean} interceptTitles
30266 * True to automatically use the element's DOM title value if available (defaults to false)
30268 interceptTitles : false,
30270 * @cfg {Boolean} trackMouse
30271 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
30273 trackMouse : false,
30275 * @cfg {Boolean} hideOnClick
30276 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
30278 hideOnClick : true,
30280 * @cfg {Number} showDelay
30281 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
30285 * @cfg {Number} hideDelay
30286 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
30290 * @cfg {Boolean} autoHide
30291 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
30292 * Used in conjunction with hideDelay.
30297 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
30298 * (defaults to true). Used in conjunction with autoDismissDelay.
30300 autoDismiss : true,
30303 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
30305 autoDismissDelay : 5000,
30307 * @cfg {Boolean} animate
30308 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
30313 * @cfg {String} title
30314 * Title text to display (defaults to ''). This can be any valid HTML markup.
30318 * @cfg {String} text
30319 * Body text to display (defaults to ''). This can be any valid HTML markup.
30323 * @cfg {String} cls
30324 * A CSS class to apply to the base quick tip element (defaults to '').
30328 * @cfg {Number} width
30329 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
30330 * minWidth or maxWidth.
30335 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
30336 * or display QuickTips in a page.
30339 tm = Roo.QuickTips;
30340 cfg = tm.tagConfig;
30342 if(!Roo.isReady){ // allow calling of init() before onReady
30343 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
30346 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
30347 el.fxDefaults = {stopFx: true};
30348 // maximum custom styling
30349 //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>');
30350 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>');
30351 tipTitle = el.child('h3');
30352 tipTitle.enableDisplayMode("block");
30353 tipBody = el.child('div.x-tip-bd');
30354 tipBodyText = el.child('div.x-tip-bd-inner');
30355 //bdLeft = el.child('div.x-tip-bd-left');
30356 //bdRight = el.child('div.x-tip-bd-right');
30357 close = el.child('div.x-tip-close');
30358 close.enableDisplayMode("block");
30359 close.on("click", hide);
30360 var d = Roo.get(document);
30361 d.on("mousedown", onDown);
30362 d.on("mouseover", onOver);
30363 d.on("mouseout", onOut);
30364 d.on("mousemove", onMove);
30365 esc = d.addKeyListener(27, hide);
30368 dd = el.initDD("default", null, {
30369 onDrag : function(){
30373 dd.setHandleElId(tipTitle.id);
30382 * Configures a new quick tip instance and assigns it to a target element. The following config options
30385 Property Type Description
30386 ---------- --------------------- ------------------------------------------------------------------------
30387 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
30389 * @param {Object} config The config object
30391 register : function(config){
30392 var cs = config instanceof Array ? config : arguments;
30393 for(var i = 0, len = cs.length; i < len; i++) {
30395 var target = c.target;
30397 if(target instanceof Array){
30398 for(var j = 0, jlen = target.length; j < jlen; j++){
30399 tagEls[target[j]] = c;
30402 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
30409 * Removes this quick tip from its element and destroys it.
30410 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
30412 unregister : function(el){
30413 delete tagEls[Roo.id(el)];
30417 * Enable this quick tip.
30419 enable : function(){
30420 if(inited && disabled){
30422 if(locks.length < 1){
30429 * Disable this quick tip.
30431 disable : function(){
30433 clearTimeout(showProc);
30434 clearTimeout(hideProc);
30435 clearTimeout(dismissProc);
30443 * Returns true if the quick tip is enabled, else false.
30445 isEnabled : function(){
30452 attribute : "qtip",
30462 // backwards compat
30463 Roo.QuickTips.tips = Roo.QuickTips.register;/*
30465 * Ext JS Library 1.1.1
30466 * Copyright(c) 2006-2007, Ext JS, LLC.
30468 * Originally Released Under LGPL - original licence link has changed is not relivant.
30471 * <script type="text/javascript">
30476 * @class Roo.tree.TreePanel
30477 * @extends Roo.data.Tree
30479 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
30480 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
30481 * @cfg {Boolean} enableDD true to enable drag and drop
30482 * @cfg {Boolean} enableDrag true to enable just drag
30483 * @cfg {Boolean} enableDrop true to enable just drop
30484 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
30485 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
30486 * @cfg {String} ddGroup The DD group this TreePanel belongs to
30487 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
30488 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
30489 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
30490 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
30491 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
30492 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
30493 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
30494 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
30495 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
30496 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
30497 * @cfg {Function} renderer Sets the rendering (formatting) function for the nodes. to return HTML markup for the tree view. The render function is called with the following parameters:<ul><li>The {Object} The data for the node.</li></ul>
30498 * @cfg {Function} rendererTip Sets the rendering (formatting) function for the nodes hovertip to return HTML markup for the tree view. The render function is called with the following parameters:<ul><li>The {Object} The data for the node.</li></ul>
30501 * @param {String/HTMLElement/Element} el The container element
30502 * @param {Object} config
30504 Roo.tree.TreePanel = function(el, config){
30506 var loader = false;
30508 root = config.root;
30509 delete config.root;
30511 if (config.loader) {
30512 loader = config.loader;
30513 delete config.loader;
30516 Roo.apply(this, config);
30517 Roo.tree.TreePanel.superclass.constructor.call(this);
30518 this.el = Roo.get(el);
30519 this.el.addClass('x-tree');
30520 //console.log(root);
30522 this.setRootNode( Roo.factory(root, Roo.tree));
30525 this.loader = Roo.factory(loader, Roo.tree);
30528 * Read-only. The id of the container element becomes this TreePanel's id.
30530 this.id = this.el.id;
30533 * @event beforeload
30534 * Fires before a node is loaded, return false to cancel
30535 * @param {Node} node The node being loaded
30537 "beforeload" : true,
30540 * Fires when a node is loaded
30541 * @param {Node} node The node that was loaded
30545 * @event textchange
30546 * Fires when the text for a node is changed
30547 * @param {Node} node The node
30548 * @param {String} text The new text
30549 * @param {String} oldText The old text
30551 "textchange" : true,
30553 * @event beforeexpand
30554 * Fires before a node is expanded, return false to cancel.
30555 * @param {Node} node The node
30556 * @param {Boolean} deep
30557 * @param {Boolean} anim
30559 "beforeexpand" : true,
30561 * @event beforecollapse
30562 * Fires before a node is collapsed, return false to cancel.
30563 * @param {Node} node The node
30564 * @param {Boolean} deep
30565 * @param {Boolean} anim
30567 "beforecollapse" : true,
30570 * Fires when a node is expanded
30571 * @param {Node} node The node
30575 * @event disabledchange
30576 * Fires when the disabled status of a node changes
30577 * @param {Node} node The node
30578 * @param {Boolean} disabled
30580 "disabledchange" : true,
30583 * Fires when a node is collapsed
30584 * @param {Node} node The node
30588 * @event beforeclick
30589 * Fires before click processing on a node. Return false to cancel the default action.
30590 * @param {Node} node The node
30591 * @param {Roo.EventObject} e The event object
30593 "beforeclick":true,
30595 * @event checkchange
30596 * Fires when a node with a checkbox's checked property changes
30597 * @param {Node} this This node
30598 * @param {Boolean} checked
30600 "checkchange":true,
30603 * Fires when a node is clicked
30604 * @param {Node} node The node
30605 * @param {Roo.EventObject} e The event object
30610 * Fires when a node is double clicked
30611 * @param {Node} node The node
30612 * @param {Roo.EventObject} e The event object
30616 * @event contextmenu
30617 * Fires when a node is right clicked
30618 * @param {Node} node The node
30619 * @param {Roo.EventObject} e The event object
30621 "contextmenu":true,
30623 * @event beforechildrenrendered
30624 * Fires right before the child nodes for a node are rendered
30625 * @param {Node} node The node
30627 "beforechildrenrendered":true,
30630 * Fires when a node starts being dragged
30631 * @param {Roo.tree.TreePanel} this
30632 * @param {Roo.tree.TreeNode} node
30633 * @param {event} e The raw browser event
30635 "startdrag" : true,
30638 * Fires when a drag operation is complete
30639 * @param {Roo.tree.TreePanel} this
30640 * @param {Roo.tree.TreeNode} node
30641 * @param {event} e The raw browser event
30646 * Fires when a dragged node is dropped on a valid DD target
30647 * @param {Roo.tree.TreePanel} this
30648 * @param {Roo.tree.TreeNode} node
30649 * @param {DD} dd The dd it was dropped on
30650 * @param {event} e The raw browser event
30654 * @event beforenodedrop
30655 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
30656 * passed to handlers has the following properties:<br />
30657 * <ul style="padding:5px;padding-left:16px;">
30658 * <li>tree - The TreePanel</li>
30659 * <li>target - The node being targeted for the drop</li>
30660 * <li>data - The drag data from the drag source</li>
30661 * <li>point - The point of the drop - append, above or below</li>
30662 * <li>source - The drag source</li>
30663 * <li>rawEvent - Raw mouse event</li>
30664 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
30665 * to be inserted by setting them on this object.</li>
30666 * <li>cancel - Set this to true to cancel the drop.</li>
30668 * @param {Object} dropEvent
30670 "beforenodedrop" : true,
30673 * Fires after a DD object is dropped on a node in this tree. The dropEvent
30674 * passed to handlers has the following properties:<br />
30675 * <ul style="padding:5px;padding-left:16px;">
30676 * <li>tree - The TreePanel</li>
30677 * <li>target - The node being targeted for the drop</li>
30678 * <li>data - The drag data from the drag source</li>
30679 * <li>point - The point of the drop - append, above or below</li>
30680 * <li>source - The drag source</li>
30681 * <li>rawEvent - Raw mouse event</li>
30682 * <li>dropNode - Dropped node(s).</li>
30684 * @param {Object} dropEvent
30688 * @event nodedragover
30689 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
30690 * passed to handlers has the following properties:<br />
30691 * <ul style="padding:5px;padding-left:16px;">
30692 * <li>tree - The TreePanel</li>
30693 * <li>target - The node being targeted for the drop</li>
30694 * <li>data - The drag data from the drag source</li>
30695 * <li>point - The point of the drop - append, above or below</li>
30696 * <li>source - The drag source</li>
30697 * <li>rawEvent - Raw mouse event</li>
30698 * <li>dropNode - Drop node(s) provided by the source.</li>
30699 * <li>cancel - Set this to true to signal drop not allowed.</li>
30701 * @param {Object} dragOverEvent
30703 "nodedragover" : true
30706 if(this.singleExpand){
30707 this.on("beforeexpand", this.restrictExpand, this);
30710 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
30711 rootVisible : true,
30712 animate: Roo.enableFx,
30715 hlDrop : Roo.enableFx,
30719 rendererTip: false,
30721 restrictExpand : function(node){
30722 var p = node.parentNode;
30724 if(p.expandedChild && p.expandedChild.parentNode == p){
30725 p.expandedChild.collapse();
30727 p.expandedChild = node;
30731 // private override
30732 setRootNode : function(node){
30733 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
30734 if(!this.rootVisible){
30735 node.ui = new Roo.tree.RootTreeNodeUI(node);
30741 * Returns the container element for this TreePanel
30743 getEl : function(){
30748 * Returns the default TreeLoader for this TreePanel
30750 getLoader : function(){
30751 return this.loader;
30757 expandAll : function(){
30758 this.root.expand(true);
30762 * Collapse all nodes
30764 collapseAll : function(){
30765 this.root.collapse(true);
30769 * Returns the selection model used by this TreePanel
30771 getSelectionModel : function(){
30772 if(!this.selModel){
30773 this.selModel = new Roo.tree.DefaultSelectionModel();
30775 return this.selModel;
30779 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
30780 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
30781 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
30784 getChecked : function(a, startNode){
30785 startNode = startNode || this.root;
30787 var f = function(){
30788 if(this.attributes.checked){
30789 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
30792 startNode.cascade(f);
30797 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
30798 * @param {String} path
30799 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
30800 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
30801 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
30803 expandPath : function(path, attr, callback){
30804 attr = attr || "id";
30805 var keys = path.split(this.pathSeparator);
30806 var curNode = this.root;
30807 if(curNode.attributes[attr] != keys[1]){ // invalid root
30809 callback(false, null);
30814 var f = function(){
30815 if(++index == keys.length){
30817 callback(true, curNode);
30821 var c = curNode.findChild(attr, keys[index]);
30824 callback(false, curNode);
30829 c.expand(false, false, f);
30831 curNode.expand(false, false, f);
30835 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
30836 * @param {String} path
30837 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
30838 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
30839 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
30841 selectPath : function(path, attr, callback){
30842 attr = attr || "id";
30843 var keys = path.split(this.pathSeparator);
30844 var v = keys.pop();
30845 if(keys.length > 0){
30846 var f = function(success, node){
30847 if(success && node){
30848 var n = node.findChild(attr, v);
30854 }else if(callback){
30855 callback(false, n);
30859 callback(false, n);
30863 this.expandPath(keys.join(this.pathSeparator), attr, f);
30865 this.root.select();
30867 callback(true, this.root);
30872 getTreeEl : function(){
30877 * Trigger rendering of this TreePanel
30879 render : function(){
30880 if (this.innerCt) {
30881 return this; // stop it rendering more than once!!
30884 this.innerCt = this.el.createChild({tag:"ul",
30885 cls:"x-tree-root-ct " +
30886 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
30888 if(this.containerScroll){
30889 Roo.dd.ScrollManager.register(this.el);
30891 if((this.enableDD || this.enableDrop) && !this.dropZone){
30893 * The dropZone used by this tree if drop is enabled
30894 * @type Roo.tree.TreeDropZone
30896 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
30897 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
30900 if((this.enableDD || this.enableDrag) && !this.dragZone){
30902 * The dragZone used by this tree if drag is enabled
30903 * @type Roo.tree.TreeDragZone
30905 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
30906 ddGroup: this.ddGroup || "TreeDD",
30907 scroll: this.ddScroll
30910 this.getSelectionModel().init(this);
30912 console.log("ROOT not set in tree");
30915 this.root.render();
30916 if(!this.rootVisible){
30917 this.root.renderChildren();
30923 * Ext JS Library 1.1.1
30924 * Copyright(c) 2006-2007, Ext JS, LLC.
30926 * Originally Released Under LGPL - original licence link has changed is not relivant.
30929 * <script type="text/javascript">
30934 * @class Roo.tree.DefaultSelectionModel
30935 * @extends Roo.util.Observable
30936 * The default single selection for a TreePanel.
30938 Roo.tree.DefaultSelectionModel = function(){
30939 this.selNode = null;
30943 * @event selectionchange
30944 * Fires when the selected node changes
30945 * @param {DefaultSelectionModel} this
30946 * @param {TreeNode} node the new selection
30948 "selectionchange" : true,
30951 * @event beforeselect
30952 * Fires before the selected node changes, return false to cancel the change
30953 * @param {DefaultSelectionModel} this
30954 * @param {TreeNode} node the new selection
30955 * @param {TreeNode} node the old selection
30957 "beforeselect" : true
30961 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
30962 init : function(tree){
30964 tree.getTreeEl().on("keydown", this.onKeyDown, this);
30965 tree.on("click", this.onNodeClick, this);
30968 onNodeClick : function(node, e){
30969 if (e.ctrlKey && this.selNode == node) {
30970 this.unselect(node);
30978 * @param {TreeNode} node The node to select
30979 * @return {TreeNode} The selected node
30981 select : function(node){
30982 var last = this.selNode;
30983 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
30985 last.ui.onSelectedChange(false);
30987 this.selNode = node;
30988 node.ui.onSelectedChange(true);
30989 this.fireEvent("selectionchange", this, node, last);
30996 * @param {TreeNode} node The node to unselect
30998 unselect : function(node){
30999 if(this.selNode == node){
31000 this.clearSelections();
31005 * Clear all selections
31007 clearSelections : function(){
31008 var n = this.selNode;
31010 n.ui.onSelectedChange(false);
31011 this.selNode = null;
31012 this.fireEvent("selectionchange", this, null);
31018 * Get the selected node
31019 * @return {TreeNode} The selected node
31021 getSelectedNode : function(){
31022 return this.selNode;
31026 * Returns true if the node is selected
31027 * @param {TreeNode} node The node to check
31028 * @return {Boolean}
31030 isSelected : function(node){
31031 return this.selNode == node;
31035 * Selects the node above the selected node in the tree, intelligently walking the nodes
31036 * @return TreeNode The new selection
31038 selectPrevious : function(){
31039 var s = this.selNode || this.lastSelNode;
31043 var ps = s.previousSibling;
31045 if(!ps.isExpanded() || ps.childNodes.length < 1){
31046 return this.select(ps);
31048 var lc = ps.lastChild;
31049 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
31052 return this.select(lc);
31054 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
31055 return this.select(s.parentNode);
31061 * Selects the node above the selected node in the tree, intelligently walking the nodes
31062 * @return TreeNode The new selection
31064 selectNext : function(){
31065 var s = this.selNode || this.lastSelNode;
31069 if(s.firstChild && s.isExpanded()){
31070 return this.select(s.firstChild);
31071 }else if(s.nextSibling){
31072 return this.select(s.nextSibling);
31073 }else if(s.parentNode){
31075 s.parentNode.bubble(function(){
31076 if(this.nextSibling){
31077 newS = this.getOwnerTree().selModel.select(this.nextSibling);
31086 onKeyDown : function(e){
31087 var s = this.selNode || this.lastSelNode;
31088 // undesirable, but required
31093 var k = e.getKey();
31101 this.selectPrevious();
31104 e.preventDefault();
31105 if(s.hasChildNodes()){
31106 if(!s.isExpanded()){
31108 }else if(s.firstChild){
31109 this.select(s.firstChild, e);
31114 e.preventDefault();
31115 if(s.hasChildNodes() && s.isExpanded()){
31117 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
31118 this.select(s.parentNode, e);
31126 * @class Roo.tree.MultiSelectionModel
31127 * @extends Roo.util.Observable
31128 * Multi selection for a TreePanel.
31130 Roo.tree.MultiSelectionModel = function(){
31131 this.selNodes = [];
31135 * @event selectionchange
31136 * Fires when the selected nodes change
31137 * @param {MultiSelectionModel} this
31138 * @param {Array} nodes Array of the selected nodes
31140 "selectionchange" : true
31144 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
31145 init : function(tree){
31147 tree.getTreeEl().on("keydown", this.onKeyDown, this);
31148 tree.on("click", this.onNodeClick, this);
31151 onNodeClick : function(node, e){
31152 this.select(node, e, e.ctrlKey);
31157 * @param {TreeNode} node The node to select
31158 * @param {EventObject} e (optional) An event associated with the selection
31159 * @param {Boolean} keepExisting True to retain existing selections
31160 * @return {TreeNode} The selected node
31162 select : function(node, e, keepExisting){
31163 if(keepExisting !== true){
31164 this.clearSelections(true);
31166 if(this.isSelected(node)){
31167 this.lastSelNode = node;
31170 this.selNodes.push(node);
31171 this.selMap[node.id] = node;
31172 this.lastSelNode = node;
31173 node.ui.onSelectedChange(true);
31174 this.fireEvent("selectionchange", this, this.selNodes);
31180 * @param {TreeNode} node The node to unselect
31182 unselect : function(node){
31183 if(this.selMap[node.id]){
31184 node.ui.onSelectedChange(false);
31185 var sn = this.selNodes;
31188 index = sn.indexOf(node);
31190 for(var i = 0, len = sn.length; i < len; i++){
31198 this.selNodes.splice(index, 1);
31200 delete this.selMap[node.id];
31201 this.fireEvent("selectionchange", this, this.selNodes);
31206 * Clear all selections
31208 clearSelections : function(suppressEvent){
31209 var sn = this.selNodes;
31211 for(var i = 0, len = sn.length; i < len; i++){
31212 sn[i].ui.onSelectedChange(false);
31214 this.selNodes = [];
31216 if(suppressEvent !== true){
31217 this.fireEvent("selectionchange", this, this.selNodes);
31223 * Returns true if the node is selected
31224 * @param {TreeNode} node The node to check
31225 * @return {Boolean}
31227 isSelected : function(node){
31228 return this.selMap[node.id] ? true : false;
31232 * Returns an array of the selected nodes
31235 getSelectedNodes : function(){
31236 return this.selNodes;
31239 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
31241 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
31243 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
31246 * Ext JS Library 1.1.1
31247 * Copyright(c) 2006-2007, Ext JS, LLC.
31249 * Originally Released Under LGPL - original licence link has changed is not relivant.
31252 * <script type="text/javascript">
31256 * @class Roo.tree.TreeNode
31257 * @extends Roo.data.Node
31258 * @cfg {String} text The text for this node
31259 * @cfg {Boolean} expanded true to start the node expanded
31260 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
31261 * @cfg {Boolean} allowDrop false if this node cannot be drop on
31262 * @cfg {Boolean} disabled true to start the node disabled
31263 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
31264 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
31265 * @cfg {String} cls A css class to be added to the node
31266 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
31267 * @cfg {String} href URL of the link used for the node (defaults to #)
31268 * @cfg {String} hrefTarget target frame for the link
31269 * @cfg {String} qtip An Ext QuickTip for the node
31270 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
31271 * @cfg {Boolean} singleClickExpand True for single click expand on this node
31272 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
31273 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
31274 * (defaults to undefined with no checkbox rendered)
31276 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
31278 Roo.tree.TreeNode = function(attributes){
31279 attributes = attributes || {};
31280 if(typeof attributes == "string"){
31281 attributes = {text: attributes};
31283 this.childrenRendered = false;
31284 this.rendered = false;
31285 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
31286 this.expanded = attributes.expanded === true;
31287 this.isTarget = attributes.isTarget !== false;
31288 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
31289 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
31292 * Read-only. The text for this node. To change it use setText().
31295 this.text = attributes.text;
31297 * True if this node is disabled.
31300 this.disabled = attributes.disabled === true;
31304 * @event textchange
31305 * Fires when the text for this node is changed
31306 * @param {Node} this This node
31307 * @param {String} text The new text
31308 * @param {String} oldText The old text
31310 "textchange" : true,
31312 * @event beforeexpand
31313 * Fires before this node is expanded, return false to cancel.
31314 * @param {Node} this This node
31315 * @param {Boolean} deep
31316 * @param {Boolean} anim
31318 "beforeexpand" : true,
31320 * @event beforecollapse
31321 * Fires before this node is collapsed, return false to cancel.
31322 * @param {Node} this This node
31323 * @param {Boolean} deep
31324 * @param {Boolean} anim
31326 "beforecollapse" : true,
31329 * Fires when this node is expanded
31330 * @param {Node} this This node
31334 * @event disabledchange
31335 * Fires when the disabled status of this node changes
31336 * @param {Node} this This node
31337 * @param {Boolean} disabled
31339 "disabledchange" : true,
31342 * Fires when this node is collapsed
31343 * @param {Node} this This node
31347 * @event beforeclick
31348 * Fires before click processing. Return false to cancel the default action.
31349 * @param {Node} this This node
31350 * @param {Roo.EventObject} e The event object
31352 "beforeclick":true,
31354 * @event checkchange
31355 * Fires when a node with a checkbox's checked property changes
31356 * @param {Node} this This node
31357 * @param {Boolean} checked
31359 "checkchange":true,
31362 * Fires when this node is clicked
31363 * @param {Node} this This node
31364 * @param {Roo.EventObject} e The event object
31369 * Fires when this node is double clicked
31370 * @param {Node} this This node
31371 * @param {Roo.EventObject} e The event object
31375 * @event contextmenu
31376 * Fires when this node is right clicked
31377 * @param {Node} this This node
31378 * @param {Roo.EventObject} e The event object
31380 "contextmenu":true,
31382 * @event beforechildrenrendered
31383 * Fires right before the child nodes for this node are rendered
31384 * @param {Node} this This node
31386 "beforechildrenrendered":true
31389 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
31392 * Read-only. The UI for this node
31395 this.ui = new uiClass(this);
31397 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
31398 preventHScroll: true,
31400 * Returns true if this node is expanded
31401 * @return {Boolean}
31403 isExpanded : function(){
31404 return this.expanded;
31408 * Returns the UI object for this node
31409 * @return {TreeNodeUI}
31411 getUI : function(){
31415 // private override
31416 setFirstChild : function(node){
31417 var of = this.firstChild;
31418 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
31419 if(this.childrenRendered && of && node != of){
31420 of.renderIndent(true, true);
31423 this.renderIndent(true, true);
31427 // private override
31428 setLastChild : function(node){
31429 var ol = this.lastChild;
31430 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
31431 if(this.childrenRendered && ol && node != ol){
31432 ol.renderIndent(true, true);
31435 this.renderIndent(true, true);
31439 // these methods are overridden to provide lazy rendering support
31440 // private override
31441 appendChild : function(){
31442 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
31443 if(node && this.childrenRendered){
31446 this.ui.updateExpandIcon();
31450 // private override
31451 removeChild : function(node){
31452 this.ownerTree.getSelectionModel().unselect(node);
31453 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
31454 // if it's been rendered remove dom node
31455 if(this.childrenRendered){
31458 if(this.childNodes.length < 1){
31459 this.collapse(false, false);
31461 this.ui.updateExpandIcon();
31463 if(!this.firstChild) {
31464 this.childrenRendered = false;
31469 // private override
31470 insertBefore : function(node, refNode){
31471 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
31472 if(newNode && refNode && this.childrenRendered){
31475 this.ui.updateExpandIcon();
31480 * Sets the text for this node
31481 * @param {String} text
31483 setText : function(text){
31484 var oldText = this.text;
31486 this.attributes.text = text;
31487 if(this.rendered){ // event without subscribing
31488 this.ui.onTextChange(this, text, oldText);
31490 this.fireEvent("textchange", this, text, oldText);
31494 * Triggers selection of this node
31496 select : function(){
31497 this.getOwnerTree().getSelectionModel().select(this);
31501 * Triggers deselection of this node
31503 unselect : function(){
31504 this.getOwnerTree().getSelectionModel().unselect(this);
31508 * Returns true if this node is selected
31509 * @return {Boolean}
31511 isSelected : function(){
31512 return this.getOwnerTree().getSelectionModel().isSelected(this);
31516 * Expand this node.
31517 * @param {Boolean} deep (optional) True to expand all children as well
31518 * @param {Boolean} anim (optional) false to cancel the default animation
31519 * @param {Function} callback (optional) A callback to be called when
31520 * expanding this node completes (does not wait for deep expand to complete).
31521 * Called with 1 parameter, this node.
31523 expand : function(deep, anim, callback){
31524 if(!this.expanded){
31525 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
31528 if(!this.childrenRendered){
31529 this.renderChildren();
31531 this.expanded = true;
31532 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
31533 this.ui.animExpand(function(){
31534 this.fireEvent("expand", this);
31535 if(typeof callback == "function"){
31539 this.expandChildNodes(true);
31541 }.createDelegate(this));
31545 this.fireEvent("expand", this);
31546 if(typeof callback == "function"){
31551 if(typeof callback == "function"){
31556 this.expandChildNodes(true);
31560 isHiddenRoot : function(){
31561 return this.isRoot && !this.getOwnerTree().rootVisible;
31565 * Collapse this node.
31566 * @param {Boolean} deep (optional) True to collapse all children as well
31567 * @param {Boolean} anim (optional) false to cancel the default animation
31569 collapse : function(deep, anim){
31570 if(this.expanded && !this.isHiddenRoot()){
31571 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
31574 this.expanded = false;
31575 if((this.getOwnerTree().animate && anim !== false) || anim){
31576 this.ui.animCollapse(function(){
31577 this.fireEvent("collapse", this);
31579 this.collapseChildNodes(true);
31581 }.createDelegate(this));
31584 this.ui.collapse();
31585 this.fireEvent("collapse", this);
31589 var cs = this.childNodes;
31590 for(var i = 0, len = cs.length; i < len; i++) {
31591 cs[i].collapse(true, false);
31597 delayedExpand : function(delay){
31598 if(!this.expandProcId){
31599 this.expandProcId = this.expand.defer(delay, this);
31604 cancelExpand : function(){
31605 if(this.expandProcId){
31606 clearTimeout(this.expandProcId);
31608 this.expandProcId = false;
31612 * Toggles expanded/collapsed state of the node
31614 toggle : function(){
31623 * Ensures all parent nodes are expanded
31625 ensureVisible : function(callback){
31626 var tree = this.getOwnerTree();
31627 tree.expandPath(this.parentNode.getPath(), false, function(){
31628 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
31629 Roo.callback(callback);
31630 }.createDelegate(this));
31634 * Expand all child nodes
31635 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
31637 expandChildNodes : function(deep){
31638 var cs = this.childNodes;
31639 for(var i = 0, len = cs.length; i < len; i++) {
31640 cs[i].expand(deep);
31645 * Collapse all child nodes
31646 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
31648 collapseChildNodes : function(deep){
31649 var cs = this.childNodes;
31650 for(var i = 0, len = cs.length; i < len; i++) {
31651 cs[i].collapse(deep);
31656 * Disables this node
31658 disable : function(){
31659 this.disabled = true;
31661 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
31662 this.ui.onDisableChange(this, true);
31664 this.fireEvent("disabledchange", this, true);
31668 * Enables this node
31670 enable : function(){
31671 this.disabled = false;
31672 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
31673 this.ui.onDisableChange(this, false);
31675 this.fireEvent("disabledchange", this, false);
31679 renderChildren : function(suppressEvent){
31680 if(suppressEvent !== false){
31681 this.fireEvent("beforechildrenrendered", this);
31683 var cs = this.childNodes;
31684 for(var i = 0, len = cs.length; i < len; i++){
31685 cs[i].render(true);
31687 this.childrenRendered = true;
31691 sort : function(fn, scope){
31692 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
31693 if(this.childrenRendered){
31694 var cs = this.childNodes;
31695 for(var i = 0, len = cs.length; i < len; i++){
31696 cs[i].render(true);
31702 render : function(bulkRender){
31703 this.ui.render(bulkRender);
31704 if(!this.rendered){
31705 this.rendered = true;
31707 this.expanded = false;
31708 this.expand(false, false);
31714 renderIndent : function(deep, refresh){
31716 this.ui.childIndent = null;
31718 this.ui.renderIndent();
31719 if(deep === true && this.childrenRendered){
31720 var cs = this.childNodes;
31721 for(var i = 0, len = cs.length; i < len; i++){
31722 cs[i].renderIndent(true, refresh);
31728 * Ext JS Library 1.1.1
31729 * Copyright(c) 2006-2007, Ext JS, LLC.
31731 * Originally Released Under LGPL - original licence link has changed is not relivant.
31734 * <script type="text/javascript">
31738 * @class Roo.tree.AsyncTreeNode
31739 * @extends Roo.tree.TreeNode
31740 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
31742 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
31744 Roo.tree.AsyncTreeNode = function(config){
31745 this.loaded = false;
31746 this.loading = false;
31747 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
31749 * @event beforeload
31750 * Fires before this node is loaded, return false to cancel
31751 * @param {Node} this This node
31753 this.addEvents({'beforeload':true, 'load': true});
31756 * Fires when this node is loaded
31757 * @param {Node} this This node
31760 * The loader used by this node (defaults to using the tree's defined loader)
31765 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
31766 expand : function(deep, anim, callback){
31767 if(this.loading){ // if an async load is already running, waiting til it's done
31769 var f = function(){
31770 if(!this.loading){ // done loading
31771 clearInterval(timer);
31772 this.expand(deep, anim, callback);
31774 }.createDelegate(this);
31775 timer = setInterval(f, 200);
31779 if(this.fireEvent("beforeload", this) === false){
31782 this.loading = true;
31783 this.ui.beforeLoad(this);
31784 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
31786 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
31790 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
31794 * Returns true if this node is currently loading
31795 * @return {Boolean}
31797 isLoading : function(){
31798 return this.loading;
31801 loadComplete : function(deep, anim, callback){
31802 this.loading = false;
31803 this.loaded = true;
31804 this.ui.afterLoad(this);
31805 this.fireEvent("load", this);
31806 this.expand(deep, anim, callback);
31810 * Returns true if this node has been loaded
31811 * @return {Boolean}
31813 isLoaded : function(){
31814 return this.loaded;
31817 hasChildNodes : function(){
31818 if(!this.isLeaf() && !this.loaded){
31821 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
31826 * Trigger a reload for this node
31827 * @param {Function} callback
31829 reload : function(callback){
31830 this.collapse(false, false);
31831 while(this.firstChild){
31832 this.removeChild(this.firstChild);
31834 this.childrenRendered = false;
31835 this.loaded = false;
31836 if(this.isHiddenRoot()){
31837 this.expanded = false;
31839 this.expand(false, false, callback);
31843 * Ext JS Library 1.1.1
31844 * Copyright(c) 2006-2007, Ext JS, LLC.
31846 * Originally Released Under LGPL - original licence link has changed is not relivant.
31849 * <script type="text/javascript">
31853 * @class Roo.tree.TreeNodeUI
31855 * @param {Object} node The node to render
31856 * The TreeNode UI implementation is separate from the
31857 * tree implementation. Unless you are customizing the tree UI,
31858 * you should never have to use this directly.
31860 Roo.tree.TreeNodeUI = function(node){
31862 this.rendered = false;
31863 this.animating = false;
31864 this.emptyIcon = Roo.BLANK_IMAGE_URL;
31867 Roo.tree.TreeNodeUI.prototype = {
31868 removeChild : function(node){
31870 this.ctNode.removeChild(node.ui.getEl());
31874 beforeLoad : function(){
31875 this.addClass("x-tree-node-loading");
31878 afterLoad : function(){
31879 this.removeClass("x-tree-node-loading");
31882 onTextChange : function(node, text, oldText){
31884 this.textNode.innerHTML = text;
31888 onDisableChange : function(node, state){
31889 this.disabled = state;
31891 this.addClass("x-tree-node-disabled");
31893 this.removeClass("x-tree-node-disabled");
31897 onSelectedChange : function(state){
31900 this.addClass("x-tree-selected");
31903 this.removeClass("x-tree-selected");
31907 onMove : function(tree, node, oldParent, newParent, index, refNode){
31908 this.childIndent = null;
31910 var targetNode = newParent.ui.getContainer();
31911 if(!targetNode){//target not rendered
31912 this.holder = document.createElement("div");
31913 this.holder.appendChild(this.wrap);
31916 var insertBefore = refNode ? refNode.ui.getEl() : null;
31918 targetNode.insertBefore(this.wrap, insertBefore);
31920 targetNode.appendChild(this.wrap);
31922 this.node.renderIndent(true);
31926 addClass : function(cls){
31928 Roo.fly(this.elNode).addClass(cls);
31932 removeClass : function(cls){
31934 Roo.fly(this.elNode).removeClass(cls);
31938 remove : function(){
31940 this.holder = document.createElement("div");
31941 this.holder.appendChild(this.wrap);
31945 fireEvent : function(){
31946 return this.node.fireEvent.apply(this.node, arguments);
31949 initEvents : function(){
31950 this.node.on("move", this.onMove, this);
31951 var E = Roo.EventManager;
31952 var a = this.anchor;
31954 var el = Roo.fly(a, '_treeui');
31956 if(Roo.isOpera){ // opera render bug ignores the CSS
31957 el.setStyle("text-decoration", "none");
31960 el.on("click", this.onClick, this);
31961 el.on("dblclick", this.onDblClick, this);
31964 Roo.EventManager.on(this.checkbox,
31965 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
31968 el.on("contextmenu", this.onContextMenu, this);
31970 var icon = Roo.fly(this.iconNode);
31971 icon.on("click", this.onClick, this);
31972 icon.on("dblclick", this.onDblClick, this);
31973 icon.on("contextmenu", this.onContextMenu, this);
31974 E.on(this.ecNode, "click", this.ecClick, this, true);
31976 if(this.node.disabled){
31977 this.addClass("x-tree-node-disabled");
31979 if(this.node.hidden){
31980 this.addClass("x-tree-node-disabled");
31982 var ot = this.node.getOwnerTree();
31983 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
31984 if(dd && (!this.node.isRoot || ot.rootVisible)){
31985 Roo.dd.Registry.register(this.elNode, {
31987 handles: this.getDDHandles(),
31993 getDDHandles : function(){
31994 return [this.iconNode, this.textNode];
31999 this.wrap.style.display = "none";
32005 this.wrap.style.display = "";
32009 onContextMenu : function(e){
32010 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
32011 e.preventDefault();
32013 this.fireEvent("contextmenu", this.node, e);
32017 onClick : function(e){
32022 if(this.fireEvent("beforeclick", this.node, e) !== false){
32023 if(!this.disabled && this.node.attributes.href){
32024 this.fireEvent("click", this.node, e);
32027 e.preventDefault();
32032 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
32033 this.node.toggle();
32036 this.fireEvent("click", this.node, e);
32042 onDblClick : function(e){
32043 e.preventDefault();
32048 this.toggleCheck();
32050 if(!this.animating && this.node.hasChildNodes()){
32051 this.node.toggle();
32053 this.fireEvent("dblclick", this.node, e);
32056 onCheckChange : function(){
32057 var checked = this.checkbox.checked;
32058 this.node.attributes.checked = checked;
32059 this.fireEvent('checkchange', this.node, checked);
32062 ecClick : function(e){
32063 if(!this.animating && this.node.hasChildNodes()){
32064 this.node.toggle();
32068 startDrop : function(){
32069 this.dropping = true;
32072 // delayed drop so the click event doesn't get fired on a drop
32073 endDrop : function(){
32074 setTimeout(function(){
32075 this.dropping = false;
32076 }.createDelegate(this), 50);
32079 expand : function(){
32080 this.updateExpandIcon();
32081 this.ctNode.style.display = "";
32084 focus : function(){
32085 if(!this.node.preventHScroll){
32086 try{this.anchor.focus();
32088 }else if(!Roo.isIE){
32090 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
32091 var l = noscroll.scrollLeft;
32092 this.anchor.focus();
32093 noscroll.scrollLeft = l;
32098 toggleCheck : function(value){
32099 var cb = this.checkbox;
32101 cb.checked = (value === undefined ? !cb.checked : value);
32107 this.anchor.blur();
32111 animExpand : function(callback){
32112 var ct = Roo.get(this.ctNode);
32114 if(!this.node.hasChildNodes()){
32115 this.updateExpandIcon();
32116 this.ctNode.style.display = "";
32117 Roo.callback(callback);
32120 this.animating = true;
32121 this.updateExpandIcon();
32124 callback : function(){
32125 this.animating = false;
32126 Roo.callback(callback);
32129 duration: this.node.ownerTree.duration || .25
32133 highlight : function(){
32134 var tree = this.node.getOwnerTree();
32135 Roo.fly(this.wrap).highlight(
32136 tree.hlColor || "C3DAF9",
32137 {endColor: tree.hlBaseColor}
32141 collapse : function(){
32142 this.updateExpandIcon();
32143 this.ctNode.style.display = "none";
32146 animCollapse : function(callback){
32147 var ct = Roo.get(this.ctNode);
32148 ct.enableDisplayMode('block');
32151 this.animating = true;
32152 this.updateExpandIcon();
32155 callback : function(){
32156 this.animating = false;
32157 Roo.callback(callback);
32160 duration: this.node.ownerTree.duration || .25
32164 getContainer : function(){
32165 return this.ctNode;
32168 getEl : function(){
32172 appendDDGhost : function(ghostNode){
32173 ghostNode.appendChild(this.elNode.cloneNode(true));
32176 getDDRepairXY : function(){
32177 return Roo.lib.Dom.getXY(this.iconNode);
32180 onRender : function(){
32184 render : function(bulkRender){
32185 var n = this.node, a = n.attributes;
32186 var targetNode = n.parentNode ?
32187 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
32189 if(!this.rendered){
32190 this.rendered = true;
32192 this.renderElements(n, a, targetNode, bulkRender);
32195 if(this.textNode.setAttributeNS){
32196 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
32198 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
32201 this.textNode.setAttribute("ext:qtip", a.qtip);
32203 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
32206 }else if(a.qtipCfg){
32207 a.qtipCfg.target = Roo.id(this.textNode);
32208 Roo.QuickTips.register(a.qtipCfg);
32211 if(!this.node.expanded){
32212 this.updateExpandIcon();
32215 if(bulkRender === true) {
32216 targetNode.appendChild(this.wrap);
32221 renderElements : function(n, a, targetNode, bulkRender){
32222 // add some indent caching, this helps performance when rendering a large tree
32223 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
32224 var t = n.getOwnerTree();
32225 var txt = t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
32226 var tip = t.rendererTip ? t.rendererTip(n.attributes) : txt;
32227 var cb = typeof a.checked == 'boolean';
32228 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
32229 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
32230 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
32231 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
32232 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
32233 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
32234 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
32235 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
32236 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
32237 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
32240 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
32241 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
32242 n.nextSibling.ui.getEl(), buf.join(""));
32244 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
32247 this.elNode = this.wrap.childNodes[0];
32248 this.ctNode = this.wrap.childNodes[1];
32249 var cs = this.elNode.childNodes;
32250 this.indentNode = cs[0];
32251 this.ecNode = cs[1];
32252 this.iconNode = cs[2];
32255 this.checkbox = cs[3];
32258 this.anchor = cs[index];
32259 this.textNode = cs[index].firstChild;
32262 getAnchor : function(){
32263 return this.anchor;
32266 getTextEl : function(){
32267 return this.textNode;
32270 getIconEl : function(){
32271 return this.iconNode;
32274 isChecked : function(){
32275 return this.checkbox ? this.checkbox.checked : false;
32278 updateExpandIcon : function(){
32280 var n = this.node, c1, c2;
32281 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
32282 var hasChild = n.hasChildNodes();
32286 c1 = "x-tree-node-collapsed";
32287 c2 = "x-tree-node-expanded";
32290 c1 = "x-tree-node-expanded";
32291 c2 = "x-tree-node-collapsed";
32294 this.removeClass("x-tree-node-leaf");
32295 this.wasLeaf = false;
32297 if(this.c1 != c1 || this.c2 != c2){
32298 Roo.fly(this.elNode).replaceClass(c1, c2);
32299 this.c1 = c1; this.c2 = c2;
32303 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
32306 this.wasLeaf = true;
32309 var ecc = "x-tree-ec-icon "+cls;
32310 if(this.ecc != ecc){
32311 this.ecNode.className = ecc;
32317 getChildIndent : function(){
32318 if(!this.childIndent){
32322 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
32324 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
32326 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
32331 this.childIndent = buf.join("");
32333 return this.childIndent;
32336 renderIndent : function(){
32339 var p = this.node.parentNode;
32341 indent = p.ui.getChildIndent();
32343 if(this.indentMarkup != indent){ // don't rerender if not required
32344 this.indentNode.innerHTML = indent;
32345 this.indentMarkup = indent;
32347 this.updateExpandIcon();
32352 Roo.tree.RootTreeNodeUI = function(){
32353 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
32355 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
32356 render : function(){
32357 if(!this.rendered){
32358 var targetNode = this.node.ownerTree.innerCt.dom;
32359 this.node.expanded = true;
32360 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
32361 this.wrap = this.ctNode = targetNode.firstChild;
32364 collapse : function(){
32366 expand : function(){
32370 * Ext JS Library 1.1.1
32371 * Copyright(c) 2006-2007, Ext JS, LLC.
32373 * Originally Released Under LGPL - original licence link has changed is not relivant.
32376 * <script type="text/javascript">
32379 * @class Roo.tree.TreeLoader
32380 * @extends Roo.util.Observable
32381 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
32382 * nodes from a specified URL. The response must be a javascript Array definition
32383 * who's elements are node definition objects. eg:
32385 [{ 'id': 1, 'text': 'A folder Node', 'leaf': false },
32386 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }]
32389 * A server request is sent, and child nodes are loaded only when a node is expanded.
32390 * The loading node's id is passed to the server under the parameter name "node" to
32391 * enable the server to produce the correct child nodes.
32393 * To pass extra parameters, an event handler may be attached to the "beforeload"
32394 * event, and the parameters specified in the TreeLoader's baseParams property:
32396 myTreeLoader.on("beforeload", function(treeLoader, node) {
32397 this.baseParams.category = node.attributes.category;
32400 * This would pass an HTTP parameter called "category" to the server containing
32401 * the value of the Node's "category" attribute.
32403 * Creates a new Treeloader.
32404 * @param {Object} config A config object containing config properties.
32406 Roo.tree.TreeLoader = function(config){
32407 this.baseParams = {};
32408 this.requestMethod = "POST";
32409 Roo.apply(this, config);
32414 * @event beforeload
32415 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
32416 * @param {Object} This TreeLoader object.
32417 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
32418 * @param {Object} callback The callback function specified in the {@link #load} call.
32423 * Fires when the node has been successfuly loaded.
32424 * @param {Object} This TreeLoader object.
32425 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
32426 * @param {Object} response The response object containing the data from the server.
32430 * @event loadexception
32431 * Fires if the network request failed.
32432 * @param {Object} This TreeLoader object.
32433 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
32434 * @param {Object} response The response object containing the data from the server.
32436 loadexception : true,
32439 * Fires before a node is created, enabling you to return custom Node types
32440 * @param {Object} This TreeLoader object.
32441 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
32446 Roo.tree.TreeLoader.superclass.constructor.call(this);
32449 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
32451 * @cfg {String} dataUrl The URL from which to request a Json string which
32452 * specifies an array of node definition object representing the child nodes
32456 * @cfg {Object} baseParams (optional) An object containing properties which
32457 * specify HTTP parameters to be passed to each request for child nodes.
32460 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
32461 * created by this loader. If the attributes sent by the server have an attribute in this object,
32462 * they take priority.
32465 * @cfg {Object} uiProviders (optional) An object containing properties which
32467 * DEPRECIATED - use 'create' event handler to modify attributes - which affect creation.
32468 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
32469 * <i>uiProvider</i> attribute of a returned child node is a string rather
32470 * than a reference to a TreeNodeUI implementation, this that string value
32471 * is used as a property name in the uiProviders object. You can define the provider named
32472 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
32477 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
32478 * child nodes before loading.
32480 clearOnLoad : true,
32483 * @cfg {String} root (optional) Default to false. Use this to read data from an object
32484 * property on loading, rather than expecting an array. (eg. more compatible to a standard
32485 * Grid query { data : [ .....] }
32490 * @cfg {String} queryParam (optional)
32491 * Name of the query as it will be passed on the querystring (defaults to 'node')
32492 * eg. the request will be ?node=[id]
32499 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
32500 * This is called automatically when a node is expanded, but may be used to reload
32501 * a node (or append new children if the {@link #clearOnLoad} option is false.)
32502 * @param {Roo.tree.TreeNode} node
32503 * @param {Function} callback
32505 load : function(node, callback){
32506 if(this.clearOnLoad){
32507 while(node.firstChild){
32508 node.removeChild(node.firstChild);
32511 if(node.attributes.children){ // preloaded json children
32512 var cs = node.attributes.children;
32513 for(var i = 0, len = cs.length; i < len; i++){
32514 node.appendChild(this.createNode(cs[i]));
32516 if(typeof callback == "function"){
32519 }else if(this.dataUrl){
32520 this.requestData(node, callback);
32524 getParams: function(node){
32525 var buf = [], bp = this.baseParams;
32526 for(var key in bp){
32527 if(typeof bp[key] != "function"){
32528 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
32531 var n = this.queryParam === false ? 'node' : this.queryParam;
32532 buf.push(n + "=", encodeURIComponent(node.id));
32533 return buf.join("");
32536 requestData : function(node, callback){
32537 if(this.fireEvent("beforeload", this, node, callback) !== false){
32538 this.transId = Roo.Ajax.request({
32539 method:this.requestMethod,
32540 url: this.dataUrl||this.url,
32541 success: this.handleResponse,
32542 failure: this.handleFailure,
32544 argument: {callback: callback, node: node},
32545 params: this.getParams(node)
32548 // if the load is cancelled, make sure we notify
32549 // the node that we are done
32550 if(typeof callback == "function"){
32556 isLoading : function(){
32557 return this.transId ? true : false;
32560 abort : function(){
32561 if(this.isLoading()){
32562 Roo.Ajax.abort(this.transId);
32567 createNode : function(attr){
32568 // apply baseAttrs, nice idea Corey!
32569 if(this.baseAttrs){
32570 Roo.applyIf(attr, this.baseAttrs);
32572 if(this.applyLoader !== false){
32573 attr.loader = this;
32575 // uiProvider = depreciated..
32577 if(typeof(attr.uiProvider) == 'string'){
32578 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
32579 /** eval:var:attr */ eval(attr.uiProvider);
32581 if(typeof(this.uiProviders['default']) != 'undefined') {
32582 attr.uiProvider = this.uiProviders['default'];
32585 this.fireEvent('create', this, attr);
32587 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
32589 new Roo.tree.TreeNode(attr) :
32590 new Roo.tree.AsyncTreeNode(attr));
32593 processResponse : function(response, node, callback){
32594 var json = response.responseText;
32597 var o = /** eval:var:zzzzzzzzzz */ eval("("+json+")");
32598 if (this.root !== false) {
32602 for(var i = 0, len = o.length; i < len; i++){
32603 var n = this.createNode(o[i]);
32605 node.appendChild(n);
32608 if(typeof callback == "function"){
32609 callback(this, node);
32612 this.handleFailure(response);
32616 handleResponse : function(response){
32617 this.transId = false;
32618 var a = response.argument;
32619 this.processResponse(response, a.node, a.callback);
32620 this.fireEvent("load", this, a.node, response);
32623 handleFailure : function(response){
32624 this.transId = false;
32625 var a = response.argument;
32626 this.fireEvent("loadexception", this, a.node, response);
32627 if(typeof a.callback == "function"){
32628 a.callback(this, a.node);
32633 * Ext JS Library 1.1.1
32634 * Copyright(c) 2006-2007, Ext JS, LLC.
32636 * Originally Released Under LGPL - original licence link has changed is not relivant.
32639 * <script type="text/javascript">
32643 * @class Roo.tree.TreeFilter
32644 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
32645 * @param {TreePanel} tree
32646 * @param {Object} config (optional)
32648 Roo.tree.TreeFilter = function(tree, config){
32650 this.filtered = {};
32651 Roo.apply(this, config);
32654 Roo.tree.TreeFilter.prototype = {
32661 * Filter the data by a specific attribute.
32662 * @param {String/RegExp} value Either string that the attribute value
32663 * should start with or a RegExp to test against the attribute
32664 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
32665 * @param {TreeNode} startNode (optional) The node to start the filter at.
32667 filter : function(value, attr, startNode){
32668 attr = attr || "text";
32670 if(typeof value == "string"){
32671 var vlen = value.length;
32672 // auto clear empty filter
32673 if(vlen == 0 && this.clearBlank){
32677 value = value.toLowerCase();
32679 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
32681 }else if(value.exec){ // regex?
32683 return value.test(n.attributes[attr]);
32686 throw 'Illegal filter type, must be string or regex';
32688 this.filterBy(f, null, startNode);
32692 * Filter by a function. The passed function will be called with each
32693 * node in the tree (or from the startNode). If the function returns true, the node is kept
32694 * otherwise it is filtered. If a node is filtered, its children are also filtered.
32695 * @param {Function} fn The filter function
32696 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
32698 filterBy : function(fn, scope, startNode){
32699 startNode = startNode || this.tree.root;
32700 if(this.autoClear){
32703 var af = this.filtered, rv = this.reverse;
32704 var f = function(n){
32705 if(n == startNode){
32711 var m = fn.call(scope || n, n);
32719 startNode.cascade(f);
32722 if(typeof id != "function"){
32724 if(n && n.parentNode){
32725 n.parentNode.removeChild(n);
32733 * Clears the current filter. Note: with the "remove" option
32734 * set a filter cannot be cleared.
32736 clear : function(){
32738 var af = this.filtered;
32740 if(typeof id != "function"){
32747 this.filtered = {};
32752 * Ext JS Library 1.1.1
32753 * Copyright(c) 2006-2007, Ext JS, LLC.
32755 * Originally Released Under LGPL - original licence link has changed is not relivant.
32758 * <script type="text/javascript">
32763 * @class Roo.tree.TreeSorter
32764 * Provides sorting of nodes in a TreePanel
32766 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
32767 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
32768 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
32769 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
32770 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
32771 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
32773 * @param {TreePanel} tree
32774 * @param {Object} config
32776 Roo.tree.TreeSorter = function(tree, config){
32777 Roo.apply(this, config);
32778 tree.on("beforechildrenrendered", this.doSort, this);
32779 tree.on("append", this.updateSort, this);
32780 tree.on("insert", this.updateSort, this);
32782 var dsc = this.dir && this.dir.toLowerCase() == "desc";
32783 var p = this.property || "text";
32784 var sortType = this.sortType;
32785 var fs = this.folderSort;
32786 var cs = this.caseSensitive === true;
32787 var leafAttr = this.leafAttr || 'leaf';
32789 this.sortFn = function(n1, n2){
32791 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
32794 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
32798 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
32799 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
32801 return dsc ? +1 : -1;
32803 return dsc ? -1 : +1;
32810 Roo.tree.TreeSorter.prototype = {
32811 doSort : function(node){
32812 node.sort(this.sortFn);
32815 compareNodes : function(n1, n2){
32816 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
32819 updateSort : function(tree, node){
32820 if(node.childrenRendered){
32821 this.doSort.defer(1, this, [node]);
32826 * Ext JS Library 1.1.1
32827 * Copyright(c) 2006-2007, Ext JS, LLC.
32829 * Originally Released Under LGPL - original licence link has changed is not relivant.
32832 * <script type="text/javascript">
32835 if(Roo.dd.DropZone){
32837 Roo.tree.TreeDropZone = function(tree, config){
32838 this.allowParentInsert = false;
32839 this.allowContainerDrop = false;
32840 this.appendOnly = false;
32841 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
32843 this.lastInsertClass = "x-tree-no-status";
32844 this.dragOverData = {};
32847 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
32848 ddGroup : "TreeDD",
32850 expandDelay : 1000,
32852 expandNode : function(node){
32853 if(node.hasChildNodes() && !node.isExpanded()){
32854 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
32858 queueExpand : function(node){
32859 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
32862 cancelExpand : function(){
32863 if(this.expandProcId){
32864 clearTimeout(this.expandProcId);
32865 this.expandProcId = false;
32869 isValidDropPoint : function(n, pt, dd, e, data){
32870 if(!n || !data){ return false; }
32871 var targetNode = n.node;
32872 var dropNode = data.node;
32873 // default drop rules
32874 if(!(targetNode && targetNode.isTarget && pt)){
32877 if(pt == "append" && targetNode.allowChildren === false){
32880 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
32883 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
32886 // reuse the object
32887 var overEvent = this.dragOverData;
32888 overEvent.tree = this.tree;
32889 overEvent.target = targetNode;
32890 overEvent.data = data;
32891 overEvent.point = pt;
32892 overEvent.source = dd;
32893 overEvent.rawEvent = e;
32894 overEvent.dropNode = dropNode;
32895 overEvent.cancel = false;
32896 var result = this.tree.fireEvent("nodedragover", overEvent);
32897 return overEvent.cancel === false && result !== false;
32900 getDropPoint : function(e, n, dd){
32903 return tn.allowChildren !== false ? "append" : false; // always append for root
32905 var dragEl = n.ddel;
32906 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
32907 var y = Roo.lib.Event.getPageY(e);
32908 //var noAppend = tn.allowChildren === false || tn.isLeaf();
32910 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
32911 var noAppend = tn.allowChildren === false;
32912 if(this.appendOnly || tn.parentNode.allowChildren === false){
32913 return noAppend ? false : "append";
32915 var noBelow = false;
32916 if(!this.allowParentInsert){
32917 noBelow = tn.hasChildNodes() && tn.isExpanded();
32919 var q = (b - t) / (noAppend ? 2 : 3);
32920 if(y >= t && y < (t + q)){
32922 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
32929 onNodeEnter : function(n, dd, e, data){
32930 this.cancelExpand();
32933 onNodeOver : function(n, dd, e, data){
32934 var pt = this.getDropPoint(e, n, dd);
32937 // auto node expand check
32938 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
32939 this.queueExpand(node);
32940 }else if(pt != "append"){
32941 this.cancelExpand();
32944 // set the insert point style on the target node
32945 var returnCls = this.dropNotAllowed;
32946 if(this.isValidDropPoint(n, pt, dd, e, data)){
32951 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
32952 cls = "x-tree-drag-insert-above";
32953 }else if(pt == "below"){
32954 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
32955 cls = "x-tree-drag-insert-below";
32957 returnCls = "x-tree-drop-ok-append";
32958 cls = "x-tree-drag-append";
32960 if(this.lastInsertClass != cls){
32961 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
32962 this.lastInsertClass = cls;
32969 onNodeOut : function(n, dd, e, data){
32970 this.cancelExpand();
32971 this.removeDropIndicators(n);
32974 onNodeDrop : function(n, dd, e, data){
32975 var point = this.getDropPoint(e, n, dd);
32976 var targetNode = n.node;
32977 targetNode.ui.startDrop();
32978 if(!this.isValidDropPoint(n, point, dd, e, data)){
32979 targetNode.ui.endDrop();
32982 // first try to find the drop node
32983 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
32986 target: targetNode,
32991 dropNode: dropNode,
32994 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
32995 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
32996 targetNode.ui.endDrop();
32999 // allow target changing
33000 targetNode = dropEvent.target;
33001 if(point == "append" && !targetNode.isExpanded()){
33002 targetNode.expand(false, null, function(){
33003 this.completeDrop(dropEvent);
33004 }.createDelegate(this));
33006 this.completeDrop(dropEvent);
33011 completeDrop : function(de){
33012 var ns = de.dropNode, p = de.point, t = de.target;
33013 if(!(ns instanceof Array)){
33017 for(var i = 0, len = ns.length; i < len; i++){
33020 t.parentNode.insertBefore(n, t);
33021 }else if(p == "below"){
33022 t.parentNode.insertBefore(n, t.nextSibling);
33028 if(this.tree.hlDrop){
33032 this.tree.fireEvent("nodedrop", de);
33035 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
33036 if(this.tree.hlDrop){
33037 dropNode.ui.focus();
33038 dropNode.ui.highlight();
33040 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
33043 getTree : function(){
33047 removeDropIndicators : function(n){
33050 Roo.fly(el).removeClass([
33051 "x-tree-drag-insert-above",
33052 "x-tree-drag-insert-below",
33053 "x-tree-drag-append"]);
33054 this.lastInsertClass = "_noclass";
33058 beforeDragDrop : function(target, e, id){
33059 this.cancelExpand();
33063 afterRepair : function(data){
33064 if(data && Roo.enableFx){
33065 data.node.ui.highlight();
33074 * Ext JS Library 1.1.1
33075 * Copyright(c) 2006-2007, Ext JS, LLC.
33077 * Originally Released Under LGPL - original licence link has changed is not relivant.
33080 * <script type="text/javascript">
33084 if(Roo.dd.DragZone){
33085 Roo.tree.TreeDragZone = function(tree, config){
33086 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
33090 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
33091 ddGroup : "TreeDD",
33093 onBeforeDrag : function(data, e){
33095 return n && n.draggable && !n.disabled;
33098 onInitDrag : function(e){
33099 var data = this.dragData;
33100 this.tree.getSelectionModel().select(data.node);
33101 this.proxy.update("");
33102 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
33103 this.tree.fireEvent("startdrag", this.tree, data.node, e);
33106 getRepairXY : function(e, data){
33107 return data.node.ui.getDDRepairXY();
33110 onEndDrag : function(data, e){
33111 this.tree.fireEvent("enddrag", this.tree, data.node, e);
33114 onValidDrop : function(dd, e, id){
33115 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
33119 beforeInvalidDrop : function(e, id){
33120 // this scrolls the original position back into view
33121 var sm = this.tree.getSelectionModel();
33122 sm.clearSelections();
33123 sm.select(this.dragData.node);
33128 * Ext JS Library 1.1.1
33129 * Copyright(c) 2006-2007, Ext JS, LLC.
33131 * Originally Released Under LGPL - original licence link has changed is not relivant.
33134 * <script type="text/javascript">
33137 * @class Roo.tree.TreeEditor
33138 * @extends Roo.Editor
33139 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
33140 * as the editor field.
33142 * @param {TreePanel} tree
33143 * @param {Object} config Either a prebuilt {@link Roo.form.Field} instance or a Field config object
33145 Roo.tree.TreeEditor = function(tree, config){
33146 config = config || {};
33147 var field = config.events ? config : new Roo.form.TextField(config);
33148 Roo.tree.TreeEditor.superclass.constructor.call(this, field);
33152 tree.on('beforeclick', this.beforeNodeClick, this);
33153 tree.getTreeEl().on('mousedown', this.hide, this);
33154 this.on('complete', this.updateNode, this);
33155 this.on('beforestartedit', this.fitToTree, this);
33156 this.on('startedit', this.bindScroll, this, {delay:10});
33157 this.on('specialkey', this.onSpecialKey, this);
33160 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
33162 * @cfg {String} alignment
33163 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
33169 * @cfg {Boolean} hideEl
33170 * True to hide the bound element while the editor is displayed (defaults to false)
33174 * @cfg {String} cls
33175 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
33177 cls: "x-small-editor x-tree-editor",
33179 * @cfg {Boolean} shim
33180 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
33186 * @cfg {Number} maxWidth
33187 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
33188 * the containing tree element's size, it will be automatically limited for you to the container width, taking
33189 * scroll and client offsets into account prior to each edit.
33196 fitToTree : function(ed, el){
33197 var td = this.tree.getTreeEl().dom, nd = el.dom;
33198 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
33199 td.scrollLeft = nd.offsetLeft;
33203 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
33204 this.setSize(w, '');
33208 triggerEdit : function(node){
33209 this.completeEdit();
33210 this.editNode = node;
33211 this.startEdit(node.ui.textNode, node.text);
33215 bindScroll : function(){
33216 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
33220 beforeNodeClick : function(node, e){
33221 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
33222 this.lastClick = new Date();
33223 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
33225 this.triggerEdit(node);
33231 updateNode : function(ed, value){
33232 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
33233 this.editNode.setText(value);
33237 onHide : function(){
33238 Roo.tree.TreeEditor.superclass.onHide.call(this);
33240 this.editNode.ui.focus();
33245 onSpecialKey : function(field, e){
33246 var k = e.getKey();
33250 }else if(k == e.ENTER && !e.hasModifier()){
33252 this.completeEdit();
33255 });//<Script type="text/javascript">
33258 * Ext JS Library 1.1.1
33259 * Copyright(c) 2006-2007, Ext JS, LLC.
33261 * Originally Released Under LGPL - original licence link has changed is not relivant.
33264 * <script type="text/javascript">
33268 * Not documented??? - probably should be...
33271 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
33272 //focus: Roo.emptyFn, // prevent odd scrolling behavior
33274 renderElements : function(n, a, targetNode, bulkRender){
33275 //consel.log("renderElements?");
33276 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
33278 var t = n.getOwnerTree();
33279 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
33281 var cols = t.columns;
33282 var bw = t.borderWidth;
33284 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
33285 var cb = typeof a.checked == "boolean";
33286 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
33287 var colcls = 'x-t-' + tid + '-c0';
33289 '<li class="x-tree-node">',
33292 '<div class="x-tree-node-el ', a.cls,'">',
33294 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
33297 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
33298 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
33299 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
33300 (a.icon ? ' x-tree-node-inline-icon' : ''),
33301 (a.iconCls ? ' '+a.iconCls : ''),
33302 '" unselectable="on" />',
33303 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
33304 (a.checked ? 'checked="checked" />' : ' />')) : ''),
33306 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
33307 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
33308 '<span unselectable="on" qtip="' + tx + '">',
33312 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
33313 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>'
33315 for(var i = 1, len = cols.length; i < len; i++){
33317 colcls = 'x-t-' + tid + '-c' +i;
33318 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
33319 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
33320 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
33326 '<div class="x-clear"></div></div>',
33327 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
33330 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
33331 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
33332 n.nextSibling.ui.getEl(), buf.join(""));
33334 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
33336 var el = this.wrap.firstChild;
33338 this.elNode = el.firstChild;
33339 this.ranchor = el.childNodes[1];
33340 this.ctNode = this.wrap.childNodes[1];
33341 var cs = el.firstChild.childNodes;
33342 this.indentNode = cs[0];
33343 this.ecNode = cs[1];
33344 this.iconNode = cs[2];
33347 this.checkbox = cs[3];
33350 this.anchor = cs[index];
33352 this.textNode = cs[index].firstChild;
33354 //el.on("click", this.onClick, this);
33355 //el.on("dblclick", this.onDblClick, this);
33358 // console.log(this);
33360 initEvents : function(){
33361 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
33364 var a = this.ranchor;
33366 var el = Roo.get(a);
33368 if(Roo.isOpera){ // opera render bug ignores the CSS
33369 el.setStyle("text-decoration", "none");
33372 el.on("click", this.onClick, this);
33373 el.on("dblclick", this.onDblClick, this);
33374 el.on("contextmenu", this.onContextMenu, this);
33378 /*onSelectedChange : function(state){
33381 this.addClass("x-tree-selected");
33384 this.removeClass("x-tree-selected");
33387 addClass : function(cls){
33389 Roo.fly(this.elRow).addClass(cls);
33395 removeClass : function(cls){
33397 Roo.fly(this.elRow).removeClass(cls);
33403 });//<Script type="text/javascript">
33407 * Ext JS Library 1.1.1
33408 * Copyright(c) 2006-2007, Ext JS, LLC.
33410 * Originally Released Under LGPL - original licence link has changed is not relivant.
33413 * <script type="text/javascript">
33418 * @class Roo.tree.ColumnTree
33419 * @extends Roo.data.TreePanel
33420 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
33421 * @cfg {int} borderWidth compined right/left border allowance
33423 * @param {String/HTMLElement/Element} el The container element
33424 * @param {Object} config
33426 Roo.tree.ColumnTree = function(el, config)
33428 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
33432 * Fire this event on a container when it resizes
33433 * @param {int} w Width
33434 * @param {int} h Height
33438 this.on('resize', this.onResize, this);
33441 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
33445 borderWidth: Roo.isBorderBox ? 0 : 2,
33448 render : function(){
33449 // add the header.....
33451 Roo.tree.ColumnTree.superclass.render.apply(this);
33453 this.el.addClass('x-column-tree');
33455 this.headers = this.el.createChild(
33456 {cls:'x-tree-headers'},this.innerCt.dom);
33458 var cols = this.columns, c;
33459 var totalWidth = 0;
33461 var len = cols.length;
33462 for(var i = 0; i < len; i++){
33464 totalWidth += c.width;
33465 this.headEls.push(this.headers.createChild({
33466 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
33468 cls:'x-tree-hd-text',
33471 style:'width:'+(c.width-this.borderWidth)+'px;'
33474 this.headers.createChild({cls:'x-clear'});
33475 // prevent floats from wrapping when clipped
33476 this.headers.setWidth(totalWidth);
33477 //this.innerCt.setWidth(totalWidth);
33478 this.innerCt.setStyle({ overflow: 'auto' });
33479 this.onResize(this.width, this.height);
33483 onResize : function(w,h)
33488 this.innerCt.setWidth(this.width);
33489 this.innerCt.setHeight(this.height-20);
33492 var cols = this.columns, c;
33493 var totalWidth = 0;
33495 var len = cols.length;
33496 for(var i = 0; i < len; i++){
33498 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
33499 // it's the expander..
33500 expEl = this.headEls[i];
33503 totalWidth += c.width;
33507 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
33509 this.headers.setWidth(w-20);
33518 * Ext JS Library 1.1.1
33519 * Copyright(c) 2006-2007, Ext JS, LLC.
33521 * Originally Released Under LGPL - original licence link has changed is not relivant.
33524 * <script type="text/javascript">
33528 * @class Roo.menu.Menu
33529 * @extends Roo.util.Observable
33530 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
33531 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
33533 * Creates a new Menu
33534 * @param {Object} config Configuration options
33536 Roo.menu.Menu = function(config){
33537 Roo.apply(this, config);
33538 this.id = this.id || Roo.id();
33541 * @event beforeshow
33542 * Fires before this menu is displayed
33543 * @param {Roo.menu.Menu} this
33547 * @event beforehide
33548 * Fires before this menu is hidden
33549 * @param {Roo.menu.Menu} this
33554 * Fires after this menu is displayed
33555 * @param {Roo.menu.Menu} this
33560 * Fires after this menu is hidden
33561 * @param {Roo.menu.Menu} this
33566 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
33567 * @param {Roo.menu.Menu} this
33568 * @param {Roo.menu.Item} menuItem The menu item that was clicked
33569 * @param {Roo.EventObject} e
33574 * Fires when the mouse is hovering over this menu
33575 * @param {Roo.menu.Menu} this
33576 * @param {Roo.EventObject} e
33577 * @param {Roo.menu.Item} menuItem The menu item that was clicked
33582 * Fires when the mouse exits this menu
33583 * @param {Roo.menu.Menu} this
33584 * @param {Roo.EventObject} e
33585 * @param {Roo.menu.Item} menuItem The menu item that was clicked
33590 * Fires when a menu item contained in this menu is clicked
33591 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
33592 * @param {Roo.EventObject} e
33596 if (this.registerMenu) {
33597 Roo.menu.MenuMgr.register(this);
33600 var mis = this.items;
33601 this.items = new Roo.util.MixedCollection();
33603 this.add.apply(this, mis);
33607 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
33609 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
33613 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
33614 * for bottom-right shadow (defaults to "sides")
33618 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
33619 * this menu (defaults to "tl-tr?")
33621 subMenuAlign : "tl-tr?",
33623 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
33624 * relative to its element of origin (defaults to "tl-bl?")
33626 defaultAlign : "tl-bl?",
33628 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
33630 allowOtherMenus : false,
33632 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
33634 registerMenu : true,
33639 render : function(){
33643 var el = this.el = new Roo.Layer({
33645 shadow:this.shadow,
33647 parentEl: this.parentEl || document.body,
33651 this.keyNav = new Roo.menu.MenuNav(this);
33654 el.addClass("x-menu-plain");
33657 el.addClass(this.cls);
33659 // generic focus element
33660 this.focusEl = el.createChild({
33661 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
33663 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
33664 ul.on("click", this.onClick, this);
33665 ul.on("mouseover", this.onMouseOver, this);
33666 ul.on("mouseout", this.onMouseOut, this);
33667 this.items.each(function(item){
33668 var li = document.createElement("li");
33669 li.className = "x-menu-list-item";
33670 ul.dom.appendChild(li);
33671 item.render(li, this);
33678 autoWidth : function(){
33679 var el = this.el, ul = this.ul;
33683 var w = this.width;
33686 }else if(Roo.isIE){
33687 el.setWidth(this.minWidth);
33688 var t = el.dom.offsetWidth; // force recalc
33689 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
33694 delayAutoWidth : function(){
33697 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
33699 this.awTask.delay(20);
33704 findTargetItem : function(e){
33705 var t = e.getTarget(".x-menu-list-item", this.ul, true);
33706 if(t && t.menuItemId){
33707 return this.items.get(t.menuItemId);
33712 onClick : function(e){
33714 if(t = this.findTargetItem(e)){
33716 this.fireEvent("click", this, t, e);
33721 setActiveItem : function(item, autoExpand){
33722 if(item != this.activeItem){
33723 if(this.activeItem){
33724 this.activeItem.deactivate();
33726 this.activeItem = item;
33727 item.activate(autoExpand);
33728 }else if(autoExpand){
33734 tryActivate : function(start, step){
33735 var items = this.items;
33736 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
33737 var item = items.get(i);
33738 if(!item.disabled && item.canActivate){
33739 this.setActiveItem(item, false);
33747 onMouseOver : function(e){
33749 if(t = this.findTargetItem(e)){
33750 if(t.canActivate && !t.disabled){
33751 this.setActiveItem(t, true);
33754 this.fireEvent("mouseover", this, e, t);
33758 onMouseOut : function(e){
33760 if(t = this.findTargetItem(e)){
33761 if(t == this.activeItem && t.shouldDeactivate(e)){
33762 this.activeItem.deactivate();
33763 delete this.activeItem;
33766 this.fireEvent("mouseout", this, e, t);
33770 * Read-only. Returns true if the menu is currently displayed, else false.
33773 isVisible : function(){
33774 return this.el && !this.hidden;
33778 * Displays this menu relative to another element
33779 * @param {String/HTMLElement/Roo.Element} element The element to align to
33780 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
33781 * the element (defaults to this.defaultAlign)
33782 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
33784 show : function(el, pos, parentMenu){
33785 this.parentMenu = parentMenu;
33789 this.fireEvent("beforeshow", this);
33790 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
33794 * Displays this menu at a specific xy position
33795 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
33796 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
33798 showAt : function(xy, parentMenu, /* private: */_e){
33799 this.parentMenu = parentMenu;
33804 this.fireEvent("beforeshow", this);
33805 xy = this.el.adjustForConstraints(xy);
33809 this.hidden = false;
33811 this.fireEvent("show", this);
33814 focus : function(){
33816 this.doFocus.defer(50, this);
33820 doFocus : function(){
33822 this.focusEl.focus();
33827 * Hides this menu and optionally all parent menus
33828 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
33830 hide : function(deep){
33831 if(this.el && this.isVisible()){
33832 this.fireEvent("beforehide", this);
33833 if(this.activeItem){
33834 this.activeItem.deactivate();
33835 this.activeItem = null;
33838 this.hidden = true;
33839 this.fireEvent("hide", this);
33841 if(deep === true && this.parentMenu){
33842 this.parentMenu.hide(true);
33847 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
33848 * Any of the following are valid:
33850 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
33851 * <li>An HTMLElement object which will be converted to a menu item</li>
33852 * <li>A menu item config object that will be created as a new menu item</li>
33853 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
33854 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
33859 var menu = new Roo.menu.Menu();
33861 // Create a menu item to add by reference
33862 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
33864 // Add a bunch of items at once using different methods.
33865 // Only the last item added will be returned.
33866 var item = menu.add(
33867 menuItem, // add existing item by ref
33868 'Dynamic Item', // new TextItem
33869 '-', // new separator
33870 { text: 'Config Item' } // new item by config
33873 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
33874 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
33877 var a = arguments, l = a.length, item;
33878 for(var i = 0; i < l; i++){
33880 if ((typeof(el) == "object") && el.xtype && el.xns) {
33881 el = Roo.factory(el, Roo.menu);
33884 if(el.render){ // some kind of Item
33885 item = this.addItem(el);
33886 }else if(typeof el == "string"){ // string
33887 if(el == "separator" || el == "-"){
33888 item = this.addSeparator();
33890 item = this.addText(el);
33892 }else if(el.tagName || el.el){ // element
33893 item = this.addElement(el);
33894 }else if(typeof el == "object"){ // must be menu item config?
33895 item = this.addMenuItem(el);
33902 * Returns this menu's underlying {@link Roo.Element} object
33903 * @return {Roo.Element} The element
33905 getEl : function(){
33913 * Adds a separator bar to the menu
33914 * @return {Roo.menu.Item} The menu item that was added
33916 addSeparator : function(){
33917 return this.addItem(new Roo.menu.Separator());
33921 * Adds an {@link Roo.Element} object to the menu
33922 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
33923 * @return {Roo.menu.Item} The menu item that was added
33925 addElement : function(el){
33926 return this.addItem(new Roo.menu.BaseItem(el));
33930 * Adds an existing object based on {@link Roo.menu.Item} to the menu
33931 * @param {Roo.menu.Item} item The menu item to add
33932 * @return {Roo.menu.Item} The menu item that was added
33934 addItem : function(item){
33935 this.items.add(item);
33937 var li = document.createElement("li");
33938 li.className = "x-menu-list-item";
33939 this.ul.dom.appendChild(li);
33940 item.render(li, this);
33941 this.delayAutoWidth();
33947 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
33948 * @param {Object} config A MenuItem config object
33949 * @return {Roo.menu.Item} The menu item that was added
33951 addMenuItem : function(config){
33952 if(!(config instanceof Roo.menu.Item)){
33953 if(typeof config.checked == "boolean"){ // must be check menu item config?
33954 config = new Roo.menu.CheckItem(config);
33956 config = new Roo.menu.Item(config);
33959 return this.addItem(config);
33963 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
33964 * @param {String} text The text to display in the menu item
33965 * @return {Roo.menu.Item} The menu item that was added
33967 addText : function(text){
33968 return this.addItem(new Roo.menu.TextItem({ text : text }));
33972 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
33973 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
33974 * @param {Roo.menu.Item} item The menu item to add
33975 * @return {Roo.menu.Item} The menu item that was added
33977 insert : function(index, item){
33978 this.items.insert(index, item);
33980 var li = document.createElement("li");
33981 li.className = "x-menu-list-item";
33982 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
33983 item.render(li, this);
33984 this.delayAutoWidth();
33990 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
33991 * @param {Roo.menu.Item} item The menu item to remove
33993 remove : function(item){
33994 this.items.removeKey(item.id);
33999 * Removes and destroys all items in the menu
34001 removeAll : function(){
34003 while(f = this.items.first()){
34009 // MenuNav is a private utility class used internally by the Menu
34010 Roo.menu.MenuNav = function(menu){
34011 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
34012 this.scope = this.menu = menu;
34015 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
34016 doRelay : function(e, h){
34017 var k = e.getKey();
34018 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
34019 this.menu.tryActivate(0, 1);
34022 return h.call(this.scope || this, e, this.menu);
34025 up : function(e, m){
34026 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
34027 m.tryActivate(m.items.length-1, -1);
34031 down : function(e, m){
34032 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
34033 m.tryActivate(0, 1);
34037 right : function(e, m){
34039 m.activeItem.expandMenu(true);
34043 left : function(e, m){
34045 if(m.parentMenu && m.parentMenu.activeItem){
34046 m.parentMenu.activeItem.activate();
34050 enter : function(e, m){
34052 e.stopPropagation();
34053 m.activeItem.onClick(e);
34054 m.fireEvent("click", this, m.activeItem);
34060 * Ext JS Library 1.1.1
34061 * Copyright(c) 2006-2007, Ext JS, LLC.
34063 * Originally Released Under LGPL - original licence link has changed is not relivant.
34066 * <script type="text/javascript">
34070 * @class Roo.menu.MenuMgr
34071 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
34074 Roo.menu.MenuMgr = function(){
34075 var menus, active, groups = {}, attached = false, lastShow = new Date();
34077 // private - called when first menu is created
34080 active = new Roo.util.MixedCollection();
34081 Roo.get(document).addKeyListener(27, function(){
34082 if(active.length > 0){
34089 function hideAll(){
34090 if(active && active.length > 0){
34091 var c = active.clone();
34092 c.each(function(m){
34099 function onHide(m){
34101 if(active.length < 1){
34102 Roo.get(document).un("mousedown", onMouseDown);
34108 function onShow(m){
34109 var last = active.last();
34110 lastShow = new Date();
34113 Roo.get(document).on("mousedown", onMouseDown);
34117 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
34118 m.parentMenu.activeChild = m;
34119 }else if(last && last.isVisible()){
34120 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
34125 function onBeforeHide(m){
34127 m.activeChild.hide();
34129 if(m.autoHideTimer){
34130 clearTimeout(m.autoHideTimer);
34131 delete m.autoHideTimer;
34136 function onBeforeShow(m){
34137 var pm = m.parentMenu;
34138 if(!pm && !m.allowOtherMenus){
34140 }else if(pm && pm.activeChild && active != m){
34141 pm.activeChild.hide();
34146 function onMouseDown(e){
34147 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
34153 function onBeforeCheck(mi, state){
34155 var g = groups[mi.group];
34156 for(var i = 0, l = g.length; i < l; i++){
34158 g[i].setChecked(false);
34167 * Hides all menus that are currently visible
34169 hideAll : function(){
34174 register : function(menu){
34178 menus[menu.id] = menu;
34179 menu.on("beforehide", onBeforeHide);
34180 menu.on("hide", onHide);
34181 menu.on("beforeshow", onBeforeShow);
34182 menu.on("show", onShow);
34183 var g = menu.group;
34184 if(g && menu.events["checkchange"]){
34188 groups[g].push(menu);
34189 menu.on("checkchange", onCheck);
34194 * Returns a {@link Roo.menu.Menu} object
34195 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
34196 * be used to generate and return a new Menu instance.
34198 get : function(menu){
34199 if(typeof menu == "string"){ // menu id
34200 return menus[menu];
34201 }else if(menu.events){ // menu instance
34203 }else if(typeof menu.length == 'number'){ // array of menu items?
34204 return new Roo.menu.Menu({items:menu});
34205 }else{ // otherwise, must be a config
34206 return new Roo.menu.Menu(menu);
34211 unregister : function(menu){
34212 delete menus[menu.id];
34213 menu.un("beforehide", onBeforeHide);
34214 menu.un("hide", onHide);
34215 menu.un("beforeshow", onBeforeShow);
34216 menu.un("show", onShow);
34217 var g = menu.group;
34218 if(g && menu.events["checkchange"]){
34219 groups[g].remove(menu);
34220 menu.un("checkchange", onCheck);
34225 registerCheckable : function(menuItem){
34226 var g = menuItem.group;
34231 groups[g].push(menuItem);
34232 menuItem.on("beforecheckchange", onBeforeCheck);
34237 unregisterCheckable : function(menuItem){
34238 var g = menuItem.group;
34240 groups[g].remove(menuItem);
34241 menuItem.un("beforecheckchange", onBeforeCheck);
34247 * Ext JS Library 1.1.1
34248 * Copyright(c) 2006-2007, Ext JS, LLC.
34250 * Originally Released Under LGPL - original licence link has changed is not relivant.
34253 * <script type="text/javascript">
34258 * @class Roo.menu.BaseItem
34259 * @extends Roo.Component
34260 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
34261 * management and base configuration options shared by all menu components.
34263 * Creates a new BaseItem
34264 * @param {Object} config Configuration options
34266 Roo.menu.BaseItem = function(config){
34267 Roo.menu.BaseItem.superclass.constructor.call(this, config);
34272 * Fires when this item is clicked
34273 * @param {Roo.menu.BaseItem} this
34274 * @param {Roo.EventObject} e
34279 * Fires when this item is activated
34280 * @param {Roo.menu.BaseItem} this
34284 * @event deactivate
34285 * Fires when this item is deactivated
34286 * @param {Roo.menu.BaseItem} this
34292 this.on("click", this.handler, this.scope, true);
34296 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
34298 * @cfg {Function} handler
34299 * A function that will handle the click event of this menu item (defaults to undefined)
34302 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
34304 canActivate : false,
34306 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
34308 activeClass : "x-menu-item-active",
34310 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
34312 hideOnClick : true,
34314 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
34319 ctype: "Roo.menu.BaseItem",
34322 actionMode : "container",
34325 render : function(container, parentMenu){
34326 this.parentMenu = parentMenu;
34327 Roo.menu.BaseItem.superclass.render.call(this, container);
34328 this.container.menuItemId = this.id;
34332 onRender : function(container, position){
34333 this.el = Roo.get(this.el);
34334 container.dom.appendChild(this.el.dom);
34338 onClick : function(e){
34339 if(!this.disabled && this.fireEvent("click", this, e) !== false
34340 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
34341 this.handleClick(e);
34348 activate : function(){
34352 var li = this.container;
34353 li.addClass(this.activeClass);
34354 this.region = li.getRegion().adjust(2, 2, -2, -2);
34355 this.fireEvent("activate", this);
34360 deactivate : function(){
34361 this.container.removeClass(this.activeClass);
34362 this.fireEvent("deactivate", this);
34366 shouldDeactivate : function(e){
34367 return !this.region || !this.region.contains(e.getPoint());
34371 handleClick : function(e){
34372 if(this.hideOnClick){
34373 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
34378 expandMenu : function(autoActivate){
34383 hideMenu : function(){
34388 * Ext JS Library 1.1.1
34389 * Copyright(c) 2006-2007, Ext JS, LLC.
34391 * Originally Released Under LGPL - original licence link has changed is not relivant.
34394 * <script type="text/javascript">
34398 * @class Roo.menu.Adapter
34399 * @extends Roo.menu.BaseItem
34400 * 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.
34401 * It provides basic rendering, activation management and enable/disable logic required to work in menus.
34403 * Creates a new Adapter
34404 * @param {Object} config Configuration options
34406 Roo.menu.Adapter = function(component, config){
34407 Roo.menu.Adapter.superclass.constructor.call(this, config);
34408 this.component = component;
34410 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
34412 canActivate : true,
34415 onRender : function(container, position){
34416 this.component.render(container);
34417 this.el = this.component.getEl();
34421 activate : function(){
34425 this.component.focus();
34426 this.fireEvent("activate", this);
34431 deactivate : function(){
34432 this.fireEvent("deactivate", this);
34436 disable : function(){
34437 this.component.disable();
34438 Roo.menu.Adapter.superclass.disable.call(this);
34442 enable : function(){
34443 this.component.enable();
34444 Roo.menu.Adapter.superclass.enable.call(this);
34448 * Ext JS Library 1.1.1
34449 * Copyright(c) 2006-2007, Ext JS, LLC.
34451 * Originally Released Under LGPL - original licence link has changed is not relivant.
34454 * <script type="text/javascript">
34458 * @class Roo.menu.TextItem
34459 * @extends Roo.menu.BaseItem
34460 * Adds a static text string to a menu, usually used as either a heading or group separator.
34461 * Note: old style constructor with text is still supported.
34464 * Creates a new TextItem
34465 * @param {Object} cfg Configuration
34467 Roo.menu.TextItem = function(cfg){
34468 if (typeof(cfg) == 'string') {
34471 Roo.apply(this,cfg);
34474 Roo.menu.TextItem.superclass.constructor.call(this);
34477 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
34479 * @cfg {Boolean} text Text to show on item.
34484 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
34486 hideOnClick : false,
34488 * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
34490 itemCls : "x-menu-text",
34493 onRender : function(){
34494 var s = document.createElement("span");
34495 s.className = this.itemCls;
34496 s.innerHTML = this.text;
34498 Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
34502 * Ext JS Library 1.1.1
34503 * Copyright(c) 2006-2007, Ext JS, LLC.
34505 * Originally Released Under LGPL - original licence link has changed is not relivant.
34508 * <script type="text/javascript">
34512 * @class Roo.menu.Separator
34513 * @extends Roo.menu.BaseItem
34514 * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
34515 * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
34517 * @param {Object} config Configuration options
34519 Roo.menu.Separator = function(config){
34520 Roo.menu.Separator.superclass.constructor.call(this, config);
34523 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
34525 * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
34527 itemCls : "x-menu-sep",
34529 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
34531 hideOnClick : false,
34534 onRender : function(li){
34535 var s = document.createElement("span");
34536 s.className = this.itemCls;
34537 s.innerHTML = " ";
34539 li.addClass("x-menu-sep-li");
34540 Roo.menu.Separator.superclass.onRender.apply(this, arguments);
34544 * Ext JS Library 1.1.1
34545 * Copyright(c) 2006-2007, Ext JS, LLC.
34547 * Originally Released Under LGPL - original licence link has changed is not relivant.
34550 * <script type="text/javascript">
34553 * @class Roo.menu.Item
34554 * @extends Roo.menu.BaseItem
34555 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
34556 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
34557 * activation and click handling.
34559 * Creates a new Item
34560 * @param {Object} config Configuration options
34562 Roo.menu.Item = function(config){
34563 Roo.menu.Item.superclass.constructor.call(this, config);
34565 this.menu = Roo.menu.MenuMgr.get(this.menu);
34568 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
34571 * @cfg {String} text
34572 * The text to show on the menu item.
34576 * @cfg {String} HTML to render in menu
34577 * The text to show on the menu item (HTML version).
34581 * @cfg {String} icon
34582 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
34586 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
34588 itemCls : "x-menu-item",
34590 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
34592 canActivate : true,
34594 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
34597 // doc'd in BaseItem
34601 ctype: "Roo.menu.Item",
34604 onRender : function(container, position){
34605 var el = document.createElement("a");
34606 el.hideFocus = true;
34607 el.unselectable = "on";
34608 el.href = this.href || "#";
34609 if(this.hrefTarget){
34610 el.target = this.hrefTarget;
34612 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
34614 var html = this.html.length ? this.html : String.format('{0}',this.text);
34616 el.innerHTML = String.format(
34617 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
34618 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
34620 Roo.menu.Item.superclass.onRender.call(this, container, position);
34624 * Sets the text to display in this menu item
34625 * @param {String} text The text to display
34626 * @param {Boolean} isHTML true to indicate text is pure html.
34628 setText : function(text, isHTML){
34636 var html = this.html.length ? this.html : String.format('{0}',this.text);
34638 this.el.update(String.format(
34639 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
34640 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
34641 this.parentMenu.autoWidth();
34646 handleClick : function(e){
34647 if(!this.href){ // if no link defined, stop the event automatically
34650 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
34654 activate : function(autoExpand){
34655 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
34665 shouldDeactivate : function(e){
34666 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
34667 if(this.menu && this.menu.isVisible()){
34668 return !this.menu.getEl().getRegion().contains(e.getPoint());
34676 deactivate : function(){
34677 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
34682 expandMenu : function(autoActivate){
34683 if(!this.disabled && this.menu){
34684 clearTimeout(this.hideTimer);
34685 delete this.hideTimer;
34686 if(!this.menu.isVisible() && !this.showTimer){
34687 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
34688 }else if (this.menu.isVisible() && autoActivate){
34689 this.menu.tryActivate(0, 1);
34695 deferExpand : function(autoActivate){
34696 delete this.showTimer;
34697 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
34699 this.menu.tryActivate(0, 1);
34704 hideMenu : function(){
34705 clearTimeout(this.showTimer);
34706 delete this.showTimer;
34707 if(!this.hideTimer && this.menu && this.menu.isVisible()){
34708 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
34713 deferHide : function(){
34714 delete this.hideTimer;
34719 * Ext JS Library 1.1.1
34720 * Copyright(c) 2006-2007, Ext JS, LLC.
34722 * Originally Released Under LGPL - original licence link has changed is not relivant.
34725 * <script type="text/javascript">
34729 * @class Roo.menu.CheckItem
34730 * @extends Roo.menu.Item
34731 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
34733 * Creates a new CheckItem
34734 * @param {Object} config Configuration options
34736 Roo.menu.CheckItem = function(config){
34737 Roo.menu.CheckItem.superclass.constructor.call(this, config);
34740 * @event beforecheckchange
34741 * Fires before the checked value is set, providing an opportunity to cancel if needed
34742 * @param {Roo.menu.CheckItem} this
34743 * @param {Boolean} checked The new checked value that will be set
34745 "beforecheckchange" : true,
34747 * @event checkchange
34748 * Fires after the checked value has been set
34749 * @param {Roo.menu.CheckItem} this
34750 * @param {Boolean} checked The checked value that was set
34752 "checkchange" : true
34754 if(this.checkHandler){
34755 this.on('checkchange', this.checkHandler, this.scope);
34758 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
34760 * @cfg {String} group
34761 * All check items with the same group name will automatically be grouped into a single-select
34762 * radio button group (defaults to '')
34765 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
34767 itemCls : "x-menu-item x-menu-check-item",
34769 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
34771 groupClass : "x-menu-group-item",
34774 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
34775 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
34776 * initialized with checked = true will be rendered as checked.
34781 ctype: "Roo.menu.CheckItem",
34784 onRender : function(c){
34785 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
34787 this.el.addClass(this.groupClass);
34789 Roo.menu.MenuMgr.registerCheckable(this);
34791 this.checked = false;
34792 this.setChecked(true, true);
34797 destroy : function(){
34799 Roo.menu.MenuMgr.unregisterCheckable(this);
34801 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
34805 * Set the checked state of this item
34806 * @param {Boolean} checked The new checked value
34807 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
34809 setChecked : function(state, suppressEvent){
34810 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
34811 if(this.container){
34812 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
34814 this.checked = state;
34815 if(suppressEvent !== true){
34816 this.fireEvent("checkchange", this, state);
34822 handleClick : function(e){
34823 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
34824 this.setChecked(!this.checked);
34826 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
34830 * Ext JS Library 1.1.1
34831 * Copyright(c) 2006-2007, Ext JS, LLC.
34833 * Originally Released Under LGPL - original licence link has changed is not relivant.
34836 * <script type="text/javascript">
34840 * @class Roo.menu.DateItem
34841 * @extends Roo.menu.Adapter
34842 * A menu item that wraps the {@link Roo.DatPicker} component.
34844 * Creates a new DateItem
34845 * @param {Object} config Configuration options
34847 Roo.menu.DateItem = function(config){
34848 Roo.menu.DateItem.superclass.constructor.call(this, new Roo.DatePicker(config), config);
34849 /** The Roo.DatePicker object @type Roo.DatePicker */
34850 this.picker = this.component;
34851 this.addEvents({select: true});
34853 this.picker.on("render", function(picker){
34854 picker.getEl().swallowEvent("click");
34855 picker.container.addClass("x-menu-date-item");
34858 this.picker.on("select", this.onSelect, this);
34861 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
34863 onSelect : function(picker, date){
34864 this.fireEvent("select", this, date, picker);
34865 Roo.menu.DateItem.superclass.handleClick.call(this);
34869 * Ext JS Library 1.1.1
34870 * Copyright(c) 2006-2007, Ext JS, LLC.
34872 * Originally Released Under LGPL - original licence link has changed is not relivant.
34875 * <script type="text/javascript">
34879 * @class Roo.menu.ColorItem
34880 * @extends Roo.menu.Adapter
34881 * A menu item that wraps the {@link Roo.ColorPalette} component.
34883 * Creates a new ColorItem
34884 * @param {Object} config Configuration options
34886 Roo.menu.ColorItem = function(config){
34887 Roo.menu.ColorItem.superclass.constructor.call(this, new Roo.ColorPalette(config), config);
34888 /** The Roo.ColorPalette object @type Roo.ColorPalette */
34889 this.palette = this.component;
34890 this.relayEvents(this.palette, ["select"]);
34891 if(this.selectHandler){
34892 this.on('select', this.selectHandler, this.scope);
34895 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);/*
34897 * Ext JS Library 1.1.1
34898 * Copyright(c) 2006-2007, Ext JS, LLC.
34900 * Originally Released Under LGPL - original licence link has changed is not relivant.
34903 * <script type="text/javascript">
34908 * @class Roo.menu.DateMenu
34909 * @extends Roo.menu.Menu
34910 * A menu containing a {@link Roo.menu.DateItem} component (which provides a date picker).
34912 * Creates a new DateMenu
34913 * @param {Object} config Configuration options
34915 Roo.menu.DateMenu = function(config){
34916 Roo.menu.DateMenu.superclass.constructor.call(this, config);
34918 var di = new Roo.menu.DateItem(config);
34921 * The {@link Roo.DatePicker} instance for this DateMenu
34924 this.picker = di.picker;
34927 * @param {DatePicker} picker
34928 * @param {Date} date
34930 this.relayEvents(di, ["select"]);
34932 this.on('beforeshow', function(){
34934 this.picker.hideMonthPicker(true);
34938 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
34942 * Ext JS Library 1.1.1
34943 * Copyright(c) 2006-2007, Ext JS, LLC.
34945 * Originally Released Under LGPL - original licence link has changed is not relivant.
34948 * <script type="text/javascript">
34953 * @class Roo.menu.ColorMenu
34954 * @extends Roo.menu.Menu
34955 * A menu containing a {@link Roo.menu.ColorItem} component (which provides a basic color picker).
34957 * Creates a new ColorMenu
34958 * @param {Object} config Configuration options
34960 Roo.menu.ColorMenu = function(config){
34961 Roo.menu.ColorMenu.superclass.constructor.call(this, config);
34963 var ci = new Roo.menu.ColorItem(config);
34966 * The {@link Roo.ColorPalette} instance for this ColorMenu
34967 * @type ColorPalette
34969 this.palette = ci.palette;
34972 * @param {ColorPalette} palette
34973 * @param {String} color
34975 this.relayEvents(ci, ["select"]);
34977 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);/*
34979 * Ext JS Library 1.1.1
34980 * Copyright(c) 2006-2007, Ext JS, LLC.
34982 * Originally Released Under LGPL - original licence link has changed is not relivant.
34985 * <script type="text/javascript">
34989 * @class Roo.form.Field
34990 * @extends Roo.BoxComponent
34991 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
34993 * Creates a new Field
34994 * @param {Object} config Configuration options
34996 Roo.form.Field = function(config){
34997 Roo.form.Field.superclass.constructor.call(this, config);
35000 Roo.extend(Roo.form.Field, Roo.BoxComponent, {
35002 * @cfg {String} fieldLabel Label to use when rendering a form.
35005 * @cfg {String} qtip Mouse over tip
35009 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
35011 invalidClass : "x-form-invalid",
35013 * @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")
35015 invalidText : "The value in this field is invalid",
35017 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
35019 focusClass : "x-form-focus",
35021 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
35022 automatic validation (defaults to "keyup").
35024 validationEvent : "keyup",
35026 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
35028 validateOnBlur : true,
35030 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
35032 validationDelay : 250,
35034 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
35035 * {tag: "input", type: "text", size: "20", autocomplete: "off"})
35037 defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"},
35039 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field")
35041 fieldClass : "x-form-field",
35043 * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'):
35046 ----------- ----------------------------------------------------------------------
35047 qtip Display a quick tip when the user hovers over the field
35048 title Display a default browser title attribute popup
35049 under Add a block div beneath the field containing the error text
35050 side Add an error icon to the right of the field with a popup on hover
35051 [element id] Add the error text directly to the innerHTML of the specified element
35054 msgTarget : 'qtip',
35056 * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal').
35061 * @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.
35066 * @cfg {Boolean} disabled True to disable the field (defaults to false).
35071 * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password (defaults to "text").
35073 inputType : undefined,
35076 * @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).
35078 tabIndex : undefined,
35081 isFormField : true,
35086 * @property {Roo.Element} fieldEl
35087 * Element Containing the rendered Field (with label etc.)
35090 * @cfg {Mixed} value A value to initialize this field with.
35095 * @cfg {String} name The field's HTML name attribute.
35098 * @cfg {String} cls A CSS class to apply to the field's underlying element.
35102 initComponent : function(){
35103 Roo.form.Field.superclass.initComponent.call(this);
35107 * Fires when this field receives input focus.
35108 * @param {Roo.form.Field} this
35113 * Fires when this field loses input focus.
35114 * @param {Roo.form.Field} this
35118 * @event specialkey
35119 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
35120 * {@link Roo.EventObject#getKey} to determine which key was pressed.
35121 * @param {Roo.form.Field} this
35122 * @param {Roo.EventObject} e The event object
35127 * Fires just before the field blurs if the field value has changed.
35128 * @param {Roo.form.Field} this
35129 * @param {Mixed} newValue The new value
35130 * @param {Mixed} oldValue The original value
35135 * Fires after the field has been marked as invalid.
35136 * @param {Roo.form.Field} this
35137 * @param {String} msg The validation message
35142 * Fires after the field has been validated with no errors.
35143 * @param {Roo.form.Field} this
35150 * Returns the name attribute of the field if available
35151 * @return {String} name The field name
35153 getName: function(){
35154 return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
35158 onRender : function(ct, position){
35159 Roo.form.Field.superclass.onRender.call(this, ct, position);
35161 var cfg = this.getAutoCreate();
35163 cfg.name = this.name || this.id;
35165 if(this.inputType){
35166 cfg.type = this.inputType;
35168 this.el = ct.createChild(cfg, position);
35170 var type = this.el.dom.type;
35172 if(type == 'password'){
35175 this.el.addClass('x-form-'+type);
35178 this.el.dom.readOnly = true;
35180 if(this.tabIndex !== undefined){
35181 this.el.dom.setAttribute('tabIndex', this.tabIndex);
35184 this.el.addClass([this.fieldClass, this.cls]);
35189 * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b>
35190 * @param {String/HTMLElement/Element} el The id of the node, a DOM node or an existing Element
35191 * @return {Roo.form.Field} this
35193 applyTo : function(target){
35194 this.allowDomMove = false;
35195 this.el = Roo.get(target);
35196 this.render(this.el.dom.parentNode);
35201 initValue : function(){
35202 if(this.value !== undefined){
35203 this.setValue(this.value);
35204 }else if(this.el.dom.value.length > 0){
35205 this.setValue(this.el.dom.value);
35210 * Returns true if this field has been changed since it was originally loaded and is not disabled.
35212 isDirty : function() {
35213 if(this.disabled) {
35216 return String(this.getValue()) !== String(this.originalValue);
35220 afterRender : function(){
35221 Roo.form.Field.superclass.afterRender.call(this);
35226 fireKey : function(e){
35227 //Roo.log('field ' + e.getKey());
35228 if(e.isNavKeyPress()){
35229 this.fireEvent("specialkey", this, e);
35234 * Resets the current field value to the originally loaded value and clears any validation messages
35236 reset : function(){
35237 this.setValue(this.originalValue);
35238 this.clearInvalid();
35242 initEvents : function(){
35243 // safari killled keypress - so keydown is now used..
35244 this.el.on("keydown" , this.fireKey, this);
35245 this.el.on("focus", this.onFocus, this);
35246 this.el.on("blur", this.onBlur, this);
35248 // reference to original value for reset
35249 this.originalValue = this.getValue();
35253 onFocus : function(){
35254 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
35255 this.el.addClass(this.focusClass);
35257 if(!this.hasFocus){
35258 this.hasFocus = true;
35259 this.startValue = this.getValue();
35260 this.fireEvent("focus", this);
35264 beforeBlur : Roo.emptyFn,
35267 onBlur : function(){
35269 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
35270 this.el.removeClass(this.focusClass);
35272 this.hasFocus = false;
35273 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
35276 var v = this.getValue();
35277 if(String(v) !== String(this.startValue)){
35278 this.fireEvent('change', this, v, this.startValue);
35280 this.fireEvent("blur", this);
35284 * Returns whether or not the field value is currently valid
35285 * @param {Boolean} preventMark True to disable marking the field invalid
35286 * @return {Boolean} True if the value is valid, else false
35288 isValid : function(preventMark){
35292 var restore = this.preventMark;
35293 this.preventMark = preventMark === true;
35294 var v = this.validateValue(this.processValue(this.getRawValue()));
35295 this.preventMark = restore;
35300 * Validates the field value
35301 * @return {Boolean} True if the value is valid, else false
35303 validate : function(){
35304 if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
35305 this.clearInvalid();
35311 processValue : function(value){
35316 // Subclasses should provide the validation implementation by overriding this
35317 validateValue : function(value){
35322 * Mark this field as invalid
35323 * @param {String} msg The validation message
35325 markInvalid : function(msg){
35326 if(!this.rendered || this.preventMark){ // not rendered
35329 this.el.addClass(this.invalidClass);
35330 msg = msg || this.invalidText;
35331 switch(this.msgTarget){
35333 this.el.dom.qtip = msg;
35334 this.el.dom.qclass = 'x-form-invalid-tip';
35335 if(Roo.QuickTips){ // fix for floating editors interacting with DND
35336 Roo.QuickTips.enable();
35340 this.el.dom.title = msg;
35344 var elp = this.el.findParent('.x-form-element', 5, true);
35345 this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
35346 this.errorEl.setWidth(elp.getWidth(true)-20);
35348 this.errorEl.update(msg);
35349 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
35352 if(!this.errorIcon){
35353 var elp = this.el.findParent('.x-form-element', 5, true);
35354 this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
35356 this.alignErrorIcon();
35357 this.errorIcon.dom.qtip = msg;
35358 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
35359 this.errorIcon.show();
35360 this.on('resize', this.alignErrorIcon, this);
35363 var t = Roo.getDom(this.msgTarget);
35365 t.style.display = this.msgDisplay;
35368 this.fireEvent('invalid', this, msg);
35372 alignErrorIcon : function(){
35373 this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
35377 * Clear any invalid styles/messages for this field
35379 clearInvalid : function(){
35380 if(!this.rendered || this.preventMark){ // not rendered
35383 this.el.removeClass(this.invalidClass);
35384 switch(this.msgTarget){
35386 this.el.dom.qtip = '';
35389 this.el.dom.title = '';
35393 Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
35397 if(this.errorIcon){
35398 this.errorIcon.dom.qtip = '';
35399 this.errorIcon.hide();
35400 this.un('resize', this.alignErrorIcon, this);
35404 var t = Roo.getDom(this.msgTarget);
35406 t.style.display = 'none';
35409 this.fireEvent('valid', this);
35413 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
35414 * @return {Mixed} value The field value
35416 getRawValue : function(){
35417 var v = this.el.getValue();
35418 if(v === this.emptyText){
35425 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
35426 * @return {Mixed} value The field value
35428 getValue : function(){
35429 var v = this.el.getValue();
35430 if(v === this.emptyText || v === undefined){
35437 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
35438 * @param {Mixed} value The value to set
35440 setRawValue : function(v){
35441 return this.el.dom.value = (v === null || v === undefined ? '' : v);
35445 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
35446 * @param {Mixed} value The value to set
35448 setValue : function(v){
35451 this.el.dom.value = (v === null || v === undefined ? '' : v);
35456 adjustSize : function(w, h){
35457 var s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
35458 s.width = this.adjustWidth(this.el.dom.tagName, s.width);
35462 adjustWidth : function(tag, w){
35463 tag = tag.toLowerCase();
35464 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
35465 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
35466 if(tag == 'input'){
35469 if(tag = 'textarea'){
35472 }else if(Roo.isOpera){
35473 if(tag == 'input'){
35476 if(tag = 'textarea'){
35486 // anything other than normal should be considered experimental
35487 Roo.form.Field.msgFx = {
35489 show: function(msgEl, f){
35490 msgEl.setDisplayed('block');
35493 hide : function(msgEl, f){
35494 msgEl.setDisplayed(false).update('');
35499 show: function(msgEl, f){
35500 msgEl.slideIn('t', {stopFx:true});
35503 hide : function(msgEl, f){
35504 msgEl.slideOut('t', {stopFx:true,useDisplay:true});
35509 show: function(msgEl, f){
35510 msgEl.fixDisplay();
35511 msgEl.alignTo(f.el, 'tl-tr');
35512 msgEl.slideIn('l', {stopFx:true});
35515 hide : function(msgEl, f){
35516 msgEl.slideOut('l', {stopFx:true,useDisplay:true});
35521 * Ext JS Library 1.1.1
35522 * Copyright(c) 2006-2007, Ext JS, LLC.
35524 * Originally Released Under LGPL - original licence link has changed is not relivant.
35527 * <script type="text/javascript">
35532 * @class Roo.form.TextField
35533 * @extends Roo.form.Field
35534 * Basic text field. Can be used as a direct replacement for traditional text inputs, or as the base
35535 * class for more sophisticated input controls (like {@link Roo.form.TextArea} and {@link Roo.form.ComboBox}).
35537 * Creates a new TextField
35538 * @param {Object} config Configuration options
35540 Roo.form.TextField = function(config){
35541 Roo.form.TextField.superclass.constructor.call(this, config);
35545 * Fires when the autosize function is triggered. The field may or may not have actually changed size
35546 * according to the default logic, but this event provides a hook for the developer to apply additional
35547 * logic at runtime to resize the field if needed.
35548 * @param {Roo.form.Field} this This text field
35549 * @param {Number} width The new field width
35555 Roo.extend(Roo.form.TextField, Roo.form.Field, {
35557 * @cfg {Boolean} grow True if this field should automatically grow and shrink to its content
35561 * @cfg {Number} growMin The minimum width to allow when grow = true (defaults to 30)
35565 * @cfg {Number} growMax The maximum width to allow when grow = true (defaults to 800)
35569 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
35573 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
35577 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
35579 disableKeyFilter : false,
35581 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
35585 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
35589 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
35591 maxLength : Number.MAX_VALUE,
35593 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
35595 minLengthText : "The minimum length for this field is {0}",
35597 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
35599 maxLengthText : "The maximum length for this field is {0}",
35601 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
35603 selectOnFocus : false,
35605 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
35607 blankText : "This field is required",
35609 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
35610 * If available, this function will be called only after the basic validators all return true, and will be passed the
35611 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
35615 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
35616 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
35617 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
35621 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
35625 * @cfg {String} emptyText The default text to display in an empty field (defaults to null).
35629 * @cfg {String} emptyClass The CSS class to apply to an empty field to style the {@link #emptyText} (defaults to
35630 * 'x-form-empty-field'). This class is automatically added and removed as needed depending on the current field value.
35632 emptyClass : 'x-form-empty-field',
35635 initEvents : function(){
35636 Roo.form.TextField.superclass.initEvents.call(this);
35637 if(this.validationEvent == 'keyup'){
35638 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
35639 this.el.on('keyup', this.filterValidation, this);
35641 else if(this.validationEvent !== false){
35642 this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
35644 if(this.selectOnFocus || this.emptyText){
35645 this.on("focus", this.preFocus, this);
35646 if(this.emptyText){
35647 this.on('blur', this.postBlur, this);
35648 this.applyEmptyText();
35651 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
35652 this.el.on("keypress", this.filterKeys, this);
35655 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
35656 this.el.on("click", this.autoSize, this);
35660 processValue : function(value){
35661 if(this.stripCharsRe){
35662 var newValue = value.replace(this.stripCharsRe, '');
35663 if(newValue !== value){
35664 this.setRawValue(newValue);
35671 filterValidation : function(e){
35672 if(!e.isNavKeyPress()){
35673 this.validationTask.delay(this.validationDelay);
35678 onKeyUp : function(e){
35679 if(!e.isNavKeyPress()){
35685 * Resets the current field value to the originally-loaded value and clears any validation messages.
35686 * Also adds emptyText and emptyClass if the original value was blank.
35688 reset : function(){
35689 Roo.form.TextField.superclass.reset.call(this);
35690 this.applyEmptyText();
35693 applyEmptyText : function(){
35694 if(this.rendered && this.emptyText && this.getRawValue().length < 1){
35695 this.setRawValue(this.emptyText);
35696 this.el.addClass(this.emptyClass);
35701 preFocus : function(){
35702 if(this.emptyText){
35703 if(this.el.dom.value == this.emptyText){
35704 this.setRawValue('');
35706 this.el.removeClass(this.emptyClass);
35708 if(this.selectOnFocus){
35709 this.el.dom.select();
35714 postBlur : function(){
35715 this.applyEmptyText();
35719 filterKeys : function(e){
35720 var k = e.getKey();
35721 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
35724 var c = e.getCharCode(), cc = String.fromCharCode(c);
35725 if(Roo.isIE && (e.isSpecialKey() || !cc)){
35728 if(!this.maskRe.test(cc)){
35733 setValue : function(v){
35734 if(this.emptyText && this.el && v !== undefined && v !== null && v !== ''){
35735 this.el.removeClass(this.emptyClass);
35737 Roo.form.TextField.superclass.setValue.apply(this, arguments);
35738 this.applyEmptyText();
35743 * Validates a value according to the field's validation rules and marks the field as invalid
35744 * if the validation fails
35745 * @param {Mixed} value The value to validate
35746 * @return {Boolean} True if the value is valid, else false
35748 validateValue : function(value){
35749 if(value.length < 1 || value === this.emptyText){ // if it's blank
35750 if(this.allowBlank){
35751 this.clearInvalid();
35754 this.markInvalid(this.blankText);
35758 if(value.length < this.minLength){
35759 this.markInvalid(String.format(this.minLengthText, this.minLength));
35762 if(value.length > this.maxLength){
35763 this.markInvalid(String.format(this.maxLengthText, this.maxLength));
35767 var vt = Roo.form.VTypes;
35768 if(!vt[this.vtype](value, this)){
35769 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
35773 if(typeof this.validator == "function"){
35774 var msg = this.validator(value);
35776 this.markInvalid(msg);
35780 if(this.regex && !this.regex.test(value)){
35781 this.markInvalid(this.regexText);
35788 * Selects text in this field
35789 * @param {Number} start (optional) The index where the selection should start (defaults to 0)
35790 * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
35792 selectText : function(start, end){
35793 var v = this.getRawValue();
35795 start = start === undefined ? 0 : start;
35796 end = end === undefined ? v.length : end;
35797 var d = this.el.dom;
35798 if(d.setSelectionRange){
35799 d.setSelectionRange(start, end);
35800 }else if(d.createTextRange){
35801 var range = d.createTextRange();
35802 range.moveStart("character", start);
35803 range.moveEnd("character", v.length-end);
35810 * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
35811 * This only takes effect if grow = true, and fires the autosize event.
35813 autoSize : function(){
35814 if(!this.grow || !this.rendered){
35818 this.metrics = Roo.util.TextMetrics.createInstance(this.el);
35821 var v = el.dom.value;
35822 var d = document.createElement('div');
35823 d.appendChild(document.createTextNode(v));
35827 var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
35828 this.el.setWidth(w);
35829 this.fireEvent("autosize", this, w);
35833 * Ext JS Library 1.1.1
35834 * Copyright(c) 2006-2007, Ext JS, LLC.
35836 * Originally Released Under LGPL - original licence link has changed is not relivant.
35839 * <script type="text/javascript">
35843 * @class Roo.form.Hidden
35844 * @extends Roo.form.TextField
35845 * Simple Hidden element used on forms
35847 * usage: form.add(new Roo.form.HiddenField({ 'name' : 'test1' }));
35850 * Creates a new Hidden form element.
35851 * @param {Object} config Configuration options
35856 // easy hidden field...
35857 Roo.form.Hidden = function(config){
35858 Roo.form.Hidden.superclass.constructor.call(this, config);
35861 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
35863 inputType: 'hidden',
35866 labelSeparator: '',
35868 itemCls : 'x-form-item-display-none'
35876 * Ext JS Library 1.1.1
35877 * Copyright(c) 2006-2007, Ext JS, LLC.
35879 * Originally Released Under LGPL - original licence link has changed is not relivant.
35882 * <script type="text/javascript">
35886 * @class Roo.form.TriggerField
35887 * @extends Roo.form.TextField
35888 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
35889 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
35890 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
35891 * for which you can provide a custom implementation. For example:
35893 var trigger = new Roo.form.TriggerField();
35894 trigger.onTriggerClick = myTriggerFn;
35895 trigger.applyTo('my-field');
35898 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
35899 * {@link Roo.form.DateField} and {@link Roo.form.ComboBox} are perfect examples of this.
35900 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
35901 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
35903 * Create a new TriggerField.
35904 * @param {Object} config Configuration options (valid {@Roo.form.TextField} config options will also be applied
35905 * to the base TextField)
35907 Roo.form.TriggerField = function(config){
35908 this.mimicing = false;
35909 Roo.form.TriggerField.superclass.constructor.call(this, config);
35912 Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
35914 * @cfg {String} triggerClass A CSS class to apply to the trigger
35917 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
35918 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
35920 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
35922 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
35926 /** @cfg {Boolean} grow @hide */
35927 /** @cfg {Number} growMin @hide */
35928 /** @cfg {Number} growMax @hide */
35934 autoSize: Roo.emptyFn,
35938 deferHeight : true,
35941 actionMode : 'wrap',
35943 onResize : function(w, h){
35944 Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
35945 if(typeof w == 'number'){
35946 var x = w - this.trigger.getWidth();
35947 this.el.setWidth(this.adjustWidth('input', x));
35948 this.trigger.setStyle('left', x+'px');
35953 adjustSize : Roo.BoxComponent.prototype.adjustSize,
35956 getResizeEl : function(){
35961 getPositionEl : function(){
35966 alignErrorIcon : function(){
35967 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
35971 onRender : function(ct, position){
35972 Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
35973 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
35974 this.trigger = this.wrap.createChild(this.triggerConfig ||
35975 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
35976 if(this.hideTrigger){
35977 this.trigger.setDisplayed(false);
35979 this.initTrigger();
35981 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
35986 initTrigger : function(){
35987 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
35988 this.trigger.addClassOnOver('x-form-trigger-over');
35989 this.trigger.addClassOnClick('x-form-trigger-click');
35993 onDestroy : function(){
35995 this.trigger.removeAllListeners();
35996 this.trigger.remove();
35999 this.wrap.remove();
36001 Roo.form.TriggerField.superclass.onDestroy.call(this);
36005 onFocus : function(){
36006 Roo.form.TriggerField.superclass.onFocus.call(this);
36007 if(!this.mimicing){
36008 this.wrap.addClass('x-trigger-wrap-focus');
36009 this.mimicing = true;
36010 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
36011 if(this.monitorTab){
36012 this.el.on("keydown", this.checkTab, this);
36018 checkTab : function(e){
36019 if(e.getKey() == e.TAB){
36020 this.triggerBlur();
36025 onBlur : function(){
36030 mimicBlur : function(e, t){
36031 if(!this.wrap.contains(t) && this.validateBlur()){
36032 this.triggerBlur();
36037 triggerBlur : function(){
36038 this.mimicing = false;
36039 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
36040 if(this.monitorTab){
36041 this.el.un("keydown", this.checkTab, this);
36043 this.wrap.removeClass('x-trigger-wrap-focus');
36044 Roo.form.TriggerField.superclass.onBlur.call(this);
36048 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
36049 validateBlur : function(e, t){
36054 onDisable : function(){
36055 Roo.form.TriggerField.superclass.onDisable.call(this);
36057 this.wrap.addClass('x-item-disabled');
36062 onEnable : function(){
36063 Roo.form.TriggerField.superclass.onEnable.call(this);
36065 this.wrap.removeClass('x-item-disabled');
36070 onShow : function(){
36071 var ae = this.getActionEl();
36074 ae.dom.style.display = '';
36075 ae.dom.style.visibility = 'visible';
36081 onHide : function(){
36082 var ae = this.getActionEl();
36083 ae.dom.style.display = 'none';
36087 * The function that should handle the trigger's click event. This method does nothing by default until overridden
36088 * by an implementing function.
36090 * @param {EventObject} e
36092 onTriggerClick : Roo.emptyFn
36095 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
36096 // to be extended by an implementing class. For an example of implementing this class, see the custom
36097 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
36098 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
36099 initComponent : function(){
36100 Roo.form.TwinTriggerField.superclass.initComponent.call(this);
36102 this.triggerConfig = {
36103 tag:'span', cls:'x-form-twin-triggers', cn:[
36104 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
36105 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
36109 getTrigger : function(index){
36110 return this.triggers[index];
36113 initTrigger : function(){
36114 var ts = this.trigger.select('.x-form-trigger', true);
36115 this.wrap.setStyle('overflow', 'hidden');
36116 var triggerField = this;
36117 ts.each(function(t, all, index){
36118 t.hide = function(){
36119 var w = triggerField.wrap.getWidth();
36120 this.dom.style.display = 'none';
36121 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
36123 t.show = function(){
36124 var w = triggerField.wrap.getWidth();
36125 this.dom.style.display = '';
36126 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
36128 var triggerIndex = 'Trigger'+(index+1);
36130 if(this['hide'+triggerIndex]){
36131 t.dom.style.display = 'none';
36133 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
36134 t.addClassOnOver('x-form-trigger-over');
36135 t.addClassOnClick('x-form-trigger-click');
36137 this.triggers = ts.elements;
36140 onTrigger1Click : Roo.emptyFn,
36141 onTrigger2Click : Roo.emptyFn
36144 * Ext JS Library 1.1.1
36145 * Copyright(c) 2006-2007, Ext JS, LLC.
36147 * Originally Released Under LGPL - original licence link has changed is not relivant.
36150 * <script type="text/javascript">
36154 * @class Roo.form.TextArea
36155 * @extends Roo.form.TextField
36156 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
36157 * support for auto-sizing.
36159 * Creates a new TextArea
36160 * @param {Object} config Configuration options
36162 Roo.form.TextArea = function(config){
36163 Roo.form.TextArea.superclass.constructor.call(this, config);
36164 // these are provided exchanges for backwards compat
36165 // minHeight/maxHeight were replaced by growMin/growMax to be
36166 // compatible with TextField growing config values
36167 if(this.minHeight !== undefined){
36168 this.growMin = this.minHeight;
36170 if(this.maxHeight !== undefined){
36171 this.growMax = this.maxHeight;
36175 Roo.extend(Roo.form.TextArea, Roo.form.TextField, {
36177 * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
36181 * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
36185 * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
36186 * in the field (equivalent to setting overflow: hidden, defaults to false)
36188 preventScrollbars: false,
36190 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
36191 * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"})
36195 onRender : function(ct, position){
36197 this.defaultAutoCreate = {
36199 style:"width:300px;height:60px;",
36200 autocomplete: "off"
36203 Roo.form.TextArea.superclass.onRender.call(this, ct, position);
36205 this.textSizeEl = Roo.DomHelper.append(document.body, {
36206 tag: "pre", cls: "x-form-grow-sizer"
36208 if(this.preventScrollbars){
36209 this.el.setStyle("overflow", "hidden");
36211 this.el.setHeight(this.growMin);
36215 onDestroy : function(){
36216 if(this.textSizeEl){
36217 this.textSizeEl.parentNode.removeChild(this.textSizeEl);
36219 Roo.form.TextArea.superclass.onDestroy.call(this);
36223 onKeyUp : function(e){
36224 if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
36230 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
36231 * This only takes effect if grow = true, and fires the autosize event if the height changes.
36233 autoSize : function(){
36234 if(!this.grow || !this.textSizeEl){
36238 var v = el.dom.value;
36239 var ts = this.textSizeEl;
36242 ts.appendChild(document.createTextNode(v));
36245 Roo.fly(ts).setWidth(this.el.getWidth());
36247 v = "  ";
36250 v = v.replace(/\n/g, '<p> </p>');
36252 v += " \n ";
36255 var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
36256 if(h != this.lastHeight){
36257 this.lastHeight = h;
36258 this.el.setHeight(h);
36259 this.fireEvent("autosize", this, h);
36264 * Ext JS Library 1.1.1
36265 * Copyright(c) 2006-2007, Ext JS, LLC.
36267 * Originally Released Under LGPL - original licence link has changed is not relivant.
36270 * <script type="text/javascript">
36275 * @class Roo.form.NumberField
36276 * @extends Roo.form.TextField
36277 * Numeric text field that provides automatic keystroke filtering and numeric validation.
36279 * Creates a new NumberField
36280 * @param {Object} config Configuration options
36282 Roo.form.NumberField = function(config){
36283 Roo.form.NumberField.superclass.constructor.call(this, config);
36286 Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
36288 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
36290 fieldClass: "x-form-field x-form-num-field",
36292 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
36294 allowDecimals : true,
36296 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
36298 decimalSeparator : ".",
36300 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
36302 decimalPrecision : 2,
36304 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
36306 allowNegative : true,
36308 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
36310 minValue : Number.NEGATIVE_INFINITY,
36312 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
36314 maxValue : Number.MAX_VALUE,
36316 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
36318 minText : "The minimum value for this field is {0}",
36320 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
36322 maxText : "The maximum value for this field is {0}",
36324 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
36325 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
36327 nanText : "{0} is not a valid number",
36330 initEvents : function(){
36331 Roo.form.NumberField.superclass.initEvents.call(this);
36332 var allowed = "0123456789";
36333 if(this.allowDecimals){
36334 allowed += this.decimalSeparator;
36336 if(this.allowNegative){
36339 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
36340 var keyPress = function(e){
36341 var k = e.getKey();
36342 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
36345 var c = e.getCharCode();
36346 if(allowed.indexOf(String.fromCharCode(c)) === -1){
36350 this.el.on("keypress", keyPress, this);
36354 validateValue : function(value){
36355 if(!Roo.form.NumberField.superclass.validateValue.call(this, value)){
36358 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
36361 var num = this.parseValue(value);
36363 this.markInvalid(String.format(this.nanText, value));
36366 if(num < this.minValue){
36367 this.markInvalid(String.format(this.minText, this.minValue));
36370 if(num > this.maxValue){
36371 this.markInvalid(String.format(this.maxText, this.maxValue));
36377 getValue : function(){
36378 return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
36382 parseValue : function(value){
36383 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
36384 return isNaN(value) ? '' : value;
36388 fixPrecision : function(value){
36389 var nan = isNaN(value);
36390 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
36391 return nan ? '' : value;
36393 return parseFloat(value).toFixed(this.decimalPrecision);
36396 setValue : function(v){
36397 Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
36401 decimalPrecisionFcn : function(v){
36402 return Math.floor(v);
36405 beforeBlur : function(){
36406 var v = this.parseValue(this.getRawValue());
36408 this.setValue(this.fixPrecision(v));
36413 * Ext JS Library 1.1.1
36414 * Copyright(c) 2006-2007, Ext JS, LLC.
36416 * Originally Released Under LGPL - original licence link has changed is not relivant.
36419 * <script type="text/javascript">
36423 * @class Roo.form.DateField
36424 * @extends Roo.form.TriggerField
36425 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
36427 * Create a new DateField
36428 * @param {Object} config
36430 Roo.form.DateField = function(config){
36431 Roo.form.DateField.superclass.constructor.call(this, config);
36437 * Fires when a date is selected
36438 * @param {Roo.form.DateField} combo This combo box
36439 * @param {Date} date The date selected
36446 if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
36447 if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
36448 this.ddMatch = null;
36449 if(this.disabledDates){
36450 var dd = this.disabledDates;
36452 for(var i = 0; i < dd.length; i++){
36454 if(i != dd.length-1) re += "|";
36456 this.ddMatch = new RegExp(re + ")");
36460 Roo.extend(Roo.form.DateField, Roo.form.TriggerField, {
36462 * @cfg {String} format
36463 * The default date format string which can be overriden for localization support. The format must be
36464 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
36468 * @cfg {String} altFormats
36469 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
36470 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
36472 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
36474 * @cfg {Array} disabledDays
36475 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
36477 disabledDays : null,
36479 * @cfg {String} disabledDaysText
36480 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
36482 disabledDaysText : "Disabled",
36484 * @cfg {Array} disabledDates
36485 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
36486 * expression so they are very powerful. Some examples:
36488 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
36489 * <li>["03/08", "09/16"] would disable those days for every year</li>
36490 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
36491 * <li>["03/../2006"] would disable every day in March 2006</li>
36492 * <li>["^03"] would disable every day in every March</li>
36494 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
36495 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
36497 disabledDates : null,
36499 * @cfg {String} disabledDatesText
36500 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
36502 disabledDatesText : "Disabled",
36504 * @cfg {Date/String} minValue
36505 * The minimum allowed date. Can be either a Javascript date object or a string date in a
36506 * valid format (defaults to null).
36510 * @cfg {Date/String} maxValue
36511 * The maximum allowed date. Can be either a Javascript date object or a string date in a
36512 * valid format (defaults to null).
36516 * @cfg {String} minText
36517 * The error text to display when the date in the cell is before minValue (defaults to
36518 * 'The date in this field must be after {minValue}').
36520 minText : "The date in this field must be equal to or after {0}",
36522 * @cfg {String} maxText
36523 * The error text to display when the date in the cell is after maxValue (defaults to
36524 * 'The date in this field must be before {maxValue}').
36526 maxText : "The date in this field must be equal to or before {0}",
36528 * @cfg {String} invalidText
36529 * The error text to display when the date in the field is invalid (defaults to
36530 * '{value} is not a valid date - it must be in the format {format}').
36532 invalidText : "{0} is not a valid date - it must be in the format {1}",
36534 * @cfg {String} triggerClass
36535 * An additional CSS class used to style the trigger button. The trigger will always get the
36536 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
36537 * which displays a calendar icon).
36539 triggerClass : 'x-form-date-trigger',
36543 * @cfg {bool} useIso
36544 * if enabled, then the date field will use a hidden field to store the
36545 * real value as iso formated date. default (false)
36549 * @cfg {String/Object} autoCreate
36550 * A DomHelper element spec, or true for a default element spec (defaults to
36551 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
36554 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
36557 hiddenField: false,
36559 onRender : function(ct, position)
36561 Roo.form.DateField.superclass.onRender.call(this, ct, position);
36563 this.el.dom.removeAttribute('name');
36564 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
36566 this.hiddenField.value = this.formatDate(this.value, 'Y-m-d');
36567 // prevent input submission
36568 this.hiddenName = this.name;
36575 validateValue : function(value)
36577 value = this.formatDate(value);
36578 if(!Roo.form.DateField.superclass.validateValue.call(this, value)){
36581 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
36584 var svalue = value;
36585 value = this.parseDate(value);
36587 this.markInvalid(String.format(this.invalidText, svalue, this.format));
36590 var time = value.getTime();
36591 if(this.minValue && time < this.minValue.getTime()){
36592 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
36595 if(this.maxValue && time > this.maxValue.getTime()){
36596 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
36599 if(this.disabledDays){
36600 var day = value.getDay();
36601 for(var i = 0; i < this.disabledDays.length; i++) {
36602 if(day === this.disabledDays[i]){
36603 this.markInvalid(this.disabledDaysText);
36608 var fvalue = this.formatDate(value);
36609 if(this.ddMatch && this.ddMatch.test(fvalue)){
36610 this.markInvalid(String.format(this.disabledDatesText, fvalue));
36617 // Provides logic to override the default TriggerField.validateBlur which just returns true
36618 validateBlur : function(){
36619 return !this.menu || !this.menu.isVisible();
36623 * Returns the current date value of the date field.
36624 * @return {Date} The date value
36626 getValue : function(){
36628 return this.hiddenField ? this.hiddenField.value : this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
36632 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
36633 * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}
36634 * (the default format used is "m/d/y").
36637 //All of these calls set the same date value (May 4, 2006)
36639 //Pass a date object:
36640 var dt = new Date('5/4/06');
36641 dateField.setValue(dt);
36643 //Pass a date string (default format):
36644 dateField.setValue('5/4/06');
36646 //Pass a date string (custom format):
36647 dateField.format = 'Y-m-d';
36648 dateField.setValue('2006-5-4');
36650 * @param {String/Date} date The date or valid date string
36652 setValue : function(date){
36653 if (this.hiddenField) {
36654 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
36656 Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
36660 parseDate : function(value){
36661 if(!value || value instanceof Date){
36664 var v = Date.parseDate(value, this.format);
36665 if(!v && this.altFormats){
36666 if(!this.altFormatsArray){
36667 this.altFormatsArray = this.altFormats.split("|");
36669 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
36670 v = Date.parseDate(value, this.altFormatsArray[i]);
36677 formatDate : function(date, fmt){
36678 return (!date || !(date instanceof Date)) ?
36679 date : date.dateFormat(fmt || this.format);
36684 select: function(m, d){
36686 this.fireEvent('select', this, d);
36688 show : function(){ // retain focus styling
36692 this.focus.defer(10, this);
36693 var ml = this.menuListeners;
36694 this.menu.un("select", ml.select, this);
36695 this.menu.un("show", ml.show, this);
36696 this.menu.un("hide", ml.hide, this);
36701 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
36702 onTriggerClick : function(){
36706 if(this.menu == null){
36707 this.menu = new Roo.menu.DateMenu();
36709 Roo.apply(this.menu.picker, {
36710 showClear: this.allowBlank,
36711 minDate : this.minValue,
36712 maxDate : this.maxValue,
36713 disabledDatesRE : this.ddMatch,
36714 disabledDatesText : this.disabledDatesText,
36715 disabledDays : this.disabledDays,
36716 disabledDaysText : this.disabledDaysText,
36717 format : this.format,
36718 minText : String.format(this.minText, this.formatDate(this.minValue)),
36719 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
36721 this.menu.on(Roo.apply({}, this.menuListeners, {
36724 this.menu.picker.setValue(this.getValue() || new Date());
36725 this.menu.show(this.el, "tl-bl?");
36728 beforeBlur : function(){
36729 var v = this.parseDate(this.getRawValue());
36735 /** @cfg {Boolean} grow @hide */
36736 /** @cfg {Number} growMin @hide */
36737 /** @cfg {Number} growMax @hide */
36744 * Ext JS Library 1.1.1
36745 * Copyright(c) 2006-2007, Ext JS, LLC.
36747 * Originally Released Under LGPL - original licence link has changed is not relivant.
36750 * <script type="text/javascript">
36755 * @class Roo.form.ComboBox
36756 * @extends Roo.form.TriggerField
36757 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
36759 * Create a new ComboBox.
36760 * @param {Object} config Configuration options
36762 Roo.form.ComboBox = function(config){
36763 Roo.form.ComboBox.superclass.constructor.call(this, config);
36767 * Fires when the dropdown list is expanded
36768 * @param {Roo.form.ComboBox} combo This combo box
36773 * Fires when the dropdown list is collapsed
36774 * @param {Roo.form.ComboBox} combo This combo box
36778 * @event beforeselect
36779 * Fires before a list item is selected. Return false to cancel the selection.
36780 * @param {Roo.form.ComboBox} combo This combo box
36781 * @param {Roo.data.Record} record The data record returned from the underlying store
36782 * @param {Number} index The index of the selected item in the dropdown list
36784 'beforeselect' : true,
36787 * Fires when a list item is selected
36788 * @param {Roo.form.ComboBox} combo This combo box
36789 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
36790 * @param {Number} index The index of the selected item in the dropdown list
36794 * @event beforequery
36795 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
36796 * The event object passed has these properties:
36797 * @param {Roo.form.ComboBox} combo This combo box
36798 * @param {String} query The query
36799 * @param {Boolean} forceAll true to force "all" query
36800 * @param {Boolean} cancel true to cancel the query
36801 * @param {Object} e The query event object
36803 'beforequery': true,
36806 * Fires when the 'add' icon is pressed (add a listener to enable add button)
36807 * @param {Roo.form.ComboBox} combo This combo box
36812 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
36813 * @param {Roo.form.ComboBox} combo This combo box
36814 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
36820 if(this.transform){
36821 this.allowDomMove = false;
36822 var s = Roo.getDom(this.transform);
36823 if(!this.hiddenName){
36824 this.hiddenName = s.name;
36827 this.mode = 'local';
36828 var d = [], opts = s.options;
36829 for(var i = 0, len = opts.length;i < len; i++){
36831 var value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
36833 this.value = value;
36835 d.push([value, o.text]);
36837 this.store = new Roo.data.SimpleStore({
36839 fields: ['value', 'text'],
36842 this.valueField = 'value';
36843 this.displayField = 'text';
36845 s.name = Roo.id(); // wipe out the name in case somewhere else they have a reference
36846 if(!this.lazyRender){
36847 this.target = true;
36848 this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
36849 s.parentNode.removeChild(s); // remove it
36850 this.render(this.el.parentNode);
36852 s.parentNode.removeChild(s); // remove it
36857 this.store = Roo.factory(this.store, Roo.data);
36860 this.selectedIndex = -1;
36861 if(this.mode == 'local'){
36862 if(config.queryDelay === undefined){
36863 this.queryDelay = 10;
36865 if(config.minChars === undefined){
36871 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
36873 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
36876 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
36877 * rendering into an Roo.Editor, defaults to false)
36880 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
36881 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
36884 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
36887 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
36888 * the dropdown list (defaults to undefined, with no header element)
36892 * @cfg {String/Roo.Template} tpl The template to use to render the output
36896 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
36898 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
36900 listWidth: undefined,
36902 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
36903 * mode = 'remote' or 'text' if mode = 'local')
36905 displayField: undefined,
36907 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
36908 * mode = 'remote' or 'value' if mode = 'local').
36909 * Note: use of a valueField requires the user make a selection
36910 * in order for a value to be mapped.
36912 valueField: undefined,
36914 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
36915 * field's data value (defaults to the underlying DOM element's name)
36917 hiddenName: undefined,
36919 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
36923 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
36925 selectedClass: 'x-combo-selected',
36927 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
36928 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
36929 * which displays a downward arrow icon).
36931 triggerClass : 'x-form-arrow-trigger',
36933 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
36937 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
36938 * anchor positions (defaults to 'tl-bl')
36940 listAlign: 'tl-bl?',
36942 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
36946 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
36947 * query specified by the allQuery config option (defaults to 'query')
36949 triggerAction: 'query',
36951 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
36952 * (defaults to 4, does not apply if editable = false)
36956 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
36957 * delay (typeAheadDelay) if it matches a known value (defaults to false)
36961 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
36962 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
36966 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
36967 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
36971 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
36972 * when editable = true (defaults to false)
36974 selectOnFocus:false,
36976 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
36978 queryParam: 'query',
36980 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
36981 * when mode = 'remote' (defaults to 'Loading...')
36983 loadingText: 'Loading...',
36985 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
36989 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
36993 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
36994 * traditional select (defaults to true)
36998 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
37002 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
37006 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
37007 * listWidth has a higher value)
37011 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
37012 * allow the user to set arbitrary text into the field (defaults to false)
37014 forceSelection:false,
37016 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
37017 * if typeAhead = true (defaults to 250)
37019 typeAheadDelay : 250,
37021 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
37022 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
37024 valueNotFoundText : undefined,
37026 * @cfg {bool} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
37028 blockFocus : false,
37031 * @cfg {bool} disableClear Disable showing of clear button.
37033 disableClear : false,
37041 onRender : function(ct, position){
37042 Roo.form.ComboBox.superclass.onRender.call(this, ct, position);
37043 if(this.hiddenName){
37044 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
37046 this.hiddenField.value =
37047 this.hiddenValue !== undefined ? this.hiddenValue :
37048 this.value !== undefined ? this.value : '';
37050 // prevent input submission
37051 this.el.dom.removeAttribute('name');
37054 this.el.dom.setAttribute('autocomplete', 'off');
37057 var cls = 'x-combo-list';
37059 this.list = new Roo.Layer({
37060 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
37063 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
37064 this.list.setWidth(lw);
37065 this.list.swallowEvent('mousewheel');
37066 this.assetHeight = 0;
37069 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
37070 this.assetHeight += this.header.getHeight();
37073 this.innerList = this.list.createChild({cls:cls+'-inner'});
37074 this.innerList.on('mouseover', this.onViewOver, this);
37075 this.innerList.on('mousemove', this.onViewMove, this);
37076 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
37078 if(this.allowBlank && !this.pageSize && !this.disableClear){
37079 this.footer = this.list.createChild({cls:cls+'-ft'});
37080 this.pageTb = new Roo.Toolbar(this.footer);
37084 this.footer = this.list.createChild({cls:cls+'-ft'});
37085 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
37086 {pageSize: this.pageSize});
37090 if (this.pageTb && this.allowBlank && !this.disableClear) {
37092 this.pageTb.add(new Roo.Toolbar.Fill(), {
37093 cls: 'x-btn-icon x-btn-clear',
37095 handler: function()
37098 _this.clearValue();
37099 _this.onSelect(false, -1);
37104 this.assetHeight += this.footer.getHeight();
37109 this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
37112 this.view = new Roo.View(this.innerList, this.tpl, {
37113 singleSelect:true, store: this.store, selectedClass: this.selectedClass
37116 this.view.on('click', this.onViewClick, this);
37118 this.store.on('beforeload', this.onBeforeLoad, this);
37119 this.store.on('load', this.onLoad, this);
37120 this.store.on('loadexception', this.collapse, this);
37122 if(this.resizable){
37123 this.resizer = new Roo.Resizable(this.list, {
37124 pinned:true, handles:'se'
37126 this.resizer.on('resize', function(r, w, h){
37127 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
37128 this.listWidth = w;
37129 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
37130 this.restrictHeight();
37132 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
37134 if(!this.editable){
37135 this.editable = true;
37136 this.setEditable(false);
37140 if (typeof(this.events.add.listeners) != 'undefined') {
37142 this.addicon = this.wrap.createChild(
37143 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
37145 this.addicon.on('click', function(e) {
37146 this.fireEvent('add', this);
37149 if (typeof(this.events.edit.listeners) != 'undefined') {
37151 this.editicon = this.wrap.createChild(
37152 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
37153 if (this.addicon) {
37154 this.editicon.setStyle('margin-left', '40px');
37156 this.editicon.on('click', function(e) {
37158 // we fire even if inothing is selected..
37159 this.fireEvent('edit', this, this.lastData );
37169 initEvents : function(){
37170 Roo.form.ComboBox.superclass.initEvents.call(this);
37172 this.keyNav = new Roo.KeyNav(this.el, {
37173 "up" : function(e){
37174 this.inKeyMode = true;
37178 "down" : function(e){
37179 if(!this.isExpanded()){
37180 this.onTriggerClick();
37182 this.inKeyMode = true;
37187 "enter" : function(e){
37188 this.onViewClick();
37192 "esc" : function(e){
37196 "tab" : function(e){
37197 this.onViewClick(false);
37203 doRelay : function(foo, bar, hname){
37204 if(hname == 'down' || this.scope.isExpanded()){
37205 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
37212 this.queryDelay = Math.max(this.queryDelay || 10,
37213 this.mode == 'local' ? 10 : 250);
37214 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
37215 if(this.typeAhead){
37216 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
37218 if(this.editable !== false){
37219 this.el.on("keyup", this.onKeyUp, this);
37221 if(this.forceSelection){
37222 this.on('blur', this.doForce, this);
37226 onDestroy : function(){
37228 this.view.setStore(null);
37229 this.view.el.removeAllListeners();
37230 this.view.el.remove();
37231 this.view.purgeListeners();
37234 this.list.destroy();
37237 this.store.un('beforeload', this.onBeforeLoad, this);
37238 this.store.un('load', this.onLoad, this);
37239 this.store.un('loadexception', this.collapse, this);
37241 Roo.form.ComboBox.superclass.onDestroy.call(this);
37245 fireKey : function(e){
37246 if(e.isNavKeyPress() && !this.list.isVisible()){
37247 this.fireEvent("specialkey", this, e);
37252 onResize: function(w, h){
37253 Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
37255 if(typeof w != 'number'){
37256 // we do not handle it!?!?
37259 var tw = this.trigger.getWidth();
37260 tw += this.addicon ? this.addicon.getWidth() : 0;
37261 tw += this.editicon ? this.editicon.getWidth() : 0;
37263 this.el.setWidth( this.adjustWidth('input', x));
37265 this.trigger.setStyle('left', x+'px');
37267 if(this.list && this.listWidth === undefined){
37268 var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
37269 this.list.setWidth(lw);
37270 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
37278 * Allow or prevent the user from directly editing the field text. If false is passed,
37279 * the user will only be able to select from the items defined in the dropdown list. This method
37280 * is the runtime equivalent of setting the 'editable' config option at config time.
37281 * @param {Boolean} value True to allow the user to directly edit the field text
37283 setEditable : function(value){
37284 if(value == this.editable){
37287 this.editable = value;
37289 this.el.dom.setAttribute('readOnly', true);
37290 this.el.on('mousedown', this.onTriggerClick, this);
37291 this.el.addClass('x-combo-noedit');
37293 this.el.dom.setAttribute('readOnly', false);
37294 this.el.un('mousedown', this.onTriggerClick, this);
37295 this.el.removeClass('x-combo-noedit');
37300 onBeforeLoad : function(){
37301 if(!this.hasFocus){
37304 this.innerList.update(this.loadingText ?
37305 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
37306 this.restrictHeight();
37307 this.selectedIndex = -1;
37311 onLoad : function(){
37312 if(!this.hasFocus){
37315 if(this.store.getCount() > 0){
37317 this.restrictHeight();
37318 if(this.lastQuery == this.allQuery){
37320 this.el.dom.select();
37322 if(!this.selectByValue(this.value, true)){
37323 this.select(0, true);
37327 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
37328 this.taTask.delay(this.typeAheadDelay);
37332 this.onEmptyResults();
37338 onTypeAhead : function(){
37339 if(this.store.getCount() > 0){
37340 var r = this.store.getAt(0);
37341 var newValue = r.data[this.displayField];
37342 var len = newValue.length;
37343 var selStart = this.getRawValue().length;
37344 if(selStart != len){
37345 this.setRawValue(newValue);
37346 this.selectText(selStart, newValue.length);
37352 onSelect : function(record, index){
37353 if(this.fireEvent('beforeselect', this, record, index) !== false){
37354 this.setFromData(index > -1 ? record.data : false);
37356 this.fireEvent('select', this, record, index);
37361 * Returns the currently selected field value or empty string if no value is set.
37362 * @return {String} value The selected value
37364 getValue : function(){
37365 if(this.valueField){
37366 return typeof this.value != 'undefined' ? this.value : '';
37368 return Roo.form.ComboBox.superclass.getValue.call(this);
37373 * Clears any text/value currently set in the field
37375 clearValue : function(){
37376 if(this.hiddenField){
37377 this.hiddenField.value = '';
37380 this.setRawValue('');
37381 this.lastSelectionText = '';
37382 this.applyEmptyText();
37386 * Sets the specified value into the field. If the value finds a match, the corresponding record text
37387 * will be displayed in the field. If the value does not match the data value of an existing item,
37388 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
37389 * Otherwise the field will be blank (although the value will still be set).
37390 * @param {String} value The value to match
37392 setValue : function(v){
37394 if(this.valueField){
37395 var r = this.findRecord(this.valueField, v);
37397 text = r.data[this.displayField];
37398 }else if(this.valueNotFoundText !== undefined){
37399 text = this.valueNotFoundText;
37402 this.lastSelectionText = text;
37403 if(this.hiddenField){
37404 this.hiddenField.value = v;
37406 Roo.form.ComboBox.superclass.setValue.call(this, text);
37410 * @property {Object} the last set data for the element
37415 * Sets the value of the field based on a object which is related to the record format for the store.
37416 * @param {Object} value the value to set as. or false on reset?
37418 setFromData : function(o){
37419 var dv = ''; // display value
37420 var vv = ''; // value value..
37422 if (this.displayField) {
37423 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
37425 // this is an error condition!!!
37426 console.log('no value field set for '+ this.name);
37429 if(this.valueField){
37430 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
37432 if(this.hiddenField){
37433 this.hiddenField.value = vv;
37435 this.lastSelectionText = dv;
37436 Roo.form.ComboBox.superclass.setValue.call(this, dv);
37440 // no hidden field.. - we store the value in 'value', but still display
37441 // display field!!!!
37442 this.lastSelectionText = dv;
37443 Roo.form.ComboBox.superclass.setValue.call(this, dv);
37449 reset : function(){
37450 // overridden so that last data is reset..
37451 this.setValue(this.originalValue);
37452 this.clearInvalid();
37453 this.lastData = false;
37456 findRecord : function(prop, value){
37458 if(this.store.getCount() > 0){
37459 this.store.each(function(r){
37460 if(r.data[prop] == value){
37470 onViewMove : function(e, t){
37471 this.inKeyMode = false;
37475 onViewOver : function(e, t){
37476 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
37479 var item = this.view.findItemFromChild(t);
37481 var index = this.view.indexOf(item);
37482 this.select(index, false);
37487 onViewClick : function(doFocus){
37488 var index = this.view.getSelectedIndexes()[0];
37489 var r = this.store.getAt(index);
37491 this.onSelect(r, index);
37493 if(doFocus !== false && !this.blockFocus){
37499 restrictHeight : function(){
37500 this.innerList.dom.style.height = '';
37501 var inner = this.innerList.dom;
37502 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
37503 this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
37504 this.list.beginUpdate();
37505 this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
37506 this.list.alignTo(this.el, this.listAlign);
37507 this.list.endUpdate();
37511 onEmptyResults : function(){
37516 * Returns true if the dropdown list is expanded, else false.
37518 isExpanded : function(){
37519 return this.list.isVisible();
37523 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
37524 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
37525 * @param {String} value The data value of the item to select
37526 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
37527 * selected item if it is not currently in view (defaults to true)
37528 * @return {Boolean} True if the value matched an item in the list, else false
37530 selectByValue : function(v, scrollIntoView){
37531 if(v !== undefined && v !== null){
37532 var r = this.findRecord(this.valueField || this.displayField, v);
37534 this.select(this.store.indexOf(r), scrollIntoView);
37542 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
37543 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
37544 * @param {Number} index The zero-based index of the list item to select
37545 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
37546 * selected item if it is not currently in view (defaults to true)
37548 select : function(index, scrollIntoView){
37549 this.selectedIndex = index;
37550 this.view.select(index);
37551 if(scrollIntoView !== false){
37552 var el = this.view.getNode(index);
37554 this.innerList.scrollChildIntoView(el, false);
37560 selectNext : function(){
37561 var ct = this.store.getCount();
37563 if(this.selectedIndex == -1){
37565 }else if(this.selectedIndex < ct-1){
37566 this.select(this.selectedIndex+1);
37572 selectPrev : function(){
37573 var ct = this.store.getCount();
37575 if(this.selectedIndex == -1){
37577 }else if(this.selectedIndex != 0){
37578 this.select(this.selectedIndex-1);
37584 onKeyUp : function(e){
37585 if(this.editable !== false && !e.isSpecialKey()){
37586 this.lastKey = e.getKey();
37587 this.dqTask.delay(this.queryDelay);
37592 validateBlur : function(){
37593 return !this.list || !this.list.isVisible();
37597 initQuery : function(){
37598 this.doQuery(this.getRawValue());
37602 doForce : function(){
37603 if(this.el.dom.value.length > 0){
37604 this.el.dom.value =
37605 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
37606 this.applyEmptyText();
37611 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
37612 * query allowing the query action to be canceled if needed.
37613 * @param {String} query The SQL query to execute
37614 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
37615 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
37616 * saved in the current store (defaults to false)
37618 doQuery : function(q, forceAll){
37619 if(q === undefined || q === null){
37624 forceAll: forceAll,
37628 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
37632 forceAll = qe.forceAll;
37633 if(forceAll === true || (q.length >= this.minChars)){
37634 if(this.lastQuery != q){
37635 this.lastQuery = q;
37636 if(this.mode == 'local'){
37637 this.selectedIndex = -1;
37639 this.store.clearFilter();
37641 this.store.filter(this.displayField, q);
37645 this.store.baseParams[this.queryParam] = q;
37647 params: this.getParams(q)
37652 this.selectedIndex = -1;
37659 getParams : function(q){
37661 //p[this.queryParam] = q;
37664 p.limit = this.pageSize;
37670 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
37672 collapse : function(){
37673 if(!this.isExpanded()){
37677 Roo.get(document).un('mousedown', this.collapseIf, this);
37678 Roo.get(document).un('mousewheel', this.collapseIf, this);
37679 this.fireEvent('collapse', this);
37683 collapseIf : function(e){
37684 if(!e.within(this.wrap) && !e.within(this.list)){
37690 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
37692 expand : function(){
37693 if(this.isExpanded() || !this.hasFocus){
37696 this.list.alignTo(this.el, this.listAlign);
37698 Roo.get(document).on('mousedown', this.collapseIf, this);
37699 Roo.get(document).on('mousewheel', this.collapseIf, this);
37700 this.fireEvent('expand', this);
37704 // Implements the default empty TriggerField.onTriggerClick function
37705 onTriggerClick : function(){
37709 if(this.isExpanded()){
37711 if (!this.blockFocus) {
37716 this.hasFocus = true;
37717 if(this.triggerAction == 'all') {
37718 this.doQuery(this.allQuery, true);
37720 this.doQuery(this.getRawValue());
37722 if (!this.blockFocus) {
37729 * @cfg {Boolean} grow
37733 * @cfg {Number} growMin
37737 * @cfg {Number} growMax
37746 * Ext JS Library 1.1.1
37747 * Copyright(c) 2006-2007, Ext JS, LLC.
37749 * Originally Released Under LGPL - original licence link has changed is not relivant.
37752 * <script type="text/javascript">
37755 * @class Roo.form.Checkbox
37756 * @extends Roo.form.Field
37757 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
37759 * Creates a new Checkbox
37760 * @param {Object} config Configuration options
37762 Roo.form.Checkbox = function(config){
37763 Roo.form.Checkbox.superclass.constructor.call(this, config);
37767 * Fires when the checkbox is checked or unchecked.
37768 * @param {Roo.form.Checkbox} this This checkbox
37769 * @param {Boolean} checked The new checked value
37775 Roo.extend(Roo.form.Checkbox, Roo.form.Field, {
37777 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
37779 focusClass : undefined,
37781 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
37783 fieldClass: "x-form-field",
37785 * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
37789 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
37790 * {tag: "input", type: "checkbox", autocomplete: "off"})
37792 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
37794 * @cfg {String} boxLabel The text that appears beside the checkbox
37798 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
37802 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
37804 valueOff: '0', // value when not checked..
37806 actionMode : 'viewEl',
37809 itemCls : 'x-menu-check-item x-form-item',
37810 groupClass : 'x-menu-group-item',
37811 inputType : 'hidden',
37814 inSetChecked: false, // check that we are not calling self...
37816 inputElement: false, // real input element?
37817 basedOn: false, // ????
37819 isFormField: true, // not sure where this is needed!!!!
37821 onResize : function(){
37822 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
37823 if(!this.boxLabel){
37824 this.el.alignTo(this.wrap, 'c-c');
37828 initEvents : function(){
37829 Roo.form.Checkbox.superclass.initEvents.call(this);
37830 this.el.on("click", this.onClick, this);
37831 this.el.on("change", this.onClick, this);
37835 getResizeEl : function(){
37839 getPositionEl : function(){
37844 onRender : function(ct, position){
37845 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
37847 if(this.inputValue !== undefined){
37848 this.el.dom.value = this.inputValue;
37851 //this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
37852 this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
37853 var viewEl = this.wrap.createChild({
37854 tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
37855 this.viewEl = viewEl;
37856 this.wrap.on('click', this.onClick, this);
37858 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
37859 this.el.on('propertychange', this.setFromHidden, this); //ie
37864 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
37865 // viewEl.on('click', this.onClick, this);
37867 //if(this.checked){
37868 this.setChecked(this.checked);
37870 //this.checked = this.el.dom;
37876 initValue : Roo.emptyFn,
37879 * Returns the checked state of the checkbox.
37880 * @return {Boolean} True if checked, else false
37882 getValue : function(){
37884 return String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
37886 return this.valueOff;
37891 onClick : function(){
37892 this.setChecked(!this.checked);
37894 //if(this.el.dom.checked != this.checked){
37895 // this.setValue(this.el.dom.checked);
37900 * Sets the checked state of the checkbox.
37901 * On is always based on a string comparison between inputValue and the param.
37902 * @param {Boolean/String} value - the value to set
37903 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
37905 setValue : function(v,suppressEvent){
37908 //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
37909 //if(this.el && this.el.dom){
37910 // this.el.dom.checked = this.checked;
37911 // this.el.dom.defaultChecked = this.checked;
37913 this.setChecked(String(v) === String(this.inputValue), suppressEvent);
37914 //this.fireEvent("check", this, this.checked);
37917 setChecked : function(state,suppressEvent)
37919 if (this.inSetChecked) {
37920 this.checked = state;
37926 this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked');
37928 this.checked = state;
37929 if(suppressEvent !== true){
37930 this.fireEvent('checkchange', this, state);
37932 this.inSetChecked = true;
37933 this.el.dom.value = state ? this.inputValue : this.valueOff;
37934 this.inSetChecked = false;
37937 // handle setting of hidden value by some other method!!?!?
37938 setFromHidden: function()
37943 //console.log("SET FROM HIDDEN");
37944 //alert('setFrom hidden');
37945 this.setValue(this.el.dom.value);
37948 onDestroy : function()
37951 Roo.get(this.viewEl).remove();
37954 Roo.form.Checkbox.superclass.onDestroy.call(this);
37959 * Ext JS Library 1.1.1
37960 * Copyright(c) 2006-2007, Ext JS, LLC.
37962 * Originally Released Under LGPL - original licence link has changed is not relivant.
37965 * <script type="text/javascript">
37969 * @class Roo.form.Radio
37970 * @extends Roo.form.Checkbox
37971 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
37972 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
37974 * Creates a new Radio
37975 * @param {Object} config Configuration options
37977 Roo.form.Radio = function(){
37978 Roo.form.Radio.superclass.constructor.apply(this, arguments);
37980 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
37981 inputType: 'radio',
37984 * If this radio is part of a group, it will return the selected value
37987 getGroupValue : function(){
37988 return this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
37990 });//<script type="text/javascript">
37993 * Ext JS Library 1.1.1
37994 * Copyright(c) 2006-2007, Ext JS, LLC.
37995 * licensing@extjs.com
37997 * http://www.extjs.com/license
38003 * Default CSS appears to render it as fixed text by default (should really be Sans-Serif)
38004 * - IE ? - no idea how much works there.
38012 * @class Ext.form.HtmlEditor
38013 * @extends Ext.form.Field
38014 * Provides a lightweight HTML Editor component.
38015 * WARNING - THIS CURRENTlY ONLY WORKS ON FIREFOX - USE FCKeditor for a cross platform version
38017 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
38018 * supported by this editor.</b><br/><br/>
38019 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
38020 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
38022 Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
38024 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
38028 * @cfg {String} createLinkText The default text for the create link prompt
38030 createLinkText : 'Please enter the URL for the link:',
38032 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
38034 defaultLinkValue : 'http:/'+'/',
38040 // private properties
38041 validationEvent : false,
38043 initialized : false,
38045 sourceEditMode : false,
38046 onFocus : Roo.emptyFn,
38048 hideMode:'offsets',
38049 defaultAutoCreate : {
38051 style:"width:500px;height:300px;",
38052 autocomplete: "off"
38056 initComponent : function(){
38059 * @event initialize
38060 * Fires when the editor is fully initialized (including the iframe)
38061 * @param {HtmlEditor} this
38066 * Fires when the editor is first receives the focus. Any insertion must wait
38067 * until after this event.
38068 * @param {HtmlEditor} this
38072 * @event beforesync
38073 * Fires before the textarea is updated with content from the editor iframe. Return false
38074 * to cancel the sync.
38075 * @param {HtmlEditor} this
38076 * @param {String} html
38080 * @event beforepush
38081 * Fires before the iframe editor is updated with content from the textarea. Return false
38082 * to cancel the push.
38083 * @param {HtmlEditor} this
38084 * @param {String} html
38089 * Fires when the textarea is updated with content from the editor iframe.
38090 * @param {HtmlEditor} this
38091 * @param {String} html
38096 * Fires when the iframe editor is updated with content from the textarea.
38097 * @param {HtmlEditor} this
38098 * @param {String} html
38102 * @event editmodechange
38103 * Fires when the editor switches edit modes
38104 * @param {HtmlEditor} this
38105 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
38107 editmodechange: true,
38109 * @event editorevent
38110 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
38111 * @param {HtmlEditor} this
38118 * Protected method that will not generally be called directly. It
38119 * is called when the editor creates its toolbar. Override this method if you need to
38120 * add custom toolbar buttons.
38121 * @param {HtmlEditor} editor
38123 createToolbar : function(editor){
38124 if (!editor.toolbars || !editor.toolbars.length) {
38125 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
38128 for (var i =0 ; i < editor.toolbars.length;i++) {
38129 editor.toolbars[i] = Roo.factory(editor.toolbars[i], Roo.form.HtmlEditor);
38130 editor.toolbars[i].init(editor);
38137 * Protected method that will not generally be called directly. It
38138 * is called when the editor initializes the iframe with HTML contents. Override this method if you
38139 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
38141 getDocMarkup : function(){
38142 return '<html><head><style type="text/css">body{border:0;margin:0;padding:3px;height:98%;cursor:text;}</style></head><body></body></html>';
38146 onRender : function(ct, position){
38147 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
38148 this.el.dom.style.border = '0 none';
38149 this.el.dom.setAttribute('tabIndex', -1);
38150 this.el.addClass('x-hidden');
38151 if(Roo.isIE){ // fix IE 1px bogus margin
38152 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
38154 this.wrap = this.el.wrap({
38155 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
38158 this.frameId = Roo.id();
38159 this.createToolbar(this);
38166 var iframe = this.wrap.createChild({
38169 name: this.frameId,
38170 frameBorder : 'no',
38171 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
38174 // console.log(iframe);
38175 //this.wrap.dom.appendChild(iframe);
38177 this.iframe = iframe.dom;
38179 this.assignDocWin();
38181 this.doc.designMode = 'on';
38184 this.doc.write(this.getDocMarkup());
38188 var task = { // must defer to wait for browser to be ready
38190 //console.log("run task?" + this.doc.readyState);
38191 this.assignDocWin();
38192 if(this.doc.body || this.doc.readyState == 'complete'){
38194 this.doc.designMode="on";
38198 Roo.TaskMgr.stop(task);
38199 this.initEditor.defer(10, this);
38206 Roo.TaskMgr.start(task);
38209 this.setSize(this.el.getSize());
38214 onResize : function(w, h){
38215 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
38216 if(this.el && this.iframe){
38217 if(typeof w == 'number'){
38218 var aw = w - this.wrap.getFrameWidth('lr');
38219 this.el.setWidth(this.adjustWidth('textarea', aw));
38220 this.iframe.style.width = aw + 'px';
38222 if(typeof h == 'number'){
38224 for (var i =0; i < this.toolbars.length;i++) {
38225 // fixme - ask toolbars for heights?
38226 tbh += this.toolbars[i].tb.el.getHeight();
38232 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
38233 this.el.setHeight(this.adjustWidth('textarea', ah));
38234 this.iframe.style.height = ah + 'px';
38236 (this.doc.body || this.doc.documentElement).style.height = (ah - (this.iframePad*2)) + 'px';
38243 * Toggles the editor between standard and source edit mode.
38244 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
38246 toggleSourceEdit : function(sourceEditMode){
38248 this.sourceEditMode = sourceEditMode === true;
38250 if(this.sourceEditMode){
38253 this.iframe.className = 'x-hidden';
38254 this.el.removeClass('x-hidden');
38255 this.el.dom.removeAttribute('tabIndex');
38260 this.iframe.className = '';
38261 this.el.addClass('x-hidden');
38262 this.el.dom.setAttribute('tabIndex', -1);
38265 this.setSize(this.wrap.getSize());
38266 this.fireEvent('editmodechange', this, this.sourceEditMode);
38269 // private used internally
38270 createLink : function(){
38271 var url = prompt(this.createLinkText, this.defaultLinkValue);
38272 if(url && url != 'http:/'+'/'){
38273 this.relayCmd('createlink', url);
38277 // private (for BoxComponent)
38278 adjustSize : Roo.BoxComponent.prototype.adjustSize,
38280 // private (for BoxComponent)
38281 getResizeEl : function(){
38285 // private (for BoxComponent)
38286 getPositionEl : function(){
38291 initEvents : function(){
38292 this.originalValue = this.getValue();
38296 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
38299 markInvalid : Roo.emptyFn,
38301 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
38304 clearInvalid : Roo.emptyFn,
38306 setValue : function(v){
38307 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
38312 * Protected method that will not generally be called directly. If you need/want
38313 * custom HTML cleanup, this is the method you should override.
38314 * @param {String} html The HTML to be cleaned
38315 * return {String} The cleaned HTML
38317 cleanHtml : function(html){
38318 html = String(html);
38319 if(html.length > 5){
38320 if(Roo.isSafari){ // strip safari nonsense
38321 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
38324 if(html == ' '){
38331 * Protected method that will not generally be called directly. Syncs the contents
38332 * of the editor iframe with the textarea.
38334 syncValue : function(){
38335 if(this.initialized){
38336 var bd = (this.doc.body || this.doc.documentElement);
38337 var html = bd.innerHTML;
38339 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
38340 var m = bs.match(/text-align:(.*?);/i);
38342 html = '<div style="'+m[0]+'">' + html + '</div>';
38345 html = this.cleanHtml(html);
38346 if(this.fireEvent('beforesync', this, html) !== false){
38347 this.el.dom.value = html;
38348 this.fireEvent('sync', this, html);
38354 * Protected method that will not generally be called directly. Pushes the value of the textarea
38355 * into the iframe editor.
38357 pushValue : function(){
38358 if(this.initialized){
38359 var v = this.el.dom.value;
38363 if(this.fireEvent('beforepush', this, v) !== false){
38364 (this.doc.body || this.doc.documentElement).innerHTML = v;
38365 this.fireEvent('push', this, v);
38371 deferFocus : function(){
38372 this.focus.defer(10, this);
38376 focus : function(){
38377 if(this.win && !this.sourceEditMode){
38384 assignDocWin: function()
38386 var iframe = this.iframe;
38389 this.doc = iframe.contentWindow.document;
38390 this.win = iframe.contentWindow;
38392 if (!Roo.get(this.frameId)) {
38395 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
38396 this.win = Roo.get(this.frameId).dom.contentWindow;
38401 initEditor : function(){
38402 //console.log("INIT EDITOR");
38403 this.assignDocWin();
38407 this.doc.designMode="on";
38409 this.doc.write(this.getDocMarkup());
38412 var dbody = (this.doc.body || this.doc.documentElement);
38413 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
38414 // this copies styles from the containing element into thsi one..
38415 // not sure why we need all of this..
38416 var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
38417 ss['background-attachment'] = 'fixed'; // w3c
38418 dbody.bgProperties = 'fixed'; // ie
38419 Roo.DomHelper.applyStyles(dbody, ss);
38420 Roo.EventManager.on(this.doc, {
38421 'mousedown': this.onEditorEvent,
38422 'dblclick': this.onEditorEvent,
38423 'click': this.onEditorEvent,
38424 'keyup': this.onEditorEvent,
38429 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
38431 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
38432 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
38434 this.initialized = true;
38436 this.fireEvent('initialize', this);
38441 onDestroy : function(){
38447 for (var i =0; i < this.toolbars.length;i++) {
38448 // fixme - ask toolbars for heights?
38449 this.toolbars[i].onDestroy();
38452 this.wrap.dom.innerHTML = '';
38453 this.wrap.remove();
38458 onFirstFocus : function(){
38460 this.assignDocWin();
38463 this.activated = true;
38464 for (var i =0; i < this.toolbars.length;i++) {
38465 this.toolbars[i].onFirstFocus();
38468 if(Roo.isGecko){ // prevent silly gecko errors
38470 var s = this.win.getSelection();
38471 if(!s.focusNode || s.focusNode.nodeType != 3){
38472 var r = s.getRangeAt(0);
38473 r.selectNodeContents((this.doc.body || this.doc.documentElement));
38478 this.execCmd('useCSS', true);
38479 this.execCmd('styleWithCSS', false);
38482 this.fireEvent('activate', this);
38486 adjustFont: function(btn){
38487 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
38488 //if(Roo.isSafari){ // safari
38491 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
38492 if(Roo.isSafari){ // safari
38493 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
38494 v = (v < 10) ? 10 : v;
38495 v = (v > 48) ? 48 : v;
38496 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
38501 v = Math.max(1, v+adjust);
38503 this.execCmd('FontSize', v );
38506 onEditorEvent : function(e){
38507 this.fireEvent('editorevent', this, e);
38508 // this.updateToolbar();
38512 insertTag : function(tg)
38514 // could be a bit smarter... -> wrap the current selected tRoo..
38516 this.execCmd("formatblock", tg);
38520 insertText : function(txt)
38524 range = this.createRange();
38525 range.deleteContents();
38526 //alert(Sender.getAttribute('label'));
38528 range.insertNode(this.doc.createTextNode(txt));
38532 relayBtnCmd : function(btn){
38533 this.relayCmd(btn.cmd);
38537 * Executes a Midas editor command on the editor document and performs necessary focus and
38538 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
38539 * @param {String} cmd The Midas command
38540 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
38542 relayCmd : function(cmd, value){
38544 this.execCmd(cmd, value);
38545 this.fireEvent('editorevent', this);
38546 //this.updateToolbar();
38551 * Executes a Midas editor command directly on the editor document.
38552 * For visual commands, you should use {@link #relayCmd} instead.
38553 * <b>This should only be called after the editor is initialized.</b>
38554 * @param {String} cmd The Midas command
38555 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
38557 execCmd : function(cmd, value){
38558 this.doc.execCommand(cmd, false, value === undefined ? null : value);
38564 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
38566 * @param {String} text
38568 insertAtCursor : function(text){
38569 if(!this.activated){
38574 var r = this.doc.selection.createRange();
38581 }else if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
38583 this.execCmd('InsertHTML', text);
38588 mozKeyPress : function(e){
38590 var c = e.getCharCode(), cmd;
38593 c = String.fromCharCode(c).toLowerCase();
38604 this.cleanUpPaste.defer(100, this);
38612 e.preventDefault();
38620 fixKeys : function(){ // load time branching for fastest keydown performance
38622 return function(e){
38623 var k = e.getKey(), r;
38626 r = this.doc.selection.createRange();
38629 r.pasteHTML('    ');
38636 r = this.doc.selection.createRange();
38638 var target = r.parentElement();
38639 if(!target || target.tagName.toLowerCase() != 'li'){
38641 r.pasteHTML('<br />');
38647 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
38648 this.cleanUpPaste.defer(100, this);
38654 }else if(Roo.isOpera){
38655 return function(e){
38656 var k = e.getKey();
38660 this.execCmd('InsertHTML','    ');
38663 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
38664 this.cleanUpPaste.defer(100, this);
38669 }else if(Roo.isSafari){
38670 return function(e){
38671 var k = e.getKey();
38675 this.execCmd('InsertText','\t');
38679 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
38680 this.cleanUpPaste.defer(100, this);
38688 getAllAncestors: function()
38690 var p = this.getSelectedNode();
38693 a.push(p); // push blank onto stack..
38694 p = this.getParentElement();
38698 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
38702 a.push(this.doc.body);
38706 lastSelNode : false,
38709 getSelection : function()
38711 this.assignDocWin();
38712 return Roo.isIE ? this.doc.selection : this.win.getSelection();
38715 getSelectedNode: function()
38717 // this may only work on Gecko!!!
38719 // should we cache this!!!!
38724 var range = this.createRange(this.getSelection());
38727 var parent = range.parentElement();
38729 var testRange = range.duplicate();
38730 testRange.moveToElementText(parent);
38731 if (testRange.inRange(range)) {
38734 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
38737 parent = parent.parentElement;
38743 var ar = range.endContainer.childNodes;
38745 ar = range.commonAncestorContainer.childNodes;
38746 //alert(ar.length);
38749 var other_nodes = [];
38750 var has_other_nodes = false;
38751 for (var i=0;i<ar.length;i++) {
38752 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
38755 // fullly contained node.
38757 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
38762 // probably selected..
38763 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
38764 other_nodes.push(ar[i]);
38767 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
38772 has_other_nodes = true;
38774 if (!nodes.length && other_nodes.length) {
38775 nodes= other_nodes;
38777 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
38783 createRange: function(sel)
38785 // this has strange effects when using with
38786 // top toolbar - not sure if it's a great idea.
38787 //this.editor.contentWindow.focus();
38788 if (typeof sel != "undefined") {
38790 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
38792 return this.doc.createRange();
38795 return this.doc.createRange();
38798 getParentElement: function()
38801 this.assignDocWin();
38802 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
38804 var range = this.createRange(sel);
38807 var p = range.commonAncestorContainer;
38808 while (p.nodeType == 3) { // text node
38820 // BC Hacks - cause I cant work out what i was trying to do..
38821 rangeIntersectsNode : function(range, node)
38823 var nodeRange = node.ownerDocument.createRange();
38825 nodeRange.selectNode(node);
38828 nodeRange.selectNodeContents(node);
38831 return range.compareBoundaryPoints(Range.END_TO_START, nodeRange) == -1 &&
38832 range.compareBoundaryPoints(Range.START_TO_END, nodeRange) == 1;
38834 rangeCompareNode : function(range, node) {
38835 var nodeRange = node.ownerDocument.createRange();
38837 nodeRange.selectNode(node);
38839 nodeRange.selectNodeContents(node);
38841 var nodeIsBefore = range.compareBoundaryPoints(Range.START_TO_START, nodeRange) == 1;
38842 var nodeIsAfter = range.compareBoundaryPoints(Range.END_TO_END, nodeRange) == -1;
38844 if (nodeIsBefore && !nodeIsAfter)
38846 if (!nodeIsBefore && nodeIsAfter)
38848 if (nodeIsBefore && nodeIsAfter)
38854 // private? - in a new class?
38855 cleanUpPaste : function()
38857 // cleans up the whole document..
38858 // console.log('cleanuppaste');
38859 this.cleanUpChildren(this.doc.body)
38863 cleanUpChildren : function (n)
38865 if (!n.childNodes.length) {
38868 for (var i = n.childNodes.length-1; i > -1 ; i--) {
38869 this.cleanUpChild(n.childNodes[i]);
38876 cleanUpChild : function (node)
38878 //console.log(node);
38879 if (node.nodeName == "#text") {
38880 // clean up silly Windows -- stuff?
38883 if (Roo.form.HtmlEditor.black.indexOf(node.tagName.toLowerCase()) > -1) {
38885 node.parentNode.removeChild(node);
38889 if (!node.attributes || !node.attributes.length) {
38890 this.cleanUpChildren(node);
38894 function cleanAttr(n,v)
38897 if (v.match(/^\./) || v.match(/^\//)) {
38900 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
38903 Roo.log("(REMOVE)"+ node.tagName +'.' + n + '=' + v);
38904 node.removeAttribute(n);
38908 function cleanStyle(n,v)
38910 if (v.match(/expression/)) { //XSS?? should we even bother..
38911 node.removeAttribute(n);
38914 var parts = v.split(/;/);
38915 Roo.each(parts, function(p) {
38916 p = p.replace(/\s+/g,'');
38920 var l = p.split(':').shift().replace(/\s+/g,'');
38922 if (Roo.form.HtmlEditor.cwhite.indexOf(l) < 0) {
38923 Roo.log('(REMOVE)' + node.tagName +'.' + n + ':'+l + '=' + v);
38924 node.removeAttribute(n);
38933 for (var i = node.attributes.length-1; i > -1 ; i--) {
38934 var a = node.attributes[i];
38936 if (Roo.form.HtmlEditor.ablack.indexOf(a.name.toLowerCase()) > -1) {
38937 node.removeAttribute(a.name);
38940 if (Roo.form.HtmlEditor.aclean.indexOf(a.name.toLowerCase()) > -1) {
38941 cleanAttr(a.name,a.value); // fixme..
38944 if (a.name == 'style') {
38945 cleanStyle(a.name,a.value);
38955 this.cleanUpChildren(node);
38961 // hide stuff that is not compatible
38975 * @event specialkey
38979 * @cfg {String} fieldClass @hide
38982 * @cfg {String} focusClass @hide
38985 * @cfg {String} autoCreate @hide
38988 * @cfg {String} inputType @hide
38991 * @cfg {String} invalidClass @hide
38994 * @cfg {String} invalidText @hide
38997 * @cfg {String} msgFx @hide
39000 * @cfg {String} validateOnBlur @hide
39004 Roo.form.HtmlEditor.white = [
39005 'area', 'br', 'img', 'input', 'hr', 'wbr',
39007 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
39008 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
39009 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
39010 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
39011 'table', 'ul', 'xmp',
39013 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
39016 'dir', 'menu', 'ol', 'ul', 'dl'
39021 Roo.form.HtmlEditor.black = [
39022 'embed', 'object', // eventually enable for flash?
39024 'base', 'basefont', 'bgsound', 'blink', 'body',
39025 'frame', 'frameset', 'head', 'html', 'ilayer',
39026 'iframe', 'layer', 'link', 'meta', 'object',
39028 'script', 'style' ,'title', 'xml' // clean later..
39030 Roo.form.HtmlEditor.clean = [
39031 'script', 'style', 'title', 'xml'
39036 Roo.form.HtmlEditor.ablack = [
39040 Roo.form.HtmlEditor.aclean = [
39041 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
39045 Roo.form.HtmlEditor.pwhite= [
39046 'http', 'https', 'mailto'
39049 Roo.form.HtmlEditor.cwhite= [
39054 // <script type="text/javascript">
39057 * Ext JS Library 1.1.1
39058 * Copyright(c) 2006-2007, Ext JS, LLC.
39064 * @class Roo.form.HtmlEditorToolbar1
39069 new Roo.form.HtmlEditor({
39072 new Roo.form.HtmlEditorToolbar1({
39073 disable : { fonts: 1 , format: 1, ..., ... , ...],
39079 * @cfg {Object} disable List of elements to disable..
39080 * @cfg {Array} btns List of additional buttons.
39084 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
39087 Roo.form.HtmlEditor.ToolbarStandard = function(config)
39090 Roo.apply(this, config);
39091 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
39092 // dont call parent... till later.
39095 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
39103 * @cfg {Object} disable List of toolbar elements to disable
39108 * @cfg {Array} fontFamilies An array of available font families
39126 // "á" , ?? a acute?
39131 "°" // , // degrees
39133 // "é" , // e ecute
39134 // "ú" , // u ecute?
39137 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
39138 "input:submit", "input:button", "select", "textarea", "label" ],
39141 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
39143 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"]
39146 * @cfg {String} defaultFont default font to use.
39148 defaultFont: 'tahoma',
39150 fontSelect : false,
39153 formatCombo : false,
39155 init : function(editor)
39157 this.editor = editor;
39160 var fid = editor.frameId;
39162 function btn(id, toggle, handler){
39163 var xid = fid + '-'+ id ;
39167 cls : 'x-btn-icon x-edit-'+id,
39168 enableToggle:toggle !== false,
39169 scope: editor, // was editor...
39170 handler:handler||editor.relayBtnCmd,
39171 clickEvent:'mousedown',
39172 tooltip: etb.buttonTips[id] || undefined, ///tips ???
39179 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
39181 // stop form submits
39182 tb.el.on('click', function(e){
39183 e.preventDefault(); // what does this do?
39186 if(!this.disable.font && !Roo.isSafari){
39187 /* why no safari for fonts
39188 editor.fontSelect = tb.el.createChild({
39191 cls:'x-font-select',
39192 html: editor.createFontOptions()
39194 editor.fontSelect.on('change', function(){
39195 var font = editor.fontSelect.dom.value;
39196 editor.relayCmd('fontname', font);
39197 editor.deferFocus();
39200 editor.fontSelect.dom,
39205 if(!this.disable.formats){
39206 this.formatCombo = new Roo.form.ComboBox({
39207 store: new Roo.data.SimpleStore({
39210 data : this.formats // from states.js
39213 //autoCreate : {tag: "div", size: "20"},
39214 displayField:'tag',
39218 triggerAction: 'all',
39219 emptyText:'Add tag',
39220 selectOnFocus:true,
39223 'select': function(c, r, i) {
39224 editor.insertTag(r.get('tag'));
39230 tb.addField(this.formatCombo);
39234 if(!this.disable.format){
39241 if(!this.disable.fontSize){
39246 btn('increasefontsize', false, editor.adjustFont),
39247 btn('decreasefontsize', false, editor.adjustFont)
39252 if(this.disable.colors){
39255 id:editor.frameId +'-forecolor',
39256 cls:'x-btn-icon x-edit-forecolor',
39257 clickEvent:'mousedown',
39258 tooltip: this.buttonTips['forecolor'] || undefined,
39260 menu : new Roo.menu.ColorMenu({
39261 allowReselect: true,
39262 focus: Roo.emptyFn,
39265 selectHandler: function(cp, color){
39266 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
39267 editor.deferFocus();
39270 clickEvent:'mousedown'
39273 id:editor.frameId +'backcolor',
39274 cls:'x-btn-icon x-edit-backcolor',
39275 clickEvent:'mousedown',
39276 tooltip: this.buttonTips['backcolor'] || undefined,
39278 menu : new Roo.menu.ColorMenu({
39279 focus: Roo.emptyFn,
39282 allowReselect: true,
39283 selectHandler: function(cp, color){
39285 editor.execCmd('useCSS', false);
39286 editor.execCmd('hilitecolor', color);
39287 editor.execCmd('useCSS', true);
39288 editor.deferFocus();
39290 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
39291 Roo.isSafari || Roo.isIE ? '#'+color : color);
39292 editor.deferFocus();
39296 clickEvent:'mousedown'
39301 // now add all the items...
39304 if(!this.disable.alignments){
39307 btn('justifyleft'),
39308 btn('justifycenter'),
39309 btn('justifyright')
39313 //if(!Roo.isSafari){
39314 if(!this.disable.links){
39317 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
39321 if(!this.disable.lists){
39324 btn('insertorderedlist'),
39325 btn('insertunorderedlist')
39328 if(!this.disable.sourceEdit){
39331 btn('sourceedit', true, function(btn){
39332 this.toggleSourceEdit(btn.pressed);
39339 // special menu.. - needs to be tidied up..
39340 if (!this.disable.special) {
39343 cls: 'x-edit-none',
39348 for (var i =0; i < this.specialChars.length; i++) {
39349 smenu.menu.items.push({
39351 html: this.specialChars[i],
39352 handler: function(a,b) {
39353 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
39366 for(var i =0; i< this.btns.length;i++) {
39367 var b = this.btns[i];
39368 b.cls = 'x-edit-none';
39377 // disable everything...
39379 this.tb.items.each(function(item){
39380 if(item.id != editor.frameId+ '-sourceedit'){
39384 this.rendered = true;
39386 // the all the btns;
39387 editor.on('editorevent', this.updateToolbar, this);
39388 // other toolbars need to implement this..
39389 //editor.on('editmodechange', this.updateToolbar, this);
39395 * Protected method that will not generally be called directly. It triggers
39396 * a toolbar update by reading the markup state of the current selection in the editor.
39398 updateToolbar: function(){
39400 if(!this.editor.activated){
39401 this.editor.onFirstFocus();
39405 var btns = this.tb.items.map,
39406 doc = this.editor.doc,
39407 frameId = this.editor.frameId;
39409 if(!this.disable.font && !Roo.isSafari){
39411 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
39412 if(name != this.fontSelect.dom.value){
39413 this.fontSelect.dom.value = name;
39417 if(!this.disable.format){
39418 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
39419 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
39420 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
39422 if(!this.disable.alignments){
39423 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
39424 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
39425 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
39427 if(!Roo.isSafari && !this.disable.lists){
39428 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
39429 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
39432 var ans = this.editor.getAllAncestors();
39433 if (this.formatCombo) {
39436 var store = this.formatCombo.store;
39437 this.formatCombo.setValue("");
39438 for (var i =0; i < ans.length;i++) {
39439 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
39441 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
39449 // hides menus... - so this cant be on a menu...
39450 Roo.menu.MenuMgr.hideAll();
39452 //this.editorsyncValue();
39456 createFontOptions : function(){
39457 var buf = [], fs = this.fontFamilies, ff, lc;
39458 for(var i = 0, len = fs.length; i< len; i++){
39460 lc = ff.toLowerCase();
39462 '<option value="',lc,'" style="font-family:',ff,';"',
39463 (this.defaultFont == lc ? ' selected="true">' : '>'),
39468 return buf.join('');
39471 toggleSourceEdit : function(sourceEditMode){
39472 if(sourceEditMode === undefined){
39473 sourceEditMode = !this.sourceEditMode;
39475 this.sourceEditMode = sourceEditMode === true;
39476 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
39477 // just toggle the button?
39478 if(btn.pressed !== this.editor.sourceEditMode){
39479 btn.toggle(this.editor.sourceEditMode);
39483 if(this.sourceEditMode){
39484 this.tb.items.each(function(item){
39485 if(item.cmd != 'sourceedit'){
39491 if(this.initialized){
39492 this.tb.items.each(function(item){
39498 // tell the editor that it's been pressed..
39499 this.editor.toggleSourceEdit(sourceEditMode);
39503 * Object collection of toolbar tooltips for the buttons in the editor. The key
39504 * is the command id associated with that button and the value is a valid QuickTips object.
39509 title: 'Bold (Ctrl+B)',
39510 text: 'Make the selected text bold.',
39511 cls: 'x-html-editor-tip'
39514 title: 'Italic (Ctrl+I)',
39515 text: 'Make the selected text italic.',
39516 cls: 'x-html-editor-tip'
39524 title: 'Bold (Ctrl+B)',
39525 text: 'Make the selected text bold.',
39526 cls: 'x-html-editor-tip'
39529 title: 'Italic (Ctrl+I)',
39530 text: 'Make the selected text italic.',
39531 cls: 'x-html-editor-tip'
39534 title: 'Underline (Ctrl+U)',
39535 text: 'Underline the selected text.',
39536 cls: 'x-html-editor-tip'
39538 increasefontsize : {
39539 title: 'Grow Text',
39540 text: 'Increase the font size.',
39541 cls: 'x-html-editor-tip'
39543 decreasefontsize : {
39544 title: 'Shrink Text',
39545 text: 'Decrease the font size.',
39546 cls: 'x-html-editor-tip'
39549 title: 'Text Highlight Color',
39550 text: 'Change the background color of the selected text.',
39551 cls: 'x-html-editor-tip'
39554 title: 'Font Color',
39555 text: 'Change the color of the selected text.',
39556 cls: 'x-html-editor-tip'
39559 title: 'Align Text Left',
39560 text: 'Align text to the left.',
39561 cls: 'x-html-editor-tip'
39564 title: 'Center Text',
39565 text: 'Center text in the editor.',
39566 cls: 'x-html-editor-tip'
39569 title: 'Align Text Right',
39570 text: 'Align text to the right.',
39571 cls: 'x-html-editor-tip'
39573 insertunorderedlist : {
39574 title: 'Bullet List',
39575 text: 'Start a bulleted list.',
39576 cls: 'x-html-editor-tip'
39578 insertorderedlist : {
39579 title: 'Numbered List',
39580 text: 'Start a numbered list.',
39581 cls: 'x-html-editor-tip'
39584 title: 'Hyperlink',
39585 text: 'Make the selected text a hyperlink.',
39586 cls: 'x-html-editor-tip'
39589 title: 'Source Edit',
39590 text: 'Switch to source editing mode.',
39591 cls: 'x-html-editor-tip'
39595 onDestroy : function(){
39598 this.tb.items.each(function(item){
39600 item.menu.removeAll();
39602 item.menu.el.destroy();
39610 onFirstFocus: function() {
39611 this.tb.items.each(function(item){
39620 // <script type="text/javascript">
39623 * Ext JS Library 1.1.1
39624 * Copyright(c) 2006-2007, Ext JS, LLC.
39631 * @class Roo.form.HtmlEditor.ToolbarContext
39636 new Roo.form.HtmlEditor({
39639 new Roo.form.HtmlEditor.ToolbarStandard(),
39640 new Roo.form.HtmlEditor.ToolbarContext()
39645 * @config : {Object} disable List of elements to disable.. (not done yet.)
39650 Roo.form.HtmlEditor.ToolbarContext = function(config)
39653 Roo.apply(this, config);
39654 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
39655 // dont call parent... till later.
39657 Roo.form.HtmlEditor.ToolbarContext.types = {
39669 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
39731 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
39736 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
39800 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
39808 * @cfg {Object} disable List of toolbar elements to disable
39817 init : function(editor)
39819 this.editor = editor;
39822 var fid = editor.frameId;
39824 function btn(id, toggle, handler){
39825 var xid = fid + '-'+ id ;
39829 cls : 'x-btn-icon x-edit-'+id,
39830 enableToggle:toggle !== false,
39831 scope: editor, // was editor...
39832 handler:handler||editor.relayBtnCmd,
39833 clickEvent:'mousedown',
39834 tooltip: etb.buttonTips[id] || undefined, ///tips ???
39838 // create a new element.
39839 var wdiv = editor.wrap.createChild({
39841 }, editor.wrap.dom.firstChild.nextSibling, true);
39843 // can we do this more than once??
39845 // stop form submits
39848 // disable everything...
39849 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
39850 this.toolbars = {};
39852 for (var i in ty) {
39853 this.toolbars[i] = this.buildToolbar(ty[i],i);
39855 this.tb = this.toolbars.BODY;
39859 this.rendered = true;
39861 // the all the btns;
39862 editor.on('editorevent', this.updateToolbar, this);
39863 // other toolbars need to implement this..
39864 //editor.on('editmodechange', this.updateToolbar, this);
39870 * Protected method that will not generally be called directly. It triggers
39871 * a toolbar update by reading the markup state of the current selection in the editor.
39873 updateToolbar: function(){
39875 if(!this.editor.activated){
39876 this.editor.onFirstFocus();
39881 var ans = this.editor.getAllAncestors();
39884 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
39885 var sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editor.doc.body;
39886 sel = sel ? sel : this.editor.doc.body;
39887 sel = sel.tagName.length ? sel : this.editor.doc.body;
39888 var tn = sel.tagName.toUpperCase();
39889 sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
39890 tn = sel.tagName.toUpperCase();
39891 if (this.tb.name == tn) {
39892 return; // no change
39895 ///console.log("show: " + tn);
39896 this.tb = this.toolbars[tn];
39898 this.tb.fields.each(function(e) {
39899 e.setValue(sel.getAttribute(e.name));
39901 this.tb.selectedNode = sel;
39904 Roo.menu.MenuMgr.hideAll();
39906 //this.editorsyncValue();
39911 onDestroy : function(){
39914 this.tb.items.each(function(item){
39916 item.menu.removeAll();
39918 item.menu.el.destroy();
39926 onFirstFocus: function() {
39927 // need to do this for all the toolbars..
39928 this.tb.items.each(function(item){
39932 buildToolbar: function(tlist, nm)
39934 var editor = this.editor;
39935 // create a new element.
39936 var wdiv = editor.wrap.createChild({
39938 }, editor.wrap.dom.firstChild.nextSibling, true);
39941 var tb = new Roo.Toolbar(wdiv);
39942 tb.add(nm+ ": ");
39943 for (var i in tlist) {
39944 var item = tlist[i];
39945 tb.add(item.title + ": ");
39950 tb.addField( new Roo.form.ComboBox({
39951 store: new Roo.data.SimpleStore({
39954 data : item.opts // from states.js
39957 displayField:'val',
39961 triggerAction: 'all',
39962 emptyText:'Select',
39963 selectOnFocus:true,
39964 width: item.width ? item.width : 130,
39966 'select': function(c, r, i) {
39967 tb.selectedNode.setAttribute(c.name, r.get('val'));
39978 tb.addField( new Roo.form.TextField({
39981 //allowBlank:false,
39986 tb.addField( new Roo.form.TextField({
39992 'change' : function(f, nv, ov) {
39993 tb.selectedNode.setAttribute(f.name, nv);
39999 tb.el.on('click', function(e){
40000 e.preventDefault(); // what does this do?
40002 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
40005 // dont need to disable them... as they will get hidden
40022 * Ext JS Library 1.1.1
40023 * Copyright(c) 2006-2007, Ext JS, LLC.
40025 * Originally Released Under LGPL - original licence link has changed is not relivant.
40028 * <script type="text/javascript">
40032 * @class Roo.form.BasicForm
40033 * @extends Roo.util.Observable
40034 * Supplies the functionality to do "actions" on forms and initialize Roo.form.Field types on existing markup.
40036 * @param {String/HTMLElement/Roo.Element} el The form element or its id
40037 * @param {Object} config Configuration options
40039 Roo.form.BasicForm = function(el, config){
40040 this.allItems = [];
40041 this.childForms = [];
40042 Roo.apply(this, config);
40044 * The Roo.form.Field items in this form.
40045 * @type MixedCollection
40049 this.items = new Roo.util.MixedCollection(false, function(o){
40050 return o.id || (o.id = Roo.id());
40054 * @event beforeaction
40055 * Fires before any action is performed. Return false to cancel the action.
40056 * @param {Form} this
40057 * @param {Action} action The action to be performed
40059 beforeaction: true,
40061 * @event actionfailed
40062 * Fires when an action fails.
40063 * @param {Form} this
40064 * @param {Action} action The action that failed
40066 actionfailed : true,
40068 * @event actioncomplete
40069 * Fires when an action is completed.
40070 * @param {Form} this
40071 * @param {Action} action The action that completed
40073 actioncomplete : true
40078 Roo.form.BasicForm.superclass.constructor.call(this);
40081 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
40083 * @cfg {String} method
40084 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
40087 * @cfg {DataReader} reader
40088 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when executing "load" actions.
40089 * This is optional as there is built-in support for processing JSON.
40092 * @cfg {DataReader} errorReader
40093 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
40094 * This is completely optional as there is built-in support for processing JSON.
40097 * @cfg {String} url
40098 * The URL to use for form actions if one isn't supplied in the action options.
40101 * @cfg {Boolean} fileUpload
40102 * Set to true if this form is a file upload.
40105 * @cfg {Object} baseParams
40106 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
40109 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
40114 activeAction : null,
40117 * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded
40118 * or setValues() data instead of when the form was first created.
40120 trackResetOnLoad : false,
40124 * childForms - used for multi-tab forms
40127 childForms : false,
40130 * allItems - full list of fields.
40136 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
40137 * element by passing it or its id or mask the form itself by passing in true.
40140 waitMsgTarget : undefined,
40143 initEl : function(el){
40144 this.el = Roo.get(el);
40145 this.id = this.el.id || Roo.id();
40146 this.el.on('submit', this.onSubmit, this);
40147 this.el.addClass('x-form');
40151 onSubmit : function(e){
40156 * Returns true if client-side validation on the form is successful.
40159 isValid : function(){
40161 this.items.each(function(f){
40170 * Returns true if any fields in this form have changed since their original load.
40173 isDirty : function(){
40175 this.items.each(function(f){
40185 * Performs a predefined action (submit or load) or custom actions you define on this form.
40186 * @param {String} actionName The name of the action type
40187 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
40188 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
40189 * accept other config options):
40191 Property Type Description
40192 ---------------- --------------- ----------------------------------------------------------------------------------
40193 url String The url for the action (defaults to the form's url)
40194 method String The form method to use (defaults to the form's method, or POST if not defined)
40195 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
40196 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
40197 validate the form on the client (defaults to false)
40199 * @return {BasicForm} this
40201 doAction : function(action, options){
40202 if(typeof action == 'string'){
40203 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
40205 if(this.fireEvent('beforeaction', this, action) !== false){
40206 this.beforeAction(action);
40207 action.run.defer(100, action);
40213 * Shortcut to do a submit action.
40214 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
40215 * @return {BasicForm} this
40217 submit : function(options){
40218 this.doAction('submit', options);
40223 * Shortcut to do a load action.
40224 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
40225 * @return {BasicForm} this
40227 load : function(options){
40228 this.doAction('load', options);
40233 * Persists the values in this form into the passed Roo.data.Record object in a beginEdit/endEdit block.
40234 * @param {Record} record The record to edit
40235 * @return {BasicForm} this
40237 updateRecord : function(record){
40238 record.beginEdit();
40239 var fs = record.fields;
40240 fs.each(function(f){
40241 var field = this.findField(f.name);
40243 record.set(f.name, field.getValue());
40251 * Loads an Roo.data.Record into this form.
40252 * @param {Record} record The record to load
40253 * @return {BasicForm} this
40255 loadRecord : function(record){
40256 this.setValues(record.data);
40261 beforeAction : function(action){
40262 var o = action.options;
40264 if(this.waitMsgTarget === true){
40265 this.el.mask(o.waitMsg, 'x-mask-loading');
40266 }else if(this.waitMsgTarget){
40267 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
40268 this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
40270 Roo.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...');
40276 afterAction : function(action, success){
40277 this.activeAction = null;
40278 var o = action.options;
40280 if(this.waitMsgTarget === true){
40282 }else if(this.waitMsgTarget){
40283 this.waitMsgTarget.unmask();
40285 Roo.MessageBox.updateProgress(1);
40286 Roo.MessageBox.hide();
40293 Roo.callback(o.success, o.scope, [this, action]);
40294 this.fireEvent('actioncomplete', this, action);
40296 Roo.callback(o.failure, o.scope, [this, action]);
40297 this.fireEvent('actionfailed', this, action);
40302 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
40303 * @param {String} id The value to search for
40306 findField : function(id){
40307 var field = this.items.get(id);
40309 this.items.each(function(f){
40310 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
40316 return field || null;
40320 * Add a secondary form to this one,
40321 * Used to provide tabbed forms. One form is primary, with hidden values
40322 * which mirror the elements from the other forms.
40324 * @param {Roo.form.Form} form to add.
40327 addForm : function(form)
40330 if (this.childForms.indexOf(form) > -1) {
40334 this.childForms.push(form);
40336 Roo.each(form.allItems, function (fe) {
40338 n = typeof(fe.getName) == 'undefined' ? fe.name : fe.getName();
40339 if (this.findField(n)) { // already added..
40342 var add = new Roo.form.Hidden({
40345 add.render(this.el);
40352 * Mark fields in this form invalid in bulk.
40353 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
40354 * @return {BasicForm} this
40356 markInvalid : function(errors){
40357 if(errors instanceof Array){
40358 for(var i = 0, len = errors.length; i < len; i++){
40359 var fieldError = errors[i];
40360 var f = this.findField(fieldError.id);
40362 f.markInvalid(fieldError.msg);
40368 if(typeof errors[id] != 'function' && (field = this.findField(id))){
40369 field.markInvalid(errors[id]);
40373 Roo.each(this.childForms || [], function (f) {
40374 f.markInvalid(errors);
40381 * Set values for fields in this form in bulk.
40382 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
40383 * @return {BasicForm} this
40385 setValues : function(values){
40386 if(values instanceof Array){ // array of objects
40387 for(var i = 0, len = values.length; i < len; i++){
40389 var f = this.findField(v.id);
40391 f.setValue(v.value);
40392 if(this.trackResetOnLoad){
40393 f.originalValue = f.getValue();
40397 }else{ // object hash
40400 if(typeof values[id] != 'function' && (field = this.findField(id))){
40402 if (field.setFromData &&
40403 field.valueField &&
40404 field.displayField &&
40405 // combos' with local stores can
40406 // be queried via setValue()
40407 // to set their value..
40408 (field.store && !field.store.isLocal)
40412 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
40413 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
40414 field.setFromData(sd);
40417 field.setValue(values[id]);
40421 if(this.trackResetOnLoad){
40422 field.originalValue = field.getValue();
40428 Roo.each(this.childForms || [], function (f) {
40429 f.setValues(values);
40436 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
40437 * they are returned as an array.
40438 * @param {Boolean} asString
40441 getValues : function(asString){
40442 if (this.childForms) {
40443 // copy values from the child forms
40444 Roo.each(this.childForms, function (f) {
40445 this.setValues(f.getValues());
40451 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
40452 if(asString === true){
40455 return Roo.urlDecode(fs);
40459 * Clears all invalid messages in this form.
40460 * @return {BasicForm} this
40462 clearInvalid : function(){
40463 this.items.each(function(f){
40467 Roo.each(this.childForms || [], function (f) {
40476 * Resets this form.
40477 * @return {BasicForm} this
40479 reset : function(){
40480 this.items.each(function(f){
40484 Roo.each(this.childForms || [], function (f) {
40493 * Add Roo.form components to this form.
40494 * @param {Field} field1
40495 * @param {Field} field2 (optional)
40496 * @param {Field} etc (optional)
40497 * @return {BasicForm} this
40500 this.items.addAll(Array.prototype.slice.call(arguments, 0));
40506 * Removes a field from the items collection (does NOT remove its markup).
40507 * @param {Field} field
40508 * @return {BasicForm} this
40510 remove : function(field){
40511 this.items.remove(field);
40516 * Looks at the fields in this form, checks them for an id attribute,
40517 * and calls applyTo on the existing dom element with that id.
40518 * @return {BasicForm} this
40520 render : function(){
40521 this.items.each(function(f){
40522 if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
40530 * Calls {@link Ext#apply} for all fields in this form with the passed object.
40531 * @param {Object} values
40532 * @return {BasicForm} this
40534 applyToFields : function(o){
40535 this.items.each(function(f){
40542 * Calls {@link Ext#applyIf} for all field in this form with the passed object.
40543 * @param {Object} values
40544 * @return {BasicForm} this
40546 applyIfToFields : function(o){
40547 this.items.each(function(f){
40555 Roo.BasicForm = Roo.form.BasicForm;/*
40557 * Ext JS Library 1.1.1
40558 * Copyright(c) 2006-2007, Ext JS, LLC.
40560 * Originally Released Under LGPL - original licence link has changed is not relivant.
40563 * <script type="text/javascript">
40567 * @class Roo.form.Form
40568 * @extends Roo.form.BasicForm
40569 * Adds the ability to dynamically render forms with JavaScript to {@link Roo.form.BasicForm}.
40571 * @param {Object} config Configuration options
40573 Roo.form.Form = function(config){
40575 if (config.items) {
40576 xitems = config.items;
40577 delete config.items;
40581 Roo.form.Form.superclass.constructor.call(this, null, config);
40582 this.url = this.url || this.action;
40584 this.root = new Roo.form.Layout(Roo.applyIf({
40588 this.active = this.root;
40590 * Array of all the buttons that have been added to this form via {@link addButton}
40594 this.allItems = [];
40597 * @event clientvalidation
40598 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
40599 * @param {Form} this
40600 * @param {Boolean} valid true if the form has passed client-side validation
40602 clientvalidation: true,
40605 * Fires when the form is rendered
40606 * @param {Roo.form.Form} form
40611 Roo.each(xitems, this.addxtype, this);
40617 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
40619 * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
40622 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
40625 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
40627 buttonAlign:'center',
40630 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
40635 * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
40636 * This property cascades to child containers if not set.
40641 * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
40642 * fires a looping event with that state. This is required to bind buttons to the valid
40643 * state using the config value formBind:true on the button.
40645 monitorValid : false,
40648 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
40654 * Opens a new {@link Roo.form.Column} container in the layout stack. If fields are passed after the config, the
40655 * fields are added and the column is closed. If no fields are passed the column remains open
40656 * until end() is called.
40657 * @param {Object} config The config to pass to the column
40658 * @param {Field} field1 (optional)
40659 * @param {Field} field2 (optional)
40660 * @param {Field} etc (optional)
40661 * @return Column The column container object
40663 column : function(c){
40664 var col = new Roo.form.Column(c);
40666 if(arguments.length > 1){ // duplicate code required because of Opera
40667 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
40674 * Opens a new {@link Roo.form.FieldSet} container in the layout stack. If fields are passed after the config, the
40675 * fields are added and the fieldset is closed. If no fields are passed the fieldset remains open
40676 * until end() is called.
40677 * @param {Object} config The config to pass to the fieldset
40678 * @param {Field} field1 (optional)
40679 * @param {Field} field2 (optional)
40680 * @param {Field} etc (optional)
40681 * @return FieldSet The fieldset container object
40683 fieldset : function(c){
40684 var fs = new Roo.form.FieldSet(c);
40686 if(arguments.length > 1){ // duplicate code required because of Opera
40687 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
40694 * Opens a new {@link Roo.form.Layout} container in the layout stack. If fields are passed after the config, the
40695 * fields are added and the container is closed. If no fields are passed the container remains open
40696 * until end() is called.
40697 * @param {Object} config The config to pass to the Layout
40698 * @param {Field} field1 (optional)
40699 * @param {Field} field2 (optional)
40700 * @param {Field} etc (optional)
40701 * @return Layout The container object
40703 container : function(c){
40704 var l = new Roo.form.Layout(c);
40706 if(arguments.length > 1){ // duplicate code required because of Opera
40707 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
40714 * Opens the passed container in the layout stack. The container can be any {@link Roo.form.Layout} or subclass.
40715 * @param {Object} container A Roo.form.Layout or subclass of Layout
40716 * @return {Form} this
40718 start : function(c){
40719 // cascade label info
40720 Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
40721 this.active.stack.push(c);
40722 c.ownerCt = this.active;
40728 * Closes the current open container
40729 * @return {Form} this
40732 if(this.active == this.root){
40735 this.active = this.active.ownerCt;
40740 * Add Roo.form components to the current open container (e.g. column, fieldset, etc.). Fields added via this method
40741 * can also be passed with an additional property of fieldLabel, which if supplied, will provide the text to display
40742 * as the label of the field.
40743 * @param {Field} field1
40744 * @param {Field} field2 (optional)
40745 * @param {Field} etc. (optional)
40746 * @return {Form} this
40749 this.active.stack.push.apply(this.active.stack, arguments);
40750 this.allItems.push.apply(this.allItems,arguments);
40752 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
40753 if(a[i].isFormField){
40758 Roo.form.Form.superclass.add.apply(this, r);
40768 * Find any element that has been added to a form, using it's ID or name
40769 * This can include framesets, columns etc. along with regular fields..
40770 * @param {String} id - id or name to find.
40772 * @return {Element} e - or false if nothing found.
40774 findbyId : function(id)
40780 Ext.each(this.allItems, function(f){
40781 if (f.id == id || f.name == id ){
40792 * Render this form into the passed container. This should only be called once!
40793 * @param {String/HTMLElement/Element} container The element this component should be rendered into
40794 * @return {Form} this
40796 render : function(ct){
40798 var o = this.autoCreate || {
40800 method : this.method || 'POST',
40801 id : this.id || Roo.id()
40803 this.initEl(ct.createChild(o));
40805 this.root.render(this.el);
40807 this.items.each(function(f){
40808 f.render('x-form-el-'+f.id);
40811 if(this.buttons.length > 0){
40812 // tables are required to maintain order and for correct IE layout
40813 var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
40814 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
40815 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
40817 var tr = tb.getElementsByTagName('tr')[0];
40818 for(var i = 0, len = this.buttons.length; i < len; i++) {
40819 var b = this.buttons[i];
40820 var td = document.createElement('td');
40821 td.className = 'x-form-btn-td';
40822 b.render(tr.appendChild(td));
40825 if(this.monitorValid){ // initialize after render
40826 this.startMonitoring();
40828 this.fireEvent('rendered', this);
40833 * Adds a button to the footer of the form - this <b>must</b> be called before the form is rendered.
40834 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
40835 * object or a valid Roo.DomHelper element config
40836 * @param {Function} handler The function called when the button is clicked
40837 * @param {Object} scope (optional) The scope of the handler function
40838 * @return {Roo.Button}
40840 addButton : function(config, handler, scope){
40844 minWidth: this.minButtonWidth,
40847 if(typeof config == "string"){
40850 Roo.apply(bc, config);
40852 var btn = new Roo.Button(null, bc);
40853 this.buttons.push(btn);
40858 * Adds a series of form elements (using the xtype property as the factory method.
40859 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column, (and 'end' to close a block)
40860 * @param {Object} config
40863 addxtype : function()
40865 var ar = Array.prototype.slice.call(arguments, 0);
40867 for(var i = 0; i < ar.length; i++) {
40869 continue; // skip -- if this happends something invalid got sent, we
40870 // should ignore it, as basically that interface element will not show up
40871 // and that should be pretty obvious!!
40874 if (Roo.form[ar[i].xtype]) {
40876 var fe = Roo.factory(ar[i], Roo.form);
40882 fe.store.form = this;
40887 this.allItems.push(fe);
40888 if (fe.items && fe.addxtype) {
40889 fe.addxtype.apply(fe, fe.items);
40899 // console.log('adding ' + ar[i].xtype);
40901 if (ar[i].xtype == 'Button') {
40902 //console.log('adding button');
40903 //console.log(ar[i]);
40904 this.addButton(ar[i]);
40905 this.allItems.push(fe);
40909 if (ar[i].xtype == 'end') { // so we can add fieldsets... / layout etc.
40910 alert('end is not supported on xtype any more, use items');
40912 // //console.log('adding end');
40920 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
40921 * option "monitorValid"
40923 startMonitoring : function(){
40926 Roo.TaskMgr.start({
40927 run : this.bindHandler,
40928 interval : this.monitorPoll || 200,
40935 * Stops monitoring of the valid state of this form
40937 stopMonitoring : function(){
40938 this.bound = false;
40942 bindHandler : function(){
40944 return false; // stops binding
40947 this.items.each(function(f){
40948 if(!f.isValid(true)){
40953 for(var i = 0, len = this.buttons.length; i < len; i++){
40954 var btn = this.buttons[i];
40955 if(btn.formBind === true && btn.disabled === valid){
40956 btn.setDisabled(!valid);
40959 this.fireEvent('clientvalidation', this, valid);
40973 Roo.Form = Roo.form.Form;
40976 * Ext JS Library 1.1.1
40977 * Copyright(c) 2006-2007, Ext JS, LLC.
40979 * Originally Released Under LGPL - original licence link has changed is not relivant.
40982 * <script type="text/javascript">
40986 * @class Roo.form.Action
40987 * Internal Class used to handle form actions
40989 * @param {Roo.form.BasicForm} el The form element or its id
40990 * @param {Object} config Configuration options
40994 // define the action interface
40995 Roo.form.Action = function(form, options){
40997 this.options = options || {};
41000 * Client Validation Failed
41003 Roo.form.Action.CLIENT_INVALID = 'client';
41005 * Server Validation Failed
41008 Roo.form.Action.SERVER_INVALID = 'server';
41010 * Connect to Server Failed
41013 Roo.form.Action.CONNECT_FAILURE = 'connect';
41015 * Reading Data from Server Failed
41018 Roo.form.Action.LOAD_FAILURE = 'load';
41020 Roo.form.Action.prototype = {
41022 failureType : undefined,
41023 response : undefined,
41024 result : undefined,
41026 // interface method
41027 run : function(options){
41031 // interface method
41032 success : function(response){
41036 // interface method
41037 handleResponse : function(response){
41041 // default connection failure
41042 failure : function(response){
41043 this.response = response;
41044 this.failureType = Roo.form.Action.CONNECT_FAILURE;
41045 this.form.afterAction(this, false);
41048 processResponse : function(response){
41049 this.response = response;
41050 if(!response.responseText){
41053 this.result = this.handleResponse(response);
41054 return this.result;
41057 // utility functions used internally
41058 getUrl : function(appendParams){
41059 var url = this.options.url || this.form.url || this.form.el.dom.action;
41061 var p = this.getParams();
41063 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
41069 getMethod : function(){
41070 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
41073 getParams : function(){
41074 var bp = this.form.baseParams;
41075 var p = this.options.params;
41077 if(typeof p == "object"){
41078 p = Roo.urlEncode(Roo.applyIf(p, bp));
41079 }else if(typeof p == 'string' && bp){
41080 p += '&' + Roo.urlEncode(bp);
41083 p = Roo.urlEncode(bp);
41088 createCallback : function(){
41090 success: this.success,
41091 failure: this.failure,
41093 timeout: (this.form.timeout*1000),
41094 upload: this.form.fileUpload ? this.success : undefined
41099 Roo.form.Action.Submit = function(form, options){
41100 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
41103 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
41108 // run get Values on the form, so it syncs any secondary forms.
41109 this.form.getValues();
41111 var o = this.options;
41112 var method = this.getMethod();
41113 var isPost = method == 'POST';
41114 if(o.clientValidation === false || this.form.isValid()){
41115 Roo.Ajax.request(Roo.apply(this.createCallback(), {
41116 form:this.form.el.dom,
41117 url:this.getUrl(!isPost),
41119 params:isPost ? this.getParams() : null,
41120 isUpload: this.form.fileUpload
41123 }else if (o.clientValidation !== false){ // client validation failed
41124 this.failureType = Roo.form.Action.CLIENT_INVALID;
41125 this.form.afterAction(this, false);
41129 success : function(response){
41130 var result = this.processResponse(response);
41131 if(result === true || result.success){
41132 this.form.afterAction(this, true);
41136 this.form.markInvalid(result.errors);
41137 this.failureType = Roo.form.Action.SERVER_INVALID;
41139 this.form.afterAction(this, false);
41142 handleResponse : function(response){
41143 if(this.form.errorReader){
41144 var rs = this.form.errorReader.read(response);
41147 for(var i = 0, len = rs.records.length; i < len; i++) {
41148 var r = rs.records[i];
41149 errors[i] = r.data;
41152 if(errors.length < 1){
41156 success : rs.success,
41162 ret = Roo.decode(response.responseText);
41166 errorMsg: "Failed to read server message: " + response.responseText,
41176 Roo.form.Action.Load = function(form, options){
41177 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
41178 this.reader = this.form.reader;
41181 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
41185 Roo.Ajax.request(Roo.apply(
41186 this.createCallback(), {
41187 method:this.getMethod(),
41188 url:this.getUrl(false),
41189 params:this.getParams()
41193 success : function(response){
41194 var result = this.processResponse(response);
41195 if(result === true || !result.success || !result.data){
41196 this.failureType = Roo.form.Action.LOAD_FAILURE;
41197 this.form.afterAction(this, false);
41200 this.form.clearInvalid();
41201 this.form.setValues(result.data);
41202 this.form.afterAction(this, true);
41205 handleResponse : function(response){
41206 if(this.form.reader){
41207 var rs = this.form.reader.read(response);
41208 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
41210 success : rs.success,
41214 return Roo.decode(response.responseText);
41218 Roo.form.Action.ACTION_TYPES = {
41219 'load' : Roo.form.Action.Load,
41220 'submit' : Roo.form.Action.Submit
41223 * Ext JS Library 1.1.1
41224 * Copyright(c) 2006-2007, Ext JS, LLC.
41226 * Originally Released Under LGPL - original licence link has changed is not relivant.
41229 * <script type="text/javascript">
41233 * @class Roo.form.Layout
41234 * @extends Roo.Component
41235 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
41237 * @param {Object} config Configuration options
41239 Roo.form.Layout = function(config){
41241 if (config.items) {
41242 xitems = config.items;
41243 delete config.items;
41245 Roo.form.Layout.superclass.constructor.call(this, config);
41247 Roo.each(xitems, this.addxtype, this);
41251 Roo.extend(Roo.form.Layout, Roo.Component, {
41253 * @cfg {String/Object} autoCreate
41254 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
41257 * @cfg {String/Object/Function} style
41258 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
41259 * a function which returns such a specification.
41262 * @cfg {String} labelAlign
41263 * Valid values are "left," "top" and "right" (defaults to "left")
41266 * @cfg {Number} labelWidth
41267 * Fixed width in pixels of all field labels (defaults to undefined)
41270 * @cfg {Boolean} clear
41271 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
41275 * @cfg {String} labelSeparator
41276 * The separator to use after field labels (defaults to ':')
41278 labelSeparator : ':',
41280 * @cfg {Boolean} hideLabels
41281 * True to suppress the display of field labels in this layout (defaults to false)
41283 hideLabels : false,
41286 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
41291 onRender : function(ct, position){
41292 if(this.el){ // from markup
41293 this.el = Roo.get(this.el);
41294 }else { // generate
41295 var cfg = this.getAutoCreate();
41296 this.el = ct.createChild(cfg, position);
41299 this.el.applyStyles(this.style);
41301 if(this.labelAlign){
41302 this.el.addClass('x-form-label-'+this.labelAlign);
41304 if(this.hideLabels){
41305 this.labelStyle = "display:none";
41306 this.elementStyle = "padding-left:0;";
41308 if(typeof this.labelWidth == 'number'){
41309 this.labelStyle = "width:"+this.labelWidth+"px;";
41310 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
41312 if(this.labelAlign == 'top'){
41313 this.labelStyle = "width:auto;";
41314 this.elementStyle = "padding-left:0;";
41317 var stack = this.stack;
41318 var slen = stack.length;
41320 if(!this.fieldTpl){
41321 var t = new Roo.Template(
41322 '<div class="x-form-item {5}">',
41323 '<label for="{0}" style="{2}">{1}{4}</label>',
41324 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
41326 '</div><div class="x-form-clear-left"></div>'
41328 t.disableFormats = true;
41330 Roo.form.Layout.prototype.fieldTpl = t;
41332 for(var i = 0; i < slen; i++) {
41333 if(stack[i].isFormField){
41334 this.renderField(stack[i]);
41336 this.renderComponent(stack[i]);
41341 this.el.createChild({cls:'x-form-clear'});
41346 renderField : function(f){
41347 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
41350 f.labelStyle||this.labelStyle||'', //2
41351 this.elementStyle||'', //3
41352 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
41353 f.itemCls||this.itemCls||'' //5
41354 ], true).getPrevSibling());
41358 renderComponent : function(c){
41359 c.render(c.isLayout ? this.el : this.el.createChild());
41362 * Adds a object form elements (using the xtype property as the factory method.)
41363 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
41364 * @param {Object} config
41366 addxtype : function(o)
41368 // create the lement.
41369 o.form = this.form;
41370 var fe = Roo.factory(o, Roo.form);
41371 this.form.allItems.push(fe);
41372 this.stack.push(fe);
41374 if (fe.isFormField) {
41375 this.form.items.add(fe);
41383 * @class Roo.form.Column
41384 * @extends Roo.form.Layout
41385 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
41387 * @param {Object} config Configuration options
41389 Roo.form.Column = function(config){
41390 Roo.form.Column.superclass.constructor.call(this, config);
41393 Roo.extend(Roo.form.Column, Roo.form.Layout, {
41395 * @cfg {Number/String} width
41396 * The fixed width of the column in pixels or CSS value (defaults to "auto")
41399 * @cfg {String/Object} autoCreate
41400 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
41404 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
41407 onRender : function(ct, position){
41408 Roo.form.Column.superclass.onRender.call(this, ct, position);
41410 this.el.setWidth(this.width);
41417 * @class Roo.form.Row
41418 * @extends Roo.form.Layout
41419 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
41421 * @param {Object} config Configuration options
41425 Roo.form.Row = function(config){
41426 Roo.form.Row.superclass.constructor.call(this, config);
41429 Roo.extend(Roo.form.Row, Roo.form.Layout, {
41431 * @cfg {Number/String} width
41432 * The fixed width of the column in pixels or CSS value (defaults to "auto")
41435 * @cfg {Number/String} height
41436 * The fixed height of the column in pixels or CSS value (defaults to "auto")
41438 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
41442 onRender : function(ct, position){
41443 //console.log('row render');
41445 var t = new Roo.Template(
41446 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
41447 '<label for="{0}" style="{2}">{1}{4}</label>',
41448 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
41452 t.disableFormats = true;
41454 Roo.form.Layout.prototype.rowTpl = t;
41456 this.fieldTpl = this.rowTpl;
41458 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
41459 var labelWidth = 100;
41461 if ((this.labelAlign != 'top')) {
41462 if (typeof this.labelWidth == 'number') {
41463 labelWidth = this.labelWidth
41465 this.padWidth = 20 + labelWidth;
41469 Roo.form.Column.superclass.onRender.call(this, ct, position);
41471 this.el.setWidth(this.width);
41474 this.el.setHeight(this.height);
41479 renderField : function(f){
41480 f.fieldEl = this.fieldTpl.append(this.el, [
41481 f.id, f.fieldLabel,
41482 f.labelStyle||this.labelStyle||'',
41483 this.elementStyle||'',
41484 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
41485 f.itemCls||this.itemCls||'',
41486 f.width ? f.width + this.padWidth : 160 + this.padWidth
41493 * @class Roo.form.FieldSet
41494 * @extends Roo.form.Layout
41495 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
41497 * @param {Object} config Configuration options
41499 Roo.form.FieldSet = function(config){
41500 Roo.form.FieldSet.superclass.constructor.call(this, config);
41503 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
41505 * @cfg {String} legend
41506 * The text to display as the legend for the FieldSet (defaults to '')
41509 * @cfg {String/Object} autoCreate
41510 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
41514 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
41517 onRender : function(ct, position){
41518 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
41520 this.setLegend(this.legend);
41525 setLegend : function(text){
41527 this.el.child('legend').update(text);
41532 * Ext JS Library 1.1.1
41533 * Copyright(c) 2006-2007, Ext JS, LLC.
41535 * Originally Released Under LGPL - original licence link has changed is not relivant.
41538 * <script type="text/javascript">
41541 * @class Roo.form.VTypes
41542 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
41545 Roo.form.VTypes = function(){
41546 // closure these in so they are only created once.
41547 var alpha = /^[a-zA-Z_]+$/;
41548 var alphanum = /^[a-zA-Z0-9_]+$/;
41549 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
41550 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
41552 // All these messages and functions are configurable
41555 * The function used to validate email addresses
41556 * @param {String} value The email address
41558 'email' : function(v){
41559 return email.test(v);
41562 * The error text to display when the email validation function returns false
41565 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
41567 * The keystroke filter mask to be applied on email input
41570 'emailMask' : /[a-z0-9_\.\-@]/i,
41573 * The function used to validate URLs
41574 * @param {String} value The URL
41576 'url' : function(v){
41577 return url.test(v);
41580 * The error text to display when the url validation function returns false
41583 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
41586 * The function used to validate alpha values
41587 * @param {String} value The value
41589 'alpha' : function(v){
41590 return alpha.test(v);
41593 * The error text to display when the alpha validation function returns false
41596 'alphaText' : 'This field should only contain letters and _',
41598 * The keystroke filter mask to be applied on alpha input
41601 'alphaMask' : /[a-z_]/i,
41604 * The function used to validate alphanumeric values
41605 * @param {String} value The value
41607 'alphanum' : function(v){
41608 return alphanum.test(v);
41611 * The error text to display when the alphanumeric validation function returns false
41614 'alphanumText' : 'This field should only contain letters, numbers and _',
41616 * The keystroke filter mask to be applied on alphanumeric input
41619 'alphanumMask' : /[a-z0-9_]/i
41621 }();//<script type="text/javascript">
41624 * @class Roo.form.FCKeditor
41625 * @extends Roo.form.TextArea
41626 * Wrapper around the FCKEditor http://www.fckeditor.net
41628 * Creates a new FCKeditor
41629 * @param {Object} config Configuration options
41631 Roo.form.FCKeditor = function(config){
41632 Roo.form.FCKeditor.superclass.constructor.call(this, config);
41635 * @event editorinit
41636 * Fired when the editor is initialized - you can add extra handlers here..
41637 * @param {FCKeditor} this
41638 * @param {Object} the FCK object.
41645 Roo.form.FCKeditor.editors = { };
41646 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
41648 //defaultAutoCreate : {
41649 // tag : "textarea",style : "width:100px;height:60px;" ,autocomplete : "off"
41653 * @cfg {Object} fck options - see fck manual for details.
41658 * @cfg {Object} fck toolbar set (Basic or Default)
41660 toolbarSet : 'Basic',
41662 * @cfg {Object} fck BasePath
41664 basePath : '/fckeditor/',
41672 onRender : function(ct, position)
41675 this.defaultAutoCreate = {
41677 style:"width:300px;height:60px;",
41678 autocomplete: "off"
41681 Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
41684 this.textSizeEl = Roo.DomHelper.append(document.body, {tag: "pre", cls: "x-form-grow-sizer"});
41685 if(this.preventScrollbars){
41686 this.el.setStyle("overflow", "hidden");
41688 this.el.setHeight(this.growMin);
41691 //console.log('onrender' + this.getId() );
41692 Roo.form.FCKeditor.editors[this.getId()] = this;
41695 this.replaceTextarea() ;
41699 getEditor : function() {
41700 return this.fckEditor;
41703 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
41704 * @param {Mixed} value The value to set
41708 setValue : function(value)
41710 //console.log('setValue: ' + value);
41712 if(typeof(value) == 'undefined') { // not sure why this is happending...
41715 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
41717 //if(!this.el || !this.getEditor()) {
41718 // this.value = value;
41719 //this.setValue.defer(100,this,[value]);
41723 if(!this.getEditor()) {
41727 this.getEditor().SetData(value);
41734 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
41735 * @return {Mixed} value The field value
41737 getValue : function()
41740 if (this.frame && this.frame.dom.style.display == 'none') {
41741 return Roo.form.FCKeditor.superclass.getValue.call(this);
41744 if(!this.el || !this.getEditor()) {
41746 // this.getValue.defer(100,this);
41751 var value=this.getEditor().GetData();
41752 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
41753 return Roo.form.FCKeditor.superclass.getValue.call(this);
41759 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
41760 * @return {Mixed} value The field value
41762 getRawValue : function()
41764 if (this.frame && this.frame.dom.style.display == 'none') {
41765 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
41768 if(!this.el || !this.getEditor()) {
41769 //this.getRawValue.defer(100,this);
41776 var value=this.getEditor().GetData();
41777 Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
41778 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
41782 setSize : function(w,h) {
41786 //if (this.frame && this.frame.dom.style.display == 'none') {
41787 // Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
41790 //if(!this.el || !this.getEditor()) {
41791 // this.setSize.defer(100,this, [w,h]);
41797 Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
41799 this.frame.dom.setAttribute('width', w);
41800 this.frame.dom.setAttribute('height', h);
41801 this.frame.setSize(w,h);
41805 toggleSourceEdit : function(value) {
41809 this.el.dom.style.display = value ? '' : 'none';
41810 this.frame.dom.style.display = value ? 'none' : '';
41815 focus: function(tag)
41817 if (this.frame.dom.style.display == 'none') {
41818 return Roo.form.FCKeditor.superclass.focus.call(this);
41820 if(!this.el || !this.getEditor()) {
41821 this.focus.defer(100,this, [tag]);
41828 var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
41829 this.getEditor().Focus();
41831 if (!this.getEditor().Selection.GetSelection()) {
41832 this.focus.defer(100,this, [tag]);
41837 var r = this.getEditor().EditorDocument.createRange();
41838 r.setStart(tgs[0],0);
41839 r.setEnd(tgs[0],0);
41840 this.getEditor().Selection.GetSelection().removeAllRanges();
41841 this.getEditor().Selection.GetSelection().addRange(r);
41842 this.getEditor().Focus();
41849 replaceTextarea : function()
41851 if ( document.getElementById( this.getId() + '___Frame' ) )
41853 //if ( !this.checkBrowser || this._isCompatibleBrowser() )
41855 // We must check the elements firstly using the Id and then the name.
41856 var oTextarea = document.getElementById( this.getId() );
41858 var colElementsByName = document.getElementsByName( this.getId() ) ;
41860 oTextarea.style.display = 'none' ;
41862 if ( oTextarea.tabIndex ) {
41863 this.TabIndex = oTextarea.tabIndex ;
41866 this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
41867 this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
41868 this.frame = Roo.get(this.getId() + '___Frame')
41871 _getConfigHtml : function()
41875 for ( var o in this.fckconfig ) {
41876 sConfig += sConfig.length > 0 ? '&' : '';
41877 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
41880 return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
41884 _getIFrameHtml : function()
41886 var sFile = 'fckeditor.html' ;
41887 /* no idea what this is about..
41890 if ( (/fcksource=true/i).test( window.top.location.search ) )
41891 sFile = 'fckeditor.original.html' ;
41896 var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
41897 sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
41900 var html = '<iframe id="' + this.getId() +
41901 '___Frame" src="' + sLink +
41902 '" width="' + this.width +
41903 '" height="' + this.height + '"' +
41904 (this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
41905 ' frameborder="0" scrolling="no"></iframe>' ;
41910 _insertHtmlBefore : function( html, element )
41912 if ( element.insertAdjacentHTML ) {
41914 element.insertAdjacentHTML( 'beforeBegin', html ) ;
41916 var oRange = document.createRange() ;
41917 oRange.setStartBefore( element ) ;
41918 var oFragment = oRange.createContextualFragment( html );
41919 element.parentNode.insertBefore( oFragment, element ) ;
41932 //Roo.reg('fckeditor', Roo.form.FCKeditor);
41934 function FCKeditor_OnComplete(editorInstance){
41935 var f = Roo.form.FCKeditor.editors[editorInstance.Name];
41936 f.fckEditor = editorInstance;
41937 //console.log("loaded");
41938 f.fireEvent('editorinit', f, editorInstance);
41958 //<script type="text/javascript">
41960 * @class Roo.form.GridField
41961 * @extends Roo.form.Field
41962 * Embed a grid (or editable grid into a form)
41965 * Creates a new GridField
41966 * @param {Object} config Configuration options
41968 Roo.form.GridField = function(config){
41969 Roo.form.GridField.superclass.constructor.call(this, config);
41973 Roo.extend(Roo.form.GridField, Roo.form.Field, {
41975 * @cfg {Number} width - used to restrict width of grid..
41979 * @cfg {Number} height - used to restrict height of grid..
41983 * @cfg {Object} xgrid (xtype'd description of grid) Grid or EditorGrid
41987 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
41988 * {tag: "input", type: "checkbox", autocomplete: "off"})
41990 // defaultAutoCreate : { tag: 'div' },
41991 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
41993 * @cfg {String} addTitle Text to include for adding a title.
41997 onResize : function(){
41998 Roo.form.Field.superclass.onResize.apply(this, arguments);
42001 initEvents : function(){
42002 // Roo.form.Checkbox.superclass.initEvents.call(this);
42003 // has no events...
42008 getResizeEl : function(){
42012 getPositionEl : function(){
42017 onRender : function(ct, position){
42019 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
42020 var style = this.style;
42023 Roo.form.DisplayImage.superclass.onRender.call(this, ct, position);
42024 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
42025 this.viewEl = this.wrap.createChild({ tag: 'div' });
42027 this.viewEl.applyStyles(style);
42030 this.viewEl.setWidth(this.width);
42033 this.viewEl.setHeight(this.height);
42035 //if(this.inputValue !== undefined){
42036 //this.setValue(this.value);
42039 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
42042 this.grid.render();
42043 this.grid.getDataSource().on('remove', this.refreshValue, this);
42044 this.grid.getDataSource().on('update', this.refreshValue, this);
42045 this.grid.on('afteredit', this.refreshValue, this);
42051 * Sets the value of the item.
42052 * @param {String} either an object or a string..
42054 setValue : function(v){
42056 v = v || []; // empty set..
42057 // this does not seem smart - it really only affects memoryproxy grids..
42058 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
42059 var ds = this.grid.getDataSource();
42060 // assumes a json reader..
42062 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
42063 ds.loadData( data);
42065 Roo.form.GridField.superclass.setValue.call(this, v);
42066 this.refreshValue();
42067 // should load data in the grid really....
42071 refreshValue: function() {
42073 this.grid.getDataSource().each(function(r) {
42076 this.el.dom.value = Roo.encode(val);
42084 * Ext JS Library 1.1.1
42085 * Copyright(c) 2006-2007, Ext JS, LLC.
42087 * Originally Released Under LGPL - original licence link has changed is not relivant.
42090 * <script type="text/javascript">
42093 * @class Roo.form.DisplayField
42094 * @extends Roo.form.Field
42095 * A generic Field to display non-editable data.
42097 * Creates a new Display Field item.
42098 * @param {Object} config Configuration options
42100 Roo.form.DisplayField = function(config){
42101 Roo.form.DisplayField.superclass.constructor.call(this, config);
42105 Roo.extend(Roo.form.DisplayField, Roo.form.TextField, {
42106 inputType: 'hidden',
42112 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
42114 focusClass : undefined,
42116 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
42118 fieldClass: 'x-form-field',
42121 * @cfg {Function} valueRenderer The renderer for the field (so you can reformat output). should return raw HTML
42123 valueRenderer: undefined,
42127 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
42128 * {tag: "input", type: "checkbox", autocomplete: "off"})
42131 // defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
42133 onResize : function(){
42134 Roo.form.DisplayField.superclass.onResize.apply(this, arguments);
42138 initEvents : function(){
42139 // Roo.form.Checkbox.superclass.initEvents.call(this);
42140 // has no events...
42145 getResizeEl : function(){
42149 getPositionEl : function(){
42154 onRender : function(ct, position){
42156 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
42157 //if(this.inputValue !== undefined){
42158 this.wrap = this.el.wrap();
42160 this.viewEl = this.wrap.createChild({ tag: 'div'});
42162 if (this.bodyStyle) {
42163 this.viewEl.applyStyles(this.bodyStyle);
42165 //this.viewEl.setStyle('padding', '2px');
42167 this.setValue(this.value);
42172 initValue : Roo.emptyFn,
42177 onClick : function(){
42182 * Sets the checked state of the checkbox.
42183 * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
42185 setValue : function(v){
42187 var html = this.valueRenderer ? this.valueRenderer(v) : String.format('{0}', v);
42188 // this might be called before we have a dom element..
42189 if (!this.viewEl) {
42192 this.viewEl.dom.innerHTML = html;
42193 Roo.form.DisplayField.superclass.setValue.call(this, v);
42196 });//<script type="text/javasscript">
42200 * @class Roo.DDView
42201 * A DnD enabled version of Roo.View.
42202 * @param {Element/String} container The Element in which to create the View.
42203 * @param {String} tpl The template string used to create the markup for each element of the View
42204 * @param {Object} config The configuration properties. These include all the config options of
42205 * {@link Roo.View} plus some specific to this class.<br>
42207 * Drag/drop is implemented by adding {@link Roo.data.Record}s to the target DDView. If copying is
42208 * not being performed, the original {@link Roo.data.Record} is removed from the source DDView.<br>
42210 * The following extra CSS rules are needed to provide insertion point highlighting:<pre><code>
42211 .x-view-drag-insert-above {
42212 border-top:1px dotted #3366cc;
42214 .x-view-drag-insert-below {
42215 border-bottom:1px dotted #3366cc;
42221 Roo.DDView = function(container, tpl, config) {
42222 Roo.DDView.superclass.constructor.apply(this, arguments);
42223 this.getEl().setStyle("outline", "0px none");
42224 this.getEl().unselectable();
42225 if (this.dragGroup) {
42226 this.setDraggable(this.dragGroup.split(","));
42228 if (this.dropGroup) {
42229 this.setDroppable(this.dropGroup.split(","));
42231 if (this.deletable) {
42232 this.setDeletable();
42234 this.isDirtyFlag = false;
42240 Roo.extend(Roo.DDView, Roo.View, {
42241 /** @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone. */
42242 /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
42243 /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
42244 /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
42248 reset: Roo.emptyFn,
42250 clearInvalid: Roo.form.Field.prototype.clearInvalid,
42252 validate: function() {
42256 destroy: function() {
42257 this.purgeListeners();
42258 this.getEl.removeAllListeners();
42259 this.getEl().remove();
42260 if (this.dragZone) {
42261 if (this.dragZone.destroy) {
42262 this.dragZone.destroy();
42265 if (this.dropZone) {
42266 if (this.dropZone.destroy) {
42267 this.dropZone.destroy();
42272 /** Allows this class to be an Roo.form.Field so it can be found using {@link Roo.form.BasicForm#findField}. */
42273 getName: function() {
42277 /** Loads the View from a JSON string representing the Records to put into the Store. */
42278 setValue: function(v) {
42280 throw "DDView.setValue(). DDView must be constructed with a valid Store";
42283 data[this.store.reader.meta.root] = v ? [].concat(v) : [];
42284 this.store.proxy = new Roo.data.MemoryProxy(data);
42288 /** @return {String} a parenthesised list of the ids of the Records in the View. */
42289 getValue: function() {
42291 this.store.each(function(rec) {
42292 result += rec.id + ',';
42294 return result.substr(0, result.length - 1) + ')';
42297 getIds: function() {
42298 var i = 0, result = new Array(this.store.getCount());
42299 this.store.each(function(rec) {
42300 result[i++] = rec.id;
42305 isDirty: function() {
42306 return this.isDirtyFlag;
42310 * Part of the Roo.dd.DropZone interface. If no target node is found, the
42311 * whole Element becomes the target, and this causes the drop gesture to append.
42313 getTargetFromEvent : function(e) {
42314 var target = e.getTarget();
42315 while ((target !== null) && (target.parentNode != this.el.dom)) {
42316 target = target.parentNode;
42319 target = this.el.dom.lastChild || this.el.dom;
42325 * Create the drag data which consists of an object which has the property "ddel" as
42326 * the drag proxy element.
42328 getDragData : function(e) {
42329 var target = this.findItemFromChild(e.getTarget());
42331 this.handleSelection(e);
42332 var selNodes = this.getSelectedNodes();
42335 copy: this.copy || (this.allowCopy && e.ctrlKey),
42339 var selectedIndices = this.getSelectedIndexes();
42340 for (var i = 0; i < selectedIndices.length; i++) {
42341 dragData.records.push(this.store.getAt(selectedIndices[i]));
42343 if (selNodes.length == 1) {
42344 dragData.ddel = target.cloneNode(true); // the div element
42346 var div = document.createElement('div'); // create the multi element drag "ghost"
42347 div.className = 'multi-proxy';
42348 for (var i = 0, len = selNodes.length; i < len; i++) {
42349 div.appendChild(selNodes[i].cloneNode(true));
42351 dragData.ddel = div;
42353 //console.log(dragData)
42354 //console.log(dragData.ddel.innerHTML)
42357 //console.log('nodragData')
42361 /** Specify to which ddGroup items in this DDView may be dragged. */
42362 setDraggable: function(ddGroup) {
42363 if (ddGroup instanceof Array) {
42364 Roo.each(ddGroup, this.setDraggable, this);
42367 if (this.dragZone) {
42368 this.dragZone.addToGroup(ddGroup);
42370 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
42371 containerScroll: true,
42375 // Draggability implies selection. DragZone's mousedown selects the element.
42376 if (!this.multiSelect) { this.singleSelect = true; }
42378 // Wire the DragZone's handlers up to methods in *this*
42379 this.dragZone.getDragData = this.getDragData.createDelegate(this);
42383 /** Specify from which ddGroup this DDView accepts drops. */
42384 setDroppable: function(ddGroup) {
42385 if (ddGroup instanceof Array) {
42386 Roo.each(ddGroup, this.setDroppable, this);
42389 if (this.dropZone) {
42390 this.dropZone.addToGroup(ddGroup);
42392 this.dropZone = new Roo.dd.DropZone(this.getEl(), {
42393 containerScroll: true,
42397 // Wire the DropZone's handlers up to methods in *this*
42398 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
42399 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
42400 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
42401 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
42402 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
42406 /** Decide whether to drop above or below a View node. */
42407 getDropPoint : function(e, n, dd){
42408 if (n == this.el.dom) { return "above"; }
42409 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
42410 var c = t + (b - t) / 2;
42411 var y = Roo.lib.Event.getPageY(e);
42419 onNodeEnter : function(n, dd, e, data){
42423 onNodeOver : function(n, dd, e, data){
42424 var pt = this.getDropPoint(e, n, dd);
42425 // set the insert point style on the target node
42426 var dragElClass = this.dropNotAllowed;
42429 if (pt == "above"){
42430 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
42431 targetElClass = "x-view-drag-insert-above";
42433 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
42434 targetElClass = "x-view-drag-insert-below";
42436 if (this.lastInsertClass != targetElClass){
42437 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
42438 this.lastInsertClass = targetElClass;
42441 return dragElClass;
42444 onNodeOut : function(n, dd, e, data){
42445 this.removeDropIndicators(n);
42448 onNodeDrop : function(n, dd, e, data){
42449 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
42452 var pt = this.getDropPoint(e, n, dd);
42453 var insertAt = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
42454 if (pt == "below") { insertAt++; }
42455 for (var i = 0; i < data.records.length; i++) {
42456 var r = data.records[i];
42457 var dup = this.store.getById(r.id);
42458 if (dup && (dd != this.dragZone)) {
42459 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
42462 this.store.insert(insertAt++, r.copy());
42464 data.source.isDirtyFlag = true;
42466 this.store.insert(insertAt++, r);
42468 this.isDirtyFlag = true;
42471 this.dragZone.cachedTarget = null;
42475 removeDropIndicators : function(n){
42477 Roo.fly(n).removeClass([
42478 "x-view-drag-insert-above",
42479 "x-view-drag-insert-below"]);
42480 this.lastInsertClass = "_noclass";
42485 * Utility method. Add a delete option to the DDView's context menu.
42486 * @param {String} imageUrl The URL of the "delete" icon image.
42488 setDeletable: function(imageUrl) {
42489 if (!this.singleSelect && !this.multiSelect) {
42490 this.singleSelect = true;
42492 var c = this.getContextMenu();
42493 this.contextMenu.on("itemclick", function(item) {
42496 this.remove(this.getSelectedIndexes());
42500 this.contextMenu.add({
42507 /** Return the context menu for this DDView. */
42508 getContextMenu: function() {
42509 if (!this.contextMenu) {
42510 // Create the View's context menu
42511 this.contextMenu = new Roo.menu.Menu({
42512 id: this.id + "-contextmenu"
42514 this.el.on("contextmenu", this.showContextMenu, this);
42516 return this.contextMenu;
42519 disableContextMenu: function() {
42520 if (this.contextMenu) {
42521 this.el.un("contextmenu", this.showContextMenu, this);
42525 showContextMenu: function(e, item) {
42526 item = this.findItemFromChild(e.getTarget());
42529 this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true);
42530 this.contextMenu.showAt(e.getXY());
42535 * Remove {@link Roo.data.Record}s at the specified indices.
42536 * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove.
42538 remove: function(selectedIndices) {
42539 selectedIndices = [].concat(selectedIndices);
42540 for (var i = 0; i < selectedIndices.length; i++) {
42541 var rec = this.store.getAt(selectedIndices[i]);
42542 this.store.remove(rec);
42547 * Double click fires the event, but also, if this is draggable, and there is only one other
42548 * related DropZone, it transfers the selected node.
42550 onDblClick : function(e){
42551 var item = this.findItemFromChild(e.getTarget());
42553 if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) {
42556 if (this.dragGroup) {
42557 var targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
42558 while (targets.indexOf(this.dropZone) > -1) {
42559 targets.remove(this.dropZone);
42561 if (targets.length == 1) {
42562 this.dragZone.cachedTarget = null;
42563 var el = Roo.get(targets[0].getEl());
42564 var box = el.getBox(true);
42565 targets[0].onNodeDrop(el.dom, {
42567 xy: [box.x, box.y + box.height - 1]
42568 }, null, this.getDragData(e));
42574 handleSelection: function(e) {
42575 this.dragZone.cachedTarget = null;
42576 var item = this.findItemFromChild(e.getTarget());
42578 this.clearSelections(true);
42581 if (item && (this.multiSelect || this.singleSelect)){
42582 if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
42583 this.select(this.getNodes(this.indexOf(this.lastSelection), item.nodeIndex), false);
42584 }else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
42585 this.unselect(item);
42587 this.select(item, this.multiSelect && e.ctrlKey);
42588 this.lastSelection = item;
42593 onItemClick : function(item, index, e){
42594 if(this.fireEvent("beforeclick", this, index, item, e) === false){
42600 unselect : function(nodeInfo, suppressEvent){
42601 var node = this.getNode(nodeInfo);
42602 if(node && this.isSelected(node)){
42603 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
42604 Roo.fly(node).removeClass(this.selectedClass);
42605 this.selections.remove(node);
42606 if(!suppressEvent){
42607 this.fireEvent("selectionchange", this, this.selections);
42615 * Ext JS Library 1.1.1
42616 * Copyright(c) 2006-2007, Ext JS, LLC.
42618 * Originally Released Under LGPL - original licence link has changed is not relivant.
42621 * <script type="text/javascript">
42625 * @class Roo.LayoutManager
42626 * @extends Roo.util.Observable
42627 * Base class for layout managers.
42629 Roo.LayoutManager = function(container, config){
42630 Roo.LayoutManager.superclass.constructor.call(this);
42631 this.el = Roo.get(container);
42632 // ie scrollbar fix
42633 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
42634 document.body.scroll = "no";
42635 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
42636 this.el.position('relative');
42638 this.id = this.el.id;
42639 this.el.addClass("x-layout-container");
42640 /** false to disable window resize monitoring @type Boolean */
42641 this.monitorWindowResize = true;
42646 * Fires when a layout is performed.
42647 * @param {Roo.LayoutManager} this
42651 * @event regionresized
42652 * Fires when the user resizes a region.
42653 * @param {Roo.LayoutRegion} region The resized region
42654 * @param {Number} newSize The new size (width for east/west, height for north/south)
42656 "regionresized" : true,
42658 * @event regioncollapsed
42659 * Fires when a region is collapsed.
42660 * @param {Roo.LayoutRegion} region The collapsed region
42662 "regioncollapsed" : true,
42664 * @event regionexpanded
42665 * Fires when a region is expanded.
42666 * @param {Roo.LayoutRegion} region The expanded region
42668 "regionexpanded" : true
42670 this.updating = false;
42671 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
42674 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
42676 * Returns true if this layout is currently being updated
42677 * @return {Boolean}
42679 isUpdating : function(){
42680 return this.updating;
42684 * Suspend the LayoutManager from doing auto-layouts while
42685 * making multiple add or remove calls
42687 beginUpdate : function(){
42688 this.updating = true;
42692 * Restore auto-layouts and optionally disable the manager from performing a layout
42693 * @param {Boolean} noLayout true to disable a layout update
42695 endUpdate : function(noLayout){
42696 this.updating = false;
42702 layout: function(){
42706 onRegionResized : function(region, newSize){
42707 this.fireEvent("regionresized", region, newSize);
42711 onRegionCollapsed : function(region){
42712 this.fireEvent("regioncollapsed", region);
42715 onRegionExpanded : function(region){
42716 this.fireEvent("regionexpanded", region);
42720 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
42721 * performs box-model adjustments.
42722 * @return {Object} The size as an object {width: (the width), height: (the height)}
42724 getViewSize : function(){
42726 if(this.el.dom != document.body){
42727 size = this.el.getSize();
42729 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
42731 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
42732 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
42737 * Returns the Element this layout is bound to.
42738 * @return {Roo.Element}
42740 getEl : function(){
42745 * Returns the specified region.
42746 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
42747 * @return {Roo.LayoutRegion}
42749 getRegion : function(target){
42750 return this.regions[target.toLowerCase()];
42753 onWindowResize : function(){
42754 if(this.monitorWindowResize){
42760 * Ext JS Library 1.1.1
42761 * Copyright(c) 2006-2007, Ext JS, LLC.
42763 * Originally Released Under LGPL - original licence link has changed is not relivant.
42766 * <script type="text/javascript">
42769 * @class Roo.BorderLayout
42770 * @extends Roo.LayoutManager
42771 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
42772 * please see: <br><br>
42773 * <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>
42774 * <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>
42777 var layout = new Roo.BorderLayout(document.body, {
42811 preferredTabWidth: 150
42816 var CP = Roo.ContentPanel;
42818 layout.beginUpdate();
42819 layout.add("north", new CP("north", "North"));
42820 layout.add("south", new CP("south", {title: "South", closable: true}));
42821 layout.add("west", new CP("west", {title: "West"}));
42822 layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
42823 layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
42824 layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
42825 layout.getRegion("center").showPanel("center1");
42826 layout.endUpdate();
42829 <b>The container the layout is rendered into can be either the body element or any other element.
42830 If it is not the body element, the container needs to either be an absolute positioned element,
42831 or you will need to add "position:relative" to the css of the container. You will also need to specify
42832 the container size if it is not the body element.</b>
42835 * Create a new BorderLayout
42836 * @param {String/HTMLElement/Element} container The container this layout is bound to
42837 * @param {Object} config Configuration options
42839 Roo.BorderLayout = function(container, config){
42840 config = config || {};
42841 Roo.BorderLayout.superclass.constructor.call(this, container, config);
42842 this.factory = config.factory || Roo.BorderLayout.RegionFactory;
42843 for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
42844 var target = this.factory.validRegions[i];
42845 if(config[target]){
42846 this.addRegion(target, config[target]);
42851 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
42853 * Creates and adds a new region if it doesn't already exist.
42854 * @param {String} target The target region key (north, south, east, west or center).
42855 * @param {Object} config The regions config object
42856 * @return {BorderLayoutRegion} The new region
42858 addRegion : function(target, config){
42859 if(!this.regions[target]){
42860 var r = this.factory.create(target, this, config);
42861 this.bindRegion(target, r);
42863 return this.regions[target];
42867 bindRegion : function(name, r){
42868 this.regions[name] = r;
42869 r.on("visibilitychange", this.layout, this);
42870 r.on("paneladded", this.layout, this);
42871 r.on("panelremoved", this.layout, this);
42872 r.on("invalidated", this.layout, this);
42873 r.on("resized", this.onRegionResized, this);
42874 r.on("collapsed", this.onRegionCollapsed, this);
42875 r.on("expanded", this.onRegionExpanded, this);
42879 * Performs a layout update.
42881 layout : function(){
42882 if(this.updating) return;
42883 var size = this.getViewSize();
42884 var w = size.width;
42885 var h = size.height;
42890 //var x = 0, y = 0;
42892 var rs = this.regions;
42893 var north = rs["north"];
42894 var south = rs["south"];
42895 var west = rs["west"];
42896 var east = rs["east"];
42897 var center = rs["center"];
42898 //if(this.hideOnLayout){ // not supported anymore
42899 //c.el.setStyle("display", "none");
42901 if(north && north.isVisible()){
42902 var b = north.getBox();
42903 var m = north.getMargins();
42904 b.width = w - (m.left+m.right);
42907 centerY = b.height + b.y + m.bottom;
42908 centerH -= centerY;
42909 north.updateBox(this.safeBox(b));
42911 if(south && south.isVisible()){
42912 var b = south.getBox();
42913 var m = south.getMargins();
42914 b.width = w - (m.left+m.right);
42916 var totalHeight = (b.height + m.top + m.bottom);
42917 b.y = h - totalHeight + m.top;
42918 centerH -= totalHeight;
42919 south.updateBox(this.safeBox(b));
42921 if(west && west.isVisible()){
42922 var b = west.getBox();
42923 var m = west.getMargins();
42924 b.height = centerH - (m.top+m.bottom);
42926 b.y = centerY + m.top;
42927 var totalWidth = (b.width + m.left + m.right);
42928 centerX += totalWidth;
42929 centerW -= totalWidth;
42930 west.updateBox(this.safeBox(b));
42932 if(east && east.isVisible()){
42933 var b = east.getBox();
42934 var m = east.getMargins();
42935 b.height = centerH - (m.top+m.bottom);
42936 var totalWidth = (b.width + m.left + m.right);
42937 b.x = w - totalWidth + m.left;
42938 b.y = centerY + m.top;
42939 centerW -= totalWidth;
42940 east.updateBox(this.safeBox(b));
42943 var m = center.getMargins();
42945 x: centerX + m.left,
42946 y: centerY + m.top,
42947 width: centerW - (m.left+m.right),
42948 height: centerH - (m.top+m.bottom)
42950 //if(this.hideOnLayout){
42951 //center.el.setStyle("display", "block");
42953 center.updateBox(this.safeBox(centerBox));
42956 this.fireEvent("layout", this);
42960 safeBox : function(box){
42961 box.width = Math.max(0, box.width);
42962 box.height = Math.max(0, box.height);
42967 * Adds a ContentPanel (or subclass) to this layout.
42968 * @param {String} target The target region key (north, south, east, west or center).
42969 * @param {Roo.ContentPanel} panel The panel to add
42970 * @return {Roo.ContentPanel} The added panel
42972 add : function(target, panel){
42974 target = target.toLowerCase();
42975 return this.regions[target].add(panel);
42979 * Remove a ContentPanel (or subclass) to this layout.
42980 * @param {String} target The target region key (north, south, east, west or center).
42981 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
42982 * @return {Roo.ContentPanel} The removed panel
42984 remove : function(target, panel){
42985 target = target.toLowerCase();
42986 return this.regions[target].remove(panel);
42990 * Searches all regions for a panel with the specified id
42991 * @param {String} panelId
42992 * @return {Roo.ContentPanel} The panel or null if it wasn't found
42994 findPanel : function(panelId){
42995 var rs = this.regions;
42996 for(var target in rs){
42997 if(typeof rs[target] != "function"){
42998 var p = rs[target].getPanel(panelId);
43008 * Searches all regions for a panel with the specified id and activates (shows) it.
43009 * @param {String/ContentPanel} panelId The panels id or the panel itself
43010 * @return {Roo.ContentPanel} The shown panel or null
43012 showPanel : function(panelId) {
43013 var rs = this.regions;
43014 for(var target in rs){
43015 var r = rs[target];
43016 if(typeof r != "function"){
43017 if(r.hasPanel(panelId)){
43018 return r.showPanel(panelId);
43026 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
43027 * @param {Roo.state.Provider} provider (optional) An alternate state provider
43029 restoreState : function(provider){
43031 provider = Roo.state.Manager;
43033 var sm = new Roo.LayoutStateManager();
43034 sm.init(this, provider);
43038 * Adds a batch of multiple ContentPanels dynamically by passing a special regions config object. This config
43039 * object should contain properties for each region to add ContentPanels to, and each property's value should be
43040 * a valid ContentPanel config object. Example:
43042 // Create the main layout
43043 var layout = new Roo.BorderLayout('main-ct', {
43054 // Create and add multiple ContentPanels at once via configs
43057 id: 'source-files',
43059 title:'Ext Source Files',
43072 * @param {Object} regions An object containing ContentPanel configs by region name
43074 batchAdd : function(regions){
43075 this.beginUpdate();
43076 for(var rname in regions){
43077 var lr = this.regions[rname];
43079 this.addTypedPanels(lr, regions[rname]);
43086 addTypedPanels : function(lr, ps){
43087 if(typeof ps == 'string'){
43088 lr.add(new Roo.ContentPanel(ps));
43090 else if(ps instanceof Array){
43091 for(var i =0, len = ps.length; i < len; i++){
43092 this.addTypedPanels(lr, ps[i]);
43095 else if(!ps.events){ // raw config?
43097 delete ps.el; // prevent conflict
43098 lr.add(new Roo.ContentPanel(el || Roo.id(), ps));
43100 else { // panel object assumed!
43105 * Adds a xtype elements to the layout.
43109 xtype : 'ContentPanel',
43116 xtype : 'NestedLayoutPanel',
43122 items : [ ... list of content panels or nested layout panels.. ]
43126 * @param {Object} cfg Xtype definition of item to add.
43128 addxtype : function(cfg)
43130 // basically accepts a pannel...
43131 // can accept a layout region..!?!?
43132 // console.log('BorderLayout add ' + cfg.xtype)
43134 if (!cfg.xtype.match(/Panel$/)) {
43138 var region = cfg.region;
43144 xitems = cfg.items;
43151 case 'ContentPanel': // ContentPanel (el, cfg)
43152 if(cfg.autoCreate) {
43153 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
43155 var el = this.el.createChild();
43156 ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
43159 this.add(region, ret);
43163 case 'TreePanel': // our new panel!
43164 cfg.el = this.el.createChild();
43165 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
43166 this.add(region, ret);
43169 case 'NestedLayoutPanel':
43170 // create a new Layout (which is a Border Layout...
43171 var el = this.el.createChild();
43172 var clayout = cfg.layout;
43174 clayout.items = clayout.items || [];
43175 // replace this exitems with the clayout ones..
43176 xitems = clayout.items;
43179 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
43180 cfg.background = false;
43182 var layout = new Roo.BorderLayout(el, clayout);
43184 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
43185 //console.log('adding nested layout panel ' + cfg.toSource());
43186 this.add(region, ret);
43192 // needs grid and region
43194 //var el = this.getRegion(region).el.createChild();
43195 var el = this.el.createChild();
43196 // create the grid first...
43198 var grid = new Roo.grid[cfg.grid.xtype](el, cfg.grid);
43200 if (region == 'center' && this.active ) {
43201 cfg.background = false;
43203 ret = new Roo[cfg.xtype](grid, cfg); // new panel!!!!!
43205 this.add(region, ret);
43206 if (cfg.background) {
43207 ret.on('activate', function(gp) {
43208 if (!gp.grid.rendered) {
43221 alert("Can not add '" + cfg.xtype + "' to BorderLayout");
43223 // GridPanel (grid, cfg)
43226 this.beginUpdate();
43228 Roo.each(xitems, function(i) {
43238 * Shortcut for creating a new BorderLayout object and adding one or more ContentPanels to it in a single step, handling
43239 * the beginUpdate and endUpdate calls internally. The key to this method is the <b>panels</b> property that can be
43240 * provided with each region config, which allows you to add ContentPanel configs in addition to the region configs
43241 * during creation. The following code is equivalent to the constructor-based example at the beginning of this class:
43244 var CP = Roo.ContentPanel;
43246 var layout = Roo.BorderLayout.create({
43250 panels: [new CP("north", "North")]
43259 panels: [new CP("west", {title: "West"})]
43268 panels: [new CP("autoTabs", {title: "Auto Tabs", closable: true})]
43277 panels: [new CP("south", {title: "South", closable: true})]
43284 preferredTabWidth: 150,
43286 new CP("center1", {title: "Close Me", closable: true}),
43287 new CP("center2", {title: "Center Panel", closable: false})
43292 layout.getRegion("center").showPanel("center1");
43297 Roo.BorderLayout.create = function(config, targetEl){
43298 var layout = new Roo.BorderLayout(targetEl || document.body, config);
43299 layout.beginUpdate();
43300 var regions = Roo.BorderLayout.RegionFactory.validRegions;
43301 for(var j = 0, jlen = regions.length; j < jlen; j++){
43302 var lr = regions[j];
43303 if(layout.regions[lr] && config[lr].panels){
43304 var r = layout.regions[lr];
43305 var ps = config[lr].panels;
43306 layout.addTypedPanels(r, ps);
43309 layout.endUpdate();
43314 Roo.BorderLayout.RegionFactory = {
43316 validRegions : ["north","south","east","west","center"],
43319 create : function(target, mgr, config){
43320 target = target.toLowerCase();
43321 if(config.lightweight || config.basic){
43322 return new Roo.BasicLayoutRegion(mgr, config, target);
43326 return new Roo.NorthLayoutRegion(mgr, config);
43328 return new Roo.SouthLayoutRegion(mgr, config);
43330 return new Roo.EastLayoutRegion(mgr, config);
43332 return new Roo.WestLayoutRegion(mgr, config);
43334 return new Roo.CenterLayoutRegion(mgr, config);
43336 throw 'Layout region "'+target+'" not supported.';
43340 * Ext JS Library 1.1.1
43341 * Copyright(c) 2006-2007, Ext JS, LLC.
43343 * Originally Released Under LGPL - original licence link has changed is not relivant.
43346 * <script type="text/javascript">
43350 * @class Roo.BasicLayoutRegion
43351 * @extends Roo.util.Observable
43352 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
43353 * and does not have a titlebar, tabs or any other features. All it does is size and position
43354 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
43356 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
43358 this.position = pos;
43361 * @scope Roo.BasicLayoutRegion
43365 * @event beforeremove
43366 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
43367 * @param {Roo.LayoutRegion} this
43368 * @param {Roo.ContentPanel} panel The panel
43369 * @param {Object} e The cancel event object
43371 "beforeremove" : true,
43373 * @event invalidated
43374 * Fires when the layout for this region is changed.
43375 * @param {Roo.LayoutRegion} this
43377 "invalidated" : true,
43379 * @event visibilitychange
43380 * Fires when this region is shown or hidden
43381 * @param {Roo.LayoutRegion} this
43382 * @param {Boolean} visibility true or false
43384 "visibilitychange" : true,
43386 * @event paneladded
43387 * Fires when a panel is added.
43388 * @param {Roo.LayoutRegion} this
43389 * @param {Roo.ContentPanel} panel The panel
43391 "paneladded" : true,
43393 * @event panelremoved
43394 * Fires when a panel is removed.
43395 * @param {Roo.LayoutRegion} this
43396 * @param {Roo.ContentPanel} panel The panel
43398 "panelremoved" : true,
43401 * Fires when this region is collapsed.
43402 * @param {Roo.LayoutRegion} this
43404 "collapsed" : true,
43407 * Fires when this region is expanded.
43408 * @param {Roo.LayoutRegion} this
43413 * Fires when this region is slid into view.
43414 * @param {Roo.LayoutRegion} this
43416 "slideshow" : true,
43419 * Fires when this region slides out of view.
43420 * @param {Roo.LayoutRegion} this
43422 "slidehide" : true,
43424 * @event panelactivated
43425 * Fires when a panel is activated.
43426 * @param {Roo.LayoutRegion} this
43427 * @param {Roo.ContentPanel} panel The activated panel
43429 "panelactivated" : true,
43432 * Fires when the user resizes this region.
43433 * @param {Roo.LayoutRegion} this
43434 * @param {Number} newSize The new size (width for east/west, height for north/south)
43438 /** A collection of panels in this region. @type Roo.util.MixedCollection */
43439 this.panels = new Roo.util.MixedCollection();
43440 this.panels.getKey = this.getPanelId.createDelegate(this);
43442 this.activePanel = null;
43443 // ensure listeners are added...
43445 if (config.listeners || config.events) {
43446 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
43447 listeners : config.listeners || {},
43448 events : config.events || {}
43452 if(skipConfig !== true){
43453 this.applyConfig(config);
43457 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
43458 getPanelId : function(p){
43462 applyConfig : function(config){
43463 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
43464 this.config = config;
43469 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
43470 * the width, for horizontal (north, south) the height.
43471 * @param {Number} newSize The new width or height
43473 resizeTo : function(newSize){
43474 var el = this.el ? this.el :
43475 (this.activePanel ? this.activePanel.getEl() : null);
43477 switch(this.position){
43480 el.setWidth(newSize);
43481 this.fireEvent("resized", this, newSize);
43485 el.setHeight(newSize);
43486 this.fireEvent("resized", this, newSize);
43492 getBox : function(){
43493 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
43496 getMargins : function(){
43497 return this.margins;
43500 updateBox : function(box){
43502 var el = this.activePanel.getEl();
43503 el.dom.style.left = box.x + "px";
43504 el.dom.style.top = box.y + "px";
43505 this.activePanel.setSize(box.width, box.height);
43509 * Returns the container element for this region.
43510 * @return {Roo.Element}
43512 getEl : function(){
43513 return this.activePanel;
43517 * Returns true if this region is currently visible.
43518 * @return {Boolean}
43520 isVisible : function(){
43521 return this.activePanel ? true : false;
43524 setActivePanel : function(panel){
43525 panel = this.getPanel(panel);
43526 if(this.activePanel && this.activePanel != panel){
43527 this.activePanel.setActiveState(false);
43528 this.activePanel.getEl().setLeftTop(-10000,-10000);
43530 this.activePanel = panel;
43531 panel.setActiveState(true);
43533 panel.setSize(this.box.width, this.box.height);
43535 this.fireEvent("panelactivated", this, panel);
43536 this.fireEvent("invalidated");
43540 * Show the specified panel.
43541 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
43542 * @return {Roo.ContentPanel} The shown panel or null
43544 showPanel : function(panel){
43545 if(panel = this.getPanel(panel)){
43546 this.setActivePanel(panel);
43552 * Get the active panel for this region.
43553 * @return {Roo.ContentPanel} The active panel or null
43555 getActivePanel : function(){
43556 return this.activePanel;
43560 * Add the passed ContentPanel(s)
43561 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
43562 * @return {Roo.ContentPanel} The panel added (if only one was added)
43564 add : function(panel){
43565 if(arguments.length > 1){
43566 for(var i = 0, len = arguments.length; i < len; i++) {
43567 this.add(arguments[i]);
43571 if(this.hasPanel(panel)){
43572 this.showPanel(panel);
43575 var el = panel.getEl();
43576 if(el.dom.parentNode != this.mgr.el.dom){
43577 this.mgr.el.dom.appendChild(el.dom);
43579 if(panel.setRegion){
43580 panel.setRegion(this);
43582 this.panels.add(panel);
43583 el.setStyle("position", "absolute");
43584 if(!panel.background){
43585 this.setActivePanel(panel);
43586 if(this.config.initialSize && this.panels.getCount()==1){
43587 this.resizeTo(this.config.initialSize);
43590 this.fireEvent("paneladded", this, panel);
43595 * Returns true if the panel is in this region.
43596 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
43597 * @return {Boolean}
43599 hasPanel : function(panel){
43600 if(typeof panel == "object"){ // must be panel obj
43601 panel = panel.getId();
43603 return this.getPanel(panel) ? true : false;
43607 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
43608 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
43609 * @param {Boolean} preservePanel Overrides the config preservePanel option
43610 * @return {Roo.ContentPanel} The panel that was removed
43612 remove : function(panel, preservePanel){
43613 panel = this.getPanel(panel);
43618 this.fireEvent("beforeremove", this, panel, e);
43619 if(e.cancel === true){
43622 var panelId = panel.getId();
43623 this.panels.removeKey(panelId);
43628 * Returns the panel specified or null if it's not in this region.
43629 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
43630 * @return {Roo.ContentPanel}
43632 getPanel : function(id){
43633 if(typeof id == "object"){ // must be panel obj
43636 return this.panels.get(id);
43640 * Returns this regions position (north/south/east/west/center).
43643 getPosition: function(){
43644 return this.position;
43648 * Ext JS Library 1.1.1
43649 * Copyright(c) 2006-2007, Ext JS, LLC.
43651 * Originally Released Under LGPL - original licence link has changed is not relivant.
43654 * <script type="text/javascript">
43658 * @class Roo.LayoutRegion
43659 * @extends Roo.BasicLayoutRegion
43660 * This class represents a region in a layout manager.
43661 * @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
43662 * @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
43663 * @cfg {Boolean} floatable False to disable floating (defaults to true)
43664 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
43665 * @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})
43666 * @cfg {String} tabPosition "top" or "bottom" (defaults to "bottom")
43667 * @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
43668 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
43669 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
43670 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
43671 * @cfg {String} title The title for the region (overrides panel titles)
43672 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
43673 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
43674 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
43675 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
43676 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
43677 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
43678 * the space available, similar to FireFox 1.5 tabs (defaults to false)
43679 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
43680 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
43681 * @cfg {Boolean} showPin True to show a pin button
43682 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
43683 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
43684 * @cfg {Boolean} disableTabTips True to disable tab tooltips
43685 * @cfg {Number} width For East/West panels
43686 * @cfg {Number} height For North/South panels
43687 * @cfg {Boolean} split To show the splitter
43689 Roo.LayoutRegion = function(mgr, config, pos){
43690 Roo.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
43691 var dh = Roo.DomHelper;
43692 /** This region's container element
43693 * @type Roo.Element */
43694 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
43695 /** This region's title element
43696 * @type Roo.Element */
43698 this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
43699 {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
43700 {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
43702 this.titleEl.enableDisplayMode();
43703 /** This region's title text element
43704 * @type HTMLElement */
43705 this.titleTextEl = this.titleEl.dom.firstChild;
43706 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
43707 this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
43708 this.closeBtn.enableDisplayMode();
43709 this.closeBtn.on("click", this.closeClicked, this);
43710 this.closeBtn.hide();
43712 this.createBody(config);
43713 this.visible = true;
43714 this.collapsed = false;
43716 if(config.hideWhenEmpty){
43718 this.on("paneladded", this.validateVisibility, this);
43719 this.on("panelremoved", this.validateVisibility, this);
43721 this.applyConfig(config);
43724 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
43726 createBody : function(){
43727 /** This region's body element
43728 * @type Roo.Element */
43729 this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
43732 applyConfig : function(c){
43733 if(c.collapsible && this.position != "center" && !this.collapsedEl){
43734 var dh = Roo.DomHelper;
43735 if(c.titlebar !== false){
43736 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
43737 this.collapseBtn.on("click", this.collapse, this);
43738 this.collapseBtn.enableDisplayMode();
43740 if(c.showPin === true || this.showPin){
43741 this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
43742 this.stickBtn.enableDisplayMode();
43743 this.stickBtn.on("click", this.expand, this);
43744 this.stickBtn.hide();
43747 /** This region's collapsed element
43748 * @type Roo.Element */
43749 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
43750 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
43752 if(c.floatable !== false){
43753 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
43754 this.collapsedEl.on("click", this.collapseClick, this);
43757 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
43758 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
43759 id: "message", unselectable: "on", style:{"float":"left"}});
43760 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
43762 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
43763 this.expandBtn.on("click", this.expand, this);
43765 if(this.collapseBtn){
43766 this.collapseBtn.setVisible(c.collapsible == true);
43768 this.cmargins = c.cmargins || this.cmargins ||
43769 (this.position == "west" || this.position == "east" ?
43770 {top: 0, left: 2, right:2, bottom: 0} :
43771 {top: 2, left: 0, right:0, bottom: 2});
43772 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
43773 this.bottomTabs = c.tabPosition != "top";
43774 this.autoScroll = c.autoScroll || false;
43775 if(this.autoScroll){
43776 this.bodyEl.setStyle("overflow", "auto");
43778 this.bodyEl.setStyle("overflow", "hidden");
43780 //if(c.titlebar !== false){
43781 if((!c.titlebar && !c.title) || c.titlebar === false){
43782 this.titleEl.hide();
43784 this.titleEl.show();
43786 this.titleTextEl.innerHTML = c.title;
43790 this.duration = c.duration || .30;
43791 this.slideDuration = c.slideDuration || .45;
43794 this.collapse(true);
43801 * Returns true if this region is currently visible.
43802 * @return {Boolean}
43804 isVisible : function(){
43805 return this.visible;
43809 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
43810 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
43812 setCollapsedTitle : function(title){
43813 title = title || " ";
43814 if(this.collapsedTitleTextEl){
43815 this.collapsedTitleTextEl.innerHTML = title;
43819 getBox : function(){
43821 if(!this.collapsed){
43822 b = this.el.getBox(false, true);
43824 b = this.collapsedEl.getBox(false, true);
43829 getMargins : function(){
43830 return this.collapsed ? this.cmargins : this.margins;
43833 highlight : function(){
43834 this.el.addClass("x-layout-panel-dragover");
43837 unhighlight : function(){
43838 this.el.removeClass("x-layout-panel-dragover");
43841 updateBox : function(box){
43843 if(!this.collapsed){
43844 this.el.dom.style.left = box.x + "px";
43845 this.el.dom.style.top = box.y + "px";
43846 this.updateBody(box.width, box.height);
43848 this.collapsedEl.dom.style.left = box.x + "px";
43849 this.collapsedEl.dom.style.top = box.y + "px";
43850 this.collapsedEl.setSize(box.width, box.height);
43853 this.tabs.autoSizeTabs();
43857 updateBody : function(w, h){
43859 this.el.setWidth(w);
43860 w -= this.el.getBorderWidth("rl");
43861 if(this.config.adjustments){
43862 w += this.config.adjustments[0];
43866 this.el.setHeight(h);
43867 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
43868 h -= this.el.getBorderWidth("tb");
43869 if(this.config.adjustments){
43870 h += this.config.adjustments[1];
43872 this.bodyEl.setHeight(h);
43874 h = this.tabs.syncHeight(h);
43877 if(this.panelSize){
43878 w = w !== null ? w : this.panelSize.width;
43879 h = h !== null ? h : this.panelSize.height;
43881 if(this.activePanel){
43882 var el = this.activePanel.getEl();
43883 w = w !== null ? w : el.getWidth();
43884 h = h !== null ? h : el.getHeight();
43885 this.panelSize = {width: w, height: h};
43886 this.activePanel.setSize(w, h);
43888 if(Roo.isIE && this.tabs){
43889 this.tabs.el.repaint();
43894 * Returns the container element for this region.
43895 * @return {Roo.Element}
43897 getEl : function(){
43902 * Hides this region.
43905 if(!this.collapsed){
43906 this.el.dom.style.left = "-2000px";
43909 this.collapsedEl.dom.style.left = "-2000px";
43910 this.collapsedEl.hide();
43912 this.visible = false;
43913 this.fireEvent("visibilitychange", this, false);
43917 * Shows this region if it was previously hidden.
43920 if(!this.collapsed){
43923 this.collapsedEl.show();
43925 this.visible = true;
43926 this.fireEvent("visibilitychange", this, true);
43929 closeClicked : function(){
43930 if(this.activePanel){
43931 this.remove(this.activePanel);
43935 collapseClick : function(e){
43937 e.stopPropagation();
43940 e.stopPropagation();
43946 * Collapses this region.
43947 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
43949 collapse : function(skipAnim){
43950 if(this.collapsed) return;
43951 this.collapsed = true;
43953 this.split.el.hide();
43955 if(this.config.animate && skipAnim !== true){
43956 this.fireEvent("invalidated", this);
43957 this.animateCollapse();
43959 this.el.setLocation(-20000,-20000);
43961 this.collapsedEl.show();
43962 this.fireEvent("collapsed", this);
43963 this.fireEvent("invalidated", this);
43967 animateCollapse : function(){
43972 * Expands this region if it was previously collapsed.
43973 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
43974 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
43976 expand : function(e, skipAnim){
43977 if(e) e.stopPropagation();
43978 if(!this.collapsed || this.el.hasActiveFx()) return;
43980 this.afterSlideIn();
43983 this.collapsed = false;
43984 if(this.config.animate && skipAnim !== true){
43985 this.animateExpand();
43989 this.split.el.show();
43991 this.collapsedEl.setLocation(-2000,-2000);
43992 this.collapsedEl.hide();
43993 this.fireEvent("invalidated", this);
43994 this.fireEvent("expanded", this);
43998 animateExpand : function(){
44002 initTabs : function(){
44003 this.bodyEl.setStyle("overflow", "hidden");
44004 var ts = new Roo.TabPanel(this.bodyEl.dom, {
44005 tabPosition: this.bottomTabs ? 'bottom' : 'top',
44006 disableTooltips: this.config.disableTabTips
44008 if(this.config.hideTabs){
44009 ts.stripWrap.setDisplayed(false);
44012 ts.resizeTabs = this.config.resizeTabs === true;
44013 ts.minTabWidth = this.config.minTabWidth || 40;
44014 ts.maxTabWidth = this.config.maxTabWidth || 250;
44015 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
44016 ts.monitorResize = false;
44017 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
44018 ts.bodyEl.addClass('x-layout-tabs-body');
44019 this.panels.each(this.initPanelAsTab, this);
44022 initPanelAsTab : function(panel){
44023 var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
44024 this.config.closeOnTab && panel.isClosable());
44025 if(panel.tabTip !== undefined){
44026 ti.setTooltip(panel.tabTip);
44028 ti.on("activate", function(){
44029 this.setActivePanel(panel);
44031 if(this.config.closeOnTab){
44032 ti.on("beforeclose", function(t, e){
44034 this.remove(panel);
44040 updatePanelTitle : function(panel, title){
44041 if(this.activePanel == panel){
44042 this.updateTitle(title);
44045 var ti = this.tabs.getTab(panel.getEl().id);
44047 if(panel.tabTip !== undefined){
44048 ti.setTooltip(panel.tabTip);
44053 updateTitle : function(title){
44054 if(this.titleTextEl && !this.config.title){
44055 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
44059 setActivePanel : function(panel){
44060 panel = this.getPanel(panel);
44061 if(this.activePanel && this.activePanel != panel){
44062 this.activePanel.setActiveState(false);
44064 this.activePanel = panel;
44065 panel.setActiveState(true);
44066 if(this.panelSize){
44067 panel.setSize(this.panelSize.width, this.panelSize.height);
44070 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
44072 this.updateTitle(panel.getTitle());
44074 this.fireEvent("invalidated", this);
44076 this.fireEvent("panelactivated", this, panel);
44080 * Shows the specified panel.
44081 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
44082 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
44084 showPanel : function(panel){
44085 if(panel = this.getPanel(panel)){
44087 var tab = this.tabs.getTab(panel.getEl().id);
44088 if(tab.isHidden()){
44089 this.tabs.unhideTab(tab.id);
44093 this.setActivePanel(panel);
44100 * Get the active panel for this region.
44101 * @return {Roo.ContentPanel} The active panel or null
44103 getActivePanel : function(){
44104 return this.activePanel;
44107 validateVisibility : function(){
44108 if(this.panels.getCount() < 1){
44109 this.updateTitle(" ");
44110 this.closeBtn.hide();
44113 if(!this.isVisible()){
44120 * Adds the passed ContentPanel(s) to this region.
44121 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
44122 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
44124 add : function(panel){
44125 if(arguments.length > 1){
44126 for(var i = 0, len = arguments.length; i < len; i++) {
44127 this.add(arguments[i]);
44131 if(this.hasPanel(panel)){
44132 this.showPanel(panel);
44135 panel.setRegion(this);
44136 this.panels.add(panel);
44137 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
44138 this.bodyEl.dom.appendChild(panel.getEl().dom);
44139 if(panel.background !== true){
44140 this.setActivePanel(panel);
44142 this.fireEvent("paneladded", this, panel);
44148 this.initPanelAsTab(panel);
44150 if(panel.background !== true){
44151 this.tabs.activate(panel.getEl().id);
44153 this.fireEvent("paneladded", this, panel);
44158 * Hides the tab for the specified panel.
44159 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
44161 hidePanel : function(panel){
44162 if(this.tabs && (panel = this.getPanel(panel))){
44163 this.tabs.hideTab(panel.getEl().id);
44168 * Unhides the tab for a previously hidden panel.
44169 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
44171 unhidePanel : function(panel){
44172 if(this.tabs && (panel = this.getPanel(panel))){
44173 this.tabs.unhideTab(panel.getEl().id);
44177 clearPanels : function(){
44178 while(this.panels.getCount() > 0){
44179 this.remove(this.panels.first());
44184 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
44185 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
44186 * @param {Boolean} preservePanel Overrides the config preservePanel option
44187 * @return {Roo.ContentPanel} The panel that was removed
44189 remove : function(panel, preservePanel){
44190 panel = this.getPanel(panel);
44195 this.fireEvent("beforeremove", this, panel, e);
44196 if(e.cancel === true){
44199 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
44200 var panelId = panel.getId();
44201 this.panels.removeKey(panelId);
44203 document.body.appendChild(panel.getEl().dom);
44206 this.tabs.removeTab(panel.getEl().id);
44207 }else if (!preservePanel){
44208 this.bodyEl.dom.removeChild(panel.getEl().dom);
44210 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
44211 var p = this.panels.first();
44212 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
44213 tempEl.appendChild(p.getEl().dom);
44214 this.bodyEl.update("");
44215 this.bodyEl.dom.appendChild(p.getEl().dom);
44217 this.updateTitle(p.getTitle());
44219 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
44220 this.setActivePanel(p);
44222 panel.setRegion(null);
44223 if(this.activePanel == panel){
44224 this.activePanel = null;
44226 if(this.config.autoDestroy !== false && preservePanel !== true){
44227 try{panel.destroy();}catch(e){}
44229 this.fireEvent("panelremoved", this, panel);
44234 * Returns the TabPanel component used by this region
44235 * @return {Roo.TabPanel}
44237 getTabs : function(){
44241 createTool : function(parentEl, className){
44242 var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
44243 children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
44244 btn.addClassOnOver("x-layout-tools-button-over");
44249 * Ext JS Library 1.1.1
44250 * Copyright(c) 2006-2007, Ext JS, LLC.
44252 * Originally Released Under LGPL - original licence link has changed is not relivant.
44255 * <script type="text/javascript">
44261 * @class Roo.SplitLayoutRegion
44262 * @extends Roo.LayoutRegion
44263 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
44265 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
44266 this.cursor = cursor;
44267 Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
44270 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
44271 splitTip : "Drag to resize.",
44272 collapsibleSplitTip : "Drag to resize. Double click to hide.",
44273 useSplitTips : false,
44275 applyConfig : function(config){
44276 Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
44279 var splitEl = Roo.DomHelper.append(this.mgr.el.dom,
44280 {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: " "});
44281 /** The SplitBar for this region
44282 * @type Roo.SplitBar */
44283 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
44284 this.split.on("moved", this.onSplitMove, this);
44285 this.split.useShim = config.useShim === true;
44286 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
44287 if(this.useSplitTips){
44288 this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
44290 if(config.collapsible){
44291 this.split.el.on("dblclick", this.collapse, this);
44294 if(typeof config.minSize != "undefined"){
44295 this.split.minSize = config.minSize;
44297 if(typeof config.maxSize != "undefined"){
44298 this.split.maxSize = config.maxSize;
44300 if(config.hideWhenEmpty || config.hidden || config.collapsed){
44301 this.hideSplitter();
44306 getHMaxSize : function(){
44307 var cmax = this.config.maxSize || 10000;
44308 var center = this.mgr.getRegion("center");
44309 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
44312 getVMaxSize : function(){
44313 var cmax = this.config.maxSize || 10000;
44314 var center = this.mgr.getRegion("center");
44315 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
44318 onSplitMove : function(split, newSize){
44319 this.fireEvent("resized", this, newSize);
44323 * Returns the {@link Roo.SplitBar} for this region.
44324 * @return {Roo.SplitBar}
44326 getSplitBar : function(){
44331 this.hideSplitter();
44332 Roo.SplitLayoutRegion.superclass.hide.call(this);
44335 hideSplitter : function(){
44337 this.split.el.setLocation(-2000,-2000);
44338 this.split.el.hide();
44344 this.split.el.show();
44346 Roo.SplitLayoutRegion.superclass.show.call(this);
44349 beforeSlide: function(){
44350 if(Roo.isGecko){// firefox overflow auto bug workaround
44351 this.bodyEl.clip();
44352 if(this.tabs) this.tabs.bodyEl.clip();
44353 if(this.activePanel){
44354 this.activePanel.getEl().clip();
44356 if(this.activePanel.beforeSlide){
44357 this.activePanel.beforeSlide();
44363 afterSlide : function(){
44364 if(Roo.isGecko){// firefox overflow auto bug workaround
44365 this.bodyEl.unclip();
44366 if(this.tabs) this.tabs.bodyEl.unclip();
44367 if(this.activePanel){
44368 this.activePanel.getEl().unclip();
44369 if(this.activePanel.afterSlide){
44370 this.activePanel.afterSlide();
44376 initAutoHide : function(){
44377 if(this.autoHide !== false){
44378 if(!this.autoHideHd){
44379 var st = new Roo.util.DelayedTask(this.slideIn, this);
44380 this.autoHideHd = {
44381 "mouseout": function(e){
44382 if(!e.within(this.el, true)){
44386 "mouseover" : function(e){
44392 this.el.on(this.autoHideHd);
44396 clearAutoHide : function(){
44397 if(this.autoHide !== false){
44398 this.el.un("mouseout", this.autoHideHd.mouseout);
44399 this.el.un("mouseover", this.autoHideHd.mouseover);
44403 clearMonitor : function(){
44404 Roo.get(document).un("click", this.slideInIf, this);
44407 // these names are backwards but not changed for compat
44408 slideOut : function(){
44409 if(this.isSlid || this.el.hasActiveFx()){
44412 this.isSlid = true;
44413 if(this.collapseBtn){
44414 this.collapseBtn.hide();
44416 this.closeBtnState = this.closeBtn.getStyle('display');
44417 this.closeBtn.hide();
44419 this.stickBtn.show();
44422 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
44423 this.beforeSlide();
44424 this.el.setStyle("z-index", 10001);
44425 this.el.slideIn(this.getSlideAnchor(), {
44426 callback: function(){
44428 this.initAutoHide();
44429 Roo.get(document).on("click", this.slideInIf, this);
44430 this.fireEvent("slideshow", this);
44437 afterSlideIn : function(){
44438 this.clearAutoHide();
44439 this.isSlid = false;
44440 this.clearMonitor();
44441 this.el.setStyle("z-index", "");
44442 if(this.collapseBtn){
44443 this.collapseBtn.show();
44445 this.closeBtn.setStyle('display', this.closeBtnState);
44447 this.stickBtn.hide();
44449 this.fireEvent("slidehide", this);
44452 slideIn : function(cb){
44453 if(!this.isSlid || this.el.hasActiveFx()){
44457 this.isSlid = false;
44458 this.beforeSlide();
44459 this.el.slideOut(this.getSlideAnchor(), {
44460 callback: function(){
44461 this.el.setLeftTop(-10000, -10000);
44463 this.afterSlideIn();
44471 slideInIf : function(e){
44472 if(!e.within(this.el)){
44477 animateCollapse : function(){
44478 this.beforeSlide();
44479 this.el.setStyle("z-index", 20000);
44480 var anchor = this.getSlideAnchor();
44481 this.el.slideOut(anchor, {
44482 callback : function(){
44483 this.el.setStyle("z-index", "");
44484 this.collapsedEl.slideIn(anchor, {duration:.3});
44486 this.el.setLocation(-10000,-10000);
44488 this.fireEvent("collapsed", this);
44495 animateExpand : function(){
44496 this.beforeSlide();
44497 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
44498 this.el.setStyle("z-index", 20000);
44499 this.collapsedEl.hide({
44502 this.el.slideIn(this.getSlideAnchor(), {
44503 callback : function(){
44504 this.el.setStyle("z-index", "");
44507 this.split.el.show();
44509 this.fireEvent("invalidated", this);
44510 this.fireEvent("expanded", this);
44538 getAnchor : function(){
44539 return this.anchors[this.position];
44542 getCollapseAnchor : function(){
44543 return this.canchors[this.position];
44546 getSlideAnchor : function(){
44547 return this.sanchors[this.position];
44550 getAlignAdj : function(){
44551 var cm = this.cmargins;
44552 switch(this.position){
44568 getExpandAdj : function(){
44569 var c = this.collapsedEl, cm = this.cmargins;
44570 switch(this.position){
44572 return [-(cm.right+c.getWidth()+cm.left), 0];
44575 return [cm.right+c.getWidth()+cm.left, 0];
44578 return [0, -(cm.top+cm.bottom+c.getHeight())];
44581 return [0, cm.top+cm.bottom+c.getHeight()];
44587 * Ext JS Library 1.1.1
44588 * Copyright(c) 2006-2007, Ext JS, LLC.
44590 * Originally Released Under LGPL - original licence link has changed is not relivant.
44593 * <script type="text/javascript">
44596 * These classes are private internal classes
44598 Roo.CenterLayoutRegion = function(mgr, config){
44599 Roo.LayoutRegion.call(this, mgr, config, "center");
44600 this.visible = true;
44601 this.minWidth = config.minWidth || 20;
44602 this.minHeight = config.minHeight || 20;
44605 Roo.extend(Roo.CenterLayoutRegion, Roo.LayoutRegion, {
44607 // center panel can't be hidden
44611 // center panel can't be hidden
44614 getMinWidth: function(){
44615 return this.minWidth;
44618 getMinHeight: function(){
44619 return this.minHeight;
44624 Roo.NorthLayoutRegion = function(mgr, config){
44625 Roo.LayoutRegion.call(this, mgr, config, "north", "n-resize");
44627 this.split.placement = Roo.SplitBar.TOP;
44628 this.split.orientation = Roo.SplitBar.VERTICAL;
44629 this.split.el.addClass("x-layout-split-v");
44631 var size = config.initialSize || config.height;
44632 if(typeof size != "undefined"){
44633 this.el.setHeight(size);
44636 Roo.extend(Roo.NorthLayoutRegion, Roo.SplitLayoutRegion, {
44637 orientation: Roo.SplitBar.VERTICAL,
44638 getBox : function(){
44639 if(this.collapsed){
44640 return this.collapsedEl.getBox();
44642 var box = this.el.getBox();
44644 box.height += this.split.el.getHeight();
44649 updateBox : function(box){
44650 if(this.split && !this.collapsed){
44651 box.height -= this.split.el.getHeight();
44652 this.split.el.setLeft(box.x);
44653 this.split.el.setTop(box.y+box.height);
44654 this.split.el.setWidth(box.width);
44656 if(this.collapsed){
44657 this.updateBody(box.width, null);
44659 Roo.LayoutRegion.prototype.updateBox.call(this, box);
44663 Roo.SouthLayoutRegion = function(mgr, config){
44664 Roo.SplitLayoutRegion.call(this, mgr, config, "south", "s-resize");
44666 this.split.placement = Roo.SplitBar.BOTTOM;
44667 this.split.orientation = Roo.SplitBar.VERTICAL;
44668 this.split.el.addClass("x-layout-split-v");
44670 var size = config.initialSize || config.height;
44671 if(typeof size != "undefined"){
44672 this.el.setHeight(size);
44675 Roo.extend(Roo.SouthLayoutRegion, Roo.SplitLayoutRegion, {
44676 orientation: Roo.SplitBar.VERTICAL,
44677 getBox : function(){
44678 if(this.collapsed){
44679 return this.collapsedEl.getBox();
44681 var box = this.el.getBox();
44683 var sh = this.split.el.getHeight();
44690 updateBox : function(box){
44691 if(this.split && !this.collapsed){
44692 var sh = this.split.el.getHeight();
44695 this.split.el.setLeft(box.x);
44696 this.split.el.setTop(box.y-sh);
44697 this.split.el.setWidth(box.width);
44699 if(this.collapsed){
44700 this.updateBody(box.width, null);
44702 Roo.LayoutRegion.prototype.updateBox.call(this, box);
44706 Roo.EastLayoutRegion = function(mgr, config){
44707 Roo.SplitLayoutRegion.call(this, mgr, config, "east", "e-resize");
44709 this.split.placement = Roo.SplitBar.RIGHT;
44710 this.split.orientation = Roo.SplitBar.HORIZONTAL;
44711 this.split.el.addClass("x-layout-split-h");
44713 var size = config.initialSize || config.width;
44714 if(typeof size != "undefined"){
44715 this.el.setWidth(size);
44718 Roo.extend(Roo.EastLayoutRegion, Roo.SplitLayoutRegion, {
44719 orientation: Roo.SplitBar.HORIZONTAL,
44720 getBox : function(){
44721 if(this.collapsed){
44722 return this.collapsedEl.getBox();
44724 var box = this.el.getBox();
44726 var sw = this.split.el.getWidth();
44733 updateBox : function(box){
44734 if(this.split && !this.collapsed){
44735 var sw = this.split.el.getWidth();
44737 this.split.el.setLeft(box.x);
44738 this.split.el.setTop(box.y);
44739 this.split.el.setHeight(box.height);
44742 if(this.collapsed){
44743 this.updateBody(null, box.height);
44745 Roo.LayoutRegion.prototype.updateBox.call(this, box);
44749 Roo.WestLayoutRegion = function(mgr, config){
44750 Roo.SplitLayoutRegion.call(this, mgr, config, "west", "w-resize");
44752 this.split.placement = Roo.SplitBar.LEFT;
44753 this.split.orientation = Roo.SplitBar.HORIZONTAL;
44754 this.split.el.addClass("x-layout-split-h");
44756 var size = config.initialSize || config.width;
44757 if(typeof size != "undefined"){
44758 this.el.setWidth(size);
44761 Roo.extend(Roo.WestLayoutRegion, Roo.SplitLayoutRegion, {
44762 orientation: Roo.SplitBar.HORIZONTAL,
44763 getBox : function(){
44764 if(this.collapsed){
44765 return this.collapsedEl.getBox();
44767 var box = this.el.getBox();
44769 box.width += this.split.el.getWidth();
44774 updateBox : function(box){
44775 if(this.split && !this.collapsed){
44776 var sw = this.split.el.getWidth();
44778 this.split.el.setLeft(box.x+box.width);
44779 this.split.el.setTop(box.y);
44780 this.split.el.setHeight(box.height);
44782 if(this.collapsed){
44783 this.updateBody(null, box.height);
44785 Roo.LayoutRegion.prototype.updateBox.call(this, box);
44790 * Ext JS Library 1.1.1
44791 * Copyright(c) 2006-2007, Ext JS, LLC.
44793 * Originally Released Under LGPL - original licence link has changed is not relivant.
44796 * <script type="text/javascript">
44801 * Private internal class for reading and applying state
44803 Roo.LayoutStateManager = function(layout){
44804 // default empty state
44813 Roo.LayoutStateManager.prototype = {
44814 init : function(layout, provider){
44815 this.provider = provider;
44816 var state = provider.get(layout.id+"-layout-state");
44818 var wasUpdating = layout.isUpdating();
44820 layout.beginUpdate();
44822 for(var key in state){
44823 if(typeof state[key] != "function"){
44824 var rstate = state[key];
44825 var r = layout.getRegion(key);
44828 r.resizeTo(rstate.size);
44830 if(rstate.collapsed == true){
44833 r.expand(null, true);
44839 layout.endUpdate();
44841 this.state = state;
44843 this.layout = layout;
44844 layout.on("regionresized", this.onRegionResized, this);
44845 layout.on("regioncollapsed", this.onRegionCollapsed, this);
44846 layout.on("regionexpanded", this.onRegionExpanded, this);
44849 storeState : function(){
44850 this.provider.set(this.layout.id+"-layout-state", this.state);
44853 onRegionResized : function(region, newSize){
44854 this.state[region.getPosition()].size = newSize;
44858 onRegionCollapsed : function(region){
44859 this.state[region.getPosition()].collapsed = true;
44863 onRegionExpanded : function(region){
44864 this.state[region.getPosition()].collapsed = false;
44869 * Ext JS Library 1.1.1
44870 * Copyright(c) 2006-2007, Ext JS, LLC.
44872 * Originally Released Under LGPL - original licence link has changed is not relivant.
44875 * <script type="text/javascript">
44878 * @class Roo.ContentPanel
44879 * @extends Roo.util.Observable
44880 * A basic ContentPanel element.
44881 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
44882 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
44883 * @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
44884 * @cfg {Boolean} closable True if the panel can be closed/removed
44885 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
44886 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
44887 * @cfg {Toolbar} toolbar A toolbar for this panel
44888 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
44889 * @cfg {String} title The title for this panel
44890 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
44891 * @cfg {String} url Calls {@link #setUrl} with this value
44892 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
44893 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
44894 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
44896 * Create a new ContentPanel.
44897 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
44898 * @param {String/Object} config A string to set only the title or a config object
44899 * @param {String} content (optional) Set the HTML content for this panel
44900 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
44902 Roo.ContentPanel = function(el, config, content){
44906 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
44910 if (config && config.parentLayout) {
44911 el = config.parentLayout.el.createChild();
44914 if(el.autoCreate){ // xtype is available if this is called from factory
44918 this.el = Roo.get(el);
44919 if(!this.el && config && config.autoCreate){
44920 if(typeof config.autoCreate == "object"){
44921 if(!config.autoCreate.id){
44922 config.autoCreate.id = config.id||el;
44924 this.el = Roo.DomHelper.append(document.body,
44925 config.autoCreate, true);
44927 this.el = Roo.DomHelper.append(document.body,
44928 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
44931 this.closable = false;
44932 this.loaded = false;
44933 this.active = false;
44934 if(typeof config == "string"){
44935 this.title = config;
44937 Roo.apply(this, config);
44940 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
44941 this.wrapEl = this.el.wrap();
44942 this.toolbar = new Roo.Toolbar(this.el.insertSibling(false, 'before'), [] , this.toolbar);
44949 this.resizeEl = Roo.get(this.resizeEl, true);
44951 this.resizeEl = this.el;
44956 * Fires when this panel is activated.
44957 * @param {Roo.ContentPanel} this
44961 * @event deactivate
44962 * Fires when this panel is activated.
44963 * @param {Roo.ContentPanel} this
44965 "deactivate" : true,
44969 * Fires when this panel is resized if fitToFrame is true.
44970 * @param {Roo.ContentPanel} this
44971 * @param {Number} width The width after any component adjustments
44972 * @param {Number} height The height after any component adjustments
44976 if(this.autoScroll){
44977 this.resizeEl.setStyle("overflow", "auto");
44979 content = content || this.content;
44981 this.setContent(content);
44983 if(config && config.url){
44984 this.setUrl(this.url, this.params, this.loadOnce);
44989 Roo.ContentPanel.superclass.constructor.call(this);
44992 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
44994 setRegion : function(region){
44995 this.region = region;
44997 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
44999 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
45004 * Returns the toolbar for this Panel if one was configured.
45005 * @return {Roo.Toolbar}
45007 getToolbar : function(){
45008 return this.toolbar;
45011 setActiveState : function(active){
45012 this.active = active;
45014 this.fireEvent("deactivate", this);
45016 this.fireEvent("activate", this);
45020 * Updates this panel's element
45021 * @param {String} content The new content
45022 * @param {Boolean} loadScripts (optional) true to look for and process scripts
45024 setContent : function(content, loadScripts){
45025 this.el.update(content, loadScripts);
45028 ignoreResize : function(w, h){
45029 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
45032 this.lastSize = {width: w, height: h};
45037 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
45038 * @return {Roo.UpdateManager} The UpdateManager
45040 getUpdateManager : function(){
45041 return this.el.getUpdateManager();
45044 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
45045 * @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:
45048 url: "your-url.php",
45049 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
45050 callback: yourFunction,
45051 scope: yourObject, //(optional scope)
45054 text: "Loading...",
45059 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
45060 * 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.
45061 * @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}
45062 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
45063 * @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.
45064 * @return {Roo.ContentPanel} this
45067 var um = this.el.getUpdateManager();
45068 um.update.apply(um, arguments);
45074 * 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.
45075 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
45076 * @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)
45077 * @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)
45078 * @return {Roo.UpdateManager} The UpdateManager
45080 setUrl : function(url, params, loadOnce){
45081 if(this.refreshDelegate){
45082 this.removeListener("activate", this.refreshDelegate);
45084 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
45085 this.on("activate", this.refreshDelegate);
45086 return this.el.getUpdateManager();
45089 _handleRefresh : function(url, params, loadOnce){
45090 if(!loadOnce || !this.loaded){
45091 var updater = this.el.getUpdateManager();
45092 updater.update(url, params, this._setLoaded.createDelegate(this));
45096 _setLoaded : function(){
45097 this.loaded = true;
45101 * Returns this panel's id
45104 getId : function(){
45109 * Returns this panel's element - used by regiosn to add.
45110 * @return {Roo.Element}
45112 getEl : function(){
45113 return this.wrapEl || this.el;
45116 adjustForComponents : function(width, height){
45117 if(this.resizeEl != this.el){
45118 width -= this.el.getFrameWidth('lr');
45119 height -= this.el.getFrameWidth('tb');
45122 var te = this.toolbar.getEl();
45123 height -= te.getHeight();
45124 te.setWidth(width);
45126 if(this.adjustments){
45127 width += this.adjustments[0];
45128 height += this.adjustments[1];
45130 return {"width": width, "height": height};
45133 setSize : function(width, height){
45134 if(this.fitToFrame && !this.ignoreResize(width, height)){
45135 if(this.fitContainer && this.resizeEl != this.el){
45136 this.el.setSize(width, height);
45138 var size = this.adjustForComponents(width, height);
45139 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
45140 this.fireEvent('resize', this, size.width, size.height);
45145 * Returns this panel's title
45148 getTitle : function(){
45153 * Set this panel's title
45154 * @param {String} title
45156 setTitle : function(title){
45157 this.title = title;
45159 this.region.updatePanelTitle(this, title);
45164 * Returns true is this panel was configured to be closable
45165 * @return {Boolean}
45167 isClosable : function(){
45168 return this.closable;
45171 beforeSlide : function(){
45173 this.resizeEl.clip();
45176 afterSlide : function(){
45178 this.resizeEl.unclip();
45182 * Force a content refresh from the URL specified in the {@link #setUrl} method.
45183 * Will fail silently if the {@link #setUrl} method has not been called.
45184 * This does not activate the panel, just updates its content.
45186 refresh : function(){
45187 if(this.refreshDelegate){
45188 this.loaded = false;
45189 this.refreshDelegate();
45194 * Destroys this panel
45196 destroy : function(){
45197 this.el.removeAllListeners();
45198 var tempEl = document.createElement("span");
45199 tempEl.appendChild(this.el.dom);
45200 tempEl.innerHTML = "";
45206 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
45216 * @param {Object} cfg Xtype definition of item to add.
45219 addxtype : function(cfg) {
45221 if (cfg.xtype.match(/^Form$/)) {
45222 var el = this.el.createChild();
45224 this.form = new Roo.form.Form(cfg);
45227 if ( this.form.allItems.length) this.form.render(el.dom);
45230 if (['View', 'JsonView'].indexOf(cfg.xtype) > -1) {
45232 cfg.el = this.el.appendChild(document.createElement("div"));
45234 var ret = new Roo[cfg.xtype](cfg);
45235 ret.render(false, ''); // render blank..
45245 * @class Roo.GridPanel
45246 * @extends Roo.ContentPanel
45248 * Create a new GridPanel.
45249 * @param {Roo.grid.Grid} grid The grid for this panel
45250 * @param {String/Object} config A string to set only the panel's title, or a config object
45252 Roo.GridPanel = function(grid, config){
45255 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
45256 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
45258 this.wrapper.dom.appendChild(grid.getGridEl().dom);
45260 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
45263 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
45265 // xtype created footer. - not sure if will work as we normally have to render first..
45266 if (this.footer && !this.footer.el && this.footer.xtype) {
45268 this.footer.container = this.grid.getView().getFooterPanel(true);
45269 this.footer.dataSource = this.grid.dataSource;
45270 this.footer = Roo.factory(this.footer, Roo);
45274 grid.monitorWindowResize = false; // turn off autosizing
45275 grid.autoHeight = false;
45276 grid.autoWidth = false;
45278 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
45281 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
45282 getId : function(){
45283 return this.grid.id;
45287 * Returns the grid for this panel
45288 * @return {Roo.grid.Grid}
45290 getGrid : function(){
45294 setSize : function(width, height){
45295 if(!this.ignoreResize(width, height)){
45296 var grid = this.grid;
45297 var size = this.adjustForComponents(width, height);
45298 grid.getGridEl().setSize(size.width, size.height);
45303 beforeSlide : function(){
45304 this.grid.getView().scroller.clip();
45307 afterSlide : function(){
45308 this.grid.getView().scroller.unclip();
45311 destroy : function(){
45312 this.grid.destroy();
45314 Roo.GridPanel.superclass.destroy.call(this);
45320 * @class Roo.NestedLayoutPanel
45321 * @extends Roo.ContentPanel
45323 * Create a new NestedLayoutPanel.
45326 * @param {Roo.BorderLayout} layout The layout for this panel
45327 * @param {String/Object} config A string to set only the title or a config object
45329 Roo.NestedLayoutPanel = function(layout, config)
45331 // construct with only one argument..
45332 /* FIXME - implement nicer consturctors
45333 if (layout.layout) {
45335 layout = config.layout;
45336 delete config.layout;
45338 if (layout.xtype && !layout.getEl) {
45339 // then layout needs constructing..
45340 layout = Roo.factory(layout, Roo);
45344 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
45346 layout.monitorWindowResize = false; // turn off autosizing
45347 this.layout = layout;
45348 this.layout.getEl().addClass("x-layout-nested-layout");
45354 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
45356 setSize : function(width, height){
45357 if(!this.ignoreResize(width, height)){
45358 var size = this.adjustForComponents(width, height);
45359 var el = this.layout.getEl();
45360 el.setSize(size.width, size.height);
45361 var touch = el.dom.offsetWidth;
45362 this.layout.layout();
45363 // ie requires a double layout on the first pass
45364 if(Roo.isIE && !this.initialized){
45365 this.initialized = true;
45366 this.layout.layout();
45371 // activate all subpanels if not currently active..
45373 setActiveState : function(active){
45374 this.active = active;
45376 this.fireEvent("deactivate", this);
45380 this.fireEvent("activate", this);
45381 // not sure if this should happen before or after..
45382 if (!this.layout) {
45383 return; // should not happen..
45386 for (var r in this.layout.regions) {
45387 reg = this.layout.getRegion(r);
45388 if (reg.getActivePanel()) {
45389 //reg.showPanel(reg.getActivePanel()); // force it to activate..
45390 reg.setActivePanel(reg.getActivePanel());
45393 if (!reg.panels.length) {
45396 reg.showPanel(reg.getPanel(0));
45405 * Returns the nested BorderLayout for this panel
45406 * @return {Roo.BorderLayout}
45408 getLayout : function(){
45409 return this.layout;
45413 * Adds a xtype elements to the layout of the nested panel
45417 xtype : 'ContentPanel',
45424 xtype : 'NestedLayoutPanel',
45430 items : [ ... list of content panels or nested layout panels.. ]
45434 * @param {Object} cfg Xtype definition of item to add.
45436 addxtype : function(cfg) {
45437 return this.layout.addxtype(cfg);
45442 Roo.ScrollPanel = function(el, config, content){
45443 config = config || {};
45444 config.fitToFrame = true;
45445 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
45447 this.el.dom.style.overflow = "hidden";
45448 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
45449 this.el.removeClass("x-layout-inactive-content");
45450 this.el.on("mousewheel", this.onWheel, this);
45452 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
45453 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
45454 up.unselectable(); down.unselectable();
45455 up.on("click", this.scrollUp, this);
45456 down.on("click", this.scrollDown, this);
45457 up.addClassOnOver("x-scroller-btn-over");
45458 down.addClassOnOver("x-scroller-btn-over");
45459 up.addClassOnClick("x-scroller-btn-click");
45460 down.addClassOnClick("x-scroller-btn-click");
45461 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
45463 this.resizeEl = this.el;
45464 this.el = wrap; this.up = up; this.down = down;
45467 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
45469 wheelIncrement : 5,
45470 scrollUp : function(){
45471 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
45474 scrollDown : function(){
45475 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
45478 afterScroll : function(){
45479 var el = this.resizeEl;
45480 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
45481 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
45482 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
45485 setSize : function(){
45486 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
45487 this.afterScroll();
45490 onWheel : function(e){
45491 var d = e.getWheelDelta();
45492 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
45493 this.afterScroll();
45497 setContent : function(content, loadScripts){
45498 this.resizeEl.update(content, loadScripts);
45512 * @class Roo.TreePanel
45513 * @extends Roo.ContentPanel
45515 * Create a new TreePanel. - defaults to fit/scoll contents.
45516 * @param {String/Object} config A string to set only the panel's title, or a config object
45517 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
45519 Roo.TreePanel = function(config){
45520 var el = config.el;
45521 var tree = config.tree;
45522 delete config.tree;
45523 delete config.el; // hopefull!
45525 // wrapper for IE7 strict & safari scroll issue
45527 var treeEl = el.createChild();
45528 config.resizeEl = treeEl;
45532 Roo.TreePanel.superclass.constructor.call(this, el, config);
45535 this.tree = new Roo.tree.TreePanel(treeEl , tree);
45536 //console.log(tree);
45537 this.on('activate', function()
45539 if (this.tree.rendered) {
45542 //console.log('render tree');
45543 this.tree.render();
45546 this.on('resize', function (cp, w, h) {
45547 this.tree.innerCt.setWidth(w);
45548 this.tree.innerCt.setHeight(h);
45549 this.tree.innerCt.setStyle('overflow-y', 'auto');
45556 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {
45573 * Ext JS Library 1.1.1
45574 * Copyright(c) 2006-2007, Ext JS, LLC.
45576 * Originally Released Under LGPL - original licence link has changed is not relivant.
45579 * <script type="text/javascript">
45584 * @class Roo.ReaderLayout
45585 * @extends Roo.BorderLayout
45586 * This is a pre-built layout that represents a classic, 5-pane application. It consists of a header, a primary
45587 * center region containing two nested regions (a top one for a list view and one for item preview below),
45588 * and regions on either side that can be used for navigation, application commands, informational displays, etc.
45589 * The setup and configuration work exactly the same as it does for a {@link Roo.BorderLayout} - this class simply
45590 * expedites the setup of the overall layout and regions for this common application style.
45593 var reader = new Roo.ReaderLayout();
45594 var CP = Roo.ContentPanel; // shortcut for adding
45596 reader.beginUpdate();
45597 reader.add("north", new CP("north", "North"));
45598 reader.add("west", new CP("west", {title: "West"}));
45599 reader.add("east", new CP("east", {title: "East"}));
45601 reader.regions.listView.add(new CP("listView", "List"));
45602 reader.regions.preview.add(new CP("preview", "Preview"));
45603 reader.endUpdate();
45606 * Create a new ReaderLayout
45607 * @param {Object} config Configuration options
45608 * @param {String/HTMLElement/Element} container (optional) The container this layout is bound to (defaults to
45609 * document.body if omitted)
45611 Roo.ReaderLayout = function(config, renderTo){
45612 var c = config || {size:{}};
45613 Roo.ReaderLayout.superclass.constructor.call(this, renderTo || document.body, {
45614 north: c.north !== false ? Roo.apply({
45618 }, c.north) : false,
45619 west: c.west !== false ? Roo.apply({
45627 margins:{left:5,right:0,bottom:5,top:5},
45628 cmargins:{left:5,right:5,bottom:5,top:5}
45629 }, c.west) : false,
45630 east: c.east !== false ? Roo.apply({
45638 margins:{left:0,right:5,bottom:5,top:5},
45639 cmargins:{left:5,right:5,bottom:5,top:5}
45640 }, c.east) : false,
45641 center: Roo.apply({
45642 tabPosition: 'top',
45646 margins:{left:c.west!==false ? 0 : 5,right:c.east!==false ? 0 : 5,bottom:5,top:2}
45650 this.el.addClass('x-reader');
45652 this.beginUpdate();
45654 var inner = new Roo.BorderLayout(Roo.get(document.body).createChild(), {
45655 south: c.preview !== false ? Roo.apply({
45662 cmargins:{top:5,left:0, right:0, bottom:0}
45663 }, c.preview) : false,
45664 center: Roo.apply({
45670 this.add('center', new Roo.NestedLayoutPanel(inner,
45671 Roo.apply({title: c.mainTitle || '',tabTip:''},c.innerPanelCfg)));
45675 this.regions.preview = inner.getRegion('south');
45676 this.regions.listView = inner.getRegion('center');
45679 Roo.extend(Roo.ReaderLayout, Roo.BorderLayout);/*
45681 * Ext JS Library 1.1.1
45682 * Copyright(c) 2006-2007, Ext JS, LLC.
45684 * Originally Released Under LGPL - original licence link has changed is not relivant.
45687 * <script type="text/javascript">
45691 * @class Roo.grid.Grid
45692 * @extends Roo.util.Observable
45693 * This class represents the primary interface of a component based grid control.
45694 * <br><br>Usage:<pre><code>
45695 var grid = new Roo.grid.Grid("my-container-id", {
45698 selModel: mySelectionModel,
45699 autoSizeColumns: true,
45700 monitorWindowResize: false,
45701 trackMouseOver: true
45706 * <b>Common Problems:</b><br/>
45707 * - Grid does not resize properly when going smaller: Setting overflow hidden on the container
45708 * element will correct this<br/>
45709 * - If you get el.style[camel]= NaNpx or -2px or something related, be certain you have given your container element
45710 * dimensions. The grid adapts to your container's size, if your container has no size defined then the results
45711 * are unpredictable.<br/>
45712 * - Do not render the grid into an element with display:none. Try using visibility:hidden. Otherwise there is no way for the
45713 * grid to calculate dimensions/offsets.<br/>
45715 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
45716 * The container MUST have some type of size defined for the grid to fill. The container will be
45717 * automatically set to position relative if it isn't already.
45718 * @param {Object} config A config object that sets properties on this grid.
45720 Roo.grid.Grid = function(container, config){
45721 // initialize the container
45722 this.container = Roo.get(container);
45723 this.container.update("");
45724 this.container.setStyle("overflow", "hidden");
45725 this.container.addClass('x-grid-container');
45727 this.id = this.container.id;
45729 Roo.apply(this, config);
45730 // check and correct shorthanded configs
45732 this.dataSource = this.ds;
45736 this.colModel = this.cm;
45740 this.selModel = this.sm;
45744 if (this.selModel) {
45745 this.selModel = Roo.factory(this.selModel, Roo.grid);
45746 this.sm = this.selModel;
45747 this.sm.xmodule = this.xmodule || false;
45749 if (typeof(this.colModel.config) == 'undefined') {
45750 this.colModel = new Roo.grid.ColumnModel(this.colModel);
45751 this.cm = this.colModel;
45752 this.cm.xmodule = this.xmodule || false;
45754 if (this.dataSource) {
45755 this.dataSource= Roo.factory(this.dataSource, Roo.data);
45756 this.ds = this.dataSource;
45757 this.ds.xmodule = this.xmodule || false;
45764 this.container.setWidth(this.width);
45768 this.container.setHeight(this.height);
45775 * The raw click event for the entire grid.
45776 * @param {Roo.EventObject} e
45781 * The raw dblclick event for the entire grid.
45782 * @param {Roo.EventObject} e
45786 * @event contextmenu
45787 * The raw contextmenu event for the entire grid.
45788 * @param {Roo.EventObject} e
45790 "contextmenu" : true,
45793 * The raw mousedown event for the entire grid.
45794 * @param {Roo.EventObject} e
45796 "mousedown" : true,
45799 * The raw mouseup event for the entire grid.
45800 * @param {Roo.EventObject} e
45805 * The raw mouseover event for the entire grid.
45806 * @param {Roo.EventObject} e
45808 "mouseover" : true,
45811 * The raw mouseout event for the entire grid.
45812 * @param {Roo.EventObject} e
45817 * The raw keypress event for the entire grid.
45818 * @param {Roo.EventObject} e
45823 * The raw keydown event for the entire grid.
45824 * @param {Roo.EventObject} e
45832 * Fires when a cell is clicked
45833 * @param {Grid} this
45834 * @param {Number} rowIndex
45835 * @param {Number} columnIndex
45836 * @param {Roo.EventObject} e
45838 "cellclick" : true,
45840 * @event celldblclick
45841 * Fires when a cell is double clicked
45842 * @param {Grid} this
45843 * @param {Number} rowIndex
45844 * @param {Number} columnIndex
45845 * @param {Roo.EventObject} e
45847 "celldblclick" : true,
45850 * Fires when a row is clicked
45851 * @param {Grid} this
45852 * @param {Number} rowIndex
45853 * @param {Roo.EventObject} e
45857 * @event rowdblclick
45858 * Fires when a row is double clicked
45859 * @param {Grid} this
45860 * @param {Number} rowIndex
45861 * @param {Roo.EventObject} e
45863 "rowdblclick" : true,
45865 * @event headerclick
45866 * Fires when a header is clicked
45867 * @param {Grid} this
45868 * @param {Number} columnIndex
45869 * @param {Roo.EventObject} e
45871 "headerclick" : true,
45873 * @event headerdblclick
45874 * Fires when a header cell is double clicked
45875 * @param {Grid} this
45876 * @param {Number} columnIndex
45877 * @param {Roo.EventObject} e
45879 "headerdblclick" : true,
45881 * @event rowcontextmenu
45882 * Fires when a row is right clicked
45883 * @param {Grid} this
45884 * @param {Number} rowIndex
45885 * @param {Roo.EventObject} e
45887 "rowcontextmenu" : true,
45889 * @event cellcontextmenu
45890 * Fires when a cell is right clicked
45891 * @param {Grid} this
45892 * @param {Number} rowIndex
45893 * @param {Number} cellIndex
45894 * @param {Roo.EventObject} e
45896 "cellcontextmenu" : true,
45898 * @event headercontextmenu
45899 * Fires when a header is right clicked
45900 * @param {Grid} this
45901 * @param {Number} columnIndex
45902 * @param {Roo.EventObject} e
45904 "headercontextmenu" : true,
45906 * @event bodyscroll
45907 * Fires when the body element is scrolled
45908 * @param {Number} scrollLeft
45909 * @param {Number} scrollTop
45911 "bodyscroll" : true,
45913 * @event columnresize
45914 * Fires when the user resizes a column
45915 * @param {Number} columnIndex
45916 * @param {Number} newSize
45918 "columnresize" : true,
45920 * @event columnmove
45921 * Fires when the user moves a column
45922 * @param {Number} oldIndex
45923 * @param {Number} newIndex
45925 "columnmove" : true,
45928 * Fires when row(s) start being dragged
45929 * @param {Grid} this
45930 * @param {Roo.GridDD} dd The drag drop object
45931 * @param {event} e The raw browser event
45933 "startdrag" : true,
45936 * Fires when a drag operation is complete
45937 * @param {Grid} this
45938 * @param {Roo.GridDD} dd The drag drop object
45939 * @param {event} e The raw browser event
45944 * Fires when dragged row(s) are dropped on a valid DD target
45945 * @param {Grid} this
45946 * @param {Roo.GridDD} dd The drag drop object
45947 * @param {String} targetId The target drag drop object
45948 * @param {event} e The raw browser event
45953 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
45954 * @param {Grid} this
45955 * @param {Roo.GridDD} dd The drag drop object
45956 * @param {String} targetId The target drag drop object
45957 * @param {event} e The raw browser event
45962 * Fires when the dragged row(s) first cross another DD target while being dragged
45963 * @param {Grid} this
45964 * @param {Roo.GridDD} dd The drag drop object
45965 * @param {String} targetId The target drag drop object
45966 * @param {event} e The raw browser event
45968 "dragenter" : true,
45971 * Fires when the dragged row(s) leave another DD target while being dragged
45972 * @param {Grid} this
45973 * @param {Roo.GridDD} dd The drag drop object
45974 * @param {String} targetId The target drag drop object
45975 * @param {event} e The raw browser event
45980 * Fires when the grid is rendered
45981 * @param {Grid} grid
45986 Roo.grid.Grid.superclass.constructor.call(this);
45988 Roo.extend(Roo.grid.Grid, Roo.util.Observable, {
45991 * @cfg {String} ddGroup - drag drop group.
45995 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Default is 25.
45997 minColumnWidth : 25,
46000 * @cfg {Boolean} autoSizeColumns True to automatically resize the columns to fit their content
46001 * <b>on initial render.</b> It is more efficient to explicitly size the columns
46002 * through the ColumnModel's {@link Roo.grid.ColumnModel#width} config option. Default is false.
46004 autoSizeColumns : false,
46007 * @cfg {Boolean} autoSizeHeaders True to measure headers with column data when auto sizing columns. Default is true.
46009 autoSizeHeaders : true,
46012 * @cfg {Boolean} monitorWindowResize True to autoSize the grid when the window resizes. Default is true.
46014 monitorWindowResize : true,
46017 * @cfg {Boolean} maxRowsToMeasure If autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of
46018 * rows measured to get a columns size. Default is 0 (all rows).
46020 maxRowsToMeasure : 0,
46023 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is true.
46025 trackMouseOver : true,
46028 * @cfg {Boolean} enableDrag True to enable drag of rows. Default is false. (double check if this is needed?)
46032 * @cfg {Boolean} enableDragDrop True to enable drag and drop of rows. Default is false.
46034 enableDragDrop : false,
46037 * @cfg {Boolean} enableColumnMove True to enable drag and drop reorder of columns. Default is true.
46039 enableColumnMove : true,
46042 * @cfg {Boolean} enableColumnHide True to enable hiding of columns with the header context menu. Default is true.
46044 enableColumnHide : true,
46047 * @cfg {Boolean} enableRowHeightSync True to manually sync row heights across locked and not locked rows. Default is false.
46049 enableRowHeightSync : false,
46052 * @cfg {Boolean} stripeRows True to stripe the rows. Default is true.
46057 * @cfg {Boolean} autoHeight True to fit the height of the grid container to the height of the data. Default is false.
46059 autoHeight : false,
46062 * @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.
46064 autoExpandColumn : false,
46067 * @cfg {Number} autoExpandMin The minimum width the autoExpandColumn can have (if enabled).
46070 autoExpandMin : 50,
46073 * @cfg {Number} autoExpandMax The maximum width the autoExpandColumn can have (if enabled). Default is 1000.
46075 autoExpandMax : 1000,
46078 * @cfg {Object} view The {@link Roo.grid.GridView} used by the grid. This can be set before a call to render().
46083 * @cfg {Object} loadMask An {@link Roo.LoadMask} config or true to mask the grid while loading. Default is false.
46091 * @cfg {Boolean} autoWidth True to set the grid's width to the default total width of the grid's columns instead
46092 * of a fixed width. Default is false.
46095 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if autoHeight is not on.
46098 * Called once after all setup has been completed and the grid is ready to be rendered.
46099 * @return {Roo.grid.Grid} this
46101 render : function(){
46102 var c = this.container;
46103 // try to detect autoHeight/width mode
46104 if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
46105 this.autoHeight = true;
46107 var view = this.getView();
46110 c.on("click", this.onClick, this);
46111 c.on("dblclick", this.onDblClick, this);
46112 c.on("contextmenu", this.onContextMenu, this);
46113 c.on("keydown", this.onKeyDown, this);
46115 this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
46117 this.getSelectionModel().init(this);
46122 this.loadMask = new Roo.LoadMask(this.container,
46123 Roo.apply({store:this.dataSource}, this.loadMask));
46127 if (this.toolbar && this.toolbar.xtype) {
46128 this.toolbar.container = this.getView().getHeaderPanel(true);
46129 this.toolbar = new Ext.Toolbar(this.toolbar);
46131 if (this.footer && this.footer.xtype) {
46132 this.footer.dataSource = this.getDataSource();
46133 this.footer.container = this.getView().getFooterPanel(true);
46134 this.footer = Roo.factory(this.footer, Roo);
46136 this.rendered = true;
46137 this.fireEvent('render', this);
46142 * Reconfigures the grid to use a different Store and Column Model.
46143 * The View will be bound to the new objects and refreshed.
46144 * @param {Roo.data.Store} dataSource The new {@link Roo.data.Store} object
46145 * @param {Roo.grid.ColumnModel} The new {@link Roo.grid.ColumnModel} object
46147 reconfigure : function(dataSource, colModel){
46149 this.loadMask.destroy();
46150 this.loadMask = new Roo.LoadMask(this.container,
46151 Roo.apply({store:dataSource}, this.loadMask));
46153 this.view.bind(dataSource, colModel);
46154 this.dataSource = dataSource;
46155 this.colModel = colModel;
46156 this.view.refresh(true);
46160 onKeyDown : function(e){
46161 this.fireEvent("keydown", e);
46165 * Destroy this grid.
46166 * @param {Boolean} removeEl True to remove the element
46168 destroy : function(removeEl, keepListeners){
46170 this.loadMask.destroy();
46172 var c = this.container;
46173 c.removeAllListeners();
46174 this.view.destroy();
46175 this.colModel.purgeListeners();
46176 if(!keepListeners){
46177 this.purgeListeners();
46180 if(removeEl === true){
46186 processEvent : function(name, e){
46187 this.fireEvent(name, e);
46188 var t = e.getTarget();
46190 var header = v.findHeaderIndex(t);
46191 if(header !== false){
46192 this.fireEvent("header" + name, this, header, e);
46194 var row = v.findRowIndex(t);
46195 var cell = v.findCellIndex(t);
46197 this.fireEvent("row" + name, this, row, e);
46198 if(cell !== false){
46199 this.fireEvent("cell" + name, this, row, cell, e);
46206 onClick : function(e){
46207 this.processEvent("click", e);
46211 onContextMenu : function(e, t){
46212 this.processEvent("contextmenu", e);
46216 onDblClick : function(e){
46217 this.processEvent("dblclick", e);
46221 walkCells : function(row, col, step, fn, scope){
46222 var cm = this.colModel, clen = cm.getColumnCount();
46223 var ds = this.dataSource, rlen = ds.getCount(), first = true;
46235 if(fn.call(scope || this, row, col, cm) === true){
46253 if(fn.call(scope || this, row, col, cm) === true){
46265 getSelections : function(){
46266 return this.selModel.getSelections();
46270 * Causes the grid to manually recalculate its dimensions. Generally this is done automatically,
46271 * but if manual update is required this method will initiate it.
46273 autoSize : function(){
46275 this.view.layout();
46276 if(this.view.adjustForScroll){
46277 this.view.adjustForScroll();
46283 * Returns the grid's underlying element.
46284 * @return {Element} The element
46286 getGridEl : function(){
46287 return this.container;
46290 // private for compatibility, overridden by editor grid
46291 stopEditing : function(){},
46294 * Returns the grid's SelectionModel.
46295 * @return {SelectionModel}
46297 getSelectionModel : function(){
46298 if(!this.selModel){
46299 this.selModel = new Roo.grid.RowSelectionModel();
46301 return this.selModel;
46305 * Returns the grid's DataSource.
46306 * @return {DataSource}
46308 getDataSource : function(){
46309 return this.dataSource;
46313 * Returns the grid's ColumnModel.
46314 * @return {ColumnModel}
46316 getColumnModel : function(){
46317 return this.colModel;
46321 * Returns the grid's GridView object.
46322 * @return {GridView}
46324 getView : function(){
46326 this.view = new Roo.grid.GridView(this.viewConfig);
46331 * Called to get grid's drag proxy text, by default returns this.ddText.
46334 getDragDropText : function(){
46335 var count = this.selModel.getCount();
46336 return String.format(this.ddText, count, count == 1 ? '' : 's');
46340 * Configures the text is the drag proxy (defaults to "%0 selected row(s)").
46341 * %0 is replaced with the number of selected rows.
46344 Roo.grid.Grid.prototype.ddText = "{0} selected row{1}";/*
46346 * Ext JS Library 1.1.1
46347 * Copyright(c) 2006-2007, Ext JS, LLC.
46349 * Originally Released Under LGPL - original licence link has changed is not relivant.
46352 * <script type="text/javascript">
46355 Roo.grid.AbstractGridView = function(){
46359 "beforerowremoved" : true,
46360 "beforerowsinserted" : true,
46361 "beforerefresh" : true,
46362 "rowremoved" : true,
46363 "rowsinserted" : true,
46364 "rowupdated" : true,
46367 Roo.grid.AbstractGridView.superclass.constructor.call(this);
46370 Roo.extend(Roo.grid.AbstractGridView, Roo.util.Observable, {
46371 rowClass : "x-grid-row",
46372 cellClass : "x-grid-cell",
46373 tdClass : "x-grid-td",
46374 hdClass : "x-grid-hd",
46375 splitClass : "x-grid-hd-split",
46377 init: function(grid){
46379 var cid = this.grid.getGridEl().id;
46380 this.colSelector = "#" + cid + " ." + this.cellClass + "-";
46381 this.tdSelector = "#" + cid + " ." + this.tdClass + "-";
46382 this.hdSelector = "#" + cid + " ." + this.hdClass + "-";
46383 this.splitSelector = "#" + cid + " ." + this.splitClass + "-";
46386 getColumnRenderers : function(){
46387 var renderers = [];
46388 var cm = this.grid.colModel;
46389 var colCount = cm.getColumnCount();
46390 for(var i = 0; i < colCount; i++){
46391 renderers[i] = cm.getRenderer(i);
46396 getColumnIds : function(){
46398 var cm = this.grid.colModel;
46399 var colCount = cm.getColumnCount();
46400 for(var i = 0; i < colCount; i++){
46401 ids[i] = cm.getColumnId(i);
46406 getDataIndexes : function(){
46407 if(!this.indexMap){
46408 this.indexMap = this.buildIndexMap();
46410 return this.indexMap.colToData;
46413 getColumnIndexByDataIndex : function(dataIndex){
46414 if(!this.indexMap){
46415 this.indexMap = this.buildIndexMap();
46417 return this.indexMap.dataToCol[dataIndex];
46421 * Set a css style for a column dynamically.
46422 * @param {Number} colIndex The index of the column
46423 * @param {String} name The css property name
46424 * @param {String} value The css value
46426 setCSSStyle : function(colIndex, name, value){
46427 var selector = "#" + this.grid.id + " .x-grid-col-" + colIndex;
46428 Roo.util.CSS.updateRule(selector, name, value);
46431 generateRules : function(cm){
46432 var ruleBuf = [], rulesId = this.grid.id + '-cssrules';
46433 Roo.util.CSS.removeStyleSheet(rulesId);
46434 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
46435 var cid = cm.getColumnId(i);
46436 ruleBuf.push(this.colSelector, cid, " {\n", cm.config[i].css, "}\n",
46437 this.tdSelector, cid, " {\n}\n",
46438 this.hdSelector, cid, " {\n}\n",
46439 this.splitSelector, cid, " {\n}\n");
46441 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
46445 * Ext JS Library 1.1.1
46446 * Copyright(c) 2006-2007, Ext JS, LLC.
46448 * Originally Released Under LGPL - original licence link has changed is not relivant.
46451 * <script type="text/javascript">
46455 // This is a support class used internally by the Grid components
46456 Roo.grid.HeaderDragZone = function(grid, hd, hd2){
46458 this.view = grid.getView();
46459 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
46460 Roo.grid.HeaderDragZone.superclass.constructor.call(this, hd);
46462 this.setHandleElId(Roo.id(hd));
46463 this.setOuterHandleElId(Roo.id(hd2));
46465 this.scroll = false;
46467 Roo.extend(Roo.grid.HeaderDragZone, Roo.dd.DragZone, {
46469 getDragData : function(e){
46470 var t = Roo.lib.Event.getTarget(e);
46471 var h = this.view.findHeaderCell(t);
46473 return {ddel: h.firstChild, header:h};
46478 onInitDrag : function(e){
46479 this.view.headersDisabled = true;
46480 var clone = this.dragData.ddel.cloneNode(true);
46481 clone.id = Roo.id();
46482 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
46483 this.proxy.update(clone);
46487 afterValidDrop : function(){
46489 setTimeout(function(){
46490 v.headersDisabled = false;
46494 afterInvalidDrop : function(){
46496 setTimeout(function(){
46497 v.headersDisabled = false;
46503 * Ext JS Library 1.1.1
46504 * Copyright(c) 2006-2007, Ext JS, LLC.
46506 * Originally Released Under LGPL - original licence link has changed is not relivant.
46509 * <script type="text/javascript">
46512 // This is a support class used internally by the Grid components
46513 Roo.grid.HeaderDropZone = function(grid, hd, hd2){
46515 this.view = grid.getView();
46516 // split the proxies so they don't interfere with mouse events
46517 this.proxyTop = Roo.DomHelper.append(document.body, {
46518 cls:"col-move-top", html:" "
46520 this.proxyBottom = Roo.DomHelper.append(document.body, {
46521 cls:"col-move-bottom", html:" "
46523 this.proxyTop.hide = this.proxyBottom.hide = function(){
46524 this.setLeftTop(-100,-100);
46525 this.setStyle("visibility", "hidden");
46527 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
46528 // temporarily disabled
46529 //Roo.dd.ScrollManager.register(this.view.scroller.dom);
46530 Roo.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
46532 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
46533 proxyOffsets : [-4, -9],
46534 fly: Roo.Element.fly,
46536 getTargetFromEvent : function(e){
46537 var t = Roo.lib.Event.getTarget(e);
46538 var cindex = this.view.findCellIndex(t);
46539 if(cindex !== false){
46540 return this.view.getHeaderCell(cindex);
46544 nextVisible : function(h){
46545 var v = this.view, cm = this.grid.colModel;
46548 if(!cm.isHidden(v.getCellIndex(h))){
46556 prevVisible : function(h){
46557 var v = this.view, cm = this.grid.colModel;
46560 if(!cm.isHidden(v.getCellIndex(h))){
46568 positionIndicator : function(h, n, e){
46569 var x = Roo.lib.Event.getPageX(e);
46570 var r = Roo.lib.Dom.getRegion(n.firstChild);
46571 var px, pt, py = r.top + this.proxyOffsets[1];
46572 if((r.right - x) <= (r.right-r.left)/2){
46573 px = r.right+this.view.borderWidth;
46579 var oldIndex = this.view.getCellIndex(h);
46580 var newIndex = this.view.getCellIndex(n);
46582 if(this.grid.colModel.isFixed(newIndex)){
46586 var locked = this.grid.colModel.isLocked(newIndex);
46591 if(oldIndex < newIndex){
46594 if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){
46597 px += this.proxyOffsets[0];
46598 this.proxyTop.setLeftTop(px, py);
46599 this.proxyTop.show();
46600 if(!this.bottomOffset){
46601 this.bottomOffset = this.view.mainHd.getHeight();
46603 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
46604 this.proxyBottom.show();
46608 onNodeEnter : function(n, dd, e, data){
46609 if(data.header != n){
46610 this.positionIndicator(data.header, n, e);
46614 onNodeOver : function(n, dd, e, data){
46615 var result = false;
46616 if(data.header != n){
46617 result = this.positionIndicator(data.header, n, e);
46620 this.proxyTop.hide();
46621 this.proxyBottom.hide();
46623 return result ? this.dropAllowed : this.dropNotAllowed;
46626 onNodeOut : function(n, dd, e, data){
46627 this.proxyTop.hide();
46628 this.proxyBottom.hide();
46631 onNodeDrop : function(n, dd, e, data){
46632 var h = data.header;
46634 var cm = this.grid.colModel;
46635 var x = Roo.lib.Event.getPageX(e);
46636 var r = Roo.lib.Dom.getRegion(n.firstChild);
46637 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
46638 var oldIndex = this.view.getCellIndex(h);
46639 var newIndex = this.view.getCellIndex(n);
46640 var locked = cm.isLocked(newIndex);
46644 if(oldIndex < newIndex){
46647 if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){
46650 cm.setLocked(oldIndex, locked, true);
46651 cm.moveColumn(oldIndex, newIndex);
46652 this.grid.fireEvent("columnmove", oldIndex, newIndex);
46660 * Ext JS Library 1.1.1
46661 * Copyright(c) 2006-2007, Ext JS, LLC.
46663 * Originally Released Under LGPL - original licence link has changed is not relivant.
46666 * <script type="text/javascript">
46670 * @class Roo.grid.GridView
46671 * @extends Roo.util.Observable
46674 * @param {Object} config
46676 Roo.grid.GridView = function(config){
46677 Roo.grid.GridView.superclass.constructor.call(this);
46680 Roo.apply(this, config);
46683 Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
46686 * Override this function to apply custom css classes to rows during rendering
46687 * @param {Record} record The record
46688 * @param {Number} index
46689 * @method getRowClass
46691 rowClass : "x-grid-row",
46693 cellClass : "x-grid-col",
46695 tdClass : "x-grid-td",
46697 hdClass : "x-grid-hd",
46699 splitClass : "x-grid-split",
46701 sortClasses : ["sort-asc", "sort-desc"],
46703 enableMoveAnim : false,
46707 dh : Roo.DomHelper,
46709 fly : Roo.Element.fly,
46711 css : Roo.util.CSS,
46717 scrollIncrement : 22,
46719 cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
46721 findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
46723 bind : function(ds, cm){
46725 this.ds.un("load", this.onLoad, this);
46726 this.ds.un("datachanged", this.onDataChange, this);
46727 this.ds.un("add", this.onAdd, this);
46728 this.ds.un("remove", this.onRemove, this);
46729 this.ds.un("update", this.onUpdate, this);
46730 this.ds.un("clear", this.onClear, this);
46733 ds.on("load", this.onLoad, this);
46734 ds.on("datachanged", this.onDataChange, this);
46735 ds.on("add", this.onAdd, this);
46736 ds.on("remove", this.onRemove, this);
46737 ds.on("update", this.onUpdate, this);
46738 ds.on("clear", this.onClear, this);
46743 this.cm.un("widthchange", this.onColWidthChange, this);
46744 this.cm.un("headerchange", this.onHeaderChange, this);
46745 this.cm.un("hiddenchange", this.onHiddenChange, this);
46746 this.cm.un("columnmoved", this.onColumnMove, this);
46747 this.cm.un("columnlockchange", this.onColumnLock, this);
46750 this.generateRules(cm);
46751 cm.on("widthchange", this.onColWidthChange, this);
46752 cm.on("headerchange", this.onHeaderChange, this);
46753 cm.on("hiddenchange", this.onHiddenChange, this);
46754 cm.on("columnmoved", this.onColumnMove, this);
46755 cm.on("columnlockchange", this.onColumnLock, this);
46760 init: function(grid){
46761 Roo.grid.GridView.superclass.init.call(this, grid);
46763 this.bind(grid.dataSource, grid.colModel);
46765 grid.on("headerclick", this.handleHeaderClick, this);
46767 if(grid.trackMouseOver){
46768 grid.on("mouseover", this.onRowOver, this);
46769 grid.on("mouseout", this.onRowOut, this);
46771 grid.cancelTextSelection = function(){};
46772 this.gridId = grid.id;
46774 var tpls = this.templates || {};
46777 tpls.master = new Roo.Template(
46778 '<div class="x-grid" hidefocus="true">',
46779 '<div class="x-grid-topbar"></div>',
46780 '<div class="x-grid-scroller"><div></div></div>',
46781 '<div class="x-grid-locked">',
46782 '<div class="x-grid-header">{lockedHeader}</div>',
46783 '<div class="x-grid-body">{lockedBody}</div>',
46785 '<div class="x-grid-viewport">',
46786 '<div class="x-grid-header">{header}</div>',
46787 '<div class="x-grid-body">{body}</div>',
46789 '<div class="x-grid-bottombar"></div>',
46790 '<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
46791 '<div class="x-grid-resize-proxy"> </div>',
46794 tpls.master.disableformats = true;
46798 tpls.header = new Roo.Template(
46799 '<table border="0" cellspacing="0" cellpadding="0">',
46800 '<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
46803 tpls.header.disableformats = true;
46805 tpls.header.compile();
46808 tpls.hcell = new Roo.Template(
46809 '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
46810 '<div class="x-grid-hd-text" unselectable="on">{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
46813 tpls.hcell.disableFormats = true;
46815 tpls.hcell.compile();
46818 tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style}" unselectable="on"> </div>');
46819 tpls.hsplit.disableFormats = true;
46821 tpls.hsplit.compile();
46824 tpls.body = new Roo.Template(
46825 '<table border="0" cellspacing="0" cellpadding="0">',
46826 "<tbody>{rows}</tbody>",
46829 tpls.body.disableFormats = true;
46831 tpls.body.compile();
46834 tpls.row = new Roo.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
46835 tpls.row.disableFormats = true;
46837 tpls.row.compile();
46840 tpls.cell = new Roo.Template(
46841 '<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
46842 '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text" unselectable="on" {attr}>{value}</div></div>',
46845 tpls.cell.disableFormats = true;
46847 tpls.cell.compile();
46849 this.templates = tpls;
46852 // remap these for backwards compat
46853 onColWidthChange : function(){
46854 this.updateColumns.apply(this, arguments);
46856 onHeaderChange : function(){
46857 this.updateHeaders.apply(this, arguments);
46859 onHiddenChange : function(){
46860 this.handleHiddenChange.apply(this, arguments);
46862 onColumnMove : function(){
46863 this.handleColumnMove.apply(this, arguments);
46865 onColumnLock : function(){
46866 this.handleLockChange.apply(this, arguments);
46869 onDataChange : function(){
46871 this.updateHeaderSortState();
46874 onClear : function(){
46878 onUpdate : function(ds, record){
46879 this.refreshRow(record);
46882 refreshRow : function(record){
46883 var ds = this.ds, index;
46884 if(typeof record == 'number'){
46886 record = ds.getAt(index);
46888 index = ds.indexOf(record);
46890 this.insertRows(ds, index, index, true);
46891 this.onRemove(ds, record, index+1, true);
46892 this.syncRowHeights(index, index);
46894 this.fireEvent("rowupdated", this, index, record);
46897 onAdd : function(ds, records, index){
46898 this.insertRows(ds, index, index + (records.length-1));
46901 onRemove : function(ds, record, index, isUpdate){
46902 if(isUpdate !== true){
46903 this.fireEvent("beforerowremoved", this, index, record);
46905 var bt = this.getBodyTable(), lt = this.getLockedTable();
46906 if(bt.rows[index]){
46907 bt.firstChild.removeChild(bt.rows[index]);
46909 if(lt.rows[index]){
46910 lt.firstChild.removeChild(lt.rows[index]);
46912 if(isUpdate !== true){
46913 this.stripeRows(index);
46914 this.syncRowHeights(index, index);
46916 this.fireEvent("rowremoved", this, index, record);
46920 onLoad : function(){
46921 this.scrollToTop();
46925 * Scrolls the grid to the top
46927 scrollToTop : function(){
46929 this.scroller.dom.scrollTop = 0;
46935 * Gets a panel in the header of the grid that can be used for toolbars etc.
46936 * After modifying the contents of this panel a call to grid.autoSize() may be
46937 * required to register any changes in size.
46938 * @param {Boolean} doShow By default the header is hidden. Pass true to show the panel
46939 * @return Roo.Element
46941 getHeaderPanel : function(doShow){
46943 this.headerPanel.show();
46945 return this.headerPanel;
46949 * Gets a panel in the footer of the grid that can be used for toolbars etc.
46950 * After modifying the contents of this panel a call to grid.autoSize() may be
46951 * required to register any changes in size.
46952 * @param {Boolean} doShow By default the footer is hidden. Pass true to show the panel
46953 * @return Roo.Element
46955 getFooterPanel : function(doShow){
46957 this.footerPanel.show();
46959 return this.footerPanel;
46962 initElements : function(){
46963 var E = Roo.Element;
46964 var el = this.grid.getGridEl().dom.firstChild;
46965 var cs = el.childNodes;
46967 this.el = new E(el);
46968 this.headerPanel = new E(el.firstChild);
46969 this.headerPanel.enableDisplayMode("block");
46971 this.scroller = new E(cs[1]);
46972 this.scrollSizer = new E(this.scroller.dom.firstChild);
46974 this.lockedWrap = new E(cs[2]);
46975 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
46976 this.lockedBody = new E(this.lockedWrap.dom.childNodes[1]);
46978 this.mainWrap = new E(cs[3]);
46979 this.mainHd = new E(this.mainWrap.dom.firstChild);
46980 this.mainBody = new E(this.mainWrap.dom.childNodes[1]);
46982 this.footerPanel = new E(cs[4]);
46983 this.footerPanel.enableDisplayMode("block");
46985 this.focusEl = new E(cs[5]);
46986 this.focusEl.swallowEvent("click", true);
46987 this.resizeProxy = new E(cs[6]);
46989 this.headerSelector = String.format(
46990 '#{0} td.x-grid-hd, #{1} td.x-grid-hd',
46991 this.lockedHd.id, this.mainHd.id
46994 this.splitterSelector = String.format(
46995 '#{0} div.x-grid-split, #{1} div.x-grid-split',
46996 this.idToCssName(this.lockedHd.id), this.idToCssName(this.mainHd.id)
46999 idToCssName : function(s)
47001 return s.replace(/[^a-z0-9]+/ig, '-');
47004 getHeaderCell : function(index){
47005 return Roo.DomQuery.select(this.headerSelector)[index];
47008 getHeaderCellMeasure : function(index){
47009 return this.getHeaderCell(index).firstChild;
47012 getHeaderCellText : function(index){
47013 return this.getHeaderCell(index).firstChild.firstChild;
47016 getLockedTable : function(){
47017 return this.lockedBody.dom.firstChild;
47020 getBodyTable : function(){
47021 return this.mainBody.dom.firstChild;
47024 getLockedRow : function(index){
47025 return this.getLockedTable().rows[index];
47028 getRow : function(index){
47029 return this.getBodyTable().rows[index];
47032 getRowComposite : function(index){
47034 this.rowEl = new Roo.CompositeElementLite();
47036 var els = [], lrow, mrow;
47037 if(lrow = this.getLockedRow(index)){
47040 if(mrow = this.getRow(index)){
47043 this.rowEl.elements = els;
47047 getCell : function(rowIndex, colIndex){
47048 var locked = this.cm.getLockedCount();
47050 if(colIndex < locked){
47051 source = this.lockedBody.dom.firstChild;
47053 source = this.mainBody.dom.firstChild;
47054 colIndex -= locked;
47056 return source.rows[rowIndex].childNodes[colIndex];
47059 getCellText : function(rowIndex, colIndex){
47060 return this.getCell(rowIndex, colIndex).firstChild.firstChild;
47063 getCellBox : function(cell){
47064 var b = this.fly(cell).getBox();
47065 if(Roo.isOpera){ // opera fails to report the Y
47066 b.y = cell.offsetTop + this.mainBody.getY();
47071 getCellIndex : function(cell){
47072 var id = String(cell.className).match(this.cellRE);
47074 return parseInt(id[1], 10);
47079 findHeaderIndex : function(n){
47080 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
47081 return r ? this.getCellIndex(r) : false;
47084 findHeaderCell : function(n){
47085 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
47086 return r ? r : false;
47089 findRowIndex : function(n){
47093 var r = Roo.fly(n).findParent("tr." + this.rowClass, 6);
47094 return r ? r.rowIndex : false;
47097 findCellIndex : function(node){
47098 var stop = this.el.dom;
47099 while(node && node != stop){
47100 if(this.findRE.test(node.className)){
47101 return this.getCellIndex(node);
47103 node = node.parentNode;
47108 getColumnId : function(index){
47109 return this.cm.getColumnId(index);
47112 getSplitters : function(){
47113 if(this.splitterSelector){
47114 return Roo.DomQuery.select(this.splitterSelector);
47120 getSplitter : function(index){
47121 return this.getSplitters()[index];
47124 onRowOver : function(e, t){
47126 if((row = this.findRowIndex(t)) !== false){
47127 this.getRowComposite(row).addClass("x-grid-row-over");
47131 onRowOut : function(e, t){
47133 if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){
47134 this.getRowComposite(row).removeClass("x-grid-row-over");
47138 renderHeaders : function(){
47140 var ct = this.templates.hcell, ht = this.templates.header, st = this.templates.hsplit;
47141 var cb = [], lb = [], sb = [], lsb = [], p = {};
47142 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
47143 p.cellId = "x-grid-hd-0-" + i;
47144 p.splitId = "x-grid-csplit-0-" + i;
47145 p.id = cm.getColumnId(i);
47146 p.title = cm.getColumnTooltip(i) || "";
47147 p.value = cm.getColumnHeader(i) || "";
47148 p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
47149 if(!cm.isLocked(i)){
47150 cb[cb.length] = ct.apply(p);
47151 sb[sb.length] = st.apply(p);
47153 lb[lb.length] = ct.apply(p);
47154 lsb[lsb.length] = st.apply(p);
47157 return [ht.apply({cells: lb.join(""), splits:lsb.join("")}),
47158 ht.apply({cells: cb.join(""), splits:sb.join("")})];
47161 updateHeaders : function(){
47162 var html = this.renderHeaders();
47163 this.lockedHd.update(html[0]);
47164 this.mainHd.update(html[1]);
47168 * Focuses the specified row.
47169 * @param {Number} row The row index
47171 focusRow : function(row){
47172 var x = this.scroller.dom.scrollLeft;
47173 this.focusCell(row, 0, false);
47174 this.scroller.dom.scrollLeft = x;
47178 * Focuses the specified cell.
47179 * @param {Number} row The row index
47180 * @param {Number} col The column index
47181 * @param {Boolean} hscroll false to disable horizontal scrolling
47183 focusCell : function(row, col, hscroll){
47184 var el = this.ensureVisible(row, col, hscroll);
47185 this.focusEl.alignTo(el, "tl-tl");
47187 this.focusEl.focus();
47189 this.focusEl.focus.defer(1, this.focusEl);
47194 * Scrolls the specified cell into view
47195 * @param {Number} row The row index
47196 * @param {Number} col The column index
47197 * @param {Boolean} hscroll false to disable horizontal scrolling
47199 ensureVisible : function(row, col, hscroll){
47200 if(typeof row != "number"){
47201 row = row.rowIndex;
47203 if(row < 0 && row >= this.ds.getCount()){
47206 col = (col !== undefined ? col : 0);
47207 var cm = this.grid.colModel;
47208 while(cm.isHidden(col)){
47212 var el = this.getCell(row, col);
47216 var c = this.scroller.dom;
47218 var ctop = parseInt(el.offsetTop, 10);
47219 var cleft = parseInt(el.offsetLeft, 10);
47220 var cbot = ctop + el.offsetHeight;
47221 var cright = cleft + el.offsetWidth;
47223 var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
47224 var stop = parseInt(c.scrollTop, 10);
47225 var sleft = parseInt(c.scrollLeft, 10);
47226 var sbot = stop + ch;
47227 var sright = sleft + c.clientWidth;
47230 c.scrollTop = ctop;
47231 }else if(cbot > sbot){
47232 c.scrollTop = cbot-ch;
47235 if(hscroll !== false){
47237 c.scrollLeft = cleft;
47238 }else if(cright > sright){
47239 c.scrollLeft = cright-c.clientWidth;
47245 updateColumns : function(){
47246 this.grid.stopEditing();
47247 var cm = this.grid.colModel, colIds = this.getColumnIds();
47248 //var totalWidth = cm.getTotalWidth();
47250 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
47251 //if(cm.isHidden(i)) continue;
47252 var w = cm.getColumnWidth(i);
47253 this.css.updateRule(this.colSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
47254 this.css.updateRule(this.hdSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
47256 this.updateSplitters();
47259 generateRules : function(cm){
47260 var ruleBuf = [], rulesId = this.idToCssName(this.grid.id)+ '-cssrules';
47261 Roo.util.CSS.removeStyleSheet(rulesId);
47262 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
47263 var cid = cm.getColumnId(i);
47265 if(cm.config[i].align){
47266 align = 'text-align:'+cm.config[i].align+';';
47269 if(cm.isHidden(i)){
47270 hidden = 'display:none;';
47272 var width = "width:" + (cm.getColumnWidth(i) - this.borderWidth) + "px;";
47274 this.colSelector, cid, " {\n", cm.config[i].css, align, width, "\n}\n",
47275 this.hdSelector, cid, " {\n", align, width, "}\n",
47276 this.tdSelector, cid, " {\n",hidden,"\n}\n",
47277 this.splitSelector, cid, " {\n", hidden , "\n}\n");
47279 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
47282 updateSplitters : function(){
47283 var cm = this.cm, s = this.getSplitters();
47284 if(s){ // splitters not created yet
47285 var pos = 0, locked = true;
47286 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
47287 if(cm.isHidden(i)) continue;
47288 var w = cm.getColumnWidth(i);
47289 if(!cm.isLocked(i) && locked){
47294 s[i].style.left = (pos-this.splitOffset) + "px";
47299 handleHiddenChange : function(colModel, colIndex, hidden){
47301 this.hideColumn(colIndex);
47303 this.unhideColumn(colIndex);
47307 hideColumn : function(colIndex){
47308 var cid = this.getColumnId(colIndex);
47309 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "none");
47310 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "none");
47312 this.updateHeaders();
47314 this.updateSplitters();
47318 unhideColumn : function(colIndex){
47319 var cid = this.getColumnId(colIndex);
47320 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "");
47321 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "");
47324 this.updateHeaders();
47326 this.updateSplitters();
47330 insertRows : function(dm, firstRow, lastRow, isUpdate){
47331 if(firstRow == 0 && lastRow == dm.getCount()-1){
47335 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
47337 var s = this.getScrollState();
47338 var markup = this.renderRows(firstRow, lastRow);
47339 this.bufferRows(markup[0], this.getLockedTable(), firstRow);
47340 this.bufferRows(markup[1], this.getBodyTable(), firstRow);
47341 this.restoreScroll(s);
47343 this.fireEvent("rowsinserted", this, firstRow, lastRow);
47344 this.syncRowHeights(firstRow, lastRow);
47345 this.stripeRows(firstRow);
47351 bufferRows : function(markup, target, index){
47352 var before = null, trows = target.rows, tbody = target.tBodies[0];
47353 if(index < trows.length){
47354 before = trows[index];
47356 var b = document.createElement("div");
47357 b.innerHTML = "<table><tbody>"+markup+"</tbody></table>";
47358 var rows = b.firstChild.rows;
47359 for(var i = 0, len = rows.length; i < len; i++){
47361 tbody.insertBefore(rows[0], before);
47363 tbody.appendChild(rows[0]);
47370 deleteRows : function(dm, firstRow, lastRow){
47371 if(dm.getRowCount()<1){
47372 this.fireEvent("beforerefresh", this);
47373 this.mainBody.update("");
47374 this.lockedBody.update("");
47375 this.fireEvent("refresh", this);
47377 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
47378 var bt = this.getBodyTable();
47379 var tbody = bt.firstChild;
47380 var rows = bt.rows;
47381 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
47382 tbody.removeChild(rows[firstRow]);
47384 this.stripeRows(firstRow);
47385 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
47389 updateRows : function(dataSource, firstRow, lastRow){
47390 var s = this.getScrollState();
47392 this.restoreScroll(s);
47395 handleSort : function(dataSource, sortColumnIndex, sortDir, noRefresh){
47399 this.updateHeaderSortState();
47402 getScrollState : function(){
47403 var sb = this.scroller.dom;
47404 return {left: sb.scrollLeft, top: sb.scrollTop};
47407 stripeRows : function(startRow){
47408 if(!this.grid.stripeRows || this.ds.getCount() < 1){
47411 startRow = startRow || 0;
47412 var rows = this.getBodyTable().rows;
47413 var lrows = this.getLockedTable().rows;
47414 var cls = ' x-grid-row-alt ';
47415 for(var i = startRow, len = rows.length; i < len; i++){
47416 var row = rows[i], lrow = lrows[i];
47417 var isAlt = ((i+1) % 2 == 0);
47418 var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
47419 if(isAlt == hasAlt){
47423 row.className += " x-grid-row-alt";
47425 row.className = row.className.replace("x-grid-row-alt", "");
47428 lrow.className = row.className;
47433 restoreScroll : function(state){
47434 var sb = this.scroller.dom;
47435 sb.scrollLeft = state.left;
47436 sb.scrollTop = state.top;
47440 syncScroll : function(){
47441 var sb = this.scroller.dom;
47442 var sh = this.mainHd.dom;
47443 var bs = this.mainBody.dom;
47444 var lv = this.lockedBody.dom;
47445 sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
47446 lv.scrollTop = bs.scrollTop = sb.scrollTop;
47449 handleScroll : function(e){
47451 var sb = this.scroller.dom;
47452 this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
47456 handleWheel : function(e){
47457 var d = e.getWheelDelta();
47458 this.scroller.dom.scrollTop -= d*22;
47459 // set this here to prevent jumpy scrolling on large tables
47460 this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
47464 renderRows : function(startRow, endRow){
47465 // pull in all the crap needed to render rows
47466 var g = this.grid, cm = g.colModel, ds = g.dataSource, stripe = g.stripeRows;
47467 var colCount = cm.getColumnCount();
47469 if(ds.getCount() < 1){
47473 // build a map for all the columns
47475 for(var i = 0; i < colCount; i++){
47476 var name = cm.getDataIndex(i);
47478 name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
47479 renderer : cm.getRenderer(i),
47480 id : cm.getColumnId(i),
47481 locked : cm.isLocked(i)
47485 startRow = startRow || 0;
47486 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
47488 // records to render
47489 var rs = ds.getRange(startRow, endRow);
47491 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
47494 // As much as I hate to duplicate code, this was branched because FireFox really hates
47495 // [].join("") on strings. The performance difference was substantial enough to
47496 // branch this function
47497 doRender : Roo.isGecko ?
47498 function(cs, rs, ds, startRow, colCount, stripe){
47499 var ts = this.templates, ct = ts.cell, rt = ts.row;
47501 var buf = "", lbuf = "", cb, lcb, c, p = {}, rp = {}, r, rowIndex;
47502 for(var j = 0, len = rs.length; j < len; j++){
47503 r = rs[j]; cb = ""; lcb = ""; rowIndex = (j+startRow);
47504 for(var i = 0; i < colCount; i++){
47506 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
47508 p.css = p.attr = "";
47509 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
47510 if(p.value == undefined || p.value === "") p.value = " ";
47511 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
47512 p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
47514 var markup = ct.apply(p);
47522 if(stripe && ((rowIndex+1) % 2 == 0)){
47523 alt[0] = "x-grid-row-alt";
47526 alt[1] = " x-grid-dirty-row";
47529 if(this.getRowClass){
47530 alt[2] = this.getRowClass(r, rowIndex);
47532 rp.alt = alt.join(" ");
47533 lbuf+= rt.apply(rp);
47535 buf+= rt.apply(rp);
47537 return [lbuf, buf];
47539 function(cs, rs, ds, startRow, colCount, stripe){
47540 var ts = this.templates, ct = ts.cell, rt = ts.row;
47542 var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
47543 for(var j = 0, len = rs.length; j < len; j++){
47544 r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
47545 for(var i = 0; i < colCount; i++){
47547 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
47549 p.css = p.attr = "";
47550 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
47551 if(p.value == undefined || p.value === "") p.value = " ";
47552 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
47553 p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
47555 var markup = ct.apply(p);
47557 cb[cb.length] = markup;
47559 lcb[lcb.length] = markup;
47563 if(stripe && ((rowIndex+1) % 2 == 0)){
47564 alt[0] = "x-grid-row-alt";
47567 alt[1] = " x-grid-dirty-row";
47570 if(this.getRowClass){
47571 alt[2] = this.getRowClass(r, rowIndex);
47573 rp.alt = alt.join(" ");
47574 rp.cells = lcb.join("");
47575 lbuf[lbuf.length] = rt.apply(rp);
47576 rp.cells = cb.join("");
47577 buf[buf.length] = rt.apply(rp);
47579 return [lbuf.join(""), buf.join("")];
47582 renderBody : function(){
47583 var markup = this.renderRows();
47584 var bt = this.templates.body;
47585 return [bt.apply({rows: markup[0]}), bt.apply({rows: markup[1]})];
47589 * Refreshes the grid
47590 * @param {Boolean} headersToo
47592 refresh : function(headersToo){
47593 this.fireEvent("beforerefresh", this);
47594 this.grid.stopEditing();
47595 var result = this.renderBody();
47596 this.lockedBody.update(result[0]);
47597 this.mainBody.update(result[1]);
47598 if(headersToo === true){
47599 this.updateHeaders();
47600 this.updateColumns();
47601 this.updateSplitters();
47602 this.updateHeaderSortState();
47604 this.syncRowHeights();
47606 this.fireEvent("refresh", this);
47609 handleColumnMove : function(cm, oldIndex, newIndex){
47610 this.indexMap = null;
47611 var s = this.getScrollState();
47612 this.refresh(true);
47613 this.restoreScroll(s);
47614 this.afterMove(newIndex);
47617 afterMove : function(colIndex){
47618 if(this.enableMoveAnim && Roo.enableFx){
47619 this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
47623 updateCell : function(dm, rowIndex, dataIndex){
47624 var colIndex = this.getColumnIndexByDataIndex(dataIndex);
47625 if(typeof colIndex == "undefined"){ // not present in grid
47628 var cm = this.grid.colModel;
47629 var cell = this.getCell(rowIndex, colIndex);
47630 var cellText = this.getCellText(rowIndex, colIndex);
47633 cellId : "x-grid-cell-" + rowIndex + "-" + colIndex,
47634 id : cm.getColumnId(colIndex),
47635 css: colIndex == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
47637 var renderer = cm.getRenderer(colIndex);
47638 var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
47639 if(typeof val == "undefined" || val === "") val = " ";
47640 cellText.innerHTML = val;
47641 cell.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
47642 this.syncRowHeights(rowIndex, rowIndex);
47645 calcColumnWidth : function(colIndex, maxRowsToMeasure){
47647 if(this.grid.autoSizeHeaders){
47648 var h = this.getHeaderCellMeasure(colIndex);
47649 maxWidth = Math.max(maxWidth, h.scrollWidth);
47652 if(this.cm.isLocked(colIndex)){
47653 tb = this.getLockedTable();
47656 tb = this.getBodyTable();
47657 index = colIndex - this.cm.getLockedCount();
47660 var rows = tb.rows;
47661 var stopIndex = Math.min(maxRowsToMeasure || rows.length, rows.length);
47662 for(var i = 0; i < stopIndex; i++){
47663 var cell = rows[i].childNodes[index].firstChild;
47664 maxWidth = Math.max(maxWidth, cell.scrollWidth);
47667 return maxWidth + /*margin for error in IE*/ 5;
47670 * Autofit a column to its content.
47671 * @param {Number} colIndex
47672 * @param {Boolean} forceMinSize true to force the column to go smaller if possible
47674 autoSizeColumn : function(colIndex, forceMinSize, suppressEvent){
47675 if(this.cm.isHidden(colIndex)){
47676 return; // can't calc a hidden column
47679 var cid = this.cm.getColumnId(colIndex);
47680 this.css.updateRule(this.colSelector +this.idToCssName( cid), "width", this.grid.minColumnWidth + "px");
47681 if(this.grid.autoSizeHeaders){
47682 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", this.grid.minColumnWidth + "px");
47685 var newWidth = this.calcColumnWidth(colIndex);
47686 this.cm.setColumnWidth(colIndex,
47687 Math.max(this.grid.minColumnWidth, newWidth), suppressEvent);
47688 if(!suppressEvent){
47689 this.grid.fireEvent("columnresize", colIndex, newWidth);
47694 * Autofits all columns to their content and then expands to fit any extra space in the grid
47696 autoSizeColumns : function(){
47697 var cm = this.grid.colModel;
47698 var colCount = cm.getColumnCount();
47699 for(var i = 0; i < colCount; i++){
47700 this.autoSizeColumn(i, true, true);
47702 if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
47705 this.updateColumns();
47711 * Autofits all columns to the grid's width proportionate with their current size
47712 * @param {Boolean} reserveScrollSpace Reserve space for a scrollbar
47714 fitColumns : function(reserveScrollSpace){
47715 var cm = this.grid.colModel;
47716 var colCount = cm.getColumnCount();
47720 for (i = 0; i < colCount; i++){
47721 if(!cm.isHidden(i) && !cm.isFixed(i)){
47722 w = cm.getColumnWidth(i);
47728 var avail = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
47729 if(reserveScrollSpace){
47732 var frac = (avail - cm.getTotalWidth())/width;
47733 while (cols.length){
47736 cm.setColumnWidth(i, Math.floor(w + w*frac), true);
47738 this.updateColumns();
47742 onRowSelect : function(rowIndex){
47743 var row = this.getRowComposite(rowIndex);
47744 row.addClass("x-grid-row-selected");
47747 onRowDeselect : function(rowIndex){
47748 var row = this.getRowComposite(rowIndex);
47749 row.removeClass("x-grid-row-selected");
47752 onCellSelect : function(row, col){
47753 var cell = this.getCell(row, col);
47755 Roo.fly(cell).addClass("x-grid-cell-selected");
47759 onCellDeselect : function(row, col){
47760 var cell = this.getCell(row, col);
47762 Roo.fly(cell).removeClass("x-grid-cell-selected");
47766 updateHeaderSortState : function(){
47767 var state = this.ds.getSortState();
47771 this.sortState = state;
47772 var sortColumn = this.cm.findColumnIndex(state.field);
47773 if(sortColumn != -1){
47774 var sortDir = state.direction;
47775 var sc = this.sortClasses;
47776 var hds = this.el.select(this.headerSelector).removeClass(sc);
47777 hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
47781 handleHeaderClick : function(g, index){
47782 if(this.headersDisabled){
47785 var dm = g.dataSource, cm = g.colModel;
47786 if(!cm.isSortable(index)){
47790 dm.sort(cm.getDataIndex(index));
47794 destroy : function(){
47796 this.colMenu.removeAll();
47797 Roo.menu.MenuMgr.unregister(this.colMenu);
47798 this.colMenu.getEl().remove();
47799 delete this.colMenu;
47802 this.hmenu.removeAll();
47803 Roo.menu.MenuMgr.unregister(this.hmenu);
47804 this.hmenu.getEl().remove();
47807 if(this.grid.enableColumnMove){
47808 var dds = Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
47810 for(var dd in dds){
47811 if(!dds[dd].config.isTarget && dds[dd].dragElId){
47812 var elid = dds[dd].dragElId;
47814 Roo.get(elid).remove();
47815 } else if(dds[dd].config.isTarget){
47816 dds[dd].proxyTop.remove();
47817 dds[dd].proxyBottom.remove();
47820 if(Roo.dd.DDM.locationCache[dd]){
47821 delete Roo.dd.DDM.locationCache[dd];
47824 delete Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
47827 Roo.util.CSS.removeStyleSheet(this.idToCssName(this.grid.id) + '-cssrules');
47828 this.bind(null, null);
47829 Roo.EventManager.removeResizeListener(this.onWindowResize, this);
47832 handleLockChange : function(){
47833 this.refresh(true);
47836 onDenyColumnLock : function(){
47840 onDenyColumnHide : function(){
47844 handleHdMenuClick : function(item){
47845 var index = this.hdCtxIndex;
47846 var cm = this.cm, ds = this.ds;
47849 ds.sort(cm.getDataIndex(index), "ASC");
47852 ds.sort(cm.getDataIndex(index), "DESC");
47855 var lc = cm.getLockedCount();
47856 if(cm.getColumnCount(true) <= lc+1){
47857 this.onDenyColumnLock();
47861 cm.setLocked(index, true, true);
47862 cm.moveColumn(index, lc);
47863 this.grid.fireEvent("columnmove", index, lc);
47865 cm.setLocked(index, true);
47869 var lc = cm.getLockedCount();
47870 if((lc-1) != index){
47871 cm.setLocked(index, false, true);
47872 cm.moveColumn(index, lc-1);
47873 this.grid.fireEvent("columnmove", index, lc-1);
47875 cm.setLocked(index, false);
47879 index = cm.getIndexById(item.id.substr(4));
47881 if(item.checked && cm.getColumnCount(true) <= 1){
47882 this.onDenyColumnHide();
47885 cm.setHidden(index, item.checked);
47891 beforeColMenuShow : function(){
47892 var cm = this.cm, colCount = cm.getColumnCount();
47893 this.colMenu.removeAll();
47894 for(var i = 0; i < colCount; i++){
47895 this.colMenu.add(new Roo.menu.CheckItem({
47896 id: "col-"+cm.getColumnId(i),
47897 text: cm.getColumnHeader(i),
47898 checked: !cm.isHidden(i),
47904 handleHdCtx : function(g, index, e){
47906 var hd = this.getHeaderCell(index);
47907 this.hdCtxIndex = index;
47908 var ms = this.hmenu.items, cm = this.cm;
47909 ms.get("asc").setDisabled(!cm.isSortable(index));
47910 ms.get("desc").setDisabled(!cm.isSortable(index));
47911 if(this.grid.enableColLock !== false){
47912 ms.get("lock").setDisabled(cm.isLocked(index));
47913 ms.get("unlock").setDisabled(!cm.isLocked(index));
47915 this.hmenu.show(hd, "tl-bl");
47918 handleHdOver : function(e){
47919 var hd = this.findHeaderCell(e.getTarget());
47920 if(hd && !this.headersDisabled){
47921 if(this.grid.colModel.isSortable(this.getCellIndex(hd))){
47922 this.fly(hd).addClass("x-grid-hd-over");
47927 handleHdOut : function(e){
47928 var hd = this.findHeaderCell(e.getTarget());
47930 this.fly(hd).removeClass("x-grid-hd-over");
47934 handleSplitDblClick : function(e, t){
47935 var i = this.getCellIndex(t);
47936 if(this.grid.enableColumnResize !== false && this.cm.isResizable(i) && !this.cm.isFixed(i)){
47937 this.autoSizeColumn(i, true);
47942 render : function(){
47945 var colCount = cm.getColumnCount();
47947 if(this.grid.monitorWindowResize === true){
47948 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
47950 var header = this.renderHeaders();
47951 var body = this.templates.body.apply({rows:""});
47952 var html = this.templates.master.apply({
47955 lockedHeader: header[0],
47959 //this.updateColumns();
47961 this.grid.getGridEl().dom.innerHTML = html;
47963 this.initElements();
47965 this.scroller.on("scroll", this.handleScroll, this);
47966 this.lockedBody.on("mousewheel", this.handleWheel, this);
47967 this.mainBody.on("mousewheel", this.handleWheel, this);
47969 this.mainHd.on("mouseover", this.handleHdOver, this);
47970 this.mainHd.on("mouseout", this.handleHdOut, this);
47971 this.mainHd.on("dblclick", this.handleSplitDblClick, this,
47972 {delegate: "."+this.splitClass});
47974 this.lockedHd.on("mouseover", this.handleHdOver, this);
47975 this.lockedHd.on("mouseout", this.handleHdOut, this);
47976 this.lockedHd.on("dblclick", this.handleSplitDblClick, this,
47977 {delegate: "."+this.splitClass});
47979 if(this.grid.enableColumnResize !== false && Roo.grid.SplitDragZone){
47980 new Roo.grid.SplitDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
47983 this.updateSplitters();
47985 if(this.grid.enableColumnMove && Roo.grid.HeaderDragZone){
47986 new Roo.grid.HeaderDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
47987 new Roo.grid.HeaderDropZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
47990 if(this.grid.enableCtxMenu !== false && Roo.menu.Menu){
47991 this.hmenu = new Roo.menu.Menu({id: this.grid.id + "-hctx"});
47993 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
47994 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
47996 if(this.grid.enableColLock !== false){
47997 this.hmenu.add('-',
47998 {id:"lock", text: this.lockText, cls: "xg-hmenu-lock"},
47999 {id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
48002 if(this.grid.enableColumnHide !== false){
48004 this.colMenu = new Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
48005 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
48006 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
48008 this.hmenu.add('-',
48009 {id:"columns", text: this.columnsText, menu: this.colMenu}
48012 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
48014 this.grid.on("headercontextmenu", this.handleHdCtx, this);
48017 if((this.grid.enableDragDrop || this.grid.enableDrag) && Roo.grid.GridDragZone){
48018 this.dd = new Roo.grid.GridDragZone(this.grid, {
48019 ddGroup : this.grid.ddGroup || 'GridDD'
48024 for(var i = 0; i < colCount; i++){
48025 if(cm.isHidden(i)){
48026 this.hideColumn(i);
48028 if(cm.config[i].align){
48029 this.css.updateRule(this.colSelector + i, "textAlign", cm.config[i].align);
48030 this.css.updateRule(this.hdSelector + i, "textAlign", cm.config[i].align);
48034 this.updateHeaderSortState();
48036 this.beforeInitialResize();
48039 // two part rendering gives faster view to the user
48040 this.renderPhase2.defer(1, this);
48043 renderPhase2 : function(){
48044 // render the rows now
48046 if(this.grid.autoSizeColumns){
48047 this.autoSizeColumns();
48051 beforeInitialResize : function(){
48055 onColumnSplitterMoved : function(i, w){
48056 this.userResized = true;
48057 var cm = this.grid.colModel;
48058 cm.setColumnWidth(i, w, true);
48059 var cid = cm.getColumnId(i);
48060 this.css.updateRule(this.colSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
48061 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
48062 this.updateSplitters();
48064 this.grid.fireEvent("columnresize", i, w);
48067 syncRowHeights : function(startIndex, endIndex){
48068 if(this.grid.enableRowHeightSync === true && this.cm.getLockedCount() > 0){
48069 startIndex = startIndex || 0;
48070 var mrows = this.getBodyTable().rows;
48071 var lrows = this.getLockedTable().rows;
48072 var len = mrows.length-1;
48073 endIndex = Math.min(endIndex || len, len);
48074 for(var i = startIndex; i <= endIndex; i++){
48075 var m = mrows[i], l = lrows[i];
48076 var h = Math.max(m.offsetHeight, l.offsetHeight);
48077 m.style.height = l.style.height = h + "px";
48082 layout : function(initialRender, is2ndPass){
48084 var auto = g.autoHeight;
48085 var scrollOffset = 16;
48086 var c = g.getGridEl(), cm = this.cm,
48087 expandCol = g.autoExpandColumn,
48089 //c.beginMeasure();
48091 if(!c.dom.offsetWidth){ // display:none?
48093 this.lockedWrap.show();
48094 this.mainWrap.show();
48099 var hasLock = this.cm.isLocked(0);
48101 var tbh = this.headerPanel.getHeight();
48102 var bbh = this.footerPanel.getHeight();
48105 var ch = this.getBodyTable().offsetHeight + tbh + bbh + this.mainHd.getHeight();
48106 var newHeight = ch + c.getBorderWidth("tb");
48108 newHeight = Math.min(g.maxHeight, newHeight);
48110 c.setHeight(newHeight);
48114 c.setWidth(cm.getTotalWidth()+c.getBorderWidth('lr'));
48117 var s = this.scroller;
48119 var csize = c.getSize(true);
48121 this.el.setSize(csize.width, csize.height);
48123 this.headerPanel.setWidth(csize.width);
48124 this.footerPanel.setWidth(csize.width);
48126 var hdHeight = this.mainHd.getHeight();
48127 var vw = csize.width;
48128 var vh = csize.height - (tbh + bbh);
48132 var bt = this.getBodyTable();
48133 var ltWidth = hasLock ?
48134 Math.max(this.getLockedTable().offsetWidth, this.lockedHd.dom.firstChild.offsetWidth) : 0;
48136 var scrollHeight = bt.offsetHeight;
48137 var scrollWidth = ltWidth + bt.offsetWidth;
48138 var vscroll = false, hscroll = false;
48140 this.scrollSizer.setSize(scrollWidth, scrollHeight+hdHeight);
48142 var lw = this.lockedWrap, mw = this.mainWrap;
48143 var lb = this.lockedBody, mb = this.mainBody;
48145 setTimeout(function(){
48146 var t = s.dom.offsetTop;
48147 var w = s.dom.clientWidth,
48148 h = s.dom.clientHeight;
48151 lw.setSize(ltWidth, h);
48153 mw.setLeftTop(ltWidth, t);
48154 mw.setSize(w-ltWidth, h);
48156 lb.setHeight(h-hdHeight);
48157 mb.setHeight(h-hdHeight);
48159 if(is2ndPass !== true && !gv.userResized && expandCol){
48160 // high speed resize without full column calculation
48162 var ci = cm.getIndexById(expandCol);
48164 ci = cm.findColumnIndex(expandCol);
48166 ci = Math.max(0, ci); // make sure it's got at least the first col.
48167 var expandId = cm.getColumnId(ci);
48168 var tw = cm.getTotalWidth(false);
48169 var currentWidth = cm.getColumnWidth(ci);
48170 var cw = Math.min(Math.max(((w-tw)+currentWidth-2)-/*scrollbar*/(w <= s.dom.offsetWidth ? 0 : 18), g.autoExpandMin), g.autoExpandMax);
48171 if(currentWidth != cw){
48172 cm.setColumnWidth(ci, cw, true);
48173 gv.css.updateRule(gv.colSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
48174 gv.css.updateRule(gv.hdSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
48175 gv.updateSplitters();
48176 gv.layout(false, true);
48188 onWindowResize : function(){
48189 if(!this.grid.monitorWindowResize || this.grid.autoHeight){
48195 appendFooter : function(parentEl){
48199 sortAscText : "Sort Ascending",
48200 sortDescText : "Sort Descending",
48201 lockText : "Lock Column",
48202 unlockText : "Unlock Column",
48203 columnsText : "Columns"
48207 Roo.grid.GridView.ColumnDragZone = function(grid, hd){
48208 Roo.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
48209 this.proxy.el.addClass('x-grid3-col-dd');
48212 Roo.extend(Roo.grid.GridView.ColumnDragZone, Roo.grid.HeaderDragZone, {
48213 handleMouseDown : function(e){
48217 callHandleMouseDown : function(e){
48218 Roo.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
48223 * Ext JS Library 1.1.1
48224 * Copyright(c) 2006-2007, Ext JS, LLC.
48226 * Originally Released Under LGPL - original licence link has changed is not relivant.
48229 * <script type="text/javascript">
48233 // This is a support class used internally by the Grid components
48234 Roo.grid.SplitDragZone = function(grid, hd, hd2){
48236 this.view = grid.getView();
48237 this.proxy = this.view.resizeProxy;
48238 Roo.grid.SplitDragZone.superclass.constructor.call(this, hd,
48239 "gridSplitters" + this.grid.getGridEl().id, {
48240 dragElId : Roo.id(this.proxy.dom), resizeFrame:false
48242 this.setHandleElId(Roo.id(hd));
48243 this.setOuterHandleElId(Roo.id(hd2));
48244 this.scroll = false;
48246 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
48247 fly: Roo.Element.fly,
48249 b4StartDrag : function(x, y){
48250 this.view.headersDisabled = true;
48251 this.proxy.setHeight(this.view.mainWrap.getHeight());
48252 var w = this.cm.getColumnWidth(this.cellIndex);
48253 var minw = Math.max(w-this.grid.minColumnWidth, 0);
48254 this.resetConstraints();
48255 this.setXConstraint(minw, 1000);
48256 this.setYConstraint(0, 0);
48257 this.minX = x - minw;
48258 this.maxX = x + 1000;
48260 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
48264 handleMouseDown : function(e){
48265 ev = Roo.EventObject.setEvent(e);
48266 var t = this.fly(ev.getTarget());
48267 if(t.hasClass("x-grid-split")){
48268 this.cellIndex = this.view.getCellIndex(t.dom);
48269 this.split = t.dom;
48270 this.cm = this.grid.colModel;
48271 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
48272 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
48277 endDrag : function(e){
48278 this.view.headersDisabled = false;
48279 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
48280 var diff = endX - this.startPos;
48281 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
48284 autoOffset : function(){
48285 this.setDelta(0,0);
48289 * Ext JS Library 1.1.1
48290 * Copyright(c) 2006-2007, Ext JS, LLC.
48292 * Originally Released Under LGPL - original licence link has changed is not relivant.
48295 * <script type="text/javascript">
48299 // This is a support class used internally by the Grid components
48300 Roo.grid.GridDragZone = function(grid, config){
48301 this.view = grid.getView();
48302 Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
48303 if(this.view.lockedBody){
48304 this.setHandleElId(Roo.id(this.view.mainBody.dom));
48305 this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
48307 this.scroll = false;
48309 this.ddel = document.createElement('div');
48310 this.ddel.className = 'x-grid-dd-wrap';
48313 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
48314 ddGroup : "GridDD",
48316 getDragData : function(e){
48317 var t = Roo.lib.Event.getTarget(e);
48318 var rowIndex = this.view.findRowIndex(t);
48319 if(rowIndex !== false){
48320 var sm = this.grid.selModel;
48321 //if(!sm.isSelected(rowIndex) || e.hasModifier()){
48322 // sm.mouseDown(e, t);
48324 if (e.hasModifier()){
48325 sm.handleMouseDown(e, t); // non modifier buttons are handled by row select.
48327 return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};
48332 onInitDrag : function(e){
48333 var data = this.dragData;
48334 this.ddel.innerHTML = this.grid.getDragDropText();
48335 this.proxy.update(this.ddel);
48336 // fire start drag?
48339 afterRepair : function(){
48340 this.dragging = false;
48343 getRepairXY : function(e, data){
48347 onEndDrag : function(data, e){
48351 onValidDrop : function(dd, e, id){
48356 beforeInvalidDrop : function(e, id){
48361 * Ext JS Library 1.1.1
48362 * Copyright(c) 2006-2007, Ext JS, LLC.
48364 * Originally Released Under LGPL - original licence link has changed is not relivant.
48367 * <script type="text/javascript">
48372 * @class Roo.grid.ColumnModel
48373 * @extends Roo.util.Observable
48374 * This is the default implementation of a ColumnModel used by the Grid. It defines
48375 * the columns in the grid.
48378 var colModel = new Roo.grid.ColumnModel([
48379 {header: "Ticker", width: 60, sortable: true, locked: true},
48380 {header: "Company Name", width: 150, sortable: true},
48381 {header: "Market Cap.", width: 100, sortable: true},
48382 {header: "$ Sales", width: 100, sortable: true, renderer: money},
48383 {header: "Employees", width: 100, sortable: true, resizable: false}
48388 * The config options listed for this class are options which may appear in each
48389 * individual column definition.
48390 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
48392 * @param {Object} config An Array of column config objects. See this class's
48393 * config objects for details.
48395 Roo.grid.ColumnModel = function(config){
48397 * The config passed into the constructor
48399 this.config = config;
48402 // if no id, create one
48403 // if the column does not have a dataIndex mapping,
48404 // map it to the order it is in the config
48405 for(var i = 0, len = config.length; i < len; i++){
48407 if(typeof c.dataIndex == "undefined"){
48410 if(typeof c.renderer == "string"){
48411 c.renderer = Roo.util.Format[c.renderer];
48413 if(typeof c.id == "undefined"){
48416 if(c.editor && c.editor.xtype){
48417 c.editor = Roo.factory(c.editor, Roo.grid);
48419 if(c.editor && c.editor.isFormField){
48420 c.editor = new Roo.grid.GridEditor(c.editor);
48422 this.lookup[c.id] = c;
48426 * The width of columns which have no width specified (defaults to 100)
48429 this.defaultWidth = 100;
48432 * Default sortable of columns which have no sortable specified (defaults to false)
48435 this.defaultSortable = false;
48439 * @event widthchange
48440 * Fires when the width of a column changes.
48441 * @param {ColumnModel} this
48442 * @param {Number} columnIndex The column index
48443 * @param {Number} newWidth The new width
48445 "widthchange": true,
48447 * @event headerchange
48448 * Fires when the text of a header changes.
48449 * @param {ColumnModel} this
48450 * @param {Number} columnIndex The column index
48451 * @param {Number} newText The new header text
48453 "headerchange": true,
48455 * @event hiddenchange
48456 * Fires when a column is hidden or "unhidden".
48457 * @param {ColumnModel} this
48458 * @param {Number} columnIndex The column index
48459 * @param {Boolean} hidden true if hidden, false otherwise
48461 "hiddenchange": true,
48463 * @event columnmoved
48464 * Fires when a column is moved.
48465 * @param {ColumnModel} this
48466 * @param {Number} oldIndex
48467 * @param {Number} newIndex
48469 "columnmoved" : true,
48471 * @event columlockchange
48472 * Fires when a column's locked state is changed
48473 * @param {ColumnModel} this
48474 * @param {Number} colIndex
48475 * @param {Boolean} locked true if locked
48477 "columnlockchange" : true
48479 Roo.grid.ColumnModel.superclass.constructor.call(this);
48481 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
48483 * @cfg {String} header The header text to display in the Grid view.
48486 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
48487 * {@link Roo.data.Record} definition from which to draw the column's value. If not
48488 * specified, the column's index is used as an index into the Record's data Array.
48491 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
48492 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
48495 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
48496 * Defaults to the value of the {@link #defaultSortable} property.
48497 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
48500 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
48503 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
48506 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
48509 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
48512 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
48513 * given the cell's data value. See {@link #setRenderer}. If not specified, the
48514 * default renderer uses the raw data value.
48517 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
48520 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
48524 * Returns the id of the column at the specified index.
48525 * @param {Number} index The column index
48526 * @return {String} the id
48528 getColumnId : function(index){
48529 return this.config[index].id;
48533 * Returns the column for a specified id.
48534 * @param {String} id The column id
48535 * @return {Object} the column
48537 getColumnById : function(id){
48538 return this.lookup[id];
48543 * Returns the column for a specified dataIndex.
48544 * @param {String} dataIndex The column dataIndex
48545 * @return {Object|Boolean} the column or false if not found
48547 getColumnByDataIndex: function(dataIndex){
48548 var index = this.findColumnIndex(dataIndex);
48549 return index > -1 ? this.config[index] : false;
48553 * Returns the index for a specified column id.
48554 * @param {String} id The column id
48555 * @return {Number} the index, or -1 if not found
48557 getIndexById : function(id){
48558 for(var i = 0, len = this.config.length; i < len; i++){
48559 if(this.config[i].id == id){
48567 * Returns the index for a specified column dataIndex.
48568 * @param {String} dataIndex The column dataIndex
48569 * @return {Number} the index, or -1 if not found
48572 findColumnIndex : function(dataIndex){
48573 for(var i = 0, len = this.config.length; i < len; i++){
48574 if(this.config[i].dataIndex == dataIndex){
48582 moveColumn : function(oldIndex, newIndex){
48583 var c = this.config[oldIndex];
48584 this.config.splice(oldIndex, 1);
48585 this.config.splice(newIndex, 0, c);
48586 this.dataMap = null;
48587 this.fireEvent("columnmoved", this, oldIndex, newIndex);
48590 isLocked : function(colIndex){
48591 return this.config[colIndex].locked === true;
48594 setLocked : function(colIndex, value, suppressEvent){
48595 if(this.isLocked(colIndex) == value){
48598 this.config[colIndex].locked = value;
48599 if(!suppressEvent){
48600 this.fireEvent("columnlockchange", this, colIndex, value);
48604 getTotalLockedWidth : function(){
48605 var totalWidth = 0;
48606 for(var i = 0; i < this.config.length; i++){
48607 if(this.isLocked(i) && !this.isHidden(i)){
48608 this.totalWidth += this.getColumnWidth(i);
48614 getLockedCount : function(){
48615 for(var i = 0, len = this.config.length; i < len; i++){
48616 if(!this.isLocked(i)){
48623 * Returns the number of columns.
48626 getColumnCount : function(visibleOnly){
48627 if(visibleOnly === true){
48629 for(var i = 0, len = this.config.length; i < len; i++){
48630 if(!this.isHidden(i)){
48636 return this.config.length;
48640 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
48641 * @param {Function} fn
48642 * @param {Object} scope (optional)
48643 * @return {Array} result
48645 getColumnsBy : function(fn, scope){
48647 for(var i = 0, len = this.config.length; i < len; i++){
48648 var c = this.config[i];
48649 if(fn.call(scope||this, c, i) === true){
48657 * Returns true if the specified column is sortable.
48658 * @param {Number} col The column index
48659 * @return {Boolean}
48661 isSortable : function(col){
48662 if(typeof this.config[col].sortable == "undefined"){
48663 return this.defaultSortable;
48665 return this.config[col].sortable;
48669 * Returns the rendering (formatting) function defined for the column.
48670 * @param {Number} col The column index.
48671 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
48673 getRenderer : function(col){
48674 if(!this.config[col].renderer){
48675 return Roo.grid.ColumnModel.defaultRenderer;
48677 return this.config[col].renderer;
48681 * Sets the rendering (formatting) function for a column.
48682 * @param {Number} col The column index
48683 * @param {Function} fn The function to use to process the cell's raw data
48684 * to return HTML markup for the grid view. The render function is called with
48685 * the following parameters:<ul>
48686 * <li>Data value.</li>
48687 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
48688 * <li>css A CSS style string to apply to the table cell.</li>
48689 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
48690 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
48691 * <li>Row index</li>
48692 * <li>Column index</li>
48693 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
48695 setRenderer : function(col, fn){
48696 this.config[col].renderer = fn;
48700 * Returns the width for the specified column.
48701 * @param {Number} col The column index
48704 getColumnWidth : function(col){
48705 return this.config[col].width || this.defaultWidth;
48709 * Sets the width for a column.
48710 * @param {Number} col The column index
48711 * @param {Number} width The new width
48713 setColumnWidth : function(col, width, suppressEvent){
48714 this.config[col].width = width;
48715 this.totalWidth = null;
48716 if(!suppressEvent){
48717 this.fireEvent("widthchange", this, col, width);
48722 * Returns the total width of all columns.
48723 * @param {Boolean} includeHidden True to include hidden column widths
48726 getTotalWidth : function(includeHidden){
48727 if(!this.totalWidth){
48728 this.totalWidth = 0;
48729 for(var i = 0, len = this.config.length; i < len; i++){
48730 if(includeHidden || !this.isHidden(i)){
48731 this.totalWidth += this.getColumnWidth(i);
48735 return this.totalWidth;
48739 * Returns the header for the specified column.
48740 * @param {Number} col The column index
48743 getColumnHeader : function(col){
48744 return this.config[col].header;
48748 * Sets the header for a column.
48749 * @param {Number} col The column index
48750 * @param {String} header The new header
48752 setColumnHeader : function(col, header){
48753 this.config[col].header = header;
48754 this.fireEvent("headerchange", this, col, header);
48758 * Returns the tooltip for the specified column.
48759 * @param {Number} col The column index
48762 getColumnTooltip : function(col){
48763 return this.config[col].tooltip;
48766 * Sets the tooltip for a column.
48767 * @param {Number} col The column index
48768 * @param {String} tooltip The new tooltip
48770 setColumnTooltip : function(col, tooltip){
48771 this.config[col].tooltip = tooltip;
48775 * Returns the dataIndex for the specified column.
48776 * @param {Number} col The column index
48779 getDataIndex : function(col){
48780 return this.config[col].dataIndex;
48784 * Sets the dataIndex for a column.
48785 * @param {Number} col The column index
48786 * @param {Number} dataIndex The new dataIndex
48788 setDataIndex : function(col, dataIndex){
48789 this.config[col].dataIndex = dataIndex;
48795 * Returns true if the cell is editable.
48796 * @param {Number} colIndex The column index
48797 * @param {Number} rowIndex The row index
48798 * @return {Boolean}
48800 isCellEditable : function(colIndex, rowIndex){
48801 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
48805 * Returns the editor defined for the cell/column.
48806 * return false or null to disable editing.
48807 * @param {Number} colIndex The column index
48808 * @param {Number} rowIndex The row index
48811 getCellEditor : function(colIndex, rowIndex){
48812 return this.config[colIndex].editor;
48816 * Sets if a column is editable.
48817 * @param {Number} col The column index
48818 * @param {Boolean} editable True if the column is editable
48820 setEditable : function(col, editable){
48821 this.config[col].editable = editable;
48826 * Returns true if the column is hidden.
48827 * @param {Number} colIndex The column index
48828 * @return {Boolean}
48830 isHidden : function(colIndex){
48831 return this.config[colIndex].hidden;
48836 * Returns true if the column width cannot be changed
48838 isFixed : function(colIndex){
48839 return this.config[colIndex].fixed;
48843 * Returns true if the column can be resized
48844 * @return {Boolean}
48846 isResizable : function(colIndex){
48847 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
48850 * Sets if a column is hidden.
48851 * @param {Number} colIndex The column index
48852 * @param {Boolean} hidden True if the column is hidden
48854 setHidden : function(colIndex, hidden){
48855 this.config[colIndex].hidden = hidden;
48856 this.totalWidth = null;
48857 this.fireEvent("hiddenchange", this, colIndex, hidden);
48861 * Sets the editor for a column.
48862 * @param {Number} col The column index
48863 * @param {Object} editor The editor object
48865 setEditor : function(col, editor){
48866 this.config[col].editor = editor;
48870 Roo.grid.ColumnModel.defaultRenderer = function(value){
48871 if(typeof value == "string" && value.length < 1){
48877 // Alias for backwards compatibility
48878 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
48881 * Ext JS Library 1.1.1
48882 * Copyright(c) 2006-2007, Ext JS, LLC.
48884 * Originally Released Under LGPL - original licence link has changed is not relivant.
48887 * <script type="text/javascript">
48891 * @class Roo.grid.AbstractSelectionModel
48892 * @extends Roo.util.Observable
48893 * Abstract base class for grid SelectionModels. It provides the interface that should be
48894 * implemented by descendant classes. This class should not be directly instantiated.
48897 Roo.grid.AbstractSelectionModel = function(){
48898 this.locked = false;
48899 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
48902 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
48903 /** @ignore Called by the grid automatically. Do not call directly. */
48904 init : function(grid){
48910 * Locks the selections.
48913 this.locked = true;
48917 * Unlocks the selections.
48919 unlock : function(){
48920 this.locked = false;
48924 * Returns true if the selections are locked.
48925 * @return {Boolean}
48927 isLocked : function(){
48928 return this.locked;
48932 * Ext JS Library 1.1.1
48933 * Copyright(c) 2006-2007, Ext JS, LLC.
48935 * Originally Released Under LGPL - original licence link has changed is not relivant.
48938 * <script type="text/javascript">
48941 * @extends Roo.grid.AbstractSelectionModel
48942 * @class Roo.grid.RowSelectionModel
48943 * The default SelectionModel used by {@link Roo.grid.Grid}.
48944 * It supports multiple selections and keyboard selection/navigation.
48946 * @param {Object} config
48948 Roo.grid.RowSelectionModel = function(config){
48949 Roo.apply(this, config);
48950 this.selections = new Roo.util.MixedCollection(false, function(o){
48955 this.lastActive = false;
48959 * @event selectionchange
48960 * Fires when the selection changes
48961 * @param {SelectionModel} this
48963 "selectionchange" : true,
48965 * @event afterselectionchange
48966 * Fires after the selection changes (eg. by key press or clicking)
48967 * @param {SelectionModel} this
48969 "afterselectionchange" : true,
48971 * @event beforerowselect
48972 * Fires when a row is selected being selected, return false to cancel.
48973 * @param {SelectionModel} this
48974 * @param {Number} rowIndex The selected index
48975 * @param {Boolean} keepExisting False if other selections will be cleared
48977 "beforerowselect" : true,
48980 * Fires when a row is selected.
48981 * @param {SelectionModel} this
48982 * @param {Number} rowIndex The selected index
48983 * @param {Roo.data.Record} r The record
48985 "rowselect" : true,
48987 * @event rowdeselect
48988 * Fires when a row is deselected.
48989 * @param {SelectionModel} this
48990 * @param {Number} rowIndex The selected index
48992 "rowdeselect" : true
48994 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
48995 this.locked = false;
48998 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
49000 * @cfg {Boolean} singleSelect
49001 * True to allow selection of only one row at a time (defaults to false)
49003 singleSelect : false,
49006 initEvents : function(){
49008 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
49009 this.grid.on("mousedown", this.handleMouseDown, this);
49010 }else{ // allow click to work like normal
49011 this.grid.on("rowclick", this.handleDragableRowClick, this);
49014 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
49015 "up" : function(e){
49017 this.selectPrevious(e.shiftKey);
49018 }else if(this.last !== false && this.lastActive !== false){
49019 var last = this.last;
49020 this.selectRange(this.last, this.lastActive-1);
49021 this.grid.getView().focusRow(this.lastActive);
49022 if(last !== false){
49026 this.selectFirstRow();
49028 this.fireEvent("afterselectionchange", this);
49030 "down" : function(e){
49032 this.selectNext(e.shiftKey);
49033 }else if(this.last !== false && this.lastActive !== false){
49034 var last = this.last;
49035 this.selectRange(this.last, this.lastActive+1);
49036 this.grid.getView().focusRow(this.lastActive);
49037 if(last !== false){
49041 this.selectFirstRow();
49043 this.fireEvent("afterselectionchange", this);
49048 var view = this.grid.view;
49049 view.on("refresh", this.onRefresh, this);
49050 view.on("rowupdated", this.onRowUpdated, this);
49051 view.on("rowremoved", this.onRemove, this);
49055 onRefresh : function(){
49056 var ds = this.grid.dataSource, i, v = this.grid.view;
49057 var s = this.selections;
49058 s.each(function(r){
49059 if((i = ds.indexOfId(r.id)) != -1){
49068 onRemove : function(v, index, r){
49069 this.selections.remove(r);
49073 onRowUpdated : function(v, index, r){
49074 if(this.isSelected(r)){
49075 v.onRowSelect(index);
49081 * @param {Array} records The records to select
49082 * @param {Boolean} keepExisting (optional) True to keep existing selections
49084 selectRecords : function(records, keepExisting){
49086 this.clearSelections();
49088 var ds = this.grid.dataSource;
49089 for(var i = 0, len = records.length; i < len; i++){
49090 this.selectRow(ds.indexOf(records[i]), true);
49095 * Gets the number of selected rows.
49098 getCount : function(){
49099 return this.selections.length;
49103 * Selects the first row in the grid.
49105 selectFirstRow : function(){
49110 * Select the last row.
49111 * @param {Boolean} keepExisting (optional) True to keep existing selections
49113 selectLastRow : function(keepExisting){
49114 this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
49118 * Selects the row immediately following the last selected row.
49119 * @param {Boolean} keepExisting (optional) True to keep existing selections
49121 selectNext : function(keepExisting){
49122 if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
49123 this.selectRow(this.last+1, keepExisting);
49124 this.grid.getView().focusRow(this.last);
49129 * Selects the row that precedes the last selected row.
49130 * @param {Boolean} keepExisting (optional) True to keep existing selections
49132 selectPrevious : function(keepExisting){
49134 this.selectRow(this.last-1, keepExisting);
49135 this.grid.getView().focusRow(this.last);
49140 * Returns the selected records
49141 * @return {Array} Array of selected records
49143 getSelections : function(){
49144 return [].concat(this.selections.items);
49148 * Returns the first selected record.
49151 getSelected : function(){
49152 return this.selections.itemAt(0);
49157 * Clears all selections.
49159 clearSelections : function(fast){
49160 if(this.locked) return;
49162 var ds = this.grid.dataSource;
49163 var s = this.selections;
49164 s.each(function(r){
49165 this.deselectRow(ds.indexOfId(r.id));
49169 this.selections.clear();
49176 * Selects all rows.
49178 selectAll : function(){
49179 if(this.locked) return;
49180 this.selections.clear();
49181 for(var i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
49182 this.selectRow(i, true);
49187 * Returns True if there is a selection.
49188 * @return {Boolean}
49190 hasSelection : function(){
49191 return this.selections.length > 0;
49195 * Returns True if the specified row is selected.
49196 * @param {Number/Record} record The record or index of the record to check
49197 * @return {Boolean}
49199 isSelected : function(index){
49200 var r = typeof index == "number" ? this.grid.dataSource.getAt(index) : index;
49201 return (r && this.selections.key(r.id) ? true : false);
49205 * Returns True if the specified record id is selected.
49206 * @param {String} id The id of record to check
49207 * @return {Boolean}
49209 isIdSelected : function(id){
49210 return (this.selections.key(id) ? true : false);
49214 handleMouseDown : function(e, t){
49215 var view = this.grid.getView(), rowIndex;
49216 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
49219 if(e.shiftKey && this.last !== false){
49220 var last = this.last;
49221 this.selectRange(last, rowIndex, e.ctrlKey);
49222 this.last = last; // reset the last
49223 view.focusRow(rowIndex);
49225 var isSelected = this.isSelected(rowIndex);
49226 if(e.button !== 0 && isSelected){
49227 view.focusRow(rowIndex);
49228 }else if(e.ctrlKey && isSelected){
49229 this.deselectRow(rowIndex);
49230 }else if(!isSelected){
49231 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
49232 view.focusRow(rowIndex);
49235 this.fireEvent("afterselectionchange", this);
49238 handleDragableRowClick : function(grid, rowIndex, e)
49240 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
49241 this.selectRow(rowIndex, false);
49242 grid.view.focusRow(rowIndex);
49243 this.fireEvent("afterselectionchange", this);
49248 * Selects multiple rows.
49249 * @param {Array} rows Array of the indexes of the row to select
49250 * @param {Boolean} keepExisting (optional) True to keep existing selections
49252 selectRows : function(rows, keepExisting){
49254 this.clearSelections();
49256 for(var i = 0, len = rows.length; i < len; i++){
49257 this.selectRow(rows[i], true);
49262 * Selects a range of rows. All rows in between startRow and endRow are also selected.
49263 * @param {Number} startRow The index of the first row in the range
49264 * @param {Number} endRow The index of the last row in the range
49265 * @param {Boolean} keepExisting (optional) True to retain existing selections
49267 selectRange : function(startRow, endRow, keepExisting){
49268 if(this.locked) return;
49270 this.clearSelections();
49272 if(startRow <= endRow){
49273 for(var i = startRow; i <= endRow; i++){
49274 this.selectRow(i, true);
49277 for(var i = startRow; i >= endRow; i--){
49278 this.selectRow(i, true);
49284 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
49285 * @param {Number} startRow The index of the first row in the range
49286 * @param {Number} endRow The index of the last row in the range
49288 deselectRange : function(startRow, endRow, preventViewNotify){
49289 if(this.locked) return;
49290 for(var i = startRow; i <= endRow; i++){
49291 this.deselectRow(i, preventViewNotify);
49297 * @param {Number} row The index of the row to select
49298 * @param {Boolean} keepExisting (optional) True to keep existing selections
49300 selectRow : function(index, keepExisting, preventViewNotify){
49301 if(this.locked || (index < 0 || index >= this.grid.dataSource.getCount())) return;
49302 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
49303 if(!keepExisting || this.singleSelect){
49304 this.clearSelections();
49306 var r = this.grid.dataSource.getAt(index);
49307 this.selections.add(r);
49308 this.last = this.lastActive = index;
49309 if(!preventViewNotify){
49310 this.grid.getView().onRowSelect(index);
49312 this.fireEvent("rowselect", this, index, r);
49313 this.fireEvent("selectionchange", this);
49319 * @param {Number} row The index of the row to deselect
49321 deselectRow : function(index, preventViewNotify){
49322 if(this.locked) return;
49323 if(this.last == index){
49326 if(this.lastActive == index){
49327 this.lastActive = false;
49329 var r = this.grid.dataSource.getAt(index);
49330 this.selections.remove(r);
49331 if(!preventViewNotify){
49332 this.grid.getView().onRowDeselect(index);
49334 this.fireEvent("rowdeselect", this, index);
49335 this.fireEvent("selectionchange", this);
49339 restoreLast : function(){
49341 this.last = this._last;
49346 acceptsNav : function(row, col, cm){
49347 return !cm.isHidden(col) && cm.isCellEditable(col, row);
49351 onEditorKey : function(field, e){
49352 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
49357 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
49359 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
49361 }else if(k == e.ENTER && !e.ctrlKey){
49365 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
49367 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
49369 }else if(k == e.ESC){
49373 g.startEditing(newCell[0], newCell[1]);
49378 * Ext JS Library 1.1.1
49379 * Copyright(c) 2006-2007, Ext JS, LLC.
49381 * Originally Released Under LGPL - original licence link has changed is not relivant.
49384 * <script type="text/javascript">
49387 * @class Roo.grid.CellSelectionModel
49388 * @extends Roo.grid.AbstractSelectionModel
49389 * This class provides the basic implementation for cell selection in a grid.
49391 * @param {Object} config The object containing the configuration of this model.
49393 Roo.grid.CellSelectionModel = function(config){
49394 Roo.apply(this, config);
49396 this.selection = null;
49400 * @event beforerowselect
49401 * Fires before a cell is selected.
49402 * @param {SelectionModel} this
49403 * @param {Number} rowIndex The selected row index
49404 * @param {Number} colIndex The selected cell index
49406 "beforecellselect" : true,
49408 * @event cellselect
49409 * Fires when a cell is selected.
49410 * @param {SelectionModel} this
49411 * @param {Number} rowIndex The selected row index
49412 * @param {Number} colIndex The selected cell index
49414 "cellselect" : true,
49416 * @event selectionchange
49417 * Fires when the active selection changes.
49418 * @param {SelectionModel} this
49419 * @param {Object} selection null for no selection or an object (o) with two properties
49421 <li>o.record: the record object for the row the selection is in</li>
49422 <li>o.cell: An array of [rowIndex, columnIndex]</li>
49425 "selectionchange" : true
49427 Roo.grid.CellSelectionModel.superclass.constructor.call(this);
49430 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel, {
49433 initEvents : function(){
49434 this.grid.on("mousedown", this.handleMouseDown, this);
49435 this.grid.getGridEl().on(Roo.isIE ? "keydown" : "keypress", this.handleKeyDown, this);
49436 var view = this.grid.view;
49437 view.on("refresh", this.onViewChange, this);
49438 view.on("rowupdated", this.onRowUpdated, this);
49439 view.on("beforerowremoved", this.clearSelections, this);
49440 view.on("beforerowsinserted", this.clearSelections, this);
49441 if(this.grid.isEditor){
49442 this.grid.on("beforeedit", this.beforeEdit, this);
49447 beforeEdit : function(e){
49448 this.select(e.row, e.column, false, true, e.record);
49452 onRowUpdated : function(v, index, r){
49453 if(this.selection && this.selection.record == r){
49454 v.onCellSelect(index, this.selection.cell[1]);
49459 onViewChange : function(){
49460 this.clearSelections(true);
49464 * Returns the currently selected cell,.
49465 * @return {Array} The selected cell (row, column) or null if none selected.
49467 getSelectedCell : function(){
49468 return this.selection ? this.selection.cell : null;
49472 * Clears all selections.
49473 * @param {Boolean} true to prevent the gridview from being notified about the change.
49475 clearSelections : function(preventNotify){
49476 var s = this.selection;
49478 if(preventNotify !== true){
49479 this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
49481 this.selection = null;
49482 this.fireEvent("selectionchange", this, null);
49487 * Returns true if there is a selection.
49488 * @return {Boolean}
49490 hasSelection : function(){
49491 return this.selection ? true : false;
49495 handleMouseDown : function(e, t){
49496 var v = this.grid.getView();
49497 if(this.isLocked()){
49500 var row = v.findRowIndex(t);
49501 var cell = v.findCellIndex(t);
49502 if(row !== false && cell !== false){
49503 this.select(row, cell);
49509 * @param {Number} rowIndex
49510 * @param {Number} collIndex
49512 select : function(rowIndex, colIndex, preventViewNotify, preventFocus, /*internal*/ r){
49513 if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
49514 this.clearSelections();
49515 r = r || this.grid.dataSource.getAt(rowIndex);
49518 cell : [rowIndex, colIndex]
49520 if(!preventViewNotify){
49521 var v = this.grid.getView();
49522 v.onCellSelect(rowIndex, colIndex);
49523 if(preventFocus !== true){
49524 v.focusCell(rowIndex, colIndex);
49527 this.fireEvent("cellselect", this, rowIndex, colIndex);
49528 this.fireEvent("selectionchange", this, this.selection);
49533 isSelectable : function(rowIndex, colIndex, cm){
49534 return !cm.isHidden(colIndex);
49538 handleKeyDown : function(e){
49539 Roo.log('Cell Sel Model handleKeyDown');
49540 if(!e.isNavKeyPress()){
49543 var g = this.grid, s = this.selection;
49546 var cell = g.walkCells(0, 0, 1, this.isSelectable, this);
49548 this.select(cell[0], cell[1]);
49553 var walk = function(row, col, step){
49554 return g.walkCells(row, col, step, sm.isSelectable, sm);
49556 var k = e.getKey(), r = s.cell[0], c = s.cell[1];
49561 // handled by onEditorKey
49562 if (g.isEditor && g.editing) {
49566 newCell = walk(r, c-1, -1);
49568 newCell = walk(r, c+1, 1);
49572 newCell = walk(r+1, c, 1);
49575 newCell = walk(r-1, c, -1);
49578 newCell = walk(r, c+1, 1);
49581 newCell = walk(r, c-1, -1);
49584 if(g.isEditor && !g.editing){
49585 g.startEditing(r, c);
49592 this.select(newCell[0], newCell[1]);
49597 acceptsNav : function(row, col, cm){
49598 return !cm.isHidden(col) && cm.isCellEditable(col, row);
49601 onEditorKey : function(field, e){
49603 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
49604 ///Roo.log('onEditorKey' + k);
49608 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
49610 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
49613 }else if(k == e.ENTER && !e.ctrlKey){
49616 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
49617 }else if(k == e.ESC){
49623 //Roo.log('next cell after edit');
49624 g.startEditing.defer(100, g, [newCell[0], newCell[1]]);
49629 * Ext JS Library 1.1.1
49630 * Copyright(c) 2006-2007, Ext JS, LLC.
49632 * Originally Released Under LGPL - original licence link has changed is not relivant.
49635 * <script type="text/javascript">
49639 * @class Roo.grid.EditorGrid
49640 * @extends Roo.grid.Grid
49641 * Class for creating and editable grid.
49642 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
49643 * The container MUST have some type of size defined for the grid to fill. The container will be
49644 * automatically set to position relative if it isn't already.
49645 * @param {Object} dataSource The data model to bind to
49646 * @param {Object} colModel The column model with info about this grid's columns
49648 Roo.grid.EditorGrid = function(container, config){
49649 Roo.grid.EditorGrid.superclass.constructor.call(this, container, config);
49650 this.getGridEl().addClass("xedit-grid");
49652 if(!this.selModel){
49653 this.selModel = new Roo.grid.CellSelectionModel();
49656 this.activeEditor = null;
49660 * @event beforeedit
49661 * Fires before cell editing is triggered. The edit event object has the following properties <br />
49662 * <ul style="padding:5px;padding-left:16px;">
49663 * <li>grid - This grid</li>
49664 * <li>record - The record being edited</li>
49665 * <li>field - The field name being edited</li>
49666 * <li>value - The value for the field being edited.</li>
49667 * <li>row - The grid row index</li>
49668 * <li>column - The grid column index</li>
49669 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
49671 * @param {Object} e An edit event (see above for description)
49673 "beforeedit" : true,
49676 * Fires after a cell is edited. <br />
49677 * <ul style="padding:5px;padding-left:16px;">
49678 * <li>grid - This grid</li>
49679 * <li>record - The record being edited</li>
49680 * <li>field - The field name being edited</li>
49681 * <li>value - The value being set</li>
49682 * <li>originalValue - The original value for the field, before the edit.</li>
49683 * <li>row - The grid row index</li>
49684 * <li>column - The grid column index</li>
49686 * @param {Object} e An edit event (see above for description)
49688 "afteredit" : true,
49690 * @event validateedit
49691 * Fires after a cell is edited, but before the value is set in the record.
49692 * You can use this to modify the value being set in the field, Return false
49693 * to cancel the change. The edit event object has the following properties <br />
49694 * <ul style="padding:5px;padding-left:16px;">
49695 * <li>editor - This editor</li>
49696 * <li>grid - This grid</li>
49697 * <li>record - The record being edited</li>
49698 * <li>field - The field name being edited</li>
49699 * <li>value - The value being set</li>
49700 * <li>originalValue - The original value for the field, before the edit.</li>
49701 * <li>row - The grid row index</li>
49702 * <li>column - The grid column index</li>
49703 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
49705 * @param {Object} e An edit event (see above for description)
49707 "validateedit" : true
49709 this.on("bodyscroll", this.stopEditing, this);
49710 this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick, this);
49713 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
49715 * @cfg {Number} clicksToEdit
49716 * The number of clicks on a cell required to display the cell's editor (defaults to 2)
49723 trackMouseOver: false, // causes very odd FF errors
49725 onCellDblClick : function(g, row, col){
49726 this.startEditing(row, col);
49729 onEditComplete : function(ed, value, startValue){
49730 this.editing = false;
49731 this.activeEditor = null;
49732 ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
49734 var field = this.colModel.getDataIndex(ed.col);
49739 originalValue: startValue,
49746 if(String(value) !== String(startValue)){
49748 if(this.fireEvent("validateedit", e) !== false && !e.cancel){
49749 r.set(field, e.value);
49750 delete e.cancel; //?? why!!!
49751 this.fireEvent("afteredit", e);
49754 this.fireEvent("afteredit", e); // always fir it!
49756 this.view.focusCell(ed.row, ed.col);
49760 * Starts editing the specified for the specified row/column
49761 * @param {Number} rowIndex
49762 * @param {Number} colIndex
49764 startEditing : function(row, col){
49765 this.stopEditing();
49766 if(this.colModel.isCellEditable(col, row)){
49767 this.view.ensureVisible(row, col, true);
49768 var r = this.dataSource.getAt(row);
49769 var field = this.colModel.getDataIndex(col);
49774 value: r.data[field],
49779 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
49780 this.editing = true;
49781 var ed = this.colModel.getCellEditor(col, row);
49787 ed.render(ed.parentEl || document.body);
49790 (function(){ // complex but required for focus issues in safari, ie and opera
49794 ed.on("complete", this.onEditComplete, this, {single: true});
49795 ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
49796 this.activeEditor = ed;
49797 var v = r.data[field];
49798 ed.startEdit(this.view.getCell(row, col), v);
49799 }).defer(50, this);
49805 * Stops any active editing
49807 stopEditing : function(){
49808 if(this.activeEditor){
49809 this.activeEditor.completeEdit();
49811 this.activeEditor = null;
49815 * Ext JS Library 1.1.1
49816 * Copyright(c) 2006-2007, Ext JS, LLC.
49818 * Originally Released Under LGPL - original licence link has changed is not relivant.
49821 * <script type="text/javascript">
49824 // private - not really -- you end up using it !
49825 // This is a support class used internally by the Grid components
49828 * @class Roo.grid.GridEditor
49829 * @extends Roo.Editor
49830 * Class for creating and editable grid elements.
49831 * @param {Object} config any settings (must include field)
49833 Roo.grid.GridEditor = function(field, config){
49834 if (!config && field.field) {
49836 field = Roo.factory(config.field, Roo.form);
49838 Roo.grid.GridEditor.superclass.constructor.call(this, field, config);
49839 field.monitorTab = false;
49842 Roo.extend(Roo.grid.GridEditor, Roo.Editor, {
49845 * @cfg {Roo.form.Field} field Field to wrap (or xtyped)
49848 alignment: "tl-tl",
49851 cls: "x-small-editor x-grid-editor",
49856 * Ext JS Library 1.1.1
49857 * Copyright(c) 2006-2007, Ext JS, LLC.
49859 * Originally Released Under LGPL - original licence link has changed is not relivant.
49862 * <script type="text/javascript">
49867 Roo.grid.PropertyRecord = Roo.data.Record.create([
49868 {name:'name',type:'string'}, 'value'
49872 Roo.grid.PropertyStore = function(grid, source){
49874 this.store = new Roo.data.Store({
49875 recordType : Roo.grid.PropertyRecord
49877 this.store.on('update', this.onUpdate, this);
49879 this.setSource(source);
49881 Roo.grid.PropertyStore.superclass.constructor.call(this);
49886 Roo.extend(Roo.grid.PropertyStore, Roo.util.Observable, {
49887 setSource : function(o){
49889 this.store.removeAll();
49892 if(this.isEditableValue(o[k])){
49893 data.push(new Roo.grid.PropertyRecord({name: k, value: o[k]}, k));
49896 this.store.loadRecords({records: data}, {}, true);
49899 onUpdate : function(ds, record, type){
49900 if(type == Roo.data.Record.EDIT){
49901 var v = record.data['value'];
49902 var oldValue = record.modified['value'];
49903 if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
49904 this.source[record.id] = v;
49906 this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
49913 getProperty : function(row){
49914 return this.store.getAt(row);
49917 isEditableValue: function(val){
49918 if(val && val instanceof Date){
49920 }else if(typeof val == 'object' || typeof val == 'function'){
49926 setValue : function(prop, value){
49927 this.source[prop] = value;
49928 this.store.getById(prop).set('value', value);
49931 getSource : function(){
49932 return this.source;
49936 Roo.grid.PropertyColumnModel = function(grid, store){
49939 g.PropertyColumnModel.superclass.constructor.call(this, [
49940 {header: this.nameText, sortable: true, dataIndex:'name', id: 'name'},
49941 {header: this.valueText, resizable:false, dataIndex: 'value', id: 'value'}
49943 this.store = store;
49944 this.bselect = Roo.DomHelper.append(document.body, {
49945 tag: 'select', style:'display:none', cls: 'x-grid-editor', children: [
49946 {tag: 'option', value: 'true', html: 'true'},
49947 {tag: 'option', value: 'false', html: 'false'}
49950 Roo.id(this.bselect);
49953 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
49954 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
49955 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
49956 'int' : new g.GridEditor(new f.NumberField({selectOnFocus:true, allowDecimals:false, style:'text-align:left;'})),
49957 'boolean' : new g.GridEditor(new f.Field({el:this.bselect,selectOnFocus:true}))
49959 this.renderCellDelegate = this.renderCell.createDelegate(this);
49960 this.renderPropDelegate = this.renderProp.createDelegate(this);
49963 Roo.extend(Roo.grid.PropertyColumnModel, Roo.grid.ColumnModel, {
49967 valueText : 'Value',
49969 dateFormat : 'm/j/Y',
49972 renderDate : function(dateVal){
49973 return dateVal.dateFormat(this.dateFormat);
49976 renderBool : function(bVal){
49977 return bVal ? 'true' : 'false';
49980 isCellEditable : function(colIndex, rowIndex){
49981 return colIndex == 1;
49984 getRenderer : function(col){
49986 this.renderCellDelegate : this.renderPropDelegate;
49989 renderProp : function(v){
49990 return this.getPropertyName(v);
49993 renderCell : function(val){
49995 if(val instanceof Date){
49996 rv = this.renderDate(val);
49997 }else if(typeof val == 'boolean'){
49998 rv = this.renderBool(val);
50000 return Roo.util.Format.htmlEncode(rv);
50003 getPropertyName : function(name){
50004 var pn = this.grid.propertyNames;
50005 return pn && pn[name] ? pn[name] : name;
50008 getCellEditor : function(colIndex, rowIndex){
50009 var p = this.store.getProperty(rowIndex);
50010 var n = p.data['name'], val = p.data['value'];
50012 if(typeof(this.grid.customEditors[n]) == 'string'){
50013 return this.editors[this.grid.customEditors[n]];
50015 if(typeof(this.grid.customEditors[n]) != 'undefined'){
50016 return this.grid.customEditors[n];
50018 if(val instanceof Date){
50019 return this.editors['date'];
50020 }else if(typeof val == 'number'){
50021 return this.editors['number'];
50022 }else if(typeof val == 'boolean'){
50023 return this.editors['boolean'];
50025 return this.editors['string'];
50031 * @class Roo.grid.PropertyGrid
50032 * @extends Roo.grid.EditorGrid
50033 * This class represents the interface of a component based property grid control.
50034 * <br><br>Usage:<pre><code>
50035 var grid = new Roo.grid.PropertyGrid("my-container-id", {
50043 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
50044 * The container MUST have some type of size defined for the grid to fill. The container will be
50045 * automatically set to position relative if it isn't already.
50046 * @param {Object} config A config object that sets properties on this grid.
50048 Roo.grid.PropertyGrid = function(container, config){
50049 config = config || {};
50050 var store = new Roo.grid.PropertyStore(this);
50051 this.store = store;
50052 var cm = new Roo.grid.PropertyColumnModel(this, store);
50053 store.store.sort('name', 'ASC');
50054 Roo.grid.PropertyGrid.superclass.constructor.call(this, container, Roo.apply({
50057 enableColLock:false,
50058 enableColumnMove:false,
50060 trackMouseOver: false,
50063 this.getGridEl().addClass('x-props-grid');
50064 this.lastEditRow = null;
50065 this.on('columnresize', this.onColumnResize, this);
50068 * @event beforepropertychange
50069 * Fires before a property changes (return false to stop?)
50070 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
50071 * @param {String} id Record Id
50072 * @param {String} newval New Value
50073 * @param {String} oldval Old Value
50075 "beforepropertychange": true,
50077 * @event propertychange
50078 * Fires after a property changes
50079 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
50080 * @param {String} id Record Id
50081 * @param {String} newval New Value
50082 * @param {String} oldval Old Value
50084 "propertychange": true
50086 this.customEditors = this.customEditors || {};
50088 Roo.extend(Roo.grid.PropertyGrid, Roo.grid.EditorGrid, {
50091 * @cfg {Object} customEditors map of colnames=> custom editors.
50092 * the custom editor can be one of the standard ones (date|string|number|int|boolean), or a
50093 * grid editor eg. Roo.grid.GridEditor(new Roo.form.TextArea({selectOnFocus:true})),
50094 * false disables editing of the field.
50098 * @cfg {Object} propertyNames map of property Names to their displayed value
50101 render : function(){
50102 Roo.grid.PropertyGrid.superclass.render.call(this);
50103 this.autoSize.defer(100, this);
50106 autoSize : function(){
50107 Roo.grid.PropertyGrid.superclass.autoSize.call(this);
50109 this.view.fitColumns();
50113 onColumnResize : function(){
50114 this.colModel.setColumnWidth(1, this.container.getWidth(true)-this.colModel.getColumnWidth(0));
50118 * Sets the data for the Grid
50119 * accepts a Key => Value object of all the elements avaiable.
50120 * @param {Object} data to appear in grid.
50122 setSource : function(source){
50123 this.store.setSource(source);
50127 * Gets all the data from the grid.
50128 * @return {Object} data data stored in grid
50130 getSource : function(){
50131 return this.store.getSource();
50135 * Ext JS Library 1.1.1
50136 * Copyright(c) 2006-2007, Ext JS, LLC.
50138 * Originally Released Under LGPL - original licence link has changed is not relivant.
50141 * <script type="text/javascript">
50145 * @class Roo.LoadMask
50146 * A simple utility class for generically masking elements while loading data. If the element being masked has
50147 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
50148 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
50149 * element's UpdateManager load indicator and will be destroyed after the initial load.
50151 * Create a new LoadMask
50152 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
50153 * @param {Object} config The config object
50155 Roo.LoadMask = function(el, config){
50156 this.el = Roo.get(el);
50157 Roo.apply(this, config);
50159 this.store.on('beforeload', this.onBeforeLoad, this);
50160 this.store.on('load', this.onLoad, this);
50161 this.store.on('loadexception', this.onLoad, this);
50162 this.removeMask = false;
50164 var um = this.el.getUpdateManager();
50165 um.showLoadIndicator = false; // disable the default indicator
50166 um.on('beforeupdate', this.onBeforeLoad, this);
50167 um.on('update', this.onLoad, this);
50168 um.on('failure', this.onLoad, this);
50169 this.removeMask = true;
50173 Roo.LoadMask.prototype = {
50175 * @cfg {Boolean} removeMask
50176 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
50177 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
50180 * @cfg {String} msg
50181 * The text to display in a centered loading message box (defaults to 'Loading...')
50183 msg : 'Loading...',
50185 * @cfg {String} msgCls
50186 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
50188 msgCls : 'x-mask-loading',
50191 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
50197 * Disables the mask to prevent it from being displayed
50199 disable : function(){
50200 this.disabled = true;
50204 * Enables the mask so that it can be displayed
50206 enable : function(){
50207 this.disabled = false;
50211 onLoad : function(){
50212 this.el.unmask(this.removeMask);
50216 onBeforeLoad : function(){
50217 if(!this.disabled){
50218 this.el.mask(this.msg, this.msgCls);
50223 destroy : function(){
50225 this.store.un('beforeload', this.onBeforeLoad, this);
50226 this.store.un('load', this.onLoad, this);
50227 this.store.un('loadexception', this.onLoad, this);
50229 var um = this.el.getUpdateManager();
50230 um.un('beforeupdate', this.onBeforeLoad, this);
50231 um.un('update', this.onLoad, this);
50232 um.un('failure', this.onLoad, this);
50237 * Ext JS Library 1.1.1
50238 * Copyright(c) 2006-2007, Ext JS, LLC.
50240 * Originally Released Under LGPL - original licence link has changed is not relivant.
50243 * <script type="text/javascript">
50245 Roo.XTemplate = function(){
50246 Roo.XTemplate.superclass.constructor.apply(this, arguments);
50249 s = ['<tpl>', s, '</tpl>'].join('');
50251 var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;
50253 var nameRe = /^<tpl\b[^>]*?for="(.*?)"/;
50254 var ifRe = /^<tpl\b[^>]*?if="(.*?)"/;
50255 var execRe = /^<tpl\b[^>]*?exec="(.*?)"/;
50259 while(m = s.match(re)){
50260 var m2 = m[0].match(nameRe);
50261 var m3 = m[0].match(ifRe);
50262 var m4 = m[0].match(execRe);
50263 var exp = null, fn = null, exec = null;
50264 var name = m2 && m2[1] ? m2[1] : '';
50266 exp = m3 && m3[1] ? m3[1] : null;
50268 fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
50272 exp = m4 && m4[1] ? m4[1] : null;
50274 exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
50279 case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
50280 case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
50281 default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
50291 s = s.replace(m[0], '{xtpl'+ id + '}');
50294 for(var i = tpls.length-1; i >= 0; --i){
50295 this.compileTpl(tpls[i]);
50297 this.master = tpls[tpls.length-1];
50300 Roo.extend(Roo.XTemplate, Roo.Template, {
50302 re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
50304 applySubTemplate : function(id, values, parent){
50305 var t = this.tpls[id];
50306 if(t.test && !t.test.call(this, values, parent)){
50309 if(t.exec && t.exec.call(this, values, parent)){
50312 var vs = t.target ? t.target.call(this, values, parent) : values;
50313 parent = t.target ? values : parent;
50314 if(t.target && vs instanceof Array){
50316 for(var i = 0, len = vs.length; i < len; i++){
50317 buf[buf.length] = t.compiled.call(this, vs[i], parent);
50319 return buf.join('');
50321 return t.compiled.call(this, vs, parent);
50324 compileTpl : function(tpl){
50325 var fm = Roo.util.Format;
50326 var useF = this.disableFormats !== true;
50327 var sep = Roo.isGecko ? "+" : ",";
50328 var fn = function(m, name, format, args){
50329 if(name.substr(0, 4) == 'xtpl'){
50330 return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent)'+sep+"'";
50333 if(name.indexOf('.') != -1){
50336 v = "values['" + name + "']";
50338 if(format && useF){
50339 args = args ? ',' + args : "";
50340 if(format.substr(0, 5) != "this."){
50341 format = "fm." + format + '(';
50343 format = 'this.call("'+ format.substr(5) + '", ';
50347 args= ''; format = "("+v+" === undefined ? '' : ";
50349 return "'"+ sep + format + v + args + ")"+sep+"'";
50352 // branched to use + in gecko and [].join() in others
50354 body = "tpl.compiled = function(values, parent){ return '" +
50355 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
50358 body = ["tpl.compiled = function(values, parent){ return ['"];
50359 body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
50360 body.push("'].join('');};");
50361 body = body.join('');
50363 /** eval:var:zzzzzzz */
50368 applyTemplate : function(values){
50369 return this.master.compiled.call(this, values, {});
50373 apply : function(){
50374 return this.applyTemplate.apply(this, arguments);
50377 compile : function(){return this;}
50380 Roo.XTemplate.from = function(el){
50381 el = Roo.getDom(el);
50382 return new Roo.XTemplate(el.value || el.innerHTML);
50384 * Original code for Roojs - LGPL
50385 * <script type="text/javascript">
50389 * @class Roo.XComponent
50390 * A delayed Element creator...
50392 * Mypart.xyx = new Roo.XComponent({
50394 parent : 'Mypart.xyz', // empty == document.element.!!
50398 disabled : function() {}
50400 tree : function() { // return an tree of xtype declared components
50404 xtype : 'NestedLayoutPanel',
50409 * @extends Roo.util.Observable
50411 * @param cfg {Object} configuration of component
50414 Roo.XComponent = function(cfg) {
50415 Roo.apply(this, cfg);
50419 * Fires when this the componnt is built
50420 * @param {Roo.XComponent} c the component
50424 * @event buildcomplete
50425 * Fires on the top level element when all elements have been built
50426 * @param {Roo.XComponent} c the top level component.
50428 'buildcomplete' : true
50432 Roo.XComponent.register(this);
50433 this.modules = false;
50434 this.el = false; // where the layout goes..
50438 Roo.extend(Roo.XComponent, Roo.util.Observable, {
50441 * The created element (with Roo.factory())
50442 * @type {Roo.Layout}
50448 * for BC - use el in new code
50449 * @type {Roo.Layout}
50455 * for BC - use el in new code
50456 * @type {Roo.Layout}
50461 * @cfg {Function|boolean} disabled
50462 * If this module is disabled by some rule, return true from the funtion
50467 * @cfg {String} parent
50468 * Name of parent element which it get xtype added to..
50473 * @cfg {String} order
50474 * Used to set the order in which elements are created (usefull for multiple tabs)
50479 * @cfg {String} name
50480 * String to display while loading.
50484 * @cfg {Array} items
50485 * A single item array - the first element is the root of the tree..
50486 * It's done this way to stay compatible with the Xtype system...
50494 Roo.apply(Roo.XComponent, {
50497 * @property buildCompleted
50498 * True when the builder has completed building the interface.
50501 buildCompleted : false,
50504 * @property topModule
50505 * the upper most module - uses document.element as it's constructor.
50512 * @property modules
50513 * array of modules to be created by registration system.
50514 * @type Roo.XComponent
50521 * Register components to be built later.
50523 * This solves the following issues
50524 * - Building is not done on page load, but after an authentication process has occured.
50525 * - Interface elements are registered on page load
50526 * - Parent Interface elements may not be loaded before child, so this handles that..
50533 module : 'Pman.Tab.projectMgr',
50535 parent : 'Pman.layout',
50536 disabled : false, // or use a function..
50539 * * @param {Object} details about module
50541 register : function(obj) {
50542 this.modules.push(obj);
50546 * convert a string to an object..
50550 toObject : function(str)
50552 if (!str || typeof(str) == 'object') {
50555 var ar = str.split('.');
50559 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
50561 throw "Module not found : " + str;
50563 Roo.each(ar, function(e) {
50564 if (typeof(o[e]) == 'undefined') {
50565 throw "Module not found : " + str;
50575 * move modules into their correct place in the tree..
50578 preBuild : function ()
50581 Roo.each(this.modules , function (obj)
50583 obj.parent = this.toObject(obj.parent);
50586 this.topModule = obj;
50590 if (!obj.parent.modules) {
50591 obj.parent.modules = new Roo.util.MixedCollection(false,
50592 function(o) { return o.order + '' }
50596 obj.parent.modules.add(obj);
50601 * make a list of modules to build.
50602 * @return {Array} list of modules.
50605 buildOrder : function()
50608 var cmp = function(a,b) {
50609 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
50612 if (!this.topModule || !this.topModule.modules) {
50613 throw "No top level modules to build";
50616 // make a flat list in order of modules to build.
50617 var mods = [ this.topModule ];
50620 // add modules to their parents..
50621 var addMod = function(m) {
50622 // Roo.debug && Roo.log(m.modKey);
50626 m.modules.keySort('ASC', cmp );
50627 m.modules.each(addMod);
50629 // not sure if this is used any more..
50631 m.finalize.name = m.name + " (clean up) ";
50632 mods.push(m.finalize);
50636 this.topModule.modules.keySort('ASC', cmp );
50637 this.topModule.modules.each(addMod);
50642 * Build the registered modules.
50643 * @param {Object} parent element.
50644 * @param {Function} optional method to call after module has been added.
50652 var mods = this.buildOrder();
50654 //this.allmods = mods;
50655 //Roo.debug && Roo.log(mods);
50657 if (!mods.length) { // should not happen
50658 throw "NO modules!!!";
50663 // flash it up as modal - so we store the mask!?
50664 Roo.MessageBox.show({ title: 'loading' });
50665 Roo.MessageBox.show({
50666 title: "Please wait...",
50667 msg: "Building Interface...",
50674 var total = mods.length;
50677 var progressRun = function() {
50678 if (!mods.length) {
50679 Roo.debug && Roo.log('hide?');
50680 Roo.MessageBox.hide();
50681 _this.topModule.fireEvent('buildcomplete', _this.topModule);
50685 var m = mods.shift();
50686 Roo.debug && Roo.log(m);
50687 if (typeof(m) == 'function') { // not sure if this is supported any more..
50689 return progressRun.defer(10, _this);
50692 Roo.MessageBox.updateProgress(
50693 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
50695 (m.name ? (' - ' + m.name) : '')
50700 var disabled = (typeof(m.disabled) == 'function') ?
50701 m.disabled.call(m.module.disabled) : m.disabled;
50705 return progressRun(); // we do not update the display!
50709 // it's a top level one..
50710 var layoutbase = new Ext.BorderLayout(document.body, {
50716 tabPosition: 'top',
50717 //resizeTabs: true,
50718 alwaysShowTabs: true,
50722 var tree = m.tree();
50723 tree.region = 'center';
50724 m.el = layoutbase.addxtype(tree);
50726 m.layout = m.panel.layout;
50727 return progressRun.defer(10, _this);
50730 var tree = m.tree();
50731 tree.region = tree.region || m.region;
50732 m.el = m.parent.el.addxtype(tree);
50733 m.fireEvent('built', m);
50735 m.layout = m.panel.layout;
50736 progressRun.defer(10, _this);
50739 progressRun.defer(1, _this);
50749 //<script type="text/javascript">
50754 * @extends Roo.LayoutDialog
50755 * A generic Login Dialog..... - only one needed in theory!?!?
50757 * Fires XComponent builder on success...
50760 * username,password, lang = for login actions.
50761 * check = 1 for periodic checking that sesion is valid.
50762 * passwordRequest = email request password
50763 * logout = 1 = to logout
50765 * Affects: (this id="????" elements)
50766 * loading (removed) (used to indicate application is loading)
50767 * loading-mask (hides) (used to hide application when it's building loading)
50773 * Myapp.login = Roo.Login({
50789 Roo.Login = function(cfg)
50795 Roo.apply(this,cfg);
50797 Roo.onReady(function() {
50803 Roo.Login.superclass.constructor.call(this, this);
50804 //this.addxtype(this.items[0]);
50810 Roo.extend(Roo.Login, Roo.LayoutDialog, {
50813 * @cfg {String} method
50814 * Method used to query for login details.
50819 * @cfg {String} url
50820 * URL to query login data. - eg. baseURL + '/Login.php'
50826 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
50831 * @property checkFails
50832 * Number of times we have attempted to get authentication check, and failed.
50837 * @property intervalID
50838 * The window interval that does the constant login checking.
50844 onLoad : function() // called on page load...
50848 if (Roo.get('loading')) { // clear any loading indicator..
50849 Roo.get('loading').remove();
50852 //this.switchLang('en'); // set the language to english..
50855 success: function(response, opts) { // check successfull...
50857 var res = this.processResponse(response);
50858 this.checkFails =0;
50859 if (!res.success) { // error!
50860 this.checkFails = 5;
50861 //console.log('call failure');
50862 return this.failure(response,opts);
50865 if (!res.data.id) { // id=0 == login failure.
50866 return this.show();
50870 //console.log(success);
50871 this.fillAuth(res.data);
50872 this.checkFails =0;
50873 Roo.XComponent.build();
50875 failure : this.show
50881 check: function(cfg) // called every so often to refresh cookie etc..
50883 if (cfg.again) { // could be undefined..
50886 this.checkFails = 0;
50889 if (this.sending) {
50890 if ( this.checkFails > 4) {
50891 Roo.MessageBox.alert("Error",
50892 "Error getting authentication status. - try reloading, or wait a while", function() {
50893 _this.sending = false;
50898 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
50901 this.sending = true;
50908 method: this.method,
50909 success: cfg.success || this.success,
50910 failure : cfg.failure || this.failure,
50920 window.onbeforeunload = function() { }; // false does not work for IE..
50930 failure : function() {
50931 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
50932 document.location = document.location.toString() + '?ts=' + Math.random();
50936 success : function() {
50937 _this.user = false;
50938 this.checkFails =0;
50940 document.location = document.location.toString() + '?ts=' + Math.random();
50947 processResponse : function (response)
50951 res = Roo.decode(response.responseText);
50953 if (typeof(res) != 'object') {
50954 res = { success : false, errorMsg : res, errors : true };
50956 if (typeof(res.success) == 'undefined') {
50957 res.success = false;
50961 res = { success : false, errorMsg : response.responseText, errors : true };
50966 success : function(response, opts) // check successfull...
50968 this.sending = false;
50969 var res = this.processResponse(response);
50970 if (!res.success) {
50971 return this.failure(response, opts);
50973 if (!res.data || !res.data.id) {
50974 return this.failure(response,opts);
50976 //console.log(res);
50977 this.fillAuth(res.data);
50979 this.checkFails =0;
50984 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
50986 this.authUser = -1;
50987 this.sending = false;
50988 var res = this.processResponse(response);
50989 //console.log(res);
50990 if ( this.checkFails > 2) {
50992 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
50993 "Error getting authentication status. - try reloading");
50996 opts.callCfg.again = true;
50997 this.check.defer(1000, this, [ opts.callCfg ]);
51003 fillAuth: function(au) {
51004 this.startAuthCheck();
51005 this.authUserId = au.id;
51006 this.authUser = au;
51007 this.lastChecked = new Date();
51008 this.fireEvent('refreshed', au);
51009 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
51010 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
51011 au.lang = au.lang || 'en';
51012 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
51013 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
51014 this.switchLang(au.lang );
51017 // open system... - -on setyp..
51018 if (this.authUserId < 0) {
51019 Roo.MessageBox.alert("Warning",
51020 "This is an open system - please set up a admin user with a password.");
51023 //Pman.onload(); // which should do nothing if it's a re-auth result...
51028 startAuthCheck : function() // starter for timeout checking..
51030 if (this.intervalID) { // timer already in place...
51034 this.intervalID = window.setInterval(function() {
51035 _this.check(false);
51036 }, 120000); // every 120 secs = 2mins..
51042 switchLang : function (lang)
51044 _T = typeof(_T) == 'undefined' ? false : _T;
51045 if (!_T || !lang.length) {
51049 if (!_T && lang != 'en') {
51050 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
51054 if (typeof(_T.en) == 'undefined') {
51056 Roo.apply(_T.en, _T);
51059 if (typeof(_T[lang]) == 'undefined') {
51060 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
51065 Roo.apply(_T, _T[lang]);
51066 // just need to set the text values for everything...
51068 /* this will not work ...
51072 function formLabel(name, val) {
51073 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
51076 formLabel('password', "Password"+':');
51077 formLabel('username', "Email Address"+':');
51078 formLabel('lang', "Language"+':');
51079 this.dialog.setTitle("Login");
51080 this.dialog.buttons[0].setText("Forgot Password");
51081 this.dialog.buttons[1].setText("Login");
51100 collapsible: false,
51102 center: { // needed??
51105 // tabPosition: 'top',
51108 alwaysShowTabs: false
51112 show : function(dlg)
51114 //console.log(this);
51115 this.form = this.layout.getRegion('center').activePanel.form;
51116 this.form.dialog = dlg;
51117 this.buttons[0].form = this.form;
51118 this.buttons[0].dialog = dlg;
51119 this.buttons[1].form = this.form;
51120 this.buttons[1].dialog = dlg;
51122 //this.resizeToLogo.defer(1000,this);
51123 // this is all related to resizing for logos..
51124 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
51126 // this.resizeToLogo.defer(1000,this);
51129 //var w = Ext.lib.Dom.getViewWidth() - 100;
51130 //var h = Ext.lib.Dom.getViewHeight() - 100;
51131 //this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
51133 if (this.disabled) {
51138 if (this.user.id < 0) { // used for inital setup situations.
51142 if (this.intervalID) {
51143 // remove the timer
51144 window.clearInterval(this.intervalID);
51145 this.intervalID = false;
51149 if (Roo.get('loading')) {
51150 Roo.get('loading').remove();
51152 if (Roo.get('loading-mask')) {
51153 Roo.get('loading-mask').hide();
51156 //incomming._node = tnode;
51158 //this.dialog.modal = !modal;
51159 //this.dialog.show();
51163 this.form.setValues({
51164 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
51165 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
51168 this.switchLang(Roo.state.Manager.get(this.realm + '.lang', 'en'));
51169 if (this.form.findField('username').getValue().length > 0 ){
51170 this.form.findField('password').focus();
51172 this.form.findField('username').focus();
51180 xtype : 'ContentPanel',
51192 style : 'margin: 10px;',
51195 actionfailed : function(f, act) {
51196 // form can return { errors: .... }
51198 //act.result.errors // invalid form element list...
51199 //act.result.errorMsg// invalid form element list...
51201 this.dialog.el.unmask();
51202 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
51203 "Login failed - communication error - try again.");
51206 actioncomplete: function(re, act) {
51208 Roo.state.Manager.set(
51209 this.dialog.realm + '.username',
51210 this.findField('username').getValue()
51212 Roo.state.Manager.set(
51213 this.dialog.realm + '.lang',
51214 this.findField('lang').getValue()
51217 this.dialog.fillAuth(act.result.data);
51219 this.dialog.hide();
51221 if (Roo.get('loading-mask')) {
51222 Roo.get('loading-mask').show();
51224 Roo.XComponent.build();
51232 xtype : 'TextField',
51234 fieldLabel: "Email Address",
51237 autoCreate : {tag: "input", type: "text", size: "20"}
51240 xtype : 'TextField',
51242 fieldLabel: "Password",
51243 inputType: 'password',
51246 autoCreate : {tag: "input", type: "text", size: "20"},
51248 specialkey : function(e,ev) {
51249 if (ev.keyCode == 13) {
51250 this.form.dialog.el.mask("Logging in");
51251 this.form.doAction('submit', {
51252 url: this.form.dialog.url,
51253 method: this.form.dialog.method
51260 xtype : 'ComboBox',
51262 fieldLabel: "Language",
51265 xtype : 'SimpleStore',
51266 fields: ['lang', 'ldisp'],
51268 [ 'en', 'English' ],
51269 [ 'zh_HK' , '\u7E41\u4E2D' ],
51270 [ 'zh_CN', '\u7C21\u4E2D' ]
51274 valueField : 'lang',
51275 hiddenName: 'lang',
51277 displayField:'ldisp',
51281 triggerAction: 'all',
51282 emptyText:'Select a Language...',
51283 selectOnFocus:true,
51285 select : function(cb, rec, ix) {
51286 this.form.switchLang(rec.data.lang);
51302 text : "Forgot Password",
51304 click : function() {
51305 //console.log(this);
51306 var n = this.form.findField('username').getValue();
51308 Roo.MessageBox.alert("Error", "Fill in your email address");
51312 url: this.dialog.url,
51316 method: this.dialog.method,
51317 success: function(response, opts) { // check successfull...
51319 var res = this.dialog.processResponse(response);
51320 if (!res.success) { // error!
51321 Roo.MessageBox.alert("Error" ,
51322 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
51325 Roo.MessageBox.alert("Notice" ,
51326 "Please check you email for the Password Reset message");
51328 failure : function() {
51329 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
51342 click : function () {
51344 this.dialog.el.mask("Logging in");
51345 this.form.doAction('submit', {
51346 url: this.dialog.url,
51347 method: this.dialog.method