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 isFirefox = ua.indexOf("firefox") > -1,
57 isIE = ua.indexOf("msie") > -1,
58 isIE7 = ua.indexOf("msie 7") > -1,
59 isIE11 = /trident.*rv\:11\./.test(ua),
60 isGecko = !isSafari && ua.indexOf("gecko") > -1,
61 isBorderBox = isIE && !isStrict,
62 isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
63 isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
64 isLinux = (ua.indexOf("linux") != -1),
65 isSecure = window.location.href.toLowerCase().indexOf("https") === 0,
66 isTouch = (function() {
68 document.createEvent("TouchEvent");
75 // remove css image flicker
78 document.execCommand("BackgroundImageCache", false, true);
84 * True if the browser is in strict mode
89 * True if the page is running over SSL
94 * True when the document is fully initialized and ready for action
99 * Turn on debugging output (currently only the factory uses this)
106 * True to automatically uncache orphaned Roo.Elements periodically (defaults to true)
109 enableGarbageCollector : true,
112 * True to automatically purge event listeners after uncaching an element (defaults to false).
113 * Note: this only happens if enableGarbageCollector is true.
116 enableListenerCollection:false,
119 * URL to a blank file used by Roo when in secure mode for iframe src and onReady src to prevent
120 * the IE insecure content warning (defaults to javascript:false).
123 SSL_SECURE_URL : "javascript:false",
126 * URL to a 1x1 transparent gif image used by Roo to create inline icons with CSS background images. (Defaults to
127 * "http://Roojs.com/s.gif" and you should change this to a URL on your server).
130 BLANK_IMAGE_URL : "http:/"+"/localhost/s.gif",
132 emptyFn : function(){},
135 * Copies all the properties of config to obj if they don't already exist.
136 * @param {Object} obj The receiver of the properties
137 * @param {Object} config The source of the properties
138 * @return {Object} returns obj
140 applyIf : function(o, c){
143 if(typeof o[p] == "undefined"){ o[p] = c[p]; }
150 * Applies event listeners to elements by selectors when the document is ready.
151 * The event name is specified with an @ suffix.
154 // add a listener for click on all anchors in element with id foo
155 '#foo a@click' : function(e, t){
159 // add the same listener to multiple selectors (separated by comma BEFORE the @)
160 '#foo a, #bar span.some-class@mouseover' : function(){
165 * @param {Object} obj The list of behaviors to apply
167 addBehaviors : function(o){
169 Roo.onReady(function(){
174 var cache = {}; // simple cache for applying multiple behaviors to same selector does query multiple times
176 var parts = b.split('@');
177 if(parts[1]){ // for Object prototype breakers
180 cache[s] = Roo.select(s);
182 cache[s].on(parts[1], o[b]);
189 * Generates unique ids. If the element already has an id, it is unchanged
190 * @param {String/HTMLElement/Element} el (optional) The element to generate an id for
191 * @param {String} prefix (optional) Id prefix (defaults "Roo-gen")
192 * @return {String} The generated Id.
194 id : function(el, prefix){
195 prefix = prefix || "roo-gen";
197 var id = prefix + (++idSeed);
198 return el ? (el.id ? el.id : (el.id = id)) : id;
203 * Extends one class with another class and optionally overrides members with the passed literal. This class
204 * also adds the function "override()" to the class that can be used to override
205 * members on an instance.
206 * @param {Object} subclass The class inheriting the functionality
207 * @param {Object} superclass The class being extended
208 * @param {Object} overrides (optional) A literal with members
213 var io = function(o){
218 return function(sb, sp, overrides){
219 if(typeof sp == 'object'){ // eg. prototype, rather than function constructor..
222 sb = function(){sp.apply(this, arguments);};
224 var F = function(){}, sbp, spp = sp.prototype;
226 sbp = sb.prototype = new F();
230 if(spp.constructor == Object.prototype.constructor){
235 sb.override = function(o){
239 Roo.override(sb, overrides);
245 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
247 Roo.override(MyClass, {
248 newMethod1: function(){
251 newMethod2: function(foo){
256 * @param {Object} origclass The class to override
257 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
258 * containing one or more methods.
261 override : function(origclass, overrides){
263 var p = origclass.prototype;
264 for(var method in overrides){
265 p[method] = overrides[method];
270 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
272 Roo.namespace('Company', 'Company.data');
273 Company.Widget = function() { ... }
274 Company.data.CustomStore = function(config) { ... }
276 * @param {String} namespace1
277 * @param {String} namespace2
278 * @param {String} etc
281 namespace : function(){
282 var a=arguments, o=null, i, j, d, rt;
283 for (i=0; i<a.length; ++i) {
287 eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
288 for (j=1; j<d.length; ++j) {
289 o[d[j]]=o[d[j]] || {};
295 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
297 Roo.factory({ xns: Roo.data, xtype : 'Store', .....});
298 Roo.factory(conf, Roo.data);
300 * @param {String} classname
301 * @param {String} namespace (optional)
305 factory : function(c, ns)
307 // no xtype, no ns or c.xns - or forced off by c.xns
308 if (!c.xtype || (!ns && !c.xns) || (c.xns === false)) { // not enough info...
311 ns = c.xns ? c.xns : ns; // if c.xns is set, then use that..
312 if (c.constructor == ns[c.xtype]) {// already created...
316 if (Roo.debug) Roo.log("Roo.Factory(" + c.xtype + ")");
317 var ret = new ns[c.xtype](c);
321 c.xns = false; // prevent recursion..
325 * Logs to console if it can.
327 * @param {String|Object} string
332 if ((typeof(console) == 'undefined') || (typeof(console.log) == 'undefined')) {
339 * 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.
343 urlEncode : function(o){
349 var ov = o[key], k = Roo.encodeURIComponent(key);
350 var type = typeof ov;
351 if(type == 'undefined'){
353 }else if(type != "function" && type != "object"){
354 buf.push(k, "=", Roo.encodeURIComponent(ov), "&");
355 }else if(ov instanceof Array){
357 for(var i = 0, len = ov.length; i < len; i++) {
358 buf.push(k, "=", Roo.encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
369 * Safe version of encodeURIComponent
370 * @param {String} data
374 encodeURIComponent : function (data)
377 return encodeURIComponent(data);
378 } catch(e) {} // should be an uri encode error.
380 if (data == '' || data == null){
383 // http://stackoverflow.com/questions/2596483/unicode-and-uri-encoding-decoding-and-escaping-in-javascript
384 function nibble_to_hex(nibble){
385 var chars = '0123456789ABCDEF';
386 return chars.charAt(nibble);
388 data = data.toString();
390 for(var i=0; i<data.length; i++){
391 var c = data.charCodeAt(i);
392 var bs = new Array();
395 bs[0] = 0xF0 | ((c & 0x1C0000) >>> 18);
396 bs[1] = 0x80 | ((c & 0x3F000) >>> 12);
397 bs[2] = 0x80 | ((c & 0xFC0) >>> 6);
398 bs[3] = 0x80 | (c & 0x3F);
399 }else if (c > 0x800){
401 bs[0] = 0xE0 | ((c & 0xF000) >>> 12);
402 bs[1] = 0x80 | ((c & 0xFC0) >>> 6);
403 bs[2] = 0x80 | (c & 0x3F);
406 bs[0] = 0xC0 | ((c & 0x7C0) >>> 6);
407 bs[1] = 0x80 | (c & 0x3F);
412 for(var j=0; j<bs.length; j++){
414 var hex = nibble_to_hex((b & 0xF0) >>> 4)
415 + nibble_to_hex(b &0x0F);
424 * 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]}.
425 * @param {String} string
426 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
427 * @return {Object} A literal with members
429 urlDecode : function(string, overwrite){
430 if(!string || !string.length){
434 var pairs = string.split('&');
435 var pair, name, value;
436 for(var i = 0, len = pairs.length; i < len; i++){
437 pair = pairs[i].split('=');
438 name = decodeURIComponent(pair[0]);
439 value = decodeURIComponent(pair[1]);
440 if(overwrite !== true){
441 if(typeof obj[name] == "undefined"){
443 }else if(typeof obj[name] == "string"){
444 obj[name] = [obj[name]];
445 obj[name].push(value);
447 obj[name].push(value);
457 * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
458 * passed array is not really an array, your function is called once with it.
459 * The supplied function is called with (Object item, Number index, Array allItems).
460 * @param {Array/NodeList/Mixed} array
461 * @param {Function} fn
462 * @param {Object} scope
464 each : function(array, fn, scope){
465 if(typeof array.length == "undefined" || typeof array == "string"){
468 for(var i = 0, len = array.length; i < len; i++){
469 if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
474 combine : function(){
475 var as = arguments, l = as.length, r = [];
476 for(var i = 0; i < l; i++){
478 if(a instanceof Array){
480 }else if(a.length !== undefined && !a.substr){
481 r = r.concat(Array.prototype.slice.call(a, 0));
490 * Escapes the passed string for use in a regular expression
491 * @param {String} str
494 escapeRe : function(s) {
495 return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
499 callback : function(cb, scope, args, delay){
500 if(typeof cb == "function"){
502 cb.defer(delay, scope, args || []);
504 cb.apply(scope, args || []);
510 * Return the dom node for the passed string (id), dom node, or Roo.Element
511 * @param {String/HTMLElement/Roo.Element} el
512 * @return HTMLElement
514 getDom : function(el){
518 return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
522 * Shorthand for {@link Roo.ComponentMgr#get}
524 * @return Roo.Component
526 getCmp : function(id){
527 return Roo.ComponentMgr.get(id);
530 num : function(v, defaultValue){
531 if(typeof v != 'number'){
537 destroy : function(){
538 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
542 as.removeAllListeners();
546 if(typeof as.purgeListeners == 'function'){
549 if(typeof as.destroy == 'function'){
556 // inpired by a similar function in mootools library
558 * Returns the type of object that is passed in. If the object passed in is null or undefined it
559 * return false otherwise it returns one of the following values:<ul>
560 * <li><b>string</b>: If the object passed is a string</li>
561 * <li><b>number</b>: If the object passed is a number</li>
562 * <li><b>boolean</b>: If the object passed is a boolean value</li>
563 * <li><b>function</b>: If the object passed is a function reference</li>
564 * <li><b>object</b>: If the object passed is an object</li>
565 * <li><b>array</b>: If the object passed is an array</li>
566 * <li><b>regexp</b>: If the object passed is a regular expression</li>
567 * <li><b>element</b>: If the object passed is a DOM Element</li>
568 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
569 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
570 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
571 * @param {Mixed} object
575 if(o === undefined || o === null){
582 if(t == 'object' && o.nodeName) {
584 case 1: return 'element';
585 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
588 if(t == 'object' || t == 'function') {
589 switch(o.constructor) {
590 case Array: return 'array';
591 case RegExp: return 'regexp';
593 if(typeof o.length == 'number' && typeof o.item == 'function') {
601 * Returns true if the passed value is null, undefined or an empty string (optional).
602 * @param {Mixed} value The value to test
603 * @param {Boolean} allowBlank (optional) Pass true if an empty string is not considered empty
606 isEmpty : function(v, allowBlank){
607 return v === null || v === undefined || (!allowBlank ? v === '' : false);
615 isFirefox : isFirefox,
625 isBorderBox : isBorderBox,
627 isWindows : isWindows,
636 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
637 * you may want to set this to true.
640 useShims : ((isIE && !isIE7) || (isGecko && isMac)),
645 * Selects a single element as a Roo Element
646 * This is about as close as you can get to jQuery's $('do crazy stuff')
647 * @param {String} selector The selector/xpath query
648 * @param {Node} root (optional) The start of the query (defaults to document).
649 * @return {Roo.Element}
651 selectNode : function(selector, root)
653 var node = Roo.DomQuery.selectNode(selector,root);
654 return node ? Roo.get(node) : new Roo.Element(false);
662 Roo.namespace("Roo", "Roo.util", "Roo.grid", "Roo.dd", "Roo.tree", "Roo.data",
663 "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout",
666 "Roo.bootstrap.dash");
669 * Ext JS Library 1.1.1
670 * Copyright(c) 2006-2007, Ext JS, LLC.
672 * Originally Released Under LGPL - original licence link has changed is not relivant.
675 * <script type="text/javascript">
679 // wrappedn so fnCleanup is not in global scope...
681 function fnCleanUp() {
682 var p = Function.prototype;
683 delete p.createSequence;
685 delete p.createDelegate;
686 delete p.createCallback;
687 delete p.createInterceptor;
689 window.detachEvent("onunload", fnCleanUp);
691 window.attachEvent("onunload", fnCleanUp);
698 * These functions are available on every Function object (any JavaScript function).
700 Roo.apply(Function.prototype, {
702 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
703 * Call directly on any function. Example: <code>myFunction.createCallback(myarg, myarg2)</code>
704 * Will create a function that is bound to those 2 args.
705 * @return {Function} The new function
707 createCallback : function(/*args...*/){
708 // make args available, in function below
709 var args = arguments;
712 return method.apply(window, args);
717 * Creates a delegate (callback) that sets the scope to obj.
718 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this)</code>
719 * Will create a function that is automatically scoped to this.
720 * @param {Object} obj (optional) The object for which the scope is set
721 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
722 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
723 * if a number the args are inserted at the specified position
724 * @return {Function} The new function
726 createDelegate : function(obj, args, appendArgs){
729 var callArgs = args || arguments;
730 if(appendArgs === true){
731 callArgs = Array.prototype.slice.call(arguments, 0);
732 callArgs = callArgs.concat(args);
733 }else if(typeof appendArgs == "number"){
734 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
735 var applyArgs = [appendArgs, 0].concat(args); // create method call params
736 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
738 return method.apply(obj || window, callArgs);
743 * Calls this function after the number of millseconds specified.
744 * @param {Number} millis The number of milliseconds for the setTimeout call (if 0 the function is executed immediately)
745 * @param {Object} obj (optional) The object for which the scope is set
746 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
747 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
748 * if a number the args are inserted at the specified position
749 * @return {Number} The timeout id that can be used with clearTimeout
751 defer : function(millis, obj, args, appendArgs){
752 var fn = this.createDelegate(obj, args, appendArgs);
754 return setTimeout(fn, millis);
760 * Create a combined function call sequence of the original function + the passed function.
761 * The resulting function returns the results of the original function.
762 * The passed fcn is called with the parameters of the original function
763 * @param {Function} fcn The function to sequence
764 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
765 * @return {Function} The new function
767 createSequence : function(fcn, scope){
768 if(typeof fcn != "function"){
773 var retval = method.apply(this || window, arguments);
774 fcn.apply(scope || this || window, arguments);
780 * Creates an interceptor function. The passed fcn is called before the original one. If it returns false, the original one is not called.
781 * The resulting function returns the results of the original function.
782 * The passed fcn is called with the parameters of the original function.
784 * @param {Function} fcn The function to call before the original
785 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
786 * @return {Function} The new function
788 createInterceptor : function(fcn, scope){
789 if(typeof fcn != "function"){
796 if(fcn.apply(scope || this || window, arguments) === false){
799 return method.apply(this || window, arguments);
805 * Ext JS Library 1.1.1
806 * Copyright(c) 2006-2007, Ext JS, LLC.
808 * Originally Released Under LGPL - original licence link has changed is not relivant.
811 * <script type="text/javascript">
814 Roo.applyIf(String, {
819 * Escapes the passed string for ' and \
820 * @param {String} string The string to escape
821 * @return {String} The escaped string
824 escape : function(string) {
825 return string.replace(/('|\\)/g, "\\$1");
829 * Pads the left side of a string with a specified character. This is especially useful
830 * for normalizing number and date strings. Example usage:
832 var s = String.leftPad('123', 5, '0');
833 // s now contains the string: '00123'
835 * @param {String} string The original string
836 * @param {Number} size The total length of the output string
837 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
838 * @return {String} The padded string
841 leftPad : function (val, size, ch) {
842 var result = new String(val);
843 if(ch === null || ch === undefined || ch === '') {
846 while (result.length < size) {
847 result = ch + result;
853 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
854 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
856 var cls = 'my-class', text = 'Some text';
857 var s = String.format('<div class="{0}">{1}</div>', cls, text);
858 // s now contains the string: '<div class="my-class">Some text</div>'
860 * @param {String} string The tokenized string to be formatted
861 * @param {String} value1 The value to replace token {0}
862 * @param {String} value2 Etc...
863 * @return {String} The formatted string
866 format : function(format){
867 var args = Array.prototype.slice.call(arguments, 1);
868 return format.replace(/\{(\d+)\}/g, function(m, i){
869 return Roo.util.Format.htmlEncode(args[i]);
875 * Utility function that allows you to easily switch a string between two alternating values. The passed value
876 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
877 * they are already different, the first value passed in is returned. Note that this method returns the new value
878 * but does not change the current string.
880 // alternate sort directions
881 sort = sort.toggle('ASC', 'DESC');
883 // instead of conditional logic:
884 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
886 * @param {String} value The value to compare to the current string
887 * @param {String} other The new value to use if the string already equals the first value passed in
888 * @return {String} The new value
891 String.prototype.toggle = function(value, other){
892 return this == value ? other : value;
895 * Ext JS Library 1.1.1
896 * Copyright(c) 2006-2007, Ext JS, LLC.
898 * Originally Released Under LGPL - original licence link has changed is not relivant.
901 * <script type="text/javascript">
907 Roo.applyIf(Number.prototype, {
909 * Checks whether or not the current number is within a desired range. If the number is already within the
910 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
911 * exceeded. Note that this method returns the constrained value but does not change the current number.
912 * @param {Number} min The minimum number in the range
913 * @param {Number} max The maximum number in the range
914 * @return {Number} The constrained value if outside the range, otherwise the current value
916 constrain : function(min, max){
917 return Math.min(Math.max(this, min), max);
921 * Ext JS Library 1.1.1
922 * Copyright(c) 2006-2007, Ext JS, LLC.
924 * Originally Released Under LGPL - original licence link has changed is not relivant.
927 * <script type="text/javascript">
932 Roo.applyIf(Array.prototype, {
935 * Checks whether or not the specified object exists in the array.
936 * @param {Object} o The object to check for
937 * @return {Number} The index of o in the array (or -1 if it is not found)
939 indexOf : function(o){
940 for (var i = 0, len = this.length; i < len; i++){
941 if(this[i] == o) return i;
947 * Removes the specified object from the array. If the object is not found nothing happens.
948 * @param {Object} o The object to remove
950 remove : function(o){
951 var index = this.indexOf(o);
953 this.splice(index, 1);
957 * Map (JS 1.6 compatibility)
958 * @param {Function} function to call
962 var len = this.length >>> 0;
963 if (typeof fun != "function")
964 throw new TypeError();
966 var res = new Array(len);
967 var thisp = arguments[1];
968 for (var i = 0; i < len; i++)
971 res[i] = fun.call(thisp, this[i], i, this);
982 * Ext JS Library 1.1.1
983 * Copyright(c) 2006-2007, Ext JS, LLC.
985 * Originally Released Under LGPL - original licence link has changed is not relivant.
988 * <script type="text/javascript">
994 * The date parsing and format syntax is a subset of
995 * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
996 * supported will provide results equivalent to their PHP versions.
998 * Following is the list of all currently supported formats:
1001 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
1003 Format Output Description
1004 ------ ---------- --------------------------------------------------------------
1005 d 10 Day of the month, 2 digits with leading zeros
1006 D Wed A textual representation of a day, three letters
1007 j 10 Day of the month without leading zeros
1008 l Wednesday A full textual representation of the day of the week
1009 S th English ordinal day of month suffix, 2 chars (use with j)
1010 w 3 Numeric representation of the day of the week
1011 z 9 The julian date, or day of the year (0-365)
1012 W 01 ISO-8601 2-digit week number of year, weeks starting on Monday (00-52)
1013 F January A full textual representation of the month
1014 m 01 Numeric representation of a month, with leading zeros
1015 M Jan Month name abbreviation, three letters
1016 n 1 Numeric representation of a month, without leading zeros
1017 t 31 Number of days in the given month
1018 L 0 Whether it's a leap year (1 if it is a leap year, else 0)
1019 Y 2007 A full numeric representation of a year, 4 digits
1020 y 07 A two digit representation of a year
1021 a pm Lowercase Ante meridiem and Post meridiem
1022 A PM Uppercase Ante meridiem and Post meridiem
1023 g 3 12-hour format of an hour without leading zeros
1024 G 15 24-hour format of an hour without leading zeros
1025 h 03 12-hour format of an hour with leading zeros
1026 H 15 24-hour format of an hour with leading zeros
1027 i 05 Minutes with leading zeros
1028 s 01 Seconds, with leading zeros
1029 O -0600 Difference to Greenwich time (GMT) in hours (Allows +08, without minutes)
1030 P -06:00 Difference to Greenwich time (GMT) with colon between hours and minutes
1031 T CST Timezone setting of the machine running the code
1032 Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east)
1035 * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
1037 var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
1038 document.write(dt.format('Y-m-d')); //2007-01-10
1039 document.write(dt.format('F j, Y, g:i a')); //January 10, 2007, 3:05 pm
1040 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
1043 * Here are some standard date/time patterns that you might find helpful. They
1044 * are not part of the source of Date.js, but to use them you can simply copy this
1045 * block of code into any script that is included after Date.js and they will also become
1046 * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
1049 ISO8601Long:"Y-m-d H:i:s",
1050 ISO8601Short:"Y-m-d",
1052 LongDate: "l, F d, Y",
1053 FullDateTime: "l, F d, Y g:i:s A",
1056 LongTime: "g:i:s A",
1057 SortableDateTime: "Y-m-d\\TH:i:s",
1058 UniversalSortableDateTime: "Y-m-d H:i:sO",
1065 var dt = new Date();
1066 document.write(dt.format(Date.patterns.ShortDate));
1071 * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
1072 * They generate precompiled functions from date formats instead of parsing and
1073 * processing the pattern every time you format a date. These functions are available
1074 * on every Date object (any javascript function).
1076 * The original article and download are here:
1077 * http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
1084 Returns the number of milliseconds between this date and date
1085 @param {Date} date (optional) Defaults to now
1086 @return {Number} The diff in milliseconds
1087 @member Date getElapsed
1089 Date.prototype.getElapsed = function(date) {
1090 return Math.abs((date || new Date()).getTime()-this.getTime());
1092 // was in date file..
1096 Date.parseFunctions = {count:0};
1098 Date.parseRegexes = [];
1100 Date.formatFunctions = {count:0};
1103 Date.prototype.dateFormat = function(format) {
1104 if (Date.formatFunctions[format] == null) {
1105 Date.createNewFormat(format);
1107 var func = Date.formatFunctions[format];
1108 return this[func]();
1113 * Formats a date given the supplied format string
1114 * @param {String} format The format string
1115 * @return {String} The formatted date
1118 Date.prototype.format = Date.prototype.dateFormat;
1121 Date.createNewFormat = function(format) {
1122 var funcName = "format" + Date.formatFunctions.count++;
1123 Date.formatFunctions[format] = funcName;
1124 var code = "Date.prototype." + funcName + " = function(){return ";
1125 var special = false;
1127 for (var i = 0; i < format.length; ++i) {
1128 ch = format.charAt(i);
1129 if (!special && ch == "\\") {
1134 code += "'" + String.escape(ch) + "' + ";
1137 code += Date.getFormatCode(ch);
1140 /** eval:var:zzzzzzzzzzzzz */
1141 eval(code.substring(0, code.length - 3) + ";}");
1145 Date.getFormatCode = function(character) {
1146 switch (character) {
1148 return "String.leftPad(this.getDate(), 2, '0') + ";
1150 return "Date.dayNames[this.getDay()].substring(0, 3) + ";
1152 return "this.getDate() + ";
1154 return "Date.dayNames[this.getDay()] + ";
1156 return "this.getSuffix() + ";
1158 return "this.getDay() + ";
1160 return "this.getDayOfYear() + ";
1162 return "this.getWeekOfYear() + ";
1164 return "Date.monthNames[this.getMonth()] + ";
1166 return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
1168 return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
1170 return "(this.getMonth() + 1) + ";
1172 return "this.getDaysInMonth() + ";
1174 return "(this.isLeapYear() ? 1 : 0) + ";
1176 return "this.getFullYear() + ";
1178 return "('' + this.getFullYear()).substring(2, 4) + ";
1180 return "(this.getHours() < 12 ? 'am' : 'pm') + ";
1182 return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
1184 return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";
1186 return "this.getHours() + ";
1188 return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
1190 return "String.leftPad(this.getHours(), 2, '0') + ";
1192 return "String.leftPad(this.getMinutes(), 2, '0') + ";
1194 return "String.leftPad(this.getSeconds(), 2, '0') + ";
1196 return "this.getGMTOffset() + ";
1198 return "this.getGMTColonOffset() + ";
1200 return "this.getTimezone() + ";
1202 return "(this.getTimezoneOffset() * -60) + ";
1204 return "'" + String.escape(character) + "' + ";
1209 * Parses the passed string using the specified format. Note that this function expects dates in normal calendar
1210 * format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of
1211 * the date format that is not specified will default to the current date value for that part. Time parts can also
1212 * be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format
1213 * string or the parse operation will fail.
1216 //dt = Fri May 25 2007 (current date)
1217 var dt = new Date();
1219 //dt = Thu May 25 2006 (today's month/day in 2006)
1220 dt = Date.parseDate("2006", "Y");
1222 //dt = Sun Jan 15 2006 (all date parts specified)
1223 dt = Date.parseDate("2006-1-15", "Y-m-d");
1225 //dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)
1226 dt = Date.parseDate("2006-1-15 3:20:01 PM", "Y-m-d h:i:s A" );
1228 * @param {String} input The unparsed date as a string
1229 * @param {String} format The format the date is in
1230 * @return {Date} The parsed date
1233 Date.parseDate = function(input, format) {
1234 if (Date.parseFunctions[format] == null) {
1235 Date.createParser(format);
1237 var func = Date.parseFunctions[format];
1238 return Date[func](input);
1244 Date.createParser = function(format) {
1245 var funcName = "parse" + Date.parseFunctions.count++;
1246 var regexNum = Date.parseRegexes.length;
1247 var currentGroup = 1;
1248 Date.parseFunctions[format] = funcName;
1250 var code = "Date." + funcName + " = function(input){\n"
1251 + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, o, z, v;\n"
1252 + "var d = new Date();\n"
1253 + "y = d.getFullYear();\n"
1254 + "m = d.getMonth();\n"
1255 + "d = d.getDate();\n"
1256 + "if (typeof(input) !== 'string') { input = input.toString(); }\n"
1257 + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
1258 + "if (results && results.length > 0) {";
1261 var special = false;
1263 for (var i = 0; i < format.length; ++i) {
1264 ch = format.charAt(i);
1265 if (!special && ch == "\\") {
1270 regex += String.escape(ch);
1273 var obj = Date.formatCodeToRegex(ch, currentGroup);
1274 currentGroup += obj.g;
1276 if (obj.g && obj.c) {
1282 code += "if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
1283 + "{v = new Date(y, m, d, h, i, s);}\n"
1284 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
1285 + "{v = new Date(y, m, d, h, i);}\n"
1286 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
1287 + "{v = new Date(y, m, d, h);}\n"
1288 + "else if (y >= 0 && m >= 0 && d > 0)\n"
1289 + "{v = new Date(y, m, d);}\n"
1290 + "else if (y >= 0 && m >= 0)\n"
1291 + "{v = new Date(y, m);}\n"
1292 + "else if (y >= 0)\n"
1293 + "{v = new Date(y);}\n"
1294 + "}return (v && (z || o))?\n" // favour UTC offset over GMT offset
1295 + " ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset
1296 + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset
1299 Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
1300 /** eval:var:zzzzzzzzzzzzz */
1305 Date.formatCodeToRegex = function(character, currentGroup) {
1306 switch (character) {
1310 s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
1313 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1314 s:"(\\d{1,2})"}; // day of month without leading zeroes
1317 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1318 s:"(\\d{2})"}; // day of month with leading zeroes
1322 s:"(?:" + Date.dayNames.join("|") + ")"};
1326 s:"(?:st|nd|rd|th)"};
1341 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
1342 s:"(" + Date.monthNames.join("|") + ")"};
1345 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
1346 s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
1349 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1350 s:"(\\d{1,2})"}; // Numeric representation of a month, without leading zeros
1353 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1354 s:"(\\d{2})"}; // Numeric representation of a month, with leading zeros
1365 c:"y = parseInt(results[" + currentGroup + "], 10);\n",
1369 c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
1370 + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
1374 c:"if (results[" + currentGroup + "] == 'am') {\n"
1375 + "if (h == 12) { h = 0; }\n"
1376 + "} else { if (h < 12) { h += 12; }}",
1380 c:"if (results[" + currentGroup + "] == 'AM') {\n"
1381 + "if (h == 12) { h = 0; }\n"
1382 + "} else { if (h < 12) { h += 12; }}",
1387 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1388 s:"(\\d{1,2})"}; // 12/24-hr format format of an hour without leading zeroes
1392 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1393 s:"(\\d{2})"}; // 12/24-hr format format of an hour with leading zeroes
1396 c:"i = parseInt(results[" + currentGroup + "], 10);\n",
1400 c:"s = parseInt(results[" + currentGroup + "], 10);\n",
1405 "o = results[", currentGroup, "];\n",
1406 "var sn = o.substring(0,1);\n", // get + / - sign
1407 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n", // get hours (performs minutes-to-hour conversion also)
1408 "var mn = o.substring(3,5) % 60;\n", // get minutes
1409 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
1410 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1412 s:"([+\-]\\d{2,4})"};
1418 "o = results[", currentGroup, "];\n",
1419 "var sn = o.substring(0,1);\n",
1420 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);\n",
1421 "var mn = o.substring(4,6) % 60;\n",
1422 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n",
1423 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1429 s:"[A-Z]{1,4}"}; // timezone abbrev. may be between 1 - 4 chars
1432 c:"z = results[" + currentGroup + "];\n" // -43200 <= UTC offset <= 50400
1433 + "z = (-43200 <= z*1 && z*1 <= 50400)? z : null;\n",
1434 s:"([+\-]?\\d{1,5})"}; // leading '+' sign is optional for UTC offset
1438 s:String.escape(character)};
1443 * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1444 * @return {String} The abbreviated timezone name (e.g. 'CST')
1446 Date.prototype.getTimezone = function() {
1447 return this.toString().replace(/^.*? ([A-Z]{1,4})[\-+][0-9]{4} .*$/, "$1");
1451 * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
1452 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600')
1454 Date.prototype.getGMTOffset = function() {
1455 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1456 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1457 + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
1461 * Get the offset from GMT of the current date (equivalent to the format specifier 'P').
1462 * @return {String} 2-characters representing hours and 2-characters representing minutes
1463 * seperated by a colon and prefixed with + or - (e.g. '-06:00')
1465 Date.prototype.getGMTColonOffset = function() {
1466 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1467 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1469 + String.leftPad(this.getTimezoneOffset() %60, 2, "0");
1473 * Get the numeric day number of the year, adjusted for leap year.
1474 * @return {Number} 0 through 364 (365 in leap years)
1476 Date.prototype.getDayOfYear = function() {
1478 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1479 for (var i = 0; i < this.getMonth(); ++i) {
1480 num += Date.daysInMonth[i];
1482 return num + this.getDate() - 1;
1486 * Get the string representation of the numeric week number of the year
1487 * (equivalent to the format specifier 'W').
1488 * @return {String} '00' through '52'
1490 Date.prototype.getWeekOfYear = function() {
1491 // Skip to Thursday of this week
1492 var now = this.getDayOfYear() + (4 - this.getDay());
1493 // Find the first Thursday of the year
1494 var jan1 = new Date(this.getFullYear(), 0, 1);
1495 var then = (7 - jan1.getDay() + 4);
1496 return String.leftPad(((now - then) / 7) + 1, 2, "0");
1500 * Whether or not the current date is in a leap year.
1501 * @return {Boolean} True if the current date is in a leap year, else false
1503 Date.prototype.isLeapYear = function() {
1504 var year = this.getFullYear();
1505 return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
1509 * Get the first day of the current month, adjusted for leap year. The returned value
1510 * is the numeric day index within the week (0-6) which can be used in conjunction with
1511 * the {@link #monthNames} array to retrieve the textual day name.
1514 var dt = new Date('1/10/2007');
1515 document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
1517 * @return {Number} The day number (0-6)
1519 Date.prototype.getFirstDayOfMonth = function() {
1520 var day = (this.getDay() - (this.getDate() - 1)) % 7;
1521 return (day < 0) ? (day + 7) : day;
1525 * Get the last day of the current month, adjusted for leap year. The returned value
1526 * is the numeric day index within the week (0-6) which can be used in conjunction with
1527 * the {@link #monthNames} array to retrieve the textual day name.
1530 var dt = new Date('1/10/2007');
1531 document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
1533 * @return {Number} The day number (0-6)
1535 Date.prototype.getLastDayOfMonth = function() {
1536 var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
1537 return (day < 0) ? (day + 7) : day;
1542 * Get the first date of this date's month
1545 Date.prototype.getFirstDateOfMonth = function() {
1546 return new Date(this.getFullYear(), this.getMonth(), 1);
1550 * Get the last date of this date's month
1553 Date.prototype.getLastDateOfMonth = function() {
1554 return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
1557 * Get the number of days in the current month, adjusted for leap year.
1558 * @return {Number} The number of days in the month
1560 Date.prototype.getDaysInMonth = function() {
1561 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1562 return Date.daysInMonth[this.getMonth()];
1566 * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
1567 * @return {String} 'st, 'nd', 'rd' or 'th'
1569 Date.prototype.getSuffix = function() {
1570 switch (this.getDate()) {
1587 Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
1590 * An array of textual month names.
1591 * Override these values for international dates, for example...
1592 * Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...];
1611 * An array of textual day names.
1612 * Override these values for international dates, for example...
1613 * Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...];
1629 Date.monthNumbers = {
1644 * Creates and returns a new Date instance with the exact same date value as the called instance.
1645 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
1646 * variable will also be changed. When the intention is to create a new variable that will not
1647 * modify the original instance, you should create a clone.
1649 * Example of correctly cloning a date:
1652 var orig = new Date('10/1/2006');
1655 document.write(orig); //returns 'Thu Oct 05 2006'!
1658 var orig = new Date('10/1/2006');
1659 var copy = orig.clone();
1661 document.write(orig); //returns 'Thu Oct 01 2006'
1663 * @return {Date} The new Date instance
1665 Date.prototype.clone = function() {
1666 return new Date(this.getTime());
1670 * Clears any time information from this date
1671 @param {Boolean} clone true to create a clone of this date, clear the time and return it
1672 @return {Date} this or the clone
1674 Date.prototype.clearTime = function(clone){
1676 return this.clone().clearTime();
1681 this.setMilliseconds(0);
1686 // safari setMonth is broken
1688 Date.brokenSetMonth = Date.prototype.setMonth;
1689 Date.prototype.setMonth = function(num){
1691 var n = Math.ceil(-num);
1692 var back_year = Math.ceil(n/12);
1693 var month = (n % 12) ? 12 - n % 12 : 0 ;
1694 this.setFullYear(this.getFullYear() - back_year);
1695 return Date.brokenSetMonth.call(this, month);
1697 return Date.brokenSetMonth.apply(this, arguments);
1702 /** Date interval constant
1706 /** Date interval constant
1710 /** Date interval constant
1714 /** Date interval constant
1718 /** Date interval constant
1722 /** Date interval constant
1726 /** Date interval constant
1732 * Provides a convenient method of performing basic date arithmetic. This method
1733 * does not modify the Date instance being called - it creates and returns
1734 * a new Date instance containing the resulting date value.
1739 var dt = new Date('10/29/2006').add(Date.DAY, 5);
1740 document.write(dt); //returns 'Fri Oct 06 2006 00:00:00'
1742 //Negative values will subtract correctly:
1743 var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
1744 document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
1746 //You can even chain several calls together in one line!
1747 var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
1748 document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
1751 * @param {String} interval A valid date interval enum value
1752 * @param {Number} value The amount to add to the current date
1753 * @return {Date} The new Date instance
1755 Date.prototype.add = function(interval, value){
1756 var d = this.clone();
1757 if (!interval || value === 0) return d;
1758 switch(interval.toLowerCase()){
1760 d.setMilliseconds(this.getMilliseconds() + value);
1763 d.setSeconds(this.getSeconds() + value);
1766 d.setMinutes(this.getMinutes() + value);
1769 d.setHours(this.getHours() + value);
1772 d.setDate(this.getDate() + value);
1775 var day = this.getDate();
1777 day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
1780 d.setMonth(this.getMonth() + value);
1783 d.setFullYear(this.getFullYear() + value);
1790 * Ext JS Library 1.1.1
1791 * Copyright(c) 2006-2007, Ext JS, LLC.
1793 * Originally Released Under LGPL - original licence link has changed is not relivant.
1796 * <script type="text/javascript">
1800 * @class Roo.lib.Dom
1803 * Dom utils (from YIU afaik)
1808 * Get the view width
1809 * @param {Boolean} full True will get the full document, otherwise it's the view width
1810 * @return {Number} The width
1813 getViewWidth : function(full) {
1814 return full ? this.getDocumentWidth() : this.getViewportWidth();
1817 * Get the view height
1818 * @param {Boolean} full True will get the full document, otherwise it's the view height
1819 * @return {Number} The height
1821 getViewHeight : function(full) {
1822 return full ? this.getDocumentHeight() : this.getViewportHeight();
1825 getDocumentHeight: function() {
1826 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
1827 return Math.max(scrollHeight, this.getViewportHeight());
1830 getDocumentWidth: function() {
1831 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
1832 return Math.max(scrollWidth, this.getViewportWidth());
1835 getViewportHeight: function() {
1836 var height = self.innerHeight;
1837 var mode = document.compatMode;
1839 if ((mode || Roo.isIE) && !Roo.isOpera) {
1840 height = (mode == "CSS1Compat") ?
1841 document.documentElement.clientHeight :
1842 document.body.clientHeight;
1848 getViewportWidth: function() {
1849 var width = self.innerWidth;
1850 var mode = document.compatMode;
1852 if (mode || Roo.isIE) {
1853 width = (mode == "CSS1Compat") ?
1854 document.documentElement.clientWidth :
1855 document.body.clientWidth;
1860 isAncestor : function(p, c) {
1867 if (p.contains && !Roo.isSafari) {
1868 return p.contains(c);
1869 } else if (p.compareDocumentPosition) {
1870 return !!(p.compareDocumentPosition(c) & 16);
1872 var parent = c.parentNode;
1877 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
1880 parent = parent.parentNode;
1886 getRegion : function(el) {
1887 return Roo.lib.Region.getRegion(el);
1890 getY : function(el) {
1891 return this.getXY(el)[1];
1894 getX : function(el) {
1895 return this.getXY(el)[0];
1898 getXY : function(el) {
1899 var p, pe, b, scroll, bd = document.body;
1900 el = Roo.getDom(el);
1901 var fly = Roo.lib.AnimBase.fly;
1902 if (el.getBoundingClientRect) {
1903 b = el.getBoundingClientRect();
1904 scroll = fly(document).getScroll();
1905 return [b.left + scroll.left, b.top + scroll.top];
1911 var hasAbsolute = fly(el).getStyle("position") == "absolute";
1918 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
1925 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1926 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1933 if (p != el && pe.getStyle('overflow') != 'visible') {
1941 if (Roo.isSafari && hasAbsolute) {
1946 if (Roo.isGecko && !hasAbsolute) {
1948 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1949 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1953 while (p && p != bd) {
1954 if (!Roo.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
1966 setXY : function(el, xy) {
1967 el = Roo.fly(el, '_setXY');
1969 var pts = el.translatePoints(xy);
1970 if (xy[0] !== false) {
1971 el.dom.style.left = pts.left + "px";
1973 if (xy[1] !== false) {
1974 el.dom.style.top = pts.top + "px";
1978 setX : function(el, x) {
1979 this.setXY(el, [x, false]);
1982 setY : function(el, y) {
1983 this.setXY(el, [false, y]);
1987 * Portions of this file are based on pieces of Yahoo User Interface Library
1988 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
1989 * YUI licensed under the BSD License:
1990 * http://developer.yahoo.net/yui/license.txt
1991 * <script type="text/javascript">
1995 Roo.lib.Event = function() {
1996 var loadComplete = false;
1998 var unloadListeners = [];
2000 var onAvailStack = [];
2002 var lastError = null;
2015 startInterval: function() {
2016 if (!this._interval) {
2018 var callback = function() {
2019 self._tryPreloadAttach();
2021 this._interval = setInterval(callback, this.POLL_INTERVAL);
2026 onAvailable: function(p_id, p_fn, p_obj, p_override) {
2027 onAvailStack.push({ id: p_id,
2030 override: p_override,
2031 checkReady: false });
2033 retryCount = this.POLL_RETRYS;
2034 this.startInterval();
2038 addListener: function(el, eventName, fn) {
2039 el = Roo.getDom(el);
2044 if ("unload" == eventName) {
2045 unloadListeners[unloadListeners.length] =
2046 [el, eventName, fn];
2050 var wrappedFn = function(e) {
2051 return fn(Roo.lib.Event.getEvent(e));
2054 var li = [el, eventName, fn, wrappedFn];
2056 var index = listeners.length;
2057 listeners[index] = li;
2059 this.doAdd(el, eventName, wrappedFn, false);
2065 removeListener: function(el, eventName, fn) {
2068 el = Roo.getDom(el);
2071 return this.purgeElement(el, false, eventName);
2075 if ("unload" == eventName) {
2077 for (i = 0,len = unloadListeners.length; i < len; i++) {
2078 var li = unloadListeners[i];
2081 li[1] == eventName &&
2083 unloadListeners.splice(i, 1);
2091 var cacheItem = null;
2094 var index = arguments[3];
2096 if ("undefined" == typeof index) {
2097 index = this._getCacheIndex(el, eventName, fn);
2101 cacheItem = listeners[index];
2104 if (!el || !cacheItem) {
2108 this.doRemove(el, eventName, cacheItem[this.WFN], false);
2110 delete listeners[index][this.WFN];
2111 delete listeners[index][this.FN];
2112 listeners.splice(index, 1);
2119 getTarget: function(ev, resolveTextNode) {
2120 ev = ev.browserEvent || ev;
2121 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2122 var t = ev.target || ev.srcElement;
2123 return this.resolveTextNode(t);
2127 resolveTextNode: function(node) {
2128 if (Roo.isSafari && node && 3 == node.nodeType) {
2129 return node.parentNode;
2136 getPageX: function(ev) {
2137 ev = ev.browserEvent || ev;
2138 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2140 if (!x && 0 !== x) {
2141 x = ev.clientX || 0;
2144 x += this.getScroll()[1];
2152 getPageY: function(ev) {
2153 ev = ev.browserEvent || ev;
2154 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2156 if (!y && 0 !== y) {
2157 y = ev.clientY || 0;
2160 y += this.getScroll()[0];
2169 getXY: function(ev) {
2170 ev = ev.browserEvent || ev;
2171 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2172 return [this.getPageX(ev), this.getPageY(ev)];
2176 getRelatedTarget: function(ev) {
2177 ev = ev.browserEvent || ev;
2178 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2179 var t = ev.relatedTarget;
2181 if (ev.type == "mouseout") {
2183 } else if (ev.type == "mouseover") {
2188 return this.resolveTextNode(t);
2192 getTime: function(ev) {
2193 ev = ev.browserEvent || ev;
2194 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2196 var t = new Date().getTime();
2200 this.lastError = ex;
2209 stopEvent: function(ev) {
2210 this.stopPropagation(ev);
2211 this.preventDefault(ev);
2215 stopPropagation: function(ev) {
2216 ev = ev.browserEvent || ev;
2217 if (ev.stopPropagation) {
2218 ev.stopPropagation();
2220 ev.cancelBubble = true;
2225 preventDefault: function(ev) {
2226 ev = ev.browserEvent || ev;
2227 if(ev.preventDefault) {
2228 ev.preventDefault();
2230 ev.returnValue = false;
2235 getEvent: function(e) {
2236 var ev = e || window.event;
2238 var c = this.getEvent.caller;
2240 ev = c.arguments[0];
2241 if (ev && Event == ev.constructor) {
2251 getCharCode: function(ev) {
2252 ev = ev.browserEvent || ev;
2253 return ev.charCode || ev.keyCode || 0;
2257 _getCacheIndex: function(el, eventName, fn) {
2258 for (var i = 0,len = listeners.length; i < len; ++i) {
2259 var li = listeners[i];
2261 li[this.FN] == fn &&
2262 li[this.EL] == el &&
2263 li[this.TYPE] == eventName) {
2275 getEl: function(id) {
2276 return document.getElementById(id);
2280 clearCache: function() {
2284 _load: function(e) {
2285 loadComplete = true;
2286 var EU = Roo.lib.Event;
2290 EU.doRemove(window, "load", EU._load);
2295 _tryPreloadAttach: function() {
2304 var tryAgain = !loadComplete;
2306 tryAgain = (retryCount > 0);
2311 for (var i = 0,len = onAvailStack.length; i < len; ++i) {
2312 var item = onAvailStack[i];
2314 var el = this.getEl(item.id);
2317 if (!item.checkReady ||
2320 (document && document.body)) {
2323 if (item.override) {
2324 if (item.override === true) {
2327 scope = item.override;
2330 item.fn.call(scope, item.obj);
2331 onAvailStack[i] = null;
2334 notAvail.push(item);
2339 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2343 this.startInterval();
2345 clearInterval(this._interval);
2346 this._interval = null;
2349 this.locked = false;
2356 purgeElement: function(el, recurse, eventName) {
2357 var elListeners = this.getListeners(el, eventName);
2359 for (var i = 0,len = elListeners.length; i < len; ++i) {
2360 var l = elListeners[i];
2361 this.removeListener(el, l.type, l.fn);
2365 if (recurse && el && el.childNodes) {
2366 for (i = 0,len = el.childNodes.length; i < len; ++i) {
2367 this.purgeElement(el.childNodes[i], recurse, eventName);
2373 getListeners: function(el, eventName) {
2374 var results = [], searchLists;
2376 searchLists = [listeners, unloadListeners];
2377 } else if (eventName == "unload") {
2378 searchLists = [unloadListeners];
2380 searchLists = [listeners];
2383 for (var j = 0; j < searchLists.length; ++j) {
2384 var searchList = searchLists[j];
2385 if (searchList && searchList.length > 0) {
2386 for (var i = 0,len = searchList.length; i < len; ++i) {
2387 var l = searchList[i];
2388 if (l && l[this.EL] === el &&
2389 (!eventName || eventName === l[this.TYPE])) {
2394 adjust: l[this.ADJ_SCOPE],
2402 return (results.length) ? results : null;
2406 _unload: function(e) {
2408 var EU = Roo.lib.Event, i, j, l, len, index;
2410 for (i = 0,len = unloadListeners.length; i < len; ++i) {
2411 l = unloadListeners[i];
2414 if (l[EU.ADJ_SCOPE]) {
2415 if (l[EU.ADJ_SCOPE] === true) {
2418 scope = l[EU.ADJ_SCOPE];
2421 l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
2422 unloadListeners[i] = null;
2428 unloadListeners = null;
2430 if (listeners && listeners.length > 0) {
2431 j = listeners.length;
2434 l = listeners[index];
2436 EU.removeListener(l[EU.EL], l[EU.TYPE],
2446 EU.doRemove(window, "unload", EU._unload);
2451 getScroll: function() {
2452 var dd = document.documentElement, db = document.body;
2453 if (dd && (dd.scrollTop || dd.scrollLeft)) {
2454 return [dd.scrollTop, dd.scrollLeft];
2456 return [db.scrollTop, db.scrollLeft];
2463 doAdd: function () {
2464 if (window.addEventListener) {
2465 return function(el, eventName, fn, capture) {
2466 el.addEventListener(eventName, fn, (capture));
2468 } else if (window.attachEvent) {
2469 return function(el, eventName, fn, capture) {
2470 el.attachEvent("on" + eventName, fn);
2479 doRemove: function() {
2480 if (window.removeEventListener) {
2481 return function (el, eventName, fn, capture) {
2482 el.removeEventListener(eventName, fn, (capture));
2484 } else if (window.detachEvent) {
2485 return function (el, eventName, fn) {
2486 el.detachEvent("on" + eventName, fn);
2498 var E = Roo.lib.Event;
2499 E.on = E.addListener;
2500 E.un = E.removeListener;
2502 if (document && document.body) {
2505 E.doAdd(window, "load", E._load);
2507 E.doAdd(window, "unload", E._unload);
2508 E._tryPreloadAttach();
2512 * Portions of this file are based on pieces of Yahoo User Interface Library
2513 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2514 * YUI licensed under the BSD License:
2515 * http://developer.yahoo.net/yui/license.txt
2516 * <script type="text/javascript">
2522 * @class Roo.lib.Ajax
2529 request : function(method, uri, cb, data, options) {
2531 var hs = options.headers;
2534 if(hs.hasOwnProperty(h)){
2535 this.initHeader(h, hs[h], false);
2539 if(options.xmlData){
2540 this.initHeader('Content-Type', 'text/xml', false);
2542 data = options.xmlData;
2546 return this.asyncRequest(method, uri, cb, data);
2549 serializeForm : function(form) {
2550 if(typeof form == 'string') {
2551 form = (document.getElementById(form) || document.forms[form]);
2554 var el, name, val, disabled, data = '', hasSubmit = false;
2555 for (var i = 0; i < form.elements.length; i++) {
2556 el = form.elements[i];
2557 disabled = form.elements[i].disabled;
2558 name = form.elements[i].name;
2559 val = form.elements[i].value;
2561 if (!disabled && name){
2565 case 'select-multiple':
2566 for (var j = 0; j < el.options.length; j++) {
2567 if (el.options[j].selected) {
2569 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
2572 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
2580 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2593 if(hasSubmit == false) {
2594 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2599 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2604 data = data.substr(0, data.length - 1);
2612 useDefaultHeader:true,
2614 defaultPostHeader:'application/x-www-form-urlencoded',
2616 useDefaultXhrHeader:true,
2618 defaultXhrHeader:'XMLHttpRequest',
2620 hasDefaultHeaders:true,
2632 setProgId:function(id)
2634 this.activeX.unshift(id);
2637 setDefaultPostHeader:function(b)
2639 this.useDefaultHeader = b;
2642 setDefaultXhrHeader:function(b)
2644 this.useDefaultXhrHeader = b;
2647 setPollingInterval:function(i)
2649 if (typeof i == 'number' && isFinite(i)) {
2650 this.pollInterval = i;
2654 createXhrObject:function(transactionId)
2660 http = new XMLHttpRequest();
2662 obj = { conn:http, tId:transactionId };
2666 for (var i = 0; i < this.activeX.length; ++i) {
2670 http = new ActiveXObject(this.activeX[i]);
2672 obj = { conn:http, tId:transactionId };
2685 getConnectionObject:function()
2688 var tId = this.transactionId;
2692 o = this.createXhrObject(tId);
2694 this.transactionId++;
2705 asyncRequest:function(method, uri, callback, postData)
2707 var o = this.getConnectionObject();
2713 o.conn.open(method, uri, true);
2715 if (this.useDefaultXhrHeader) {
2716 if (!this.defaultHeaders['X-Requested-With']) {
2717 this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
2721 if(postData && this.useDefaultHeader){
2722 this.initHeader('Content-Type', this.defaultPostHeader);
2725 if (this.hasDefaultHeaders || this.hasHeaders) {
2729 this.handleReadyState(o, callback);
2730 o.conn.send(postData || null);
2736 handleReadyState:function(o, callback)
2740 if (callback && callback.timeout) {
2742 this.timeout[o.tId] = window.setTimeout(function() {
2743 oConn.abort(o, callback, true);
2744 }, callback.timeout);
2747 this.poll[o.tId] = window.setInterval(
2749 if (o.conn && o.conn.readyState == 4) {
2750 window.clearInterval(oConn.poll[o.tId]);
2751 delete oConn.poll[o.tId];
2753 if(callback && callback.timeout) {
2754 window.clearTimeout(oConn.timeout[o.tId]);
2755 delete oConn.timeout[o.tId];
2758 oConn.handleTransactionResponse(o, callback);
2761 , this.pollInterval);
2764 handleTransactionResponse:function(o, callback, isAbort)
2768 this.releaseObject(o);
2772 var httpStatus, responseObject;
2776 if (o.conn.status !== undefined && o.conn.status != 0) {
2777 httpStatus = o.conn.status;
2789 if (httpStatus >= 200 && httpStatus < 300) {
2790 responseObject = this.createResponseObject(o, callback.argument);
2791 if (callback.success) {
2792 if (!callback.scope) {
2793 callback.success(responseObject);
2798 callback.success.apply(callback.scope, [responseObject]);
2803 switch (httpStatus) {
2811 responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
2812 if (callback.failure) {
2813 if (!callback.scope) {
2814 callback.failure(responseObject);
2817 callback.failure.apply(callback.scope, [responseObject]);
2822 responseObject = this.createResponseObject(o, callback.argument);
2823 if (callback.failure) {
2824 if (!callback.scope) {
2825 callback.failure(responseObject);
2828 callback.failure.apply(callback.scope, [responseObject]);
2834 this.releaseObject(o);
2835 responseObject = null;
2838 createResponseObject:function(o, callbackArg)
2845 var headerStr = o.conn.getAllResponseHeaders();
2846 var header = headerStr.split('\n');
2847 for (var i = 0; i < header.length; i++) {
2848 var delimitPos = header[i].indexOf(':');
2849 if (delimitPos != -1) {
2850 headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
2858 obj.status = o.conn.status;
2859 obj.statusText = o.conn.statusText;
2860 obj.getResponseHeader = headerObj;
2861 obj.getAllResponseHeaders = headerStr;
2862 obj.responseText = o.conn.responseText;
2863 obj.responseXML = o.conn.responseXML;
2865 if (typeof callbackArg !== undefined) {
2866 obj.argument = callbackArg;
2872 createExceptionObject:function(tId, callbackArg, isAbort)
2875 var COMM_ERROR = 'communication failure';
2876 var ABORT_CODE = -1;
2877 var ABORT_ERROR = 'transaction aborted';
2883 obj.status = ABORT_CODE;
2884 obj.statusText = ABORT_ERROR;
2887 obj.status = COMM_CODE;
2888 obj.statusText = COMM_ERROR;
2892 obj.argument = callbackArg;
2898 initHeader:function(label, value, isDefault)
2900 var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
2902 if (headerObj[label] === undefined) {
2903 headerObj[label] = value;
2908 headerObj[label] = value + "," + headerObj[label];
2912 this.hasDefaultHeaders = true;
2915 this.hasHeaders = true;
2920 setHeader:function(o)
2922 if (this.hasDefaultHeaders) {
2923 for (var prop in this.defaultHeaders) {
2924 if (this.defaultHeaders.hasOwnProperty(prop)) {
2925 o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
2930 if (this.hasHeaders) {
2931 for (var prop in this.headers) {
2932 if (this.headers.hasOwnProperty(prop)) {
2933 o.conn.setRequestHeader(prop, this.headers[prop]);
2937 this.hasHeaders = false;
2941 resetDefaultHeaders:function() {
2942 delete this.defaultHeaders;
2943 this.defaultHeaders = {};
2944 this.hasDefaultHeaders = false;
2947 abort:function(o, callback, isTimeout)
2949 if(this.isCallInProgress(o)) {
2951 window.clearInterval(this.poll[o.tId]);
2952 delete this.poll[o.tId];
2954 delete this.timeout[o.tId];
2957 this.handleTransactionResponse(o, callback, true);
2967 isCallInProgress:function(o)
2970 return o.conn.readyState != 4 && o.conn.readyState != 0;
2979 releaseObject:function(o)
2988 'MSXML2.XMLHTTP.3.0',
2996 * Portions of this file are based on pieces of Yahoo User Interface Library
2997 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2998 * YUI licensed under the BSD License:
2999 * http://developer.yahoo.net/yui/license.txt
3000 * <script type="text/javascript">
3004 Roo.lib.Region = function(t, r, b, l) {
3014 Roo.lib.Region.prototype = {
3015 contains : function(region) {
3016 return ( region.left >= this.left &&
3017 region.right <= this.right &&
3018 region.top >= this.top &&
3019 region.bottom <= this.bottom );
3023 getArea : function() {
3024 return ( (this.bottom - this.top) * (this.right - this.left) );
3027 intersect : function(region) {
3028 var t = Math.max(this.top, region.top);
3029 var r = Math.min(this.right, region.right);
3030 var b = Math.min(this.bottom, region.bottom);
3031 var l = Math.max(this.left, region.left);
3033 if (b >= t && r >= l) {
3034 return new Roo.lib.Region(t, r, b, l);
3039 union : function(region) {
3040 var t = Math.min(this.top, region.top);
3041 var r = Math.max(this.right, region.right);
3042 var b = Math.max(this.bottom, region.bottom);
3043 var l = Math.min(this.left, region.left);
3045 return new Roo.lib.Region(t, r, b, l);
3048 adjust : function(t, l, b, r) {
3057 Roo.lib.Region.getRegion = function(el) {
3058 var p = Roo.lib.Dom.getXY(el);
3061 var r = p[0] + el.offsetWidth;
3062 var b = p[1] + el.offsetHeight;
3065 return new Roo.lib.Region(t, r, b, l);
3068 * Portions of this file are based on pieces of Yahoo User Interface Library
3069 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3070 * YUI licensed under the BSD License:
3071 * http://developer.yahoo.net/yui/license.txt
3072 * <script type="text/javascript">
3075 //@@dep Roo.lib.Region
3078 Roo.lib.Point = function(x, y) {
3079 if (x instanceof Array) {
3083 this.x = this.right = this.left = this[0] = x;
3084 this.y = this.top = this.bottom = this[1] = y;
3087 Roo.lib.Point.prototype = new Roo.lib.Region();
3089 * Portions of this file are based on pieces of Yahoo User Interface Library
3090 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3091 * YUI licensed under the BSD License:
3092 * http://developer.yahoo.net/yui/license.txt
3093 * <script type="text/javascript">
3100 scroll : function(el, args, duration, easing, cb, scope) {
3101 this.run(el, args, duration, easing, cb, scope, Roo.lib.Scroll);
3104 motion : function(el, args, duration, easing, cb, scope) {
3105 this.run(el, args, duration, easing, cb, scope, Roo.lib.Motion);
3108 color : function(el, args, duration, easing, cb, scope) {
3109 this.run(el, args, duration, easing, cb, scope, Roo.lib.ColorAnim);
3112 run : function(el, args, duration, easing, cb, scope, type) {
3113 type = type || Roo.lib.AnimBase;
3114 if (typeof easing == "string") {
3115 easing = Roo.lib.Easing[easing];
3117 var anim = new type(el, args, duration, easing);
3118 anim.animateX(function() {
3119 Roo.callback(cb, scope);
3125 * Portions of this file are based on pieces of Yahoo User Interface Library
3126 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3127 * YUI licensed under the BSD License:
3128 * http://developer.yahoo.net/yui/license.txt
3129 * <script type="text/javascript">
3137 if (!libFlyweight) {
3138 libFlyweight = new Roo.Element.Flyweight();
3140 libFlyweight.dom = el;
3141 return libFlyweight;
3144 // since this uses fly! - it cant be in DOM (which does not have fly yet..)
3148 Roo.lib.AnimBase = function(el, attributes, duration, method) {
3150 this.init(el, attributes, duration, method);
3154 Roo.lib.AnimBase.fly = fly;
3158 Roo.lib.AnimBase.prototype = {
3160 toString: function() {
3161 var el = this.getEl();
3162 var id = el.id || el.tagName;
3163 return ("Anim " + id);
3167 noNegatives: /width|height|opacity|padding/i,
3168 offsetAttribute: /^((width|height)|(top|left))$/,
3169 defaultUnit: /width|height|top$|bottom$|left$|right$/i,
3170 offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i
3174 doMethod: function(attr, start, end) {
3175 return this.method(this.currentFrame, start, end - start, this.totalFrames);
3179 setAttribute: function(attr, val, unit) {
3180 if (this.patterns.noNegatives.test(attr)) {
3181 val = (val > 0) ? val : 0;
3184 Roo.fly(this.getEl(), '_anim').setStyle(attr, val + unit);
3188 getAttribute: function(attr) {
3189 var el = this.getEl();
3190 var val = fly(el).getStyle(attr);
3192 if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) {
3193 return parseFloat(val);
3196 var a = this.patterns.offsetAttribute.exec(attr) || [];
3197 var pos = !!( a[3] );
3198 var box = !!( a[2] );
3201 if (box || (fly(el).getStyle('position') == 'absolute' && pos)) {
3202 val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];
3211 getDefaultUnit: function(attr) {
3212 if (this.patterns.defaultUnit.test(attr)) {
3219 animateX : function(callback, scope) {
3220 var f = function() {
3221 this.onComplete.removeListener(f);
3222 if (typeof callback == "function") {
3223 callback.call(scope || this, this);
3226 this.onComplete.addListener(f, this);
3231 setRuntimeAttribute: function(attr) {
3234 var attributes = this.attributes;
3236 this.runtimeAttributes[attr] = {};
3238 var isset = function(prop) {
3239 return (typeof prop !== 'undefined');
3242 if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) {
3246 start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr);
3249 if (isset(attributes[attr]['to'])) {
3250 end = attributes[attr]['to'];
3251 } else if (isset(attributes[attr]['by'])) {
3252 if (start.constructor == Array) {
3254 for (var i = 0, len = start.length; i < len; ++i) {
3255 end[i] = start[i] + attributes[attr]['by'][i];
3258 end = start + attributes[attr]['by'];
3262 this.runtimeAttributes[attr].start = start;
3263 this.runtimeAttributes[attr].end = end;
3266 this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr);
3270 init: function(el, attributes, duration, method) {
3272 var isAnimated = false;
3275 var startTime = null;
3278 var actualFrames = 0;
3281 el = Roo.getDom(el);
3284 this.attributes = attributes || {};
3287 this.duration = duration || 1;
3290 this.method = method || Roo.lib.Easing.easeNone;
3293 this.useSeconds = true;
3296 this.currentFrame = 0;
3299 this.totalFrames = Roo.lib.AnimMgr.fps;
3302 this.getEl = function() {
3307 this.isAnimated = function() {
3312 this.getStartTime = function() {
3316 this.runtimeAttributes = {};
3319 this.animate = function() {
3320 if (this.isAnimated()) {
3324 this.currentFrame = 0;
3326 this.totalFrames = ( this.useSeconds ) ? Math.ceil(Roo.lib.AnimMgr.fps * this.duration) : this.duration;
3328 Roo.lib.AnimMgr.registerElement(this);
3332 this.stop = function(finish) {
3334 this.currentFrame = this.totalFrames;
3335 this._onTween.fire();
3337 Roo.lib.AnimMgr.stop(this);
3340 var onStart = function() {
3341 this.onStart.fire();
3343 this.runtimeAttributes = {};
3344 for (var attr in this.attributes) {
3345 this.setRuntimeAttribute(attr);
3350 startTime = new Date();
3354 var onTween = function() {
3356 duration: new Date() - this.getStartTime(),
3357 currentFrame: this.currentFrame
3360 data.toString = function() {
3362 'duration: ' + data.duration +
3363 ', currentFrame: ' + data.currentFrame
3367 this.onTween.fire(data);
3369 var runtimeAttributes = this.runtimeAttributes;
3371 for (var attr in runtimeAttributes) {
3372 this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit);
3378 var onComplete = function() {
3379 var actual_duration = (new Date() - startTime) / 1000 ;
3382 duration: actual_duration,
3383 frames: actualFrames,
3384 fps: actualFrames / actual_duration
3387 data.toString = function() {
3389 'duration: ' + data.duration +
3390 ', frames: ' + data.frames +
3391 ', fps: ' + data.fps
3397 this.onComplete.fire(data);
3401 this._onStart = new Roo.util.Event(this);
3402 this.onStart = new Roo.util.Event(this);
3403 this.onTween = new Roo.util.Event(this);
3404 this._onTween = new Roo.util.Event(this);
3405 this.onComplete = new Roo.util.Event(this);
3406 this._onComplete = new Roo.util.Event(this);
3407 this._onStart.addListener(onStart);
3408 this._onTween.addListener(onTween);
3409 this._onComplete.addListener(onComplete);
3414 * Portions of this file are based on pieces of Yahoo User Interface Library
3415 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3416 * YUI licensed under the BSD License:
3417 * http://developer.yahoo.net/yui/license.txt
3418 * <script type="text/javascript">
3422 Roo.lib.AnimMgr = new function() {
3439 this.registerElement = function(tween) {
3440 queue[queue.length] = tween;
3442 tween._onStart.fire();
3447 this.unRegister = function(tween, index) {
3448 tween._onComplete.fire();
3449 index = index || getIndex(tween);
3451 queue.splice(index, 1);
3455 if (tweenCount <= 0) {
3461 this.start = function() {
3462 if (thread === null) {
3463 thread = setInterval(this.run, this.delay);
3468 this.stop = function(tween) {
3470 clearInterval(thread);
3472 for (var i = 0, len = queue.length; i < len; ++i) {
3473 if (queue[0].isAnimated()) {
3474 this.unRegister(queue[0], 0);
3483 this.unRegister(tween);
3488 this.run = function() {
3489 for (var i = 0, len = queue.length; i < len; ++i) {
3490 var tween = queue[i];
3491 if (!tween || !tween.isAnimated()) {
3495 if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)
3497 tween.currentFrame += 1;
3499 if (tween.useSeconds) {
3500 correctFrame(tween);
3502 tween._onTween.fire();
3505 Roo.lib.AnimMgr.stop(tween, i);
3510 var getIndex = function(anim) {
3511 for (var i = 0, len = queue.length; i < len; ++i) {
3512 if (queue[i] == anim) {
3520 var correctFrame = function(tween) {
3521 var frames = tween.totalFrames;
3522 var frame = tween.currentFrame;
3523 var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames);
3524 var elapsed = (new Date() - tween.getStartTime());
3527 if (elapsed < tween.duration * 1000) {
3528 tweak = Math.round((elapsed / expected - 1) * tween.currentFrame);
3530 tweak = frames - (frame + 1);
3532 if (tweak > 0 && isFinite(tweak)) {
3533 if (tween.currentFrame + tweak >= frames) {
3534 tweak = frames - (frame + 1);
3537 tween.currentFrame += tweak;
3543 * Portions of this file are based on pieces of Yahoo User Interface Library
3544 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3545 * YUI licensed under the BSD License:
3546 * http://developer.yahoo.net/yui/license.txt
3547 * <script type="text/javascript">
3550 Roo.lib.Bezier = new function() {
3552 this.getPosition = function(points, t) {
3553 var n = points.length;
3556 for (var i = 0; i < n; ++i) {
3557 tmp[i] = [points[i][0], points[i][1]];
3560 for (var j = 1; j < n; ++j) {
3561 for (i = 0; i < n - j; ++i) {
3562 tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
3563 tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
3567 return [ tmp[0][0], tmp[0][1] ];
3571 * Portions of this file are based on pieces of Yahoo User Interface Library
3572 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3573 * YUI licensed under the BSD License:
3574 * http://developer.yahoo.net/yui/license.txt
3575 * <script type="text/javascript">
3580 Roo.lib.ColorAnim = function(el, attributes, duration, method) {
3581 Roo.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
3584 Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase);
3586 var fly = Roo.lib.AnimBase.fly;
3588 var superclass = Y.ColorAnim.superclass;
3589 var proto = Y.ColorAnim.prototype;
3591 proto.toString = function() {
3592 var el = this.getEl();
3593 var id = el.id || el.tagName;
3594 return ("ColorAnim " + id);
3597 proto.patterns.color = /color$/i;
3598 proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
3599 proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
3600 proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
3601 proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
3604 proto.parseColor = function(s) {
3605 if (s.length == 3) {
3609 var c = this.patterns.hex.exec(s);
3610 if (c && c.length == 4) {
3611 return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
3614 c = this.patterns.rgb.exec(s);
3615 if (c && c.length == 4) {
3616 return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
3619 c = this.patterns.hex3.exec(s);
3620 if (c && c.length == 4) {
3621 return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
3626 // since this uses fly! - it cant be in ColorAnim (which does not have fly yet..)
3627 proto.getAttribute = function(attr) {
3628 var el = this.getEl();
3629 if (this.patterns.color.test(attr)) {
3630 var val = fly(el).getStyle(attr);
3632 if (this.patterns.transparent.test(val)) {
3633 var parent = el.parentNode;
3634 val = fly(parent).getStyle(attr);
3636 while (parent && this.patterns.transparent.test(val)) {
3637 parent = parent.parentNode;
3638 val = fly(parent).getStyle(attr);
3639 if (parent.tagName.toUpperCase() == 'HTML') {
3645 val = superclass.getAttribute.call(this, attr);
3650 proto.getAttribute = function(attr) {
3651 var el = this.getEl();
3652 if (this.patterns.color.test(attr)) {
3653 var val = fly(el).getStyle(attr);
3655 if (this.patterns.transparent.test(val)) {
3656 var parent = el.parentNode;
3657 val = fly(parent).getStyle(attr);
3659 while (parent && this.patterns.transparent.test(val)) {
3660 parent = parent.parentNode;
3661 val = fly(parent).getStyle(attr);
3662 if (parent.tagName.toUpperCase() == 'HTML') {
3668 val = superclass.getAttribute.call(this, attr);
3674 proto.doMethod = function(attr, start, end) {
3677 if (this.patterns.color.test(attr)) {
3679 for (var i = 0, len = start.length; i < len; ++i) {
3680 val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
3683 val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')';
3686 val = superclass.doMethod.call(this, attr, start, end);
3692 proto.setRuntimeAttribute = function(attr) {
3693 superclass.setRuntimeAttribute.call(this, attr);
3695 if (this.patterns.color.test(attr)) {
3696 var attributes = this.attributes;
3697 var start = this.parseColor(this.runtimeAttributes[attr].start);
3698 var end = this.parseColor(this.runtimeAttributes[attr].end);
3700 if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') {
3701 end = this.parseColor(attributes[attr].by);
3703 for (var i = 0, len = start.length; i < len; ++i) {
3704 end[i] = start[i] + end[i];
3708 this.runtimeAttributes[attr].start = start;
3709 this.runtimeAttributes[attr].end = end;
3715 * Portions of this file are based on pieces of Yahoo User Interface Library
3716 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3717 * YUI licensed under the BSD License:
3718 * http://developer.yahoo.net/yui/license.txt
3719 * <script type="text/javascript">
3725 easeNone: function (t, b, c, d) {
3726 return c * t / d + b;
3730 easeIn: function (t, b, c, d) {
3731 return c * (t /= d) * t + b;
3735 easeOut: function (t, b, c, d) {
3736 return -c * (t /= d) * (t - 2) + b;
3740 easeBoth: function (t, b, c, d) {
3741 if ((t /= d / 2) < 1) {
3742 return c / 2 * t * t + b;
3745 return -c / 2 * ((--t) * (t - 2) - 1) + b;
3749 easeInStrong: function (t, b, c, d) {
3750 return c * (t /= d) * t * t * t + b;
3754 easeOutStrong: function (t, b, c, d) {
3755 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
3759 easeBothStrong: function (t, b, c, d) {
3760 if ((t /= d / 2) < 1) {
3761 return c / 2 * t * t * t * t + b;
3764 return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
3769 elasticIn: function (t, b, c, d, a, p) {
3773 if ((t /= d) == 1) {
3780 if (!a || a < Math.abs(c)) {
3785 var s = p / (2 * Math.PI) * Math.asin(c / a);
3788 return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3792 elasticOut: function (t, b, c, d, a, p) {
3796 if ((t /= d) == 1) {
3803 if (!a || a < Math.abs(c)) {
3808 var s = p / (2 * Math.PI) * Math.asin(c / a);
3811 return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
3815 elasticBoth: function (t, b, c, d, a, p) {
3820 if ((t /= d / 2) == 2) {
3828 if (!a || a < Math.abs(c)) {
3833 var s = p / (2 * Math.PI) * Math.asin(c / a);
3837 return -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
3838 Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3840 return a * Math.pow(2, -10 * (t -= 1)) *
3841 Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
3846 backIn: function (t, b, c, d, s) {
3847 if (typeof s == 'undefined') {
3850 return c * (t /= d) * t * ((s + 1) * t - s) + b;
3854 backOut: function (t, b, c, d, s) {
3855 if (typeof s == 'undefined') {
3858 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
3862 backBoth: function (t, b, c, d, s) {
3863 if (typeof s == 'undefined') {
3867 if ((t /= d / 2 ) < 1) {
3868 return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
3870 return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
3874 bounceIn: function (t, b, c, d) {
3875 return c - Roo.lib.Easing.bounceOut(d - t, 0, c, d) + b;
3879 bounceOut: function (t, b, c, d) {
3880 if ((t /= d) < (1 / 2.75)) {
3881 return c * (7.5625 * t * t) + b;
3882 } else if (t < (2 / 2.75)) {
3883 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
3884 } else if (t < (2.5 / 2.75)) {
3885 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
3887 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
3891 bounceBoth: function (t, b, c, d) {
3893 return Roo.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
3895 return Roo.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
3898 * Portions of this file are based on pieces of Yahoo User Interface Library
3899 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3900 * YUI licensed under the BSD License:
3901 * http://developer.yahoo.net/yui/license.txt
3902 * <script type="text/javascript">
3906 Roo.lib.Motion = function(el, attributes, duration, method) {
3908 Roo.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method);
3912 Roo.extend(Roo.lib.Motion, Roo.lib.ColorAnim);
3916 var superclass = Y.Motion.superclass;
3917 var proto = Y.Motion.prototype;
3919 proto.toString = function() {
3920 var el = this.getEl();
3921 var id = el.id || el.tagName;
3922 return ("Motion " + id);
3925 proto.patterns.points = /^points$/i;
3927 proto.setAttribute = function(attr, val, unit) {
3928 if (this.patterns.points.test(attr)) {
3929 unit = unit || 'px';
3930 superclass.setAttribute.call(this, 'left', val[0], unit);
3931 superclass.setAttribute.call(this, 'top', val[1], unit);
3933 superclass.setAttribute.call(this, attr, val, unit);
3937 proto.getAttribute = function(attr) {
3938 if (this.patterns.points.test(attr)) {
3940 superclass.getAttribute.call(this, 'left'),
3941 superclass.getAttribute.call(this, 'top')
3944 val = superclass.getAttribute.call(this, attr);
3950 proto.doMethod = function(attr, start, end) {
3953 if (this.patterns.points.test(attr)) {
3954 var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
3955 val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
3957 val = superclass.doMethod.call(this, attr, start, end);
3962 proto.setRuntimeAttribute = function(attr) {
3963 if (this.patterns.points.test(attr)) {
3964 var el = this.getEl();
3965 var attributes = this.attributes;
3967 var control = attributes['points']['control'] || [];
3971 if (control.length > 0 && !(control[0] instanceof Array)) {
3972 control = [control];
3975 for (i = 0,len = control.length; i < len; ++i) {
3976 tmp[i] = control[i];
3981 Roo.fly(el).position();
3983 if (isset(attributes['points']['from'])) {
3984 Roo.lib.Dom.setXY(el, attributes['points']['from']);
3987 Roo.lib.Dom.setXY(el, Roo.lib.Dom.getXY(el));
3990 start = this.getAttribute('points');
3993 if (isset(attributes['points']['to'])) {
3994 end = translateValues.call(this, attributes['points']['to'], start);
3996 var pageXY = Roo.lib.Dom.getXY(this.getEl());
3997 for (i = 0,len = control.length; i < len; ++i) {
3998 control[i] = translateValues.call(this, control[i], start);
4002 } else if (isset(attributes['points']['by'])) {
4003 end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
4005 for (i = 0,len = control.length; i < len; ++i) {
4006 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
4010 this.runtimeAttributes[attr] = [start];
4012 if (control.length > 0) {
4013 this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
4016 this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
4019 superclass.setRuntimeAttribute.call(this, attr);
4023 var translateValues = function(val, start) {
4024 var pageXY = Roo.lib.Dom.getXY(this.getEl());
4025 val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
4030 var isset = function(prop) {
4031 return (typeof prop !== 'undefined');
4035 * Portions of this file are based on pieces of Yahoo User Interface Library
4036 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
4037 * YUI licensed under the BSD License:
4038 * http://developer.yahoo.net/yui/license.txt
4039 * <script type="text/javascript">
4043 Roo.lib.Scroll = function(el, attributes, duration, method) {
4045 Roo.lib.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
4049 Roo.extend(Roo.lib.Scroll, Roo.lib.ColorAnim);
4053 var superclass = Y.Scroll.superclass;
4054 var proto = Y.Scroll.prototype;
4056 proto.toString = function() {
4057 var el = this.getEl();
4058 var id = el.id || el.tagName;
4059 return ("Scroll " + id);
4062 proto.doMethod = function(attr, start, end) {
4065 if (attr == 'scroll') {
4067 this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames),
4068 this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames)
4072 val = superclass.doMethod.call(this, attr, start, end);
4077 proto.getAttribute = function(attr) {
4079 var el = this.getEl();
4081 if (attr == 'scroll') {
4082 val = [ el.scrollLeft, el.scrollTop ];
4084 val = superclass.getAttribute.call(this, attr);
4090 proto.setAttribute = function(attr, val, unit) {
4091 var el = this.getEl();
4093 if (attr == 'scroll') {
4094 el.scrollLeft = val[0];
4095 el.scrollTop = val[1];
4097 superclass.setAttribute.call(this, attr, val, unit);
4103 * Ext JS Library 1.1.1
4104 * Copyright(c) 2006-2007, Ext JS, LLC.
4106 * Originally Released Under LGPL - original licence link has changed is not relivant.
4109 * <script type="text/javascript">
4113 // nasty IE9 hack - what a pile of crap that is..
4115 if (typeof Range != "undefined" && typeof Range.prototype.createContextualFragment == "undefined") {
4116 Range.prototype.createContextualFragment = function (html) {
4117 var doc = window.document;
4118 var container = doc.createElement("div");
4119 container.innerHTML = html;
4120 var frag = doc.createDocumentFragment(), n;
4121 while ((n = container.firstChild)) {
4122 frag.appendChild(n);
4129 * @class Roo.DomHelper
4130 * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.
4131 * For more information see <a href="http://web.archive.org/web/20071221063734/http://www.jackslocum.com/blog/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">this blog post with examples</a>.
4134 Roo.DomHelper = function(){
4135 var tempTableEl = null;
4136 var emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i;
4137 var tableRe = /^table|tbody|tr|td$/i;
4139 // build as innerHTML where available
4141 var createHtml = function(o){
4142 if(typeof o == 'string'){
4151 if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") continue;
4152 if(attr == "style"){
4154 if(typeof s == "function"){
4157 if(typeof s == "string"){
4158 b += ' style="' + s + '"';
4159 }else if(typeof s == "object"){
4162 if(typeof s[key] != "function"){
4163 b += key + ":" + s[key] + ";";
4170 b += ' class="' + o["cls"] + '"';
4171 }else if(attr == "htmlFor"){
4172 b += ' for="' + o["htmlFor"] + '"';
4174 b += " " + attr + '="' + o[attr] + '"';
4178 if(emptyTags.test(o.tag)){
4182 var cn = o.children || o.cn;
4184 //http://bugs.kde.org/show_bug.cgi?id=71506
4185 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4186 for(var i = 0, len = cn.length; i < len; i++) {
4187 b += createHtml(cn[i], b);
4190 b += createHtml(cn, b);
4196 b += "</" + o.tag + ">";
4203 var createDom = function(o, parentNode){
4205 // defininition craeted..
4207 if (o.ns && o.ns != 'html') {
4209 if (o.xmlns && typeof(xmlns[o.ns]) == 'undefined') {
4210 xmlns[o.ns] = o.xmlns;
4213 if (typeof(xmlns[o.ns]) == 'undefined') {
4214 console.log("Trying to create namespace element " + o.ns + ", however no xmlns was sent to builder previously");
4220 if (typeof(o) == 'string') {
4221 return parentNode.appendChild(document.createTextNode(o));
4223 o.tag = o.tag || div;
4224 if (o.ns && Roo.isIE) {
4226 o.tag = o.ns + ':' + o.tag;
4229 var el = ns ? document.createElementNS( ns, o.tag||'div') : document.createElement(o.tag||'div');
4230 var useSet = el.setAttribute ? true : false; // In IE some elements don't have setAttribute
4233 if(attr == "tag" || attr == "ns" ||attr == "xmlns" ||attr == "children" || attr == "cn" || attr == "html" ||
4234 attr == "style" || typeof o[attr] == "function") continue;
4236 if(attr=="cls" && Roo.isIE){
4237 el.className = o["cls"];
4239 if(useSet) el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]);
4240 else el[attr] = o[attr];
4243 Roo.DomHelper.applyStyles(el, o.style);
4244 var cn = o.children || o.cn;
4246 //http://bugs.kde.org/show_bug.cgi?id=71506
4247 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4248 for(var i = 0, len = cn.length; i < len; i++) {
4249 createDom(cn[i], el);
4256 el.innerHTML = o.html;
4259 parentNode.appendChild(el);
4264 var ieTable = function(depth, s, h, e){
4265 tempTableEl.innerHTML = [s, h, e].join('');
4266 var i = -1, el = tempTableEl;
4273 // kill repeat to save bytes
4277 tbe = '</tbody>'+te,
4283 * Nasty code for IE's broken table implementation
4285 var insertIntoTable = function(tag, where, el, html){
4287 tempTableEl = document.createElement('div');
4292 if(where == 'afterbegin' || where == 'beforeend'){ // INTO a TD
4295 if(where == 'beforebegin'){
4299 before = el.nextSibling;
4302 node = ieTable(4, trs, html, tre);
4304 else if(tag == 'tr'){
4305 if(where == 'beforebegin'){
4308 node = ieTable(3, tbs, html, tbe);
4309 } else if(where == 'afterend'){
4310 before = el.nextSibling;
4312 node = ieTable(3, tbs, html, tbe);
4313 } else{ // INTO a TR
4314 if(where == 'afterbegin'){
4315 before = el.firstChild;
4317 node = ieTable(4, trs, html, tre);
4319 } else if(tag == 'tbody'){
4320 if(where == 'beforebegin'){
4323 node = ieTable(2, ts, html, te);
4324 } else if(where == 'afterend'){
4325 before = el.nextSibling;
4327 node = ieTable(2, ts, html, te);
4329 if(where == 'afterbegin'){
4330 before = el.firstChild;
4332 node = ieTable(3, tbs, html, tbe);
4335 if(where == 'beforebegin' || where == 'afterend'){ // OUTSIDE the table
4338 if(where == 'afterbegin'){
4339 before = el.firstChild;
4341 node = ieTable(2, ts, html, te);
4343 el.insertBefore(node, before);
4348 /** True to force the use of DOM instead of html fragments @type Boolean */
4352 * Returns the markup for the passed Element(s) config
4353 * @param {Object} o The Dom object spec (and children)
4356 markup : function(o){
4357 return createHtml(o);
4361 * Applies a style specification to an element
4362 * @param {String/HTMLElement} el The element to apply styles to
4363 * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or
4364 * a function which returns such a specification.
4366 applyStyles : function(el, styles){
4369 if(typeof styles == "string"){
4370 var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;
4372 while ((matches = re.exec(styles)) != null){
4373 el.setStyle(matches[1], matches[2]);
4375 }else if (typeof styles == "object"){
4376 for (var style in styles){
4377 el.setStyle(style, styles[style]);
4379 }else if (typeof styles == "function"){
4380 Roo.DomHelper.applyStyles(el, styles.call());
4386 * Inserts an HTML fragment into the Dom
4387 * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
4388 * @param {HTMLElement} el The context element
4389 * @param {String} html The HTML fragmenet
4390 * @return {HTMLElement} The new node
4392 insertHtml : function(where, el, html){
4393 where = where.toLowerCase();
4394 if(el.insertAdjacentHTML){
4395 if(tableRe.test(el.tagName)){
4397 if(rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html)){
4403 el.insertAdjacentHTML('BeforeBegin', html);
4404 return el.previousSibling;
4406 el.insertAdjacentHTML('AfterBegin', html);
4407 return el.firstChild;
4409 el.insertAdjacentHTML('BeforeEnd', html);
4410 return el.lastChild;
4412 el.insertAdjacentHTML('AfterEnd', html);
4413 return el.nextSibling;
4415 throw 'Illegal insertion point -> "' + where + '"';
4417 var range = el.ownerDocument.createRange();
4421 range.setStartBefore(el);
4422 frag = range.createContextualFragment(html);
4423 el.parentNode.insertBefore(frag, el);
4424 return el.previousSibling;
4427 range.setStartBefore(el.firstChild);
4428 frag = range.createContextualFragment(html);
4429 el.insertBefore(frag, el.firstChild);
4430 return el.firstChild;
4432 el.innerHTML = html;
4433 return el.firstChild;
4437 range.setStartAfter(el.lastChild);
4438 frag = range.createContextualFragment(html);
4439 el.appendChild(frag);
4440 return el.lastChild;
4442 el.innerHTML = html;
4443 return el.lastChild;
4446 range.setStartAfter(el);
4447 frag = range.createContextualFragment(html);
4448 el.parentNode.insertBefore(frag, el.nextSibling);
4449 return el.nextSibling;
4451 throw 'Illegal insertion point -> "' + where + '"';
4455 * Creates new Dom element(s) and inserts them before el
4456 * @param {String/HTMLElement/Element} el The context element
4457 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4458 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4459 * @return {HTMLElement/Roo.Element} The new node
4461 insertBefore : function(el, o, returnElement){
4462 return this.doInsert(el, o, returnElement, "beforeBegin");
4466 * Creates new Dom element(s) and inserts them after el
4467 * @param {String/HTMLElement/Element} el The context element
4468 * @param {Object} o The Dom object spec (and children)
4469 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4470 * @return {HTMLElement/Roo.Element} The new node
4472 insertAfter : function(el, o, returnElement){
4473 return this.doInsert(el, o, returnElement, "afterEnd", "nextSibling");
4477 * Creates new Dom element(s) and inserts them as the first child of el
4478 * @param {String/HTMLElement/Element} el The context element
4479 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4480 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4481 * @return {HTMLElement/Roo.Element} The new node
4483 insertFirst : function(el, o, returnElement){
4484 return this.doInsert(el, o, returnElement, "afterBegin");
4488 doInsert : function(el, o, returnElement, pos, sibling){
4489 el = Roo.getDom(el);
4491 if(this.useDom || o.ns){
4492 newNode = createDom(o, null);
4493 el.parentNode.insertBefore(newNode, sibling ? el[sibling] : el);
4495 var html = createHtml(o);
4496 newNode = this.insertHtml(pos, el, html);
4498 return returnElement ? Roo.get(newNode, true) : newNode;
4502 * Creates new Dom element(s) and appends them to el
4503 * @param {String/HTMLElement/Element} el The context element
4504 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4505 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4506 * @return {HTMLElement/Roo.Element} The new node
4508 append : function(el, o, returnElement){
4509 el = Roo.getDom(el);
4511 if(this.useDom || o.ns){
4512 newNode = createDom(o, null);
4513 el.appendChild(newNode);
4515 var html = createHtml(o);
4516 newNode = this.insertHtml("beforeEnd", el, html);
4518 return returnElement ? Roo.get(newNode, true) : newNode;
4522 * Creates new Dom element(s) and overwrites the contents of el with them
4523 * @param {String/HTMLElement/Element} el The context element
4524 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4525 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4526 * @return {HTMLElement/Roo.Element} The new node
4528 overwrite : function(el, o, returnElement){
4529 el = Roo.getDom(el);
4532 while (el.childNodes.length) {
4533 el.removeChild(el.firstChild);
4537 el.innerHTML = createHtml(o);
4540 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4544 * Creates a new Roo.DomHelper.Template from the Dom object spec
4545 * @param {Object} o The Dom object spec (and children)
4546 * @return {Roo.DomHelper.Template} The new template
4548 createTemplate : function(o){
4549 var html = createHtml(o);
4550 return new Roo.Template(html);
4556 * Ext JS Library 1.1.1
4557 * Copyright(c) 2006-2007, Ext JS, LLC.
4559 * Originally Released Under LGPL - original licence link has changed is not relivant.
4562 * <script type="text/javascript">
4566 * @class Roo.Template
4567 * Represents an HTML fragment template. Templates can be precompiled for greater performance.
4568 * For a list of available format functions, see {@link Roo.util.Format}.<br />
4571 var t = new Roo.Template({
4572 html : '<div name="{id}">' +
4573 '<span class="{cls}">{name:trim} {someval:this.myformat}{value:ellipsis(10)}</span>' +
4575 myformat: function (value, allValues) {
4576 return 'XX' + value;
4579 t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
4581 * For more information see this blog post with examples:
4582 * <a href="http://www.cnitblog.com/seeyeah/archive/2011/12/30/38728.html/">DomHelper
4583 - Create Elements using DOM, HTML fragments and Templates</a>.
4585 * @param {Object} cfg - Configuration object.
4587 Roo.Template = function(cfg){
4589 if(cfg instanceof Array){
4591 }else if(arguments.length > 1){
4592 cfg = Array.prototype.join.call(arguments, "");
4596 if (typeof(cfg) == 'object') {
4607 Roo.Template.prototype = {
4610 * @cfg {String} url The Url to load the template from. beware if you are loading from a url, the data may not be ready if you use it instantly..
4611 * it should be fixed so that template is observable...
4615 * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")
4619 * Returns an HTML fragment of this template with the specified values applied.
4620 * @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'})
4621 * @return {String} The HTML fragment
4623 applyTemplate : function(values){
4627 return this.compiled(values);
4629 var useF = this.disableFormats !== true;
4630 var fm = Roo.util.Format, tpl = this;
4631 var fn = function(m, name, format, args){
4633 if(format.substr(0, 5) == "this."){
4634 return tpl.call(format.substr(5), values[name], values);
4637 // quoted values are required for strings in compiled templates,
4638 // but for non compiled we need to strip them
4639 // quoted reversed for jsmin
4640 var re = /^\s*['"](.*)["']\s*$/;
4641 args = args.split(',');
4642 for(var i = 0, len = args.length; i < len; i++){
4643 args[i] = args[i].replace(re, "$1");
4645 args = [values[name]].concat(args);
4647 args = [values[name]];
4649 return fm[format].apply(fm, args);
4652 return values[name] !== undefined ? values[name] : "";
4655 return this.html.replace(this.re, fn);
4673 this.loading = true;
4674 this.compiled = false;
4676 var cx = new Roo.data.Connection();
4680 success : function (response) {
4682 _t.html = response.responseText;
4686 failure : function(response) {
4687 Roo.log("Template failed to load from " + _t.url);
4694 * Sets the HTML used as the template and optionally compiles it.
4695 * @param {String} html
4696 * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
4697 * @return {Roo.Template} this
4699 set : function(html, compile){
4701 this.compiled = null;
4709 * True to disable format functions (defaults to false)
4712 disableFormats : false,
4715 * The regular expression used to match template variables
4719 re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
4722 * Compiles the template into an internal function, eliminating the RegEx overhead.
4723 * @return {Roo.Template} this
4725 compile : function(){
4726 var fm = Roo.util.Format;
4727 var useF = this.disableFormats !== true;
4728 var sep = Roo.isGecko ? "+" : ",";
4729 var fn = function(m, name, format, args){
4731 args = args ? ',' + args : "";
4732 if(format.substr(0, 5) != "this."){
4733 format = "fm." + format + '(';
4735 format = 'this.call("'+ format.substr(5) + '", ';
4739 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
4741 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
4744 // branched to use + in gecko and [].join() in others
4746 body = "this.compiled = function(values){ return '" +
4747 this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
4750 body = ["this.compiled = function(values){ return ['"];
4751 body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
4752 body.push("'].join('');};");
4753 body = body.join('');
4763 // private function used to call members
4764 call : function(fnName, value, allValues){
4765 return this[fnName](value, allValues);
4769 * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
4770 * @param {String/HTMLElement/Roo.Element} el The context element
4771 * @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'})
4772 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4773 * @return {HTMLElement/Roo.Element} The new node or Element
4775 insertFirst: function(el, values, returnElement){
4776 return this.doInsert('afterBegin', el, values, returnElement);
4780 * Applies the supplied values to the template and inserts the new node(s) before el.
4781 * @param {String/HTMLElement/Roo.Element} el The context element
4782 * @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'})
4783 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4784 * @return {HTMLElement/Roo.Element} The new node or Element
4786 insertBefore: function(el, values, returnElement){
4787 return this.doInsert('beforeBegin', el, values, returnElement);
4791 * Applies the supplied values to the template and inserts the new node(s) after el.
4792 * @param {String/HTMLElement/Roo.Element} el The context element
4793 * @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'})
4794 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4795 * @return {HTMLElement/Roo.Element} The new node or Element
4797 insertAfter : function(el, values, returnElement){
4798 return this.doInsert('afterEnd', el, values, returnElement);
4802 * Applies the supplied values to the template and appends the new node(s) to el.
4803 * @param {String/HTMLElement/Roo.Element} el The context element
4804 * @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'})
4805 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4806 * @return {HTMLElement/Roo.Element} The new node or Element
4808 append : function(el, values, returnElement){
4809 return this.doInsert('beforeEnd', el, values, returnElement);
4812 doInsert : function(where, el, values, returnEl){
4813 el = Roo.getDom(el);
4814 var newNode = Roo.DomHelper.insertHtml(where, el, this.applyTemplate(values));
4815 return returnEl ? Roo.get(newNode, true) : newNode;
4819 * Applies the supplied values to the template and overwrites the content of el with the new node(s).
4820 * @param {String/HTMLElement/Roo.Element} el The context element
4821 * @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'})
4822 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4823 * @return {HTMLElement/Roo.Element} The new node or Element
4825 overwrite : function(el, values, returnElement){
4826 el = Roo.getDom(el);
4827 el.innerHTML = this.applyTemplate(values);
4828 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4832 * Alias for {@link #applyTemplate}
4835 Roo.Template.prototype.apply = Roo.Template.prototype.applyTemplate;
4838 Roo.DomHelper.Template = Roo.Template;
4841 * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
4842 * @param {String/HTMLElement} el A DOM element or its id
4843 * @returns {Roo.Template} The created template
4846 Roo.Template.from = function(el){
4847 el = Roo.getDom(el);
4848 return new Roo.Template(el.value || el.innerHTML);
4851 * Ext JS Library 1.1.1
4852 * Copyright(c) 2006-2007, Ext JS, LLC.
4854 * Originally Released Under LGPL - original licence link has changed is not relivant.
4857 * <script type="text/javascript">
4862 * This is code is also distributed under MIT license for use
4863 * with jQuery and prototype JavaScript libraries.
4866 * @class Roo.DomQuery
4867 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).
4869 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>
4872 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.
4874 <h4>Element Selectors:</h4>
4876 <li> <b>*</b> any element</li>
4877 <li> <b>E</b> an element with the tag E</li>
4878 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
4879 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
4880 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
4881 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
4883 <h4>Attribute Selectors:</h4>
4884 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
4886 <li> <b>E[foo]</b> has an attribute "foo"</li>
4887 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
4888 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
4889 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
4890 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
4891 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
4892 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
4894 <h4>Pseudo Classes:</h4>
4896 <li> <b>E:first-child</b> E is the first child of its parent</li>
4897 <li> <b>E:last-child</b> E is the last child of its parent</li>
4898 <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>
4899 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
4900 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
4901 <li> <b>E:only-child</b> E is the only child of its parent</li>
4902 <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>
4903 <li> <b>E:first</b> the first E in the resultset</li>
4904 <li> <b>E:last</b> the last E in the resultset</li>
4905 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
4906 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
4907 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
4908 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
4909 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
4910 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
4911 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
4912 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
4913 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
4915 <h4>CSS Value Selectors:</h4>
4917 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
4918 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
4919 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
4920 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
4921 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
4922 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
4926 Roo.DomQuery = function(){
4927 var cache = {}, simpleCache = {}, valueCache = {};
4928 var nonSpace = /\S/;
4929 var trimRe = /^\s+|\s+$/g;
4930 var tplRe = /\{(\d+)\}/g;
4931 var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
4932 var tagTokenRe = /^(#)?([\w-\*]+)/;
4933 var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/;
4935 function child(p, index){
4937 var n = p.firstChild;
4939 if(n.nodeType == 1){
4950 while((n = n.nextSibling) && n.nodeType != 1);
4955 while((n = n.previousSibling) && n.nodeType != 1);
4959 function children(d){
4960 var n = d.firstChild, ni = -1;
4962 var nx = n.nextSibling;
4963 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
4973 function byClassName(c, a, v){
4977 var r = [], ri = -1, cn;
4978 for(var i = 0, ci; ci = c[i]; i++){
4979 if((' '+ci.className+' ').indexOf(v) != -1){
4986 function attrValue(n, attr){
4987 if(!n.tagName && typeof n.length != "undefined"){
4996 if(attr == "class" || attr == "className"){
4999 return n.getAttribute(attr) || n[attr];
5003 function getNodes(ns, mode, tagName){
5004 var result = [], ri = -1, cs;
5008 tagName = tagName || "*";
5009 if(typeof ns.getElementsByTagName != "undefined"){
5013 for(var i = 0, ni; ni = ns[i]; i++){
5014 cs = ni.getElementsByTagName(tagName);
5015 for(var j = 0, ci; ci = cs[j]; j++){
5019 }else if(mode == "/" || mode == ">"){
5020 var utag = tagName.toUpperCase();
5021 for(var i = 0, ni, cn; ni = ns[i]; i++){
5022 cn = ni.children || ni.childNodes;
5023 for(var j = 0, cj; cj = cn[j]; j++){
5024 if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
5029 }else if(mode == "+"){
5030 var utag = tagName.toUpperCase();
5031 for(var i = 0, n; n = ns[i]; i++){
5032 while((n = n.nextSibling) && n.nodeType != 1);
5033 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
5037 }else if(mode == "~"){
5038 for(var i = 0, n; n = ns[i]; i++){
5039 while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName)));
5048 function concat(a, b){
5052 for(var i = 0, l = b.length; i < l; i++){
5058 function byTag(cs, tagName){
5059 if(cs.tagName || cs == document){
5065 var r = [], ri = -1;
5066 tagName = tagName.toLowerCase();
5067 for(var i = 0, ci; ci = cs[i]; i++){
5068 if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
5075 function byId(cs, attr, id){
5076 if(cs.tagName || cs == document){
5082 var r = [], ri = -1;
5083 for(var i = 0,ci; ci = cs[i]; i++){
5084 if(ci && ci.id == id){
5092 function byAttribute(cs, attr, value, op, custom){
5093 var r = [], ri = -1, st = custom=="{";
5094 var f = Roo.DomQuery.operators[op];
5095 for(var i = 0, ci; ci = cs[i]; i++){
5098 a = Roo.DomQuery.getStyle(ci, attr);
5100 else if(attr == "class" || attr == "className"){
5102 }else if(attr == "for"){
5104 }else if(attr == "href"){
5105 a = ci.getAttribute("href", 2);
5107 a = ci.getAttribute(attr);
5109 if((f && f(a, value)) || (!f && a)){
5116 function byPseudo(cs, name, value){
5117 return Roo.DomQuery.pseudos[name](cs, value);
5120 // This is for IE MSXML which does not support expandos.
5121 // IE runs the same speed using setAttribute, however FF slows way down
5122 // and Safari completely fails so they need to continue to use expandos.
5123 var isIE = window.ActiveXObject ? true : false;
5125 // this eval is stop the compressor from
5126 // renaming the variable to something shorter
5128 /** eval:var:batch */
5133 function nodupIEXml(cs){
5135 cs[0].setAttribute("_nodup", d);
5137 for(var i = 1, len = cs.length; i < len; i++){
5139 if(!c.getAttribute("_nodup") != d){
5140 c.setAttribute("_nodup", d);
5144 for(var i = 0, len = cs.length; i < len; i++){
5145 cs[i].removeAttribute("_nodup");
5154 var len = cs.length, c, i, r = cs, cj, ri = -1;
5155 if(!len || typeof cs.nodeType != "undefined" || len == 1){
5158 if(isIE && typeof cs[0].selectSingleNode != "undefined"){
5159 return nodupIEXml(cs);
5163 for(i = 1; c = cs[i]; i++){
5168 for(var j = 0; j < i; j++){
5171 for(j = i+1; cj = cs[j]; j++){
5183 function quickDiffIEXml(c1, c2){
5185 for(var i = 0, len = c1.length; i < len; i++){
5186 c1[i].setAttribute("_qdiff", d);
5189 for(var i = 0, len = c2.length; i < len; i++){
5190 if(c2[i].getAttribute("_qdiff") != d){
5191 r[r.length] = c2[i];
5194 for(var i = 0, len = c1.length; i < len; i++){
5195 c1[i].removeAttribute("_qdiff");
5200 function quickDiff(c1, c2){
5201 var len1 = c1.length;
5205 if(isIE && c1[0].selectSingleNode){
5206 return quickDiffIEXml(c1, c2);
5209 for(var i = 0; i < len1; i++){
5213 for(var i = 0, len = c2.length; i < len; i++){
5214 if(c2[i]._qdiff != d){
5215 r[r.length] = c2[i];
5221 function quickId(ns, mode, root, id){
5223 var d = root.ownerDocument || root;
5224 return d.getElementById(id);
5226 ns = getNodes(ns, mode, "*");
5227 return byId(ns, null, id);
5231 getStyle : function(el, name){
5232 return Roo.fly(el).getStyle(name);
5235 * Compiles a selector/xpath query into a reusable function. The returned function
5236 * takes one parameter "root" (optional), which is the context node from where the query should start.
5237 * @param {String} selector The selector/xpath query
5238 * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
5239 * @return {Function}
5241 compile : function(path, type){
5242 type = type || "select";
5244 var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"];
5245 var q = path, mode, lq;
5246 var tk = Roo.DomQuery.matchers;
5247 var tklen = tk.length;
5250 // accept leading mode switch
5251 var lmode = q.match(modeRe);
5252 if(lmode && lmode[1]){
5253 fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
5254 q = q.replace(lmode[1], "");
5256 // strip leading slashes
5257 while(path.substr(0, 1)=="/"){
5258 path = path.substr(1);
5261 while(q && lq != q){
5263 var tm = q.match(tagTokenRe);
5264 if(type == "select"){
5267 fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';
5269 fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';
5271 q = q.replace(tm[0], "");
5272 }else if(q.substr(0, 1) != '@'){
5273 fn[fn.length] = 'n = getNodes(n, mode, "*");';
5278 fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';
5280 fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';
5282 q = q.replace(tm[0], "");
5285 while(!(mm = q.match(modeRe))){
5286 var matched = false;
5287 for(var j = 0; j < tklen; j++){
5289 var m = q.match(t.re);
5291 fn[fn.length] = t.select.replace(tplRe, function(x, i){
5294 q = q.replace(m[0], "");
5299 // prevent infinite loop on bad selector
5301 throw 'Error parsing selector, parsing failed at "' + q + '"';
5305 fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";';
5306 q = q.replace(mm[1], "");
5309 fn[fn.length] = "return nodup(n);\n}";
5312 * list of variables that need from compression as they are used by eval.
5322 * eval:var:byClassName
5324 * eval:var:byAttribute
5325 * eval:var:attrValue
5333 * Selects a group of elements.
5334 * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
5335 * @param {Node} root (optional) The start of the query (defaults to document).
5338 select : function(path, root, type){
5339 if(!root || root == document){
5342 if(typeof root == "string"){
5343 root = document.getElementById(root);
5345 var paths = path.split(",");
5347 for(var i = 0, len = paths.length; i < len; i++){
5348 var p = paths[i].replace(trimRe, "");
5350 cache[p] = Roo.DomQuery.compile(p);
5352 throw p + " is not a valid selector";
5355 var result = cache[p](root);
5356 if(result && result != document){
5357 results = results.concat(result);
5360 if(paths.length > 1){
5361 return nodup(results);
5367 * Selects a single element.
5368 * @param {String} selector The selector/xpath query
5369 * @param {Node} root (optional) The start of the query (defaults to document).
5372 selectNode : function(path, root){
5373 return Roo.DomQuery.select(path, root)[0];
5377 * Selects the value of a node, optionally replacing null with the defaultValue.
5378 * @param {String} selector The selector/xpath query
5379 * @param {Node} root (optional) The start of the query (defaults to document).
5380 * @param {String} defaultValue
5382 selectValue : function(path, root, defaultValue){
5383 path = path.replace(trimRe, "");
5384 if(!valueCache[path]){
5385 valueCache[path] = Roo.DomQuery.compile(path, "select");
5387 var n = valueCache[path](root);
5388 n = n[0] ? n[0] : n;
5389 var v = (n && n.firstChild ? n.firstChild.nodeValue : null);
5390 return ((v === null||v === undefined||v==='') ? defaultValue : v);
5394 * Selects the value of a node, parsing integers and floats.
5395 * @param {String} selector The selector/xpath query
5396 * @param {Node} root (optional) The start of the query (defaults to document).
5397 * @param {Number} defaultValue
5400 selectNumber : function(path, root, defaultValue){
5401 var v = Roo.DomQuery.selectValue(path, root, defaultValue || 0);
5402 return parseFloat(v);
5406 * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
5407 * @param {String/HTMLElement/Array} el An element id, element or array of elements
5408 * @param {String} selector The simple selector to test
5411 is : function(el, ss){
5412 if(typeof el == "string"){
5413 el = document.getElementById(el);
5415 var isArray = (el instanceof Array);
5416 var result = Roo.DomQuery.filter(isArray ? el : [el], ss);
5417 return isArray ? (result.length == el.length) : (result.length > 0);
5421 * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
5422 * @param {Array} el An array of elements to filter
5423 * @param {String} selector The simple selector to test
5424 * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
5425 * the selector instead of the ones that match
5428 filter : function(els, ss, nonMatches){
5429 ss = ss.replace(trimRe, "");
5430 if(!simpleCache[ss]){
5431 simpleCache[ss] = Roo.DomQuery.compile(ss, "simple");
5433 var result = simpleCache[ss](els);
5434 return nonMatches ? quickDiff(result, els) : result;
5438 * Collection of matching regular expressions and code snippets.
5442 select: 'n = byClassName(n, null, " {1} ");'
5444 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
5445 select: 'n = byPseudo(n, "{1}", "{2}");'
5447 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
5448 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
5451 select: 'n = byId(n, null, "{1}");'
5454 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
5459 * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
5460 * 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, > <.
5463 "=" : function(a, v){
5466 "!=" : function(a, v){
5469 "^=" : function(a, v){
5470 return a && a.substr(0, v.length) == v;
5472 "$=" : function(a, v){
5473 return a && a.substr(a.length-v.length) == v;
5475 "*=" : function(a, v){
5476 return a && a.indexOf(v) !== -1;
5478 "%=" : function(a, v){
5479 return (a % v) == 0;
5481 "|=" : function(a, v){
5482 return a && (a == v || a.substr(0, v.length+1) == v+'-');
5484 "~=" : function(a, v){
5485 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
5490 * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
5491 * and the argument (if any) supplied in the selector.
5494 "first-child" : function(c){
5495 var r = [], ri = -1, n;
5496 for(var i = 0, ci; ci = n = c[i]; i++){
5497 while((n = n.previousSibling) && n.nodeType != 1);
5505 "last-child" : function(c){
5506 var r = [], ri = -1, n;
5507 for(var i = 0, ci; ci = n = c[i]; i++){
5508 while((n = n.nextSibling) && n.nodeType != 1);
5516 "nth-child" : function(c, a) {
5517 var r = [], ri = -1;
5518 var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a);
5519 var f = (m[1] || 1) - 0, l = m[2] - 0;
5520 for(var i = 0, n; n = c[i]; i++){
5521 var pn = n.parentNode;
5522 if (batch != pn._batch) {
5524 for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
5525 if(cn.nodeType == 1){
5532 if (l == 0 || n.nodeIndex == l){
5535 } else if ((n.nodeIndex + l) % f == 0){
5543 "only-child" : function(c){
5544 var r = [], ri = -1;;
5545 for(var i = 0, ci; ci = c[i]; i++){
5546 if(!prev(ci) && !next(ci)){
5553 "empty" : function(c){
5554 var r = [], ri = -1;
5555 for(var i = 0, ci; ci = c[i]; i++){
5556 var cns = ci.childNodes, j = 0, cn, empty = true;
5559 if(cn.nodeType == 1 || cn.nodeType == 3){
5571 "contains" : function(c, v){
5572 var r = [], ri = -1;
5573 for(var i = 0, ci; ci = c[i]; i++){
5574 if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
5581 "nodeValue" : function(c, v){
5582 var r = [], ri = -1;
5583 for(var i = 0, ci; ci = c[i]; i++){
5584 if(ci.firstChild && ci.firstChild.nodeValue == v){
5591 "checked" : function(c){
5592 var r = [], ri = -1;
5593 for(var i = 0, ci; ci = c[i]; i++){
5594 if(ci.checked == true){
5601 "not" : function(c, ss){
5602 return Roo.DomQuery.filter(c, ss, true);
5605 "odd" : function(c){
5606 return this["nth-child"](c, "odd");
5609 "even" : function(c){
5610 return this["nth-child"](c, "even");
5613 "nth" : function(c, a){
5614 return c[a-1] || [];
5617 "first" : function(c){
5621 "last" : function(c){
5622 return c[c.length-1] || [];
5625 "has" : function(c, ss){
5626 var s = Roo.DomQuery.select;
5627 var r = [], ri = -1;
5628 for(var i = 0, ci; ci = c[i]; i++){
5629 if(s(ss, ci).length > 0){
5636 "next" : function(c, ss){
5637 var is = Roo.DomQuery.is;
5638 var r = [], ri = -1;
5639 for(var i = 0, ci; ci = c[i]; i++){
5648 "prev" : function(c, ss){
5649 var is = Roo.DomQuery.is;
5650 var r = [], ri = -1;
5651 for(var i = 0, ci; ci = c[i]; i++){
5664 * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Roo.DomQuery#select}
5665 * @param {String} path The selector/xpath query
5666 * @param {Node} root (optional) The start of the query (defaults to document).
5671 Roo.query = Roo.DomQuery.select;
5674 * Ext JS Library 1.1.1
5675 * Copyright(c) 2006-2007, Ext JS, LLC.
5677 * Originally Released Under LGPL - original licence link has changed is not relivant.
5680 * <script type="text/javascript">
5684 * @class Roo.util.Observable
5685 * Base class that provides a common interface for publishing events. Subclasses are expected to
5686 * to have a property "events" with all the events defined.<br>
5689 Employee = function(name){
5696 Roo.extend(Employee, Roo.util.Observable);
5698 * @param {Object} config properties to use (incuding events / listeners)
5701 Roo.util.Observable = function(cfg){
5704 this.addEvents(cfg.events || {});
5706 delete cfg.events; // make sure
5709 Roo.apply(this, cfg);
5712 this.on(this.listeners);
5713 delete this.listeners;
5716 Roo.util.Observable.prototype = {
5718 * @cfg {Object} listeners list of events and functions to call for this object,
5722 'click' : function(e) {
5732 * Fires the specified event with the passed parameters (minus the event name).
5733 * @param {String} eventName
5734 * @param {Object...} args Variable number of parameters are passed to handlers
5735 * @return {Boolean} returns false if any of the handlers return false otherwise it returns true
5737 fireEvent : function(){
5738 var ce = this.events[arguments[0].toLowerCase()];
5739 if(typeof ce == "object"){
5740 return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
5747 filterOptRe : /^(?:scope|delay|buffer|single)$/,
5750 * Appends an event handler to this component
5751 * @param {String} eventName The type of event to listen for
5752 * @param {Function} handler The method the event invokes
5753 * @param {Object} scope (optional) The scope in which to execute the handler
5754 * function. The handler function's "this" context.
5755 * @param {Object} options (optional) An object containing handler configuration
5756 * properties. This may contain any of the following properties:<ul>
5757 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
5758 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
5759 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
5760 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
5761 * by the specified number of milliseconds. If the event fires again within that time, the original
5762 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
5765 * <b>Combining Options</b><br>
5766 * Using the options argument, it is possible to combine different types of listeners:<br>
5768 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
5770 el.on('click', this.onClick, this, {
5777 * <b>Attaching multiple handlers in 1 call</b><br>
5778 * The method also allows for a single argument to be passed which is a config object containing properties
5779 * which specify multiple handlers.
5788 fn: this.onMouseOver,
5792 fn: this.onMouseOut,
5798 * Or a shorthand syntax which passes the same scope object to all handlers:
5801 'click': this.onClick,
5802 'mouseover': this.onMouseOver,
5803 'mouseout': this.onMouseOut,
5808 addListener : function(eventName, fn, scope, o){
5809 if(typeof eventName == "object"){
5812 if(this.filterOptRe.test(e)){
5815 if(typeof o[e] == "function"){
5817 this.addListener(e, o[e], o.scope, o);
5819 // individual options
5820 this.addListener(e, o[e].fn, o[e].scope, o[e]);
5825 o = (!o || typeof o == "boolean") ? {} : o;
5826 eventName = eventName.toLowerCase();
5827 var ce = this.events[eventName] || true;
5828 if(typeof ce == "boolean"){
5829 ce = new Roo.util.Event(this, eventName);
5830 this.events[eventName] = ce;
5832 ce.addListener(fn, scope, o);
5836 * Removes a listener
5837 * @param {String} eventName The type of event to listen for
5838 * @param {Function} handler The handler to remove
5839 * @param {Object} scope (optional) The scope (this object) for the handler
5841 removeListener : function(eventName, fn, scope){
5842 var ce = this.events[eventName.toLowerCase()];
5843 if(typeof ce == "object"){
5844 ce.removeListener(fn, scope);
5849 * Removes all listeners for this object
5851 purgeListeners : function(){
5852 for(var evt in this.events){
5853 if(typeof this.events[evt] == "object"){
5854 this.events[evt].clearListeners();
5859 relayEvents : function(o, events){
5860 var createHandler = function(ename){
5862 return this.fireEvent.apply(this, Roo.combine(ename, Array.prototype.slice.call(arguments, 0)));
5865 for(var i = 0, len = events.length; i < len; i++){
5866 var ename = events[i];
5867 if(!this.events[ename]){ this.events[ename] = true; };
5868 o.on(ename, createHandler(ename), this);
5873 * Used to define events on this Observable
5874 * @param {Object} object The object with the events defined
5876 addEvents : function(o){
5880 Roo.applyIf(this.events, o);
5884 * Checks to see if this object has any listeners for a specified event
5885 * @param {String} eventName The name of the event to check for
5886 * @return {Boolean} True if the event is being listened for, else false
5888 hasListener : function(eventName){
5889 var e = this.events[eventName];
5890 return typeof e == "object" && e.listeners.length > 0;
5894 * Appends an event handler to this element (shorthand for addListener)
5895 * @param {String} eventName The type of event to listen for
5896 * @param {Function} handler The method the event invokes
5897 * @param {Object} scope (optional) The scope in which to execute the handler
5898 * function. The handler function's "this" context.
5899 * @param {Object} options (optional)
5902 Roo.util.Observable.prototype.on = Roo.util.Observable.prototype.addListener;
5904 * Removes a listener (shorthand for removeListener)
5905 * @param {String} eventName The type of event to listen for
5906 * @param {Function} handler The handler to remove
5907 * @param {Object} scope (optional) The scope (this object) for the handler
5910 Roo.util.Observable.prototype.un = Roo.util.Observable.prototype.removeListener;
5913 * Starts capture on the specified Observable. All events will be passed
5914 * to the supplied function with the event name + standard signature of the event
5915 * <b>before</b> the event is fired. If the supplied function returns false,
5916 * the event will not fire.
5917 * @param {Observable} o The Observable to capture
5918 * @param {Function} fn The function to call
5919 * @param {Object} scope (optional) The scope (this object) for the fn
5922 Roo.util.Observable.capture = function(o, fn, scope){
5923 o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
5927 * Removes <b>all</b> added captures from the Observable.
5928 * @param {Observable} o The Observable to release
5931 Roo.util.Observable.releaseCapture = function(o){
5932 o.fireEvent = Roo.util.Observable.prototype.fireEvent;
5937 var createBuffered = function(h, o, scope){
5938 var task = new Roo.util.DelayedTask();
5940 task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0));
5944 var createSingle = function(h, e, fn, scope){
5946 e.removeListener(fn, scope);
5947 return h.apply(scope, arguments);
5951 var createDelayed = function(h, o, scope){
5953 var args = Array.prototype.slice.call(arguments, 0);
5954 setTimeout(function(){
5955 h.apply(scope, args);
5960 Roo.util.Event = function(obj, name){
5963 this.listeners = [];
5966 Roo.util.Event.prototype = {
5967 addListener : function(fn, scope, options){
5968 var o = options || {};
5969 scope = scope || this.obj;
5970 if(!this.isListening(fn, scope)){
5971 var l = {fn: fn, scope: scope, options: o};
5974 h = createDelayed(h, o, scope);
5977 h = createSingle(h, this, fn, scope);
5980 h = createBuffered(h, o, scope);
5983 if(!this.firing){ // if we are currently firing this event, don't disturb the listener loop
5984 this.listeners.push(l);
5986 this.listeners = this.listeners.slice(0);
5987 this.listeners.push(l);
5992 findListener : function(fn, scope){
5993 scope = scope || this.obj;
5994 var ls = this.listeners;
5995 for(var i = 0, len = ls.length; i < len; i++){
5997 if(l.fn == fn && l.scope == scope){
6004 isListening : function(fn, scope){
6005 return this.findListener(fn, scope) != -1;
6008 removeListener : function(fn, scope){
6010 if((index = this.findListener(fn, scope)) != -1){
6012 this.listeners.splice(index, 1);
6014 this.listeners = this.listeners.slice(0);
6015 this.listeners.splice(index, 1);
6022 clearListeners : function(){
6023 this.listeners = [];
6027 var ls = this.listeners, scope, len = ls.length;
6030 var args = Array.prototype.slice.call(arguments, 0);
6031 for(var i = 0; i < len; i++){
6033 if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
6034 this.firing = false;
6038 this.firing = false;
6045 * Ext JS Library 1.1.1
6046 * Copyright(c) 2006-2007, Ext JS, LLC.
6048 * Originally Released Under LGPL - original licence link has changed is not relivant.
6051 * <script type="text/javascript">
6055 * @class Roo.EventManager
6056 * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
6057 * several useful events directly.
6058 * See {@link Roo.EventObject} for more details on normalized event objects.
6061 Roo.EventManager = function(){
6062 var docReadyEvent, docReadyProcId, docReadyState = false;
6063 var resizeEvent, resizeTask, textEvent, textSize;
6064 var E = Roo.lib.Event;
6065 var D = Roo.lib.Dom;
6070 var fireDocReady = function(){
6072 docReadyState = true;
6075 clearInterval(docReadyProcId);
6077 if(Roo.isGecko || Roo.isOpera) {
6078 document.removeEventListener("DOMContentLoaded", fireDocReady, false);
6081 var defer = document.getElementById("ie-deferred-loader");
6083 defer.onreadystatechange = null;
6084 defer.parentNode.removeChild(defer);
6088 docReadyEvent.fire();
6089 docReadyEvent.clearListeners();
6094 var initDocReady = function(){
6095 docReadyEvent = new Roo.util.Event();
6096 if(Roo.isGecko || Roo.isOpera) {
6097 document.addEventListener("DOMContentLoaded", fireDocReady, false);
6099 document.write("<s"+'cript id="ie-deferred-loader" defer="defer" src="/'+'/:"></s'+"cript>");
6100 var defer = document.getElementById("ie-deferred-loader");
6101 defer.onreadystatechange = function(){
6102 if(this.readyState == "complete"){
6106 }else if(Roo.isSafari){
6107 docReadyProcId = setInterval(function(){
6108 var rs = document.readyState;
6109 if(rs == "complete") {
6114 // no matter what, make sure it fires on load
6115 E.on(window, "load", fireDocReady);
6118 var createBuffered = function(h, o){
6119 var task = new Roo.util.DelayedTask(h);
6121 // create new event object impl so new events don't wipe out properties
6122 e = new Roo.EventObjectImpl(e);
6123 task.delay(o.buffer, h, null, [e]);
6127 var createSingle = function(h, el, ename, fn){
6129 Roo.EventManager.removeListener(el, ename, fn);
6134 var createDelayed = function(h, o){
6136 // create new event object impl so new events don't wipe out properties
6137 e = new Roo.EventObjectImpl(e);
6138 setTimeout(function(){
6143 var transitionEndVal = false;
6145 var transitionEnd = function()
6147 if (transitionEndVal) {
6148 return transitionEndVal;
6150 var el = document.createElement('div');
6152 var transEndEventNames = {
6153 WebkitTransition : 'webkitTransitionEnd',
6154 MozTransition : 'transitionend',
6155 OTransition : 'oTransitionEnd otransitionend',
6156 transition : 'transitionend'
6159 for (var name in transEndEventNames) {
6160 if (el.style[name] !== undefined) {
6161 transitionEndVal = transEndEventNames[name];
6162 return transitionEndVal ;
6168 var listen = function(element, ename, opt, fn, scope){
6169 var o = (!opt || typeof opt == "boolean") ? {} : opt;
6170 fn = fn || o.fn; scope = scope || o.scope;
6171 var el = Roo.getDom(element);
6175 throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
6178 if (ename == 'transitionend') {
6179 ename = transitionEnd();
6181 var h = function(e){
6182 e = Roo.EventObject.setEvent(e);
6185 t = e.getTarget(o.delegate, el);
6192 if(o.stopEvent === true){
6195 if(o.preventDefault === true){
6198 if(o.stopPropagation === true){
6199 e.stopPropagation();
6202 if(o.normalized === false){
6206 fn.call(scope || el, e, t, o);
6209 h = createDelayed(h, o);
6212 h = createSingle(h, el, ename, fn);
6215 h = createBuffered(h, o);
6217 fn._handlers = fn._handlers || [];
6220 fn._handlers.push([Roo.id(el), ename, h]);
6225 if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery
6226 el.addEventListener("DOMMouseScroll", h, false);
6227 E.on(window, 'unload', function(){
6228 el.removeEventListener("DOMMouseScroll", h, false);
6231 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6232 Roo.EventManager.stoppedMouseDownEvent.addListener(h);
6237 var stopListening = function(el, ename, fn){
6238 var id = Roo.id(el), hds = fn._handlers, hd = fn;
6240 for(var i = 0, len = hds.length; i < len; i++){
6242 if(h[0] == id && h[1] == ename){
6249 E.un(el, ename, hd);
6250 el = Roo.getDom(el);
6251 if(ename == "mousewheel" && el.addEventListener){
6252 el.removeEventListener("DOMMouseScroll", hd, false);
6254 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6255 Roo.EventManager.stoppedMouseDownEvent.removeListener(hd);
6259 var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
6266 * @scope Roo.EventManager
6271 * This is no longer needed and is deprecated. Places a simple wrapper around an event handler to override the browser event
6272 * object with a Roo.EventObject
6273 * @param {Function} fn The method the event invokes
6274 * @param {Object} scope An object that becomes the scope of the handler
6275 * @param {boolean} override If true, the obj passed in becomes
6276 * the execution scope of the listener
6277 * @return {Function} The wrapped function
6280 wrap : function(fn, scope, override){
6282 Roo.EventObject.setEvent(e);
6283 fn.call(override ? scope || window : window, Roo.EventObject, scope);
6288 * Appends an event handler to an element (shorthand for addListener)
6289 * @param {String/HTMLElement} element The html element or id to assign the
6290 * @param {String} eventName The type of event to listen for
6291 * @param {Function} handler The method the event invokes
6292 * @param {Object} scope (optional) The scope in which to execute the handler
6293 * function. The handler function's "this" context.
6294 * @param {Object} options (optional) An object containing handler configuration
6295 * properties. This may contain any of the following properties:<ul>
6296 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6297 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6298 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6299 * <li>preventDefault {Boolean} True to prevent the default action</li>
6300 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6301 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6302 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6303 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6304 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6305 * by the specified number of milliseconds. If the event fires again within that time, the original
6306 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6309 * <b>Combining Options</b><br>
6310 * Using the options argument, it is possible to combine different types of listeners:<br>
6312 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6314 el.on('click', this.onClick, this, {
6321 * <b>Attaching multiple handlers in 1 call</b><br>
6322 * The method also allows for a single argument to be passed which is a config object containing properties
6323 * which specify multiple handlers.
6333 fn: this.onMouseOver
6342 * Or a shorthand syntax:<br>
6345 'click' : this.onClick,
6346 'mouseover' : this.onMouseOver,
6347 'mouseout' : this.onMouseOut
6351 addListener : function(element, eventName, fn, scope, options){
6352 if(typeof eventName == "object"){
6358 if(typeof o[e] == "function"){
6360 listen(element, e, o, o[e], o.scope);
6362 // individual options
6363 listen(element, e, o[e]);
6368 return listen(element, eventName, options, fn, scope);
6372 * Removes an event handler
6374 * @param {String/HTMLElement} element The id or html element to remove the
6376 * @param {String} eventName The type of event
6377 * @param {Function} fn
6378 * @return {Boolean} True if a listener was actually removed
6380 removeListener : function(element, eventName, fn){
6381 return stopListening(element, eventName, fn);
6385 * Fires when the document is ready (before onload and before images are loaded). Can be
6386 * accessed shorthanded Roo.onReady().
6387 * @param {Function} fn The method the event invokes
6388 * @param {Object} scope An object that becomes the scope of the handler
6389 * @param {boolean} options
6391 onDocumentReady : function(fn, scope, options){
6392 if(docReadyState){ // if it already fired
6393 docReadyEvent.addListener(fn, scope, options);
6394 docReadyEvent.fire();
6395 docReadyEvent.clearListeners();
6401 docReadyEvent.addListener(fn, scope, options);
6405 * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers.
6406 * @param {Function} fn The method the event invokes
6407 * @param {Object} scope An object that becomes the scope of the handler
6408 * @param {boolean} options
6410 onWindowResize : function(fn, scope, options){
6412 resizeEvent = new Roo.util.Event();
6413 resizeTask = new Roo.util.DelayedTask(function(){
6414 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6416 E.on(window, "resize", function(){
6418 resizeTask.delay(50);
6420 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6424 resizeEvent.addListener(fn, scope, options);
6428 * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
6429 * @param {Function} fn The method the event invokes
6430 * @param {Object} scope An object that becomes the scope of the handler
6431 * @param {boolean} options
6433 onTextResize : function(fn, scope, options){
6435 textEvent = new Roo.util.Event();
6436 var textEl = new Roo.Element(document.createElement('div'));
6437 textEl.dom.className = 'x-text-resize';
6438 textEl.dom.innerHTML = 'X';
6439 textEl.appendTo(document.body);
6440 textSize = textEl.dom.offsetHeight;
6441 setInterval(function(){
6442 if(textEl.dom.offsetHeight != textSize){
6443 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
6445 }, this.textResizeInterval);
6447 textEvent.addListener(fn, scope, options);
6451 * Removes the passed window resize listener.
6452 * @param {Function} fn The method the event invokes
6453 * @param {Object} scope The scope of handler
6455 removeResizeListener : function(fn, scope){
6457 resizeEvent.removeListener(fn, scope);
6462 fireResize : function(){
6464 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6468 * Url used for onDocumentReady with using SSL (defaults to Roo.SSL_SECURE_URL)
6472 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
6474 textResizeInterval : 50
6479 * @scopeAlias pub=Roo.EventManager
6483 * Appends an event handler to an element (shorthand for addListener)
6484 * @param {String/HTMLElement} element The html element or id to assign the
6485 * @param {String} eventName The type of event to listen for
6486 * @param {Function} handler The method the event invokes
6487 * @param {Object} scope (optional) The scope in which to execute the handler
6488 * function. The handler function's "this" context.
6489 * @param {Object} options (optional) An object containing handler configuration
6490 * properties. This may contain any of the following properties:<ul>
6491 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6492 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6493 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6494 * <li>preventDefault {Boolean} True to prevent the default action</li>
6495 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6496 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6497 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6498 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6499 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6500 * by the specified number of milliseconds. If the event fires again within that time, the original
6501 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6504 * <b>Combining Options</b><br>
6505 * Using the options argument, it is possible to combine different types of listeners:<br>
6507 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6509 el.on('click', this.onClick, this, {
6516 * <b>Attaching multiple handlers in 1 call</b><br>
6517 * The method also allows for a single argument to be passed which is a config object containing properties
6518 * which specify multiple handlers.
6528 fn: this.onMouseOver
6537 * Or a shorthand syntax:<br>
6540 'click' : this.onClick,
6541 'mouseover' : this.onMouseOver,
6542 'mouseout' : this.onMouseOut
6546 pub.on = pub.addListener;
6547 pub.un = pub.removeListener;
6549 pub.stoppedMouseDownEvent = new Roo.util.Event();
6553 * Fires when the document is ready (before onload and before images are loaded). Shorthand of {@link Roo.EventManager#onDocumentReady}.
6554 * @param {Function} fn The method the event invokes
6555 * @param {Object} scope An object that becomes the scope of the handler
6556 * @param {boolean} override If true, the obj passed in becomes
6557 * the execution scope of the listener
6561 Roo.onReady = Roo.EventManager.onDocumentReady;
6563 Roo.onReady(function(){
6564 var bd = Roo.get(document.body);
6569 : Roo.isGecko ? "roo-gecko"
6570 : Roo.isOpera ? "roo-opera"
6571 : Roo.isSafari ? "roo-safari" : ""];
6574 cls.push("roo-mac");
6577 cls.push("roo-linux");
6579 if(Roo.isBorderBox){
6580 cls.push('roo-border-box');
6582 if(Roo.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"
6583 var p = bd.dom.parentNode;
6585 p.className += ' roo-strict';
6588 bd.addClass(cls.join(' '));
6592 * @class Roo.EventObject
6593 * EventObject exposes the Yahoo! UI Event functionality directly on the object
6594 * passed to your event handler. It exists mostly for convenience. It also fixes the annoying null checks automatically to cleanup your code
6597 function handleClick(e){ // e is not a standard event object, it is a Roo.EventObject
6599 var target = e.getTarget();
6602 var myDiv = Roo.get("myDiv");
6603 myDiv.on("click", handleClick);
6605 Roo.EventManager.on("myDiv", 'click', handleClick);
6606 Roo.EventManager.addListener("myDiv", 'click', handleClick);
6610 Roo.EventObject = function(){
6612 var E = Roo.lib.Event;
6614 // safari keypress events for special keys return bad keycodes
6617 63235 : 39, // right
6620 63276 : 33, // page up
6621 63277 : 34, // page down
6622 63272 : 46, // delete
6627 // normalize button clicks
6628 var btnMap = Roo.isIE ? {1:0,4:1,2:2} :
6629 (Roo.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
6631 Roo.EventObjectImpl = function(e){
6633 this.setEvent(e.browserEvent || e);
6636 Roo.EventObjectImpl.prototype = {
6638 * Used to fix doc tools.
6639 * @scope Roo.EventObject.prototype
6645 /** The normal browser event */
6646 browserEvent : null,
6647 /** The button pressed in a mouse event */
6649 /** True if the shift key was down during the event */
6651 /** True if the control key was down during the event */
6653 /** True if the alt key was down during the event */
6712 setEvent : function(e){
6713 if(e == this || (e && e.browserEvent)){ // already wrapped
6716 this.browserEvent = e;
6718 // normalize buttons
6719 this.button = e.button ? btnMap[e.button] : (e.which ? e.which-1 : -1);
6720 if(e.type == 'click' && this.button == -1){
6724 this.shiftKey = e.shiftKey;
6725 // mac metaKey behaves like ctrlKey
6726 this.ctrlKey = e.ctrlKey || e.metaKey;
6727 this.altKey = e.altKey;
6728 // in getKey these will be normalized for the mac
6729 this.keyCode = e.keyCode;
6730 // keyup warnings on firefox.
6731 this.charCode = (e.type == 'keyup' || e.type == 'keydown') ? 0 : e.charCode;
6732 // cache the target for the delayed and or buffered events
6733 this.target = E.getTarget(e);
6735 this.xy = E.getXY(e);
6738 this.shiftKey = false;
6739 this.ctrlKey = false;
6740 this.altKey = false;
6750 * Stop the event (preventDefault and stopPropagation)
6752 stopEvent : function(){
6753 if(this.browserEvent){
6754 if(this.browserEvent.type == 'mousedown'){
6755 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6757 E.stopEvent(this.browserEvent);
6762 * Prevents the browsers default handling of the event.
6764 preventDefault : function(){
6765 if(this.browserEvent){
6766 E.preventDefault(this.browserEvent);
6771 isNavKeyPress : function(){
6772 var k = this.keyCode;
6773 k = Roo.isSafari ? (safariKeys[k] || k) : k;
6774 return (k >= 33 && k <= 40) || k == this.RETURN || k == this.TAB || k == this.ESC;
6777 isSpecialKey : function(){
6778 var k = this.keyCode;
6779 return (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13 || k == 40 || k == 27 ||
6780 (k == 16) || (k == 17) ||
6781 (k >= 18 && k <= 20) ||
6782 (k >= 33 && k <= 35) ||
6783 (k >= 36 && k <= 39) ||
6784 (k >= 44 && k <= 45);
6787 * Cancels bubbling of the event.
6789 stopPropagation : function(){
6790 if(this.browserEvent){
6791 if(this.type == 'mousedown'){
6792 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6794 E.stopPropagation(this.browserEvent);
6799 * Gets the key code for the event.
6802 getCharCode : function(){
6803 return this.charCode || this.keyCode;
6807 * Returns a normalized keyCode for the event.
6808 * @return {Number} The key code
6810 getKey : function(){
6811 var k = this.keyCode || this.charCode;
6812 return Roo.isSafari ? (safariKeys[k] || k) : k;
6816 * Gets the x coordinate of the event.
6819 getPageX : function(){
6824 * Gets the y coordinate of the event.
6827 getPageY : function(){
6832 * Gets the time of the event.
6835 getTime : function(){
6836 if(this.browserEvent){
6837 return E.getTime(this.browserEvent);
6843 * Gets the page coordinates of the event.
6844 * @return {Array} The xy values like [x, y]
6851 * Gets the target for the event.
6852 * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
6853 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6854 search as a number or element (defaults to 10 || document.body)
6855 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6856 * @return {HTMLelement}
6858 getTarget : function(selector, maxDepth, returnEl){
6859 return selector ? Roo.fly(this.target).findParent(selector, maxDepth, returnEl) : this.target;
6862 * Gets the related target.
6863 * @return {HTMLElement}
6865 getRelatedTarget : function(){
6866 if(this.browserEvent){
6867 return E.getRelatedTarget(this.browserEvent);
6873 * Normalizes mouse wheel delta across browsers
6874 * @return {Number} The delta
6876 getWheelDelta : function(){
6877 var e = this.browserEvent;
6879 if(e.wheelDelta){ /* IE/Opera. */
6880 delta = e.wheelDelta/120;
6881 }else if(e.detail){ /* Mozilla case. */
6882 delta = -e.detail/3;
6888 * Returns true if the control, meta, shift or alt key was pressed during this event.
6891 hasModifier : function(){
6892 return !!((this.ctrlKey || this.altKey) || this.shiftKey);
6896 * Returns true if the target of this event equals el or is a child of el
6897 * @param {String/HTMLElement/Element} el
6898 * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
6901 within : function(el, related){
6902 var t = this[related ? "getRelatedTarget" : "getTarget"]();
6903 return t && Roo.fly(el).contains(t);
6906 getPoint : function(){
6907 return new Roo.lib.Point(this.xy[0], this.xy[1]);
6911 return new Roo.EventObjectImpl();
6916 * Ext JS Library 1.1.1
6917 * Copyright(c) 2006-2007, Ext JS, LLC.
6919 * Originally Released Under LGPL - original licence link has changed is not relivant.
6922 * <script type="text/javascript">
6926 // was in Composite Element!??!?!
6929 var D = Roo.lib.Dom;
6930 var E = Roo.lib.Event;
6931 var A = Roo.lib.Anim;
6933 // local style camelizing for speed
6935 var camelRe = /(-[a-z])/gi;
6936 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
6937 var view = document.defaultView;
6940 * @class Roo.Element
6941 * Represents an Element in the DOM.<br><br>
6944 var el = Roo.get("my-div");
6947 var el = getEl("my-div");
6949 // or with a DOM element
6950 var el = Roo.get(myDivElement);
6952 * Using Roo.get() or getEl() instead of calling the constructor directly ensures you get the same object
6953 * each call instead of constructing a new one.<br><br>
6954 * <b>Animations</b><br />
6955 * Many of the functions for manipulating an element have an optional "animate" parameter. The animate parameter
6956 * should either be a boolean (true) or an object literal with animation options. The animation options are:
6958 Option Default Description
6959 --------- -------- ---------------------------------------------
6960 duration .35 The duration of the animation in seconds
6961 easing easeOut The YUI easing method
6962 callback none A function to execute when the anim completes
6963 scope this The scope (this) of the callback function
6965 * Also, the Anim object being used for the animation will be set on your options object as "anim", which allows you to stop or
6966 * manipulate the animation. Here's an example:
6968 var el = Roo.get("my-div");
6973 // default animation
6974 el.setWidth(100, true);
6976 // animation with some options set
6983 // using the "anim" property to get the Anim object
6989 el.setWidth(100, opt);
6991 if(opt.anim.isAnimated()){
6995 * <b> Composite (Collections of) Elements</b><br />
6996 * For working with collections of Elements, see <a href="Roo.CompositeElement.html">Roo.CompositeElement</a>
6997 * @constructor Create a new Element directly.
6998 * @param {String/HTMLElement} element
6999 * @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).
7001 Roo.Element = function(element, forceNew){
7002 var dom = typeof element == "string" ?
7003 document.getElementById(element) : element;
7004 if(!dom){ // invalid id/element
7008 if(forceNew !== true && id && Roo.Element.cache[id]){ // element object already exists
7009 return Roo.Element.cache[id];
7019 * The DOM element ID
7022 this.id = id || Roo.id(dom);
7025 var El = Roo.Element;
7029 * The element's default display mode (defaults to "")
7032 originalDisplay : "",
7036 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
7041 * Sets the element's visibility mode. When setVisible() is called it
7042 * will use this to determine whether to set the visibility or the display property.
7043 * @param visMode Element.VISIBILITY or Element.DISPLAY
7044 * @return {Roo.Element} this
7046 setVisibilityMode : function(visMode){
7047 this.visibilityMode = visMode;
7051 * Convenience method for setVisibilityMode(Element.DISPLAY)
7052 * @param {String} display (optional) What to set display to when visible
7053 * @return {Roo.Element} this
7055 enableDisplayMode : function(display){
7056 this.setVisibilityMode(El.DISPLAY);
7057 if(typeof display != "undefined") this.originalDisplay = display;
7062 * 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)
7063 * @param {String} selector The simple selector to test
7064 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7065 search as a number or element (defaults to 10 || document.body)
7066 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
7067 * @return {HTMLElement} The matching DOM node (or null if no match was found)
7069 findParent : function(simpleSelector, maxDepth, returnEl){
7070 var p = this.dom, b = document.body, depth = 0, dq = Roo.DomQuery, stopEl;
7071 maxDepth = maxDepth || 50;
7072 if(typeof maxDepth != "number"){
7073 stopEl = Roo.getDom(maxDepth);
7076 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
7077 if(dq.is(p, simpleSelector)){
7078 return returnEl ? Roo.get(p) : p;
7088 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
7089 * @param {String} selector The simple selector to test
7090 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7091 search as a number or element (defaults to 10 || document.body)
7092 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
7093 * @return {HTMLElement} The matching DOM node (or null if no match was found)
7095 findParentNode : function(simpleSelector, maxDepth, returnEl){
7096 var p = Roo.fly(this.dom.parentNode, '_internal');
7097 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
7101 * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
7102 * This is a shortcut for findParentNode() that always returns an Roo.Element.
7103 * @param {String} selector The simple selector to test
7104 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7105 search as a number or element (defaults to 10 || document.body)
7106 * @return {Roo.Element} The matching DOM node (or null if no match was found)
7108 up : function(simpleSelector, maxDepth){
7109 return this.findParentNode(simpleSelector, maxDepth, true);
7115 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
7116 * @param {String} selector The simple selector to test
7117 * @return {Boolean} True if this element matches the selector, else false
7119 is : function(simpleSelector){
7120 return Roo.DomQuery.is(this.dom, simpleSelector);
7124 * Perform animation on this element.
7125 * @param {Object} args The YUI animation control args
7126 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to .35)
7127 * @param {Function} onComplete (optional) Function to call when animation completes
7128 * @param {String} easing (optional) Easing method to use (defaults to 'easeOut')
7129 * @param {String} animType (optional) 'run' is the default. Can also be 'color', 'motion', or 'scroll'
7130 * @return {Roo.Element} this
7132 animate : function(args, duration, onComplete, easing, animType){
7133 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
7138 * @private Internal animation call
7140 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
7141 animType = animType || 'run';
7143 var anim = Roo.lib.Anim[animType](
7145 (opt.duration || defaultDur) || .35,
7146 (opt.easing || defaultEase) || 'easeOut',
7148 Roo.callback(cb, this);
7149 Roo.callback(opt.callback, opt.scope || this, [this, opt]);
7157 // private legacy anim prep
7158 preanim : function(a, i){
7159 return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
7163 * Removes worthless text nodes
7164 * @param {Boolean} forceReclean (optional) By default the element
7165 * keeps track if it has been cleaned already so
7166 * you can call this over and over. However, if you update the element and
7167 * need to force a reclean, you can pass true.
7169 clean : function(forceReclean){
7170 if(this.isCleaned && forceReclean !== true){
7174 var d = this.dom, n = d.firstChild, ni = -1;
7176 var nx = n.nextSibling;
7177 if(n.nodeType == 3 && !ns.test(n.nodeValue)){
7184 this.isCleaned = true;
7189 calcOffsetsTo : function(el){
7192 var restorePos = false;
7193 if(el.getStyle('position') == 'static'){
7194 el.position('relative');
7199 while(op && op != d && op.tagName != 'HTML'){
7202 op = op.offsetParent;
7205 el.position('static');
7211 * Scrolls this element into view within the passed container.
7212 * @param {String/HTMLElement/Element} container (optional) The container element to scroll (defaults to document.body)
7213 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
7214 * @return {Roo.Element} this
7216 scrollIntoView : function(container, hscroll){
7217 var c = Roo.getDom(container) || document.body;
7220 var o = this.calcOffsetsTo(c),
7223 b = t+el.offsetHeight,
7224 r = l+el.offsetWidth;
7226 var ch = c.clientHeight;
7227 var ct = parseInt(c.scrollTop, 10);
7228 var cl = parseInt(c.scrollLeft, 10);
7230 var cr = cl + c.clientWidth;
7238 if(hscroll !== false){
7242 c.scrollLeft = r-c.clientWidth;
7249 scrollChildIntoView : function(child, hscroll){
7250 Roo.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
7254 * Measures the element's content height and updates height to match. Note: this function uses setTimeout so
7255 * the new height may not be available immediately.
7256 * @param {Boolean} animate (optional) Animate the transition (defaults to false)
7257 * @param {Float} duration (optional) Length of the animation in seconds (defaults to .35)
7258 * @param {Function} onComplete (optional) Function to call when animation completes
7259 * @param {String} easing (optional) Easing method to use (defaults to easeOut)
7260 * @return {Roo.Element} this
7262 autoHeight : function(animate, duration, onComplete, easing){
7263 var oldHeight = this.getHeight();
7265 this.setHeight(1); // force clipping
7266 setTimeout(function(){
7267 var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari
7269 this.setHeight(height);
7271 if(typeof onComplete == "function"){
7275 this.setHeight(oldHeight); // restore original height
7276 this.setHeight(height, animate, duration, function(){
7278 if(typeof onComplete == "function") onComplete();
7279 }.createDelegate(this), easing);
7281 }.createDelegate(this), 0);
7286 * Returns true if this element is an ancestor of the passed element
7287 * @param {HTMLElement/String} el The element to check
7288 * @return {Boolean} True if this element is an ancestor of el, else false
7290 contains : function(el){
7291 if(!el){return false;}
7292 return D.isAncestor(this.dom, el.dom ? el.dom : el);
7296 * Checks whether the element is currently visible using both visibility and display properties.
7297 * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
7298 * @return {Boolean} True if the element is currently visible, else false
7300 isVisible : function(deep) {
7301 var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
7302 if(deep !== true || !vis){
7305 var p = this.dom.parentNode;
7306 while(p && p.tagName.toLowerCase() != "body"){
7307 if(!Roo.fly(p, '_isVisible').isVisible()){
7316 * Creates a {@link Roo.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
7317 * @param {String} selector The CSS selector
7318 * @param {Boolean} unique (optional) True to create a unique Roo.Element for each child (defaults to false, which creates a single shared flyweight object)
7319 * @return {CompositeElement/CompositeElementLite} The composite element
7321 select : function(selector, unique){
7322 return El.select(selector, unique, this.dom);
7326 * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
7327 * @param {String} selector The CSS selector
7328 * @return {Array} An array of the matched nodes
7330 query : function(selector, unique){
7331 return Roo.DomQuery.select(selector, this.dom);
7335 * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
7336 * @param {String} selector The CSS selector
7337 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7338 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7340 child : function(selector, returnDom){
7341 var n = Roo.DomQuery.selectNode(selector, this.dom);
7342 return returnDom ? n : Roo.get(n);
7346 * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
7347 * @param {String} selector The CSS selector
7348 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7349 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7351 down : function(selector, returnDom){
7352 var n = Roo.DomQuery.selectNode(" > " + selector, this.dom);
7353 return returnDom ? n : Roo.get(n);
7357 * Initializes a {@link Roo.dd.DD} drag drop object for this element.
7358 * @param {String} group The group the DD object is member of
7359 * @param {Object} config The DD config object
7360 * @param {Object} overrides An object containing methods to override/implement on the DD object
7361 * @return {Roo.dd.DD} The DD object
7363 initDD : function(group, config, overrides){
7364 var dd = new Roo.dd.DD(Roo.id(this.dom), group, config);
7365 return Roo.apply(dd, overrides);
7369 * Initializes a {@link Roo.dd.DDProxy} object for this element.
7370 * @param {String} group The group the DDProxy object is member of
7371 * @param {Object} config The DDProxy config object
7372 * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
7373 * @return {Roo.dd.DDProxy} The DDProxy object
7375 initDDProxy : function(group, config, overrides){
7376 var dd = new Roo.dd.DDProxy(Roo.id(this.dom), group, config);
7377 return Roo.apply(dd, overrides);
7381 * Initializes a {@link Roo.dd.DDTarget} object for this element.
7382 * @param {String} group The group the DDTarget object is member of
7383 * @param {Object} config The DDTarget config object
7384 * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
7385 * @return {Roo.dd.DDTarget} The DDTarget object
7387 initDDTarget : function(group, config, overrides){
7388 var dd = new Roo.dd.DDTarget(Roo.id(this.dom), group, config);
7389 return Roo.apply(dd, overrides);
7393 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
7394 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
7395 * @param {Boolean} visible Whether the element is visible
7396 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7397 * @return {Roo.Element} this
7399 setVisible : function(visible, animate){
7401 if(this.visibilityMode == El.DISPLAY){
7402 this.setDisplayed(visible);
7405 this.dom.style.visibility = visible ? "visible" : "hidden";
7408 // closure for composites
7410 var visMode = this.visibilityMode;
7412 this.setOpacity(.01);
7413 this.setVisible(true);
7415 this.anim({opacity: { to: (visible?1:0) }},
7416 this.preanim(arguments, 1),
7417 null, .35, 'easeIn', function(){
7419 if(visMode == El.DISPLAY){
7420 dom.style.display = "none";
7422 dom.style.visibility = "hidden";
7424 Roo.get(dom).setOpacity(1);
7432 * Returns true if display is not "none"
7435 isDisplayed : function() {
7436 return this.getStyle("display") != "none";
7440 * Toggles the element's visibility or display, depending on visibility mode.
7441 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7442 * @return {Roo.Element} this
7444 toggle : function(animate){
7445 this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
7450 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
7451 * @param {Boolean} value Boolean value to display the element using its default display, or a string to set the display directly
7452 * @return {Roo.Element} this
7454 setDisplayed : function(value) {
7455 if(typeof value == "boolean"){
7456 value = value ? this.originalDisplay : "none";
7458 this.setStyle("display", value);
7463 * Tries to focus the element. Any exceptions are caught and ignored.
7464 * @return {Roo.Element} this
7466 focus : function() {
7474 * Tries to blur the element. Any exceptions are caught and ignored.
7475 * @return {Roo.Element} this
7485 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
7486 * @param {String/Array} className The CSS class to add, or an array of classes
7487 * @return {Roo.Element} this
7489 addClass : function(className){
7490 if(className instanceof Array){
7491 for(var i = 0, len = className.length; i < len; i++) {
7492 this.addClass(className[i]);
7495 if(className && !this.hasClass(className)){
7496 this.dom.className = this.dom.className + " " + className;
7503 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
7504 * @param {String/Array} className The CSS class to add, or an array of classes
7505 * @return {Roo.Element} this
7507 radioClass : function(className){
7508 var siblings = this.dom.parentNode.childNodes;
7509 for(var i = 0; i < siblings.length; i++) {
7510 var s = siblings[i];
7511 if(s.nodeType == 1){
7512 Roo.get(s).removeClass(className);
7515 this.addClass(className);
7520 * Removes one or more CSS classes from the element.
7521 * @param {String/Array} className The CSS class to remove, or an array of classes
7522 * @return {Roo.Element} this
7524 removeClass : function(className){
7525 if(!className || !this.dom.className){
7528 if(className instanceof Array){
7529 for(var i = 0, len = className.length; i < len; i++) {
7530 this.removeClass(className[i]);
7533 if(this.hasClass(className)){
7534 var re = this.classReCache[className];
7536 re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
7537 this.classReCache[className] = re;
7539 this.dom.className =
7540 this.dom.className.replace(re, " ");
7550 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
7551 * @param {String} className The CSS class to toggle
7552 * @return {Roo.Element} this
7554 toggleClass : function(className){
7555 if(this.hasClass(className)){
7556 this.removeClass(className);
7558 this.addClass(className);
7564 * Checks if the specified CSS class exists on this element's DOM node.
7565 * @param {String} className The CSS class to check for
7566 * @return {Boolean} True if the class exists, else false
7568 hasClass : function(className){
7569 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
7573 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
7574 * @param {String} oldClassName The CSS class to replace
7575 * @param {String} newClassName The replacement CSS class
7576 * @return {Roo.Element} this
7578 replaceClass : function(oldClassName, newClassName){
7579 this.removeClass(oldClassName);
7580 this.addClass(newClassName);
7585 * Returns an object with properties matching the styles requested.
7586 * For example, el.getStyles('color', 'font-size', 'width') might return
7587 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
7588 * @param {String} style1 A style name
7589 * @param {String} style2 A style name
7590 * @param {String} etc.
7591 * @return {Object} The style object
7593 getStyles : function(){
7594 var a = arguments, len = a.length, r = {};
7595 for(var i = 0; i < len; i++){
7596 r[a[i]] = this.getStyle(a[i]);
7602 * Normalizes currentStyle and computedStyle. This is not YUI getStyle, it is an optimised version.
7603 * @param {String} property The style property whose value is returned.
7604 * @return {String} The current value of the style property for this element.
7606 getStyle : function(){
7607 return view && view.getComputedStyle ?
7609 var el = this.dom, v, cs, camel;
7610 if(prop == 'float'){
7613 if(el.style && (v = el.style[prop])){
7616 if(cs = view.getComputedStyle(el, "")){
7617 if(!(camel = propCache[prop])){
7618 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7625 var el = this.dom, v, cs, camel;
7626 if(prop == 'opacity'){
7627 if(typeof el.style.filter == 'string'){
7628 var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i);
7630 var fv = parseFloat(m[1]);
7632 return fv ? fv / 100 : 0;
7637 }else if(prop == 'float'){
7638 prop = "styleFloat";
7640 if(!(camel = propCache[prop])){
7641 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7643 if(v = el.style[camel]){
7646 if(cs = el.currentStyle){
7654 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
7655 * @param {String/Object} property The style property to be set, or an object of multiple styles.
7656 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
7657 * @return {Roo.Element} this
7659 setStyle : function(prop, value){
7660 if(typeof prop == "string"){
7662 if (prop == 'float') {
7663 this.setStyle(Roo.isIE ? 'styleFloat' : 'cssFloat', value);
7668 if(!(camel = propCache[prop])){
7669 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7672 if(camel == 'opacity') {
7673 this.setOpacity(value);
7675 this.dom.style[camel] = value;
7678 for(var style in prop){
7679 if(typeof prop[style] != "function"){
7680 this.setStyle(style, prop[style]);
7688 * More flexible version of {@link #setStyle} for setting style properties.
7689 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
7690 * a function which returns such a specification.
7691 * @return {Roo.Element} this
7693 applyStyles : function(style){
7694 Roo.DomHelper.applyStyles(this.dom, style);
7699 * 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).
7700 * @return {Number} The X position of the element
7703 return D.getX(this.dom);
7707 * 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).
7708 * @return {Number} The Y position of the element
7711 return D.getY(this.dom);
7715 * 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).
7716 * @return {Array} The XY position of the element
7719 return D.getXY(this.dom);
7723 * 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).
7724 * @param {Number} The X position of the element
7725 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7726 * @return {Roo.Element} this
7728 setX : function(x, animate){
7730 D.setX(this.dom, x);
7732 this.setXY([x, this.getY()], this.preanim(arguments, 1));
7738 * 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).
7739 * @param {Number} The Y position of the element
7740 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7741 * @return {Roo.Element} this
7743 setY : function(y, animate){
7745 D.setY(this.dom, y);
7747 this.setXY([this.getX(), y], this.preanim(arguments, 1));
7753 * Sets the element's left position directly using CSS style (instead of {@link #setX}).
7754 * @param {String} left The left CSS property value
7755 * @return {Roo.Element} this
7757 setLeft : function(left){
7758 this.setStyle("left", this.addUnits(left));
7763 * Sets the element's top position directly using CSS style (instead of {@link #setY}).
7764 * @param {String} top The top CSS property value
7765 * @return {Roo.Element} this
7767 setTop : function(top){
7768 this.setStyle("top", this.addUnits(top));
7773 * Sets the element's CSS right style.
7774 * @param {String} right The right CSS property value
7775 * @return {Roo.Element} this
7777 setRight : function(right){
7778 this.setStyle("right", this.addUnits(right));
7783 * Sets the element's CSS bottom style.
7784 * @param {String} bottom The bottom CSS property value
7785 * @return {Roo.Element} this
7787 setBottom : function(bottom){
7788 this.setStyle("bottom", this.addUnits(bottom));
7793 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7794 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7795 * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
7796 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7797 * @return {Roo.Element} this
7799 setXY : function(pos, animate){
7801 D.setXY(this.dom, pos);
7803 this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion');
7809 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7810 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7811 * @param {Number} x X value for new position (coordinates are page-based)
7812 * @param {Number} y Y value for new position (coordinates are page-based)
7813 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7814 * @return {Roo.Element} this
7816 setLocation : function(x, y, animate){
7817 this.setXY([x, y], this.preanim(arguments, 2));
7822 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7823 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7824 * @param {Number} x X value for new position (coordinates are page-based)
7825 * @param {Number} y Y value for new position (coordinates are page-based)
7826 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7827 * @return {Roo.Element} this
7829 moveTo : function(x, y, animate){
7830 this.setXY([x, y], this.preanim(arguments, 2));
7835 * Returns the region of the given element.
7836 * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
7837 * @return {Region} A Roo.lib.Region containing "top, left, bottom, right" member data.
7839 getRegion : function(){
7840 return D.getRegion(this.dom);
7844 * Returns the offset height of the element
7845 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
7846 * @return {Number} The element's height
7848 getHeight : function(contentHeight){
7849 var h = this.dom.offsetHeight || 0;
7850 return contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
7854 * Returns the offset width of the element
7855 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
7856 * @return {Number} The element's width
7858 getWidth : function(contentWidth){
7859 var w = this.dom.offsetWidth || 0;
7860 return contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
7864 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
7865 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
7866 * if a height has not been set using CSS.
7869 getComputedHeight : function(){
7870 var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight);
7872 h = parseInt(this.getStyle('height'), 10) || 0;
7873 if(!this.isBorderBox()){
7874 h += this.getFrameWidth('tb');
7881 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
7882 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
7883 * if a width has not been set using CSS.
7886 getComputedWidth : function(){
7887 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
7889 w = parseInt(this.getStyle('width'), 10) || 0;
7890 if(!this.isBorderBox()){
7891 w += this.getFrameWidth('lr');
7898 * Returns the size of the element.
7899 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
7900 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
7902 getSize : function(contentSize){
7903 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
7907 * Returns the width and height of the viewport.
7908 * @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)}
7910 getViewSize : function(){
7911 var d = this.dom, doc = document, aw = 0, ah = 0;
7912 if(d == doc || d == doc.body){
7913 return {width : D.getViewWidth(), height: D.getViewHeight()};
7916 width : d.clientWidth,
7917 height: d.clientHeight
7923 * Returns the value of the "value" attribute
7924 * @param {Boolean} asNumber true to parse the value as a number
7925 * @return {String/Number}
7927 getValue : function(asNumber){
7928 return asNumber ? parseInt(this.dom.value, 10) : this.dom.value;
7932 adjustWidth : function(width){
7933 if(typeof width == "number"){
7934 if(this.autoBoxAdjust && !this.isBorderBox()){
7935 width -= (this.getBorderWidth("lr") + this.getPadding("lr"));
7945 adjustHeight : function(height){
7946 if(typeof height == "number"){
7947 if(this.autoBoxAdjust && !this.isBorderBox()){
7948 height -= (this.getBorderWidth("tb") + this.getPadding("tb"));
7958 * Set the width of the element
7959 * @param {Number} width The new width
7960 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7961 * @return {Roo.Element} this
7963 setWidth : function(width, animate){
7964 width = this.adjustWidth(width);
7966 this.dom.style.width = this.addUnits(width);
7968 this.anim({width: {to: width}}, this.preanim(arguments, 1));
7974 * Set the height of the element
7975 * @param {Number} height The new height
7976 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7977 * @return {Roo.Element} this
7979 setHeight : function(height, animate){
7980 height = this.adjustHeight(height);
7982 this.dom.style.height = this.addUnits(height);
7984 this.anim({height: {to: height}}, this.preanim(arguments, 1));
7990 * Set the size of the element. If animation is true, both width an height will be animated concurrently.
7991 * @param {Number} width The new width
7992 * @param {Number} height The new height
7993 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7994 * @return {Roo.Element} this
7996 setSize : function(width, height, animate){
7997 if(typeof width == "object"){ // in case of object from getSize()
7998 height = width.height; width = width.width;
8000 width = this.adjustWidth(width); height = this.adjustHeight(height);
8002 this.dom.style.width = this.addUnits(width);
8003 this.dom.style.height = this.addUnits(height);
8005 this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2));
8011 * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
8012 * @param {Number} x X value for new position (coordinates are page-based)
8013 * @param {Number} y Y value for new position (coordinates are page-based)
8014 * @param {Number} width The new width
8015 * @param {Number} height The new height
8016 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8017 * @return {Roo.Element} this
8019 setBounds : function(x, y, width, height, animate){
8021 this.setSize(width, height);
8022 this.setLocation(x, y);
8024 width = this.adjustWidth(width); height = this.adjustHeight(height);
8025 this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}},
8026 this.preanim(arguments, 4), 'motion');
8032 * 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.
8033 * @param {Roo.lib.Region} region The region to fill
8034 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8035 * @return {Roo.Element} this
8037 setRegion : function(region, animate){
8038 this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1));
8043 * Appends an event handler
8045 * @param {String} eventName The type of event to append
8046 * @param {Function} fn The method the event invokes
8047 * @param {Object} scope (optional) The scope (this object) of the fn
8048 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
8050 addListener : function(eventName, fn, scope, options){
8052 Roo.EventManager.on(this.dom, eventName, fn, scope || this, options);
8057 * Removes an event handler from this element
8058 * @param {String} eventName the type of event to remove
8059 * @param {Function} fn the method the event invokes
8060 * @return {Roo.Element} this
8062 removeListener : function(eventName, fn){
8063 Roo.EventManager.removeListener(this.dom, eventName, fn);
8068 * Removes all previous added listeners from this element
8069 * @return {Roo.Element} this
8071 removeAllListeners : function(){
8072 E.purgeElement(this.dom);
8076 relayEvent : function(eventName, observable){
8077 this.on(eventName, function(e){
8078 observable.fireEvent(eventName, e);
8083 * Set the opacity of the element
8084 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
8085 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8086 * @return {Roo.Element} this
8088 setOpacity : function(opacity, animate){
8090 var s = this.dom.style;
8093 s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
8094 (opacity == 1 ? "" : "alpha(opacity=" + opacity * 100 + ")");
8096 s.opacity = opacity;
8099 this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn');
8105 * Gets the left X coordinate
8106 * @param {Boolean} local True to get the local css position instead of page coordinate
8109 getLeft : function(local){
8113 return parseInt(this.getStyle("left"), 10) || 0;
8118 * Gets the right X coordinate of the element (element X position + element width)
8119 * @param {Boolean} local True to get the local css position instead of page coordinate
8122 getRight : function(local){
8124 return this.getX() + this.getWidth();
8126 return (this.getLeft(true) + this.getWidth()) || 0;
8131 * Gets the top Y coordinate
8132 * @param {Boolean} local True to get the local css position instead of page coordinate
8135 getTop : function(local) {
8139 return parseInt(this.getStyle("top"), 10) || 0;
8144 * Gets the bottom Y coordinate of the element (element Y position + element height)
8145 * @param {Boolean} local True to get the local css position instead of page coordinate
8148 getBottom : function(local){
8150 return this.getY() + this.getHeight();
8152 return (this.getTop(true) + this.getHeight()) || 0;
8157 * Initializes positioning on this element. If a desired position is not passed, it will make the
8158 * the element positioned relative IF it is not already positioned.
8159 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
8160 * @param {Number} zIndex (optional) The zIndex to apply
8161 * @param {Number} x (optional) Set the page X position
8162 * @param {Number} y (optional) Set the page Y position
8164 position : function(pos, zIndex, x, y){
8166 if(this.getStyle('position') == 'static'){
8167 this.setStyle('position', 'relative');
8170 this.setStyle("position", pos);
8173 this.setStyle("z-index", zIndex);
8175 if(x !== undefined && y !== undefined){
8177 }else if(x !== undefined){
8179 }else if(y !== undefined){
8185 * Clear positioning back to the default when the document was loaded
8186 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
8187 * @return {Roo.Element} this
8189 clearPositioning : function(value){
8197 "position" : "static"
8203 * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
8204 * snapshot before performing an update and then restoring the element.
8207 getPositioning : function(){
8208 var l = this.getStyle("left");
8209 var t = this.getStyle("top");
8211 "position" : this.getStyle("position"),
8213 "right" : l ? "" : this.getStyle("right"),
8215 "bottom" : t ? "" : this.getStyle("bottom"),
8216 "z-index" : this.getStyle("z-index")
8221 * Gets the width of the border(s) for the specified side(s)
8222 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8223 * passing lr would get the border (l)eft width + the border (r)ight width.
8224 * @return {Number} The width of the sides passed added together
8226 getBorderWidth : function(side){
8227 return this.addStyles(side, El.borders);
8231 * Gets the width of the padding(s) for the specified side(s)
8232 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8233 * passing lr would get the padding (l)eft + the padding (r)ight.
8234 * @return {Number} The padding of the sides passed added together
8236 getPadding : function(side){
8237 return this.addStyles(side, El.paddings);
8241 * Set positioning with an object returned by getPositioning().
8242 * @param {Object} posCfg
8243 * @return {Roo.Element} this
8245 setPositioning : function(pc){
8246 this.applyStyles(pc);
8247 if(pc.right == "auto"){
8248 this.dom.style.right = "";
8250 if(pc.bottom == "auto"){
8251 this.dom.style.bottom = "";
8257 fixDisplay : function(){
8258 if(this.getStyle("display") == "none"){
8259 this.setStyle("visibility", "hidden");
8260 this.setStyle("display", this.originalDisplay); // first try reverting to default
8261 if(this.getStyle("display") == "none"){ // if that fails, default to block
8262 this.setStyle("display", "block");
8268 * Quick set left and top adding default units
8269 * @param {String} left The left CSS property value
8270 * @param {String} top The top CSS property value
8271 * @return {Roo.Element} this
8273 setLeftTop : function(left, top){
8274 this.dom.style.left = this.addUnits(left);
8275 this.dom.style.top = this.addUnits(top);
8280 * Move this element relative to its current position.
8281 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
8282 * @param {Number} distance How far to move the element in pixels
8283 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8284 * @return {Roo.Element} this
8286 move : function(direction, distance, animate){
8287 var xy = this.getXY();
8288 direction = direction.toLowerCase();
8292 this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2));
8296 this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2));
8301 this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2));
8306 this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2));
8313 * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
8314 * @return {Roo.Element} this
8317 if(!this.isClipped){
8318 this.isClipped = true;
8319 this.originalClip = {
8320 "o": this.getStyle("overflow"),
8321 "x": this.getStyle("overflow-x"),
8322 "y": this.getStyle("overflow-y")
8324 this.setStyle("overflow", "hidden");
8325 this.setStyle("overflow-x", "hidden");
8326 this.setStyle("overflow-y", "hidden");
8332 * Return clipping (overflow) to original clipping before clip() was called
8333 * @return {Roo.Element} this
8335 unclip : function(){
8337 this.isClipped = false;
8338 var o = this.originalClip;
8339 if(o.o){this.setStyle("overflow", o.o);}
8340 if(o.x){this.setStyle("overflow-x", o.x);}
8341 if(o.y){this.setStyle("overflow-y", o.y);}
8348 * Gets the x,y coordinates specified by the anchor position on the element.
8349 * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo} for details on supported anchor positions.
8350 * @param {Object} size (optional) An object containing the size to use for calculating anchor position
8351 * {width: (target width), height: (target height)} (defaults to the element's current size)
8352 * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead of page coordinates
8353 * @return {Array} [x, y] An array containing the element's x and y coordinates
8355 getAnchorXY : function(anchor, local, s){
8356 //Passing a different size is useful for pre-calculating anchors,
8357 //especially for anchored animations that change the el size.
8359 var w, h, vp = false;
8362 if(d == document.body || d == document){
8364 w = D.getViewWidth(); h = D.getViewHeight();
8366 w = this.getWidth(); h = this.getHeight();
8369 w = s.width; h = s.height;
8371 var x = 0, y = 0, r = Math.round;
8372 switch((anchor || "tl").toLowerCase()){
8414 var sc = this.getScroll();
8415 return [x + sc.left, y + sc.top];
8417 //Add the element's offset xy
8418 var o = this.getXY();
8419 return [x+o[0], y+o[1]];
8423 * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
8424 * supported position values.
8425 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8426 * @param {String} position The position to align to.
8427 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8428 * @return {Array} [x, y]
8430 getAlignToXY : function(el, p, o){
8434 throw "Element.alignTo with an element that doesn't exist";
8436 var c = false; //constrain to viewport
8437 var p1 = "", p2 = "";
8444 }else if(p.indexOf("-") == -1){
8447 p = p.toLowerCase();
8448 var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
8450 throw "Element.alignTo with an invalid alignment " + p;
8452 p1 = m[1]; p2 = m[2]; c = !!m[3];
8454 //Subtract the aligned el's internal xy from the target's offset xy
8455 //plus custom offset to get the aligned el's new offset xy
8456 var a1 = this.getAnchorXY(p1, true);
8457 var a2 = el.getAnchorXY(p2, false);
8458 var x = a2[0] - a1[0] + o[0];
8459 var y = a2[1] - a1[1] + o[1];
8461 //constrain the aligned el to viewport if necessary
8462 var w = this.getWidth(), h = this.getHeight(), r = el.getRegion();
8463 // 5px of margin for ie
8464 var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;
8466 //If we are at a viewport boundary and the aligned el is anchored on a target border that is
8467 //perpendicular to the vp border, allow the aligned el to slide on that border,
8468 //otherwise swap the aligned el to the opposite border of the target.
8469 var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);
8470 var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);
8471 var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
8472 var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
8475 var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5;
8476 var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5;
8478 if((x+w) > dw + scrollX){
8479 x = swapX ? r.left-w : dw+scrollX-w;
8482 x = swapX ? r.right : scrollX;
8484 if((y+h) > dh + scrollY){
8485 y = swapY ? r.top-h : dh+scrollY-h;
8488 y = swapY ? r.bottom : scrollY;
8495 getConstrainToXY : function(){
8496 var os = {top:0, left:0, bottom:0, right: 0};
8498 return function(el, local, offsets, proposedXY){
8500 offsets = offsets ? Roo.applyIf(offsets, os) : os;
8502 var vw, vh, vx = 0, vy = 0;
8503 if(el.dom == document.body || el.dom == document){
8504 vw = Roo.lib.Dom.getViewWidth();
8505 vh = Roo.lib.Dom.getViewHeight();
8507 vw = el.dom.clientWidth;
8508 vh = el.dom.clientHeight;
8510 var vxy = el.getXY();
8516 var s = el.getScroll();
8518 vx += offsets.left + s.left;
8519 vy += offsets.top + s.top;
8521 vw -= offsets.right;
8522 vh -= offsets.bottom;
8527 var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
8528 var x = xy[0], y = xy[1];
8529 var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
8531 // only move it if it needs it
8534 // first validate right/bottom
8543 // then make sure top/left isn't negative
8552 return moved ? [x, y] : false;
8557 adjustForConstraints : function(xy, parent, offsets){
8558 return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
8562 * Aligns this element with another element relative to the specified anchor points. If the other element is the
8563 * document it aligns it to the viewport.
8564 * The position parameter is optional, and can be specified in any one of the following formats:
8566 * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
8567 * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
8568 * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
8569 * deprecated in favor of the newer two anchor syntax below</i>.</li>
8570 * <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
8571 * element's anchor point, and the second value is used as the target's anchor point.</li>
8573 * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
8574 * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
8575 * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
8576 * that specified in order to enforce the viewport constraints.
8577 * Following are all of the supported anchor positions:
8580 ----- -----------------------------
8581 tl The top left corner (default)
8582 t The center of the top edge
8583 tr The top right corner
8584 l The center of the left edge
8585 c In the center of the element
8586 r The center of the right edge
8587 bl The bottom left corner
8588 b The center of the bottom edge
8589 br The bottom right corner
8593 // align el to other-el using the default positioning ("tl-bl", non-constrained)
8594 el.alignTo("other-el");
8596 // align the top left corner of el with the top right corner of other-el (constrained to viewport)
8597 el.alignTo("other-el", "tr?");
8599 // align the bottom right corner of el with the center left edge of other-el
8600 el.alignTo("other-el", "br-l?");
8602 // align the center of el with the bottom left corner of other-el and
8603 // adjust the x position by -6 pixels (and the y position by 0)
8604 el.alignTo("other-el", "c-bl", [-6, 0]);
8606 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8607 * @param {String} position The position to align to.
8608 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8609 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8610 * @return {Roo.Element} this
8612 alignTo : function(element, position, offsets, animate){
8613 var xy = this.getAlignToXY(element, position, offsets);
8614 this.setXY(xy, this.preanim(arguments, 3));
8619 * Anchors an element to another element and realigns it when the window is resized.
8620 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8621 * @param {String} position The position to align to.
8622 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8623 * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
8624 * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
8625 * is a number, it is used as the buffer delay (defaults to 50ms).
8626 * @param {Function} callback The function to call after the animation finishes
8627 * @return {Roo.Element} this
8629 anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
8630 var action = function(){
8631 this.alignTo(el, alignment, offsets, animate);
8632 Roo.callback(callback, this);
8634 Roo.EventManager.onWindowResize(action, this);
8635 var tm = typeof monitorScroll;
8636 if(tm != 'undefined'){
8637 Roo.EventManager.on(window, 'scroll', action, this,
8638 {buffer: tm == 'number' ? monitorScroll : 50});
8640 action.call(this); // align immediately
8644 * Clears any opacity settings from this element. Required in some cases for IE.
8645 * @return {Roo.Element} this
8647 clearOpacity : function(){
8648 if (window.ActiveXObject) {
8649 if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){
8650 this.dom.style.filter = "";
8653 this.dom.style.opacity = "";
8654 this.dom.style["-moz-opacity"] = "";
8655 this.dom.style["-khtml-opacity"] = "";
8661 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8662 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8663 * @return {Roo.Element} this
8665 hide : function(animate){
8666 this.setVisible(false, this.preanim(arguments, 0));
8671 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8672 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8673 * @return {Roo.Element} this
8675 show : function(animate){
8676 this.setVisible(true, this.preanim(arguments, 0));
8681 * @private Test if size has a unit, otherwise appends the default
8683 addUnits : function(size){
8684 return Roo.Element.addUnits(size, this.defaultUnit);
8688 * Temporarily enables offsets (width,height,x,y) for an element with display:none, use endMeasure() when done.
8689 * @return {Roo.Element} this
8691 beginMeasure : function(){
8693 if(el.offsetWidth || el.offsetHeight){
8694 return this; // offsets work already
8697 var p = this.dom, b = document.body; // start with this element
8698 while((!el.offsetWidth && !el.offsetHeight) && p && p.tagName && p != b){
8699 var pe = Roo.get(p);
8700 if(pe.getStyle('display') == 'none'){
8701 changed.push({el: p, visibility: pe.getStyle("visibility")});
8702 p.style.visibility = "hidden";
8703 p.style.display = "block";
8707 this._measureChanged = changed;
8713 * Restores displays to before beginMeasure was called
8714 * @return {Roo.Element} this
8716 endMeasure : function(){
8717 var changed = this._measureChanged;
8719 for(var i = 0, len = changed.length; i < len; i++) {
8721 r.el.style.visibility = r.visibility;
8722 r.el.style.display = "none";
8724 this._measureChanged = null;
8730 * Update the innerHTML of this element, optionally searching for and processing scripts
8731 * @param {String} html The new HTML
8732 * @param {Boolean} loadScripts (optional) true to look for and process scripts
8733 * @param {Function} callback For async script loading you can be noticed when the update completes
8734 * @return {Roo.Element} this
8736 update : function(html, loadScripts, callback){
8737 if(typeof html == "undefined"){
8740 if(loadScripts !== true){
8741 this.dom.innerHTML = html;
8742 if(typeof callback == "function"){
8750 html += '<span id="' + id + '"></span>';
8752 E.onAvailable(id, function(){
8753 var hd = document.getElementsByTagName("head")[0];
8754 var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
8755 var srcRe = /\ssrc=([\'\"])(.*?)\1/i;
8756 var typeRe = /\stype=([\'\"])(.*?)\1/i;
8759 while(match = re.exec(html)){
8760 var attrs = match[1];
8761 var srcMatch = attrs ? attrs.match(srcRe) : false;
8762 if(srcMatch && srcMatch[2]){
8763 var s = document.createElement("script");
8764 s.src = srcMatch[2];
8765 var typeMatch = attrs.match(typeRe);
8766 if(typeMatch && typeMatch[2]){
8767 s.type = typeMatch[2];
8770 }else if(match[2] && match[2].length > 0){
8771 if(window.execScript) {
8772 window.execScript(match[2]);
8780 window.eval(match[2]);
8784 var el = document.getElementById(id);
8785 if(el){el.parentNode.removeChild(el);}
8786 if(typeof callback == "function"){
8790 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
8795 * Direct access to the UpdateManager update() method (takes the same parameters).
8796 * @param {String/Function} url The url for this request or a function to call to get the url
8797 * @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}
8798 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
8799 * @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.
8800 * @return {Roo.Element} this
8803 var um = this.getUpdateManager();
8804 um.update.apply(um, arguments);
8809 * Gets this element's UpdateManager
8810 * @return {Roo.UpdateManager} The UpdateManager
8812 getUpdateManager : function(){
8813 if(!this.updateManager){
8814 this.updateManager = new Roo.UpdateManager(this);
8816 return this.updateManager;
8820 * Disables text selection for this element (normalized across browsers)
8821 * @return {Roo.Element} this
8823 unselectable : function(){
8824 this.dom.unselectable = "on";
8825 this.swallowEvent("selectstart", true);
8826 this.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
8827 this.addClass("x-unselectable");
8832 * Calculates the x, y to center this element on the screen
8833 * @return {Array} The x, y values [x, y]
8835 getCenterXY : function(){
8836 return this.getAlignToXY(document, 'c-c');
8840 * Centers the Element in either the viewport, or another Element.
8841 * @param {String/HTMLElement/Roo.Element} centerIn (optional) The element in which to center the element.
8843 center : function(centerIn){
8844 this.alignTo(centerIn || document, 'c-c');
8849 * Tests various css rules/browsers to determine if this element uses a border box
8852 isBorderBox : function(){
8853 return noBoxAdjust[this.dom.tagName.toLowerCase()] || Roo.isBorderBox;
8857 * Return a box {x, y, width, height} that can be used to set another elements
8858 * size/location to match this element.
8859 * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
8860 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
8861 * @return {Object} box An object in the format {x, y, width, height}
8863 getBox : function(contentBox, local){
8868 var left = parseInt(this.getStyle("left"), 10) || 0;
8869 var top = parseInt(this.getStyle("top"), 10) || 0;
8872 var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
8874 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
8876 var l = this.getBorderWidth("l")+this.getPadding("l");
8877 var r = this.getBorderWidth("r")+this.getPadding("r");
8878 var t = this.getBorderWidth("t")+this.getPadding("t");
8879 var b = this.getBorderWidth("b")+this.getPadding("b");
8880 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)};
8882 bx.right = bx.x + bx.width;
8883 bx.bottom = bx.y + bx.height;
8888 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
8889 for more information about the sides.
8890 * @param {String} sides
8893 getFrameWidth : function(sides, onlyContentBox){
8894 return onlyContentBox && Roo.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
8898 * 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.
8899 * @param {Object} box The box to fill {x, y, width, height}
8900 * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
8901 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8902 * @return {Roo.Element} this
8904 setBox : function(box, adjust, animate){
8905 var w = box.width, h = box.height;
8906 if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){
8907 w -= (this.getBorderWidth("lr") + this.getPadding("lr"));
8908 h -= (this.getBorderWidth("tb") + this.getPadding("tb"));
8910 this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2));
8915 * Forces the browser to repaint this element
8916 * @return {Roo.Element} this
8918 repaint : function(){
8920 this.addClass("x-repaint");
8921 setTimeout(function(){
8922 Roo.get(dom).removeClass("x-repaint");
8928 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
8929 * then it returns the calculated width of the sides (see getPadding)
8930 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
8931 * @return {Object/Number}
8933 getMargins : function(side){
8936 top: parseInt(this.getStyle("margin-top"), 10) || 0,
8937 left: parseInt(this.getStyle("margin-left"), 10) || 0,
8938 bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0,
8939 right: parseInt(this.getStyle("margin-right"), 10) || 0
8942 return this.addStyles(side, El.margins);
8947 addStyles : function(sides, styles){
8949 for(var i = 0, len = sides.length; i < len; i++){
8950 v = this.getStyle(styles[sides.charAt(i)]);
8952 w = parseInt(v, 10);
8960 * Creates a proxy element of this element
8961 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
8962 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
8963 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
8964 * @return {Roo.Element} The new proxy element
8966 createProxy : function(config, renderTo, matchBox){
8968 renderTo = Roo.getDom(renderTo);
8970 renderTo = document.body;
8972 config = typeof config == "object" ?
8973 config : {tag : "div", cls: config};
8974 var proxy = Roo.DomHelper.append(renderTo, config, true);
8976 proxy.setBox(this.getBox());
8982 * Puts a mask over this element to disable user interaction. Requires core.css.
8983 * This method can only be applied to elements which accept child nodes.
8984 * @param {String} msg (optional) A message to display in the mask
8985 * @param {String} msgCls (optional) A css class to apply to the msg element
8986 * @return {Element} The mask element
8988 mask : function(msg, msgCls)
8990 if(this.getStyle("position") == "static" && this.dom.tagName !== 'BODY'){
8991 this.setStyle("position", "relative");
8994 this._mask = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask"}, true);
8996 this.addClass("x-masked");
8997 this._mask.setDisplayed(true);
9002 while (dom && dom.style) {
9003 if (!isNaN(parseInt(dom.style.zIndex))) {
9004 z = Math.max(z, parseInt(dom.style.zIndex));
9006 dom = dom.parentNode;
9008 // if we are masking the body - then it hides everything..
9009 if (this.dom == document.body) {
9011 this._mask.setWidth(Roo.lib.Dom.getDocumentWidth());
9012 this._mask.setHeight(Roo.lib.Dom.getDocumentHeight());
9015 if(typeof msg == 'string'){
9017 this._maskMsg = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask-msg", cn:{tag:'div'}}, true);
9019 var mm = this._maskMsg;
9020 mm.dom.className = msgCls ? "roo-el-mask-msg " + msgCls : "roo-el-mask-msg";
9021 if (mm.dom.firstChild) { // weird IE issue?
9022 mm.dom.firstChild.innerHTML = msg;
9024 mm.setDisplayed(true);
9026 mm.setStyle('z-index', z + 102);
9028 if(Roo.isIE && !(Roo.isIE7 && Roo.isStrict) && this.getStyle('height') == 'auto'){ // ie will not expand full height automatically
9029 this._mask.setHeight(this.getHeight());
9031 this._mask.setStyle('z-index', z + 100);
9037 * Removes a previously applied mask. If removeEl is true the mask overlay is destroyed, otherwise
9038 * it is cached for reuse.
9040 unmask : function(removeEl){
9042 if(removeEl === true){
9043 this._mask.remove();
9046 this._maskMsg.remove();
9047 delete this._maskMsg;
9050 this._mask.setDisplayed(false);
9052 this._maskMsg.setDisplayed(false);
9056 this.removeClass("x-masked");
9060 * Returns true if this element is masked
9063 isMasked : function(){
9064 return this._mask && this._mask.isVisible();
9068 * Creates an iframe shim for this element to keep selects and other windowed objects from
9070 * @return {Roo.Element} The new shim element
9072 createShim : function(){
9073 var el = document.createElement('iframe');
9074 el.frameBorder = 'no';
9075 el.className = 'roo-shim';
9076 if(Roo.isIE && Roo.isSecure){
9077 el.src = Roo.SSL_SECURE_URL;
9079 var shim = Roo.get(this.dom.parentNode.insertBefore(el, this.dom));
9080 shim.autoBoxAdjust = false;
9085 * Removes this element from the DOM and deletes it from the cache
9087 remove : function(){
9088 if(this.dom.parentNode){
9089 this.dom.parentNode.removeChild(this.dom);
9091 delete El.cache[this.dom.id];
9095 * Sets up event handlers to add and remove a css class when the mouse is over this element
9096 * @param {String} className
9097 * @param {Boolean} preventFlicker (optional) If set to true, it prevents flickering by filtering
9098 * mouseout events for children elements
9099 * @return {Roo.Element} this
9101 addClassOnOver : function(className, preventFlicker){
9102 this.on("mouseover", function(){
9103 Roo.fly(this, '_internal').addClass(className);
9105 var removeFn = function(e){
9106 if(preventFlicker !== true || !e.within(this, true)){
9107 Roo.fly(this, '_internal').removeClass(className);
9110 this.on("mouseout", removeFn, this.dom);
9115 * Sets up event handlers to add and remove a css class when this element has the focus
9116 * @param {String} className
9117 * @return {Roo.Element} this
9119 addClassOnFocus : function(className){
9120 this.on("focus", function(){
9121 Roo.fly(this, '_internal').addClass(className);
9123 this.on("blur", function(){
9124 Roo.fly(this, '_internal').removeClass(className);
9129 * 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)
9130 * @param {String} className
9131 * @return {Roo.Element} this
9133 addClassOnClick : function(className){
9135 this.on("mousedown", function(){
9136 Roo.fly(dom, '_internal').addClass(className);
9137 var d = Roo.get(document);
9138 var fn = function(){
9139 Roo.fly(dom, '_internal').removeClass(className);
9140 d.removeListener("mouseup", fn);
9142 d.on("mouseup", fn);
9148 * Stops the specified event from bubbling and optionally prevents the default action
9149 * @param {String} eventName
9150 * @param {Boolean} preventDefault (optional) true to prevent the default action too
9151 * @return {Roo.Element} this
9153 swallowEvent : function(eventName, preventDefault){
9154 var fn = function(e){
9155 e.stopPropagation();
9160 if(eventName instanceof Array){
9161 for(var i = 0, len = eventName.length; i < len; i++){
9162 this.on(eventName[i], fn);
9166 this.on(eventName, fn);
9173 fitToParentDelegate : Roo.emptyFn, // keep a reference to the fitToParent delegate
9176 * Sizes this element to its parent element's dimensions performing
9177 * neccessary box adjustments.
9178 * @param {Boolean} monitorResize (optional) If true maintains the fit when the browser window is resized.
9179 * @param {String/HTMLElment/Element} targetParent (optional) The target parent, default to the parentNode.
9180 * @return {Roo.Element} this
9182 fitToParent : function(monitorResize, targetParent) {
9183 Roo.EventManager.removeResizeListener(this.fitToParentDelegate); // always remove previous fitToParent delegate from onWindowResize
9184 this.fitToParentDelegate = Roo.emptyFn; // remove reference to previous delegate
9185 if (monitorResize === true && !this.dom.parentNode) { // check if this Element still exists
9188 var p = Roo.get(targetParent || this.dom.parentNode);
9189 this.setSize(p.getComputedWidth() - p.getFrameWidth('lr'), p.getComputedHeight() - p.getFrameWidth('tb'));
9190 if (monitorResize === true) {
9191 this.fitToParentDelegate = this.fitToParent.createDelegate(this, [true, targetParent]);
9192 Roo.EventManager.onWindowResize(this.fitToParentDelegate);
9198 * Gets the next sibling, skipping text nodes
9199 * @return {HTMLElement} The next sibling or null
9201 getNextSibling : function(){
9202 var n = this.dom.nextSibling;
9203 while(n && n.nodeType != 1){
9210 * Gets the previous sibling, skipping text nodes
9211 * @return {HTMLElement} The previous sibling or null
9213 getPrevSibling : function(){
9214 var n = this.dom.previousSibling;
9215 while(n && n.nodeType != 1){
9216 n = n.previousSibling;
9223 * Appends the passed element(s) to this element
9224 * @param {String/HTMLElement/Array/Element/CompositeElement} el
9225 * @return {Roo.Element} this
9227 appendChild: function(el){
9234 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
9235 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
9236 * automatically generated with the specified attributes.
9237 * @param {HTMLElement} insertBefore (optional) a child element of this element
9238 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
9239 * @return {Roo.Element} The new child element
9241 createChild: function(config, insertBefore, returnDom){
9242 config = config || {tag:'div'};
9244 return Roo.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
9246 return Roo.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
9250 * Appends this element to the passed element
9251 * @param {String/HTMLElement/Element} el The new parent element
9252 * @return {Roo.Element} this
9254 appendTo: function(el){
9255 el = Roo.getDom(el);
9256 el.appendChild(this.dom);
9261 * Inserts this element before the passed element in the DOM
9262 * @param {String/HTMLElement/Element} el The element to insert before
9263 * @return {Roo.Element} this
9265 insertBefore: function(el){
9266 el = Roo.getDom(el);
9267 el.parentNode.insertBefore(this.dom, el);
9272 * Inserts this element after the passed element in the DOM
9273 * @param {String/HTMLElement/Element} el The element to insert after
9274 * @return {Roo.Element} this
9276 insertAfter: function(el){
9277 el = Roo.getDom(el);
9278 el.parentNode.insertBefore(this.dom, el.nextSibling);
9283 * Inserts (or creates) an element (or DomHelper config) as the first child of the this element
9284 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9285 * @return {Roo.Element} The new child
9287 insertFirst: function(el, returnDom){
9289 if(typeof el == 'object' && !el.nodeType){ // dh config
9290 return this.createChild(el, this.dom.firstChild, returnDom);
9292 el = Roo.getDom(el);
9293 this.dom.insertBefore(el, this.dom.firstChild);
9294 return !returnDom ? Roo.get(el) : el;
9299 * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
9300 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9301 * @param {String} where (optional) 'before' or 'after' defaults to before
9302 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9303 * @return {Roo.Element} the inserted Element
9305 insertSibling: function(el, where, returnDom){
9306 where = where ? where.toLowerCase() : 'before';
9308 var rt, refNode = where == 'before' ? this.dom : this.dom.nextSibling;
9310 if(typeof el == 'object' && !el.nodeType){ // dh config
9311 if(where == 'after' && !this.dom.nextSibling){
9312 rt = Roo.DomHelper.append(this.dom.parentNode, el, !returnDom);
9314 rt = Roo.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom);
9318 rt = this.dom.parentNode.insertBefore(Roo.getDom(el),
9319 where == 'before' ? this.dom : this.dom.nextSibling);
9328 * Creates and wraps this element with another element
9329 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
9330 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9331 * @return {HTMLElement/Element} The newly created wrapper element
9333 wrap: function(config, returnDom){
9335 config = {tag: "div"};
9337 var newEl = Roo.DomHelper.insertBefore(this.dom, config, !returnDom);
9338 newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
9343 * Replaces the passed element with this element
9344 * @param {String/HTMLElement/Element} el The element to replace
9345 * @return {Roo.Element} this
9347 replace: function(el){
9349 this.insertBefore(el);
9355 * Inserts an html fragment into this element
9356 * @param {String} where Where to insert the html in relation to the this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
9357 * @param {String} html The HTML fragment
9358 * @param {Boolean} returnEl True to return an Roo.Element
9359 * @return {HTMLElement/Roo.Element} The inserted node (or nearest related if more than 1 inserted)
9361 insertHtml : function(where, html, returnEl){
9362 var el = Roo.DomHelper.insertHtml(where, this.dom, html);
9363 return returnEl ? Roo.get(el) : el;
9367 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
9368 * @param {Object} o The object with the attributes
9369 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
9370 * @return {Roo.Element} this
9372 set : function(o, useSet){
9374 useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet;
9376 if(attr == "style" || typeof o[attr] == "function") continue;
9378 el.className = o["cls"];
9380 if(useSet) el.setAttribute(attr, o[attr]);
9381 else el[attr] = o[attr];
9385 Roo.DomHelper.applyStyles(el, o.style);
9391 * Convenience method for constructing a KeyMap
9392 * @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:
9393 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9394 * @param {Function} fn The function to call
9395 * @param {Object} scope (optional) The scope of the function
9396 * @return {Roo.KeyMap} The KeyMap created
9398 addKeyListener : function(key, fn, scope){
9400 if(typeof key != "object" || key instanceof Array){
9416 return new Roo.KeyMap(this, config);
9420 * Creates a KeyMap for this element
9421 * @param {Object} config The KeyMap config. See {@link Roo.KeyMap} for more details
9422 * @return {Roo.KeyMap} The KeyMap created
9424 addKeyMap : function(config){
9425 return new Roo.KeyMap(this, config);
9429 * Returns true if this element is scrollable.
9432 isScrollable : function(){
9434 return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
9438 * 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().
9439 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
9440 * @param {Number} value The new scroll value
9441 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9442 * @return {Element} this
9445 scrollTo : function(side, value, animate){
9446 var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop";
9448 this.dom[prop] = value;
9450 var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value];
9451 this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
9457 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
9458 * within this element's scrollable range.
9459 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
9460 * @param {Number} distance How far to scroll the element in pixels
9461 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9462 * @return {Boolean} Returns true if a scroll was triggered or false if the element
9463 * was scrolled as far as it could go.
9465 scroll : function(direction, distance, animate){
9466 if(!this.isScrollable()){
9470 var l = el.scrollLeft, t = el.scrollTop;
9471 var w = el.scrollWidth, h = el.scrollHeight;
9472 var cw = el.clientWidth, ch = el.clientHeight;
9473 direction = direction.toLowerCase();
9474 var scrolled = false;
9475 var a = this.preanim(arguments, 2);
9480 var v = Math.min(l + distance, w-cw);
9481 this.scrollTo("left", v, a);
9488 var v = Math.max(l - distance, 0);
9489 this.scrollTo("left", v, a);
9497 var v = Math.max(t - distance, 0);
9498 this.scrollTo("top", v, a);
9506 var v = Math.min(t + distance, h-ch);
9507 this.scrollTo("top", v, a);
9516 * Translates the passed page coordinates into left/top css values for this element
9517 * @param {Number/Array} x The page x or an array containing [x, y]
9518 * @param {Number} y The page y
9519 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
9521 translatePoints : function(x, y){
9522 if(typeof x == 'object' || x instanceof Array){
9525 var p = this.getStyle('position');
9526 var o = this.getXY();
9528 var l = parseInt(this.getStyle('left'), 10);
9529 var t = parseInt(this.getStyle('top'), 10);
9532 l = (p == "relative") ? 0 : this.dom.offsetLeft;
9535 t = (p == "relative") ? 0 : this.dom.offsetTop;
9538 return {left: (x - o[0] + l), top: (y - o[1] + t)};
9542 * Returns the current scroll position of the element.
9543 * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
9545 getScroll : function(){
9546 var d = this.dom, doc = document;
9547 if(d == doc || d == doc.body){
9548 var l = window.pageXOffset || doc.documentElement.scrollLeft || doc.body.scrollLeft || 0;
9549 var t = window.pageYOffset || doc.documentElement.scrollTop || doc.body.scrollTop || 0;
9550 return {left: l, top: t};
9552 return {left: d.scrollLeft, top: d.scrollTop};
9557 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
9558 * are convert to standard 6 digit hex color.
9559 * @param {String} attr The css attribute
9560 * @param {String} defaultValue The default value to use when a valid color isn't found
9561 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
9564 getColor : function(attr, defaultValue, prefix){
9565 var v = this.getStyle(attr);
9566 if(!v || v == "transparent" || v == "inherit") {
9567 return defaultValue;
9569 var color = typeof prefix == "undefined" ? "#" : prefix;
9570 if(v.substr(0, 4) == "rgb("){
9571 var rvs = v.slice(4, v.length -1).split(",");
9572 for(var i = 0; i < 3; i++){
9573 var h = parseInt(rvs[i]).toString(16);
9580 if(v.substr(0, 1) == "#"){
9582 for(var i = 1; i < 4; i++){
9583 var c = v.charAt(i);
9586 }else if(v.length == 7){
9587 color += v.substr(1);
9591 return(color.length > 5 ? color.toLowerCase() : defaultValue);
9595 * Wraps the specified element with a special markup/CSS block that renders by default as a gray container with a
9596 * gradient background, rounded corners and a 4-way shadow.
9597 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element (defaults to 'x-box').
9598 * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
9599 * so if you supply an alternate base class, make sure you also supply all of the necessary rules.
9600 * @return {Roo.Element} this
9602 boxWrap : function(cls){
9603 cls = cls || 'x-box';
9604 var el = Roo.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', cls)));
9605 el.child('.'+cls+'-mc').dom.appendChild(this.dom);
9610 * Returns the value of a namespaced attribute from the element's underlying DOM node.
9611 * @param {String} namespace The namespace in which to look for the attribute
9612 * @param {String} name The attribute name
9613 * @return {String} The attribute value
9615 getAttributeNS : Roo.isIE ? function(ns, name){
9617 var type = typeof d[ns+":"+name];
9618 if(type != 'undefined' && type != 'unknown'){
9619 return d[ns+":"+name];
9622 } : function(ns, name){
9624 return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
9629 * Sets or Returns the value the dom attribute value
9630 * @param {String|Object} name The attribute name (or object to set multiple attributes)
9631 * @param {String} value (optional) The value to set the attribute to
9632 * @return {String} The attribute value
9634 attr : function(name){
9635 if (arguments.length > 1) {
9636 this.dom.setAttribute(name, arguments[1]);
9637 return arguments[1];
9639 if (typeof(name) == 'object') {
9640 for(var i in name) {
9641 this.attr(i, name[i]);
9647 if (!this.dom.hasAttribute(name)) {
9650 return this.dom.getAttribute(name);
9657 var ep = El.prototype;
9660 * Appends an event handler (Shorthand for addListener)
9661 * @param {String} eventName The type of event to append
9662 * @param {Function} fn The method the event invokes
9663 * @param {Object} scope (optional) The scope (this object) of the fn
9664 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
9667 ep.on = ep.addListener;
9669 ep.mon = ep.addListener;
9672 * Removes an event handler from this element (shorthand for removeListener)
9673 * @param {String} eventName the type of event to remove
9674 * @param {Function} fn the method the event invokes
9675 * @return {Roo.Element} this
9678 ep.un = ep.removeListener;
9681 * true to automatically adjust width and height settings for box-model issues (default to true)
9683 ep.autoBoxAdjust = true;
9686 El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;
9689 El.addUnits = function(v, defaultUnit){
9690 if(v === "" || v == "auto"){
9693 if(v === undefined){
9696 if(typeof v == "number" || !El.unitPattern.test(v)){
9697 return v + (defaultUnit || 'px');
9702 // special markup used throughout Roo when box wrapping elements
9703 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>';
9705 * Visibility mode constant - Use visibility to hide element
9711 * Visibility mode constant - Use display to hide element
9717 El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
9718 El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
9719 El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
9731 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9732 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9733 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9734 * @return {Element} The Element object
9737 El.get = function(el){
9739 if(!el){ return null; }
9740 if(typeof el == "string"){ // element id
9741 if(!(elm = document.getElementById(el))){
9744 if(ex = El.cache[el]){
9747 ex = El.cache[el] = new El(elm);
9750 }else if(el.tagName){ // dom element
9754 if(ex = El.cache[id]){
9757 ex = El.cache[id] = new El(el);
9760 }else if(el instanceof El){
9762 el.dom = document.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
9763 // catch case where it hasn't been appended
9764 El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
9767 }else if(el.isComposite){
9769 }else if(el instanceof Array){
9770 return El.select(el);
9771 }else if(el == document){
9772 // create a bogus element object representing the document object
9774 var f = function(){};
9775 f.prototype = El.prototype;
9777 docEl.dom = document;
9785 El.uncache = function(el){
9786 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
9788 delete El.cache[a[i].id || a[i]];
9794 // Garbage collection - uncache elements/purge listeners on orphaned elements
9795 // so we don't hold a reference and cause the browser to retain them
9796 El.garbageCollect = function(){
9797 if(!Roo.enableGarbageCollector){
9798 clearInterval(El.collectorThread);
9801 for(var eid in El.cache){
9802 var el = El.cache[eid], d = el.dom;
9803 // -------------------------------------------------------
9804 // Determining what is garbage:
9805 // -------------------------------------------------------
9807 // dom node is null, definitely garbage
9808 // -------------------------------------------------------
9810 // no parentNode == direct orphan, definitely garbage
9811 // -------------------------------------------------------
9812 // !d.offsetParent && !document.getElementById(eid)
9813 // display none elements have no offsetParent so we will
9814 // also try to look it up by it's id. However, check
9815 // offsetParent first so we don't do unneeded lookups.
9816 // This enables collection of elements that are not orphans
9817 // directly, but somewhere up the line they have an orphan
9819 // -------------------------------------------------------
9820 if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){
9821 delete El.cache[eid];
9822 if(d && Roo.enableListenerCollection){
9828 El.collectorThreadId = setInterval(El.garbageCollect, 30000);
9832 El.Flyweight = function(dom){
9835 El.Flyweight.prototype = El.prototype;
9837 El._flyweights = {};
9839 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9840 * the dom node can be overwritten by other code.
9841 * @param {String/HTMLElement} el The dom node or id
9842 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9843 * prevent conflicts (e.g. internally Roo uses "_internal")
9845 * @return {Element} The shared Element object
9847 El.fly = function(el, named){
9848 named = named || '_global';
9849 el = Roo.getDom(el);
9853 if(!El._flyweights[named]){
9854 El._flyweights[named] = new El.Flyweight();
9856 El._flyweights[named].dom = el;
9857 return El._flyweights[named];
9861 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9862 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9863 * Shorthand of {@link Roo.Element#get}
9864 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9865 * @return {Element} The Element object
9871 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9872 * the dom node can be overwritten by other code.
9873 * Shorthand of {@link Roo.Element#fly}
9874 * @param {String/HTMLElement} el The dom node or id
9875 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9876 * prevent conflicts (e.g. internally Roo uses "_internal")
9878 * @return {Element} The shared Element object
9884 // speedy lookup for elements never to box adjust
9885 var noBoxAdjust = Roo.isStrict ? {
9888 input:1, select:1, textarea:1
9890 if(Roo.isIE || Roo.isGecko){
9891 noBoxAdjust['button'] = 1;
9895 Roo.EventManager.on(window, 'unload', function(){
9897 delete El._flyweights;
9905 Roo.Element.selectorFunction = Roo.DomQuery.select;
9908 Roo.Element.select = function(selector, unique, root){
9910 if(typeof selector == "string"){
9911 els = Roo.Element.selectorFunction(selector, root);
9912 }else if(selector.length !== undefined){
9915 throw "Invalid selector";
9917 if(unique === true){
9918 return new Roo.CompositeElement(els);
9920 return new Roo.CompositeElementLite(els);
9924 * Selects elements based on the passed CSS selector to enable working on them as 1.
9925 * @param {String/Array} selector The CSS selector or an array of elements
9926 * @param {Boolean} unique (optional) true to create a unique Roo.Element for each element (defaults to a shared flyweight object)
9927 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
9928 * @return {CompositeElementLite/CompositeElement}
9932 Roo.select = Roo.Element.select;
9949 * Ext JS Library 1.1.1
9950 * Copyright(c) 2006-2007, Ext JS, LLC.
9952 * Originally Released Under LGPL - original licence link has changed is not relivant.
9955 * <script type="text/javascript">
9960 //Notifies Element that fx methods are available
9961 Roo.enableFx = true;
9965 * <p>A class to provide basic animation and visual effects support. <b>Note:</b> This class is automatically applied
9966 * to the {@link Roo.Element} interface when included, so all effects calls should be performed via Element.
9967 * Conversely, since the effects are not actually defined in Element, Roo.Fx <b>must</b> be included in order for the
9968 * Element effects to work.</p><br/>
9970 * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that
9971 * they return the Element object itself as the method return value, it is not always possible to mix the two in a single
9972 * method chain. The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced.
9973 * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately. For this reason,
9974 * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the
9975 * expected results and should be done with care.</p><br/>
9977 * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element
9978 * that will serve as either the start or end point of the animation. Following are all of the supported anchor positions:</p>
9981 ----- -----------------------------
9982 tl The top left corner
9983 t The center of the top edge
9984 tr The top right corner
9985 l The center of the left edge
9986 r The center of the right edge
9987 bl The bottom left corner
9988 b The center of the bottom edge
9989 br The bottom right corner
9991 * <b>Although some Fx methods accept specific custom config parameters, the ones shown in the Config Options section
9992 * below are common options that can be passed to any Fx method.</b>
9993 * @cfg {Function} callback A function called when the effect is finished
9994 * @cfg {Object} scope The scope of the effect function
9995 * @cfg {String} easing A valid Easing value for the effect
9996 * @cfg {String} afterCls A css class to apply after the effect
9997 * @cfg {Number} duration The length of time (in seconds) that the effect should last
9998 * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes
9999 * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to
10000 * effects that end with the element being visually hidden, ignored otherwise)
10001 * @cfg {String/Object/Function} afterStyle A style specification string, e.g. "width:100px", or an object in the form {width:"100px"}, or
10002 * a function which returns such a specification that will be applied to the Element after the effect finishes
10003 * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs
10004 * @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
10005 * @cfg {Boolean} stopFx Whether subsequent effects should be stopped and removed after the current effect finishes
10009 * Slides the element into view. An anchor point can be optionally passed to set the point of
10010 * origin for the slide effect. This function automatically handles wrapping the element with
10011 * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
10014 // default: slide the element in from the top
10017 // custom: slide the element in from the right with a 2-second duration
10018 el.slideIn('r', { duration: 2 });
10020 // common config options shown with default values
10026 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
10027 * @param {Object} options (optional) Object literal with any of the Fx config options
10028 * @return {Roo.Element} The Element
10030 slideIn : function(anchor, o){
10031 var el = this.getFxEl();
10034 el.queueFx(o, function(){
10036 anchor = anchor || "t";
10038 // fix display to visibility
10041 // restore values after effect
10042 var r = this.getFxRestore();
10043 var b = this.getBox();
10044 // fixed size for slide
10048 var wrap = this.fxWrap(r.pos, o, "hidden");
10050 var st = this.dom.style;
10051 st.visibility = "visible";
10052 st.position = "absolute";
10054 // clear out temp styles after slide and unwrap
10055 var after = function(){
10056 el.fxUnwrap(wrap, r.pos, o);
10057 st.width = r.width;
10058 st.height = r.height;
10061 // time to calc the positions
10062 var a, pt = {to: [b.x, b.y]}, bw = {to: b.width}, bh = {to: b.height};
10064 switch(anchor.toLowerCase()){
10066 wrap.setSize(b.width, 0);
10067 st.left = st.bottom = "0";
10071 wrap.setSize(0, b.height);
10072 st.right = st.top = "0";
10076 wrap.setSize(0, b.height);
10077 wrap.setX(b.right);
10078 st.left = st.top = "0";
10079 a = {width: bw, points: pt};
10082 wrap.setSize(b.width, 0);
10083 wrap.setY(b.bottom);
10084 st.left = st.top = "0";
10085 a = {height: bh, points: pt};
10088 wrap.setSize(0, 0);
10089 st.right = st.bottom = "0";
10090 a = {width: bw, height: bh};
10093 wrap.setSize(0, 0);
10094 wrap.setY(b.y+b.height);
10095 st.right = st.top = "0";
10096 a = {width: bw, height: bh, points: pt};
10099 wrap.setSize(0, 0);
10100 wrap.setXY([b.right, b.bottom]);
10101 st.left = st.top = "0";
10102 a = {width: bw, height: bh, points: pt};
10105 wrap.setSize(0, 0);
10106 wrap.setX(b.x+b.width);
10107 st.left = st.bottom = "0";
10108 a = {width: bw, height: bh, points: pt};
10111 this.dom.style.visibility = "visible";
10114 arguments.callee.anim = wrap.fxanim(a,
10124 * Slides the element out of view. An anchor point can be optionally passed to set the end point
10125 * for the slide effect. When the effect is completed, the element will be hidden (visibility =
10126 * 'hidden') but block elements will still take up space in the document. The element must be removed
10127 * from the DOM using the 'remove' config option if desired. This function automatically handles
10128 * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
10131 // default: slide the element out to the top
10134 // custom: slide the element out to the right with a 2-second duration
10135 el.slideOut('r', { duration: 2 });
10137 // common config options shown with default values
10145 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
10146 * @param {Object} options (optional) Object literal with any of the Fx config options
10147 * @return {Roo.Element} The Element
10149 slideOut : function(anchor, o){
10150 var el = this.getFxEl();
10153 el.queueFx(o, function(){
10155 anchor = anchor || "t";
10157 // restore values after effect
10158 var r = this.getFxRestore();
10160 var b = this.getBox();
10161 // fixed size for slide
10165 var wrap = this.fxWrap(r.pos, o, "visible");
10167 var st = this.dom.style;
10168 st.visibility = "visible";
10169 st.position = "absolute";
10173 var after = function(){
10175 el.setDisplayed(false);
10180 el.fxUnwrap(wrap, r.pos, o);
10182 st.width = r.width;
10183 st.height = r.height;
10188 var a, zero = {to: 0};
10189 switch(anchor.toLowerCase()){
10191 st.left = st.bottom = "0";
10192 a = {height: zero};
10195 st.right = st.top = "0";
10199 st.left = st.top = "0";
10200 a = {width: zero, points: {to:[b.right, b.y]}};
10203 st.left = st.top = "0";
10204 a = {height: zero, points: {to:[b.x, b.bottom]}};
10207 st.right = st.bottom = "0";
10208 a = {width: zero, height: zero};
10211 st.right = st.top = "0";
10212 a = {width: zero, height: zero, points: {to:[b.x, b.bottom]}};
10215 st.left = st.top = "0";
10216 a = {width: zero, height: zero, points: {to:[b.x+b.width, b.bottom]}};
10219 st.left = st.bottom = "0";
10220 a = {width: zero, height: zero, points: {to:[b.right, b.y]}};
10224 arguments.callee.anim = wrap.fxanim(a,
10234 * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
10235 * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
10236 * The element must be removed from the DOM using the 'remove' config option if desired.
10242 // common config options shown with default values
10250 * @param {Object} options (optional) Object literal with any of the Fx config options
10251 * @return {Roo.Element} The Element
10253 puff : function(o){
10254 var el = this.getFxEl();
10257 el.queueFx(o, function(){
10258 this.clearOpacity();
10261 // restore values after effect
10262 var r = this.getFxRestore();
10263 var st = this.dom.style;
10265 var after = function(){
10267 el.setDisplayed(false);
10274 el.setPositioning(r.pos);
10275 st.width = r.width;
10276 st.height = r.height;
10281 var width = this.getWidth();
10282 var height = this.getHeight();
10284 arguments.callee.anim = this.fxanim({
10285 width : {to: this.adjustWidth(width * 2)},
10286 height : {to: this.adjustHeight(height * 2)},
10287 points : {by: [-(width * .5), -(height * .5)]},
10289 fontSize: {to:200, unit: "%"}
10300 * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
10301 * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
10302 * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
10308 // all config options shown with default values
10316 * @param {Object} options (optional) Object literal with any of the Fx config options
10317 * @return {Roo.Element} The Element
10319 switchOff : function(o){
10320 var el = this.getFxEl();
10323 el.queueFx(o, function(){
10324 this.clearOpacity();
10327 // restore values after effect
10328 var r = this.getFxRestore();
10329 var st = this.dom.style;
10331 var after = function(){
10333 el.setDisplayed(false);
10339 el.setPositioning(r.pos);
10340 st.width = r.width;
10341 st.height = r.height;
10346 this.fxanim({opacity:{to:0.3}}, null, null, .1, null, function(){
10347 this.clearOpacity();
10351 points:{by:[0, this.getHeight() * .5]}
10352 }, o, 'motion', 0.3, 'easeIn', after);
10353 }).defer(100, this);
10360 * Highlights the Element by setting a color (applies to the background-color by default, but can be
10361 * changed using the "attr" config option) and then fading back to the original color. If no original
10362 * color is available, you should provide the "endColor" config option which will be cleared after the animation.
10365 // default: highlight background to yellow
10368 // custom: highlight foreground text to blue for 2 seconds
10369 el.highlight("0000ff", { attr: 'color', duration: 2 });
10371 // common config options shown with default values
10372 el.highlight("ffff9c", {
10373 attr: "background-color", //can be any valid CSS property (attribute) that supports a color value
10374 endColor: (current color) or "ffffff",
10379 * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
10380 * @param {Object} options (optional) Object literal with any of the Fx config options
10381 * @return {Roo.Element} The Element
10383 highlight : function(color, o){
10384 var el = this.getFxEl();
10387 el.queueFx(o, function(){
10388 color = color || "ffff9c";
10389 attr = o.attr || "backgroundColor";
10391 this.clearOpacity();
10394 var origColor = this.getColor(attr);
10395 var restoreColor = this.dom.style[attr];
10396 endColor = (o.endColor || origColor) || "ffffff";
10398 var after = function(){
10399 el.dom.style[attr] = restoreColor;
10404 a[attr] = {from: color, to: endColor};
10405 arguments.callee.anim = this.fxanim(a,
10415 * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
10418 // default: a single light blue ripple
10421 // custom: 3 red ripples lasting 3 seconds total
10422 el.frame("ff0000", 3, { duration: 3 });
10424 // common config options shown with default values
10425 el.frame("C3DAF9", 1, {
10426 duration: 1 //duration of entire animation (not each individual ripple)
10427 // Note: Easing is not configurable and will be ignored if included
10430 * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
10431 * @param {Number} count (optional) The number of ripples to display (defaults to 1)
10432 * @param {Object} options (optional) Object literal with any of the Fx config options
10433 * @return {Roo.Element} The Element
10435 frame : function(color, count, o){
10436 var el = this.getFxEl();
10439 el.queueFx(o, function(){
10440 color = color || "#C3DAF9";
10441 if(color.length == 6){
10442 color = "#" + color;
10444 count = count || 1;
10445 duration = o.duration || 1;
10448 var b = this.getBox();
10449 var animFn = function(){
10450 var proxy = this.createProxy({
10453 visbility:"hidden",
10454 position:"absolute",
10455 "z-index":"35000", // yee haw
10456 border:"0px solid " + color
10459 var scale = Roo.isBorderBox ? 2 : 1;
10461 top:{from:b.y, to:b.y - 20},
10462 left:{from:b.x, to:b.x - 20},
10463 borderWidth:{from:0, to:10},
10464 opacity:{from:1, to:0},
10465 height:{from:b.height, to:(b.height + (20*scale))},
10466 width:{from:b.width, to:(b.width + (20*scale))}
10467 }, duration, function(){
10471 animFn.defer((duration/2)*1000, this);
10482 * Creates a pause before any subsequent queued effects begin. If there are
10483 * no effects queued after the pause it will have no effect.
10488 * @param {Number} seconds The length of time to pause (in seconds)
10489 * @return {Roo.Element} The Element
10491 pause : function(seconds){
10492 var el = this.getFxEl();
10495 el.queueFx(o, function(){
10496 setTimeout(function(){
10498 }, seconds * 1000);
10504 * Fade an element in (from transparent to opaque). The ending opacity can be specified
10505 * using the "endOpacity" config option.
10508 // default: fade in from opacity 0 to 100%
10511 // custom: fade in from opacity 0 to 75% over 2 seconds
10512 el.fadeIn({ endOpacity: .75, duration: 2});
10514 // common config options shown with default values
10516 endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
10521 * @param {Object} options (optional) Object literal with any of the Fx config options
10522 * @return {Roo.Element} The Element
10524 fadeIn : function(o){
10525 var el = this.getFxEl();
10527 el.queueFx(o, function(){
10528 this.setOpacity(0);
10530 this.dom.style.visibility = 'visible';
10531 var to = o.endOpacity || 1;
10532 arguments.callee.anim = this.fxanim({opacity:{to:to}},
10533 o, null, .5, "easeOut", function(){
10535 this.clearOpacity();
10544 * Fade an element out (from opaque to transparent). The ending opacity can be specified
10545 * using the "endOpacity" config option.
10548 // default: fade out from the element's current opacity to 0
10551 // custom: fade out from the element's current opacity to 25% over 2 seconds
10552 el.fadeOut({ endOpacity: .25, duration: 2});
10554 // common config options shown with default values
10556 endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
10563 * @param {Object} options (optional) Object literal with any of the Fx config options
10564 * @return {Roo.Element} The Element
10566 fadeOut : function(o){
10567 var el = this.getFxEl();
10569 el.queueFx(o, function(){
10570 arguments.callee.anim = this.fxanim({opacity:{to:o.endOpacity || 0}},
10571 o, null, .5, "easeOut", function(){
10572 if(this.visibilityMode == Roo.Element.DISPLAY || o.useDisplay){
10573 this.dom.style.display = "none";
10575 this.dom.style.visibility = "hidden";
10577 this.clearOpacity();
10585 * Animates the transition of an element's dimensions from a starting height/width
10586 * to an ending height/width.
10589 // change height and width to 100x100 pixels
10590 el.scale(100, 100);
10592 // common config options shown with default values. The height and width will default to
10593 // the element's existing values if passed as null.
10596 [element's height], {
10601 * @param {Number} width The new width (pass undefined to keep the original width)
10602 * @param {Number} height The new height (pass undefined to keep the original height)
10603 * @param {Object} options (optional) Object literal with any of the Fx config options
10604 * @return {Roo.Element} The Element
10606 scale : function(w, h, o){
10607 this.shift(Roo.apply({}, o, {
10615 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
10616 * Any of these properties not specified in the config object will not be changed. This effect
10617 * requires that at least one new dimension, position or opacity setting must be passed in on
10618 * the config object in order for the function to have any effect.
10621 // slide the element horizontally to x position 200 while changing the height and opacity
10622 el.shift({ x: 200, height: 50, opacity: .8 });
10624 // common config options shown with default values.
10626 width: [element's width],
10627 height: [element's height],
10628 x: [element's x position],
10629 y: [element's y position],
10630 opacity: [element's opacity],
10635 * @param {Object} options Object literal with any of the Fx config options
10636 * @return {Roo.Element} The Element
10638 shift : function(o){
10639 var el = this.getFxEl();
10641 el.queueFx(o, function(){
10642 var a = {}, w = o.width, h = o.height, x = o.x, y = o.y, op = o.opacity;
10643 if(w !== undefined){
10644 a.width = {to: this.adjustWidth(w)};
10646 if(h !== undefined){
10647 a.height = {to: this.adjustHeight(h)};
10649 if(x !== undefined || y !== undefined){
10651 x !== undefined ? x : this.getX(),
10652 y !== undefined ? y : this.getY()
10655 if(op !== undefined){
10656 a.opacity = {to: op};
10658 if(o.xy !== undefined){
10659 a.points = {to: o.xy};
10661 arguments.callee.anim = this.fxanim(a,
10662 o, 'motion', .35, "easeOut", function(){
10670 * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
10671 * ending point of the effect.
10674 // default: slide the element downward while fading out
10677 // custom: slide the element out to the right with a 2-second duration
10678 el.ghost('r', { duration: 2 });
10680 // common config options shown with default values
10688 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
10689 * @param {Object} options (optional) Object literal with any of the Fx config options
10690 * @return {Roo.Element} The Element
10692 ghost : function(anchor, o){
10693 var el = this.getFxEl();
10696 el.queueFx(o, function(){
10697 anchor = anchor || "b";
10699 // restore values after effect
10700 var r = this.getFxRestore();
10701 var w = this.getWidth(),
10702 h = this.getHeight();
10704 var st = this.dom.style;
10706 var after = function(){
10708 el.setDisplayed(false);
10714 el.setPositioning(r.pos);
10715 st.width = r.width;
10716 st.height = r.height;
10721 var a = {opacity: {to: 0}, points: {}}, pt = a.points;
10722 switch(anchor.toLowerCase()){
10749 arguments.callee.anim = this.fxanim(a,
10759 * Ensures that all effects queued after syncFx is called on the element are
10760 * run concurrently. This is the opposite of {@link #sequenceFx}.
10761 * @return {Roo.Element} The Element
10763 syncFx : function(){
10764 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10773 * Ensures that all effects queued after sequenceFx is called on the element are
10774 * run in sequence. This is the opposite of {@link #syncFx}.
10775 * @return {Roo.Element} The Element
10777 sequenceFx : function(){
10778 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10780 concurrent : false,
10787 nextFx : function(){
10788 var ef = this.fxQueue[0];
10795 * Returns true if the element has any effects actively running or queued, else returns false.
10796 * @return {Boolean} True if element has active effects, else false
10798 hasActiveFx : function(){
10799 return this.fxQueue && this.fxQueue[0];
10803 * Stops any running effects and clears the element's internal effects queue if it contains
10804 * any additional effects that haven't started yet.
10805 * @return {Roo.Element} The Element
10807 stopFx : function(){
10808 if(this.hasActiveFx()){
10809 var cur = this.fxQueue[0];
10810 if(cur && cur.anim && cur.anim.isAnimated()){
10811 this.fxQueue = [cur]; // clear out others
10812 cur.anim.stop(true);
10819 beforeFx : function(o){
10820 if(this.hasActiveFx() && !o.concurrent){
10831 * Returns true if the element is currently blocking so that no other effect can be queued
10832 * until this effect is finished, else returns false if blocking is not set. This is commonly
10833 * used to ensure that an effect initiated by a user action runs to completion prior to the
10834 * same effect being restarted (e.g., firing only one effect even if the user clicks several times).
10835 * @return {Boolean} True if blocking, else false
10837 hasFxBlock : function(){
10838 var q = this.fxQueue;
10839 return q && q[0] && q[0].block;
10843 queueFx : function(o, fn){
10847 if(!this.hasFxBlock()){
10848 Roo.applyIf(o, this.fxDefaults);
10850 var run = this.beforeFx(o);
10851 fn.block = o.block;
10852 this.fxQueue.push(fn);
10864 fxWrap : function(pos, o, vis){
10866 if(!o.wrap || !(wrap = Roo.get(o.wrap))){
10869 wrapXY = this.getXY();
10871 var div = document.createElement("div");
10872 div.style.visibility = vis;
10873 wrap = Roo.get(this.dom.parentNode.insertBefore(div, this.dom));
10874 wrap.setPositioning(pos);
10875 if(wrap.getStyle("position") == "static"){
10876 wrap.position("relative");
10878 this.clearPositioning('auto');
10880 wrap.dom.appendChild(this.dom);
10882 wrap.setXY(wrapXY);
10889 fxUnwrap : function(wrap, pos, o){
10890 this.clearPositioning();
10891 this.setPositioning(pos);
10893 wrap.dom.parentNode.insertBefore(this.dom, wrap.dom);
10899 getFxRestore : function(){
10900 var st = this.dom.style;
10901 return {pos: this.getPositioning(), width: st.width, height : st.height};
10905 afterFx : function(o){
10907 this.applyStyles(o.afterStyle);
10910 this.addClass(o.afterCls);
10912 if(o.remove === true){
10915 Roo.callback(o.callback, o.scope, [this]);
10917 this.fxQueue.shift();
10923 getFxEl : function(){ // support for composite element fx
10924 return Roo.get(this.dom);
10928 fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){
10929 animType = animType || 'run';
10931 var anim = Roo.lib.Anim[animType](
10933 (opt.duration || defaultDur) || .35,
10934 (opt.easing || defaultEase) || 'easeOut',
10936 Roo.callback(cb, this);
10945 // backwords compat
10946 Roo.Fx.resize = Roo.Fx.scale;
10948 //When included, Roo.Fx is automatically applied to Element so that all basic
10949 //effects are available directly via the Element API
10950 Roo.apply(Roo.Element.prototype, Roo.Fx);/*
10952 * Ext JS Library 1.1.1
10953 * Copyright(c) 2006-2007, Ext JS, LLC.
10955 * Originally Released Under LGPL - original licence link has changed is not relivant.
10958 * <script type="text/javascript">
10963 * @class Roo.CompositeElement
10964 * Standard composite class. Creates a Roo.Element for every element in the collection.
10966 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
10967 * actions will be performed on all the elements in this collection.</b>
10969 * All methods return <i>this</i> and can be chained.
10971 var els = Roo.select("#some-el div.some-class", true);
10972 // or select directly from an existing element
10973 var el = Roo.get('some-el');
10974 el.select('div.some-class', true);
10976 els.setWidth(100); // all elements become 100 width
10977 els.hide(true); // all elements fade out and hide
10979 els.setWidth(100).hide(true);
10982 Roo.CompositeElement = function(els){
10983 this.elements = [];
10984 this.addElements(els);
10986 Roo.CompositeElement.prototype = {
10988 addElements : function(els){
10989 if(!els) return this;
10990 if(typeof els == "string"){
10991 els = Roo.Element.selectorFunction(els);
10993 var yels = this.elements;
10994 var index = yels.length-1;
10995 for(var i = 0, len = els.length; i < len; i++) {
10996 yels[++index] = Roo.get(els[i]);
11002 * Clears this composite and adds the elements returned by the passed selector.
11003 * @param {String/Array} els A string CSS selector, an array of elements or an element
11004 * @return {CompositeElement} this
11006 fill : function(els){
11007 this.elements = [];
11013 * Filters this composite to only elements that match the passed selector.
11014 * @param {String} selector A string CSS selector
11015 * @param {Boolean} inverse return inverse filter (not matches)
11016 * @return {CompositeElement} this
11018 filter : function(selector, inverse){
11020 inverse = inverse || false;
11021 this.each(function(el){
11022 var match = inverse ? !el.is(selector) : el.is(selector);
11024 els[els.length] = el.dom;
11031 invoke : function(fn, args){
11032 var els = this.elements;
11033 for(var i = 0, len = els.length; i < len; i++) {
11034 Roo.Element.prototype[fn].apply(els[i], args);
11039 * Adds elements to this composite.
11040 * @param {String/Array} els A string CSS selector, an array of elements or an element
11041 * @return {CompositeElement} this
11043 add : function(els){
11044 if(typeof els == "string"){
11045 this.addElements(Roo.Element.selectorFunction(els));
11046 }else if(els.length !== undefined){
11047 this.addElements(els);
11049 this.addElements([els]);
11054 * Calls the passed function passing (el, this, index) for each element in this composite.
11055 * @param {Function} fn The function to call
11056 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
11057 * @return {CompositeElement} this
11059 each : function(fn, scope){
11060 var els = this.elements;
11061 for(var i = 0, len = els.length; i < len; i++){
11062 if(fn.call(scope || els[i], els[i], this, i) === false) {
11070 * Returns the Element object at the specified index
11071 * @param {Number} index
11072 * @return {Roo.Element}
11074 item : function(index){
11075 return this.elements[index] || null;
11079 * Returns the first Element
11080 * @return {Roo.Element}
11082 first : function(){
11083 return this.item(0);
11087 * Returns the last Element
11088 * @return {Roo.Element}
11091 return this.item(this.elements.length-1);
11095 * Returns the number of elements in this composite
11098 getCount : function(){
11099 return this.elements.length;
11103 * Returns true if this composite contains the passed element
11106 contains : function(el){
11107 return this.indexOf(el) !== -1;
11111 * Returns true if this composite contains the passed element
11114 indexOf : function(el){
11115 return this.elements.indexOf(Roo.get(el));
11120 * Removes the specified element(s).
11121 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
11122 * or an array of any of those.
11123 * @param {Boolean} removeDom (optional) True to also remove the element from the document
11124 * @return {CompositeElement} this
11126 removeElement : function(el, removeDom){
11127 if(el instanceof Array){
11128 for(var i = 0, len = el.length; i < len; i++){
11129 this.removeElement(el[i]);
11133 var index = typeof el == 'number' ? el : this.indexOf(el);
11136 var d = this.elements[index];
11140 d.parentNode.removeChild(d);
11143 this.elements.splice(index, 1);
11149 * Replaces the specified element with the passed element.
11150 * @param {String/HTMLElement/Element/Number} el The id of an element, the Element itself, the index of the element in this composite
11152 * @param {String/HTMLElement/Element} replacement The id of an element or the Element itself.
11153 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
11154 * @return {CompositeElement} this
11156 replaceElement : function(el, replacement, domReplace){
11157 var index = typeof el == 'number' ? el : this.indexOf(el);
11160 this.elements[index].replaceWith(replacement);
11162 this.elements.splice(index, 1, Roo.get(replacement))
11169 * Removes all elements.
11171 clear : function(){
11172 this.elements = [];
11176 Roo.CompositeElement.createCall = function(proto, fnName){
11177 if(!proto[fnName]){
11178 proto[fnName] = function(){
11179 return this.invoke(fnName, arguments);
11183 for(var fnName in Roo.Element.prototype){
11184 if(typeof Roo.Element.prototype[fnName] == "function"){
11185 Roo.CompositeElement.createCall(Roo.CompositeElement.prototype, fnName);
11191 * Ext JS Library 1.1.1
11192 * Copyright(c) 2006-2007, Ext JS, LLC.
11194 * Originally Released Under LGPL - original licence link has changed is not relivant.
11197 * <script type="text/javascript">
11201 * @class Roo.CompositeElementLite
11202 * @extends Roo.CompositeElement
11203 * Flyweight composite class. Reuses the same Roo.Element for element operations.
11205 var els = Roo.select("#some-el div.some-class");
11206 // or select directly from an existing element
11207 var el = Roo.get('some-el');
11208 el.select('div.some-class');
11210 els.setWidth(100); // all elements become 100 width
11211 els.hide(true); // all elements fade out and hide
11213 els.setWidth(100).hide(true);
11214 </code></pre><br><br>
11215 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
11216 * actions will be performed on all the elements in this collection.</b>
11218 Roo.CompositeElementLite = function(els){
11219 Roo.CompositeElementLite.superclass.constructor.call(this, els);
11220 this.el = new Roo.Element.Flyweight();
11222 Roo.extend(Roo.CompositeElementLite, Roo.CompositeElement, {
11223 addElements : function(els){
11225 if(els instanceof Array){
11226 this.elements = this.elements.concat(els);
11228 var yels = this.elements;
11229 var index = yels.length-1;
11230 for(var i = 0, len = els.length; i < len; i++) {
11231 yels[++index] = els[i];
11237 invoke : function(fn, args){
11238 var els = this.elements;
11240 for(var i = 0, len = els.length; i < len; i++) {
11242 Roo.Element.prototype[fn].apply(el, args);
11247 * Returns a flyweight Element of the dom element object at the specified index
11248 * @param {Number} index
11249 * @return {Roo.Element}
11251 item : function(index){
11252 if(!this.elements[index]){
11255 this.el.dom = this.elements[index];
11259 // fixes scope with flyweight
11260 addListener : function(eventName, handler, scope, opt){
11261 var els = this.elements;
11262 for(var i = 0, len = els.length; i < len; i++) {
11263 Roo.EventManager.on(els[i], eventName, handler, scope || els[i], opt);
11269 * Calls the passed function passing (el, this, index) for each element in this composite. <b>The element
11270 * passed is the flyweight (shared) Roo.Element instance, so if you require a
11271 * a reference to the dom node, use el.dom.</b>
11272 * @param {Function} fn The function to call
11273 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
11274 * @return {CompositeElement} this
11276 each : function(fn, scope){
11277 var els = this.elements;
11279 for(var i = 0, len = els.length; i < len; i++){
11281 if(fn.call(scope || el, el, this, i) === false){
11288 indexOf : function(el){
11289 return this.elements.indexOf(Roo.getDom(el));
11292 replaceElement : function(el, replacement, domReplace){
11293 var index = typeof el == 'number' ? el : this.indexOf(el);
11295 replacement = Roo.getDom(replacement);
11297 var d = this.elements[index];
11298 d.parentNode.insertBefore(replacement, d);
11299 d.parentNode.removeChild(d);
11301 this.elements.splice(index, 1, replacement);
11306 Roo.CompositeElementLite.prototype.on = Roo.CompositeElementLite.prototype.addListener;
11310 * Ext JS Library 1.1.1
11311 * Copyright(c) 2006-2007, Ext JS, LLC.
11313 * Originally Released Under LGPL - original licence link has changed is not relivant.
11316 * <script type="text/javascript">
11322 * @class Roo.data.Connection
11323 * @extends Roo.util.Observable
11324 * The class encapsulates a connection to the page's originating domain, allowing requests to be made
11325 * either to a configured URL, or to a URL specified at request time.<br><br>
11327 * Requests made by this class are asynchronous, and will return immediately. No data from
11328 * the server will be available to the statement immediately following the {@link #request} call.
11329 * To process returned data, use a callback in the request options object, or an event listener.</p><br>
11331 * Note: If you are doing a file upload, you will not get a normal response object sent back to
11332 * your callback or event handler. Since the upload is handled via in IFRAME, there is no XMLHttpRequest.
11333 * The response object is created using the innerHTML of the IFRAME's document as the responseText
11334 * property and, if present, the IFRAME's XML document as the responseXML property.</p><br>
11335 * This means that a valid XML or HTML document must be returned. If JSON data is required, it is suggested
11336 * that it be placed either inside a <textarea> in an HTML document and retrieved from the responseText
11337 * using a regex, or inside a CDATA section in an XML document and retrieved from the responseXML using
11338 * standard DOM methods.
11340 * @param {Object} config a configuration object.
11342 Roo.data.Connection = function(config){
11343 Roo.apply(this, config);
11346 * @event beforerequest
11347 * Fires before a network request is made to retrieve a data object.
11348 * @param {Connection} conn This Connection object.
11349 * @param {Object} options The options config object passed to the {@link #request} method.
11351 "beforerequest" : true,
11353 * @event requestcomplete
11354 * Fires if the request was successfully completed.
11355 * @param {Connection} conn This Connection object.
11356 * @param {Object} response The XHR object containing the response data.
11357 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11358 * @param {Object} options The options config object passed to the {@link #request} method.
11360 "requestcomplete" : true,
11362 * @event requestexception
11363 * Fires if an error HTTP status was returned from the server.
11364 * See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html} for details of HTTP status codes.
11365 * @param {Connection} conn This Connection object.
11366 * @param {Object} response The XHR object containing the response data.
11367 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11368 * @param {Object} options The options config object passed to the {@link #request} method.
11370 "requestexception" : true
11372 Roo.data.Connection.superclass.constructor.call(this);
11375 Roo.extend(Roo.data.Connection, Roo.util.Observable, {
11377 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11380 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11381 * extra parameters to each request made by this object. (defaults to undefined)
11384 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11385 * to each request made by this object. (defaults to undefined)
11388 * @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)
11391 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11395 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11401 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11404 disableCaching: true,
11407 * Sends an HTTP request to a remote server.
11408 * @param {Object} options An object which may contain the following properties:<ul>
11409 * <li><b>url</b> {String} (Optional) The URL to which to send the request. Defaults to configured URL</li>
11410 * <li><b>params</b> {Object/String/Function} (Optional) An object containing properties which are used as parameters to the
11411 * request, a url encoded string or a function to call to get either.</li>
11412 * <li><b>method</b> {String} (Optional) The HTTP method to use for the request. Defaults to the configured method, or
11413 * if no method was configured, "GET" if no parameters are being sent, and "POST" if parameters are being sent.</li>
11414 * <li><b>callback</b> {Function} (Optional) The function to be called upon receipt of the HTTP response.
11415 * The callback is called regardless of success or failure and is passed the following parameters:<ul>
11416 * <li>options {Object} The parameter to the request call.</li>
11417 * <li>success {Boolean} True if the request succeeded.</li>
11418 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11420 * <li><b>success</b> {Function} (Optional) The function to be called upon success of the request.
11421 * The callback is passed the following parameters:<ul>
11422 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11423 * <li>options {Object} The parameter to the request call.</li>
11425 * <li><b>failure</b> {Function} (Optional) The function to be called upon failure of the request.
11426 * The callback is passed the following parameters:<ul>
11427 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11428 * <li>options {Object} The parameter to the request call.</li>
11430 * <li><b>scope</b> {Object} (Optional) The scope in which to execute the callbacks: The "this" object
11431 * for the callback function. Defaults to the browser window.</li>
11432 * <li><b>form</b> {Object/String} (Optional) A form object or id to pull parameters from.</li>
11433 * <li><b>isUpload</b> {Boolean} (Optional) True if the form object is a file upload (will usually be automatically detected).</li>
11434 * <li><b>headers</b> {Object} (Optional) Request headers to set for the request.</li>
11435 * <li><b>xmlData</b> {Object} (Optional) XML document to use for the post. Note: This will be used instead of
11436 * params for the post data. Any params will be appended to the URL.</li>
11437 * <li><b>disableCaching</b> {Boolean} (Optional) True to add a unique cache-buster param to GET requests.</li>
11439 * @return {Number} transactionId
11441 request : function(o){
11442 if(this.fireEvent("beforerequest", this, o) !== false){
11445 if(typeof p == "function"){
11446 p = p.call(o.scope||window, o);
11448 if(typeof p == "object"){
11449 p = Roo.urlEncode(o.params);
11451 if(this.extraParams){
11452 var extras = Roo.urlEncode(this.extraParams);
11453 p = p ? (p + '&' + extras) : extras;
11456 var url = o.url || this.url;
11457 if(typeof url == 'function'){
11458 url = url.call(o.scope||window, o);
11462 var form = Roo.getDom(o.form);
11463 url = url || form.action;
11465 var enctype = form.getAttribute("enctype");
11466 if(o.isUpload || (enctype && enctype.toLowerCase() == 'multipart/form-data')){
11467 return this.doFormUpload(o, p, url);
11469 var f = Roo.lib.Ajax.serializeForm(form);
11470 p = p ? (p + '&' + f) : f;
11473 var hs = o.headers;
11474 if(this.defaultHeaders){
11475 hs = Roo.apply(hs || {}, this.defaultHeaders);
11482 success: this.handleResponse,
11483 failure: this.handleFailure,
11485 argument: {options: o},
11486 timeout : o.timeout || this.timeout
11489 var method = o.method||this.method||(p ? "POST" : "GET");
11491 if(method == 'GET' && (this.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
11492 url += (url.indexOf('?') != -1 ? '&' : '?') + '_dc=' + (new Date().getTime());
11495 if(typeof o.autoAbort == 'boolean'){ // options gets top priority
11499 }else if(this.autoAbort !== false){
11503 if((method == 'GET' && p) || o.xmlData){
11504 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
11507 this.transId = Roo.lib.Ajax.request(method, url, cb, p, o);
11508 return this.transId;
11510 Roo.callback(o.callback, o.scope, [o, null, null]);
11516 * Determine whether this object has a request outstanding.
11517 * @param {Number} transactionId (Optional) defaults to the last transaction
11518 * @return {Boolean} True if there is an outstanding request.
11520 isLoading : function(transId){
11522 return Roo.lib.Ajax.isCallInProgress(transId);
11524 return this.transId ? true : false;
11529 * Aborts any outstanding request.
11530 * @param {Number} transactionId (Optional) defaults to the last transaction
11532 abort : function(transId){
11533 if(transId || this.isLoading()){
11534 Roo.lib.Ajax.abort(transId || this.transId);
11539 handleResponse : function(response){
11540 this.transId = false;
11541 var options = response.argument.options;
11542 response.argument = options ? options.argument : null;
11543 this.fireEvent("requestcomplete", this, response, options);
11544 Roo.callback(options.success, options.scope, [response, options]);
11545 Roo.callback(options.callback, options.scope, [options, true, response]);
11549 handleFailure : function(response, e){
11550 this.transId = false;
11551 var options = response.argument.options;
11552 response.argument = options ? options.argument : null;
11553 this.fireEvent("requestexception", this, response, options, e);
11554 Roo.callback(options.failure, options.scope, [response, options]);
11555 Roo.callback(options.callback, options.scope, [options, false, response]);
11559 doFormUpload : function(o, ps, url){
11561 var frame = document.createElement('iframe');
11564 frame.className = 'x-hidden';
11566 frame.src = Roo.SSL_SECURE_URL;
11568 document.body.appendChild(frame);
11571 document.frames[id].name = id;
11574 var form = Roo.getDom(o.form);
11576 form.method = 'POST';
11577 form.enctype = form.encoding = 'multipart/form-data';
11583 if(ps){ // add dynamic params
11585 ps = Roo.urlDecode(ps, false);
11587 if(ps.hasOwnProperty(k)){
11588 hd = document.createElement('input');
11589 hd.type = 'hidden';
11592 form.appendChild(hd);
11599 var r = { // bogus response object
11604 r.argument = o ? o.argument : null;
11609 doc = frame.contentWindow.document;
11611 doc = (frame.contentDocument || window.frames[id].document);
11613 if(doc && doc.body){
11614 r.responseText = doc.body.innerHTML;
11616 if(doc && doc.XMLDocument){
11617 r.responseXML = doc.XMLDocument;
11619 r.responseXML = doc;
11626 Roo.EventManager.removeListener(frame, 'load', cb, this);
11628 this.fireEvent("requestcomplete", this, r, o);
11629 Roo.callback(o.success, o.scope, [r, o]);
11630 Roo.callback(o.callback, o.scope, [o, true, r]);
11632 setTimeout(function(){document.body.removeChild(frame);}, 100);
11635 Roo.EventManager.on(frame, 'load', cb, this);
11638 if(hiddens){ // remove dynamic params
11639 for(var i = 0, len = hiddens.length; i < len; i++){
11640 form.removeChild(hiddens[i]);
11647 * Ext JS Library 1.1.1
11648 * Copyright(c) 2006-2007, Ext JS, LLC.
11650 * Originally Released Under LGPL - original licence link has changed is not relivant.
11653 * <script type="text/javascript">
11657 * Global Ajax request class.
11660 * @extends Roo.data.Connection
11663 * @cfg {String} url The default URL to be used for requests to the server. (defaults to undefined)
11664 * @cfg {Object} extraParams An object containing properties which are used as extra parameters to each request made by this object. (defaults to undefined)
11665 * @cfg {Object} defaultHeaders An object containing request headers which are added to each request made by this object. (defaults to undefined)
11666 * @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)
11667 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11668 * @cfg {Boolean} autoAbort (Optional) Whether a new request should abort any pending requests. (defaults to false)
11669 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11671 Roo.Ajax = new Roo.data.Connection({
11680 * Serialize the passed form into a url encoded string
11682 * @param {String/HTMLElement} form
11685 serializeForm : function(form){
11686 return Roo.lib.Ajax.serializeForm(form);
11690 * Ext JS Library 1.1.1
11691 * Copyright(c) 2006-2007, Ext JS, LLC.
11693 * Originally Released Under LGPL - original licence link has changed is not relivant.
11696 * <script type="text/javascript">
11701 * @class Roo.UpdateManager
11702 * @extends Roo.util.Observable
11703 * Provides AJAX-style update for Element object.<br><br>
11706 * // Get it from a Roo.Element object
11707 * var el = Roo.get("foo");
11708 * var mgr = el.getUpdateManager();
11709 * mgr.update("http://myserver.com/index.php", "param1=1&param2=2");
11711 * mgr.formUpdate("myFormId", "http://myserver.com/index.php");
11713 * // or directly (returns the same UpdateManager instance)
11714 * var mgr = new Roo.UpdateManager("myElementId");
11715 * mgr.startAutoRefresh(60, "http://myserver.com/index.php");
11716 * mgr.on("update", myFcnNeedsToKnow);
11718 // short handed call directly from the element object
11719 Roo.get("foo").load({
11723 text: "Loading Foo..."
11727 * Create new UpdateManager directly.
11728 * @param {String/HTMLElement/Roo.Element} el The element to update
11729 * @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).
11731 Roo.UpdateManager = function(el, forceNew){
11733 if(!forceNew && el.updateManager){
11734 return el.updateManager;
11737 * The Element object
11738 * @type Roo.Element
11742 * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.
11745 this.defaultUrl = null;
11749 * @event beforeupdate
11750 * Fired before an update is made, return false from your handler and the update is cancelled.
11751 * @param {Roo.Element} el
11752 * @param {String/Object/Function} url
11753 * @param {String/Object} params
11755 "beforeupdate": true,
11758 * Fired after successful update is made.
11759 * @param {Roo.Element} el
11760 * @param {Object} oResponseObject The response Object
11765 * Fired on update failure.
11766 * @param {Roo.Element} el
11767 * @param {Object} oResponseObject The response Object
11771 var d = Roo.UpdateManager.defaults;
11773 * Blank page URL to use with SSL file uploads (Defaults to Roo.UpdateManager.defaults.sslBlankUrl or "about:blank").
11776 this.sslBlankUrl = d.sslBlankUrl;
11778 * Whether to append unique parameter on get request to disable caching (Defaults to Roo.UpdateManager.defaults.disableCaching or false).
11781 this.disableCaching = d.disableCaching;
11783 * Text for loading indicator (Defaults to Roo.UpdateManager.defaults.indicatorText or '<div class="loading-indicator">Loading...</div>').
11786 this.indicatorText = d.indicatorText;
11788 * Whether to show indicatorText when loading (Defaults to Roo.UpdateManager.defaults.showLoadIndicator or true).
11791 this.showLoadIndicator = d.showLoadIndicator;
11793 * Timeout for requests or form posts in seconds (Defaults to Roo.UpdateManager.defaults.timeout or 30 seconds).
11796 this.timeout = d.timeout;
11799 * True to process scripts in the output (Defaults to Roo.UpdateManager.defaults.loadScripts (false)).
11802 this.loadScripts = d.loadScripts;
11805 * Transaction object of current executing transaction
11807 this.transaction = null;
11812 this.autoRefreshProcId = null;
11814 * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
11817 this.refreshDelegate = this.refresh.createDelegate(this);
11819 * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
11822 this.updateDelegate = this.update.createDelegate(this);
11824 * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
11827 this.formUpdateDelegate = this.formUpdate.createDelegate(this);
11831 this.successDelegate = this.processSuccess.createDelegate(this);
11835 this.failureDelegate = this.processFailure.createDelegate(this);
11837 if(!this.renderer){
11839 * The renderer for this UpdateManager. Defaults to {@link Roo.UpdateManager.BasicRenderer}.
11841 this.renderer = new Roo.UpdateManager.BasicRenderer();
11844 Roo.UpdateManager.superclass.constructor.call(this);
11847 Roo.extend(Roo.UpdateManager, Roo.util.Observable, {
11849 * Get the Element this UpdateManager is bound to
11850 * @return {Roo.Element} The element
11852 getEl : function(){
11856 * Performs an async request, updating this element with the response. If params are specified it uses POST, otherwise it uses GET.
11857 * @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:
11860 url: "your-url.php",<br/>
11861 params: {param1: "foo", param2: "bar"}, // or a URL encoded string<br/>
11862 callback: yourFunction,<br/>
11863 scope: yourObject, //(optional scope) <br/>
11864 discardUrl: false, <br/>
11865 nocache: false,<br/>
11866 text: "Loading...",<br/>
11868 scripts: false<br/>
11871 * The only required property is url. The optional properties nocache, text and scripts
11872 * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their associated property on this UpdateManager instance.
11873 * @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}
11874 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11875 * @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.
11877 update : function(url, params, callback, discardUrl){
11878 if(this.fireEvent("beforeupdate", this.el, url, params) !== false){
11879 var method = this.method,
11881 if(typeof url == "object"){ // must be config object
11884 params = params || cfg.params;
11885 callback = callback || cfg.callback;
11886 discardUrl = discardUrl || cfg.discardUrl;
11887 if(callback && cfg.scope){
11888 callback = callback.createDelegate(cfg.scope);
11890 if(typeof cfg.method != "undefined"){method = cfg.method;};
11891 if(typeof cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;};
11892 if(typeof cfg.text != "undefined"){this.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};
11893 if(typeof cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;};
11894 if(typeof cfg.timeout != "undefined"){this.timeout = cfg.timeout;};
11896 this.showLoading();
11898 this.defaultUrl = url;
11900 if(typeof url == "function"){
11901 url = url.call(this);
11904 method = method || (params ? "POST" : "GET");
11905 if(method == "GET"){
11906 url = this.prepareUrl(url);
11909 var o = Roo.apply(cfg ||{}, {
11912 success: this.successDelegate,
11913 failure: this.failureDelegate,
11914 callback: undefined,
11915 timeout: (this.timeout*1000),
11916 argument: {"url": url, "form": null, "callback": callback, "params": params}
11918 Roo.log("updated manager called with timeout of " + o.timeout);
11919 this.transaction = Roo.Ajax.request(o);
11924 * 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.
11925 * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.
11926 * @param {String/HTMLElement} form The form Id or form element
11927 * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
11928 * @param {Boolean} reset (optional) Whether to try to reset the form after the update
11929 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11931 formUpdate : function(form, url, reset, callback){
11932 if(this.fireEvent("beforeupdate", this.el, form, url) !== false){
11933 if(typeof url == "function"){
11934 url = url.call(this);
11936 form = Roo.getDom(form);
11937 this.transaction = Roo.Ajax.request({
11940 success: this.successDelegate,
11941 failure: this.failureDelegate,
11942 timeout: (this.timeout*1000),
11943 argument: {"url": url, "form": form, "callback": callback, "reset": reset}
11945 this.showLoading.defer(1, this);
11950 * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
11951 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
11953 refresh : function(callback){
11954 if(this.defaultUrl == null){
11957 this.update(this.defaultUrl, null, callback, true);
11961 * Set this element to auto refresh.
11962 * @param {Number} interval How often to update (in seconds).
11963 * @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)
11964 * @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}
11965 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
11966 * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
11968 startAutoRefresh : function(interval, url, params, callback, refreshNow){
11970 this.update(url || this.defaultUrl, params, callback, true);
11972 if(this.autoRefreshProcId){
11973 clearInterval(this.autoRefreshProcId);
11975 this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [url || this.defaultUrl, params, callback, true]), interval*1000);
11979 * Stop auto refresh on this element.
11981 stopAutoRefresh : function(){
11982 if(this.autoRefreshProcId){
11983 clearInterval(this.autoRefreshProcId);
11984 delete this.autoRefreshProcId;
11988 isAutoRefreshing : function(){
11989 return this.autoRefreshProcId ? true : false;
11992 * Called to update the element to "Loading" state. Override to perform custom action.
11994 showLoading : function(){
11995 if(this.showLoadIndicator){
11996 this.el.update(this.indicatorText);
12001 * Adds unique parameter to query string if disableCaching = true
12004 prepareUrl : function(url){
12005 if(this.disableCaching){
12006 var append = "_dc=" + (new Date().getTime());
12007 if(url.indexOf("?") !== -1){
12008 url += "&" + append;
12010 url += "?" + append;
12019 processSuccess : function(response){
12020 this.transaction = null;
12021 if(response.argument.form && response.argument.reset){
12022 try{ // put in try/catch since some older FF releases had problems with this
12023 response.argument.form.reset();
12026 if(this.loadScripts){
12027 this.renderer.render(this.el, response, this,
12028 this.updateComplete.createDelegate(this, [response]));
12030 this.renderer.render(this.el, response, this);
12031 this.updateComplete(response);
12035 updateComplete : function(response){
12036 this.fireEvent("update", this.el, response);
12037 if(typeof response.argument.callback == "function"){
12038 response.argument.callback(this.el, true, response);
12045 processFailure : function(response){
12046 this.transaction = null;
12047 this.fireEvent("failure", this.el, response);
12048 if(typeof response.argument.callback == "function"){
12049 response.argument.callback(this.el, false, response);
12054 * Set the content renderer for this UpdateManager. See {@link Roo.UpdateManager.BasicRenderer#render} for more details.
12055 * @param {Object} renderer The object implementing the render() method
12057 setRenderer : function(renderer){
12058 this.renderer = renderer;
12061 getRenderer : function(){
12062 return this.renderer;
12066 * Set the defaultUrl used for updates
12067 * @param {String/Function} defaultUrl The url or a function to call to get the url
12069 setDefaultUrl : function(defaultUrl){
12070 this.defaultUrl = defaultUrl;
12074 * Aborts the executing transaction
12076 abort : function(){
12077 if(this.transaction){
12078 Roo.Ajax.abort(this.transaction);
12083 * Returns true if an update is in progress
12084 * @return {Boolean}
12086 isUpdating : function(){
12087 if(this.transaction){
12088 return Roo.Ajax.isLoading(this.transaction);
12095 * @class Roo.UpdateManager.defaults
12096 * @static (not really - but it helps the doc tool)
12097 * The defaults collection enables customizing the default properties of UpdateManager
12099 Roo.UpdateManager.defaults = {
12101 * Timeout for requests or form posts in seconds (Defaults 30 seconds).
12107 * True to process scripts by default (Defaults to false).
12110 loadScripts : false,
12113 * Blank page URL to use with SSL file uploads (Defaults to "javascript:false").
12116 sslBlankUrl : (Roo.SSL_SECURE_URL || "javascript:false"),
12118 * Whether to append unique parameter on get request to disable caching (Defaults to false).
12121 disableCaching : false,
12123 * Whether to show indicatorText when loading (Defaults to true).
12126 showLoadIndicator : true,
12128 * Text for loading indicator (Defaults to '<div class="loading-indicator">Loading...</div>').
12131 indicatorText : '<div class="loading-indicator">Loading...</div>'
12135 * Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', ...}).
12137 * <pre><code>Roo.UpdateManager.updateElement("my-div", "stuff.php");</code></pre>
12138 * @param {String/HTMLElement/Roo.Element} el The element to update
12139 * @param {String} url The url
12140 * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
12141 * @param {Object} options (optional) A config object with any of the UpdateManager properties you want to set - for example: {disableCaching:true, indicatorText: "Loading data..."}
12144 * @member Roo.UpdateManager
12146 Roo.UpdateManager.updateElement = function(el, url, params, options){
12147 var um = Roo.get(el, true).getUpdateManager();
12148 Roo.apply(um, options);
12149 um.update(url, params, options ? options.callback : null);
12151 // alias for backwards compat
12152 Roo.UpdateManager.update = Roo.UpdateManager.updateElement;
12154 * @class Roo.UpdateManager.BasicRenderer
12155 * Default Content renderer. Updates the elements innerHTML with the responseText.
12157 Roo.UpdateManager.BasicRenderer = function(){};
12159 Roo.UpdateManager.BasicRenderer.prototype = {
12161 * This is called when the transaction is completed and it's time to update the element - The BasicRenderer
12162 * updates the elements innerHTML with the responseText - To perform a custom render (i.e. XML or JSON processing),
12163 * create an object with a "render(el, response)" method and pass it to setRenderer on the UpdateManager.
12164 * @param {Roo.Element} el The element being rendered
12165 * @param {Object} response The YUI Connect response object
12166 * @param {UpdateManager} updateManager The calling update manager
12167 * @param {Function} callback A callback that will need to be called if loadScripts is true on the UpdateManager
12169 render : function(el, response, updateManager, callback){
12170 el.update(response.responseText, updateManager.loadScripts, callback);
12176 * (c)) Alan Knowles
12182 * @class Roo.DomTemplate
12183 * @extends Roo.Template
12184 * An effort at a dom based template engine..
12186 * Similar to XTemplate, except it uses dom parsing to create the template..
12188 * Supported features:
12193 {a_variable} - output encoded.
12194 {a_variable.format:("Y-m-d")} - call a method on the variable
12195 {a_variable:raw} - unencoded output
12196 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
12197 {a_variable:this.method_on_template(...)} - call a method on the template object.
12202 <div roo-for="a_variable or condition.."></div>
12203 <div roo-if="a_variable or condition"></div>
12204 <div roo-exec="some javascript"></div>
12205 <div roo-name="named_template"></div>
12210 Roo.DomTemplate = function()
12212 Roo.DomTemplate.superclass.constructor.apply(this, arguments);
12219 Roo.extend(Roo.DomTemplate, Roo.Template, {
12221 * id counter for sub templates.
12225 * flag to indicate if dom parser is inside a pre,
12226 * it will strip whitespace if not.
12231 * The various sub templates
12239 * basic tag replacing syntax
12242 * // you can fake an object call by doing this
12246 re : /(\{|\%7B)([\w-\.]+)(?:\:([\w\.]*)(?:\(([^)]*?)?\))?)?(\}|\%7D)/g,
12247 //re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
12249 iterChild : function (node, method) {
12251 var oldPre = this.inPre;
12252 if (node.tagName == 'PRE') {
12255 for( var i = 0; i < node.childNodes.length; i++) {
12256 method.call(this, node.childNodes[i]);
12258 this.inPre = oldPre;
12264 * compile the template
12266 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
12269 compile: function()
12273 // covert the html into DOM...
12277 doc = document.implementation.createHTMLDocument("");
12278 doc.documentElement.innerHTML = this.html ;
12279 div = doc.documentElement;
12281 // old IE... - nasty -- it causes all sorts of issues.. with
12282 // images getting pulled from server..
12283 div = document.createElement('div');
12284 div.innerHTML = this.html;
12286 //doc.documentElement.innerHTML = htmlBody
12292 this.iterChild(div, function(n) {_t.compileNode(n, true); });
12294 var tpls = this.tpls;
12296 // create a top level template from the snippet..
12298 //Roo.log(div.innerHTML);
12305 body : div.innerHTML,
12318 Roo.each(tpls, function(tp){
12319 this.compileTpl(tp);
12320 this.tpls[tp.id] = tp;
12323 this.master = tpls[0];
12329 compileNode : function(node, istop) {
12334 // skip anything not a tag..
12335 if (node.nodeType != 1) {
12336 if (node.nodeType == 3 && !this.inPre) {
12337 // reduce white space..
12338 node.nodeValue = node.nodeValue.replace(/\s+/g, ' ');
12361 case (node.hasAttribute('roo-for')): tpl.attr = 'for'; break;
12362 case (node.hasAttribute('roo-if')): tpl.attr = 'if'; break;
12363 case (node.hasAttribute('roo-name')): tpl.attr = 'name'; break;
12364 case (node.hasAttribute('roo-exec')): tpl.attr = 'exec'; break;
12370 // just itterate children..
12371 this.iterChild(node,this.compileNode);
12374 tpl.uid = this.id++;
12375 tpl.value = node.getAttribute('roo-' + tpl.attr);
12376 node.removeAttribute('roo-'+ tpl.attr);
12377 if (tpl.attr != 'name') {
12378 var placeholder = document.createTextNode('{domtpl' + tpl.uid + '}');
12379 node.parentNode.replaceChild(placeholder, node);
12382 var placeholder = document.createElement('span');
12383 placeholder.className = 'roo-tpl-' + tpl.value;
12384 node.parentNode.replaceChild(placeholder, node);
12387 // parent now sees '{domtplXXXX}
12388 this.iterChild(node,this.compileNode);
12390 // we should now have node body...
12391 var div = document.createElement('div');
12392 div.appendChild(node);
12394 // this has the unfortunate side effect of converting tagged attributes
12395 // eg. href="{...}" into %7C...%7D
12396 // this has been fixed by searching for those combo's although it's a bit hacky..
12399 tpl.body = div.innerHTML;
12406 switch (tpl.value) {
12407 case '.': tpl.forCall = new Function('values', 'parent', 'with(values){ return values; }'); break;
12408 case '..': tpl.forCall= new Function('values', 'parent', 'with(values){ return parent; }'); break;
12409 default: tpl.forCall= new Function('values', 'parent', 'with(values){ return '+tpl.value+'; }');
12414 tpl.execCall = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
12418 tpl.ifCall = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
12422 tpl.id = tpl.value; // replace non characters???
12428 this.tpls.push(tpl);
12438 * Compile a segment of the template into a 'sub-template'
12444 compileTpl : function(tpl)
12446 var fm = Roo.util.Format;
12447 var useF = this.disableFormats !== true;
12449 var sep = Roo.isGecko ? "+\n" : ",\n";
12451 var undef = function(str) {
12452 Roo.debug && Roo.log("Property not found :" + str);
12456 //Roo.log(tpl.body);
12460 var fn = function(m, lbrace, name, format, args)
12463 //Roo.log(arguments);
12464 args = args ? args.replace(/\\'/g,"'") : args;
12465 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
12466 if (typeof(format) == 'undefined') {
12467 format = 'htmlEncode';
12469 if (format == 'raw' ) {
12473 if(name.substr(0, 6) == 'domtpl'){
12474 return "'"+ sep +'this.applySubTemplate('+name.substr(6)+', values, parent)'+sep+"'";
12477 // build an array of options to determine if value is undefined..
12479 // basically get 'xxxx.yyyy' then do
12480 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
12481 // (function () { Roo.log("Property not found"); return ''; })() :
12486 Roo.each(name.split('.'), function(st) {
12487 lookfor += (lookfor.length ? '.': '') + st;
12488 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
12491 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
12494 if(format && useF){
12496 args = args ? ',' + args : "";
12498 if(format.substr(0, 5) != "this."){
12499 format = "fm." + format + '(';
12501 format = 'this.call("'+ format.substr(5) + '", ';
12505 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
12508 if (args && args.length) {
12509 // called with xxyx.yuu:(test,test)
12511 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
12513 // raw.. - :raw modifier..
12514 return "'"+ sep + udef_st + name + ")"+sep+"'";
12518 // branched to use + in gecko and [].join() in others
12520 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
12521 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
12524 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
12525 body.push(tpl.body.replace(/(\r\n|\n)/g,
12526 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
12527 body.push("'].join('');};};");
12528 body = body.join('');
12531 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
12533 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
12540 * same as applyTemplate, except it's done to one of the subTemplates
12541 * when using named templates, you can do:
12543 * var str = pl.applySubTemplate('your-name', values);
12546 * @param {Number} id of the template
12547 * @param {Object} values to apply to template
12548 * @param {Object} parent (normaly the instance of this object)
12550 applySubTemplate : function(id, values, parent)
12554 var t = this.tpls[id];
12558 if(t.ifCall && !t.ifCall.call(this, values, parent)){
12559 Roo.debug && Roo.log('if call on ' + t.value + ' return false');
12563 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-if="' + t.value + '" - ' + e.toString());
12570 if(t.execCall && t.execCall.call(this, values, parent)){
12574 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
12580 var vs = t.forCall ? t.forCall.call(this, values, parent) : values;
12581 parent = t.target ? values : parent;
12582 if(t.forCall && vs instanceof Array){
12584 for(var i = 0, len = vs.length; i < len; i++){
12586 buf[buf.length] = t.compiled.call(this, vs[i], parent);
12588 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
12590 //Roo.log(t.compiled);
12594 return buf.join('');
12597 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
12602 return t.compiled.call(this, vs, parent);
12604 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
12606 //Roo.log(t.compiled);
12614 applyTemplate : function(values){
12615 return this.master.compiled.call(this, values, {});
12616 //var s = this.subs;
12619 apply : function(){
12620 return this.applyTemplate.apply(this, arguments);
12625 Roo.DomTemplate.from = function(el){
12626 el = Roo.getDom(el);
12627 return new Roo.Domtemplate(el.value || el.innerHTML);
12630 * Ext JS Library 1.1.1
12631 * Copyright(c) 2006-2007, Ext JS, LLC.
12633 * Originally Released Under LGPL - original licence link has changed is not relivant.
12636 * <script type="text/javascript">
12640 * @class Roo.util.DelayedTask
12641 * Provides a convenient method of performing setTimeout where a new
12642 * timeout cancels the old timeout. An example would be performing validation on a keypress.
12643 * You can use this class to buffer
12644 * the keypress events for a certain number of milliseconds, and perform only if they stop
12645 * for that amount of time.
12646 * @constructor The parameters to this constructor serve as defaults and are not required.
12647 * @param {Function} fn (optional) The default function to timeout
12648 * @param {Object} scope (optional) The default scope of that timeout
12649 * @param {Array} args (optional) The default Array of arguments
12651 Roo.util.DelayedTask = function(fn, scope, args){
12652 var id = null, d, t;
12654 var call = function(){
12655 var now = new Date().getTime();
12659 fn.apply(scope, args || []);
12663 * Cancels any pending timeout and queues a new one
12664 * @param {Number} delay The milliseconds to delay
12665 * @param {Function} newFn (optional) Overrides function passed to constructor
12666 * @param {Object} newScope (optional) Overrides scope passed to constructor
12667 * @param {Array} newArgs (optional) Overrides args passed to constructor
12669 this.delay = function(delay, newFn, newScope, newArgs){
12670 if(id && delay != d){
12674 t = new Date().getTime();
12676 scope = newScope || scope;
12677 args = newArgs || args;
12679 id = setInterval(call, d);
12684 * Cancel the last queued timeout
12686 this.cancel = function(){
12694 * Ext JS Library 1.1.1
12695 * Copyright(c) 2006-2007, Ext JS, LLC.
12697 * Originally Released Under LGPL - original licence link has changed is not relivant.
12700 * <script type="text/javascript">
12704 Roo.util.TaskRunner = function(interval){
12705 interval = interval || 10;
12706 var tasks = [], removeQueue = [];
12708 var running = false;
12710 var stopThread = function(){
12716 var startThread = function(){
12719 id = setInterval(runTasks, interval);
12723 var removeTask = function(task){
12724 removeQueue.push(task);
12730 var runTasks = function(){
12731 if(removeQueue.length > 0){
12732 for(var i = 0, len = removeQueue.length; i < len; i++){
12733 tasks.remove(removeQueue[i]);
12736 if(tasks.length < 1){
12741 var now = new Date().getTime();
12742 for(var i = 0, len = tasks.length; i < len; ++i){
12744 var itime = now - t.taskRunTime;
12745 if(t.interval <= itime){
12746 var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
12747 t.taskRunTime = now;
12748 if(rt === false || t.taskRunCount === t.repeat){
12753 if(t.duration && t.duration <= (now - t.taskStartTime)){
12760 * Queues a new task.
12761 * @param {Object} task
12763 this.start = function(task){
12765 task.taskStartTime = new Date().getTime();
12766 task.taskRunTime = 0;
12767 task.taskRunCount = 0;
12772 this.stop = function(task){
12777 this.stopAll = function(){
12779 for(var i = 0, len = tasks.length; i < len; i++){
12780 if(tasks[i].onStop){
12789 Roo.TaskMgr = new Roo.util.TaskRunner();/*
12791 * Ext JS Library 1.1.1
12792 * Copyright(c) 2006-2007, Ext JS, LLC.
12794 * Originally Released Under LGPL - original licence link has changed is not relivant.
12797 * <script type="text/javascript">
12802 * @class Roo.util.MixedCollection
12803 * @extends Roo.util.Observable
12804 * A Collection class that maintains both numeric indexes and keys and exposes events.
12806 * @param {Boolean} allowFunctions True if the addAll function should add function references to the
12807 * collection (defaults to false)
12808 * @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
12809 * and return the key value for that item. This is used when available to look up the key on items that
12810 * were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
12811 * equivalent to providing an implementation for the {@link #getKey} method.
12813 Roo.util.MixedCollection = function(allowFunctions, keyFn){
12821 * Fires when the collection is cleared.
12826 * Fires when an item is added to the collection.
12827 * @param {Number} index The index at which the item was added.
12828 * @param {Object} o The item added.
12829 * @param {String} key The key associated with the added item.
12834 * Fires when an item is replaced in the collection.
12835 * @param {String} key he key associated with the new added.
12836 * @param {Object} old The item being replaced.
12837 * @param {Object} new The new item.
12842 * Fires when an item is removed from the collection.
12843 * @param {Object} o The item being removed.
12844 * @param {String} key (optional) The key associated with the removed item.
12849 this.allowFunctions = allowFunctions === true;
12851 this.getKey = keyFn;
12853 Roo.util.MixedCollection.superclass.constructor.call(this);
12856 Roo.extend(Roo.util.MixedCollection, Roo.util.Observable, {
12857 allowFunctions : false,
12860 * Adds an item to the collection.
12861 * @param {String} key The key to associate with the item
12862 * @param {Object} o The item to add.
12863 * @return {Object} The item added.
12865 add : function(key, o){
12866 if(arguments.length == 1){
12868 key = this.getKey(o);
12870 if(typeof key == "undefined" || key === null){
12872 this.items.push(o);
12873 this.keys.push(null);
12875 var old = this.map[key];
12877 return this.replace(key, o);
12880 this.items.push(o);
12882 this.keys.push(key);
12884 this.fireEvent("add", this.length-1, o, key);
12889 * MixedCollection has a generic way to fetch keys if you implement getKey.
12892 var mc = new Roo.util.MixedCollection();
12893 mc.add(someEl.dom.id, someEl);
12894 mc.add(otherEl.dom.id, otherEl);
12898 var mc = new Roo.util.MixedCollection();
12899 mc.getKey = function(el){
12905 // or via the constructor
12906 var mc = new Roo.util.MixedCollection(false, function(el){
12912 * @param o {Object} The item for which to find the key.
12913 * @return {Object} The key for the passed item.
12915 getKey : function(o){
12920 * Replaces an item in the collection.
12921 * @param {String} key The key associated with the item to replace, or the item to replace.
12922 * @param o {Object} o (optional) If the first parameter passed was a key, the item to associate with that key.
12923 * @return {Object} The new item.
12925 replace : function(key, o){
12926 if(arguments.length == 1){
12928 key = this.getKey(o);
12930 var old = this.item(key);
12931 if(typeof key == "undefined" || key === null || typeof old == "undefined"){
12932 return this.add(key, o);
12934 var index = this.indexOfKey(key);
12935 this.items[index] = o;
12937 this.fireEvent("replace", key, old, o);
12942 * Adds all elements of an Array or an Object to the collection.
12943 * @param {Object/Array} objs An Object containing properties which will be added to the collection, or
12944 * an Array of values, each of which are added to the collection.
12946 addAll : function(objs){
12947 if(arguments.length > 1 || objs instanceof Array){
12948 var args = arguments.length > 1 ? arguments : objs;
12949 for(var i = 0, len = args.length; i < len; i++){
12953 for(var key in objs){
12954 if(this.allowFunctions || typeof objs[key] != "function"){
12955 this.add(key, objs[key]);
12962 * Executes the specified function once for every item in the collection, passing each
12963 * item as the first and only parameter. returning false from the function will stop the iteration.
12964 * @param {Function} fn The function to execute for each item.
12965 * @param {Object} scope (optional) The scope in which to execute the function.
12967 each : function(fn, scope){
12968 var items = [].concat(this.items); // each safe for removal
12969 for(var i = 0, len = items.length; i < len; i++){
12970 if(fn.call(scope || items[i], items[i], i, len) === false){
12977 * Executes the specified function once for every key in the collection, passing each
12978 * key, and its associated item as the first two parameters.
12979 * @param {Function} fn The function to execute for each item.
12980 * @param {Object} scope (optional) The scope in which to execute the function.
12982 eachKey : function(fn, scope){
12983 for(var i = 0, len = this.keys.length; i < len; i++){
12984 fn.call(scope || window, this.keys[i], this.items[i], i, len);
12989 * Returns the first item in the collection which elicits a true return value from the
12990 * passed selection function.
12991 * @param {Function} fn The selection function to execute for each item.
12992 * @param {Object} scope (optional) The scope in which to execute the function.
12993 * @return {Object} The first item in the collection which returned true from the selection function.
12995 find : function(fn, scope){
12996 for(var i = 0, len = this.items.length; i < len; i++){
12997 if(fn.call(scope || window, this.items[i], this.keys[i])){
12998 return this.items[i];
13005 * Inserts an item at the specified index in the collection.
13006 * @param {Number} index The index to insert the item at.
13007 * @param {String} key The key to associate with the new item, or the item itself.
13008 * @param {Object} o (optional) If the second parameter was a key, the new item.
13009 * @return {Object} The item inserted.
13011 insert : function(index, key, o){
13012 if(arguments.length == 2){
13014 key = this.getKey(o);
13016 if(index >= this.length){
13017 return this.add(key, o);
13020 this.items.splice(index, 0, o);
13021 if(typeof key != "undefined" && key != null){
13024 this.keys.splice(index, 0, key);
13025 this.fireEvent("add", index, o, key);
13030 * Removed an item from the collection.
13031 * @param {Object} o The item to remove.
13032 * @return {Object} The item removed.
13034 remove : function(o){
13035 return this.removeAt(this.indexOf(o));
13039 * Remove an item from a specified index in the collection.
13040 * @param {Number} index The index within the collection of the item to remove.
13042 removeAt : function(index){
13043 if(index < this.length && index >= 0){
13045 var o = this.items[index];
13046 this.items.splice(index, 1);
13047 var key = this.keys[index];
13048 if(typeof key != "undefined"){
13049 delete this.map[key];
13051 this.keys.splice(index, 1);
13052 this.fireEvent("remove", o, key);
13057 * Removed an item associated with the passed key fom the collection.
13058 * @param {String} key The key of the item to remove.
13060 removeKey : function(key){
13061 return this.removeAt(this.indexOfKey(key));
13065 * Returns the number of items in the collection.
13066 * @return {Number} the number of items in the collection.
13068 getCount : function(){
13069 return this.length;
13073 * Returns index within the collection of the passed Object.
13074 * @param {Object} o The item to find the index of.
13075 * @return {Number} index of the item.
13077 indexOf : function(o){
13078 if(!this.items.indexOf){
13079 for(var i = 0, len = this.items.length; i < len; i++){
13080 if(this.items[i] == o) return i;
13084 return this.items.indexOf(o);
13089 * Returns index within the collection of the passed key.
13090 * @param {String} key The key to find the index of.
13091 * @return {Number} index of the key.
13093 indexOfKey : function(key){
13094 if(!this.keys.indexOf){
13095 for(var i = 0, len = this.keys.length; i < len; i++){
13096 if(this.keys[i] == key) return i;
13100 return this.keys.indexOf(key);
13105 * Returns the item associated with the passed key OR index. Key has priority over index.
13106 * @param {String/Number} key The key or index of the item.
13107 * @return {Object} The item associated with the passed key.
13109 item : function(key){
13110 var item = typeof this.map[key] != "undefined" ? this.map[key] : this.items[key];
13111 return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype!
13115 * Returns the item at the specified index.
13116 * @param {Number} index The index of the item.
13119 itemAt : function(index){
13120 return this.items[index];
13124 * Returns the item associated with the passed key.
13125 * @param {String/Number} key The key of the item.
13126 * @return {Object} The item associated with the passed key.
13128 key : function(key){
13129 return this.map[key];
13133 * Returns true if the collection contains the passed Object as an item.
13134 * @param {Object} o The Object to look for in the collection.
13135 * @return {Boolean} True if the collection contains the Object as an item.
13137 contains : function(o){
13138 return this.indexOf(o) != -1;
13142 * Returns true if the collection contains the passed Object as a key.
13143 * @param {String} key The key to look for in the collection.
13144 * @return {Boolean} True if the collection contains the Object as a key.
13146 containsKey : function(key){
13147 return typeof this.map[key] != "undefined";
13151 * Removes all items from the collection.
13153 clear : function(){
13158 this.fireEvent("clear");
13162 * Returns the first item in the collection.
13163 * @return {Object} the first item in the collection..
13165 first : function(){
13166 return this.items[0];
13170 * Returns the last item in the collection.
13171 * @return {Object} the last item in the collection..
13174 return this.items[this.length-1];
13177 _sort : function(property, dir, fn){
13178 var dsc = String(dir).toUpperCase() == "DESC" ? -1 : 1;
13179 fn = fn || function(a, b){
13182 var c = [], k = this.keys, items = this.items;
13183 for(var i = 0, len = items.length; i < len; i++){
13184 c[c.length] = {key: k[i], value: items[i], index: i};
13186 c.sort(function(a, b){
13187 var v = fn(a[property], b[property]) * dsc;
13189 v = (a.index < b.index ? -1 : 1);
13193 for(var i = 0, len = c.length; i < len; i++){
13194 items[i] = c[i].value;
13197 this.fireEvent("sort", this);
13201 * Sorts this collection with the passed comparison function
13202 * @param {String} direction (optional) "ASC" or "DESC"
13203 * @param {Function} fn (optional) comparison function
13205 sort : function(dir, fn){
13206 this._sort("value", dir, fn);
13210 * Sorts this collection by keys
13211 * @param {String} direction (optional) "ASC" or "DESC"
13212 * @param {Function} fn (optional) a comparison function (defaults to case insensitive string)
13214 keySort : function(dir, fn){
13215 this._sort("key", dir, fn || function(a, b){
13216 return String(a).toUpperCase()-String(b).toUpperCase();
13221 * Returns a range of items in this collection
13222 * @param {Number} startIndex (optional) defaults to 0
13223 * @param {Number} endIndex (optional) default to the last item
13224 * @return {Array} An array of items
13226 getRange : function(start, end){
13227 var items = this.items;
13228 if(items.length < 1){
13231 start = start || 0;
13232 end = Math.min(typeof end == "undefined" ? this.length-1 : end, this.length-1);
13235 for(var i = start; i <= end; i++) {
13236 r[r.length] = items[i];
13239 for(var i = start; i >= end; i--) {
13240 r[r.length] = items[i];
13247 * Filter the <i>objects</i> in this collection by a specific property.
13248 * Returns a new collection that has been filtered.
13249 * @param {String} property A property on your objects
13250 * @param {String/RegExp} value Either string that the property values
13251 * should start with or a RegExp to test against the property
13252 * @return {MixedCollection} The new filtered collection
13254 filter : function(property, value){
13255 if(!value.exec){ // not a regex
13256 value = String(value);
13257 if(value.length == 0){
13258 return this.clone();
13260 value = new RegExp("^" + Roo.escapeRe(value), "i");
13262 return this.filterBy(function(o){
13263 return o && value.test(o[property]);
13268 * Filter by a function. * Returns a new collection that has been filtered.
13269 * The passed function will be called with each
13270 * object in the collection. If the function returns true, the value is included
13271 * otherwise it is filtered.
13272 * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
13273 * @param {Object} scope (optional) The scope of the function (defaults to this)
13274 * @return {MixedCollection} The new filtered collection
13276 filterBy : function(fn, scope){
13277 var r = new Roo.util.MixedCollection();
13278 r.getKey = this.getKey;
13279 var k = this.keys, it = this.items;
13280 for(var i = 0, len = it.length; i < len; i++){
13281 if(fn.call(scope||this, it[i], k[i])){
13282 r.add(k[i], it[i]);
13289 * Creates a duplicate of this collection
13290 * @return {MixedCollection}
13292 clone : function(){
13293 var r = new Roo.util.MixedCollection();
13294 var k = this.keys, it = this.items;
13295 for(var i = 0, len = it.length; i < len; i++){
13296 r.add(k[i], it[i]);
13298 r.getKey = this.getKey;
13303 * Returns the item associated with the passed key or index.
13305 * @param {String/Number} key The key or index of the item.
13306 * @return {Object} The item associated with the passed key.
13308 Roo.util.MixedCollection.prototype.get = Roo.util.MixedCollection.prototype.item;/*
13310 * Ext JS Library 1.1.1
13311 * Copyright(c) 2006-2007, Ext JS, LLC.
13313 * Originally Released Under LGPL - original licence link has changed is not relivant.
13316 * <script type="text/javascript">
13319 * @class Roo.util.JSON
13320 * Modified version of Douglas Crockford"s json.js that doesn"t
13321 * mess with the Object prototype
13322 * http://www.json.org/js.html
13325 Roo.util.JSON = new (function(){
13326 var useHasOwn = {}.hasOwnProperty ? true : false;
13328 // crashes Safari in some instances
13329 //var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
13331 var pad = function(n) {
13332 return n < 10 ? "0" + n : n;
13345 var encodeString = function(s){
13346 if (/["\\\x00-\x1f]/.test(s)) {
13347 return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
13352 c = b.charCodeAt();
13354 Math.floor(c / 16).toString(16) +
13355 (c % 16).toString(16);
13358 return '"' + s + '"';
13361 var encodeArray = function(o){
13362 var a = ["["], b, i, l = o.length, v;
13363 for (i = 0; i < l; i += 1) {
13365 switch (typeof v) {
13374 a.push(v === null ? "null" : Roo.util.JSON.encode(v));
13382 var encodeDate = function(o){
13383 return '"' + o.getFullYear() + "-" +
13384 pad(o.getMonth() + 1) + "-" +
13385 pad(o.getDate()) + "T" +
13386 pad(o.getHours()) + ":" +
13387 pad(o.getMinutes()) + ":" +
13388 pad(o.getSeconds()) + '"';
13392 * Encodes an Object, Array or other value
13393 * @param {Mixed} o The variable to encode
13394 * @return {String} The JSON string
13396 this.encode = function(o)
13398 // should this be extended to fully wrap stringify..
13400 if(typeof o == "undefined" || o === null){
13402 }else if(o instanceof Array){
13403 return encodeArray(o);
13404 }else if(o instanceof Date){
13405 return encodeDate(o);
13406 }else if(typeof o == "string"){
13407 return encodeString(o);
13408 }else if(typeof o == "number"){
13409 return isFinite(o) ? String(o) : "null";
13410 }else if(typeof o == "boolean"){
13413 var a = ["{"], b, i, v;
13415 if(!useHasOwn || o.hasOwnProperty(i)) {
13417 switch (typeof v) {
13426 a.push(this.encode(i), ":",
13427 v === null ? "null" : this.encode(v));
13438 * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError.
13439 * @param {String} json The JSON string
13440 * @return {Object} The resulting object
13442 this.decode = function(json){
13444 return /** eval:var:json */ eval("(" + json + ')');
13448 * Shorthand for {@link Roo.util.JSON#encode}
13449 * @member Roo encode
13451 Roo.encode = typeof(JSON) != 'undefined' && JSON.stringify ? JSON.stringify : Roo.util.JSON.encode;
13453 * Shorthand for {@link Roo.util.JSON#decode}
13454 * @member Roo decode
13456 Roo.decode = typeof(JSON) != 'undefined' && JSON.parse ? JSON.parse : Roo.util.JSON.decode;
13459 * Ext JS Library 1.1.1
13460 * Copyright(c) 2006-2007, Ext JS, LLC.
13462 * Originally Released Under LGPL - original licence link has changed is not relivant.
13465 * <script type="text/javascript">
13469 * @class Roo.util.Format
13470 * Reusable data formatting functions
13473 Roo.util.Format = function(){
13474 var trimRe = /^\s+|\s+$/g;
13477 * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
13478 * @param {String} value The string to truncate
13479 * @param {Number} length The maximum length to allow before truncating
13480 * @return {String} The converted text
13482 ellipsis : function(value, len){
13483 if(value && value.length > len){
13484 return value.substr(0, len-3)+"...";
13490 * Checks a reference and converts it to empty string if it is undefined
13491 * @param {Mixed} value Reference to check
13492 * @return {Mixed} Empty string if converted, otherwise the original value
13494 undef : function(value){
13495 return typeof value != "undefined" ? value : "";
13499 * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
13500 * @param {String} value The string to encode
13501 * @return {String} The encoded text
13503 htmlEncode : function(value){
13504 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
13508 * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
13509 * @param {String} value The string to decode
13510 * @return {String} The decoded text
13512 htmlDecode : function(value){
13513 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"');
13517 * Trims any whitespace from either side of a string
13518 * @param {String} value The text to trim
13519 * @return {String} The trimmed text
13521 trim : function(value){
13522 return String(value).replace(trimRe, "");
13526 * Returns a substring from within an original string
13527 * @param {String} value The original text
13528 * @param {Number} start The start index of the substring
13529 * @param {Number} length The length of the substring
13530 * @return {String} The substring
13532 substr : function(value, start, length){
13533 return String(value).substr(start, length);
13537 * Converts a string to all lower case letters
13538 * @param {String} value The text to convert
13539 * @return {String} The converted text
13541 lowercase : function(value){
13542 return String(value).toLowerCase();
13546 * Converts a string to all upper case letters
13547 * @param {String} value The text to convert
13548 * @return {String} The converted text
13550 uppercase : function(value){
13551 return String(value).toUpperCase();
13555 * Converts the first character only of a string to upper case
13556 * @param {String} value The text to convert
13557 * @return {String} The converted text
13559 capitalize : function(value){
13560 return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
13564 call : function(value, fn){
13565 if(arguments.length > 2){
13566 var args = Array.prototype.slice.call(arguments, 2);
13567 args.unshift(value);
13569 return /** eval:var:value */ eval(fn).apply(window, args);
13571 /** eval:var:value */
13572 return /** eval:var:value */ eval(fn).call(window, value);
13578 * safer version of Math.toFixed..??/
13579 * @param {Number/String} value The numeric value to format
13580 * @param {Number/String} value Decimal places
13581 * @return {String} The formatted currency string
13583 toFixed : function(v, n)
13585 // why not use to fixed - precision is buggered???
13587 return Math.round(v-0);
13589 var fact = Math.pow(10,n+1);
13590 v = (Math.round((v-0)*fact))/fact;
13591 var z = (''+fact).substring(2);
13592 if (v == Math.floor(v)) {
13593 return Math.floor(v) + '.' + z;
13596 // now just padd decimals..
13597 var ps = String(v).split('.');
13598 var fd = (ps[1] + z);
13599 var r = fd.substring(0,n);
13600 var rm = fd.substring(n);
13602 return ps[0] + '.' + r;
13604 r*=1; // turn it into a number;
13606 if (String(r).length != n) {
13609 r = String(r).substring(1); // chop the end off.
13612 return ps[0] + '.' + r;
13617 * Format a number as US currency
13618 * @param {Number/String} value The numeric value to format
13619 * @return {String} The formatted currency string
13621 usMoney : function(v){
13622 return '$' + Roo.util.Format.number(v);
13627 * eventually this should probably emulate php's number_format
13628 * @param {Number/String} value The numeric value to format
13629 * @param {Number} decimals number of decimal places
13630 * @return {String} The formatted currency string
13632 number : function(v,decimals)
13634 // multiply and round.
13635 decimals = typeof(decimals) == 'undefined' ? 2 : decimals;
13636 var mul = Math.pow(10, decimals);
13637 var zero = String(mul).substring(1);
13638 v = (Math.round((v-0)*mul))/mul;
13640 // if it's '0' number.. then
13642 //v = (v == Math.floor(v)) ? v + "." + zero : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
13644 var ps = v.split('.');
13648 var r = /(\d+)(\d{3})/;
13650 while (r.test(whole)) {
13651 whole = whole.replace(r, '$1' + ',' + '$2');
13657 (decimals ? ('.'+ ps[1] + zero.substring(ps[1].length)) : '') :
13658 // does not have decimals
13659 (decimals ? ('.' + zero) : '');
13662 return whole + sub ;
13666 * Parse a value into a formatted date using the specified format pattern.
13667 * @param {Mixed} value The value to format
13668 * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
13669 * @return {String} The formatted date string
13671 date : function(v, format){
13675 if(!(v instanceof Date)){
13676 v = new Date(Date.parse(v));
13678 return v.dateFormat(format || Roo.util.Format.defaults.date);
13682 * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
13683 * @param {String} format Any valid date format string
13684 * @return {Function} The date formatting function
13686 dateRenderer : function(format){
13687 return function(v){
13688 return Roo.util.Format.date(v, format);
13693 stripTagsRE : /<\/?[^>]+>/gi,
13696 * Strips all HTML tags
13697 * @param {Mixed} value The text from which to strip tags
13698 * @return {String} The stripped text
13700 stripTags : function(v){
13701 return !v ? v : String(v).replace(this.stripTagsRE, "");
13705 Roo.util.Format.defaults = {
13709 * Ext JS Library 1.1.1
13710 * Copyright(c) 2006-2007, Ext JS, LLC.
13712 * Originally Released Under LGPL - original licence link has changed is not relivant.
13715 * <script type="text/javascript">
13722 * @class Roo.MasterTemplate
13723 * @extends Roo.Template
13724 * Provides a template that can have child templates. The syntax is:
13726 var t = new Roo.MasterTemplate(
13727 '<select name="{name}">',
13728 '<tpl name="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
13731 t.add('options', {value: 'foo', text: 'bar'});
13732 // or you can add multiple child elements in one shot
13733 t.addAll('options', [
13734 {value: 'foo', text: 'bar'},
13735 {value: 'foo2', text: 'bar2'},
13736 {value: 'foo3', text: 'bar3'}
13738 // then append, applying the master template values
13739 t.append('my-form', {name: 'my-select'});
13741 * A name attribute for the child template is not required if you have only one child
13742 * template or you want to refer to them by index.
13744 Roo.MasterTemplate = function(){
13745 Roo.MasterTemplate.superclass.constructor.apply(this, arguments);
13746 this.originalHtml = this.html;
13748 var m, re = this.subTemplateRe;
13751 while(m = re.exec(this.html)){
13752 var name = m[1], content = m[2];
13757 tpl : new Roo.Template(content)
13760 st[name] = st[subIndex];
13762 st[subIndex].tpl.compile();
13763 st[subIndex].tpl.call = this.call.createDelegate(this);
13766 this.subCount = subIndex;
13769 Roo.extend(Roo.MasterTemplate, Roo.Template, {
13771 * The regular expression used to match sub templates
13775 subTemplateRe : /<tpl(?:\sname="([\w-]+)")?>((?:.|\n)*?)<\/tpl>/gi,
13778 * Applies the passed values to a child template.
13779 * @param {String/Number} name (optional) The name or index of the child template
13780 * @param {Array/Object} values The values to be applied to the template
13781 * @return {MasterTemplate} this
13783 add : function(name, values){
13784 if(arguments.length == 1){
13785 values = arguments[0];
13788 var s = this.subs[name];
13789 s.buffer[s.buffer.length] = s.tpl.apply(values);
13794 * Applies all the passed values to a child template.
13795 * @param {String/Number} name (optional) The name or index of the child template
13796 * @param {Array} values The values to be applied to the template, this should be an array of objects.
13797 * @param {Boolean} reset (optional) True to reset the template first
13798 * @return {MasterTemplate} this
13800 fill : function(name, values, reset){
13802 if(a.length == 1 || (a.length == 2 && typeof a[1] == "boolean")){
13810 for(var i = 0, len = values.length; i < len; i++){
13811 this.add(name, values[i]);
13817 * Resets the template for reuse
13818 * @return {MasterTemplate} this
13820 reset : function(){
13822 for(var i = 0; i < this.subCount; i++){
13828 applyTemplate : function(values){
13830 var replaceIndex = -1;
13831 this.html = this.originalHtml.replace(this.subTemplateRe, function(m, name){
13832 return s[++replaceIndex].buffer.join("");
13834 return Roo.MasterTemplate.superclass.applyTemplate.call(this, values);
13837 apply : function(){
13838 return this.applyTemplate.apply(this, arguments);
13841 compile : function(){return this;}
13845 * Alias for fill().
13848 Roo.MasterTemplate.prototype.addAll = Roo.MasterTemplate.prototype.fill;
13850 * Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML. e.g.
13851 * var tpl = Roo.MasterTemplate.from('element-id');
13852 * @param {String/HTMLElement} el
13853 * @param {Object} config
13856 Roo.MasterTemplate.from = function(el, config){
13857 el = Roo.getDom(el);
13858 return new Roo.MasterTemplate(el.value || el.innerHTML, config || '');
13861 * Ext JS Library 1.1.1
13862 * Copyright(c) 2006-2007, Ext JS, LLC.
13864 * Originally Released Under LGPL - original licence link has changed is not relivant.
13867 * <script type="text/javascript">
13872 * @class Roo.util.CSS
13873 * Utility class for manipulating CSS rules
13876 Roo.util.CSS = function(){
13878 var doc = document;
13880 var camelRe = /(-[a-z])/gi;
13881 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
13885 * Very simple dynamic creation of stylesheets from a text blob of rules. The text will wrapped in a style
13886 * tag and appended to the HEAD of the document.
13887 * @param {String|Object} cssText The text containing the css rules
13888 * @param {String} id An id to add to the stylesheet for later removal
13889 * @return {StyleSheet}
13891 createStyleSheet : function(cssText, id){
13893 var head = doc.getElementsByTagName("head")[0];
13894 var nrules = doc.createElement("style");
13895 nrules.setAttribute("type", "text/css");
13897 nrules.setAttribute("id", id);
13899 if (typeof(cssText) != 'string') {
13900 // support object maps..
13901 // not sure if this a good idea..
13902 // perhaps it should be merged with the general css handling
13903 // and handle js style props.
13904 var cssTextNew = [];
13905 for(var n in cssText) {
13907 for(var k in cssText[n]) {
13908 citems.push( k + ' : ' +cssText[n][k] + ';' );
13910 cssTextNew.push( n + ' { ' + citems.join(' ') + '} ');
13913 cssText = cssTextNew.join("\n");
13919 head.appendChild(nrules);
13920 ss = nrules.styleSheet;
13921 ss.cssText = cssText;
13924 nrules.appendChild(doc.createTextNode(cssText));
13926 nrules.cssText = cssText;
13928 head.appendChild(nrules);
13929 ss = nrules.styleSheet ? nrules.styleSheet : (nrules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
13931 this.cacheStyleSheet(ss);
13936 * Removes a style or link tag by id
13937 * @param {String} id The id of the tag
13939 removeStyleSheet : function(id){
13940 var existing = doc.getElementById(id);
13942 existing.parentNode.removeChild(existing);
13947 * Dynamically swaps an existing stylesheet reference for a new one
13948 * @param {String} id The id of an existing link tag to remove
13949 * @param {String} url The href of the new stylesheet to include
13951 swapStyleSheet : function(id, url){
13952 this.removeStyleSheet(id);
13953 var ss = doc.createElement("link");
13954 ss.setAttribute("rel", "stylesheet");
13955 ss.setAttribute("type", "text/css");
13956 ss.setAttribute("id", id);
13957 ss.setAttribute("href", url);
13958 doc.getElementsByTagName("head")[0].appendChild(ss);
13962 * Refresh the rule cache if you have dynamically added stylesheets
13963 * @return {Object} An object (hash) of rules indexed by selector
13965 refreshCache : function(){
13966 return this.getRules(true);
13970 cacheStyleSheet : function(stylesheet){
13974 try{// try catch for cross domain access issue
13975 var ssRules = stylesheet.cssRules || stylesheet.rules;
13976 for(var j = ssRules.length-1; j >= 0; --j){
13977 rules[ssRules[j].selectorText] = ssRules[j];
13983 * Gets all css rules for the document
13984 * @param {Boolean} refreshCache true to refresh the internal cache
13985 * @return {Object} An object (hash) of rules indexed by selector
13987 getRules : function(refreshCache){
13988 if(rules == null || refreshCache){
13990 var ds = doc.styleSheets;
13991 for(var i =0, len = ds.length; i < len; i++){
13993 this.cacheStyleSheet(ds[i]);
14001 * Gets an an individual CSS rule by selector(s)
14002 * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
14003 * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
14004 * @return {CSSRule} The CSS rule or null if one is not found
14006 getRule : function(selector, refreshCache){
14007 var rs = this.getRules(refreshCache);
14008 if(!(selector instanceof Array)){
14009 return rs[selector];
14011 for(var i = 0; i < selector.length; i++){
14012 if(rs[selector[i]]){
14013 return rs[selector[i]];
14021 * Updates a rule property
14022 * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
14023 * @param {String} property The css property
14024 * @param {String} value The new value for the property
14025 * @return {Boolean} true If a rule was found and updated
14027 updateRule : function(selector, property, value){
14028 if(!(selector instanceof Array)){
14029 var rule = this.getRule(selector);
14031 rule.style[property.replace(camelRe, camelFn)] = value;
14035 for(var i = 0; i < selector.length; i++){
14036 if(this.updateRule(selector[i], property, value)){
14046 * Ext JS Library 1.1.1
14047 * Copyright(c) 2006-2007, Ext JS, LLC.
14049 * Originally Released Under LGPL - original licence link has changed is not relivant.
14052 * <script type="text/javascript">
14058 * @class Roo.util.ClickRepeater
14059 * @extends Roo.util.Observable
14061 * A wrapper class which can be applied to any element. Fires a "click" event while the
14062 * mouse is pressed. The interval between firings may be specified in the config but
14063 * defaults to 10 milliseconds.
14065 * Optionally, a CSS class may be applied to the element during the time it is pressed.
14067 * @cfg {String/HTMLElement/Element} el The element to act as a button.
14068 * @cfg {Number} delay The initial delay before the repeating event begins firing.
14069 * Similar to an autorepeat key delay.
14070 * @cfg {Number} interval The interval between firings of the "click" event. Default 10 ms.
14071 * @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
14072 * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
14073 * "interval" and "delay" are ignored. "immediate" is honored.
14074 * @cfg {Boolean} preventDefault True to prevent the default click event
14075 * @cfg {Boolean} stopDefault True to stop the default click event
14078 * 2007-02-02 jvs Original code contributed by Nige "Animal" White
14079 * 2007-02-02 jvs Renamed to ClickRepeater
14080 * 2007-02-03 jvs Modifications for FF Mac and Safari
14083 * @param {String/HTMLElement/Element} el The element to listen on
14084 * @param {Object} config
14086 Roo.util.ClickRepeater = function(el, config)
14088 this.el = Roo.get(el);
14089 this.el.unselectable();
14091 Roo.apply(this, config);
14096 * Fires when the mouse button is depressed.
14097 * @param {Roo.util.ClickRepeater} this
14099 "mousedown" : true,
14102 * Fires on a specified interval during the time the element is pressed.
14103 * @param {Roo.util.ClickRepeater} this
14108 * Fires when the mouse key is released.
14109 * @param {Roo.util.ClickRepeater} this
14114 this.el.on("mousedown", this.handleMouseDown, this);
14115 if(this.preventDefault || this.stopDefault){
14116 this.el.on("click", function(e){
14117 if(this.preventDefault){
14118 e.preventDefault();
14120 if(this.stopDefault){
14126 // allow inline handler
14128 this.on("click", this.handler, this.scope || this);
14131 Roo.util.ClickRepeater.superclass.constructor.call(this);
14134 Roo.extend(Roo.util.ClickRepeater, Roo.util.Observable, {
14137 preventDefault : true,
14138 stopDefault : false,
14142 handleMouseDown : function(){
14143 clearTimeout(this.timer);
14145 if(this.pressClass){
14146 this.el.addClass(this.pressClass);
14148 this.mousedownTime = new Date();
14150 Roo.get(document).on("mouseup", this.handleMouseUp, this);
14151 this.el.on("mouseout", this.handleMouseOut, this);
14153 this.fireEvent("mousedown", this);
14154 this.fireEvent("click", this);
14156 this.timer = this.click.defer(this.delay || this.interval, this);
14160 click : function(){
14161 this.fireEvent("click", this);
14162 this.timer = this.click.defer(this.getInterval(), this);
14166 getInterval: function(){
14167 if(!this.accelerate){
14168 return this.interval;
14170 var pressTime = this.mousedownTime.getElapsed();
14171 if(pressTime < 500){
14173 }else if(pressTime < 1700){
14175 }else if(pressTime < 2600){
14177 }else if(pressTime < 3500){
14179 }else if(pressTime < 4400){
14181 }else if(pressTime < 5300){
14183 }else if(pressTime < 6200){
14191 handleMouseOut : function(){
14192 clearTimeout(this.timer);
14193 if(this.pressClass){
14194 this.el.removeClass(this.pressClass);
14196 this.el.on("mouseover", this.handleMouseReturn, this);
14200 handleMouseReturn : function(){
14201 this.el.un("mouseover", this.handleMouseReturn);
14202 if(this.pressClass){
14203 this.el.addClass(this.pressClass);
14209 handleMouseUp : function(){
14210 clearTimeout(this.timer);
14211 this.el.un("mouseover", this.handleMouseReturn);
14212 this.el.un("mouseout", this.handleMouseOut);
14213 Roo.get(document).un("mouseup", this.handleMouseUp);
14214 this.el.removeClass(this.pressClass);
14215 this.fireEvent("mouseup", this);
14219 * Ext JS Library 1.1.1
14220 * Copyright(c) 2006-2007, Ext JS, LLC.
14222 * Originally Released Under LGPL - original licence link has changed is not relivant.
14225 * <script type="text/javascript">
14230 * @class Roo.KeyNav
14231 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
14232 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
14233 * way to implement custom navigation schemes for any UI component.</p>
14234 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
14235 * pageUp, pageDown, del, home, end. Usage:</p>
14237 var nav = new Roo.KeyNav("my-element", {
14238 "left" : function(e){
14239 this.moveLeft(e.ctrlKey);
14241 "right" : function(e){
14242 this.moveRight(e.ctrlKey);
14244 "enter" : function(e){
14251 * @param {String/HTMLElement/Roo.Element} el The element to bind to
14252 * @param {Object} config The config
14254 Roo.KeyNav = function(el, config){
14255 this.el = Roo.get(el);
14256 Roo.apply(this, config);
14257 if(!this.disabled){
14258 this.disabled = true;
14263 Roo.KeyNav.prototype = {
14265 * @cfg {Boolean} disabled
14266 * True to disable this KeyNav instance (defaults to false)
14270 * @cfg {String} defaultEventAction
14271 * The method to call on the {@link Roo.EventObject} after this KeyNav intercepts a key. Valid values are
14272 * {@link Roo.EventObject#stopEvent}, {@link Roo.EventObject#preventDefault} and
14273 * {@link Roo.EventObject#stopPropagation} (defaults to 'stopEvent')
14275 defaultEventAction: "stopEvent",
14277 * @cfg {Boolean} forceKeyDown
14278 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
14279 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
14280 * handle keydown instead of keypress.
14282 forceKeyDown : false,
14285 prepareEvent : function(e){
14286 var k = e.getKey();
14287 var h = this.keyToHandler[k];
14288 //if(h && this[h]){
14289 // e.stopPropagation();
14291 if(Roo.isSafari && h && k >= 37 && k <= 40){
14297 relay : function(e){
14298 var k = e.getKey();
14299 var h = this.keyToHandler[k];
14301 if(this.doRelay(e, this[h], h) !== true){
14302 e[this.defaultEventAction]();
14308 doRelay : function(e, h, hname){
14309 return h.call(this.scope || this, e);
14312 // possible handlers
14326 // quick lookup hash
14343 * Enable this KeyNav
14345 enable: function(){
14347 // ie won't do special keys on keypress, no one else will repeat keys with keydown
14348 // the EventObject will normalize Safari automatically
14349 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
14350 this.el.on("keydown", this.relay, this);
14352 this.el.on("keydown", this.prepareEvent, this);
14353 this.el.on("keypress", this.relay, this);
14355 this.disabled = false;
14360 * Disable this KeyNav
14362 disable: function(){
14363 if(!this.disabled){
14364 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
14365 this.el.un("keydown", this.relay);
14367 this.el.un("keydown", this.prepareEvent);
14368 this.el.un("keypress", this.relay);
14370 this.disabled = true;
14375 * Ext JS Library 1.1.1
14376 * Copyright(c) 2006-2007, Ext JS, LLC.
14378 * Originally Released Under LGPL - original licence link has changed is not relivant.
14381 * <script type="text/javascript">
14386 * @class Roo.KeyMap
14387 * Handles mapping keys to actions for an element. One key map can be used for multiple actions.
14388 * The constructor accepts the same config object as defined by {@link #addBinding}.
14389 * If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
14390 * combination it will call the function with this signature (if the match is a multi-key
14391 * combination the callback will still be called only once): (String key, Roo.EventObject e)
14392 * A KeyMap can also handle a string representation of keys.<br />
14395 // map one key by key code
14396 var map = new Roo.KeyMap("my-element", {
14397 key: 13, // or Roo.EventObject.ENTER
14402 // map multiple keys to one action by string
14403 var map = new Roo.KeyMap("my-element", {
14409 // map multiple keys to multiple actions by strings and array of codes
14410 var map = new Roo.KeyMap("my-element", [
14413 fn: function(){ alert("Return was pressed"); }
14416 fn: function(){ alert('a, b or c was pressed'); }
14421 fn: function(){ alert('Control + shift + tab was pressed.'); }
14425 * <b>Note: A KeyMap starts enabled</b>
14427 * @param {String/HTMLElement/Roo.Element} el The element to bind to
14428 * @param {Object} config The config (see {@link #addBinding})
14429 * @param {String} eventName (optional) The event to bind to (defaults to "keydown")
14431 Roo.KeyMap = function(el, config, eventName){
14432 this.el = Roo.get(el);
14433 this.eventName = eventName || "keydown";
14434 this.bindings = [];
14436 this.addBinding(config);
14441 Roo.KeyMap.prototype = {
14443 * True to stop the event from bubbling and prevent the default browser action if the
14444 * key was handled by the KeyMap (defaults to false)
14450 * Add a new binding to this KeyMap. The following config object properties are supported:
14452 Property Type Description
14453 ---------- --------------- ----------------------------------------------------------------------
14454 key String/Array A single keycode or an array of keycodes to handle
14455 shift Boolean True to handle key only when shift is pressed (defaults to false)
14456 ctrl Boolean True to handle key only when ctrl is pressed (defaults to false)
14457 alt Boolean True to handle key only when alt is pressed (defaults to false)
14458 fn Function The function to call when KeyMap finds the expected key combination
14459 scope Object The scope of the callback function
14465 var map = new Roo.KeyMap(document, {
14466 key: Roo.EventObject.ENTER,
14471 //Add a new binding to the existing KeyMap later
14479 * @param {Object/Array} config A single KeyMap config or an array of configs
14481 addBinding : function(config){
14482 if(config instanceof Array){
14483 for(var i = 0, len = config.length; i < len; i++){
14484 this.addBinding(config[i]);
14488 var keyCode = config.key,
14489 shift = config.shift,
14490 ctrl = config.ctrl,
14493 scope = config.scope;
14494 if(typeof keyCode == "string"){
14496 var keyString = keyCode.toUpperCase();
14497 for(var j = 0, len = keyString.length; j < len; j++){
14498 ks.push(keyString.charCodeAt(j));
14502 var keyArray = keyCode instanceof Array;
14503 var handler = function(e){
14504 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
14505 var k = e.getKey();
14507 for(var i = 0, len = keyCode.length; i < len; i++){
14508 if(keyCode[i] == k){
14509 if(this.stopEvent){
14512 fn.call(scope || window, k, e);
14518 if(this.stopEvent){
14521 fn.call(scope || window, k, e);
14526 this.bindings.push(handler);
14530 * Shorthand for adding a single key listener
14531 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the
14532 * following options:
14533 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
14534 * @param {Function} fn The function to call
14535 * @param {Object} scope (optional) The scope of the function
14537 on : function(key, fn, scope){
14538 var keyCode, shift, ctrl, alt;
14539 if(typeof key == "object" && !(key instanceof Array)){
14558 handleKeyDown : function(e){
14559 if(this.enabled){ //just in case
14560 var b = this.bindings;
14561 for(var i = 0, len = b.length; i < len; i++){
14562 b[i].call(this, e);
14568 * Returns true if this KeyMap is enabled
14569 * @return {Boolean}
14571 isEnabled : function(){
14572 return this.enabled;
14576 * Enables this KeyMap
14578 enable: function(){
14580 this.el.on(this.eventName, this.handleKeyDown, this);
14581 this.enabled = true;
14586 * Disable this KeyMap
14588 disable: function(){
14590 this.el.removeListener(this.eventName, this.handleKeyDown, this);
14591 this.enabled = false;
14596 * Ext JS Library 1.1.1
14597 * Copyright(c) 2006-2007, Ext JS, LLC.
14599 * Originally Released Under LGPL - original licence link has changed is not relivant.
14602 * <script type="text/javascript">
14607 * @class Roo.util.TextMetrics
14608 * Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
14609 * wide, in pixels, a given block of text will be.
14612 Roo.util.TextMetrics = function(){
14616 * Measures the size of the specified text
14617 * @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
14618 * that can affect the size of the rendered text
14619 * @param {String} text The text to measure
14620 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
14621 * in order to accurately measure the text height
14622 * @return {Object} An object containing the text's size {width: (width), height: (height)}
14624 measure : function(el, text, fixedWidth){
14626 shared = Roo.util.TextMetrics.Instance(el, fixedWidth);
14629 shared.setFixedWidth(fixedWidth || 'auto');
14630 return shared.getSize(text);
14634 * Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
14635 * the overhead of multiple calls to initialize the style properties on each measurement.
14636 * @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
14637 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
14638 * in order to accurately measure the text height
14639 * @return {Roo.util.TextMetrics.Instance} instance The new instance
14641 createInstance : function(el, fixedWidth){
14642 return Roo.util.TextMetrics.Instance(el, fixedWidth);
14649 Roo.util.TextMetrics.Instance = function(bindTo, fixedWidth){
14650 var ml = new Roo.Element(document.createElement('div'));
14651 document.body.appendChild(ml.dom);
14652 ml.position('absolute');
14653 ml.setLeftTop(-1000, -1000);
14657 ml.setWidth(fixedWidth);
14662 * Returns the size of the specified text based on the internal element's style and width properties
14663 * @memberOf Roo.util.TextMetrics.Instance#
14664 * @param {String} text The text to measure
14665 * @return {Object} An object containing the text's size {width: (width), height: (height)}
14667 getSize : function(text){
14669 var s = ml.getSize();
14675 * Binds this TextMetrics instance to an element from which to copy existing CSS styles
14676 * that can affect the size of the rendered text
14677 * @memberOf Roo.util.TextMetrics.Instance#
14678 * @param {String/HTMLElement} el The element, dom node or id
14680 bind : function(el){
14682 Roo.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height')
14687 * Sets a fixed width on the internal measurement element. If the text will be multiline, you have
14688 * to set a fixed width in order to accurately measure the text height.
14689 * @memberOf Roo.util.TextMetrics.Instance#
14690 * @param {Number} width The width to set on the element
14692 setFixedWidth : function(width){
14693 ml.setWidth(width);
14697 * Returns the measured width of the specified text
14698 * @memberOf Roo.util.TextMetrics.Instance#
14699 * @param {String} text The text to measure
14700 * @return {Number} width The width in pixels
14702 getWidth : function(text){
14703 ml.dom.style.width = 'auto';
14704 return this.getSize(text).width;
14708 * Returns the measured height of the specified text. For multiline text, be sure to call
14709 * {@link #setFixedWidth} if necessary.
14710 * @memberOf Roo.util.TextMetrics.Instance#
14711 * @param {String} text The text to measure
14712 * @return {Number} height The height in pixels
14714 getHeight : function(text){
14715 return this.getSize(text).height;
14719 instance.bind(bindTo);
14724 // backwards compat
14725 Roo.Element.measureText = Roo.util.TextMetrics.measure;/*
14727 * Ext JS Library 1.1.1
14728 * Copyright(c) 2006-2007, Ext JS, LLC.
14730 * Originally Released Under LGPL - original licence link has changed is not relivant.
14733 * <script type="text/javascript">
14737 * @class Roo.state.Provider
14738 * Abstract base class for state provider implementations. This class provides methods
14739 * for encoding and decoding <b>typed</b> variables including dates and defines the
14740 * Provider interface.
14742 Roo.state.Provider = function(){
14744 * @event statechange
14745 * Fires when a state change occurs.
14746 * @param {Provider} this This state provider
14747 * @param {String} key The state key which was changed
14748 * @param {String} value The encoded value for the state
14751 "statechange": true
14754 Roo.state.Provider.superclass.constructor.call(this);
14756 Roo.extend(Roo.state.Provider, Roo.util.Observable, {
14758 * Returns the current value for a key
14759 * @param {String} name The key name
14760 * @param {Mixed} defaultValue A default value to return if the key's value is not found
14761 * @return {Mixed} The state data
14763 get : function(name, defaultValue){
14764 return typeof this.state[name] == "undefined" ?
14765 defaultValue : this.state[name];
14769 * Clears a value from the state
14770 * @param {String} name The key name
14772 clear : function(name){
14773 delete this.state[name];
14774 this.fireEvent("statechange", this, name, null);
14778 * Sets the value for a key
14779 * @param {String} name The key name
14780 * @param {Mixed} value The value to set
14782 set : function(name, value){
14783 this.state[name] = value;
14784 this.fireEvent("statechange", this, name, value);
14788 * Decodes a string previously encoded with {@link #encodeValue}.
14789 * @param {String} value The value to decode
14790 * @return {Mixed} The decoded value
14792 decodeValue : function(cookie){
14793 var re = /^(a|n|d|b|s|o)\:(.*)$/;
14794 var matches = re.exec(unescape(cookie));
14795 if(!matches || !matches[1]) return; // non state cookie
14796 var type = matches[1];
14797 var v = matches[2];
14800 return parseFloat(v);
14802 return new Date(Date.parse(v));
14807 var values = v.split("^");
14808 for(var i = 0, len = values.length; i < len; i++){
14809 all.push(this.decodeValue(values[i]));
14814 var values = v.split("^");
14815 for(var i = 0, len = values.length; i < len; i++){
14816 var kv = values[i].split("=");
14817 all[kv[0]] = this.decodeValue(kv[1]);
14826 * Encodes a value including type information. Decode with {@link #decodeValue}.
14827 * @param {Mixed} value The value to encode
14828 * @return {String} The encoded value
14830 encodeValue : function(v){
14832 if(typeof v == "number"){
14834 }else if(typeof v == "boolean"){
14835 enc = "b:" + (v ? "1" : "0");
14836 }else if(v instanceof Date){
14837 enc = "d:" + v.toGMTString();
14838 }else if(v instanceof Array){
14840 for(var i = 0, len = v.length; i < len; i++){
14841 flat += this.encodeValue(v[i]);
14842 if(i != len-1) flat += "^";
14845 }else if(typeof v == "object"){
14848 if(typeof v[key] != "function"){
14849 flat += key + "=" + this.encodeValue(v[key]) + "^";
14852 enc = "o:" + flat.substring(0, flat.length-1);
14856 return escape(enc);
14862 * Ext JS Library 1.1.1
14863 * Copyright(c) 2006-2007, Ext JS, LLC.
14865 * Originally Released Under LGPL - original licence link has changed is not relivant.
14868 * <script type="text/javascript">
14871 * @class Roo.state.Manager
14872 * This is the global state manager. By default all components that are "state aware" check this class
14873 * for state information if you don't pass them a custom state provider. In order for this class
14874 * to be useful, it must be initialized with a provider when your application initializes.
14876 // in your initialization function
14878 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
14880 // supposed you have a {@link Roo.BorderLayout}
14881 var layout = new Roo.BorderLayout(...);
14882 layout.restoreState();
14883 // or a {Roo.BasicDialog}
14884 var dialog = new Roo.BasicDialog(...);
14885 dialog.restoreState();
14889 Roo.state.Manager = function(){
14890 var provider = new Roo.state.Provider();
14894 * Configures the default state provider for your application
14895 * @param {Provider} stateProvider The state provider to set
14897 setProvider : function(stateProvider){
14898 provider = stateProvider;
14902 * Returns the current value for a key
14903 * @param {String} name The key name
14904 * @param {Mixed} defaultValue The default value to return if the key lookup does not match
14905 * @return {Mixed} The state data
14907 get : function(key, defaultValue){
14908 return provider.get(key, defaultValue);
14912 * Sets the value for a key
14913 * @param {String} name The key name
14914 * @param {Mixed} value The state data
14916 set : function(key, value){
14917 provider.set(key, value);
14921 * Clears a value from the state
14922 * @param {String} name The key name
14924 clear : function(key){
14925 provider.clear(key);
14929 * Gets the currently configured state provider
14930 * @return {Provider} The state provider
14932 getProvider : function(){
14939 * Ext JS Library 1.1.1
14940 * Copyright(c) 2006-2007, Ext JS, LLC.
14942 * Originally Released Under LGPL - original licence link has changed is not relivant.
14945 * <script type="text/javascript">
14948 * @class Roo.state.CookieProvider
14949 * @extends Roo.state.Provider
14950 * The default Provider implementation which saves state via cookies.
14953 var cp = new Roo.state.CookieProvider({
14955 expires: new Date(new Date().getTime()+(1000*60*60*24*30)); //30 days
14956 domain: "roojs.com"
14958 Roo.state.Manager.setProvider(cp);
14960 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
14961 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
14962 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
14963 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'roojs.com' to include
14964 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
14965 * domain the page is running on including the 'www' like 'www.roojs.com')
14966 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
14968 * Create a new CookieProvider
14969 * @param {Object} config The configuration object
14971 Roo.state.CookieProvider = function(config){
14972 Roo.state.CookieProvider.superclass.constructor.call(this);
14974 this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
14975 this.domain = null;
14976 this.secure = false;
14977 Roo.apply(this, config);
14978 this.state = this.readCookies();
14981 Roo.extend(Roo.state.CookieProvider, Roo.state.Provider, {
14983 set : function(name, value){
14984 if(typeof value == "undefined" || value === null){
14988 this.setCookie(name, value);
14989 Roo.state.CookieProvider.superclass.set.call(this, name, value);
14993 clear : function(name){
14994 this.clearCookie(name);
14995 Roo.state.CookieProvider.superclass.clear.call(this, name);
14999 readCookies : function(){
15001 var c = document.cookie + ";";
15002 var re = /\s?(.*?)=(.*?);/g;
15004 while((matches = re.exec(c)) != null){
15005 var name = matches[1];
15006 var value = matches[2];
15007 if(name && name.substring(0,3) == "ys-"){
15008 cookies[name.substr(3)] = this.decodeValue(value);
15015 setCookie : function(name, value){
15016 document.cookie = "ys-"+ name + "=" + this.encodeValue(value) +
15017 ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
15018 ((this.path == null) ? "" : ("; path=" + this.path)) +
15019 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
15020 ((this.secure == true) ? "; secure" : "");
15024 clearCookie : function(name){
15025 document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
15026 ((this.path == null) ? "" : ("; path=" + this.path)) +
15027 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
15028 ((this.secure == true) ? "; secure" : "");
15032 * Ext JS Library 1.1.1
15033 * Copyright(c) 2006-2007, Ext JS, LLC.
15035 * Originally Released Under LGPL - original licence link has changed is not relivant.
15038 * <script type="text/javascript">
15043 * @class Roo.ComponentMgr
15044 * Provides a common registry of all components on a page so that they can be easily accessed by component id (see {@link Roo.getCmp}).
15047 Roo.ComponentMgr = function(){
15048 var all = new Roo.util.MixedCollection();
15052 * Registers a component.
15053 * @param {Roo.Component} c The component
15055 register : function(c){
15060 * Unregisters a component.
15061 * @param {Roo.Component} c The component
15063 unregister : function(c){
15068 * Returns a component by id
15069 * @param {String} id The component id
15071 get : function(id){
15072 return all.get(id);
15076 * Registers a function that will be called when a specified component is added to ComponentMgr
15077 * @param {String} id The component id
15078 * @param {Funtction} fn The callback function
15079 * @param {Object} scope The scope of the callback
15081 onAvailable : function(id, fn, scope){
15082 all.on("add", function(index, o){
15084 fn.call(scope || o, o);
15085 all.un("add", fn, scope);
15092 * Ext JS Library 1.1.1
15093 * Copyright(c) 2006-2007, Ext JS, LLC.
15095 * Originally Released Under LGPL - original licence link has changed is not relivant.
15098 * <script type="text/javascript">
15102 * @class Roo.Component
15103 * @extends Roo.util.Observable
15104 * Base class for all major Roo components. All subclasses of Component can automatically participate in the standard
15105 * Roo component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show
15106 * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Roo.Container} and
15107 * to be automatically registered with the {@link Roo.ComponentMgr} so that it can be referenced at any time via {@link Roo.getCmp}.
15108 * All visual components (widgets) that require rendering into a layout should subclass Component.
15110 * @param {Roo.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
15111 * 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
15112 * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
15114 Roo.Component = function(config){
15115 config = config || {};
15116 if(config.tagName || config.dom || typeof config == "string"){ // element object
15117 config = {el: config, id: config.id || config};
15119 this.initialConfig = config;
15121 Roo.apply(this, config);
15125 * Fires after the component is disabled.
15126 * @param {Roo.Component} this
15131 * Fires after the component is enabled.
15132 * @param {Roo.Component} this
15136 * @event beforeshow
15137 * Fires before the component is shown. Return false to stop the show.
15138 * @param {Roo.Component} this
15143 * Fires after the component is shown.
15144 * @param {Roo.Component} this
15148 * @event beforehide
15149 * Fires before the component is hidden. Return false to stop the hide.
15150 * @param {Roo.Component} this
15155 * Fires after the component is hidden.
15156 * @param {Roo.Component} this
15160 * @event beforerender
15161 * Fires before the component is rendered. Return false to stop the render.
15162 * @param {Roo.Component} this
15164 beforerender : true,
15167 * Fires after the component is rendered.
15168 * @param {Roo.Component} this
15172 * @event beforedestroy
15173 * Fires before the component is destroyed. Return false to stop the destroy.
15174 * @param {Roo.Component} this
15176 beforedestroy : true,
15179 * Fires after the component is destroyed.
15180 * @param {Roo.Component} this
15185 this.id = "roo-comp-" + (++Roo.Component.AUTO_ID);
15187 Roo.ComponentMgr.register(this);
15188 Roo.Component.superclass.constructor.call(this);
15189 this.initComponent();
15190 if(this.renderTo){ // not supported by all components yet. use at your own risk!
15191 this.render(this.renderTo);
15192 delete this.renderTo;
15197 Roo.Component.AUTO_ID = 1000;
15199 Roo.extend(Roo.Component, Roo.util.Observable, {
15201 * @scope Roo.Component.prototype
15203 * true if this component is hidden. Read-only.
15208 * true if this component is disabled. Read-only.
15213 * true if this component has been rendered. Read-only.
15217 /** @cfg {String} disableClass
15218 * CSS class added to the component when it is disabled (defaults to "x-item-disabled").
15220 disabledClass : "x-item-disabled",
15221 /** @cfg {Boolean} allowDomMove
15222 * Whether the component can move the Dom node when rendering (defaults to true).
15224 allowDomMove : true,
15225 /** @cfg {String} hideMode (display|visibility)
15226 * How this component should hidden. Supported values are
15227 * "visibility" (css visibility), "offsets" (negative offset position) and
15228 * "display" (css display) - defaults to "display".
15230 hideMode: 'display',
15233 ctype : "Roo.Component",
15236 * @cfg {String} actionMode
15237 * which property holds the element that used for hide() / show() / disable() / enable()
15243 getActionEl : function(){
15244 return this[this.actionMode];
15247 initComponent : Roo.emptyFn,
15249 * If this is a lazy rendering component, render it to its container element.
15250 * @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.
15252 render : function(container, position){
15253 if(!this.rendered && this.fireEvent("beforerender", this) !== false){
15254 if(!container && this.el){
15255 this.el = Roo.get(this.el);
15256 container = this.el.dom.parentNode;
15257 this.allowDomMove = false;
15259 this.container = Roo.get(container);
15260 this.rendered = true;
15261 if(position !== undefined){
15262 if(typeof position == 'number'){
15263 position = this.container.dom.childNodes[position];
15265 position = Roo.getDom(position);
15268 this.onRender(this.container, position || null);
15270 this.el.addClass(this.cls);
15274 this.el.applyStyles(this.style);
15277 this.fireEvent("render", this);
15278 this.afterRender(this.container);
15290 // default function is not really useful
15291 onRender : function(ct, position){
15293 this.el = Roo.get(this.el);
15294 if(this.allowDomMove !== false){
15295 ct.dom.insertBefore(this.el.dom, position);
15301 getAutoCreate : function(){
15302 var cfg = typeof this.autoCreate == "object" ?
15303 this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
15304 if(this.id && !cfg.id){
15311 afterRender : Roo.emptyFn,
15314 * Destroys this component by purging any event listeners, removing the component's element from the DOM,
15315 * removing the component from its {@link Roo.Container} (if applicable) and unregistering it from {@link Roo.ComponentMgr}.
15317 destroy : function(){
15318 if(this.fireEvent("beforedestroy", this) !== false){
15319 this.purgeListeners();
15320 this.beforeDestroy();
15322 this.el.removeAllListeners();
15324 if(this.actionMode == "container"){
15325 this.container.remove();
15329 Roo.ComponentMgr.unregister(this);
15330 this.fireEvent("destroy", this);
15335 beforeDestroy : function(){
15340 onDestroy : function(){
15345 * Returns the underlying {@link Roo.Element}.
15346 * @return {Roo.Element} The element
15348 getEl : function(){
15353 * Returns the id of this component.
15356 getId : function(){
15361 * Try to focus this component.
15362 * @param {Boolean} selectText True to also select the text in this component (if applicable)
15363 * @return {Roo.Component} this
15365 focus : function(selectText){
15368 if(selectText === true){
15369 this.el.dom.select();
15384 * Disable this component.
15385 * @return {Roo.Component} this
15387 disable : function(){
15391 this.disabled = true;
15392 this.fireEvent("disable", this);
15397 onDisable : function(){
15398 this.getActionEl().addClass(this.disabledClass);
15399 this.el.dom.disabled = true;
15403 * Enable this component.
15404 * @return {Roo.Component} this
15406 enable : function(){
15410 this.disabled = false;
15411 this.fireEvent("enable", this);
15416 onEnable : function(){
15417 this.getActionEl().removeClass(this.disabledClass);
15418 this.el.dom.disabled = false;
15422 * Convenience function for setting disabled/enabled by boolean.
15423 * @param {Boolean} disabled
15425 setDisabled : function(disabled){
15426 this[disabled ? "disable" : "enable"]();
15430 * Show this component.
15431 * @return {Roo.Component} this
15434 if(this.fireEvent("beforeshow", this) !== false){
15435 this.hidden = false;
15439 this.fireEvent("show", this);
15445 onShow : function(){
15446 var ae = this.getActionEl();
15447 if(this.hideMode == 'visibility'){
15448 ae.dom.style.visibility = "visible";
15449 }else if(this.hideMode == 'offsets'){
15450 ae.removeClass('x-hidden');
15452 ae.dom.style.display = "";
15457 * Hide this component.
15458 * @return {Roo.Component} this
15461 if(this.fireEvent("beforehide", this) !== false){
15462 this.hidden = true;
15466 this.fireEvent("hide", this);
15472 onHide : function(){
15473 var ae = this.getActionEl();
15474 if(this.hideMode == 'visibility'){
15475 ae.dom.style.visibility = "hidden";
15476 }else if(this.hideMode == 'offsets'){
15477 ae.addClass('x-hidden');
15479 ae.dom.style.display = "none";
15484 * Convenience function to hide or show this component by boolean.
15485 * @param {Boolean} visible True to show, false to hide
15486 * @return {Roo.Component} this
15488 setVisible: function(visible){
15498 * Returns true if this component is visible.
15500 isVisible : function(){
15501 return this.getActionEl().isVisible();
15504 cloneConfig : function(overrides){
15505 overrides = overrides || {};
15506 var id = overrides.id || Roo.id();
15507 var cfg = Roo.applyIf(overrides, this.initialConfig);
15508 cfg.id = id; // prevent dup id
15509 return new this.constructor(cfg);
15513 * Ext JS Library 1.1.1
15514 * Copyright(c) 2006-2007, Ext JS, LLC.
15516 * Originally Released Under LGPL - original licence link has changed is not relivant.
15519 * <script type="text/javascript">
15523 * @class Roo.BoxComponent
15524 * @extends Roo.Component
15525 * Base class for any visual {@link Roo.Component} that uses a box container. BoxComponent provides automatic box
15526 * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model. All
15527 * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext
15528 * layout containers.
15530 * @param {Roo.Element/String/Object} config The configuration options.
15532 Roo.BoxComponent = function(config){
15533 Roo.Component.call(this, config);
15537 * Fires after the component is resized.
15538 * @param {Roo.Component} this
15539 * @param {Number} adjWidth The box-adjusted width that was set
15540 * @param {Number} adjHeight The box-adjusted height that was set
15541 * @param {Number} rawWidth The width that was originally specified
15542 * @param {Number} rawHeight The height that was originally specified
15547 * Fires after the component is moved.
15548 * @param {Roo.Component} this
15549 * @param {Number} x The new x position
15550 * @param {Number} y The new y position
15556 Roo.extend(Roo.BoxComponent, Roo.Component, {
15557 // private, set in afterRender to signify that the component has been rendered
15559 // private, used to defer height settings to subclasses
15560 deferHeight: false,
15561 /** @cfg {Number} width
15562 * width (optional) size of component
15564 /** @cfg {Number} height
15565 * height (optional) size of component
15569 * Sets the width and height of the component. This method fires the resize event. This method can accept
15570 * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.
15571 * @param {Number/Object} width The new width to set, or a size object in the format {width, height}
15572 * @param {Number} height The new height to set (not required if a size object is passed as the first arg)
15573 * @return {Roo.BoxComponent} this
15575 setSize : function(w, h){
15576 // support for standard size objects
15577 if(typeof w == 'object'){
15582 if(!this.boxReady){
15588 // prevent recalcs when not needed
15589 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
15592 this.lastSize = {width: w, height: h};
15594 var adj = this.adjustSize(w, h);
15595 var aw = adj.width, ah = adj.height;
15596 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
15597 var rz = this.getResizeEl();
15598 if(!this.deferHeight && aw !== undefined && ah !== undefined){
15599 rz.setSize(aw, ah);
15600 }else if(!this.deferHeight && ah !== undefined){
15602 }else if(aw !== undefined){
15605 this.onResize(aw, ah, w, h);
15606 this.fireEvent('resize', this, aw, ah, w, h);
15612 * Gets the current size of the component's underlying element.
15613 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
15615 getSize : function(){
15616 return this.el.getSize();
15620 * Gets the current XY position of the component's underlying element.
15621 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
15622 * @return {Array} The XY position of the element (e.g., [100, 200])
15624 getPosition : function(local){
15625 if(local === true){
15626 return [this.el.getLeft(true), this.el.getTop(true)];
15628 return this.xy || this.el.getXY();
15632 * Gets the current box measurements of the component's underlying element.
15633 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
15634 * @returns {Object} box An object in the format {x, y, width, height}
15636 getBox : function(local){
15637 var s = this.el.getSize();
15639 s.x = this.el.getLeft(true);
15640 s.y = this.el.getTop(true);
15642 var xy = this.xy || this.el.getXY();
15650 * Sets the current box measurements of the component's underlying element.
15651 * @param {Object} box An object in the format {x, y, width, height}
15652 * @returns {Roo.BoxComponent} this
15654 updateBox : function(box){
15655 this.setSize(box.width, box.height);
15656 this.setPagePosition(box.x, box.y);
15661 getResizeEl : function(){
15662 return this.resizeEl || this.el;
15666 getPositionEl : function(){
15667 return this.positionEl || this.el;
15671 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
15672 * This method fires the move event.
15673 * @param {Number} left The new left
15674 * @param {Number} top The new top
15675 * @returns {Roo.BoxComponent} this
15677 setPosition : function(x, y){
15680 if(!this.boxReady){
15683 var adj = this.adjustPosition(x, y);
15684 var ax = adj.x, ay = adj.y;
15686 var el = this.getPositionEl();
15687 if(ax !== undefined || ay !== undefined){
15688 if(ax !== undefined && ay !== undefined){
15689 el.setLeftTop(ax, ay);
15690 }else if(ax !== undefined){
15692 }else if(ay !== undefined){
15695 this.onPosition(ax, ay);
15696 this.fireEvent('move', this, ax, ay);
15702 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
15703 * This method fires the move event.
15704 * @param {Number} x The new x position
15705 * @param {Number} y The new y position
15706 * @returns {Roo.BoxComponent} this
15708 setPagePosition : function(x, y){
15711 if(!this.boxReady){
15714 if(x === undefined || y === undefined){ // cannot translate undefined points
15717 var p = this.el.translatePoints(x, y);
15718 this.setPosition(p.left, p.top);
15723 onRender : function(ct, position){
15724 Roo.BoxComponent.superclass.onRender.call(this, ct, position);
15726 this.resizeEl = Roo.get(this.resizeEl);
15728 if(this.positionEl){
15729 this.positionEl = Roo.get(this.positionEl);
15734 afterRender : function(){
15735 Roo.BoxComponent.superclass.afterRender.call(this);
15736 this.boxReady = true;
15737 this.setSize(this.width, this.height);
15738 if(this.x || this.y){
15739 this.setPosition(this.x, this.y);
15741 if(this.pageX || this.pageY){
15742 this.setPagePosition(this.pageX, this.pageY);
15747 * Force the component's size to recalculate based on the underlying element's current height and width.
15748 * @returns {Roo.BoxComponent} this
15750 syncSize : function(){
15751 delete this.lastSize;
15752 this.setSize(this.el.getWidth(), this.el.getHeight());
15757 * Called after the component is resized, this method is empty by default but can be implemented by any
15758 * subclass that needs to perform custom logic after a resize occurs.
15759 * @param {Number} adjWidth The box-adjusted width that was set
15760 * @param {Number} adjHeight The box-adjusted height that was set
15761 * @param {Number} rawWidth The width that was originally specified
15762 * @param {Number} rawHeight The height that was originally specified
15764 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
15769 * Called after the component is moved, this method is empty by default but can be implemented by any
15770 * subclass that needs to perform custom logic after a move occurs.
15771 * @param {Number} x The new x position
15772 * @param {Number} y The new y position
15774 onPosition : function(x, y){
15779 adjustSize : function(w, h){
15780 if(this.autoWidth){
15783 if(this.autoHeight){
15786 return {width : w, height: h};
15790 adjustPosition : function(x, y){
15791 return {x : x, y: y};
15794 * Original code for Roojs - LGPL
15795 * <script type="text/javascript">
15799 * @class Roo.XComponent
15800 * A delayed Element creator...
15801 * Or a way to group chunks of interface together.
15802 * technically this is a wrapper around a tree of Roo elements (which defines a 'module'),
15803 * used in conjunction with XComponent.build() it will create an instance of each element,
15804 * then call addxtype() to build the User interface.
15806 * Mypart.xyx = new Roo.XComponent({
15808 parent : 'Mypart.xyz', // empty == document.element.!!
15812 disabled : function() {}
15814 tree : function() { // return an tree of xtype declared components
15818 xtype : 'NestedLayoutPanel',
15825 * It can be used to build a big heiracy, with parent etc.
15826 * or you can just use this to render a single compoent to a dom element
15827 * MYPART.render(Roo.Element | String(id) | dom_element )
15834 * Roo is designed primarily as a single page application, so the UI build for a standard interface will
15835 * expect a single 'TOP' level module normally indicated by the 'parent' of the XComponent definition being defined as false.
15837 * Each sub module is expected to have a parent pointing to the class name of it's parent module.
15839 * When the top level is false, a 'Roo.BorderLayout' is created and the element is flagged as 'topModule'
15840 * - if mulitple topModules exist, the last one is defined as the top module.
15844 * When the top level or multiple modules are to embedded into a existing HTML page,
15845 * the parent element can container '#id' of the element where the module will be drawn.
15849 * Unlike classic Roo, the bootstrap tends not to be used as a single page.
15850 * it relies more on a include mechanism, where sub modules are included into an outer page.
15851 * This is normally managed by the builder tools using Roo.apply( options, Included.Sub.Module )
15853 * Bootstrap Roo Included elements
15855 * Our builder application needs the ability to preview these sub compoennts. They will normally have parent=false set,
15856 * hence confusing the component builder as it thinks there are multiple top level elements.
15860 * @extends Roo.util.Observable
15862 * @param cfg {Object} configuration of component
15865 Roo.XComponent = function(cfg) {
15866 Roo.apply(this, cfg);
15870 * Fires when this the componnt is built
15871 * @param {Roo.XComponent} c the component
15876 this.region = this.region || 'center'; // default..
15877 Roo.XComponent.register(this);
15878 this.modules = false;
15879 this.el = false; // where the layout goes..
15883 Roo.extend(Roo.XComponent, Roo.util.Observable, {
15886 * The created element (with Roo.factory())
15887 * @type {Roo.Layout}
15893 * for BC - use el in new code
15894 * @type {Roo.Layout}
15900 * for BC - use el in new code
15901 * @type {Roo.Layout}
15906 * @cfg {Function|boolean} disabled
15907 * If this module is disabled by some rule, return true from the funtion
15912 * @cfg {String} parent
15913 * Name of parent element which it get xtype added to..
15918 * @cfg {String} order
15919 * Used to set the order in which elements are created (usefull for multiple tabs)
15924 * @cfg {String} name
15925 * String to display while loading.
15929 * @cfg {String} region
15930 * Region to render component to (defaults to center)
15935 * @cfg {Array} items
15936 * A single item array - the first element is the root of the tree..
15937 * It's done this way to stay compatible with the Xtype system...
15943 * The method that retuns the tree of parts that make up this compoennt
15950 * render element to dom or tree
15951 * @param {Roo.Element|String|DomElement} optional render to if parent is not set.
15954 render : function(el)
15958 var hp = this.parent ? 1 : 0;
15959 Roo.debug && Roo.log(this);
15961 if (!el && typeof(this.parent) == 'string' && this.parent.substring(0,1) == '#') {
15962 // if parent is a '#.....' string, then let's use that..
15963 var ename = this.parent.substr(1);
15964 this.parent = false;
15965 Roo.debug && Roo.log(ename);
15967 case 'bootstrap-body' :
15968 if (typeof(Roo.bootstrap.Body) != 'undefined') {
15969 this.parent = { el : new Roo.bootstrap.Body() };
15970 Roo.debug && Roo.log("setting el to doc body");
15973 throw "Container is bootstrap body, but Roo.bootstrap.Body is not defined";
15977 this.parent = { el : true};
15980 el = Roo.get(ename);
15985 if (!el && !this.parent) {
15986 Roo.debug && Roo.log("Warning - element can not be found :#" + ename );
15990 Roo.debug && Roo.log("EL:");
15991 Roo.debug && Roo.log(el);
15992 Roo.debug && Roo.log("this.parent.el:");
15993 Roo.debug && Roo.log(this.parent.el);
15995 var tree = this._tree ? this._tree() : this.tree();
15997 // altertive root elements ??? - we need a better way to indicate these.
15998 var is_alt = (typeof(Roo.bootstrap) != 'undefined' && tree.xns == Roo.bootstrap) ||
15999 (typeof(Roo.mailer) != 'undefined' && tree.xns == Roo.mailer) ;
16001 if (!this.parent && is_alt) {
16002 //el = Roo.get(document.body);
16003 this.parent = { el : true };
16008 if (!this.parent) {
16010 Roo.debug && Roo.log("no parent - creating one");
16012 el = el ? Roo.get(el) : false;
16014 // it's a top level one..
16016 el : new Roo.BorderLayout(el || document.body, {
16022 tabPosition: 'top',
16023 //resizeTabs: true,
16024 alwaysShowTabs: el && hp? false : true,
16025 hideTabs: el || !hp ? true : false,
16032 if (!this.parent.el) {
16033 // probably an old style ctor, which has been disabled.
16037 // The 'tree' method is '_tree now'
16039 tree.region = tree.region || this.region;
16041 if (this.parent.el === true) {
16042 // bootstrap... - body..
16043 this.parent.el = Roo.factory(tree);
16046 this.el = this.parent.el.addxtype(tree);
16047 this.fireEvent('built', this);
16049 this.panel = this.el;
16050 this.layout = this.panel.layout;
16051 this.parentLayout = this.parent.layout || false;
16057 Roo.apply(Roo.XComponent, {
16059 * @property hideProgress
16060 * true to disable the building progress bar.. usefull on single page renders.
16063 hideProgress : false,
16065 * @property buildCompleted
16066 * True when the builder has completed building the interface.
16069 buildCompleted : false,
16072 * @property topModule
16073 * the upper most module - uses document.element as it's constructor.
16080 * @property modules
16081 * array of modules to be created by registration system.
16082 * @type {Array} of Roo.XComponent
16087 * @property elmodules
16088 * array of modules to be created by which use #ID
16089 * @type {Array} of Roo.XComponent
16095 * @property build_from_html
16096 * Build elements from html - used by bootstrap HTML stuff
16097 * - this is cleared after build is completed
16098 * @type {boolean} true (default false)
16101 build_from_html : false,
16104 * Register components to be built later.
16106 * This solves the following issues
16107 * - Building is not done on page load, but after an authentication process has occured.
16108 * - Interface elements are registered on page load
16109 * - Parent Interface elements may not be loaded before child, so this handles that..
16116 module : 'Pman.Tab.projectMgr',
16118 parent : 'Pman.layout',
16119 disabled : false, // or use a function..
16122 * * @param {Object} details about module
16124 register : function(obj) {
16126 Roo.XComponent.event.fireEvent('register', obj);
16127 switch(typeof(obj.disabled) ) {
16133 if ( obj.disabled() ) {
16139 if (obj.disabled) {
16145 this.modules.push(obj);
16149 * convert a string to an object..
16150 * eg. 'AAA.BBB' -> finds AAA.BBB
16154 toObject : function(str)
16156 if (!str || typeof(str) == 'object') {
16159 if (str.substring(0,1) == '#') {
16163 var ar = str.split('.');
16168 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
16170 throw "Module not found : " + str;
16174 throw "Module not found : " + str;
16176 Roo.each(ar, function(e) {
16177 if (typeof(o[e]) == 'undefined') {
16178 throw "Module not found : " + str;
16189 * move modules into their correct place in the tree..
16192 preBuild : function ()
16195 Roo.each(this.modules , function (obj)
16197 Roo.XComponent.event.fireEvent('beforebuild', obj);
16199 var opar = obj.parent;
16201 obj.parent = this.toObject(opar);
16203 Roo.debug && Roo.log("parent:toObject failed: " + e.toString());
16208 Roo.debug && Roo.log("GOT top level module");
16209 Roo.debug && Roo.log(obj);
16210 obj.modules = new Roo.util.MixedCollection(false,
16211 function(o) { return o.order + '' }
16213 this.topModule = obj;
16216 // parent is a string (usually a dom element name..)
16217 if (typeof(obj.parent) == 'string') {
16218 this.elmodules.push(obj);
16221 if (obj.parent.constructor != Roo.XComponent) {
16222 Roo.debug && Roo.log("Warning : Object Parent is not instance of XComponent:" + obj.name)
16224 if (!obj.parent.modules) {
16225 obj.parent.modules = new Roo.util.MixedCollection(false,
16226 function(o) { return o.order + '' }
16229 if (obj.parent.disabled) {
16230 obj.disabled = true;
16232 obj.parent.modules.add(obj);
16237 * make a list of modules to build.
16238 * @return {Array} list of modules.
16241 buildOrder : function()
16244 var cmp = function(a,b) {
16245 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
16247 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
16248 throw "No top level modules to build";
16251 // make a flat list in order of modules to build.
16252 var mods = this.topModule ? [ this.topModule ] : [];
16255 // elmodules (is a list of DOM based modules )
16256 Roo.each(this.elmodules, function(e) {
16258 if (!this.topModule &&
16259 typeof(e.parent) == 'string' &&
16260 e.parent.substring(0,1) == '#' &&
16261 Roo.get(e.parent.substr(1))
16264 _this.topModule = e;
16270 // add modules to their parents..
16271 var addMod = function(m) {
16272 Roo.debug && Roo.log("build Order: add: " + m.name);
16275 if (m.modules && !m.disabled) {
16276 Roo.debug && Roo.log("build Order: " + m.modules.length + " child modules");
16277 m.modules.keySort('ASC', cmp );
16278 Roo.debug && Roo.log("build Order: " + m.modules.length + " child modules (after sort)");
16280 m.modules.each(addMod);
16282 Roo.debug && Roo.log("build Order: no child modules");
16284 // not sure if this is used any more..
16286 m.finalize.name = m.name + " (clean up) ";
16287 mods.push(m.finalize);
16291 if (this.topModule && this.topModule.modules) {
16292 this.topModule.modules.keySort('ASC', cmp );
16293 this.topModule.modules.each(addMod);
16299 * Build the registered modules.
16300 * @param {Object} parent element.
16301 * @param {Function} optional method to call after module has been added.
16305 build : function(opts)
16308 if (typeof(opts) != 'undefined') {
16309 Roo.apply(this,opts);
16313 var mods = this.buildOrder();
16315 //this.allmods = mods;
16316 //Roo.debug && Roo.log(mods);
16318 if (!mods.length) { // should not happen
16319 throw "NO modules!!!";
16323 var msg = "Building Interface...";
16324 // flash it up as modal - so we store the mask!?
16325 if (!this.hideProgress && Roo.MessageBox) {
16326 Roo.MessageBox.show({ title: 'loading' });
16327 Roo.MessageBox.show({
16328 title: "Please wait...",
16337 var total = mods.length;
16340 var progressRun = function() {
16341 if (!mods.length) {
16342 Roo.debug && Roo.log('hide?');
16343 if (!this.hideProgress && Roo.MessageBox) {
16344 Roo.MessageBox.hide();
16346 Roo.XComponent.build_from_html = false; // reset, so dialogs will be build from javascript
16348 Roo.XComponent.event.fireEvent('buildcomplete', _this.topModule);
16354 var m = mods.shift();
16357 Roo.debug && Roo.log(m);
16358 // not sure if this is supported any more.. - modules that are are just function
16359 if (typeof(m) == 'function') {
16361 return progressRun.defer(10, _this);
16365 msg = "Building Interface " + (total - mods.length) +
16367 (m.name ? (' - ' + m.name) : '');
16368 Roo.debug && Roo.log(msg);
16369 if (!this.hideProgress && Roo.MessageBox) {
16370 Roo.MessageBox.updateProgress( (total - mods.length)/total, msg );
16374 // is the module disabled?
16375 var disabled = (typeof(m.disabled) == 'function') ?
16376 m.disabled.call(m.module.disabled) : m.disabled;
16380 return progressRun(); // we do not update the display!
16388 // it's 10 on top level, and 1 on others??? why...
16389 return progressRun.defer(10, _this);
16392 progressRun.defer(1, _this);
16406 * wrapper for event.on - aliased later..
16407 * Typically use to register a event handler for register:
16409 * eg. Roo.XComponent.on('register', function(comp) { comp.disable = true } );
16418 Roo.XComponent.event = new Roo.util.Observable({
16422 * Fires when an Component is registered,
16423 * set the disable property on the Component to stop registration.
16424 * @param {Roo.XComponent} c the component being registerd.
16429 * @event beforebuild
16430 * Fires before each Component is built
16431 * can be used to apply permissions.
16432 * @param {Roo.XComponent} c the component being registerd.
16435 'beforebuild' : true,
16437 * @event buildcomplete
16438 * Fires on the top level element when all elements have been built
16439 * @param {Roo.XComponent} the top level component.
16441 'buildcomplete' : true
16446 Roo.XComponent.on = Roo.XComponent.event.on.createDelegate(Roo.XComponent.event);
16449 * Ext JS Library 1.1.1
16450 * Copyright(c) 2006-2007, Ext JS, LLC.
16452 * Originally Released Under LGPL - original licence link has changed is not relivant.
16455 * <script type="text/javascript">
16461 * These classes are derivatives of the similarly named classes in the YUI Library.
16462 * The original license:
16463 * Copyright (c) 2006, Yahoo! Inc. All rights reserved.
16464 * Code licensed under the BSD License:
16465 * http://developer.yahoo.net/yui/license.txt
16470 var Event=Roo.EventManager;
16471 var Dom=Roo.lib.Dom;
16474 * @class Roo.dd.DragDrop
16475 * @extends Roo.util.Observable
16476 * Defines the interface and base operation of items that that can be
16477 * dragged or can be drop targets. It was designed to be extended, overriding
16478 * the event handlers for startDrag, onDrag, onDragOver and onDragOut.
16479 * Up to three html elements can be associated with a DragDrop instance:
16481 * <li>linked element: the element that is passed into the constructor.
16482 * This is the element which defines the boundaries for interaction with
16483 * other DragDrop objects.</li>
16484 * <li>handle element(s): The drag operation only occurs if the element that
16485 * was clicked matches a handle element. By default this is the linked
16486 * element, but there are times that you will want only a portion of the
16487 * linked element to initiate the drag operation, and the setHandleElId()
16488 * method provides a way to define this.</li>
16489 * <li>drag element: this represents the element that would be moved along
16490 * with the cursor during a drag operation. By default, this is the linked
16491 * element itself as in {@link Roo.dd.DD}. setDragElId() lets you define
16492 * a separate element that would be moved, as in {@link Roo.dd.DDProxy}.
16495 * This class should not be instantiated until the onload event to ensure that
16496 * the associated elements are available.
16497 * The following would define a DragDrop obj that would interact with any
16498 * other DragDrop obj in the "group1" group:
16500 * dd = new Roo.dd.DragDrop("div1", "group1");
16502 * Since none of the event handlers have been implemented, nothing would
16503 * actually happen if you were to run the code above. Normally you would
16504 * override this class or one of the default implementations, but you can
16505 * also override the methods you want on an instance of the class...
16507 * dd.onDragDrop = function(e, id) {
16508 * alert("dd was dropped on " + id);
16512 * @param {String} id of the element that is linked to this instance
16513 * @param {String} sGroup the group of related DragDrop objects
16514 * @param {object} config an object containing configurable attributes
16515 * Valid properties for DragDrop:
16516 * padding, isTarget, maintainOffset, primaryButtonOnly
16518 Roo.dd.DragDrop = function(id, sGroup, config) {
16520 this.init(id, sGroup, config);
16525 Roo.extend(Roo.dd.DragDrop, Roo.util.Observable , {
16528 * The id of the element associated with this object. This is what we
16529 * refer to as the "linked element" because the size and position of
16530 * this element is used to determine when the drag and drop objects have
16538 * Configuration attributes passed into the constructor
16545 * The id of the element that will be dragged. By default this is same
16546 * as the linked element , but could be changed to another element. Ex:
16548 * @property dragElId
16555 * the id of the element that initiates the drag operation. By default
16556 * this is the linked element, but could be changed to be a child of this
16557 * element. This lets us do things like only starting the drag when the
16558 * header element within the linked html element is clicked.
16559 * @property handleElId
16566 * An associative array of HTML tags that will be ignored if clicked.
16567 * @property invalidHandleTypes
16568 * @type {string: string}
16570 invalidHandleTypes: null,
16573 * An associative array of ids for elements that will be ignored if clicked
16574 * @property invalidHandleIds
16575 * @type {string: string}
16577 invalidHandleIds: null,
16580 * An indexted array of css class names for elements that will be ignored
16582 * @property invalidHandleClasses
16585 invalidHandleClasses: null,
16588 * The linked element's absolute X position at the time the drag was
16590 * @property startPageX
16597 * The linked element's absolute X position at the time the drag was
16599 * @property startPageY
16606 * The group defines a logical collection of DragDrop objects that are
16607 * related. Instances only get events when interacting with other
16608 * DragDrop object in the same group. This lets us define multiple
16609 * groups using a single DragDrop subclass if we want.
16611 * @type {string: string}
16616 * Individual drag/drop instances can be locked. This will prevent
16617 * onmousedown start drag.
16625 * Lock this instance
16628 lock: function() { this.locked = true; },
16631 * Unlock this instace
16634 unlock: function() { this.locked = false; },
16637 * By default, all insances can be a drop target. This can be disabled by
16638 * setting isTarget to false.
16645 * The padding configured for this drag and drop object for calculating
16646 * the drop zone intersection with this object.
16653 * Cached reference to the linked element
16654 * @property _domRef
16660 * Internal typeof flag
16661 * @property __ygDragDrop
16664 __ygDragDrop: true,
16667 * Set to true when horizontal contraints are applied
16668 * @property constrainX
16675 * Set to true when vertical contraints are applied
16676 * @property constrainY
16683 * The left constraint
16691 * The right constraint
16699 * The up constraint
16708 * The down constraint
16716 * Maintain offsets when we resetconstraints. Set to true when you want
16717 * the position of the element relative to its parent to stay the same
16718 * when the page changes
16720 * @property maintainOffset
16723 maintainOffset: false,
16726 * Array of pixel locations the element will snap to if we specified a
16727 * horizontal graduation/interval. This array is generated automatically
16728 * when you define a tick interval.
16735 * Array of pixel locations the element will snap to if we specified a
16736 * vertical graduation/interval. This array is generated automatically
16737 * when you define a tick interval.
16744 * By default the drag and drop instance will only respond to the primary
16745 * button click (left button for a right-handed mouse). Set to true to
16746 * allow drag and drop to start with any mouse click that is propogated
16748 * @property primaryButtonOnly
16751 primaryButtonOnly: true,
16754 * The availabe property is false until the linked dom element is accessible.
16755 * @property available
16761 * By default, drags can only be initiated if the mousedown occurs in the
16762 * region the linked element is. This is done in part to work around a
16763 * bug in some browsers that mis-report the mousedown if the previous
16764 * mouseup happened outside of the window. This property is set to true
16765 * if outer handles are defined.
16767 * @property hasOuterHandles
16771 hasOuterHandles: false,
16774 * Code that executes immediately before the startDrag event
16775 * @method b4StartDrag
16778 b4StartDrag: function(x, y) { },
16781 * Abstract method called after a drag/drop object is clicked
16782 * and the drag or mousedown time thresholds have beeen met.
16783 * @method startDrag
16784 * @param {int} X click location
16785 * @param {int} Y click location
16787 startDrag: function(x, y) { /* override this */ },
16790 * Code that executes immediately before the onDrag event
16794 b4Drag: function(e) { },
16797 * Abstract method called during the onMouseMove event while dragging an
16800 * @param {Event} e the mousemove event
16802 onDrag: function(e) { /* override this */ },
16805 * Abstract method called when this element fist begins hovering over
16806 * another DragDrop obj
16807 * @method onDragEnter
16808 * @param {Event} e the mousemove event
16809 * @param {String|DragDrop[]} id In POINT mode, the element
16810 * id this is hovering over. In INTERSECT mode, an array of one or more
16811 * dragdrop items being hovered over.
16813 onDragEnter: function(e, id) { /* override this */ },
16816 * Code that executes immediately before the onDragOver event
16817 * @method b4DragOver
16820 b4DragOver: function(e) { },
16823 * Abstract method called when this element is hovering over another
16825 * @method onDragOver
16826 * @param {Event} e the mousemove event
16827 * @param {String|DragDrop[]} id In POINT mode, the element
16828 * id this is hovering over. In INTERSECT mode, an array of dd items
16829 * being hovered over.
16831 onDragOver: function(e, id) { /* override this */ },
16834 * Code that executes immediately before the onDragOut event
16835 * @method b4DragOut
16838 b4DragOut: function(e) { },
16841 * Abstract method called when we are no longer hovering over an element
16842 * @method onDragOut
16843 * @param {Event} e the mousemove event
16844 * @param {String|DragDrop[]} id In POINT mode, the element
16845 * id this was hovering over. In INTERSECT mode, an array of dd items
16846 * that the mouse is no longer over.
16848 onDragOut: function(e, id) { /* override this */ },
16851 * Code that executes immediately before the onDragDrop event
16852 * @method b4DragDrop
16855 b4DragDrop: function(e) { },
16858 * Abstract method called when this item is dropped on another DragDrop
16860 * @method onDragDrop
16861 * @param {Event} e the mouseup event
16862 * @param {String|DragDrop[]} id In POINT mode, the element
16863 * id this was dropped on. In INTERSECT mode, an array of dd items this
16866 onDragDrop: function(e, id) { /* override this */ },
16869 * Abstract method called when this item is dropped on an area with no
16871 * @method onInvalidDrop
16872 * @param {Event} e the mouseup event
16874 onInvalidDrop: function(e) { /* override this */ },
16877 * Code that executes immediately before the endDrag event
16878 * @method b4EndDrag
16881 b4EndDrag: function(e) { },
16884 * Fired when we are done dragging the object
16886 * @param {Event} e the mouseup event
16888 endDrag: function(e) { /* override this */ },
16891 * Code executed immediately before the onMouseDown event
16892 * @method b4MouseDown
16893 * @param {Event} e the mousedown event
16896 b4MouseDown: function(e) { },
16899 * Event handler that fires when a drag/drop obj gets a mousedown
16900 * @method onMouseDown
16901 * @param {Event} e the mousedown event
16903 onMouseDown: function(e) { /* override this */ },
16906 * Event handler that fires when a drag/drop obj gets a mouseup
16907 * @method onMouseUp
16908 * @param {Event} e the mouseup event
16910 onMouseUp: function(e) { /* override this */ },
16913 * Override the onAvailable method to do what is needed after the initial
16914 * position was determined.
16915 * @method onAvailable
16917 onAvailable: function () {
16921 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
16924 defaultPadding : {left:0, right:0, top:0, bottom:0},
16927 * Initializes the drag drop object's constraints to restrict movement to a certain element.
16931 var dd = new Roo.dd.DDProxy("dragDiv1", "proxytest",
16932 { dragElId: "existingProxyDiv" });
16933 dd.startDrag = function(){
16934 this.constrainTo("parent-id");
16937 * Or you can initalize it using the {@link Roo.Element} object:
16939 Roo.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
16940 startDrag : function(){
16941 this.constrainTo("parent-id");
16945 * @param {String/HTMLElement/Element} constrainTo The element to constrain to.
16946 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
16947 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
16948 * an object containing the sides to pad. For example: {right:10, bottom:10}
16949 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
16951 constrainTo : function(constrainTo, pad, inContent){
16952 if(typeof pad == "number"){
16953 pad = {left: pad, right:pad, top:pad, bottom:pad};
16955 pad = pad || this.defaultPadding;
16956 var b = Roo.get(this.getEl()).getBox();
16957 var ce = Roo.get(constrainTo);
16958 var s = ce.getScroll();
16959 var c, cd = ce.dom;
16960 if(cd == document.body){
16961 c = { x: s.left, y: s.top, width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
16964 c = {x : xy[0]+s.left, y: xy[1]+s.top, width: cd.clientWidth, height: cd.clientHeight};
16968 var topSpace = b.y - c.y;
16969 var leftSpace = b.x - c.x;
16971 this.resetConstraints();
16972 this.setXConstraint(leftSpace - (pad.left||0), // left
16973 c.width - leftSpace - b.width - (pad.right||0) //right
16975 this.setYConstraint(topSpace - (pad.top||0), //top
16976 c.height - topSpace - b.height - (pad.bottom||0) //bottom
16981 * Returns a reference to the linked element
16983 * @return {HTMLElement} the html element
16985 getEl: function() {
16986 if (!this._domRef) {
16987 this._domRef = Roo.getDom(this.id);
16990 return this._domRef;
16994 * Returns a reference to the actual element to drag. By default this is
16995 * the same as the html element, but it can be assigned to another
16996 * element. An example of this can be found in Roo.dd.DDProxy
16997 * @method getDragEl
16998 * @return {HTMLElement} the html element
17000 getDragEl: function() {
17001 return Roo.getDom(this.dragElId);
17005 * Sets up the DragDrop object. Must be called in the constructor of any
17006 * Roo.dd.DragDrop subclass
17008 * @param id the id of the linked element
17009 * @param {String} sGroup the group of related items
17010 * @param {object} config configuration attributes
17012 init: function(id, sGroup, config) {
17013 this.initTarget(id, sGroup, config);
17014 if (!Roo.isTouch) {
17015 Event.on(this.id, "mousedown", this.handleMouseDown, this);
17017 Event.on(this.id, "touchstart", this.handleMouseDown, this);
17018 // Event.on(this.id, "selectstart", Event.preventDefault);
17022 * Initializes Targeting functionality only... the object does not
17023 * get a mousedown handler.
17024 * @method initTarget
17025 * @param id the id of the linked element
17026 * @param {String} sGroup the group of related items
17027 * @param {object} config configuration attributes
17029 initTarget: function(id, sGroup, config) {
17031 // configuration attributes
17032 this.config = config || {};
17034 // create a local reference to the drag and drop manager
17035 this.DDM = Roo.dd.DDM;
17036 // initialize the groups array
17039 // assume that we have an element reference instead of an id if the
17040 // parameter is not a string
17041 if (typeof id !== "string") {
17048 // add to an interaction group
17049 this.addToGroup((sGroup) ? sGroup : "default");
17051 // We don't want to register this as the handle with the manager
17052 // so we just set the id rather than calling the setter.
17053 this.handleElId = id;
17055 // the linked element is the element that gets dragged by default
17056 this.setDragElId(id);
17058 // by default, clicked anchors will not start drag operations.
17059 this.invalidHandleTypes = { A: "A" };
17060 this.invalidHandleIds = {};
17061 this.invalidHandleClasses = [];
17063 this.applyConfig();
17065 this.handleOnAvailable();
17069 * Applies the configuration parameters that were passed into the constructor.
17070 * This is supposed to happen at each level through the inheritance chain. So
17071 * a DDProxy implentation will execute apply config on DDProxy, DD, and
17072 * DragDrop in order to get all of the parameters that are available in
17074 * @method applyConfig
17076 applyConfig: function() {
17078 // configurable properties:
17079 // padding, isTarget, maintainOffset, primaryButtonOnly
17080 this.padding = this.config.padding || [0, 0, 0, 0];
17081 this.isTarget = (this.config.isTarget !== false);
17082 this.maintainOffset = (this.config.maintainOffset);
17083 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
17088 * Executed when the linked element is available
17089 * @method handleOnAvailable
17092 handleOnAvailable: function() {
17093 this.available = true;
17094 this.resetConstraints();
17095 this.onAvailable();
17099 * Configures the padding for the target zone in px. Effectively expands
17100 * (or reduces) the virtual object size for targeting calculations.
17101 * Supports css-style shorthand; if only one parameter is passed, all sides
17102 * will have that padding, and if only two are passed, the top and bottom
17103 * will have the first param, the left and right the second.
17104 * @method setPadding
17105 * @param {int} iTop Top pad
17106 * @param {int} iRight Right pad
17107 * @param {int} iBot Bot pad
17108 * @param {int} iLeft Left pad
17110 setPadding: function(iTop, iRight, iBot, iLeft) {
17111 // this.padding = [iLeft, iRight, iTop, iBot];
17112 if (!iRight && 0 !== iRight) {
17113 this.padding = [iTop, iTop, iTop, iTop];
17114 } else if (!iBot && 0 !== iBot) {
17115 this.padding = [iTop, iRight, iTop, iRight];
17117 this.padding = [iTop, iRight, iBot, iLeft];
17122 * Stores the initial placement of the linked element.
17123 * @method setInitialPosition
17124 * @param {int} diffX the X offset, default 0
17125 * @param {int} diffY the Y offset, default 0
17127 setInitPosition: function(diffX, diffY) {
17128 var el = this.getEl();
17130 if (!this.DDM.verifyEl(el)) {
17134 var dx = diffX || 0;
17135 var dy = diffY || 0;
17137 var p = Dom.getXY( el );
17139 this.initPageX = p[0] - dx;
17140 this.initPageY = p[1] - dy;
17142 this.lastPageX = p[0];
17143 this.lastPageY = p[1];
17146 this.setStartPosition(p);
17150 * Sets the start position of the element. This is set when the obj
17151 * is initialized, the reset when a drag is started.
17152 * @method setStartPosition
17153 * @param pos current position (from previous lookup)
17156 setStartPosition: function(pos) {
17157 var p = pos || Dom.getXY( this.getEl() );
17158 this.deltaSetXY = null;
17160 this.startPageX = p[0];
17161 this.startPageY = p[1];
17165 * Add this instance to a group of related drag/drop objects. All
17166 * instances belong to at least one group, and can belong to as many
17167 * groups as needed.
17168 * @method addToGroup
17169 * @param sGroup {string} the name of the group
17171 addToGroup: function(sGroup) {
17172 this.groups[sGroup] = true;
17173 this.DDM.regDragDrop(this, sGroup);
17177 * Remove's this instance from the supplied interaction group
17178 * @method removeFromGroup
17179 * @param {string} sGroup The group to drop
17181 removeFromGroup: function(sGroup) {
17182 if (this.groups[sGroup]) {
17183 delete this.groups[sGroup];
17186 this.DDM.removeDDFromGroup(this, sGroup);
17190 * Allows you to specify that an element other than the linked element
17191 * will be moved with the cursor during a drag
17192 * @method setDragElId
17193 * @param id {string} the id of the element that will be used to initiate the drag
17195 setDragElId: function(id) {
17196 this.dragElId = id;
17200 * Allows you to specify a child of the linked element that should be
17201 * used to initiate the drag operation. An example of this would be if
17202 * you have a content div with text and links. Clicking anywhere in the
17203 * content area would normally start the drag operation. Use this method
17204 * to specify that an element inside of the content div is the element
17205 * that starts the drag operation.
17206 * @method setHandleElId
17207 * @param id {string} the id of the element that will be used to
17208 * initiate the drag.
17210 setHandleElId: function(id) {
17211 if (typeof id !== "string") {
17214 this.handleElId = id;
17215 this.DDM.regHandle(this.id, id);
17219 * Allows you to set an element outside of the linked element as a drag
17221 * @method setOuterHandleElId
17222 * @param id the id of the element that will be used to initiate the drag
17224 setOuterHandleElId: function(id) {
17225 if (typeof id !== "string") {
17228 Event.on(id, "mousedown",
17229 this.handleMouseDown, this);
17230 this.setHandleElId(id);
17232 this.hasOuterHandles = true;
17236 * Remove all drag and drop hooks for this element
17239 unreg: function() {
17240 Event.un(this.id, "mousedown",
17241 this.handleMouseDown);
17242 Event.un(this.id, "touchstart",
17243 this.handleMouseDown);
17244 this._domRef = null;
17245 this.DDM._remove(this);
17248 destroy : function(){
17253 * Returns true if this instance is locked, or the drag drop mgr is locked
17254 * (meaning that all drag/drop is disabled on the page.)
17256 * @return {boolean} true if this obj or all drag/drop is locked, else
17259 isLocked: function() {
17260 return (this.DDM.isLocked() || this.locked);
17264 * Fired when this object is clicked
17265 * @method handleMouseDown
17267 * @param {Roo.dd.DragDrop} oDD the clicked dd object (this dd obj)
17270 handleMouseDown: function(e, oDD){
17272 if (!Roo.isTouch && this.primaryButtonOnly && e.button != 0) {
17273 //Roo.log('not touch/ button !=0');
17276 if (e.browserEvent.touches && e.browserEvent.touches.length != 1) {
17277 return; // double touch..
17281 if (this.isLocked()) {
17282 //Roo.log('locked');
17286 this.DDM.refreshCache(this.groups);
17287 // Roo.log([Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e)]);
17288 var pt = new Roo.lib.Point(Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e));
17289 if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
17290 //Roo.log('no outer handes or not over target');
17293 // Roo.log('check validator');
17294 if (this.clickValidator(e)) {
17295 // Roo.log('validate success');
17296 // set the initial element position
17297 this.setStartPosition();
17300 this.b4MouseDown(e);
17301 this.onMouseDown(e);
17303 this.DDM.handleMouseDown(e, this);
17305 this.DDM.stopEvent(e);
17313 clickValidator: function(e) {
17314 var target = e.getTarget();
17315 return ( this.isValidHandleChild(target) &&
17316 (this.id == this.handleElId ||
17317 this.DDM.handleWasClicked(target, this.id)) );
17321 * Allows you to specify a tag name that should not start a drag operation
17322 * when clicked. This is designed to facilitate embedding links within a
17323 * drag handle that do something other than start the drag.
17324 * @method addInvalidHandleType
17325 * @param {string} tagName the type of element to exclude
17327 addInvalidHandleType: function(tagName) {
17328 var type = tagName.toUpperCase();
17329 this.invalidHandleTypes[type] = type;
17333 * Lets you to specify an element id for a child of a drag handle
17334 * that should not initiate a drag
17335 * @method addInvalidHandleId
17336 * @param {string} id the element id of the element you wish to ignore
17338 addInvalidHandleId: function(id) {
17339 if (typeof id !== "string") {
17342 this.invalidHandleIds[id] = id;
17346 * Lets you specify a css class of elements that will not initiate a drag
17347 * @method addInvalidHandleClass
17348 * @param {string} cssClass the class of the elements you wish to ignore
17350 addInvalidHandleClass: function(cssClass) {
17351 this.invalidHandleClasses.push(cssClass);
17355 * Unsets an excluded tag name set by addInvalidHandleType
17356 * @method removeInvalidHandleType
17357 * @param {string} tagName the type of element to unexclude
17359 removeInvalidHandleType: function(tagName) {
17360 var type = tagName.toUpperCase();
17361 // this.invalidHandleTypes[type] = null;
17362 delete this.invalidHandleTypes[type];
17366 * Unsets an invalid handle id
17367 * @method removeInvalidHandleId
17368 * @param {string} id the id of the element to re-enable
17370 removeInvalidHandleId: function(id) {
17371 if (typeof id !== "string") {
17374 delete this.invalidHandleIds[id];
17378 * Unsets an invalid css class
17379 * @method removeInvalidHandleClass
17380 * @param {string} cssClass the class of the element(s) you wish to
17383 removeInvalidHandleClass: function(cssClass) {
17384 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
17385 if (this.invalidHandleClasses[i] == cssClass) {
17386 delete this.invalidHandleClasses[i];
17392 * Checks the tag exclusion list to see if this click should be ignored
17393 * @method isValidHandleChild
17394 * @param {HTMLElement} node the HTMLElement to evaluate
17395 * @return {boolean} true if this is a valid tag type, false if not
17397 isValidHandleChild: function(node) {
17400 // var n = (node.nodeName == "#text") ? node.parentNode : node;
17403 nodeName = node.nodeName.toUpperCase();
17405 nodeName = node.nodeName;
17407 valid = valid && !this.invalidHandleTypes[nodeName];
17408 valid = valid && !this.invalidHandleIds[node.id];
17410 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
17411 valid = !Dom.hasClass(node, this.invalidHandleClasses[i]);
17420 * Create the array of horizontal tick marks if an interval was specified
17421 * in setXConstraint().
17422 * @method setXTicks
17425 setXTicks: function(iStartX, iTickSize) {
17427 this.xTickSize = iTickSize;
17431 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
17433 this.xTicks[this.xTicks.length] = i;
17438 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
17440 this.xTicks[this.xTicks.length] = i;
17445 this.xTicks.sort(this.DDM.numericSort) ;
17449 * Create the array of vertical tick marks if an interval was specified in
17450 * setYConstraint().
17451 * @method setYTicks
17454 setYTicks: function(iStartY, iTickSize) {
17456 this.yTickSize = iTickSize;
17460 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
17462 this.yTicks[this.yTicks.length] = i;
17467 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
17469 this.yTicks[this.yTicks.length] = i;
17474 this.yTicks.sort(this.DDM.numericSort) ;
17478 * By default, the element can be dragged any place on the screen. Use
17479 * this method to limit the horizontal travel of the element. Pass in
17480 * 0,0 for the parameters if you want to lock the drag to the y axis.
17481 * @method setXConstraint
17482 * @param {int} iLeft the number of pixels the element can move to the left
17483 * @param {int} iRight the number of pixels the element can move to the
17485 * @param {int} iTickSize optional parameter for specifying that the
17487 * should move iTickSize pixels at a time.
17489 setXConstraint: function(iLeft, iRight, iTickSize) {
17490 this.leftConstraint = iLeft;
17491 this.rightConstraint = iRight;
17493 this.minX = this.initPageX - iLeft;
17494 this.maxX = this.initPageX + iRight;
17495 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
17497 this.constrainX = true;
17501 * Clears any constraints applied to this instance. Also clears ticks
17502 * since they can't exist independent of a constraint at this time.
17503 * @method clearConstraints
17505 clearConstraints: function() {
17506 this.constrainX = false;
17507 this.constrainY = false;
17512 * Clears any tick interval defined for this instance
17513 * @method clearTicks
17515 clearTicks: function() {
17516 this.xTicks = null;
17517 this.yTicks = null;
17518 this.xTickSize = 0;
17519 this.yTickSize = 0;
17523 * By default, the element can be dragged any place on the screen. Set
17524 * this to limit the vertical travel of the element. Pass in 0,0 for the
17525 * parameters if you want to lock the drag to the x axis.
17526 * @method setYConstraint
17527 * @param {int} iUp the number of pixels the element can move up
17528 * @param {int} iDown the number of pixels the element can move down
17529 * @param {int} iTickSize optional parameter for specifying that the
17530 * element should move iTickSize pixels at a time.
17532 setYConstraint: function(iUp, iDown, iTickSize) {
17533 this.topConstraint = iUp;
17534 this.bottomConstraint = iDown;
17536 this.minY = this.initPageY - iUp;
17537 this.maxY = this.initPageY + iDown;
17538 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
17540 this.constrainY = true;
17545 * resetConstraints must be called if you manually reposition a dd element.
17546 * @method resetConstraints
17547 * @param {boolean} maintainOffset
17549 resetConstraints: function() {
17552 // Maintain offsets if necessary
17553 if (this.initPageX || this.initPageX === 0) {
17554 // figure out how much this thing has moved
17555 var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
17556 var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
17558 this.setInitPosition(dx, dy);
17560 // This is the first time we have detected the element's position
17562 this.setInitPosition();
17565 if (this.constrainX) {
17566 this.setXConstraint( this.leftConstraint,
17567 this.rightConstraint,
17571 if (this.constrainY) {
17572 this.setYConstraint( this.topConstraint,
17573 this.bottomConstraint,
17579 * Normally the drag element is moved pixel by pixel, but we can specify
17580 * that it move a number of pixels at a time. This method resolves the
17581 * location when we have it set up like this.
17583 * @param {int} val where we want to place the object
17584 * @param {int[]} tickArray sorted array of valid points
17585 * @return {int} the closest tick
17588 getTick: function(val, tickArray) {
17591 // If tick interval is not defined, it is effectively 1 pixel,
17592 // so we return the value passed to us.
17594 } else if (tickArray[0] >= val) {
17595 // The value is lower than the first tick, so we return the first
17597 return tickArray[0];
17599 for (var i=0, len=tickArray.length; i<len; ++i) {
17601 if (tickArray[next] && tickArray[next] >= val) {
17602 var diff1 = val - tickArray[i];
17603 var diff2 = tickArray[next] - val;
17604 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
17608 // The value is larger than the last tick, so we return the last
17610 return tickArray[tickArray.length - 1];
17617 * @return {string} string representation of the dd obj
17619 toString: function() {
17620 return ("DragDrop " + this.id);
17628 * Ext JS Library 1.1.1
17629 * Copyright(c) 2006-2007, Ext JS, LLC.
17631 * Originally Released Under LGPL - original licence link has changed is not relivant.
17634 * <script type="text/javascript">
17639 * The drag and drop utility provides a framework for building drag and drop
17640 * applications. In addition to enabling drag and drop for specific elements,
17641 * the drag and drop elements are tracked by the manager class, and the
17642 * interactions between the various elements are tracked during the drag and
17643 * the implementing code is notified about these important moments.
17646 // Only load the library once. Rewriting the manager class would orphan
17647 // existing drag and drop instances.
17648 if (!Roo.dd.DragDropMgr) {
17651 * @class Roo.dd.DragDropMgr
17652 * DragDropMgr is a singleton that tracks the element interaction for
17653 * all DragDrop items in the window. Generally, you will not call
17654 * this class directly, but it does have helper methods that could
17655 * be useful in your DragDrop implementations.
17658 Roo.dd.DragDropMgr = function() {
17660 var Event = Roo.EventManager;
17665 * Two dimensional Array of registered DragDrop objects. The first
17666 * dimension is the DragDrop item group, the second the DragDrop
17669 * @type {string: string}
17676 * Array of element ids defined as drag handles. Used to determine
17677 * if the element that generated the mousedown event is actually the
17678 * handle and not the html element itself.
17679 * @property handleIds
17680 * @type {string: string}
17687 * the DragDrop object that is currently being dragged
17688 * @property dragCurrent
17696 * the DragDrop object(s) that are being hovered over
17697 * @property dragOvers
17705 * the X distance between the cursor and the object being dragged
17714 * the Y distance between the cursor and the object being dragged
17723 * Flag to determine if we should prevent the default behavior of the
17724 * events we define. By default this is true, but this can be set to
17725 * false if you need the default behavior (not recommended)
17726 * @property preventDefault
17730 preventDefault: true,
17733 * Flag to determine if we should stop the propagation of the events
17734 * we generate. This is true by default but you may want to set it to
17735 * false if the html element contains other features that require the
17737 * @property stopPropagation
17741 stopPropagation: true,
17744 * Internal flag that is set to true when drag and drop has been
17746 * @property initialized
17753 * All drag and drop can be disabled.
17761 * Called the first time an element is registered.
17767 this.initialized = true;
17771 * In point mode, drag and drop interaction is defined by the
17772 * location of the cursor during the drag/drop
17780 * In intersect mode, drag and drop interactio nis defined by the
17781 * overlap of two or more drag and drop objects.
17782 * @property INTERSECT
17789 * The current drag and drop mode. Default: POINT
17797 * Runs method on all drag and drop objects
17798 * @method _execOnAll
17802 _execOnAll: function(sMethod, args) {
17803 for (var i in this.ids) {
17804 for (var j in this.ids[i]) {
17805 var oDD = this.ids[i][j];
17806 if (! this.isTypeOfDD(oDD)) {
17809 oDD[sMethod].apply(oDD, args);
17815 * Drag and drop initialization. Sets up the global event handlers
17820 _onLoad: function() {
17824 if (!Roo.isTouch) {
17825 Event.on(document, "mouseup", this.handleMouseUp, this, true);
17826 Event.on(document, "mousemove", this.handleMouseMove, this, true);
17828 Event.on(document, "touchend", this.handleMouseUp, this, true);
17829 Event.on(document, "touchmove", this.handleMouseMove, this, true);
17831 Event.on(window, "unload", this._onUnload, this, true);
17832 Event.on(window, "resize", this._onResize, this, true);
17833 // Event.on(window, "mouseout", this._test);
17838 * Reset constraints on all drag and drop objs
17839 * @method _onResize
17843 _onResize: function(e) {
17844 this._execOnAll("resetConstraints", []);
17848 * Lock all drag and drop functionality
17852 lock: function() { this.locked = true; },
17855 * Unlock all drag and drop functionality
17859 unlock: function() { this.locked = false; },
17862 * Is drag and drop locked?
17864 * @return {boolean} True if drag and drop is locked, false otherwise.
17867 isLocked: function() { return this.locked; },
17870 * Location cache that is set for all drag drop objects when a drag is
17871 * initiated, cleared when the drag is finished.
17872 * @property locationCache
17879 * Set useCache to false if you want to force object the lookup of each
17880 * drag and drop linked element constantly during a drag.
17881 * @property useCache
17888 * The number of pixels that the mouse needs to move after the
17889 * mousedown before the drag is initiated. Default=3;
17890 * @property clickPixelThresh
17894 clickPixelThresh: 3,
17897 * The number of milliseconds after the mousedown event to initiate the
17898 * drag if we don't get a mouseup event. Default=1000
17899 * @property clickTimeThresh
17903 clickTimeThresh: 350,
17906 * Flag that indicates that either the drag pixel threshold or the
17907 * mousdown time threshold has been met
17908 * @property dragThreshMet
17913 dragThreshMet: false,
17916 * Timeout used for the click time threshold
17917 * @property clickTimeout
17922 clickTimeout: null,
17925 * The X position of the mousedown event stored for later use when a
17926 * drag threshold is met.
17935 * The Y position of the mousedown event stored for later use when a
17936 * drag threshold is met.
17945 * Each DragDrop instance must be registered with the DragDropMgr.
17946 * This is executed in DragDrop.init()
17947 * @method regDragDrop
17948 * @param {DragDrop} oDD the DragDrop object to register
17949 * @param {String} sGroup the name of the group this element belongs to
17952 regDragDrop: function(oDD, sGroup) {
17953 if (!this.initialized) { this.init(); }
17955 if (!this.ids[sGroup]) {
17956 this.ids[sGroup] = {};
17958 this.ids[sGroup][oDD.id] = oDD;
17962 * Removes the supplied dd instance from the supplied group. Executed
17963 * by DragDrop.removeFromGroup, so don't call this function directly.
17964 * @method removeDDFromGroup
17968 removeDDFromGroup: function(oDD, sGroup) {
17969 if (!this.ids[sGroup]) {
17970 this.ids[sGroup] = {};
17973 var obj = this.ids[sGroup];
17974 if (obj && obj[oDD.id]) {
17975 delete obj[oDD.id];
17980 * Unregisters a drag and drop item. This is executed in
17981 * DragDrop.unreg, use that method instead of calling this directly.
17986 _remove: function(oDD) {
17987 for (var g in oDD.groups) {
17988 if (g && this.ids[g][oDD.id]) {
17989 delete this.ids[g][oDD.id];
17992 delete this.handleIds[oDD.id];
17996 * Each DragDrop handle element must be registered. This is done
17997 * automatically when executing DragDrop.setHandleElId()
17998 * @method regHandle
17999 * @param {String} sDDId the DragDrop id this element is a handle for
18000 * @param {String} sHandleId the id of the element that is the drag
18004 regHandle: function(sDDId, sHandleId) {
18005 if (!this.handleIds[sDDId]) {
18006 this.handleIds[sDDId] = {};
18008 this.handleIds[sDDId][sHandleId] = sHandleId;
18012 * Utility function to determine if a given element has been
18013 * registered as a drag drop item.
18014 * @method isDragDrop
18015 * @param {String} id the element id to check
18016 * @return {boolean} true if this element is a DragDrop item,
18020 isDragDrop: function(id) {
18021 return ( this.getDDById(id) ) ? true : false;
18025 * Returns the drag and drop instances that are in all groups the
18026 * passed in instance belongs to.
18027 * @method getRelated
18028 * @param {DragDrop} p_oDD the obj to get related data for
18029 * @param {boolean} bTargetsOnly if true, only return targetable objs
18030 * @return {DragDrop[]} the related instances
18033 getRelated: function(p_oDD, bTargetsOnly) {
18035 for (var i in p_oDD.groups) {
18036 for (j in this.ids[i]) {
18037 var dd = this.ids[i][j];
18038 if (! this.isTypeOfDD(dd)) {
18041 if (!bTargetsOnly || dd.isTarget) {
18042 oDDs[oDDs.length] = dd;
18051 * Returns true if the specified dd target is a legal target for
18052 * the specifice drag obj
18053 * @method isLegalTarget
18054 * @param {DragDrop} the drag obj
18055 * @param {DragDrop} the target
18056 * @return {boolean} true if the target is a legal target for the
18060 isLegalTarget: function (oDD, oTargetDD) {
18061 var targets = this.getRelated(oDD, true);
18062 for (var i=0, len=targets.length;i<len;++i) {
18063 if (targets[i].id == oTargetDD.id) {
18072 * My goal is to be able to transparently determine if an object is
18073 * typeof DragDrop, and the exact subclass of DragDrop. typeof
18074 * returns "object", oDD.constructor.toString() always returns
18075 * "DragDrop" and not the name of the subclass. So for now it just
18076 * evaluates a well-known variable in DragDrop.
18077 * @method isTypeOfDD
18078 * @param {Object} the object to evaluate
18079 * @return {boolean} true if typeof oDD = DragDrop
18082 isTypeOfDD: function (oDD) {
18083 return (oDD && oDD.__ygDragDrop);
18087 * Utility function to determine if a given element has been
18088 * registered as a drag drop handle for the given Drag Drop object.
18090 * @param {String} id the element id to check
18091 * @return {boolean} true if this element is a DragDrop handle, false
18095 isHandle: function(sDDId, sHandleId) {
18096 return ( this.handleIds[sDDId] &&
18097 this.handleIds[sDDId][sHandleId] );
18101 * Returns the DragDrop instance for a given id
18102 * @method getDDById
18103 * @param {String} id the id of the DragDrop object
18104 * @return {DragDrop} the drag drop object, null if it is not found
18107 getDDById: function(id) {
18108 for (var i in this.ids) {
18109 if (this.ids[i][id]) {
18110 return this.ids[i][id];
18117 * Fired after a registered DragDrop object gets the mousedown event.
18118 * Sets up the events required to track the object being dragged
18119 * @method handleMouseDown
18120 * @param {Event} e the event
18121 * @param oDD the DragDrop object being dragged
18125 handleMouseDown: function(e, oDD) {
18127 Roo.QuickTips.disable();
18129 this.currentTarget = e.getTarget();
18131 this.dragCurrent = oDD;
18133 var el = oDD.getEl();
18135 // track start position
18136 this.startX = e.getPageX();
18137 this.startY = e.getPageY();
18139 this.deltaX = this.startX - el.offsetLeft;
18140 this.deltaY = this.startY - el.offsetTop;
18142 this.dragThreshMet = false;
18144 this.clickTimeout = setTimeout(
18146 var DDM = Roo.dd.DDM;
18147 DDM.startDrag(DDM.startX, DDM.startY);
18149 this.clickTimeThresh );
18153 * Fired when either the drag pixel threshol or the mousedown hold
18154 * time threshold has been met.
18155 * @method startDrag
18156 * @param x {int} the X position of the original mousedown
18157 * @param y {int} the Y position of the original mousedown
18160 startDrag: function(x, y) {
18161 clearTimeout(this.clickTimeout);
18162 if (this.dragCurrent) {
18163 this.dragCurrent.b4StartDrag(x, y);
18164 this.dragCurrent.startDrag(x, y);
18166 this.dragThreshMet = true;
18170 * Internal function to handle the mouseup event. Will be invoked
18171 * from the context of the document.
18172 * @method handleMouseUp
18173 * @param {Event} e the event
18177 handleMouseUp: function(e) {
18180 Roo.QuickTips.enable();
18182 if (! this.dragCurrent) {
18186 clearTimeout(this.clickTimeout);
18188 if (this.dragThreshMet) {
18189 this.fireEvents(e, true);
18199 * Utility to stop event propagation and event default, if these
18200 * features are turned on.
18201 * @method stopEvent
18202 * @param {Event} e the event as returned by this.getEvent()
18205 stopEvent: function(e){
18206 if(this.stopPropagation) {
18207 e.stopPropagation();
18210 if (this.preventDefault) {
18211 e.preventDefault();
18216 * Internal function to clean up event handlers after the drag
18217 * operation is complete
18219 * @param {Event} e the event
18223 stopDrag: function(e) {
18224 // Fire the drag end event for the item that was dragged
18225 if (this.dragCurrent) {
18226 if (this.dragThreshMet) {
18227 this.dragCurrent.b4EndDrag(e);
18228 this.dragCurrent.endDrag(e);
18231 this.dragCurrent.onMouseUp(e);
18234 this.dragCurrent = null;
18235 this.dragOvers = {};
18239 * Internal function to handle the mousemove event. Will be invoked
18240 * from the context of the html element.
18242 * @TODO figure out what we can do about mouse events lost when the
18243 * user drags objects beyond the window boundary. Currently we can
18244 * detect this in internet explorer by verifying that the mouse is
18245 * down during the mousemove event. Firefox doesn't give us the
18246 * button state on the mousemove event.
18247 * @method handleMouseMove
18248 * @param {Event} e the event
18252 handleMouseMove: function(e) {
18253 if (! this.dragCurrent) {
18257 // var button = e.which || e.button;
18259 // check for IE mouseup outside of page boundary
18260 if (Roo.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
18262 return this.handleMouseUp(e);
18265 if (!this.dragThreshMet) {
18266 var diffX = Math.abs(this.startX - e.getPageX());
18267 var diffY = Math.abs(this.startY - e.getPageY());
18268 if (diffX > this.clickPixelThresh ||
18269 diffY > this.clickPixelThresh) {
18270 this.startDrag(this.startX, this.startY);
18274 if (this.dragThreshMet) {
18275 this.dragCurrent.b4Drag(e);
18276 this.dragCurrent.onDrag(e);
18277 if(!this.dragCurrent.moveOnly){
18278 this.fireEvents(e, false);
18288 * Iterates over all of the DragDrop elements to find ones we are
18289 * hovering over or dropping on
18290 * @method fireEvents
18291 * @param {Event} e the event
18292 * @param {boolean} isDrop is this a drop op or a mouseover op?
18296 fireEvents: function(e, isDrop) {
18297 var dc = this.dragCurrent;
18299 // If the user did the mouse up outside of the window, we could
18300 // get here even though we have ended the drag.
18301 if (!dc || dc.isLocked()) {
18305 var pt = e.getPoint();
18307 // cache the previous dragOver array
18313 var enterEvts = [];
18315 // Check to see if the object(s) we were hovering over is no longer
18316 // being hovered over so we can fire the onDragOut event
18317 for (var i in this.dragOvers) {
18319 var ddo = this.dragOvers[i];
18321 if (! this.isTypeOfDD(ddo)) {
18325 if (! this.isOverTarget(pt, ddo, this.mode)) {
18326 outEvts.push( ddo );
18329 oldOvers[i] = true;
18330 delete this.dragOvers[i];
18333 for (var sGroup in dc.groups) {
18335 if ("string" != typeof sGroup) {
18339 for (i in this.ids[sGroup]) {
18340 var oDD = this.ids[sGroup][i];
18341 if (! this.isTypeOfDD(oDD)) {
18345 if (oDD.isTarget && !oDD.isLocked() && oDD != dc) {
18346 if (this.isOverTarget(pt, oDD, this.mode)) {
18347 // look for drop interactions
18349 dropEvts.push( oDD );
18350 // look for drag enter and drag over interactions
18353 // initial drag over: dragEnter fires
18354 if (!oldOvers[oDD.id]) {
18355 enterEvts.push( oDD );
18356 // subsequent drag overs: dragOver fires
18358 overEvts.push( oDD );
18361 this.dragOvers[oDD.id] = oDD;
18369 if (outEvts.length) {
18370 dc.b4DragOut(e, outEvts);
18371 dc.onDragOut(e, outEvts);
18374 if (enterEvts.length) {
18375 dc.onDragEnter(e, enterEvts);
18378 if (overEvts.length) {
18379 dc.b4DragOver(e, overEvts);
18380 dc.onDragOver(e, overEvts);
18383 if (dropEvts.length) {
18384 dc.b4DragDrop(e, dropEvts);
18385 dc.onDragDrop(e, dropEvts);
18389 // fire dragout events
18391 for (i=0, len=outEvts.length; i<len; ++i) {
18392 dc.b4DragOut(e, outEvts[i].id);
18393 dc.onDragOut(e, outEvts[i].id);
18396 // fire enter events
18397 for (i=0,len=enterEvts.length; i<len; ++i) {
18398 // dc.b4DragEnter(e, oDD.id);
18399 dc.onDragEnter(e, enterEvts[i].id);
18402 // fire over events
18403 for (i=0,len=overEvts.length; i<len; ++i) {
18404 dc.b4DragOver(e, overEvts[i].id);
18405 dc.onDragOver(e, overEvts[i].id);
18408 // fire drop events
18409 for (i=0, len=dropEvts.length; i<len; ++i) {
18410 dc.b4DragDrop(e, dropEvts[i].id);
18411 dc.onDragDrop(e, dropEvts[i].id);
18416 // notify about a drop that did not find a target
18417 if (isDrop && !dropEvts.length) {
18418 dc.onInvalidDrop(e);
18424 * Helper function for getting the best match from the list of drag
18425 * and drop objects returned by the drag and drop events when we are
18426 * in INTERSECT mode. It returns either the first object that the
18427 * cursor is over, or the object that has the greatest overlap with
18428 * the dragged element.
18429 * @method getBestMatch
18430 * @param {DragDrop[]} dds The array of drag and drop objects
18432 * @return {DragDrop} The best single match
18435 getBestMatch: function(dds) {
18437 // Return null if the input is not what we expect
18438 //if (!dds || !dds.length || dds.length == 0) {
18440 // If there is only one item, it wins
18441 //} else if (dds.length == 1) {
18443 var len = dds.length;
18448 // Loop through the targeted items
18449 for (var i=0; i<len; ++i) {
18451 // If the cursor is over the object, it wins. If the
18452 // cursor is over multiple matches, the first one we come
18454 if (dd.cursorIsOver) {
18457 // Otherwise the object with the most overlap wins
18460 winner.overlap.getArea() < dd.overlap.getArea()) {
18471 * Refreshes the cache of the top-left and bottom-right points of the
18472 * drag and drop objects in the specified group(s). This is in the
18473 * format that is stored in the drag and drop instance, so typical
18476 * Roo.dd.DragDropMgr.refreshCache(ddinstance.groups);
18480 * Roo.dd.DragDropMgr.refreshCache({group1:true, group2:true});
18482 * @TODO this really should be an indexed array. Alternatively this
18483 * method could accept both.
18484 * @method refreshCache
18485 * @param {Object} groups an associative array of groups to refresh
18488 refreshCache: function(groups) {
18489 for (var sGroup in groups) {
18490 if ("string" != typeof sGroup) {
18493 for (var i in this.ids[sGroup]) {
18494 var oDD = this.ids[sGroup][i];
18496 if (this.isTypeOfDD(oDD)) {
18497 // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
18498 var loc = this.getLocation(oDD);
18500 this.locationCache[oDD.id] = loc;
18502 delete this.locationCache[oDD.id];
18503 // this will unregister the drag and drop object if
18504 // the element is not in a usable state
18513 * This checks to make sure an element exists and is in the DOM. The
18514 * main purpose is to handle cases where innerHTML is used to remove
18515 * drag and drop objects from the DOM. IE provides an 'unspecified
18516 * error' when trying to access the offsetParent of such an element
18518 * @param {HTMLElement} el the element to check
18519 * @return {boolean} true if the element looks usable
18522 verifyEl: function(el) {
18527 parent = el.offsetParent;
18530 parent = el.offsetParent;
18541 * Returns a Region object containing the drag and drop element's position
18542 * and size, including the padding configured for it
18543 * @method getLocation
18544 * @param {DragDrop} oDD the drag and drop object to get the
18546 * @return {Roo.lib.Region} a Region object representing the total area
18547 * the element occupies, including any padding
18548 * the instance is configured for.
18551 getLocation: function(oDD) {
18552 if (! this.isTypeOfDD(oDD)) {
18556 var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
18559 pos= Roo.lib.Dom.getXY(el);
18567 x2 = x1 + el.offsetWidth;
18569 y2 = y1 + el.offsetHeight;
18571 t = y1 - oDD.padding[0];
18572 r = x2 + oDD.padding[1];
18573 b = y2 + oDD.padding[2];
18574 l = x1 - oDD.padding[3];
18576 return new Roo.lib.Region( t, r, b, l );
18580 * Checks the cursor location to see if it over the target
18581 * @method isOverTarget
18582 * @param {Roo.lib.Point} pt The point to evaluate
18583 * @param {DragDrop} oTarget the DragDrop object we are inspecting
18584 * @return {boolean} true if the mouse is over the target
18588 isOverTarget: function(pt, oTarget, intersect) {
18589 // use cache if available
18590 var loc = this.locationCache[oTarget.id];
18591 if (!loc || !this.useCache) {
18592 loc = this.getLocation(oTarget);
18593 this.locationCache[oTarget.id] = loc;
18601 oTarget.cursorIsOver = loc.contains( pt );
18603 // DragDrop is using this as a sanity check for the initial mousedown
18604 // in this case we are done. In POINT mode, if the drag obj has no
18605 // contraints, we are also done. Otherwise we need to evaluate the
18606 // location of the target as related to the actual location of the
18607 // dragged element.
18608 var dc = this.dragCurrent;
18609 if (!dc || !dc.getTargetCoord ||
18610 (!intersect && !dc.constrainX && !dc.constrainY)) {
18611 return oTarget.cursorIsOver;
18614 oTarget.overlap = null;
18616 // Get the current location of the drag element, this is the
18617 // location of the mouse event less the delta that represents
18618 // where the original mousedown happened on the element. We
18619 // need to consider constraints and ticks as well.
18620 var pos = dc.getTargetCoord(pt.x, pt.y);
18622 var el = dc.getDragEl();
18623 var curRegion = new Roo.lib.Region( pos.y,
18624 pos.x + el.offsetWidth,
18625 pos.y + el.offsetHeight,
18628 var overlap = curRegion.intersect(loc);
18631 oTarget.overlap = overlap;
18632 return (intersect) ? true : oTarget.cursorIsOver;
18639 * unload event handler
18640 * @method _onUnload
18644 _onUnload: function(e, me) {
18645 Roo.dd.DragDropMgr.unregAll();
18649 * Cleans up the drag and drop events and objects.
18654 unregAll: function() {
18656 if (this.dragCurrent) {
18658 this.dragCurrent = null;
18661 this._execOnAll("unreg", []);
18663 for (i in this.elementCache) {
18664 delete this.elementCache[i];
18667 this.elementCache = {};
18672 * A cache of DOM elements
18673 * @property elementCache
18680 * Get the wrapper for the DOM element specified
18681 * @method getElWrapper
18682 * @param {String} id the id of the element to get
18683 * @return {Roo.dd.DDM.ElementWrapper} the wrapped element
18685 * @deprecated This wrapper isn't that useful
18688 getElWrapper: function(id) {
18689 var oWrapper = this.elementCache[id];
18690 if (!oWrapper || !oWrapper.el) {
18691 oWrapper = this.elementCache[id] =
18692 new this.ElementWrapper(Roo.getDom(id));
18698 * Returns the actual DOM element
18699 * @method getElement
18700 * @param {String} id the id of the elment to get
18701 * @return {Object} The element
18702 * @deprecated use Roo.getDom instead
18705 getElement: function(id) {
18706 return Roo.getDom(id);
18710 * Returns the style property for the DOM element (i.e.,
18711 * document.getElById(id).style)
18713 * @param {String} id the id of the elment to get
18714 * @return {Object} The style property of the element
18715 * @deprecated use Roo.getDom instead
18718 getCss: function(id) {
18719 var el = Roo.getDom(id);
18720 return (el) ? el.style : null;
18724 * Inner class for cached elements
18725 * @class DragDropMgr.ElementWrapper
18730 ElementWrapper: function(el) {
18735 this.el = el || null;
18740 this.id = this.el && el.id;
18742 * A reference to the style property
18745 this.css = this.el && el.style;
18749 * Returns the X position of an html element
18751 * @param el the element for which to get the position
18752 * @return {int} the X coordinate
18754 * @deprecated use Roo.lib.Dom.getX instead
18757 getPosX: function(el) {
18758 return Roo.lib.Dom.getX(el);
18762 * Returns the Y position of an html element
18764 * @param el the element for which to get the position
18765 * @return {int} the Y coordinate
18766 * @deprecated use Roo.lib.Dom.getY instead
18769 getPosY: function(el) {
18770 return Roo.lib.Dom.getY(el);
18774 * Swap two nodes. In IE, we use the native method, for others we
18775 * emulate the IE behavior
18777 * @param n1 the first node to swap
18778 * @param n2 the other node to swap
18781 swapNode: function(n1, n2) {
18785 var p = n2.parentNode;
18786 var s = n2.nextSibling;
18789 p.insertBefore(n1, n2);
18790 } else if (n2 == n1.nextSibling) {
18791 p.insertBefore(n2, n1);
18793 n1.parentNode.replaceChild(n2, n1);
18794 p.insertBefore(n1, s);
18800 * Returns the current scroll position
18801 * @method getScroll
18805 getScroll: function () {
18806 var t, l, dde=document.documentElement, db=document.body;
18807 if (dde && (dde.scrollTop || dde.scrollLeft)) {
18809 l = dde.scrollLeft;
18816 return { top: t, left: l };
18820 * Returns the specified element style property
18822 * @param {HTMLElement} el the element
18823 * @param {string} styleProp the style property
18824 * @return {string} The value of the style property
18825 * @deprecated use Roo.lib.Dom.getStyle
18828 getStyle: function(el, styleProp) {
18829 return Roo.fly(el).getStyle(styleProp);
18833 * Gets the scrollTop
18834 * @method getScrollTop
18835 * @return {int} the document's scrollTop
18838 getScrollTop: function () { return this.getScroll().top; },
18841 * Gets the scrollLeft
18842 * @method getScrollLeft
18843 * @return {int} the document's scrollTop
18846 getScrollLeft: function () { return this.getScroll().left; },
18849 * Sets the x/y position of an element to the location of the
18852 * @param {HTMLElement} moveEl The element to move
18853 * @param {HTMLElement} targetEl The position reference element
18856 moveToEl: function (moveEl, targetEl) {
18857 var aCoord = Roo.lib.Dom.getXY(targetEl);
18858 Roo.lib.Dom.setXY(moveEl, aCoord);
18862 * Numeric array sort function
18863 * @method numericSort
18866 numericSort: function(a, b) { return (a - b); },
18870 * @property _timeoutCount
18877 * Trying to make the load order less important. Without this we get
18878 * an error if this file is loaded before the Event Utility.
18879 * @method _addListeners
18883 _addListeners: function() {
18884 var DDM = Roo.dd.DDM;
18885 if ( Roo.lib.Event && document ) {
18888 if (DDM._timeoutCount > 2000) {
18890 setTimeout(DDM._addListeners, 10);
18891 if (document && document.body) {
18892 DDM._timeoutCount += 1;
18899 * Recursively searches the immediate parent and all child nodes for
18900 * the handle element in order to determine wheter or not it was
18902 * @method handleWasClicked
18903 * @param node the html element to inspect
18906 handleWasClicked: function(node, id) {
18907 if (this.isHandle(id, node.id)) {
18910 // check to see if this is a text node child of the one we want
18911 var p = node.parentNode;
18914 if (this.isHandle(id, p.id)) {
18929 // shorter alias, save a few bytes
18930 Roo.dd.DDM = Roo.dd.DragDropMgr;
18931 Roo.dd.DDM._addListeners();
18935 * Ext JS Library 1.1.1
18936 * Copyright(c) 2006-2007, Ext JS, LLC.
18938 * Originally Released Under LGPL - original licence link has changed is not relivant.
18941 * <script type="text/javascript">
18946 * A DragDrop implementation where the linked element follows the
18947 * mouse cursor during a drag.
18948 * @extends Roo.dd.DragDrop
18950 * @param {String} id the id of the linked element
18951 * @param {String} sGroup the group of related DragDrop items
18952 * @param {object} config an object containing configurable attributes
18953 * Valid properties for DD:
18956 Roo.dd.DD = function(id, sGroup, config) {
18958 this.init(id, sGroup, config);
18962 Roo.extend(Roo.dd.DD, Roo.dd.DragDrop, {
18965 * When set to true, the utility automatically tries to scroll the browser
18966 * window wehn a drag and drop element is dragged near the viewport boundary.
18967 * Defaults to true.
18974 * Sets the pointer offset to the distance between the linked element's top
18975 * left corner and the location the element was clicked
18976 * @method autoOffset
18977 * @param {int} iPageX the X coordinate of the click
18978 * @param {int} iPageY the Y coordinate of the click
18980 autoOffset: function(iPageX, iPageY) {
18981 var x = iPageX - this.startPageX;
18982 var y = iPageY - this.startPageY;
18983 this.setDelta(x, y);
18987 * Sets the pointer offset. You can call this directly to force the
18988 * offset to be in a particular location (e.g., pass in 0,0 to set it
18989 * to the center of the object)
18991 * @param {int} iDeltaX the distance from the left
18992 * @param {int} iDeltaY the distance from the top
18994 setDelta: function(iDeltaX, iDeltaY) {
18995 this.deltaX = iDeltaX;
18996 this.deltaY = iDeltaY;
19000 * Sets the drag element to the location of the mousedown or click event,
19001 * maintaining the cursor location relative to the location on the element
19002 * that was clicked. Override this if you want to place the element in a
19003 * location other than where the cursor is.
19004 * @method setDragElPos
19005 * @param {int} iPageX the X coordinate of the mousedown or drag event
19006 * @param {int} iPageY the Y coordinate of the mousedown or drag event
19008 setDragElPos: function(iPageX, iPageY) {
19009 // the first time we do this, we are going to check to make sure
19010 // the element has css positioning
19012 var el = this.getDragEl();
19013 this.alignElWithMouse(el, iPageX, iPageY);
19017 * Sets the element to the location of the mousedown or click event,
19018 * maintaining the cursor location relative to the location on the element
19019 * that was clicked. Override this if you want to place the element in a
19020 * location other than where the cursor is.
19021 * @method alignElWithMouse
19022 * @param {HTMLElement} el the element to move
19023 * @param {int} iPageX the X coordinate of the mousedown or drag event
19024 * @param {int} iPageY the Y coordinate of the mousedown or drag event
19026 alignElWithMouse: function(el, iPageX, iPageY) {
19027 var oCoord = this.getTargetCoord(iPageX, iPageY);
19028 var fly = el.dom ? el : Roo.fly(el);
19029 if (!this.deltaSetXY) {
19030 var aCoord = [oCoord.x, oCoord.y];
19032 var newLeft = fly.getLeft(true);
19033 var newTop = fly.getTop(true);
19034 this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
19036 fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
19039 this.cachePosition(oCoord.x, oCoord.y);
19040 this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
19045 * Saves the most recent position so that we can reset the constraints and
19046 * tick marks on-demand. We need to know this so that we can calculate the
19047 * number of pixels the element is offset from its original position.
19048 * @method cachePosition
19049 * @param iPageX the current x position (optional, this just makes it so we
19050 * don't have to look it up again)
19051 * @param iPageY the current y position (optional, this just makes it so we
19052 * don't have to look it up again)
19054 cachePosition: function(iPageX, iPageY) {
19056 this.lastPageX = iPageX;
19057 this.lastPageY = iPageY;
19059 var aCoord = Roo.lib.Dom.getXY(this.getEl());
19060 this.lastPageX = aCoord[0];
19061 this.lastPageY = aCoord[1];
19066 * Auto-scroll the window if the dragged object has been moved beyond the
19067 * visible window boundary.
19068 * @method autoScroll
19069 * @param {int} x the drag element's x position
19070 * @param {int} y the drag element's y position
19071 * @param {int} h the height of the drag element
19072 * @param {int} w the width of the drag element
19075 autoScroll: function(x, y, h, w) {
19078 // The client height
19079 var clientH = Roo.lib.Dom.getViewWidth();
19081 // The client width
19082 var clientW = Roo.lib.Dom.getViewHeight();
19084 // The amt scrolled down
19085 var st = this.DDM.getScrollTop();
19087 // The amt scrolled right
19088 var sl = this.DDM.getScrollLeft();
19090 // Location of the bottom of the element
19093 // Location of the right of the element
19096 // The distance from the cursor to the bottom of the visible area,
19097 // adjusted so that we don't scroll if the cursor is beyond the
19098 // element drag constraints
19099 var toBot = (clientH + st - y - this.deltaY);
19101 // The distance from the cursor to the right of the visible area
19102 var toRight = (clientW + sl - x - this.deltaX);
19105 // How close to the edge the cursor must be before we scroll
19106 // var thresh = (document.all) ? 100 : 40;
19109 // How many pixels to scroll per autoscroll op. This helps to reduce
19110 // clunky scrolling. IE is more sensitive about this ... it needs this
19111 // value to be higher.
19112 var scrAmt = (document.all) ? 80 : 30;
19114 // Scroll down if we are near the bottom of the visible page and the
19115 // obj extends below the crease
19116 if ( bot > clientH && toBot < thresh ) {
19117 window.scrollTo(sl, st + scrAmt);
19120 // Scroll up if the window is scrolled down and the top of the object
19121 // goes above the top border
19122 if ( y < st && st > 0 && y - st < thresh ) {
19123 window.scrollTo(sl, st - scrAmt);
19126 // Scroll right if the obj is beyond the right border and the cursor is
19127 // near the border.
19128 if ( right > clientW && toRight < thresh ) {
19129 window.scrollTo(sl + scrAmt, st);
19132 // Scroll left if the window has been scrolled to the right and the obj
19133 // extends past the left border
19134 if ( x < sl && sl > 0 && x - sl < thresh ) {
19135 window.scrollTo(sl - scrAmt, st);
19141 * Finds the location the element should be placed if we want to move
19142 * it to where the mouse location less the click offset would place us.
19143 * @method getTargetCoord
19144 * @param {int} iPageX the X coordinate of the click
19145 * @param {int} iPageY the Y coordinate of the click
19146 * @return an object that contains the coordinates (Object.x and Object.y)
19149 getTargetCoord: function(iPageX, iPageY) {
19152 var x = iPageX - this.deltaX;
19153 var y = iPageY - this.deltaY;
19155 if (this.constrainX) {
19156 if (x < this.minX) { x = this.minX; }
19157 if (x > this.maxX) { x = this.maxX; }
19160 if (this.constrainY) {
19161 if (y < this.minY) { y = this.minY; }
19162 if (y > this.maxY) { y = this.maxY; }
19165 x = this.getTick(x, this.xTicks);
19166 y = this.getTick(y, this.yTicks);
19173 * Sets up config options specific to this class. Overrides
19174 * Roo.dd.DragDrop, but all versions of this method through the
19175 * inheritance chain are called
19177 applyConfig: function() {
19178 Roo.dd.DD.superclass.applyConfig.call(this);
19179 this.scroll = (this.config.scroll !== false);
19183 * Event that fires prior to the onMouseDown event. Overrides
19186 b4MouseDown: function(e) {
19187 // this.resetConstraints();
19188 this.autoOffset(e.getPageX(),
19193 * Event that fires prior to the onDrag event. Overrides
19196 b4Drag: function(e) {
19197 this.setDragElPos(e.getPageX(),
19201 toString: function() {
19202 return ("DD " + this.id);
19205 //////////////////////////////////////////////////////////////////////////
19206 // Debugging ygDragDrop events that can be overridden
19207 //////////////////////////////////////////////////////////////////////////
19209 startDrag: function(x, y) {
19212 onDrag: function(e) {
19215 onDragEnter: function(e, id) {
19218 onDragOver: function(e, id) {
19221 onDragOut: function(e, id) {
19224 onDragDrop: function(e, id) {
19227 endDrag: function(e) {
19234 * Ext JS Library 1.1.1
19235 * Copyright(c) 2006-2007, Ext JS, LLC.
19237 * Originally Released Under LGPL - original licence link has changed is not relivant.
19240 * <script type="text/javascript">
19244 * @class Roo.dd.DDProxy
19245 * A DragDrop implementation that inserts an empty, bordered div into
19246 * the document that follows the cursor during drag operations. At the time of
19247 * the click, the frame div is resized to the dimensions of the linked html
19248 * element, and moved to the exact location of the linked element.
19250 * References to the "frame" element refer to the single proxy element that
19251 * was created to be dragged in place of all DDProxy elements on the
19254 * @extends Roo.dd.DD
19256 * @param {String} id the id of the linked html element
19257 * @param {String} sGroup the group of related DragDrop objects
19258 * @param {object} config an object containing configurable attributes
19259 * Valid properties for DDProxy in addition to those in DragDrop:
19260 * resizeFrame, centerFrame, dragElId
19262 Roo.dd.DDProxy = function(id, sGroup, config) {
19264 this.init(id, sGroup, config);
19270 * The default drag frame div id
19271 * @property Roo.dd.DDProxy.dragElId
19275 Roo.dd.DDProxy.dragElId = "ygddfdiv";
19277 Roo.extend(Roo.dd.DDProxy, Roo.dd.DD, {
19280 * By default we resize the drag frame to be the same size as the element
19281 * we want to drag (this is to get the frame effect). We can turn it off
19282 * if we want a different behavior.
19283 * @property resizeFrame
19289 * By default the frame is positioned exactly where the drag element is, so
19290 * we use the cursor offset provided by Roo.dd.DD. Another option that works only if
19291 * you do not have constraints on the obj is to have the drag frame centered
19292 * around the cursor. Set centerFrame to true for this effect.
19293 * @property centerFrame
19296 centerFrame: false,
19299 * Creates the proxy element if it does not yet exist
19300 * @method createFrame
19302 createFrame: function() {
19304 var body = document.body;
19306 if (!body || !body.firstChild) {
19307 setTimeout( function() { self.createFrame(); }, 50 );
19311 var div = this.getDragEl();
19314 div = document.createElement("div");
19315 div.id = this.dragElId;
19318 s.position = "absolute";
19319 s.visibility = "hidden";
19321 s.border = "2px solid #aaa";
19324 // appendChild can blow up IE if invoked prior to the window load event
19325 // while rendering a table. It is possible there are other scenarios
19326 // that would cause this to happen as well.
19327 body.insertBefore(div, body.firstChild);
19332 * Initialization for the drag frame element. Must be called in the
19333 * constructor of all subclasses
19334 * @method initFrame
19336 initFrame: function() {
19337 this.createFrame();
19340 applyConfig: function() {
19341 Roo.dd.DDProxy.superclass.applyConfig.call(this);
19343 this.resizeFrame = (this.config.resizeFrame !== false);
19344 this.centerFrame = (this.config.centerFrame);
19345 this.setDragElId(this.config.dragElId || Roo.dd.DDProxy.dragElId);
19349 * Resizes the drag frame to the dimensions of the clicked object, positions
19350 * it over the object, and finally displays it
19351 * @method showFrame
19352 * @param {int} iPageX X click position
19353 * @param {int} iPageY Y click position
19356 showFrame: function(iPageX, iPageY) {
19357 var el = this.getEl();
19358 var dragEl = this.getDragEl();
19359 var s = dragEl.style;
19361 this._resizeProxy();
19363 if (this.centerFrame) {
19364 this.setDelta( Math.round(parseInt(s.width, 10)/2),
19365 Math.round(parseInt(s.height, 10)/2) );
19368 this.setDragElPos(iPageX, iPageY);
19370 Roo.fly(dragEl).show();
19374 * The proxy is automatically resized to the dimensions of the linked
19375 * element when a drag is initiated, unless resizeFrame is set to false
19376 * @method _resizeProxy
19379 _resizeProxy: function() {
19380 if (this.resizeFrame) {
19381 var el = this.getEl();
19382 Roo.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
19386 // overrides Roo.dd.DragDrop
19387 b4MouseDown: function(e) {
19388 var x = e.getPageX();
19389 var y = e.getPageY();
19390 this.autoOffset(x, y);
19391 this.setDragElPos(x, y);
19394 // overrides Roo.dd.DragDrop
19395 b4StartDrag: function(x, y) {
19396 // show the drag frame
19397 this.showFrame(x, y);
19400 // overrides Roo.dd.DragDrop
19401 b4EndDrag: function(e) {
19402 Roo.fly(this.getDragEl()).hide();
19405 // overrides Roo.dd.DragDrop
19406 // By default we try to move the element to the last location of the frame.
19407 // This is so that the default behavior mirrors that of Roo.dd.DD.
19408 endDrag: function(e) {
19410 var lel = this.getEl();
19411 var del = this.getDragEl();
19413 // Show the drag frame briefly so we can get its position
19414 del.style.visibility = "";
19417 // Hide the linked element before the move to get around a Safari
19419 lel.style.visibility = "hidden";
19420 Roo.dd.DDM.moveToEl(lel, del);
19421 del.style.visibility = "hidden";
19422 lel.style.visibility = "";
19427 beforeMove : function(){
19431 afterDrag : function(){
19435 toString: function() {
19436 return ("DDProxy " + this.id);
19442 * Ext JS Library 1.1.1
19443 * Copyright(c) 2006-2007, Ext JS, LLC.
19445 * Originally Released Under LGPL - original licence link has changed is not relivant.
19448 * <script type="text/javascript">
19452 * @class Roo.dd.DDTarget
19453 * A DragDrop implementation that does not move, but can be a drop
19454 * target. You would get the same result by simply omitting implementation
19455 * for the event callbacks, but this way we reduce the processing cost of the
19456 * event listener and the callbacks.
19457 * @extends Roo.dd.DragDrop
19459 * @param {String} id the id of the element that is a drop target
19460 * @param {String} sGroup the group of related DragDrop objects
19461 * @param {object} config an object containing configurable attributes
19462 * Valid properties for DDTarget in addition to those in
19466 Roo.dd.DDTarget = function(id, sGroup, config) {
19468 this.initTarget(id, sGroup, config);
19470 if (config.listeners || config.events) {
19471 Roo.dd.DragDrop.superclass.constructor.call(this, {
19472 listeners : config.listeners || {},
19473 events : config.events || {}
19478 // Roo.dd.DDTarget.prototype = new Roo.dd.DragDrop();
19479 Roo.extend(Roo.dd.DDTarget, Roo.dd.DragDrop, {
19480 toString: function() {
19481 return ("DDTarget " + this.id);
19486 * Ext JS Library 1.1.1
19487 * Copyright(c) 2006-2007, Ext JS, LLC.
19489 * Originally Released Under LGPL - original licence link has changed is not relivant.
19492 * <script type="text/javascript">
19497 * @class Roo.dd.ScrollManager
19498 * Provides automatic scrolling of overflow regions in the page during drag operations.<br><br>
19499 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
19502 Roo.dd.ScrollManager = function(){
19503 var ddm = Roo.dd.DragDropMgr;
19510 var onStop = function(e){
19515 var triggerRefresh = function(){
19516 if(ddm.dragCurrent){
19517 ddm.refreshCache(ddm.dragCurrent.groups);
19521 var doScroll = function(){
19522 if(ddm.dragCurrent){
19523 var dds = Roo.dd.ScrollManager;
19525 if(proc.el.scroll(proc.dir, dds.increment)){
19529 proc.el.scroll(proc.dir, dds.increment, true, dds.animDuration, triggerRefresh);
19534 var clearProc = function(){
19536 clearInterval(proc.id);
19543 var startProc = function(el, dir){
19544 Roo.log('scroll startproc');
19548 proc.id = setInterval(doScroll, Roo.dd.ScrollManager.frequency);
19551 var onFire = function(e, isDrop){
19553 if(isDrop || !ddm.dragCurrent){ return; }
19554 var dds = Roo.dd.ScrollManager;
19555 if(!dragEl || dragEl != ddm.dragCurrent){
19556 dragEl = ddm.dragCurrent;
19557 // refresh regions on drag start
19558 dds.refreshCache();
19561 var xy = Roo.lib.Event.getXY(e);
19562 var pt = new Roo.lib.Point(xy[0], xy[1]);
19563 for(var id in els){
19564 var el = els[id], r = el._region;
19565 if(r && r.contains(pt) && el.isScrollable()){
19566 if(r.bottom - pt.y <= dds.thresh){
19568 startProc(el, "down");
19571 }else if(r.right - pt.x <= dds.thresh){
19573 startProc(el, "left");
19576 }else if(pt.y - r.top <= dds.thresh){
19578 startProc(el, "up");
19581 }else if(pt.x - r.left <= dds.thresh){
19583 startProc(el, "right");
19592 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
19593 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
19597 * Registers new overflow element(s) to auto scroll
19598 * @param {String/HTMLElement/Element/Array} el The id of or the element to be scrolled or an array of either
19600 register : function(el){
19601 if(el instanceof Array){
19602 for(var i = 0, len = el.length; i < len; i++) {
19603 this.register(el[i]);
19609 Roo.dd.ScrollManager.els = els;
19613 * Unregisters overflow element(s) so they are no longer scrolled
19614 * @param {String/HTMLElement/Element/Array} el The id of or the element to be removed or an array of either
19616 unregister : function(el){
19617 if(el instanceof Array){
19618 for(var i = 0, len = el.length; i < len; i++) {
19619 this.unregister(el[i]);
19628 * The number of pixels from the edge of a container the pointer needs to be to
19629 * trigger scrolling (defaults to 25)
19635 * The number of pixels to scroll in each scroll increment (defaults to 50)
19641 * The frequency of scrolls in milliseconds (defaults to 500)
19647 * True to animate the scroll (defaults to true)
19653 * The animation duration in seconds -
19654 * MUST BE less than Roo.dd.ScrollManager.frequency! (defaults to .4)
19660 * Manually trigger a cache refresh.
19662 refreshCache : function(){
19663 for(var id in els){
19664 if(typeof els[id] == 'object'){ // for people extending the object prototype
19665 els[id]._region = els[id].getRegion();
19672 * Ext JS Library 1.1.1
19673 * Copyright(c) 2006-2007, Ext JS, LLC.
19675 * Originally Released Under LGPL - original licence link has changed is not relivant.
19678 * <script type="text/javascript">
19683 * @class Roo.dd.Registry
19684 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
19685 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
19688 Roo.dd.Registry = function(){
19691 var autoIdSeed = 0;
19693 var getId = function(el, autogen){
19694 if(typeof el == "string"){
19698 if(!id && autogen !== false){
19699 id = "roodd-" + (++autoIdSeed);
19707 * Register a drag drop element
19708 * @param {String|HTMLElement} element The id or DOM node to register
19709 * @param {Object} data (optional) A custom data object that will be passed between the elements that are involved
19710 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
19711 * knows how to interpret, plus there are some specific properties known to the Registry that should be
19712 * populated in the data object (if applicable):
19714 Value Description<br />
19715 --------- ------------------------------------------<br />
19716 handles Array of DOM nodes that trigger dragging<br />
19717 for the element being registered<br />
19718 isHandle True if the element passed in triggers<br />
19719 dragging itself, else false
19722 register : function(el, data){
19724 if(typeof el == "string"){
19725 el = document.getElementById(el);
19728 elements[getId(el)] = data;
19729 if(data.isHandle !== false){
19730 handles[data.ddel.id] = data;
19733 var hs = data.handles;
19734 for(var i = 0, len = hs.length; i < len; i++){
19735 handles[getId(hs[i])] = data;
19741 * Unregister a drag drop element
19742 * @param {String|HTMLElement} element The id or DOM node to unregister
19744 unregister : function(el){
19745 var id = getId(el, false);
19746 var data = elements[id];
19748 delete elements[id];
19750 var hs = data.handles;
19751 for(var i = 0, len = hs.length; i < len; i++){
19752 delete handles[getId(hs[i], false)];
19759 * Returns the handle registered for a DOM Node by id
19760 * @param {String|HTMLElement} id The DOM node or id to look up
19761 * @return {Object} handle The custom handle data
19763 getHandle : function(id){
19764 if(typeof id != "string"){ // must be element?
19767 return handles[id];
19771 * Returns the handle that is registered for the DOM node that is the target of the event
19772 * @param {Event} e The event
19773 * @return {Object} handle The custom handle data
19775 getHandleFromEvent : function(e){
19776 var t = Roo.lib.Event.getTarget(e);
19777 return t ? handles[t.id] : null;
19781 * Returns a custom data object that is registered for a DOM node by id
19782 * @param {String|HTMLElement} id The DOM node or id to look up
19783 * @return {Object} data The custom data
19785 getTarget : function(id){
19786 if(typeof id != "string"){ // must be element?
19789 return elements[id];
19793 * Returns a custom data object that is registered for the DOM node that is the target of the event
19794 * @param {Event} e The event
19795 * @return {Object} data The custom data
19797 getTargetFromEvent : function(e){
19798 var t = Roo.lib.Event.getTarget(e);
19799 return t ? elements[t.id] || handles[t.id] : null;
19804 * Ext JS Library 1.1.1
19805 * Copyright(c) 2006-2007, Ext JS, LLC.
19807 * Originally Released Under LGPL - original licence link has changed is not relivant.
19810 * <script type="text/javascript">
19815 * @class Roo.dd.StatusProxy
19816 * A specialized drag proxy that supports a drop status icon, {@link Roo.Layer} styles and auto-repair. This is the
19817 * default drag proxy used by all Roo.dd components.
19819 * @param {Object} config
19821 Roo.dd.StatusProxy = function(config){
19822 Roo.apply(this, config);
19823 this.id = this.id || Roo.id();
19824 this.el = new Roo.Layer({
19826 id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
19827 {tag: "div", cls: "x-dd-drop-icon"},
19828 {tag: "div", cls: "x-dd-drag-ghost"}
19831 shadow: !config || config.shadow !== false
19833 this.ghost = Roo.get(this.el.dom.childNodes[1]);
19834 this.dropStatus = this.dropNotAllowed;
19837 Roo.dd.StatusProxy.prototype = {
19839 * @cfg {String} dropAllowed
19840 * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
19842 dropAllowed : "x-dd-drop-ok",
19844 * @cfg {String} dropNotAllowed
19845 * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
19847 dropNotAllowed : "x-dd-drop-nodrop",
19850 * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
19851 * over the current target element.
19852 * @param {String} cssClass The css class for the new drop status indicator image
19854 setStatus : function(cssClass){
19855 cssClass = cssClass || this.dropNotAllowed;
19856 if(this.dropStatus != cssClass){
19857 this.el.replaceClass(this.dropStatus, cssClass);
19858 this.dropStatus = cssClass;
19863 * Resets the status indicator to the default dropNotAllowed value
19864 * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
19866 reset : function(clearGhost){
19867 this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
19868 this.dropStatus = this.dropNotAllowed;
19870 this.ghost.update("");
19875 * Updates the contents of the ghost element
19876 * @param {String} html The html that will replace the current innerHTML of the ghost element
19878 update : function(html){
19879 if(typeof html == "string"){
19880 this.ghost.update(html);
19882 this.ghost.update("");
19883 html.style.margin = "0";
19884 this.ghost.dom.appendChild(html);
19886 // ensure float = none set?? cant remember why though.
19887 var el = this.ghost.dom.firstChild;
19889 Roo.fly(el).setStyle('float', 'none');
19894 * Returns the underlying proxy {@link Roo.Layer}
19895 * @return {Roo.Layer} el
19897 getEl : function(){
19902 * Returns the ghost element
19903 * @return {Roo.Element} el
19905 getGhost : function(){
19911 * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
19913 hide : function(clear){
19921 * Stops the repair animation if it's currently running
19924 if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
19930 * Displays this proxy
19937 * Force the Layer to sync its shadow and shim positions to the element
19944 * Causes the proxy to return to its position of origin via an animation. Should be called after an
19945 * invalid drop operation by the item being dragged.
19946 * @param {Array} xy The XY position of the element ([x, y])
19947 * @param {Function} callback The function to call after the repair is complete
19948 * @param {Object} scope The scope in which to execute the callback
19950 repair : function(xy, callback, scope){
19951 this.callback = callback;
19952 this.scope = scope;
19953 if(xy && this.animRepair !== false){
19954 this.el.addClass("x-dd-drag-repair");
19955 this.el.hideUnders(true);
19956 this.anim = this.el.shift({
19957 duration: this.repairDuration || .5,
19961 callback: this.afterRepair,
19965 this.afterRepair();
19970 afterRepair : function(){
19972 if(typeof this.callback == "function"){
19973 this.callback.call(this.scope || this);
19975 this.callback = null;
19980 * Ext JS Library 1.1.1
19981 * Copyright(c) 2006-2007, Ext JS, LLC.
19983 * Originally Released Under LGPL - original licence link has changed is not relivant.
19986 * <script type="text/javascript">
19990 * @class Roo.dd.DragSource
19991 * @extends Roo.dd.DDProxy
19992 * A simple class that provides the basic implementation needed to make any element draggable.
19994 * @param {String/HTMLElement/Element} el The container element
19995 * @param {Object} config
19997 Roo.dd.DragSource = function(el, config){
19998 this.el = Roo.get(el);
19999 this.dragData = {};
20001 Roo.apply(this, config);
20004 this.proxy = new Roo.dd.StatusProxy();
20007 Roo.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
20008 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
20010 this.dragging = false;
20013 Roo.extend(Roo.dd.DragSource, Roo.dd.DDProxy, {
20015 * @cfg {String} dropAllowed
20016 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
20018 dropAllowed : "x-dd-drop-ok",
20020 * @cfg {String} dropNotAllowed
20021 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
20023 dropNotAllowed : "x-dd-drop-nodrop",
20026 * Returns the data object associated with this drag source
20027 * @return {Object} data An object containing arbitrary data
20029 getDragData : function(e){
20030 return this.dragData;
20034 onDragEnter : function(e, id){
20035 var target = Roo.dd.DragDropMgr.getDDById(id);
20036 this.cachedTarget = target;
20037 if(this.beforeDragEnter(target, e, id) !== false){
20038 if(target.isNotifyTarget){
20039 var status = target.notifyEnter(this, e, this.dragData);
20040 this.proxy.setStatus(status);
20042 this.proxy.setStatus(this.dropAllowed);
20045 if(this.afterDragEnter){
20047 * An empty function by default, but provided so that you can perform a custom action
20048 * when the dragged item enters the drop target by providing an implementation.
20049 * @param {Roo.dd.DragDrop} target The drop target
20050 * @param {Event} e The event object
20051 * @param {String} id The id of the dragged element
20052 * @method afterDragEnter
20054 this.afterDragEnter(target, e, id);
20060 * An empty function by default, but provided so that you can perform a custom action
20061 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
20062 * @param {Roo.dd.DragDrop} target The drop target
20063 * @param {Event} e The event object
20064 * @param {String} id The id of the dragged element
20065 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
20067 beforeDragEnter : function(target, e, id){
20072 alignElWithMouse: function() {
20073 Roo.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
20078 onDragOver : function(e, id){
20079 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
20080 if(this.beforeDragOver(target, e, id) !== false){
20081 if(target.isNotifyTarget){
20082 var status = target.notifyOver(this, e, this.dragData);
20083 Roo.log('run here??????????????');
20085 this.proxy.setStatus(status);
20088 if(this.afterDragOver){
20090 * An empty function by default, but provided so that you can perform a custom action
20091 * while the dragged item is over the drop target by providing an implementation.
20092 * @param {Roo.dd.DragDrop} target The drop target
20093 * @param {Event} e The event object
20094 * @param {String} id The id of the dragged element
20095 * @method afterDragOver
20097 this.afterDragOver(target, e, id);
20103 * An empty function by default, but provided so that you can perform a custom action
20104 * while the dragged item is over the drop target and optionally cancel the onDragOver.
20105 * @param {Roo.dd.DragDrop} target The drop target
20106 * @param {Event} e The event object
20107 * @param {String} id The id of the dragged element
20108 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
20110 beforeDragOver : function(target, e, id){
20115 onDragOut : function(e, id){
20116 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
20117 if(this.beforeDragOut(target, e, id) !== false){
20118 if(target.isNotifyTarget){
20119 target.notifyOut(this, e, this.dragData);
20121 this.proxy.reset();
20122 if(this.afterDragOut){
20124 * An empty function by default, but provided so that you can perform a custom action
20125 * after the dragged item is dragged out of the target without dropping.
20126 * @param {Roo.dd.DragDrop} target The drop target
20127 * @param {Event} e The event object
20128 * @param {String} id The id of the dragged element
20129 * @method afterDragOut
20131 this.afterDragOut(target, e, id);
20134 this.cachedTarget = null;
20138 * An empty function by default, but provided so that you can perform a custom action before the dragged
20139 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
20140 * @param {Roo.dd.DragDrop} target The drop target
20141 * @param {Event} e The event object
20142 * @param {String} id The id of the dragged element
20143 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
20145 beforeDragOut : function(target, e, id){
20150 onDragDrop : function(e, id){
20151 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
20152 if(this.beforeDragDrop(target, e, id) !== false){
20153 if(target.isNotifyTarget){
20154 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
20155 this.onValidDrop(target, e, id);
20157 this.onInvalidDrop(target, e, id);
20160 this.onValidDrop(target, e, id);
20163 if(this.afterDragDrop){
20165 * An empty function by default, but provided so that you can perform a custom action
20166 * after a valid drag drop has occurred by providing an implementation.
20167 * @param {Roo.dd.DragDrop} target The drop target
20168 * @param {Event} e The event object
20169 * @param {String} id The id of the dropped element
20170 * @method afterDragDrop
20172 this.afterDragDrop(target, e, id);
20175 delete this.cachedTarget;
20179 * An empty function by default, but provided so that you can perform a custom action before the dragged
20180 * item is dropped onto the target and optionally cancel the onDragDrop.
20181 * @param {Roo.dd.DragDrop} target The drop target
20182 * @param {Event} e The event object
20183 * @param {String} id The id of the dragged element
20184 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
20186 beforeDragDrop : function(target, e, id){
20191 onValidDrop : function(target, e, id){
20193 if(this.afterValidDrop){
20195 * An empty function by default, but provided so that you can perform a custom action
20196 * after a valid drop has occurred by providing an implementation.
20197 * @param {Object} target The target DD
20198 * @param {Event} e The event object
20199 * @param {String} id The id of the dropped element
20200 * @method afterInvalidDrop
20202 this.afterValidDrop(target, e, id);
20207 getRepairXY : function(e, data){
20208 return this.el.getXY();
20212 onInvalidDrop : function(target, e, id){
20213 this.beforeInvalidDrop(target, e, id);
20214 if(this.cachedTarget){
20215 if(this.cachedTarget.isNotifyTarget){
20216 this.cachedTarget.notifyOut(this, e, this.dragData);
20218 this.cacheTarget = null;
20220 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
20222 if(this.afterInvalidDrop){
20224 * An empty function by default, but provided so that you can perform a custom action
20225 * after an invalid drop has occurred by providing an implementation.
20226 * @param {Event} e The event object
20227 * @param {String} id The id of the dropped element
20228 * @method afterInvalidDrop
20230 this.afterInvalidDrop(e, id);
20235 afterRepair : function(){
20237 this.el.highlight(this.hlColor || "c3daf9");
20239 this.dragging = false;
20243 * An empty function by default, but provided so that you can perform a custom action after an invalid
20244 * drop has occurred.
20245 * @param {Roo.dd.DragDrop} target The drop target
20246 * @param {Event} e The event object
20247 * @param {String} id The id of the dragged element
20248 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
20250 beforeInvalidDrop : function(target, e, id){
20255 handleMouseDown : function(e){
20256 if(this.dragging) {
20259 var data = this.getDragData(e);
20260 if(data && this.onBeforeDrag(data, e) !== false){
20261 this.dragData = data;
20263 Roo.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
20268 * An empty function by default, but provided so that you can perform a custom action before the initial
20269 * drag event begins and optionally cancel it.
20270 * @param {Object} data An object containing arbitrary data to be shared with drop targets
20271 * @param {Event} e The event object
20272 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
20274 onBeforeDrag : function(data, e){
20279 * An empty function by default, but provided so that you can perform a custom action once the initial
20280 * drag event has begun. The drag cannot be canceled from this function.
20281 * @param {Number} x The x position of the click on the dragged object
20282 * @param {Number} y The y position of the click on the dragged object
20284 onStartDrag : Roo.emptyFn,
20286 // private - YUI override
20287 startDrag : function(x, y){
20288 this.proxy.reset();
20289 this.dragging = true;
20290 this.proxy.update("");
20291 this.onInitDrag(x, y);
20296 onInitDrag : function(x, y){
20297 var clone = this.el.dom.cloneNode(true);
20298 clone.id = Roo.id(); // prevent duplicate ids
20299 this.proxy.update(clone);
20300 this.onStartDrag(x, y);
20305 * Returns the drag source's underlying {@link Roo.dd.StatusProxy}
20306 * @return {Roo.dd.StatusProxy} proxy The StatusProxy
20308 getProxy : function(){
20313 * Hides the drag source's {@link Roo.dd.StatusProxy}
20315 hideProxy : function(){
20317 this.proxy.reset(true);
20318 this.dragging = false;
20322 triggerCacheRefresh : function(){
20323 Roo.dd.DDM.refreshCache(this.groups);
20326 // private - override to prevent hiding
20327 b4EndDrag: function(e) {
20330 // private - override to prevent moving
20331 endDrag : function(e){
20332 this.onEndDrag(this.dragData, e);
20336 onEndDrag : function(data, e){
20339 // private - pin to cursor
20340 autoOffset : function(x, y) {
20341 this.setDelta(-12, -20);
20345 * Ext JS Library 1.1.1
20346 * Copyright(c) 2006-2007, Ext JS, LLC.
20348 * Originally Released Under LGPL - original licence link has changed is not relivant.
20351 * <script type="text/javascript">
20356 * @class Roo.dd.DropTarget
20357 * @extends Roo.dd.DDTarget
20358 * A simple class that provides the basic implementation needed to make any element a drop target that can have
20359 * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
20361 * @param {String/HTMLElement/Element} el The container element
20362 * @param {Object} config
20364 Roo.dd.DropTarget = function(el, config){
20365 this.el = Roo.get(el);
20367 var listeners = false; ;
20368 if (config && config.listeners) {
20369 listeners= config.listeners;
20370 delete config.listeners;
20372 Roo.apply(this, config);
20374 if(this.containerScroll){
20375 Roo.dd.ScrollManager.register(this.el);
20379 * @scope Roo.dd.DropTarget
20384 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
20385 * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
20386 * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
20388 * IMPORTANT : it should set this.overClass and this.dropAllowed
20390 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
20391 * @param {Event} e The event
20392 * @param {Object} data An object containing arbitrary data supplied by the drag source
20398 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the target.
20399 * This method will be called on every mouse movement while the drag source is over the drop target.
20400 * This default implementation simply returns the dropAllowed config value.
20402 * IMPORTANT : it should set this.dropAllowed
20404 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
20405 * @param {Event} e The event
20406 * @param {Object} data An object containing arbitrary data supplied by the drag source
20412 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source has been dragged
20413 * out of the target without dropping. This default implementation simply removes the CSS class specified by
20414 * overClass (if any) from the drop element.
20416 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
20417 * @param {Event} e The event
20418 * @param {Object} data An object containing arbitrary data supplied by the drag source
20424 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the dragged item has
20425 * been dropped on it. This method has no default implementation and returns false, so you must provide an
20426 * implementation that does something to process the drop event and returns true so that the drag source's
20427 * repair action does not run.
20429 * IMPORTANT : it should set this.success
20431 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
20432 * @param {Event} e The event
20433 * @param {Object} data An object containing arbitrary data supplied by the drag source
20439 Roo.dd.DropTarget.superclass.constructor.call( this,
20441 this.ddGroup || this.group,
20444 listeners : listeners || {}
20452 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
20454 * @cfg {String} overClass
20455 * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
20458 * @cfg {String} ddGroup
20459 * The drag drop group to handle drop events for
20463 * @cfg {String} dropAllowed
20464 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
20466 dropAllowed : "x-dd-drop-ok",
20468 * @cfg {String} dropNotAllowed
20469 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
20471 dropNotAllowed : "x-dd-drop-nodrop",
20473 * @cfg {boolean} success
20474 * set this after drop listener..
20478 * @cfg {boolean|String} valid true/false or string (ok-add/ok-sub/ok/nodrop)
20479 * if the drop point is valid for over/enter..
20486 isNotifyTarget : true,
20491 notifyEnter : function(dd, e, data)
20494 this.fireEvent('enter', dd, e, data);
20495 if(this.overClass){
20496 this.el.addClass(this.overClass);
20498 return typeof(this.valid) == 'string' ? 'x-dd-drop-' + this.valid : (
20499 this.valid ? this.dropAllowed : this.dropNotAllowed
20506 notifyOver : function(dd, e, data)
20509 this.fireEvent('over', dd, e, data);
20510 return typeof(this.valid) == 'string' ? 'x-dd-drop-' + this.valid : (
20511 this.valid ? this.dropAllowed : this.dropNotAllowed
20518 notifyOut : function(dd, e, data)
20520 this.fireEvent('out', dd, e, data);
20521 if(this.overClass){
20522 this.el.removeClass(this.overClass);
20529 notifyDrop : function(dd, e, data)
20531 this.success = false;
20532 this.fireEvent('drop', dd, e, data);
20533 return this.success;
20537 * Ext JS Library 1.1.1
20538 * Copyright(c) 2006-2007, Ext JS, LLC.
20540 * Originally Released Under LGPL - original licence link has changed is not relivant.
20543 * <script type="text/javascript">
20548 * @class Roo.dd.DragZone
20549 * @extends Roo.dd.DragSource
20550 * This class provides a container DD instance that proxies for multiple child node sources.<br />
20551 * By default, this class requires that draggable child nodes are registered with {@link Roo.dd.Registry}.
20553 * @param {String/HTMLElement/Element} el The container element
20554 * @param {Object} config
20556 Roo.dd.DragZone = function(el, config){
20557 Roo.dd.DragZone.superclass.constructor.call(this, el, config);
20558 if(this.containerScroll){
20559 Roo.dd.ScrollManager.register(this.el);
20563 Roo.extend(Roo.dd.DragZone, Roo.dd.DragSource, {
20565 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
20566 * for auto scrolling during drag operations.
20569 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
20570 * method after a failed drop (defaults to "c3daf9" - light blue)
20574 * Called when a mousedown occurs in this container. Looks in {@link Roo.dd.Registry}
20575 * for a valid target to drag based on the mouse down. Override this method
20576 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
20577 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
20578 * @param {EventObject} e The mouse down event
20579 * @return {Object} The dragData
20581 getDragData : function(e){
20582 return Roo.dd.Registry.getHandleFromEvent(e);
20586 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
20587 * this.dragData.ddel
20588 * @param {Number} x The x position of the click on the dragged object
20589 * @param {Number} y The y position of the click on the dragged object
20590 * @return {Boolean} true to continue the drag, false to cancel
20592 onInitDrag : function(x, y){
20593 this.proxy.update(this.dragData.ddel.cloneNode(true));
20594 this.onStartDrag(x, y);
20599 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
20601 afterRepair : function(){
20603 Roo.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
20605 this.dragging = false;
20609 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
20610 * the XY of this.dragData.ddel
20611 * @param {EventObject} e The mouse up event
20612 * @return {Array} The xy location (e.g. [100, 200])
20614 getRepairXY : function(e){
20615 return Roo.Element.fly(this.dragData.ddel).getXY();
20619 * Ext JS Library 1.1.1
20620 * Copyright(c) 2006-2007, Ext JS, LLC.
20622 * Originally Released Under LGPL - original licence link has changed is not relivant.
20625 * <script type="text/javascript">
20628 * @class Roo.dd.DropZone
20629 * @extends Roo.dd.DropTarget
20630 * This class provides a container DD instance that proxies for multiple child node targets.<br />
20631 * By default, this class requires that child nodes accepting drop are registered with {@link Roo.dd.Registry}.
20633 * @param {String/HTMLElement/Element} el The container element
20634 * @param {Object} config
20636 Roo.dd.DropZone = function(el, config){
20637 Roo.dd.DropZone.superclass.constructor.call(this, el, config);
20640 Roo.extend(Roo.dd.DropZone, Roo.dd.DropTarget, {
20642 * Returns a custom data object associated with the DOM node that is the target of the event. By default
20643 * this looks up the event target in the {@link Roo.dd.Registry}, although you can override this method to
20644 * provide your own custom lookup.
20645 * @param {Event} e The event
20646 * @return {Object} data The custom data
20648 getTargetFromEvent : function(e){
20649 return Roo.dd.Registry.getTargetFromEvent(e);
20653 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has entered a drop node
20654 * that it has registered. This method has no default implementation and should be overridden to provide
20655 * node-specific processing if necessary.
20656 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
20657 * {@link #getTargetFromEvent} for this node)
20658 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20659 * @param {Event} e The event
20660 * @param {Object} data An object containing arbitrary data supplied by the drag source
20662 onNodeEnter : function(n, dd, e, data){
20667 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is over a drop node
20668 * that it has registered. The default implementation returns this.dropNotAllowed, so it should be
20669 * overridden to provide the proper feedback.
20670 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
20671 * {@link #getTargetFromEvent} for this node)
20672 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20673 * @param {Event} e The event
20674 * @param {Object} data An object containing arbitrary data supplied by the drag source
20675 * @return {String} status The CSS class that communicates the drop status back to the source so that the
20676 * underlying {@link Roo.dd.StatusProxy} can be updated
20678 onNodeOver : function(n, dd, e, data){
20679 return this.dropAllowed;
20683 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dragged out of
20684 * the drop node without dropping. This method has no default implementation and should be overridden to provide
20685 * node-specific processing if necessary.
20686 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
20687 * {@link #getTargetFromEvent} for this node)
20688 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20689 * @param {Event} e The event
20690 * @param {Object} data An object containing arbitrary data supplied by the drag source
20692 onNodeOut : function(n, dd, e, data){
20697 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped onto
20698 * the drop node. The default implementation returns false, so it should be overridden to provide the
20699 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
20700 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
20701 * {@link #getTargetFromEvent} for this node)
20702 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20703 * @param {Event} e The event
20704 * @param {Object} data An object containing arbitrary data supplied by the drag source
20705 * @return {Boolean} True if the drop was valid, else false
20707 onNodeDrop : function(n, dd, e, data){
20712 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is being dragged over it,
20713 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
20714 * it should be overridden to provide the proper feedback if necessary.
20715 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20716 * @param {Event} e The event
20717 * @param {Object} data An object containing arbitrary data supplied by the drag source
20718 * @return {String} status The CSS class that communicates the drop status back to the source so that the
20719 * underlying {@link Roo.dd.StatusProxy} can be updated
20721 onContainerOver : function(dd, e, data){
20722 return this.dropNotAllowed;
20726 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped on it,
20727 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
20728 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
20729 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
20730 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20731 * @param {Event} e The event
20732 * @param {Object} data An object containing arbitrary data supplied by the drag source
20733 * @return {Boolean} True if the drop was valid, else false
20735 onContainerDrop : function(dd, e, data){
20740 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source is now over
20741 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
20742 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
20743 * you should override this method and provide a custom implementation.
20744 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20745 * @param {Event} e The event
20746 * @param {Object} data An object containing arbitrary data supplied by the drag source
20747 * @return {String} status The CSS class that communicates the drop status back to the source so that the
20748 * underlying {@link Roo.dd.StatusProxy} can be updated
20750 notifyEnter : function(dd, e, data){
20751 return this.dropNotAllowed;
20755 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the drop zone.
20756 * This method will be called on every mouse movement while the drag source is over the drop zone.
20757 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
20758 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
20759 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
20760 * registered node, it will call {@link #onContainerOver}.
20761 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20762 * @param {Event} e The event
20763 * @param {Object} data An object containing arbitrary data supplied by the drag source
20764 * @return {String} status The CSS class that communicates the drop status back to the source so that the
20765 * underlying {@link Roo.dd.StatusProxy} can be updated
20767 notifyOver : function(dd, e, data){
20768 var n = this.getTargetFromEvent(e);
20769 if(!n){ // not over valid drop target
20770 if(this.lastOverNode){
20771 this.onNodeOut(this.lastOverNode, dd, e, data);
20772 this.lastOverNode = null;
20774 return this.onContainerOver(dd, e, data);
20776 if(this.lastOverNode != n){
20777 if(this.lastOverNode){
20778 this.onNodeOut(this.lastOverNode, dd, e, data);
20780 this.onNodeEnter(n, dd, e, data);
20781 this.lastOverNode = n;
20783 return this.onNodeOver(n, dd, e, data);
20787 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source has been dragged
20788 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
20789 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
20790 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
20791 * @param {Event} e The event
20792 * @param {Object} data An object containing arbitrary data supplied by the drag zone
20794 notifyOut : function(dd, e, data){
20795 if(this.lastOverNode){
20796 this.onNodeOut(this.lastOverNode, dd, e, data);
20797 this.lastOverNode = null;
20802 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the dragged item has
20803 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
20804 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
20805 * otherwise it will call {@link #onContainerDrop}.
20806 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
20807 * @param {Event} e The event
20808 * @param {Object} data An object containing arbitrary data supplied by the drag source
20809 * @return {Boolean} True if the drop was valid, else false
20811 notifyDrop : function(dd, e, data){
20812 if(this.lastOverNode){
20813 this.onNodeOut(this.lastOverNode, dd, e, data);
20814 this.lastOverNode = null;
20816 var n = this.getTargetFromEvent(e);
20818 this.onNodeDrop(n, dd, e, data) :
20819 this.onContainerDrop(dd, e, data);
20823 triggerCacheRefresh : function(){
20824 Roo.dd.DDM.refreshCache(this.groups);
20828 * Ext JS Library 1.1.1
20829 * Copyright(c) 2006-2007, Ext JS, LLC.
20831 * Originally Released Under LGPL - original licence link has changed is not relivant.
20834 * <script type="text/javascript">
20839 * @class Roo.data.SortTypes
20841 * Defines the default sorting (casting?) comparison functions used when sorting data.
20843 Roo.data.SortTypes = {
20845 * Default sort that does nothing
20846 * @param {Mixed} s The value being converted
20847 * @return {Mixed} The comparison value
20849 none : function(s){
20854 * The regular expression used to strip tags
20858 stripTagsRE : /<\/?[^>]+>/gi,
20861 * Strips all HTML tags to sort on text only
20862 * @param {Mixed} s The value being converted
20863 * @return {String} The comparison value
20865 asText : function(s){
20866 return String(s).replace(this.stripTagsRE, "");
20870 * Strips all HTML tags to sort on text only - Case insensitive
20871 * @param {Mixed} s The value being converted
20872 * @return {String} The comparison value
20874 asUCText : function(s){
20875 return String(s).toUpperCase().replace(this.stripTagsRE, "");
20879 * Case insensitive string
20880 * @param {Mixed} s The value being converted
20881 * @return {String} The comparison value
20883 asUCString : function(s) {
20884 return String(s).toUpperCase();
20889 * @param {Mixed} s The value being converted
20890 * @return {Number} The comparison value
20892 asDate : function(s) {
20896 if(s instanceof Date){
20897 return s.getTime();
20899 return Date.parse(String(s));
20904 * @param {Mixed} s The value being converted
20905 * @return {Float} The comparison value
20907 asFloat : function(s) {
20908 var val = parseFloat(String(s).replace(/,/g, ""));
20909 if(isNaN(val)) val = 0;
20915 * @param {Mixed} s The value being converted
20916 * @return {Number} The comparison value
20918 asInt : function(s) {
20919 var val = parseInt(String(s).replace(/,/g, ""));
20920 if(isNaN(val)) val = 0;
20925 * Ext JS Library 1.1.1
20926 * Copyright(c) 2006-2007, Ext JS, LLC.
20928 * Originally Released Under LGPL - original licence link has changed is not relivant.
20931 * <script type="text/javascript">
20935 * @class Roo.data.Record
20936 * Instances of this class encapsulate both record <em>definition</em> information, and record
20937 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
20938 * to access Records cached in an {@link Roo.data.Store} object.<br>
20940 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
20941 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
20944 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
20946 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
20947 * {@link #create}. The parameters are the same.
20948 * @param {Array} data An associative Array of data values keyed by the field name.
20949 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
20950 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
20951 * not specified an integer id is generated.
20953 Roo.data.Record = function(data, id){
20954 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
20959 * Generate a constructor for a specific record layout.
20960 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
20961 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
20962 * Each field definition object may contain the following properties: <ul>
20963 * <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,
20964 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
20965 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
20966 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
20967 * is being used, then this is a string containing the javascript expression to reference the data relative to
20968 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
20969 * to the data item relative to the record element. If the mapping expression is the same as the field name,
20970 * this may be omitted.</p></li>
20971 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
20972 * <ul><li>auto (Default, implies no conversion)</li>
20977 * <li>date</li></ul></p></li>
20978 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
20979 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
20980 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
20981 * by the Reader into an object that will be stored in the Record. It is passed the
20982 * following parameters:<ul>
20983 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
20985 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
20987 * <br>usage:<br><pre><code>
20988 var TopicRecord = Roo.data.Record.create(
20989 {name: 'title', mapping: 'topic_title'},
20990 {name: 'author', mapping: 'username'},
20991 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
20992 {name: 'lastPost', mapping: 'post_time', type: 'date'},
20993 {name: 'lastPoster', mapping: 'user2'},
20994 {name: 'excerpt', mapping: 'post_text'}
20997 var myNewRecord = new TopicRecord({
20998 title: 'Do my job please',
21001 lastPost: new Date(),
21002 lastPoster: 'Animal',
21003 excerpt: 'No way dude!'
21005 myStore.add(myNewRecord);
21010 Roo.data.Record.create = function(o){
21011 var f = function(){
21012 f.superclass.constructor.apply(this, arguments);
21014 Roo.extend(f, Roo.data.Record);
21015 var p = f.prototype;
21016 p.fields = new Roo.util.MixedCollection(false, function(field){
21019 for(var i = 0, len = o.length; i < len; i++){
21020 p.fields.add(new Roo.data.Field(o[i]));
21022 f.getField = function(name){
21023 return p.fields.get(name);
21028 Roo.data.Record.AUTO_ID = 1000;
21029 Roo.data.Record.EDIT = 'edit';
21030 Roo.data.Record.REJECT = 'reject';
21031 Roo.data.Record.COMMIT = 'commit';
21033 Roo.data.Record.prototype = {
21035 * Readonly flag - true if this record has been modified.
21044 join : function(store){
21045 this.store = store;
21049 * Set the named field to the specified value.
21050 * @param {String} name The name of the field to set.
21051 * @param {Object} value The value to set the field to.
21053 set : function(name, value){
21054 if(this.data[name] == value){
21058 if(!this.modified){
21059 this.modified = {};
21061 if(typeof this.modified[name] == 'undefined'){
21062 this.modified[name] = this.data[name];
21064 this.data[name] = value;
21065 if(!this.editing && this.store){
21066 this.store.afterEdit(this);
21071 * Get the value of the named field.
21072 * @param {String} name The name of the field to get the value of.
21073 * @return {Object} The value of the field.
21075 get : function(name){
21076 return this.data[name];
21080 beginEdit : function(){
21081 this.editing = true;
21082 this.modified = {};
21086 cancelEdit : function(){
21087 this.editing = false;
21088 delete this.modified;
21092 endEdit : function(){
21093 this.editing = false;
21094 if(this.dirty && this.store){
21095 this.store.afterEdit(this);
21100 * Usually called by the {@link Roo.data.Store} which owns the Record.
21101 * Rejects all changes made to the Record since either creation, or the last commit operation.
21102 * Modified fields are reverted to their original values.
21104 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
21105 * of reject operations.
21107 reject : function(){
21108 var m = this.modified;
21110 if(typeof m[n] != "function"){
21111 this.data[n] = m[n];
21114 this.dirty = false;
21115 delete this.modified;
21116 this.editing = false;
21118 this.store.afterReject(this);
21123 * Usually called by the {@link Roo.data.Store} which owns the Record.
21124 * Commits all changes made to the Record since either creation, or the last commit operation.
21126 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
21127 * of commit operations.
21129 commit : function(){
21130 this.dirty = false;
21131 delete this.modified;
21132 this.editing = false;
21134 this.store.afterCommit(this);
21139 hasError : function(){
21140 return this.error != null;
21144 clearError : function(){
21149 * Creates a copy of this record.
21150 * @param {String} id (optional) A new record id if you don't want to use this record's id
21153 copy : function(newId) {
21154 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
21158 * Ext JS Library 1.1.1
21159 * Copyright(c) 2006-2007, Ext JS, LLC.
21161 * Originally Released Under LGPL - original licence link has changed is not relivant.
21164 * <script type="text/javascript">
21170 * @class Roo.data.Store
21171 * @extends Roo.util.Observable
21172 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
21173 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
21175 * 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
21176 * has no knowledge of the format of the data returned by the Proxy.<br>
21178 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
21179 * instances from the data object. These records are cached and made available through accessor functions.
21181 * Creates a new Store.
21182 * @param {Object} config A config object containing the objects needed for the Store to access data,
21183 * and read the data into Records.
21185 Roo.data.Store = function(config){
21186 this.data = new Roo.util.MixedCollection(false);
21187 this.data.getKey = function(o){
21190 this.baseParams = {};
21192 this.paramNames = {
21197 "multisort" : "_multisort"
21200 if(config && config.data){
21201 this.inlineData = config.data;
21202 delete config.data;
21205 Roo.apply(this, config);
21207 if(this.reader){ // reader passed
21208 this.reader = Roo.factory(this.reader, Roo.data);
21209 this.reader.xmodule = this.xmodule || false;
21210 if(!this.recordType){
21211 this.recordType = this.reader.recordType;
21213 if(this.reader.onMetaChange){
21214 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
21218 if(this.recordType){
21219 this.fields = this.recordType.prototype.fields;
21221 this.modified = [];
21225 * @event datachanged
21226 * Fires when the data cache has changed, and a widget which is using this Store
21227 * as a Record cache should refresh its view.
21228 * @param {Store} this
21230 datachanged : true,
21232 * @event metachange
21233 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
21234 * @param {Store} this
21235 * @param {Object} meta The JSON metadata
21240 * Fires when Records have been added to the Store
21241 * @param {Store} this
21242 * @param {Roo.data.Record[]} records The array of Records added
21243 * @param {Number} index The index at which the record(s) were added
21248 * Fires when a Record has been removed from the Store
21249 * @param {Store} this
21250 * @param {Roo.data.Record} record The Record that was removed
21251 * @param {Number} index The index at which the record was removed
21256 * Fires when a Record has been updated
21257 * @param {Store} this
21258 * @param {Roo.data.Record} record The Record that was updated
21259 * @param {String} operation The update operation being performed. Value may be one of:
21261 Roo.data.Record.EDIT
21262 Roo.data.Record.REJECT
21263 Roo.data.Record.COMMIT
21269 * Fires when the data cache has been cleared.
21270 * @param {Store} this
21274 * @event beforeload
21275 * Fires before a request is made for a new data object. If the beforeload handler returns false
21276 * the load action will be canceled.
21277 * @param {Store} this
21278 * @param {Object} options The loading options that were specified (see {@link #load} for details)
21282 * @event beforeloadadd
21283 * Fires after a new set of Records has been loaded.
21284 * @param {Store} this
21285 * @param {Roo.data.Record[]} records The Records that were loaded
21286 * @param {Object} options The loading options that were specified (see {@link #load} for details)
21288 beforeloadadd : true,
21291 * Fires after a new set of Records has been loaded, before they are added to the store.
21292 * @param {Store} this
21293 * @param {Roo.data.Record[]} records The Records that were loaded
21294 * @param {Object} options The loading options that were specified (see {@link #load} for details)
21295 * @params {Object} return from reader
21299 * @event loadexception
21300 * Fires if an exception occurs in the Proxy during loading.
21301 * Called with the signature of the Proxy's "loadexception" event.
21302 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
21305 * @param {Object} return from JsonData.reader() - success, totalRecords, records
21306 * @param {Object} load options
21307 * @param {Object} jsonData from your request (normally this contains the Exception)
21309 loadexception : true
21313 this.proxy = Roo.factory(this.proxy, Roo.data);
21314 this.proxy.xmodule = this.xmodule || false;
21315 this.relayEvents(this.proxy, ["loadexception"]);
21317 this.sortToggle = {};
21318 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
21320 Roo.data.Store.superclass.constructor.call(this);
21322 if(this.inlineData){
21323 this.loadData(this.inlineData);
21324 delete this.inlineData;
21328 Roo.extend(Roo.data.Store, Roo.util.Observable, {
21330 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
21331 * without a remote query - used by combo/forms at present.
21335 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
21338 * @cfg {Array} data Inline data to be loaded when the store is initialized.
21341 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
21342 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
21345 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
21346 * on any HTTP request
21349 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
21352 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
21356 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
21357 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
21359 remoteSort : false,
21362 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
21363 * loaded or when a record is removed. (defaults to false).
21365 pruneModifiedRecords : false,
21368 lastOptions : null,
21371 * Add Records to the Store and fires the add event.
21372 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
21374 add : function(records){
21375 records = [].concat(records);
21376 for(var i = 0, len = records.length; i < len; i++){
21377 records[i].join(this);
21379 var index = this.data.length;
21380 this.data.addAll(records);
21381 this.fireEvent("add", this, records, index);
21385 * Remove a Record from the Store and fires the remove event.
21386 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
21388 remove : function(record){
21389 var index = this.data.indexOf(record);
21390 this.data.removeAt(index);
21391 if(this.pruneModifiedRecords){
21392 this.modified.remove(record);
21394 this.fireEvent("remove", this, record, index);
21398 * Remove all Records from the Store and fires the clear event.
21400 removeAll : function(){
21402 if(this.pruneModifiedRecords){
21403 this.modified = [];
21405 this.fireEvent("clear", this);
21409 * Inserts Records to the Store at the given index and fires the add event.
21410 * @param {Number} index The start index at which to insert the passed Records.
21411 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
21413 insert : function(index, records){
21414 records = [].concat(records);
21415 for(var i = 0, len = records.length; i < len; i++){
21416 this.data.insert(index, records[i]);
21417 records[i].join(this);
21419 this.fireEvent("add", this, records, index);
21423 * Get the index within the cache of the passed Record.
21424 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
21425 * @return {Number} The index of the passed Record. Returns -1 if not found.
21427 indexOf : function(record){
21428 return this.data.indexOf(record);
21432 * Get the index within the cache of the Record with the passed id.
21433 * @param {String} id The id of the Record to find.
21434 * @return {Number} The index of the Record. Returns -1 if not found.
21436 indexOfId : function(id){
21437 return this.data.indexOfKey(id);
21441 * Get the Record with the specified id.
21442 * @param {String} id The id of the Record to find.
21443 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
21445 getById : function(id){
21446 return this.data.key(id);
21450 * Get the Record at the specified index.
21451 * @param {Number} index The index of the Record to find.
21452 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
21454 getAt : function(index){
21455 return this.data.itemAt(index);
21459 * Returns a range of Records between specified indices.
21460 * @param {Number} startIndex (optional) The starting index (defaults to 0)
21461 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
21462 * @return {Roo.data.Record[]} An array of Records
21464 getRange : function(start, end){
21465 return this.data.getRange(start, end);
21469 storeOptions : function(o){
21470 o = Roo.apply({}, o);
21473 this.lastOptions = o;
21477 * Loads the Record cache from the configured Proxy using the configured Reader.
21479 * If using remote paging, then the first load call must specify the <em>start</em>
21480 * and <em>limit</em> properties in the options.params property to establish the initial
21481 * position within the dataset, and the number of Records to cache on each read from the Proxy.
21483 * <strong>It is important to note that for remote data sources, loading is asynchronous,
21484 * and this call will return before the new data has been loaded. Perform any post-processing
21485 * in a callback function, or in a "load" event handler.</strong>
21487 * @param {Object} options An object containing properties which control loading options:<ul>
21488 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
21489 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
21490 * passed the following arguments:<ul>
21491 * <li>r : Roo.data.Record[]</li>
21492 * <li>options: Options object from the load call</li>
21493 * <li>success: Boolean success indicator</li></ul></li>
21494 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
21495 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
21498 load : function(options){
21499 options = options || {};
21500 if(this.fireEvent("beforeload", this, options) !== false){
21501 this.storeOptions(options);
21502 var p = Roo.apply(options.params || {}, this.baseParams);
21503 // if meta was not loaded from remote source.. try requesting it.
21504 if (!this.reader.metaFromRemote) {
21505 p._requestMeta = 1;
21507 if(this.sortInfo && this.remoteSort){
21508 var pn = this.paramNames;
21509 p[pn["sort"]] = this.sortInfo.field;
21510 p[pn["dir"]] = this.sortInfo.direction;
21512 if (this.multiSort) {
21513 var pn = this.paramNames;
21514 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
21517 this.proxy.load(p, this.reader, this.loadRecords, this, options);
21522 * Reloads the Record cache from the configured Proxy using the configured Reader and
21523 * the options from the last load operation performed.
21524 * @param {Object} options (optional) An object containing properties which may override the options
21525 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
21526 * the most recently used options are reused).
21528 reload : function(options){
21529 this.load(Roo.applyIf(options||{}, this.lastOptions));
21533 // Called as a callback by the Reader during a load operation.
21534 loadRecords : function(o, options, success){
21535 if(!o || success === false){
21536 if(success !== false){
21537 this.fireEvent("load", this, [], options, o);
21539 if(options.callback){
21540 options.callback.call(options.scope || this, [], options, false);
21544 // if data returned failure - throw an exception.
21545 if (o.success === false) {
21546 // show a message if no listener is registered.
21547 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
21548 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
21550 // loadmask wil be hooked into this..
21551 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
21554 var r = o.records, t = o.totalRecords || r.length;
21556 this.fireEvent("beforeloadadd", this, r, options, o);
21558 if(!options || options.add !== true){
21559 if(this.pruneModifiedRecords){
21560 this.modified = [];
21562 for(var i = 0, len = r.length; i < len; i++){
21566 this.data = this.snapshot;
21567 delete this.snapshot;
21570 this.data.addAll(r);
21571 this.totalLength = t;
21573 this.fireEvent("datachanged", this);
21575 this.totalLength = Math.max(t, this.data.length+r.length);
21578 this.fireEvent("load", this, r, options, o);
21579 if(options.callback){
21580 options.callback.call(options.scope || this, r, options, true);
21586 * Loads data from a passed data block. A Reader which understands the format of the data
21587 * must have been configured in the constructor.
21588 * @param {Object} data The data block from which to read the Records. The format of the data expected
21589 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
21590 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
21592 loadData : function(o, append){
21593 var r = this.reader.readRecords(o);
21594 this.loadRecords(r, {add: append}, true);
21598 * Gets the number of cached records.
21600 * <em>If using paging, this may not be the total size of the dataset. If the data object
21601 * used by the Reader contains the dataset size, then the getTotalCount() function returns
21602 * the data set size</em>
21604 getCount : function(){
21605 return this.data.length || 0;
21609 * Gets the total number of records in the dataset as returned by the server.
21611 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
21612 * the dataset size</em>
21614 getTotalCount : function(){
21615 return this.totalLength || 0;
21619 * Returns the sort state of the Store as an object with two properties:
21621 field {String} The name of the field by which the Records are sorted
21622 direction {String} The sort order, "ASC" or "DESC"
21625 getSortState : function(){
21626 return this.sortInfo;
21630 applySort : function(){
21631 if(this.sortInfo && !this.remoteSort){
21632 var s = this.sortInfo, f = s.field;
21633 var st = this.fields.get(f).sortType;
21634 var fn = function(r1, r2){
21635 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
21636 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
21638 this.data.sort(s.direction, fn);
21639 if(this.snapshot && this.snapshot != this.data){
21640 this.snapshot.sort(s.direction, fn);
21646 * Sets the default sort column and order to be used by the next load operation.
21647 * @param {String} fieldName The name of the field to sort by.
21648 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
21650 setDefaultSort : function(field, dir){
21651 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
21655 * Sort the Records.
21656 * If remote sorting is used, the sort is performed on the server, and the cache is
21657 * reloaded. If local sorting is used, the cache is sorted internally.
21658 * @param {String} fieldName The name of the field to sort by.
21659 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
21661 sort : function(fieldName, dir){
21662 var f = this.fields.get(fieldName);
21664 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
21666 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
21667 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
21672 this.sortToggle[f.name] = dir;
21673 this.sortInfo = {field: f.name, direction: dir};
21674 if(!this.remoteSort){
21676 this.fireEvent("datachanged", this);
21678 this.load(this.lastOptions);
21683 * Calls the specified function for each of the Records in the cache.
21684 * @param {Function} fn The function to call. The Record is passed as the first parameter.
21685 * Returning <em>false</em> aborts and exits the iteration.
21686 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
21688 each : function(fn, scope){
21689 this.data.each(fn, scope);
21693 * Gets all records modified since the last commit. Modified records are persisted across load operations
21694 * (e.g., during paging).
21695 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
21697 getModifiedRecords : function(){
21698 return this.modified;
21702 createFilterFn : function(property, value, anyMatch){
21703 if(!value.exec){ // not a regex
21704 value = String(value);
21705 if(value.length == 0){
21708 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
21710 return function(r){
21711 return value.test(r.data[property]);
21716 * Sums the value of <i>property</i> for each record between start and end and returns the result.
21717 * @param {String} property A field on your records
21718 * @param {Number} start The record index to start at (defaults to 0)
21719 * @param {Number} end The last record index to include (defaults to length - 1)
21720 * @return {Number} The sum
21722 sum : function(property, start, end){
21723 var rs = this.data.items, v = 0;
21724 start = start || 0;
21725 end = (end || end === 0) ? end : rs.length-1;
21727 for(var i = start; i <= end; i++){
21728 v += (rs[i].data[property] || 0);
21734 * Filter the records by a specified property.
21735 * @param {String} field A field on your records
21736 * @param {String/RegExp} value Either a string that the field
21737 * should start with or a RegExp to test against the field
21738 * @param {Boolean} anyMatch True to match any part not just the beginning
21740 filter : function(property, value, anyMatch){
21741 var fn = this.createFilterFn(property, value, anyMatch);
21742 return fn ? this.filterBy(fn) : this.clearFilter();
21746 * Filter by a function. The specified function will be called with each
21747 * record in this data source. If the function returns true the record is included,
21748 * otherwise it is filtered.
21749 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
21750 * @param {Object} scope (optional) The scope of the function (defaults to this)
21752 filterBy : function(fn, scope){
21753 this.snapshot = this.snapshot || this.data;
21754 this.data = this.queryBy(fn, scope||this);
21755 this.fireEvent("datachanged", this);
21759 * Query the records by a specified property.
21760 * @param {String} field A field on your records
21761 * @param {String/RegExp} value Either a string that the field
21762 * should start with or a RegExp to test against the field
21763 * @param {Boolean} anyMatch True to match any part not just the beginning
21764 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
21766 query : function(property, value, anyMatch){
21767 var fn = this.createFilterFn(property, value, anyMatch);
21768 return fn ? this.queryBy(fn) : this.data.clone();
21772 * Query by a function. The specified function will be called with each
21773 * record in this data source. If the function returns true the record is included
21775 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
21776 * @param {Object} scope (optional) The scope of the function (defaults to this)
21777 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
21779 queryBy : function(fn, scope){
21780 var data = this.snapshot || this.data;
21781 return data.filterBy(fn, scope||this);
21785 * Collects unique values for a particular dataIndex from this store.
21786 * @param {String} dataIndex The property to collect
21787 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
21788 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
21789 * @return {Array} An array of the unique values
21791 collect : function(dataIndex, allowNull, bypassFilter){
21792 var d = (bypassFilter === true && this.snapshot) ?
21793 this.snapshot.items : this.data.items;
21794 var v, sv, r = [], l = {};
21795 for(var i = 0, len = d.length; i < len; i++){
21796 v = d[i].data[dataIndex];
21798 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
21807 * Revert to a view of the Record cache with no filtering applied.
21808 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
21810 clearFilter : function(suppressEvent){
21811 if(this.snapshot && this.snapshot != this.data){
21812 this.data = this.snapshot;
21813 delete this.snapshot;
21814 if(suppressEvent !== true){
21815 this.fireEvent("datachanged", this);
21821 afterEdit : function(record){
21822 if(this.modified.indexOf(record) == -1){
21823 this.modified.push(record);
21825 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
21829 afterReject : function(record){
21830 this.modified.remove(record);
21831 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
21835 afterCommit : function(record){
21836 this.modified.remove(record);
21837 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
21841 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
21842 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
21844 commitChanges : function(){
21845 var m = this.modified.slice(0);
21846 this.modified = [];
21847 for(var i = 0, len = m.length; i < len; i++){
21853 * Cancel outstanding changes on all changed records.
21855 rejectChanges : function(){
21856 var m = this.modified.slice(0);
21857 this.modified = [];
21858 for(var i = 0, len = m.length; i < len; i++){
21863 onMetaChange : function(meta, rtype, o){
21864 this.recordType = rtype;
21865 this.fields = rtype.prototype.fields;
21866 delete this.snapshot;
21867 this.sortInfo = meta.sortInfo || this.sortInfo;
21868 this.modified = [];
21869 this.fireEvent('metachange', this, this.reader.meta);
21872 moveIndex : function(data, type)
21874 var index = this.indexOf(data);
21876 var newIndex = index + type;
21880 this.insert(newIndex, data);
21885 * Ext JS Library 1.1.1
21886 * Copyright(c) 2006-2007, Ext JS, LLC.
21888 * Originally Released Under LGPL - original licence link has changed is not relivant.
21891 * <script type="text/javascript">
21895 * @class Roo.data.SimpleStore
21896 * @extends Roo.data.Store
21897 * Small helper class to make creating Stores from Array data easier.
21898 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
21899 * @cfg {Array} fields An array of field definition objects, or field name strings.
21900 * @cfg {Array} data The multi-dimensional array of data
21902 * @param {Object} config
21904 Roo.data.SimpleStore = function(config){
21905 Roo.data.SimpleStore.superclass.constructor.call(this, {
21907 reader: new Roo.data.ArrayReader({
21910 Roo.data.Record.create(config.fields)
21912 proxy : new Roo.data.MemoryProxy(config.data)
21916 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
21918 * Ext JS Library 1.1.1
21919 * Copyright(c) 2006-2007, Ext JS, LLC.
21921 * Originally Released Under LGPL - original licence link has changed is not relivant.
21924 * <script type="text/javascript">
21929 * @extends Roo.data.Store
21930 * @class Roo.data.JsonStore
21931 * Small helper class to make creating Stores for JSON data easier. <br/>
21933 var store = new Roo.data.JsonStore({
21934 url: 'get-images.php',
21936 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
21939 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
21940 * JsonReader and HttpProxy (unless inline data is provided).</b>
21941 * @cfg {Array} fields An array of field definition objects, or field name strings.
21943 * @param {Object} config
21945 Roo.data.JsonStore = function(c){
21946 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
21947 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
21948 reader: new Roo.data.JsonReader(c, c.fields)
21951 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
21953 * Ext JS Library 1.1.1
21954 * Copyright(c) 2006-2007, Ext JS, LLC.
21956 * Originally Released Under LGPL - original licence link has changed is not relivant.
21959 * <script type="text/javascript">
21963 Roo.data.Field = function(config){
21964 if(typeof config == "string"){
21965 config = {name: config};
21967 Roo.apply(this, config);
21970 this.type = "auto";
21973 var st = Roo.data.SortTypes;
21974 // named sortTypes are supported, here we look them up
21975 if(typeof this.sortType == "string"){
21976 this.sortType = st[this.sortType];
21979 // set default sortType for strings and dates
21980 if(!this.sortType){
21983 this.sortType = st.asUCString;
21986 this.sortType = st.asDate;
21989 this.sortType = st.none;
21994 var stripRe = /[\$,%]/g;
21996 // prebuilt conversion function for this field, instead of
21997 // switching every time we're reading a value
21999 var cv, dateFormat = this.dateFormat;
22004 cv = function(v){ return v; };
22007 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
22011 return v !== undefined && v !== null && v !== '' ?
22012 parseInt(String(v).replace(stripRe, ""), 10) : '';
22017 return v !== undefined && v !== null && v !== '' ?
22018 parseFloat(String(v).replace(stripRe, ""), 10) : '';
22023 cv = function(v){ return v === true || v === "true" || v == 1; };
22030 if(v instanceof Date){
22034 if(dateFormat == "timestamp"){
22035 return new Date(v*1000);
22037 return Date.parseDate(v, dateFormat);
22039 var parsed = Date.parse(v);
22040 return parsed ? new Date(parsed) : null;
22049 Roo.data.Field.prototype = {
22057 * Ext JS Library 1.1.1
22058 * Copyright(c) 2006-2007, Ext JS, LLC.
22060 * Originally Released Under LGPL - original licence link has changed is not relivant.
22063 * <script type="text/javascript">
22066 // Base class for reading structured data from a data source. This class is intended to be
22067 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
22070 * @class Roo.data.DataReader
22071 * Base class for reading structured data from a data source. This class is intended to be
22072 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
22075 Roo.data.DataReader = function(meta, recordType){
22079 this.recordType = recordType instanceof Array ?
22080 Roo.data.Record.create(recordType) : recordType;
22083 Roo.data.DataReader.prototype = {
22085 * Create an empty record
22086 * @param {Object} data (optional) - overlay some values
22087 * @return {Roo.data.Record} record created.
22089 newRow : function(d) {
22091 this.recordType.prototype.fields.each(function(c) {
22093 case 'int' : da[c.name] = 0; break;
22094 case 'date' : da[c.name] = new Date(); break;
22095 case 'float' : da[c.name] = 0.0; break;
22096 case 'boolean' : da[c.name] = false; break;
22097 default : da[c.name] = ""; break;
22101 return new this.recordType(Roo.apply(da, d));
22106 * Ext JS Library 1.1.1
22107 * Copyright(c) 2006-2007, Ext JS, LLC.
22109 * Originally Released Under LGPL - original licence link has changed is not relivant.
22112 * <script type="text/javascript">
22116 * @class Roo.data.DataProxy
22117 * @extends Roo.data.Observable
22118 * This class is an abstract base class for implementations which provide retrieval of
22119 * unformatted data objects.<br>
22121 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
22122 * (of the appropriate type which knows how to parse the data object) to provide a block of
22123 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
22125 * Custom implementations must implement the load method as described in
22126 * {@link Roo.data.HttpProxy#load}.
22128 Roo.data.DataProxy = function(){
22131 * @event beforeload
22132 * Fires before a network request is made to retrieve a data object.
22133 * @param {Object} This DataProxy object.
22134 * @param {Object} params The params parameter to the load function.
22139 * Fires before the load method's callback is called.
22140 * @param {Object} This DataProxy object.
22141 * @param {Object} o The data object.
22142 * @param {Object} arg The callback argument object passed to the load function.
22146 * @event loadexception
22147 * Fires if an Exception occurs during data retrieval.
22148 * @param {Object} This DataProxy object.
22149 * @param {Object} o The data object.
22150 * @param {Object} arg The callback argument object passed to the load function.
22151 * @param {Object} e The Exception.
22153 loadexception : true
22155 Roo.data.DataProxy.superclass.constructor.call(this);
22158 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
22161 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
22165 * Ext JS Library 1.1.1
22166 * Copyright(c) 2006-2007, Ext JS, LLC.
22168 * Originally Released Under LGPL - original licence link has changed is not relivant.
22171 * <script type="text/javascript">
22174 * @class Roo.data.MemoryProxy
22175 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
22176 * to the Reader when its load method is called.
22178 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
22180 Roo.data.MemoryProxy = function(data){
22184 Roo.data.MemoryProxy.superclass.constructor.call(this);
22188 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
22190 * Load data from the requested source (in this case an in-memory
22191 * data object passed to the constructor), read the data object into
22192 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
22193 * process that block using the passed callback.
22194 * @param {Object} params This parameter is not used by the MemoryProxy class.
22195 * @param {Roo.data.DataReader} reader The Reader object which converts the data
22196 * object into a block of Roo.data.Records.
22197 * @param {Function} callback The function into which to pass the block of Roo.data.records.
22198 * The function must be passed <ul>
22199 * <li>The Record block object</li>
22200 * <li>The "arg" argument from the load function</li>
22201 * <li>A boolean success indicator</li>
22203 * @param {Object} scope The scope in which to call the callback
22204 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
22206 load : function(params, reader, callback, scope, arg){
22207 params = params || {};
22210 result = reader.readRecords(this.data);
22212 this.fireEvent("loadexception", this, arg, null, e);
22213 callback.call(scope, null, arg, false);
22216 callback.call(scope, result, arg, true);
22220 update : function(params, records){
22225 * Ext JS Library 1.1.1
22226 * Copyright(c) 2006-2007, Ext JS, LLC.
22228 * Originally Released Under LGPL - original licence link has changed is not relivant.
22231 * <script type="text/javascript">
22234 * @class Roo.data.HttpProxy
22235 * @extends Roo.data.DataProxy
22236 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
22237 * configured to reference a certain URL.<br><br>
22239 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
22240 * from which the running page was served.<br><br>
22242 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
22244 * Be aware that to enable the browser to parse an XML document, the server must set
22245 * the Content-Type header in the HTTP response to "text/xml".
22247 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
22248 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
22249 * will be used to make the request.
22251 Roo.data.HttpProxy = function(conn){
22252 Roo.data.HttpProxy.superclass.constructor.call(this);
22253 // is conn a conn config or a real conn?
22255 this.useAjax = !conn || !conn.events;
22259 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
22260 // thse are take from connection...
22263 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
22266 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
22267 * extra parameters to each request made by this object. (defaults to undefined)
22270 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
22271 * to each request made by this object. (defaults to undefined)
22274 * @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)
22277 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
22280 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
22286 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
22290 * Return the {@link Roo.data.Connection} object being used by this Proxy.
22291 * @return {Connection} The Connection object. This object may be used to subscribe to events on
22292 * a finer-grained basis than the DataProxy events.
22294 getConnection : function(){
22295 return this.useAjax ? Roo.Ajax : this.conn;
22299 * Load data from the configured {@link Roo.data.Connection}, read the data object into
22300 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
22301 * process that block using the passed callback.
22302 * @param {Object} params An object containing properties which are to be used as HTTP parameters
22303 * for the request to the remote server.
22304 * @param {Roo.data.DataReader} reader The Reader object which converts the data
22305 * object into a block of Roo.data.Records.
22306 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
22307 * The function must be passed <ul>
22308 * <li>The Record block object</li>
22309 * <li>The "arg" argument from the load function</li>
22310 * <li>A boolean success indicator</li>
22312 * @param {Object} scope The scope in which to call the callback
22313 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
22315 load : function(params, reader, callback, scope, arg){
22316 if(this.fireEvent("beforeload", this, params) !== false){
22318 params : params || {},
22320 callback : callback,
22325 callback : this.loadResponse,
22329 Roo.applyIf(o, this.conn);
22330 if(this.activeRequest){
22331 Roo.Ajax.abort(this.activeRequest);
22333 this.activeRequest = Roo.Ajax.request(o);
22335 this.conn.request(o);
22338 callback.call(scope||this, null, arg, false);
22343 loadResponse : function(o, success, response){
22344 delete this.activeRequest;
22346 this.fireEvent("loadexception", this, o, response);
22347 o.request.callback.call(o.request.scope, null, o.request.arg, false);
22352 result = o.reader.read(response);
22354 this.fireEvent("loadexception", this, o, response, e);
22355 o.request.callback.call(o.request.scope, null, o.request.arg, false);
22359 this.fireEvent("load", this, o, o.request.arg);
22360 o.request.callback.call(o.request.scope, result, o.request.arg, true);
22364 update : function(dataSet){
22369 updateResponse : function(dataSet){
22374 * Ext JS Library 1.1.1
22375 * Copyright(c) 2006-2007, Ext JS, LLC.
22377 * Originally Released Under LGPL - original licence link has changed is not relivant.
22380 * <script type="text/javascript">
22384 * @class Roo.data.ScriptTagProxy
22385 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
22386 * other than the originating domain of the running page.<br><br>
22388 * <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
22389 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
22391 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
22392 * source code that is used as the source inside a <script> tag.<br><br>
22394 * In order for the browser to process the returned data, the server must wrap the data object
22395 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
22396 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
22397 * depending on whether the callback name was passed:
22400 boolean scriptTag = false;
22401 String cb = request.getParameter("callback");
22404 response.setContentType("text/javascript");
22406 response.setContentType("application/x-json");
22408 Writer out = response.getWriter();
22410 out.write(cb + "(");
22412 out.print(dataBlock.toJsonString());
22419 * @param {Object} config A configuration object.
22421 Roo.data.ScriptTagProxy = function(config){
22422 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
22423 Roo.apply(this, config);
22424 this.head = document.getElementsByTagName("head")[0];
22427 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
22429 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
22431 * @cfg {String} url The URL from which to request the data object.
22434 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
22438 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
22439 * the server the name of the callback function set up by the load call to process the returned data object.
22440 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
22441 * javascript output which calls this named function passing the data object as its only parameter.
22443 callbackParam : "callback",
22445 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
22446 * name to the request.
22451 * Load data from the configured URL, read the data object into
22452 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
22453 * process that block using the passed callback.
22454 * @param {Object} params An object containing properties which are to be used as HTTP parameters
22455 * for the request to the remote server.
22456 * @param {Roo.data.DataReader} reader The Reader object which converts the data
22457 * object into a block of Roo.data.Records.
22458 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
22459 * The function must be passed <ul>
22460 * <li>The Record block object</li>
22461 * <li>The "arg" argument from the load function</li>
22462 * <li>A boolean success indicator</li>
22464 * @param {Object} scope The scope in which to call the callback
22465 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
22467 load : function(params, reader, callback, scope, arg){
22468 if(this.fireEvent("beforeload", this, params) !== false){
22470 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
22472 var url = this.url;
22473 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
22475 url += "&_dc=" + (new Date().getTime());
22477 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
22480 cb : "stcCallback"+transId,
22481 scriptId : "stcScript"+transId,
22485 callback : callback,
22491 window[trans.cb] = function(o){
22492 conn.handleResponse(o, trans);
22495 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
22497 if(this.autoAbort !== false){
22501 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
22503 var script = document.createElement("script");
22504 script.setAttribute("src", url);
22505 script.setAttribute("type", "text/javascript");
22506 script.setAttribute("id", trans.scriptId);
22507 this.head.appendChild(script);
22509 this.trans = trans;
22511 callback.call(scope||this, null, arg, false);
22516 isLoading : function(){
22517 return this.trans ? true : false;
22521 * Abort the current server request.
22523 abort : function(){
22524 if(this.isLoading()){
22525 this.destroyTrans(this.trans);
22530 destroyTrans : function(trans, isLoaded){
22531 this.head.removeChild(document.getElementById(trans.scriptId));
22532 clearTimeout(trans.timeoutId);
22534 window[trans.cb] = undefined;
22536 delete window[trans.cb];
22539 // if hasn't been loaded, wait for load to remove it to prevent script error
22540 window[trans.cb] = function(){
22541 window[trans.cb] = undefined;
22543 delete window[trans.cb];
22550 handleResponse : function(o, trans){
22551 this.trans = false;
22552 this.destroyTrans(trans, true);
22555 result = trans.reader.readRecords(o);
22557 this.fireEvent("loadexception", this, o, trans.arg, e);
22558 trans.callback.call(trans.scope||window, null, trans.arg, false);
22561 this.fireEvent("load", this, o, trans.arg);
22562 trans.callback.call(trans.scope||window, result, trans.arg, true);
22566 handleFailure : function(trans){
22567 this.trans = false;
22568 this.destroyTrans(trans, false);
22569 this.fireEvent("loadexception", this, null, trans.arg);
22570 trans.callback.call(trans.scope||window, null, trans.arg, false);
22574 * Ext JS Library 1.1.1
22575 * Copyright(c) 2006-2007, Ext JS, LLC.
22577 * Originally Released Under LGPL - original licence link has changed is not relivant.
22580 * <script type="text/javascript">
22584 * @class Roo.data.JsonReader
22585 * @extends Roo.data.DataReader
22586 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
22587 * based on mappings in a provided Roo.data.Record constructor.
22589 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
22590 * in the reply previously.
22595 var RecordDef = Roo.data.Record.create([
22596 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
22597 {name: 'occupation'} // This field will use "occupation" as the mapping.
22599 var myReader = new Roo.data.JsonReader({
22600 totalProperty: "results", // The property which contains the total dataset size (optional)
22601 root: "rows", // The property which contains an Array of row objects
22602 id: "id" // The property within each row object that provides an ID for the record (optional)
22606 * This would consume a JSON file like this:
22608 { 'results': 2, 'rows': [
22609 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
22610 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
22613 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
22614 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
22615 * paged from the remote server.
22616 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
22617 * @cfg {String} root name of the property which contains the Array of row objects.
22618 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
22619 * @cfg {Array} fields Array of field definition objects
22621 * Create a new JsonReader
22622 * @param {Object} meta Metadata configuration options
22623 * @param {Object} recordType Either an Array of field definition objects,
22624 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
22626 Roo.data.JsonReader = function(meta, recordType){
22629 // set some defaults:
22630 Roo.applyIf(meta, {
22631 totalProperty: 'total',
22632 successProperty : 'success',
22637 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
22639 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
22642 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
22643 * Used by Store query builder to append _requestMeta to params.
22646 metaFromRemote : false,
22648 * This method is only used by a DataProxy which has retrieved data from a remote server.
22649 * @param {Object} response The XHR object which contains the JSON data in its responseText.
22650 * @return {Object} data A data block which is used by an Roo.data.Store object as
22651 * a cache of Roo.data.Records.
22653 read : function(response){
22654 var json = response.responseText;
22656 var o = /* eval:var:o */ eval("("+json+")");
22658 throw {message: "JsonReader.read: Json object not found"};
22664 this.metaFromRemote = true;
22665 this.meta = o.metaData;
22666 this.recordType = Roo.data.Record.create(o.metaData.fields);
22667 this.onMetaChange(this.meta, this.recordType, o);
22669 return this.readRecords(o);
22672 // private function a store will implement
22673 onMetaChange : function(meta, recordType, o){
22680 simpleAccess: function(obj, subsc) {
22687 getJsonAccessor: function(){
22689 return function(expr) {
22691 return(re.test(expr))
22692 ? new Function("obj", "return obj." + expr)
22697 return Roo.emptyFn;
22702 * Create a data block containing Roo.data.Records from an XML document.
22703 * @param {Object} o An object which contains an Array of row objects in the property specified
22704 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
22705 * which contains the total size of the dataset.
22706 * @return {Object} data A data block which is used by an Roo.data.Store object as
22707 * a cache of Roo.data.Records.
22709 readRecords : function(o){
22711 * After any data loads, the raw JSON data is available for further custom processing.
22715 var s = this.meta, Record = this.recordType,
22716 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
22718 // Generate extraction functions for the totalProperty, the root, the id, and for each field
22720 if(s.totalProperty) {
22721 this.getTotal = this.getJsonAccessor(s.totalProperty);
22723 if(s.successProperty) {
22724 this.getSuccess = this.getJsonAccessor(s.successProperty);
22726 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
22728 var g = this.getJsonAccessor(s.id);
22729 this.getId = function(rec) {
22731 return (r === undefined || r === "") ? null : r;
22734 this.getId = function(){return null;};
22737 for(var jj = 0; jj < fl; jj++){
22739 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
22740 this.ef[jj] = this.getJsonAccessor(map);
22744 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
22745 if(s.totalProperty){
22746 var vt = parseInt(this.getTotal(o), 10);
22751 if(s.successProperty){
22752 var vs = this.getSuccess(o);
22753 if(vs === false || vs === 'false'){
22758 for(var i = 0; i < c; i++){
22761 var id = this.getId(n);
22762 for(var j = 0; j < fl; j++){
22764 var v = this.ef[j](n);
22766 Roo.log('missing convert for ' + f.name);
22770 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
22772 var record = new Record(values, id);
22774 records[i] = record;
22780 totalRecords : totalRecords
22785 * Ext JS Library 1.1.1
22786 * Copyright(c) 2006-2007, Ext JS, LLC.
22788 * Originally Released Under LGPL - original licence link has changed is not relivant.
22791 * <script type="text/javascript">
22795 * @class Roo.data.XmlReader
22796 * @extends Roo.data.DataReader
22797 * Data reader class to create an Array of {@link Roo.data.Record} objects from an XML document
22798 * based on mappings in a provided Roo.data.Record constructor.<br><br>
22800 * <em>Note that in order for the browser to parse a returned XML document, the Content-Type
22801 * header in the HTTP response must be set to "text/xml".</em>
22805 var RecordDef = Roo.data.Record.create([
22806 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
22807 {name: 'occupation'} // This field will use "occupation" as the mapping.
22809 var myReader = new Roo.data.XmlReader({
22810 totalRecords: "results", // The element which contains the total dataset size (optional)
22811 record: "row", // The repeated element which contains row information
22812 id: "id" // The element within the row that provides an ID for the record (optional)
22816 * This would consume an XML file like this:
22820 <results>2</results>
22823 <name>Bill</name>
22824 <occupation>Gardener</occupation>
22828 <name>Ben</name>
22829 <occupation>Horticulturalist</occupation>
22833 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
22834 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
22835 * paged from the remote server.
22836 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
22837 * @cfg {String} success The DomQuery path to the success attribute used by forms.
22838 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
22839 * a record identifier value.
22841 * Create a new XmlReader
22842 * @param {Object} meta Metadata configuration options
22843 * @param {Mixed} recordType The definition of the data record type to produce. This can be either a valid
22844 * Record subclass created with {@link Roo.data.Record#create}, or an array of objects with which to call
22845 * Roo.data.Record.create. See the {@link Roo.data.Record} class for more details.
22847 Roo.data.XmlReader = function(meta, recordType){
22849 Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields);
22851 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
22853 * This method is only used by a DataProxy which has retrieved data from a remote server.
22854 * @param {Object} response The XHR object which contains the parsed XML document. The response is expected
22855 * to contain a method called 'responseXML' that returns an XML document object.
22856 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
22857 * a cache of Roo.data.Records.
22859 read : function(response){
22860 var doc = response.responseXML;
22862 throw {message: "XmlReader.read: XML Document not available"};
22864 return this.readRecords(doc);
22868 * Create a data block containing Roo.data.Records from an XML document.
22869 * @param {Object} doc A parsed XML document.
22870 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
22871 * a cache of Roo.data.Records.
22873 readRecords : function(doc){
22875 * After any data loads/reads, the raw XML Document is available for further custom processing.
22876 * @type XMLDocument
22878 this.xmlData = doc;
22879 var root = doc.documentElement || doc;
22880 var q = Roo.DomQuery;
22881 var recordType = this.recordType, fields = recordType.prototype.fields;
22882 var sid = this.meta.id;
22883 var totalRecords = 0, success = true;
22884 if(this.meta.totalRecords){
22885 totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
22888 if(this.meta.success){
22889 var sv = q.selectValue(this.meta.success, root, true);
22890 success = sv !== false && sv !== 'false';
22893 var ns = q.select(this.meta.record, root);
22894 for(var i = 0, len = ns.length; i < len; i++) {
22897 var id = sid ? q.selectValue(sid, n) : undefined;
22898 for(var j = 0, jlen = fields.length; j < jlen; j++){
22899 var f = fields.items[j];
22900 var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
22902 values[f.name] = v;
22904 var record = new recordType(values, id);
22906 records[records.length] = record;
22912 totalRecords : totalRecords || records.length
22917 * Ext JS Library 1.1.1
22918 * Copyright(c) 2006-2007, Ext JS, LLC.
22920 * Originally Released Under LGPL - original licence link has changed is not relivant.
22923 * <script type="text/javascript">
22927 * @class Roo.data.ArrayReader
22928 * @extends Roo.data.DataReader
22929 * Data reader class to create an Array of Roo.data.Record objects from an Array.
22930 * Each element of that Array represents a row of data fields. The
22931 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
22932 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
22936 var RecordDef = Roo.data.Record.create([
22937 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
22938 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
22940 var myReader = new Roo.data.ArrayReader({
22941 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
22945 * This would consume an Array like this:
22947 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
22949 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
22951 * Create a new JsonReader
22952 * @param {Object} meta Metadata configuration options.
22953 * @param {Object} recordType Either an Array of field definition objects
22954 * as specified to {@link Roo.data.Record#create},
22955 * or an {@link Roo.data.Record} object
22956 * created using {@link Roo.data.Record#create}.
22958 Roo.data.ArrayReader = function(meta, recordType){
22959 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
22962 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
22964 * Create a data block containing Roo.data.Records from an XML document.
22965 * @param {Object} o An Array of row objects which represents the dataset.
22966 * @return {Object} data A data block which is used by an Roo.data.Store object as
22967 * a cache of Roo.data.Records.
22969 readRecords : function(o){
22970 var sid = this.meta ? this.meta.id : null;
22971 var recordType = this.recordType, fields = recordType.prototype.fields;
22974 for(var i = 0; i < root.length; i++){
22977 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
22978 for(var j = 0, jlen = fields.length; j < jlen; j++){
22979 var f = fields.items[j];
22980 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
22981 var v = n[k] !== undefined ? n[k] : f.defaultValue;
22983 values[f.name] = v;
22985 var record = new recordType(values, id);
22987 records[records.length] = record;
22991 totalRecords : records.length
22996 * Ext JS Library 1.1.1
22997 * Copyright(c) 2006-2007, Ext JS, LLC.
22999 * Originally Released Under LGPL - original licence link has changed is not relivant.
23002 * <script type="text/javascript">
23007 * @class Roo.data.Tree
23008 * @extends Roo.util.Observable
23009 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
23010 * in the tree have most standard DOM functionality.
23012 * @param {Node} root (optional) The root node
23014 Roo.data.Tree = function(root){
23015 this.nodeHash = {};
23017 * The root node for this tree
23022 this.setRootNode(root);
23027 * Fires when a new child node is appended to a node in this tree.
23028 * @param {Tree} tree The owner tree
23029 * @param {Node} parent The parent node
23030 * @param {Node} node The newly appended node
23031 * @param {Number} index The index of the newly appended node
23036 * Fires when a child node is removed from a node in this tree.
23037 * @param {Tree} tree The owner tree
23038 * @param {Node} parent The parent node
23039 * @param {Node} node The child node removed
23044 * Fires when a node is moved to a new location in the tree
23045 * @param {Tree} tree The owner tree
23046 * @param {Node} node The node moved
23047 * @param {Node} oldParent The old parent of this node
23048 * @param {Node} newParent The new parent of this node
23049 * @param {Number} index The index it was moved to
23054 * Fires when a new child node is inserted in a node in this tree.
23055 * @param {Tree} tree The owner tree
23056 * @param {Node} parent The parent node
23057 * @param {Node} node The child node inserted
23058 * @param {Node} refNode The child node the node was inserted before
23062 * @event beforeappend
23063 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
23064 * @param {Tree} tree The owner tree
23065 * @param {Node} parent The parent node
23066 * @param {Node} node The child node to be appended
23068 "beforeappend" : true,
23070 * @event beforeremove
23071 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
23072 * @param {Tree} tree The owner tree
23073 * @param {Node} parent The parent node
23074 * @param {Node} node The child node to be removed
23076 "beforeremove" : true,
23078 * @event beforemove
23079 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
23080 * @param {Tree} tree The owner tree
23081 * @param {Node} node The node being moved
23082 * @param {Node} oldParent The parent of the node
23083 * @param {Node} newParent The new parent the node is moving to
23084 * @param {Number} index The index it is being moved to
23086 "beforemove" : true,
23088 * @event beforeinsert
23089 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
23090 * @param {Tree} tree The owner tree
23091 * @param {Node} parent The parent node
23092 * @param {Node} node The child node to be inserted
23093 * @param {Node} refNode The child node the node is being inserted before
23095 "beforeinsert" : true
23098 Roo.data.Tree.superclass.constructor.call(this);
23101 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
23102 pathSeparator: "/",
23104 proxyNodeEvent : function(){
23105 return this.fireEvent.apply(this, arguments);
23109 * Returns the root node for this tree.
23112 getRootNode : function(){
23117 * Sets the root node for this tree.
23118 * @param {Node} node
23121 setRootNode : function(node){
23123 node.ownerTree = this;
23124 node.isRoot = true;
23125 this.registerNode(node);
23130 * Gets a node in this tree by its id.
23131 * @param {String} id
23134 getNodeById : function(id){
23135 return this.nodeHash[id];
23138 registerNode : function(node){
23139 this.nodeHash[node.id] = node;
23142 unregisterNode : function(node){
23143 delete this.nodeHash[node.id];
23146 toString : function(){
23147 return "[Tree"+(this.id?" "+this.id:"")+"]";
23152 * @class Roo.data.Node
23153 * @extends Roo.util.Observable
23154 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
23155 * @cfg {String} id The id for this node. If one is not specified, one is generated.
23157 * @param {Object} attributes The attributes/config for the node
23159 Roo.data.Node = function(attributes){
23161 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
23164 this.attributes = attributes || {};
23165 this.leaf = this.attributes.leaf;
23167 * The node id. @type String
23169 this.id = this.attributes.id;
23171 this.id = Roo.id(null, "ynode-");
23172 this.attributes.id = this.id;
23177 * All child nodes of this node. @type Array
23179 this.childNodes = [];
23180 if(!this.childNodes.indexOf){ // indexOf is a must
23181 this.childNodes.indexOf = function(o){
23182 for(var i = 0, len = this.length; i < len; i++){
23191 * The parent node for this node. @type Node
23193 this.parentNode = null;
23195 * The first direct child node of this node, or null if this node has no child nodes. @type Node
23197 this.firstChild = null;
23199 * The last direct child node of this node, or null if this node has no child nodes. @type Node
23201 this.lastChild = null;
23203 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
23205 this.previousSibling = null;
23207 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
23209 this.nextSibling = null;
23214 * Fires when a new child node is appended
23215 * @param {Tree} tree The owner tree
23216 * @param {Node} this This node
23217 * @param {Node} node The newly appended node
23218 * @param {Number} index The index of the newly appended node
23223 * Fires when a child node is removed
23224 * @param {Tree} tree The owner tree
23225 * @param {Node} this This node
23226 * @param {Node} node The removed node
23231 * Fires when this node is moved to a new location in the tree
23232 * @param {Tree} tree The owner tree
23233 * @param {Node} this This node
23234 * @param {Node} oldParent The old parent of this node
23235 * @param {Node} newParent The new parent of this node
23236 * @param {Number} index The index it was moved to
23241 * Fires when a new child node is inserted.
23242 * @param {Tree} tree The owner tree
23243 * @param {Node} this This node
23244 * @param {Node} node The child node inserted
23245 * @param {Node} refNode The child node the node was inserted before
23249 * @event beforeappend
23250 * Fires before a new child is appended, return false to cancel the append.
23251 * @param {Tree} tree The owner tree
23252 * @param {Node} this This node
23253 * @param {Node} node The child node to be appended
23255 "beforeappend" : true,
23257 * @event beforeremove
23258 * Fires before a child is removed, return false to cancel the remove.
23259 * @param {Tree} tree The owner tree
23260 * @param {Node} this This node
23261 * @param {Node} node The child node to be removed
23263 "beforeremove" : true,
23265 * @event beforemove
23266 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
23267 * @param {Tree} tree The owner tree
23268 * @param {Node} this This node
23269 * @param {Node} oldParent The parent of this node
23270 * @param {Node} newParent The new parent this node is moving to
23271 * @param {Number} index The index it is being moved to
23273 "beforemove" : true,
23275 * @event beforeinsert
23276 * Fires before a new child is inserted, return false to cancel the insert.
23277 * @param {Tree} tree The owner tree
23278 * @param {Node} this This node
23279 * @param {Node} node The child node to be inserted
23280 * @param {Node} refNode The child node the node is being inserted before
23282 "beforeinsert" : true
23284 this.listeners = this.attributes.listeners;
23285 Roo.data.Node.superclass.constructor.call(this);
23288 Roo.extend(Roo.data.Node, Roo.util.Observable, {
23289 fireEvent : function(evtName){
23290 // first do standard event for this node
23291 if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
23294 // then bubble it up to the tree if the event wasn't cancelled
23295 var ot = this.getOwnerTree();
23297 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
23305 * Returns true if this node is a leaf
23306 * @return {Boolean}
23308 isLeaf : function(){
23309 return this.leaf === true;
23313 setFirstChild : function(node){
23314 this.firstChild = node;
23318 setLastChild : function(node){
23319 this.lastChild = node;
23324 * Returns true if this node is the last child of its parent
23325 * @return {Boolean}
23327 isLast : function(){
23328 return (!this.parentNode ? true : this.parentNode.lastChild == this);
23332 * Returns true if this node is the first child of its parent
23333 * @return {Boolean}
23335 isFirst : function(){
23336 return (!this.parentNode ? true : this.parentNode.firstChild == this);
23339 hasChildNodes : function(){
23340 return !this.isLeaf() && this.childNodes.length > 0;
23344 * Insert node(s) as the last child node of this node.
23345 * @param {Node/Array} node The node or Array of nodes to append
23346 * @return {Node} The appended node if single append, or null if an array was passed
23348 appendChild : function(node){
23350 if(node instanceof Array){
23352 }else if(arguments.length > 1){
23355 // if passed an array or multiple args do them one by one
23357 for(var i = 0, len = multi.length; i < len; i++) {
23358 this.appendChild(multi[i]);
23361 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
23364 var index = this.childNodes.length;
23365 var oldParent = node.parentNode;
23366 // it's a move, make sure we move it cleanly
23368 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
23371 oldParent.removeChild(node);
23373 index = this.childNodes.length;
23375 this.setFirstChild(node);
23377 this.childNodes.push(node);
23378 node.parentNode = this;
23379 var ps = this.childNodes[index-1];
23381 node.previousSibling = ps;
23382 ps.nextSibling = node;
23384 node.previousSibling = null;
23386 node.nextSibling = null;
23387 this.setLastChild(node);
23388 node.setOwnerTree(this.getOwnerTree());
23389 this.fireEvent("append", this.ownerTree, this, node, index);
23391 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
23398 * Removes a child node from this node.
23399 * @param {Node} node The node to remove
23400 * @return {Node} The removed node
23402 removeChild : function(node){
23403 var index = this.childNodes.indexOf(node);
23407 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
23411 // remove it from childNodes collection
23412 this.childNodes.splice(index, 1);
23415 if(node.previousSibling){
23416 node.previousSibling.nextSibling = node.nextSibling;
23418 if(node.nextSibling){
23419 node.nextSibling.previousSibling = node.previousSibling;
23422 // update child refs
23423 if(this.firstChild == node){
23424 this.setFirstChild(node.nextSibling);
23426 if(this.lastChild == node){
23427 this.setLastChild(node.previousSibling);
23430 node.setOwnerTree(null);
23431 // clear any references from the node
23432 node.parentNode = null;
23433 node.previousSibling = null;
23434 node.nextSibling = null;
23435 this.fireEvent("remove", this.ownerTree, this, node);
23440 * Inserts the first node before the second node in this nodes childNodes collection.
23441 * @param {Node} node The node to insert
23442 * @param {Node} refNode The node to insert before (if null the node is appended)
23443 * @return {Node} The inserted node
23445 insertBefore : function(node, refNode){
23446 if(!refNode){ // like standard Dom, refNode can be null for append
23447 return this.appendChild(node);
23450 if(node == refNode){
23454 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
23457 var index = this.childNodes.indexOf(refNode);
23458 var oldParent = node.parentNode;
23459 var refIndex = index;
23461 // when moving internally, indexes will change after remove
23462 if(oldParent == this && this.childNodes.indexOf(node) < index){
23466 // it's a move, make sure we move it cleanly
23468 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
23471 oldParent.removeChild(node);
23474 this.setFirstChild(node);
23476 this.childNodes.splice(refIndex, 0, node);
23477 node.parentNode = this;
23478 var ps = this.childNodes[refIndex-1];
23480 node.previousSibling = ps;
23481 ps.nextSibling = node;
23483 node.previousSibling = null;
23485 node.nextSibling = refNode;
23486 refNode.previousSibling = node;
23487 node.setOwnerTree(this.getOwnerTree());
23488 this.fireEvent("insert", this.ownerTree, this, node, refNode);
23490 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
23496 * Returns the child node at the specified index.
23497 * @param {Number} index
23500 item : function(index){
23501 return this.childNodes[index];
23505 * Replaces one child node in this node with another.
23506 * @param {Node} newChild The replacement node
23507 * @param {Node} oldChild The node to replace
23508 * @return {Node} The replaced node
23510 replaceChild : function(newChild, oldChild){
23511 this.insertBefore(newChild, oldChild);
23512 this.removeChild(oldChild);
23517 * Returns the index of a child node
23518 * @param {Node} node
23519 * @return {Number} The index of the node or -1 if it was not found
23521 indexOf : function(child){
23522 return this.childNodes.indexOf(child);
23526 * Returns the tree this node is in.
23529 getOwnerTree : function(){
23530 // if it doesn't have one, look for one
23531 if(!this.ownerTree){
23535 this.ownerTree = p.ownerTree;
23541 return this.ownerTree;
23545 * Returns depth of this node (the root node has a depth of 0)
23548 getDepth : function(){
23551 while(p.parentNode){
23559 setOwnerTree : function(tree){
23560 // if it's move, we need to update everyone
23561 if(tree != this.ownerTree){
23562 if(this.ownerTree){
23563 this.ownerTree.unregisterNode(this);
23565 this.ownerTree = tree;
23566 var cs = this.childNodes;
23567 for(var i = 0, len = cs.length; i < len; i++) {
23568 cs[i].setOwnerTree(tree);
23571 tree.registerNode(this);
23577 * Returns the path for this node. The path can be used to expand or select this node programmatically.
23578 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
23579 * @return {String} The path
23581 getPath : function(attr){
23582 attr = attr || "id";
23583 var p = this.parentNode;
23584 var b = [this.attributes[attr]];
23586 b.unshift(p.attributes[attr]);
23589 var sep = this.getOwnerTree().pathSeparator;
23590 return sep + b.join(sep);
23594 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
23595 * function call will be the scope provided or the current node. The arguments to the function
23596 * will be the args provided or the current node. If the function returns false at any point,
23597 * the bubble is stopped.
23598 * @param {Function} fn The function to call
23599 * @param {Object} scope (optional) The scope of the function (defaults to current node)
23600 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
23602 bubble : function(fn, scope, args){
23605 if(fn.call(scope || p, args || p) === false){
23613 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
23614 * function call will be the scope provided or the current node. The arguments to the function
23615 * will be the args provided or the current node. If the function returns false at any point,
23616 * the cascade is stopped on that branch.
23617 * @param {Function} fn The function to call
23618 * @param {Object} scope (optional) The scope of the function (defaults to current node)
23619 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
23621 cascade : function(fn, scope, args){
23622 if(fn.call(scope || this, args || this) !== false){
23623 var cs = this.childNodes;
23624 for(var i = 0, len = cs.length; i < len; i++) {
23625 cs[i].cascade(fn, scope, args);
23631 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
23632 * function call will be the scope provided or the current node. The arguments to the function
23633 * will be the args provided or the current node. If the function returns false at any point,
23634 * the iteration stops.
23635 * @param {Function} fn The function to call
23636 * @param {Object} scope (optional) The scope of the function (defaults to current node)
23637 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
23639 eachChild : function(fn, scope, args){
23640 var cs = this.childNodes;
23641 for(var i = 0, len = cs.length; i < len; i++) {
23642 if(fn.call(scope || this, args || cs[i]) === false){
23649 * Finds the first child that has the attribute with the specified value.
23650 * @param {String} attribute The attribute name
23651 * @param {Mixed} value The value to search for
23652 * @return {Node} The found child or null if none was found
23654 findChild : function(attribute, value){
23655 var cs = this.childNodes;
23656 for(var i = 0, len = cs.length; i < len; i++) {
23657 if(cs[i].attributes[attribute] == value){
23665 * Finds the first child by a custom function. The child matches if the function passed
23667 * @param {Function} fn
23668 * @param {Object} scope (optional)
23669 * @return {Node} The found child or null if none was found
23671 findChildBy : function(fn, scope){
23672 var cs = this.childNodes;
23673 for(var i = 0, len = cs.length; i < len; i++) {
23674 if(fn.call(scope||cs[i], cs[i]) === true){
23682 * Sorts this nodes children using the supplied sort function
23683 * @param {Function} fn
23684 * @param {Object} scope (optional)
23686 sort : function(fn, scope){
23687 var cs = this.childNodes;
23688 var len = cs.length;
23690 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
23692 for(var i = 0; i < len; i++){
23694 n.previousSibling = cs[i-1];
23695 n.nextSibling = cs[i+1];
23697 this.setFirstChild(n);
23700 this.setLastChild(n);
23707 * Returns true if this node is an ancestor (at any point) of the passed node.
23708 * @param {Node} node
23709 * @return {Boolean}
23711 contains : function(node){
23712 return node.isAncestor(this);
23716 * Returns true if the passed node is an ancestor (at any point) of this node.
23717 * @param {Node} node
23718 * @return {Boolean}
23720 isAncestor : function(node){
23721 var p = this.parentNode;
23731 toString : function(){
23732 return "[Node"+(this.id?" "+this.id:"")+"]";
23736 * Ext JS Library 1.1.1
23737 * Copyright(c) 2006-2007, Ext JS, LLC.
23739 * Originally Released Under LGPL - original licence link has changed is not relivant.
23742 * <script type="text/javascript">
23747 * @extends Roo.Element
23748 * An extended {@link Roo.Element} object that supports a shadow and shim, constrain to viewport and
23749 * automatic maintaining of shadow/shim positions.
23750 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
23751 * @cfg {String/Boolean} shadow True to create a shadow element with default class "x-layer-shadow", or
23752 * you can pass a string with a CSS class name. False turns off the shadow.
23753 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: "div", cls: "x-layer"}).
23754 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
23755 * @cfg {String} cls CSS class to add to the element
23756 * @cfg {Number} zindex Starting z-index (defaults to 11000)
23757 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 3)
23759 * @param {Object} config An object with config options.
23760 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
23763 Roo.Layer = function(config, existingEl){
23764 config = config || {};
23765 var dh = Roo.DomHelper;
23766 var cp = config.parentEl, pel = cp ? Roo.getDom(cp) : document.body;
23768 this.dom = Roo.getDom(existingEl);
23771 var o = config.dh || {tag: "div", cls: "x-layer"};
23772 this.dom = dh.append(pel, o);
23775 this.addClass(config.cls);
23777 this.constrain = config.constrain !== false;
23778 this.visibilityMode = Roo.Element.VISIBILITY;
23780 this.id = this.dom.id = config.id;
23782 this.id = Roo.id(this.dom);
23784 this.zindex = config.zindex || this.getZIndex();
23785 this.position("absolute", this.zindex);
23787 this.shadowOffset = config.shadowOffset || 4;
23788 this.shadow = new Roo.Shadow({
23789 offset : this.shadowOffset,
23790 mode : config.shadow
23793 this.shadowOffset = 0;
23795 this.useShim = config.shim !== false && Roo.useShims;
23796 this.useDisplay = config.useDisplay;
23800 var supr = Roo.Element.prototype;
23802 // shims are shared among layer to keep from having 100 iframes
23805 Roo.extend(Roo.Layer, Roo.Element, {
23807 getZIndex : function(){
23808 return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
23811 getShim : function(){
23818 var shim = shims.shift();
23820 shim = this.createShim();
23821 shim.enableDisplayMode('block');
23822 shim.dom.style.display = 'none';
23823 shim.dom.style.visibility = 'visible';
23825 var pn = this.dom.parentNode;
23826 if(shim.dom.parentNode != pn){
23827 pn.insertBefore(shim.dom, this.dom);
23829 shim.setStyle('z-index', this.getZIndex()-2);
23834 hideShim : function(){
23836 this.shim.setDisplayed(false);
23837 shims.push(this.shim);
23842 disableShadow : function(){
23844 this.shadowDisabled = true;
23845 this.shadow.hide();
23846 this.lastShadowOffset = this.shadowOffset;
23847 this.shadowOffset = 0;
23851 enableShadow : function(show){
23853 this.shadowDisabled = false;
23854 this.shadowOffset = this.lastShadowOffset;
23855 delete this.lastShadowOffset;
23863 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
23864 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
23865 sync : function(doShow){
23866 var sw = this.shadow;
23867 if(!this.updating && this.isVisible() && (sw || this.useShim)){
23868 var sh = this.getShim();
23870 var w = this.getWidth(),
23871 h = this.getHeight();
23873 var l = this.getLeft(true),
23874 t = this.getTop(true);
23876 if(sw && !this.shadowDisabled){
23877 if(doShow && !sw.isVisible()){
23880 sw.realign(l, t, w, h);
23886 // fit the shim behind the shadow, so it is shimmed too
23887 var a = sw.adjusts, s = sh.dom.style;
23888 s.left = (Math.min(l, l+a.l))+"px";
23889 s.top = (Math.min(t, t+a.t))+"px";
23890 s.width = (w+a.w)+"px";
23891 s.height = (h+a.h)+"px";
23898 sh.setLeftTop(l, t);
23905 destroy : function(){
23908 this.shadow.hide();
23910 this.removeAllListeners();
23911 var pn = this.dom.parentNode;
23913 pn.removeChild(this.dom);
23915 Roo.Element.uncache(this.id);
23918 remove : function(){
23923 beginUpdate : function(){
23924 this.updating = true;
23928 endUpdate : function(){
23929 this.updating = false;
23934 hideUnders : function(negOffset){
23936 this.shadow.hide();
23942 constrainXY : function(){
23943 if(this.constrain){
23944 var vw = Roo.lib.Dom.getViewWidth(),
23945 vh = Roo.lib.Dom.getViewHeight();
23946 var s = Roo.get(document).getScroll();
23948 var xy = this.getXY();
23949 var x = xy[0], y = xy[1];
23950 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
23951 // only move it if it needs it
23953 // first validate right/bottom
23954 if((x + w) > vw+s.left){
23955 x = vw - w - this.shadowOffset;
23958 if((y + h) > vh+s.top){
23959 y = vh - h - this.shadowOffset;
23962 // then make sure top/left isn't negative
23973 var ay = this.avoidY;
23974 if(y <= ay && (y+h) >= ay){
23980 supr.setXY.call(this, xy);
23986 isVisible : function(){
23987 return this.visible;
23991 showAction : function(){
23992 this.visible = true; // track visibility to prevent getStyle calls
23993 if(this.useDisplay === true){
23994 this.setDisplayed("");
23995 }else if(this.lastXY){
23996 supr.setXY.call(this, this.lastXY);
23997 }else if(this.lastLT){
23998 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
24003 hideAction : function(){
24004 this.visible = false;
24005 if(this.useDisplay === true){
24006 this.setDisplayed(false);
24008 this.setLeftTop(-10000,-10000);
24012 // overridden Element method
24013 setVisible : function(v, a, d, c, e){
24018 var cb = function(){
24023 }.createDelegate(this);
24024 supr.setVisible.call(this, true, true, d, cb, e);
24027 this.hideUnders(true);
24036 }.createDelegate(this);
24038 supr.setVisible.call(this, v, a, d, cb, e);
24047 storeXY : function(xy){
24048 delete this.lastLT;
24052 storeLeftTop : function(left, top){
24053 delete this.lastXY;
24054 this.lastLT = [left, top];
24058 beforeFx : function(){
24059 this.beforeAction();
24060 return Roo.Layer.superclass.beforeFx.apply(this, arguments);
24064 afterFx : function(){
24065 Roo.Layer.superclass.afterFx.apply(this, arguments);
24066 this.sync(this.isVisible());
24070 beforeAction : function(){
24071 if(!this.updating && this.shadow){
24072 this.shadow.hide();
24076 // overridden Element method
24077 setLeft : function(left){
24078 this.storeLeftTop(left, this.getTop(true));
24079 supr.setLeft.apply(this, arguments);
24083 setTop : function(top){
24084 this.storeLeftTop(this.getLeft(true), top);
24085 supr.setTop.apply(this, arguments);
24089 setLeftTop : function(left, top){
24090 this.storeLeftTop(left, top);
24091 supr.setLeftTop.apply(this, arguments);
24095 setXY : function(xy, a, d, c, e){
24097 this.beforeAction();
24099 var cb = this.createCB(c);
24100 supr.setXY.call(this, xy, a, d, cb, e);
24107 createCB : function(c){
24118 // overridden Element method
24119 setX : function(x, a, d, c, e){
24120 this.setXY([x, this.getY()], a, d, c, e);
24123 // overridden Element method
24124 setY : function(y, a, d, c, e){
24125 this.setXY([this.getX(), y], a, d, c, e);
24128 // overridden Element method
24129 setSize : function(w, h, a, d, c, e){
24130 this.beforeAction();
24131 var cb = this.createCB(c);
24132 supr.setSize.call(this, w, h, a, d, cb, e);
24138 // overridden Element method
24139 setWidth : function(w, a, d, c, e){
24140 this.beforeAction();
24141 var cb = this.createCB(c);
24142 supr.setWidth.call(this, w, a, d, cb, e);
24148 // overridden Element method
24149 setHeight : function(h, a, d, c, e){
24150 this.beforeAction();
24151 var cb = this.createCB(c);
24152 supr.setHeight.call(this, h, a, d, cb, e);
24158 // overridden Element method
24159 setBounds : function(x, y, w, h, a, d, c, e){
24160 this.beforeAction();
24161 var cb = this.createCB(c);
24163 this.storeXY([x, y]);
24164 supr.setXY.call(this, [x, y]);
24165 supr.setSize.call(this, w, h, a, d, cb, e);
24168 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
24174 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
24175 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
24176 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
24177 * @param {Number} zindex The new z-index to set
24178 * @return {this} The Layer
24180 setZIndex : function(zindex){
24181 this.zindex = zindex;
24182 this.setStyle("z-index", zindex + 2);
24184 this.shadow.setZIndex(zindex + 1);
24187 this.shim.setStyle("z-index", zindex);
24193 * Ext JS Library 1.1.1
24194 * Copyright(c) 2006-2007, Ext JS, LLC.
24196 * Originally Released Under LGPL - original licence link has changed is not relivant.
24199 * <script type="text/javascript">
24204 * @class Roo.Shadow
24205 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
24206 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
24207 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
24209 * Create a new Shadow
24210 * @param {Object} config The config object
24212 Roo.Shadow = function(config){
24213 Roo.apply(this, config);
24214 if(typeof this.mode != "string"){
24215 this.mode = this.defaultMode;
24217 var o = this.offset, a = {h: 0};
24218 var rad = Math.floor(this.offset/2);
24219 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
24225 a.l -= this.offset + rad;
24226 a.t -= this.offset + rad;
24237 a.l -= (this.offset - rad);
24238 a.t -= this.offset + rad;
24240 a.w -= (this.offset - rad)*2;
24251 a.l -= (this.offset - rad);
24252 a.t -= (this.offset - rad);
24254 a.w -= (this.offset + rad + 1);
24255 a.h -= (this.offset + rad);
24264 Roo.Shadow.prototype = {
24266 * @cfg {String} mode
24267 * The shadow display mode. Supports the following options:<br />
24268 * sides: Shadow displays on both sides and bottom only<br />
24269 * frame: Shadow displays equally on all four sides<br />
24270 * drop: Traditional bottom-right drop shadow (default)
24273 * @cfg {String} offset
24274 * The number of pixels to offset the shadow from the element (defaults to 4)
24279 defaultMode: "drop",
24282 * Displays the shadow under the target element
24283 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
24285 show : function(target){
24286 target = Roo.get(target);
24288 this.el = Roo.Shadow.Pool.pull();
24289 if(this.el.dom.nextSibling != target.dom){
24290 this.el.insertBefore(target);
24293 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
24295 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
24298 target.getLeft(true),
24299 target.getTop(true),
24303 this.el.dom.style.display = "block";
24307 * Returns true if the shadow is visible, else false
24309 isVisible : function(){
24310 return this.el ? true : false;
24314 * Direct alignment when values are already available. Show must be called at least once before
24315 * calling this method to ensure it is initialized.
24316 * @param {Number} left The target element left position
24317 * @param {Number} top The target element top position
24318 * @param {Number} width The target element width
24319 * @param {Number} height The target element height
24321 realign : function(l, t, w, h){
24325 var a = this.adjusts, d = this.el.dom, s = d.style;
24327 s.left = (l+a.l)+"px";
24328 s.top = (t+a.t)+"px";
24329 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
24331 if(s.width != sws || s.height != shs){
24335 var cn = d.childNodes;
24336 var sww = Math.max(0, (sw-12))+"px";
24337 cn[0].childNodes[1].style.width = sww;
24338 cn[1].childNodes[1].style.width = sww;
24339 cn[2].childNodes[1].style.width = sww;
24340 cn[1].style.height = Math.max(0, (sh-12))+"px";
24346 * Hides this shadow
24350 this.el.dom.style.display = "none";
24351 Roo.Shadow.Pool.push(this.el);
24357 * Adjust the z-index of this shadow
24358 * @param {Number} zindex The new z-index
24360 setZIndex : function(z){
24363 this.el.setStyle("z-index", z);
24368 // Private utility class that manages the internal Shadow cache
24369 Roo.Shadow.Pool = function(){
24371 var markup = Roo.isIE ?
24372 '<div class="x-ie-shadow"></div>' :
24373 '<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>';
24376 var sh = p.shift();
24378 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
24379 sh.autoBoxAdjust = false;
24384 push : function(sh){
24390 * Ext JS Library 1.1.1
24391 * Copyright(c) 2006-2007, Ext JS, LLC.
24393 * Originally Released Under LGPL - original licence link has changed is not relivant.
24396 * <script type="text/javascript">
24401 * @class Roo.SplitBar
24402 * @extends Roo.util.Observable
24403 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
24407 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
24408 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
24409 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
24410 split.minSize = 100;
24411 split.maxSize = 600;
24412 split.animate = true;
24413 split.on('moved', splitterMoved);
24416 * Create a new SplitBar
24417 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
24418 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
24419 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
24420 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
24421 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
24422 position of the SplitBar).
24424 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
24427 this.el = Roo.get(dragElement, true);
24428 this.el.dom.unselectable = "on";
24430 this.resizingEl = Roo.get(resizingElement, true);
24434 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
24435 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
24438 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
24441 * The minimum size of the resizing element. (Defaults to 0)
24447 * The maximum size of the resizing element. (Defaults to 2000)
24450 this.maxSize = 2000;
24453 * Whether to animate the transition to the new size
24456 this.animate = false;
24459 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
24462 this.useShim = false;
24467 if(!existingProxy){
24469 this.proxy = Roo.SplitBar.createProxy(this.orientation);
24471 this.proxy = Roo.get(existingProxy).dom;
24474 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
24477 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
24480 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
24483 this.dragSpecs = {};
24486 * @private The adapter to use to positon and resize elements
24488 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
24489 this.adapter.init(this);
24491 if(this.orientation == Roo.SplitBar.HORIZONTAL){
24493 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
24494 this.el.addClass("x-splitbar-h");
24497 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
24498 this.el.addClass("x-splitbar-v");
24504 * Fires when the splitter is moved (alias for {@link #event-moved})
24505 * @param {Roo.SplitBar} this
24506 * @param {Number} newSize the new width or height
24511 * Fires when the splitter is moved
24512 * @param {Roo.SplitBar} this
24513 * @param {Number} newSize the new width or height
24517 * @event beforeresize
24518 * Fires before the splitter is dragged
24519 * @param {Roo.SplitBar} this
24521 "beforeresize" : true,
24523 "beforeapply" : true
24526 Roo.util.Observable.call(this);
24529 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
24530 onStartProxyDrag : function(x, y){
24531 this.fireEvent("beforeresize", this);
24533 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
24535 o.enableDisplayMode("block");
24536 // all splitbars share the same overlay
24537 Roo.SplitBar.prototype.overlay = o;
24539 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
24540 this.overlay.show();
24541 Roo.get(this.proxy).setDisplayed("block");
24542 var size = this.adapter.getElementSize(this);
24543 this.activeMinSize = this.getMinimumSize();;
24544 this.activeMaxSize = this.getMaximumSize();;
24545 var c1 = size - this.activeMinSize;
24546 var c2 = Math.max(this.activeMaxSize - size, 0);
24547 if(this.orientation == Roo.SplitBar.HORIZONTAL){
24548 this.dd.resetConstraints();
24549 this.dd.setXConstraint(
24550 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
24551 this.placement == Roo.SplitBar.LEFT ? c2 : c1
24553 this.dd.setYConstraint(0, 0);
24555 this.dd.resetConstraints();
24556 this.dd.setXConstraint(0, 0);
24557 this.dd.setYConstraint(
24558 this.placement == Roo.SplitBar.TOP ? c1 : c2,
24559 this.placement == Roo.SplitBar.TOP ? c2 : c1
24562 this.dragSpecs.startSize = size;
24563 this.dragSpecs.startPoint = [x, y];
24564 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
24568 * @private Called after the drag operation by the DDProxy
24570 onEndProxyDrag : function(e){
24571 Roo.get(this.proxy).setDisplayed(false);
24572 var endPoint = Roo.lib.Event.getXY(e);
24574 this.overlay.hide();
24577 if(this.orientation == Roo.SplitBar.HORIZONTAL){
24578 newSize = this.dragSpecs.startSize +
24579 (this.placement == Roo.SplitBar.LEFT ?
24580 endPoint[0] - this.dragSpecs.startPoint[0] :
24581 this.dragSpecs.startPoint[0] - endPoint[0]
24584 newSize = this.dragSpecs.startSize +
24585 (this.placement == Roo.SplitBar.TOP ?
24586 endPoint[1] - this.dragSpecs.startPoint[1] :
24587 this.dragSpecs.startPoint[1] - endPoint[1]
24590 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
24591 if(newSize != this.dragSpecs.startSize){
24592 if(this.fireEvent('beforeapply', this, newSize) !== false){
24593 this.adapter.setElementSize(this, newSize);
24594 this.fireEvent("moved", this, newSize);
24595 this.fireEvent("resize", this, newSize);
24601 * Get the adapter this SplitBar uses
24602 * @return The adapter object
24604 getAdapter : function(){
24605 return this.adapter;
24609 * Set the adapter this SplitBar uses
24610 * @param {Object} adapter A SplitBar adapter object
24612 setAdapter : function(adapter){
24613 this.adapter = adapter;
24614 this.adapter.init(this);
24618 * Gets the minimum size for the resizing element
24619 * @return {Number} The minimum size
24621 getMinimumSize : function(){
24622 return this.minSize;
24626 * Sets the minimum size for the resizing element
24627 * @param {Number} minSize The minimum size
24629 setMinimumSize : function(minSize){
24630 this.minSize = minSize;
24634 * Gets the maximum size for the resizing element
24635 * @return {Number} The maximum size
24637 getMaximumSize : function(){
24638 return this.maxSize;
24642 * Sets the maximum size for the resizing element
24643 * @param {Number} maxSize The maximum size
24645 setMaximumSize : function(maxSize){
24646 this.maxSize = maxSize;
24650 * Sets the initialize size for the resizing element
24651 * @param {Number} size The initial size
24653 setCurrentSize : function(size){
24654 var oldAnimate = this.animate;
24655 this.animate = false;
24656 this.adapter.setElementSize(this, size);
24657 this.animate = oldAnimate;
24661 * Destroy this splitbar.
24662 * @param {Boolean} removeEl True to remove the element
24664 destroy : function(removeEl){
24666 this.shim.remove();
24669 this.proxy.parentNode.removeChild(this.proxy);
24677 * @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.
24679 Roo.SplitBar.createProxy = function(dir){
24680 var proxy = new Roo.Element(document.createElement("div"));
24681 proxy.unselectable();
24682 var cls = 'x-splitbar-proxy';
24683 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
24684 document.body.appendChild(proxy.dom);
24689 * @class Roo.SplitBar.BasicLayoutAdapter
24690 * Default Adapter. It assumes the splitter and resizing element are not positioned
24691 * elements and only gets/sets the width of the element. Generally used for table based layouts.
24693 Roo.SplitBar.BasicLayoutAdapter = function(){
24696 Roo.SplitBar.BasicLayoutAdapter.prototype = {
24697 // do nothing for now
24698 init : function(s){
24702 * Called before drag operations to get the current size of the resizing element.
24703 * @param {Roo.SplitBar} s The SplitBar using this adapter
24705 getElementSize : function(s){
24706 if(s.orientation == Roo.SplitBar.HORIZONTAL){
24707 return s.resizingEl.getWidth();
24709 return s.resizingEl.getHeight();
24714 * Called after drag operations to set the size of the resizing element.
24715 * @param {Roo.SplitBar} s The SplitBar using this adapter
24716 * @param {Number} newSize The new size to set
24717 * @param {Function} onComplete A function to be invoked when resizing is complete
24719 setElementSize : function(s, newSize, onComplete){
24720 if(s.orientation == Roo.SplitBar.HORIZONTAL){
24722 s.resizingEl.setWidth(newSize);
24724 onComplete(s, newSize);
24727 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
24732 s.resizingEl.setHeight(newSize);
24734 onComplete(s, newSize);
24737 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
24744 *@class Roo.SplitBar.AbsoluteLayoutAdapter
24745 * @extends Roo.SplitBar.BasicLayoutAdapter
24746 * Adapter that moves the splitter element to align with the resized sizing element.
24747 * Used with an absolute positioned SplitBar.
24748 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
24749 * document.body, make sure you assign an id to the body element.
24751 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
24752 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
24753 this.container = Roo.get(container);
24756 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
24757 init : function(s){
24758 this.basic.init(s);
24761 getElementSize : function(s){
24762 return this.basic.getElementSize(s);
24765 setElementSize : function(s, newSize, onComplete){
24766 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
24769 moveSplitter : function(s){
24770 var yes = Roo.SplitBar;
24771 switch(s.placement){
24773 s.el.setX(s.resizingEl.getRight());
24776 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
24779 s.el.setY(s.resizingEl.getBottom());
24782 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
24789 * Orientation constant - Create a vertical SplitBar
24793 Roo.SplitBar.VERTICAL = 1;
24796 * Orientation constant - Create a horizontal SplitBar
24800 Roo.SplitBar.HORIZONTAL = 2;
24803 * Placement constant - The resizing element is to the left of the splitter element
24807 Roo.SplitBar.LEFT = 1;
24810 * Placement constant - The resizing element is to the right of the splitter element
24814 Roo.SplitBar.RIGHT = 2;
24817 * Placement constant - The resizing element is positioned above the splitter element
24821 Roo.SplitBar.TOP = 3;
24824 * Placement constant - The resizing element is positioned under splitter element
24828 Roo.SplitBar.BOTTOM = 4;
24831 * Ext JS Library 1.1.1
24832 * Copyright(c) 2006-2007, Ext JS, LLC.
24834 * Originally Released Under LGPL - original licence link has changed is not relivant.
24837 * <script type="text/javascript">
24842 * @extends Roo.util.Observable
24843 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
24844 * This class also supports single and multi selection modes. <br>
24845 * Create a data model bound view:
24847 var store = new Roo.data.Store(...);
24849 var view = new Roo.View({
24851 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
24853 singleSelect: true,
24854 selectedClass: "ydataview-selected",
24858 // listen for node click?
24859 view.on("click", function(vw, index, node, e){
24860 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
24864 dataModel.load("foobar.xml");
24866 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
24868 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
24869 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
24871 * Note: old style constructor is still suported (container, template, config)
24874 * Create a new View
24875 * @param {Object} config The config object
24878 Roo.View = function(config, depreciated_tpl, depreciated_config){
24880 this.parent = false;
24882 if (typeof(depreciated_tpl) == 'undefined') {
24883 // new way.. - universal constructor.
24884 Roo.apply(this, config);
24885 this.el = Roo.get(this.el);
24888 this.el = Roo.get(config);
24889 this.tpl = depreciated_tpl;
24890 Roo.apply(this, depreciated_config);
24892 this.wrapEl = this.el.wrap().wrap();
24893 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
24896 if(typeof(this.tpl) == "string"){
24897 this.tpl = new Roo.Template(this.tpl);
24899 // support xtype ctors..
24900 this.tpl = new Roo.factory(this.tpl, Roo);
24904 this.tpl.compile();
24909 * @event beforeclick
24910 * Fires before a click is processed. Returns false to cancel the default action.
24911 * @param {Roo.View} this
24912 * @param {Number} index The index of the target node
24913 * @param {HTMLElement} node The target node
24914 * @param {Roo.EventObject} e The raw event object
24916 "beforeclick" : true,
24919 * Fires when a template node is clicked.
24920 * @param {Roo.View} this
24921 * @param {Number} index The index of the target node
24922 * @param {HTMLElement} node The target node
24923 * @param {Roo.EventObject} e The raw event object
24928 * Fires when a template node is double clicked.
24929 * @param {Roo.View} this
24930 * @param {Number} index The index of the target node
24931 * @param {HTMLElement} node The target node
24932 * @param {Roo.EventObject} e The raw event object
24936 * @event contextmenu
24937 * Fires when a template node is right clicked.
24938 * @param {Roo.View} this
24939 * @param {Number} index The index of the target node
24940 * @param {HTMLElement} node The target node
24941 * @param {Roo.EventObject} e The raw event object
24943 "contextmenu" : true,
24945 * @event selectionchange
24946 * Fires when the selected nodes change.
24947 * @param {Roo.View} this
24948 * @param {Array} selections Array of the selected nodes
24950 "selectionchange" : true,
24953 * @event beforeselect
24954 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
24955 * @param {Roo.View} this
24956 * @param {HTMLElement} node The node to be selected
24957 * @param {Array} selections Array of currently selected nodes
24959 "beforeselect" : true,
24961 * @event preparedata
24962 * Fires on every row to render, to allow you to change the data.
24963 * @param {Roo.View} this
24964 * @param {Object} data to be rendered (change this)
24966 "preparedata" : true
24974 "click": this.onClick,
24975 "dblclick": this.onDblClick,
24976 "contextmenu": this.onContextMenu,
24980 this.selections = [];
24982 this.cmp = new Roo.CompositeElementLite([]);
24984 this.store = Roo.factory(this.store, Roo.data);
24985 this.setStore(this.store, true);
24988 if ( this.footer && this.footer.xtype) {
24990 var fctr = this.wrapEl.appendChild(document.createElement("div"));
24992 this.footer.dataSource = this.store
24993 this.footer.container = fctr;
24994 this.footer = Roo.factory(this.footer, Roo);
24995 fctr.insertFirst(this.el);
24997 // this is a bit insane - as the paging toolbar seems to detach the el..
24998 // dom.parentNode.parentNode.parentNode
24999 // they get detached?
25003 Roo.View.superclass.constructor.call(this);
25008 Roo.extend(Roo.View, Roo.util.Observable, {
25011 * @cfg {Roo.data.Store} store Data store to load data from.
25016 * @cfg {String|Roo.Element} el The container element.
25021 * @cfg {String|Roo.Template} tpl The template used by this View
25025 * @cfg {String} dataName the named area of the template to use as the data area
25026 * Works with domtemplates roo-name="name"
25030 * @cfg {String} selectedClass The css class to add to selected nodes
25032 selectedClass : "x-view-selected",
25034 * @cfg {String} emptyText The empty text to show when nothing is loaded.
25039 * @cfg {String} text to display on mask (default Loading)
25043 * @cfg {Boolean} multiSelect Allow multiple selection
25045 multiSelect : false,
25047 * @cfg {Boolean} singleSelect Allow single selection
25049 singleSelect: false,
25052 * @cfg {Boolean} toggleSelect - selecting
25054 toggleSelect : false,
25057 * @cfg {Boolean} tickable - selecting
25062 * Returns the element this view is bound to.
25063 * @return {Roo.Element}
25065 getEl : function(){
25066 return this.wrapEl;
25072 * Refreshes the view. - called by datachanged on the store. - do not call directly.
25074 refresh : function(){
25075 //Roo.log('refresh');
25078 // if we are using something like 'domtemplate', then
25079 // the what gets used is:
25080 // t.applySubtemplate(NAME, data, wrapping data..)
25081 // the outer template then get' applied with
25082 // the store 'extra data'
25083 // and the body get's added to the
25084 // roo-name="data" node?
25085 // <span class='roo-tpl-{name}'></span> ?????
25089 this.clearSelections();
25090 this.el.update("");
25092 var records = this.store.getRange();
25093 if(records.length < 1) {
25095 // is this valid?? = should it render a template??
25097 this.el.update(this.emptyText);
25101 if (this.dataName) {
25102 this.el.update(t.apply(this.store.meta)); //????
25103 el = this.el.child('.roo-tpl-' + this.dataName);
25106 for(var i = 0, len = records.length; i < len; i++){
25107 var data = this.prepareData(records[i].data, i, records[i]);
25108 this.fireEvent("preparedata", this, data, i, records[i]);
25110 var d = Roo.apply({}, data);
25113 Roo.apply(d, {'roo-id' : Roo.id()});
25117 Roo.each(this.parent.item, function(item){
25118 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
25121 Roo.apply(d, {'roo-data-checked' : 'checked'});
25125 html[html.length] = Roo.util.Format.trim(
25127 t.applySubtemplate(this.dataName, d, this.store.meta) :
25134 el.update(html.join(""));
25135 this.nodes = el.dom.childNodes;
25136 this.updateIndexes(0);
25141 * Function to override to reformat the data that is sent to
25142 * the template for each node.
25143 * DEPRICATED - use the preparedata event handler.
25144 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
25145 * a JSON object for an UpdateManager bound view).
25147 prepareData : function(data, index, record)
25149 this.fireEvent("preparedata", this, data, index, record);
25153 onUpdate : function(ds, record){
25154 // Roo.log('on update');
25155 this.clearSelections();
25156 var index = this.store.indexOf(record);
25157 var n = this.nodes[index];
25158 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
25159 n.parentNode.removeChild(n);
25160 this.updateIndexes(index, index);
25166 onAdd : function(ds, records, index)
25168 //Roo.log(['on Add', ds, records, index] );
25169 this.clearSelections();
25170 if(this.nodes.length == 0){
25174 var n = this.nodes[index];
25175 for(var i = 0, len = records.length; i < len; i++){
25176 var d = this.prepareData(records[i].data, i, records[i]);
25178 this.tpl.insertBefore(n, d);
25181 this.tpl.append(this.el, d);
25184 this.updateIndexes(index);
25187 onRemove : function(ds, record, index){
25188 // Roo.log('onRemove');
25189 this.clearSelections();
25190 var el = this.dataName ?
25191 this.el.child('.roo-tpl-' + this.dataName) :
25194 el.dom.removeChild(this.nodes[index]);
25195 this.updateIndexes(index);
25199 * Refresh an individual node.
25200 * @param {Number} index
25202 refreshNode : function(index){
25203 this.onUpdate(this.store, this.store.getAt(index));
25206 updateIndexes : function(startIndex, endIndex){
25207 var ns = this.nodes;
25208 startIndex = startIndex || 0;
25209 endIndex = endIndex || ns.length - 1;
25210 for(var i = startIndex; i <= endIndex; i++){
25211 ns[i].nodeIndex = i;
25216 * Changes the data store this view uses and refresh the view.
25217 * @param {Store} store
25219 setStore : function(store, initial){
25220 if(!initial && this.store){
25221 this.store.un("datachanged", this.refresh);
25222 this.store.un("add", this.onAdd);
25223 this.store.un("remove", this.onRemove);
25224 this.store.un("update", this.onUpdate);
25225 this.store.un("clear", this.refresh);
25226 this.store.un("beforeload", this.onBeforeLoad);
25227 this.store.un("load", this.onLoad);
25228 this.store.un("loadexception", this.onLoad);
25232 store.on("datachanged", this.refresh, this);
25233 store.on("add", this.onAdd, this);
25234 store.on("remove", this.onRemove, this);
25235 store.on("update", this.onUpdate, this);
25236 store.on("clear", this.refresh, this);
25237 store.on("beforeload", this.onBeforeLoad, this);
25238 store.on("load", this.onLoad, this);
25239 store.on("loadexception", this.onLoad, this);
25247 * onbeforeLoad - masks the loading area.
25250 onBeforeLoad : function(store,opts)
25252 //Roo.log('onBeforeLoad');
25254 this.el.update("");
25256 this.el.mask(this.mask ? this.mask : "Loading" );
25258 onLoad : function ()
25265 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
25266 * @param {HTMLElement} node
25267 * @return {HTMLElement} The template node
25269 findItemFromChild : function(node){
25270 var el = this.dataName ?
25271 this.el.child('.roo-tpl-' + this.dataName,true) :
25274 if(!node || node.parentNode == el){
25277 var p = node.parentNode;
25278 while(p && p != el){
25279 if(p.parentNode == el){
25288 onClick : function(e){
25289 var item = this.findItemFromChild(e.getTarget());
25291 var index = this.indexOf(item);
25292 if(this.onItemClick(item, index, e) !== false){
25293 this.fireEvent("click", this, index, item, e);
25296 this.clearSelections();
25301 onContextMenu : function(e){
25302 var item = this.findItemFromChild(e.getTarget());
25304 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
25309 onDblClick : function(e){
25310 var item = this.findItemFromChild(e.getTarget());
25312 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
25316 onItemClick : function(item, index, e)
25318 if(this.fireEvent("beforeclick", this, index, item, e) === false){
25321 if (this.toggleSelect) {
25322 var m = this.isSelected(item) ? 'unselect' : 'select';
25325 _t[m](item, true, false);
25328 if(this.multiSelect || this.singleSelect){
25329 if(this.multiSelect && e.shiftKey && this.lastSelection){
25330 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
25332 this.select(item, this.multiSelect && e.ctrlKey);
25333 this.lastSelection = item;
25336 if(!this.tickable){
25337 e.preventDefault();
25345 * Get the number of selected nodes.
25348 getSelectionCount : function(){
25349 return this.selections.length;
25353 * Get the currently selected nodes.
25354 * @return {Array} An array of HTMLElements
25356 getSelectedNodes : function(){
25357 return this.selections;
25361 * Get the indexes of the selected nodes.
25364 getSelectedIndexes : function(){
25365 var indexes = [], s = this.selections;
25366 for(var i = 0, len = s.length; i < len; i++){
25367 indexes.push(s[i].nodeIndex);
25373 * Clear all selections
25374 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
25376 clearSelections : function(suppressEvent){
25377 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
25378 this.cmp.elements = this.selections;
25379 this.cmp.removeClass(this.selectedClass);
25380 this.selections = [];
25381 if(!suppressEvent){
25382 this.fireEvent("selectionchange", this, this.selections);
25388 * Returns true if the passed node is selected
25389 * @param {HTMLElement/Number} node The node or node index
25390 * @return {Boolean}
25392 isSelected : function(node){
25393 var s = this.selections;
25397 node = this.getNode(node);
25398 return s.indexOf(node) !== -1;
25403 * @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
25404 * @param {Boolean} keepExisting (optional) true to keep existing selections
25405 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
25407 select : function(nodeInfo, keepExisting, suppressEvent){
25408 if(nodeInfo instanceof Array){
25410 this.clearSelections(true);
25412 for(var i = 0, len = nodeInfo.length; i < len; i++){
25413 this.select(nodeInfo[i], true, true);
25417 var node = this.getNode(nodeInfo);
25418 if(!node || this.isSelected(node)){
25419 return; // already selected.
25422 this.clearSelections(true);
25425 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
25426 Roo.fly(node).addClass(this.selectedClass);
25427 this.selections.push(node);
25428 if(!suppressEvent){
25429 this.fireEvent("selectionchange", this, this.selections);
25437 * @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
25438 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
25439 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
25441 unselect : function(nodeInfo, keepExisting, suppressEvent)
25443 if(nodeInfo instanceof Array){
25444 Roo.each(this.selections, function(s) {
25445 this.unselect(s, nodeInfo);
25449 var node = this.getNode(nodeInfo);
25450 if(!node || !this.isSelected(node)){
25451 //Roo.log("not selected");
25452 return; // not selected.
25456 Roo.each(this.selections, function(s) {
25458 Roo.fly(node).removeClass(this.selectedClass);
25465 this.selections= ns;
25466 this.fireEvent("selectionchange", this, this.selections);
25470 * Gets a template node.
25471 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
25472 * @return {HTMLElement} The node or null if it wasn't found
25474 getNode : function(nodeInfo){
25475 if(typeof nodeInfo == "string"){
25476 return document.getElementById(nodeInfo);
25477 }else if(typeof nodeInfo == "number"){
25478 return this.nodes[nodeInfo];
25484 * Gets a range template nodes.
25485 * @param {Number} startIndex
25486 * @param {Number} endIndex
25487 * @return {Array} An array of nodes
25489 getNodes : function(start, end){
25490 var ns = this.nodes;
25491 start = start || 0;
25492 end = typeof end == "undefined" ? ns.length - 1 : end;
25495 for(var i = start; i <= end; i++){
25499 for(var i = start; i >= end; i--){
25507 * Finds the index of the passed node
25508 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
25509 * @return {Number} The index of the node or -1
25511 indexOf : function(node){
25512 node = this.getNode(node);
25513 if(typeof node.nodeIndex == "number"){
25514 return node.nodeIndex;
25516 var ns = this.nodes;
25517 for(var i = 0, len = ns.length; i < len; i++){
25527 * Ext JS Library 1.1.1
25528 * Copyright(c) 2006-2007, Ext JS, LLC.
25530 * Originally Released Under LGPL - original licence link has changed is not relivant.
25533 * <script type="text/javascript">
25537 * @class Roo.JsonView
25538 * @extends Roo.View
25539 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
25541 var view = new Roo.JsonView({
25542 container: "my-element",
25543 tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
25548 // listen for node click?
25549 view.on("click", function(vw, index, node, e){
25550 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
25553 // direct load of JSON data
25554 view.load("foobar.php");
25556 // Example from my blog list
25557 var tpl = new Roo.Template(
25558 '<div class="entry">' +
25559 '<a class="entry-title" href="{link}">{title}</a>' +
25560 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
25561 "</div><hr />"
25564 var moreView = new Roo.JsonView({
25565 container : "entry-list",
25569 moreView.on("beforerender", this.sortEntries, this);
25571 url: "/blog/get-posts.php",
25572 params: "allposts=true",
25573 text: "Loading Blog Entries..."
25577 * Note: old code is supported with arguments : (container, template, config)
25581 * Create a new JsonView
25583 * @param {Object} config The config object
25586 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
25589 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
25591 var um = this.el.getUpdateManager();
25592 um.setRenderer(this);
25593 um.on("update", this.onLoad, this);
25594 um.on("failure", this.onLoadException, this);
25597 * @event beforerender
25598 * Fires before rendering of the downloaded JSON data.
25599 * @param {Roo.JsonView} this
25600 * @param {Object} data The JSON data loaded
25604 * Fires when data is loaded.
25605 * @param {Roo.JsonView} this
25606 * @param {Object} data The JSON data loaded
25607 * @param {Object} response The raw Connect response object
25610 * @event loadexception
25611 * Fires when loading fails.
25612 * @param {Roo.JsonView} this
25613 * @param {Object} response The raw Connect response object
25616 'beforerender' : true,
25618 'loadexception' : true
25621 Roo.extend(Roo.JsonView, Roo.View, {
25623 * @type {String} The root property in the loaded JSON object that contains the data
25628 * Refreshes the view.
25630 refresh : function(){
25631 this.clearSelections();
25632 this.el.update("");
25634 var o = this.jsonData;
25635 if(o && o.length > 0){
25636 for(var i = 0, len = o.length; i < len; i++){
25637 var data = this.prepareData(o[i], i, o);
25638 html[html.length] = this.tpl.apply(data);
25641 html.push(this.emptyText);
25643 this.el.update(html.join(""));
25644 this.nodes = this.el.dom.childNodes;
25645 this.updateIndexes(0);
25649 * 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.
25650 * @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:
25653 url: "your-url.php",
25654 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
25655 callback: yourFunction,
25656 scope: yourObject, //(optional scope)
25659 text: "Loading...",
25664 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
25665 * 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.
25666 * @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}
25667 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
25668 * @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.
25671 var um = this.el.getUpdateManager();
25672 um.update.apply(um, arguments);
25675 render : function(el, response){
25676 this.clearSelections();
25677 this.el.update("");
25680 o = Roo.util.JSON.decode(response.responseText);
25683 o = o[this.jsonRoot];
25688 * The current JSON data or null
25691 this.beforeRender();
25696 * Get the number of records in the current JSON dataset
25699 getCount : function(){
25700 return this.jsonData ? this.jsonData.length : 0;
25704 * Returns the JSON object for the specified node(s)
25705 * @param {HTMLElement/Array} node The node or an array of nodes
25706 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
25707 * you get the JSON object for the node
25709 getNodeData : function(node){
25710 if(node instanceof Array){
25712 for(var i = 0, len = node.length; i < len; i++){
25713 data.push(this.getNodeData(node[i]));
25717 return this.jsonData[this.indexOf(node)] || null;
25720 beforeRender : function(){
25721 this.snapshot = this.jsonData;
25723 this.sort.apply(this, this.sortInfo);
25725 this.fireEvent("beforerender", this, this.jsonData);
25728 onLoad : function(el, o){
25729 this.fireEvent("load", this, this.jsonData, o);
25732 onLoadException : function(el, o){
25733 this.fireEvent("loadexception", this, o);
25737 * Filter the data by a specific property.
25738 * @param {String} property A property on your JSON objects
25739 * @param {String/RegExp} value Either string that the property values
25740 * should start with, or a RegExp to test against the property
25742 filter : function(property, value){
25745 var ss = this.snapshot;
25746 if(typeof value == "string"){
25747 var vlen = value.length;
25749 this.clearFilter();
25752 value = value.toLowerCase();
25753 for(var i = 0, len = ss.length; i < len; i++){
25755 if(o[property].substr(0, vlen).toLowerCase() == value){
25759 } else if(value.exec){ // regex?
25760 for(var i = 0, len = ss.length; i < len; i++){
25762 if(value.test(o[property])){
25769 this.jsonData = data;
25775 * Filter by a function. The passed function will be called with each
25776 * object in the current dataset. If the function returns true the value is kept,
25777 * otherwise it is filtered.
25778 * @param {Function} fn
25779 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
25781 filterBy : function(fn, scope){
25784 var ss = this.snapshot;
25785 for(var i = 0, len = ss.length; i < len; i++){
25787 if(fn.call(scope || this, o)){
25791 this.jsonData = data;
25797 * Clears the current filter.
25799 clearFilter : function(){
25800 if(this.snapshot && this.jsonData != this.snapshot){
25801 this.jsonData = this.snapshot;
25808 * Sorts the data for this view and refreshes it.
25809 * @param {String} property A property on your JSON objects to sort on
25810 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
25811 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
25813 sort : function(property, dir, sortType){
25814 this.sortInfo = Array.prototype.slice.call(arguments, 0);
25817 var dsc = dir && dir.toLowerCase() == "desc";
25818 var f = function(o1, o2){
25819 var v1 = sortType ? sortType(o1[p]) : o1[p];
25820 var v2 = sortType ? sortType(o2[p]) : o2[p];
25823 return dsc ? +1 : -1;
25824 } else if(v1 > v2){
25825 return dsc ? -1 : +1;
25830 this.jsonData.sort(f);
25832 if(this.jsonData != this.snapshot){
25833 this.snapshot.sort(f);
25839 * Ext JS Library 1.1.1
25840 * Copyright(c) 2006-2007, Ext JS, LLC.
25842 * Originally Released Under LGPL - original licence link has changed is not relivant.
25845 * <script type="text/javascript">
25850 * @class Roo.ColorPalette
25851 * @extends Roo.Component
25852 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
25853 * Here's an example of typical usage:
25855 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
25856 cp.render('my-div');
25858 cp.on('select', function(palette, selColor){
25859 // do something with selColor
25863 * Create a new ColorPalette
25864 * @param {Object} config The config object
25866 Roo.ColorPalette = function(config){
25867 Roo.ColorPalette.superclass.constructor.call(this, config);
25871 * Fires when a color is selected
25872 * @param {ColorPalette} this
25873 * @param {String} color The 6-digit color hex code (without the # symbol)
25879 this.on("select", this.handler, this.scope, true);
25882 Roo.extend(Roo.ColorPalette, Roo.Component, {
25884 * @cfg {String} itemCls
25885 * The CSS class to apply to the containing element (defaults to "x-color-palette")
25887 itemCls : "x-color-palette",
25889 * @cfg {String} value
25890 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
25891 * the hex codes are case-sensitive.
25894 clickEvent:'click',
25896 ctype: "Roo.ColorPalette",
25899 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
25901 allowReselect : false,
25904 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
25905 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
25906 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
25907 * of colors with the width setting until the box is symmetrical.</p>
25908 * <p>You can override individual colors if needed:</p>
25910 var cp = new Roo.ColorPalette();
25911 cp.colors[0] = "FF0000"; // change the first box to red
25914 Or you can provide a custom array of your own for complete control:
25916 var cp = new Roo.ColorPalette();
25917 cp.colors = ["000000", "993300", "333300"];
25922 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
25923 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
25924 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
25925 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
25926 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
25930 onRender : function(container, position){
25931 var t = new Roo.MasterTemplate(
25932 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
25934 var c = this.colors;
25935 for(var i = 0, len = c.length; i < len; i++){
25938 var el = document.createElement("div");
25939 el.className = this.itemCls;
25941 container.dom.insertBefore(el, position);
25942 this.el = Roo.get(el);
25943 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
25944 if(this.clickEvent != 'click'){
25945 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
25950 afterRender : function(){
25951 Roo.ColorPalette.superclass.afterRender.call(this);
25953 var s = this.value;
25960 handleClick : function(e, t){
25961 e.preventDefault();
25962 if(!this.disabled){
25963 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
25964 this.select(c.toUpperCase());
25969 * Selects the specified color in the palette (fires the select event)
25970 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
25972 select : function(color){
25973 color = color.replace("#", "");
25974 if(color != this.value || this.allowReselect){
25977 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
25979 el.child("a.color-"+color).addClass("x-color-palette-sel");
25980 this.value = color;
25981 this.fireEvent("select", this, color);
25986 * Ext JS Library 1.1.1
25987 * Copyright(c) 2006-2007, Ext JS, LLC.
25989 * Originally Released Under LGPL - original licence link has changed is not relivant.
25992 * <script type="text/javascript">
25996 * @class Roo.DatePicker
25997 * @extends Roo.Component
25998 * Simple date picker class.
26000 * Create a new DatePicker
26001 * @param {Object} config The config object
26003 Roo.DatePicker = function(config){
26004 Roo.DatePicker.superclass.constructor.call(this, config);
26006 this.value = config && config.value ?
26007 config.value.clearTime() : new Date().clearTime();
26012 * Fires when a date is selected
26013 * @param {DatePicker} this
26014 * @param {Date} date The selected date
26018 * @event monthchange
26019 * Fires when the displayed month changes
26020 * @param {DatePicker} this
26021 * @param {Date} date The selected month
26023 'monthchange': true
26027 this.on("select", this.handler, this.scope || this);
26029 // build the disabledDatesRE
26030 if(!this.disabledDatesRE && this.disabledDates){
26031 var dd = this.disabledDates;
26033 for(var i = 0; i < dd.length; i++){
26035 if(i != dd.length-1) re += "|";
26037 this.disabledDatesRE = new RegExp(re + ")");
26041 Roo.extend(Roo.DatePicker, Roo.Component, {
26043 * @cfg {String} todayText
26044 * The text to display on the button that selects the current date (defaults to "Today")
26046 todayText : "Today",
26048 * @cfg {String} okText
26049 * The text to display on the ok button
26051 okText : " OK ", //   to give the user extra clicking room
26053 * @cfg {String} cancelText
26054 * The text to display on the cancel button
26056 cancelText : "Cancel",
26058 * @cfg {String} todayTip
26059 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
26061 todayTip : "{0} (Spacebar)",
26063 * @cfg {Date} minDate
26064 * Minimum allowable date (JavaScript date object, defaults to null)
26068 * @cfg {Date} maxDate
26069 * Maximum allowable date (JavaScript date object, defaults to null)
26073 * @cfg {String} minText
26074 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
26076 minText : "This date is before the minimum date",
26078 * @cfg {String} maxText
26079 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
26081 maxText : "This date is after the maximum date",
26083 * @cfg {String} format
26084 * The default date format string which can be overriden for localization support. The format must be
26085 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
26089 * @cfg {Array} disabledDays
26090 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
26092 disabledDays : null,
26094 * @cfg {String} disabledDaysText
26095 * The tooltip to display when the date falls on a disabled day (defaults to "")
26097 disabledDaysText : "",
26099 * @cfg {RegExp} disabledDatesRE
26100 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
26102 disabledDatesRE : null,
26104 * @cfg {String} disabledDatesText
26105 * The tooltip text to display when the date falls on a disabled date (defaults to "")
26107 disabledDatesText : "",
26109 * @cfg {Boolean} constrainToViewport
26110 * True to constrain the date picker to the viewport (defaults to true)
26112 constrainToViewport : true,
26114 * @cfg {Array} monthNames
26115 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
26117 monthNames : Date.monthNames,
26119 * @cfg {Array} dayNames
26120 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
26122 dayNames : Date.dayNames,
26124 * @cfg {String} nextText
26125 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
26127 nextText: 'Next Month (Control+Right)',
26129 * @cfg {String} prevText
26130 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
26132 prevText: 'Previous Month (Control+Left)',
26134 * @cfg {String} monthYearText
26135 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
26137 monthYearText: 'Choose a month (Control+Up/Down to move years)',
26139 * @cfg {Number} startDay
26140 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
26144 * @cfg {Bool} showClear
26145 * Show a clear button (usefull for date form elements that can be blank.)
26151 * Sets the value of the date field
26152 * @param {Date} value The date to set
26154 setValue : function(value){
26155 var old = this.value;
26157 if (typeof(value) == 'string') {
26159 value = Date.parseDate(value, this.format);
26162 value = new Date();
26165 this.value = value.clearTime(true);
26167 this.update(this.value);
26172 * Gets the current selected value of the date field
26173 * @return {Date} The selected date
26175 getValue : function(){
26180 focus : function(){
26182 this.update(this.activeDate);
26187 onRender : function(container, position){
26190 '<table cellspacing="0">',
26191 '<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>',
26192 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
26193 var dn = this.dayNames;
26194 for(var i = 0; i < 7; i++){
26195 var d = this.startDay+i;
26199 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
26201 m[m.length] = "</tr></thead><tbody><tr>";
26202 for(var i = 0; i < 42; i++) {
26203 if(i % 7 == 0 && i != 0){
26204 m[m.length] = "</tr><tr>";
26206 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
26208 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
26209 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
26211 var el = document.createElement("div");
26212 el.className = "x-date-picker";
26213 el.innerHTML = m.join("");
26215 container.dom.insertBefore(el, position);
26217 this.el = Roo.get(el);
26218 this.eventEl = Roo.get(el.firstChild);
26220 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
26221 handler: this.showPrevMonth,
26223 preventDefault:true,
26227 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
26228 handler: this.showNextMonth,
26230 preventDefault:true,
26234 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
26236 this.monthPicker = this.el.down('div.x-date-mp');
26237 this.monthPicker.enableDisplayMode('block');
26239 var kn = new Roo.KeyNav(this.eventEl, {
26240 "left" : function(e){
26242 this.showPrevMonth() :
26243 this.update(this.activeDate.add("d", -1));
26246 "right" : function(e){
26248 this.showNextMonth() :
26249 this.update(this.activeDate.add("d", 1));
26252 "up" : function(e){
26254 this.showNextYear() :
26255 this.update(this.activeDate.add("d", -7));
26258 "down" : function(e){
26260 this.showPrevYear() :
26261 this.update(this.activeDate.add("d", 7));
26264 "pageUp" : function(e){
26265 this.showNextMonth();
26268 "pageDown" : function(e){
26269 this.showPrevMonth();
26272 "enter" : function(e){
26273 e.stopPropagation();
26280 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
26282 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
26284 this.el.unselectable();
26286 this.cells = this.el.select("table.x-date-inner tbody td");
26287 this.textNodes = this.el.query("table.x-date-inner tbody span");
26289 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
26291 tooltip: this.monthYearText
26294 this.mbtn.on('click', this.showMonthPicker, this);
26295 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
26298 var today = (new Date()).dateFormat(this.format);
26300 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
26301 if (this.showClear) {
26302 baseTb.add( new Roo.Toolbar.Fill());
26305 text: String.format(this.todayText, today),
26306 tooltip: String.format(this.todayTip, today),
26307 handler: this.selectToday,
26311 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
26314 if (this.showClear) {
26316 baseTb.add( new Roo.Toolbar.Fill());
26319 cls: 'x-btn-icon x-btn-clear',
26320 handler: function() {
26322 this.fireEvent("select", this, '');
26332 this.update(this.value);
26335 createMonthPicker : function(){
26336 if(!this.monthPicker.dom.firstChild){
26337 var buf = ['<table border="0" cellspacing="0">'];
26338 for(var i = 0; i < 6; i++){
26340 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
26341 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
26343 '<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>' :
26344 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
26348 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
26350 '</button><button type="button" class="x-date-mp-cancel">',
26352 '</button></td></tr>',
26355 this.monthPicker.update(buf.join(''));
26356 this.monthPicker.on('click', this.onMonthClick, this);
26357 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
26359 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
26360 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
26362 this.mpMonths.each(function(m, a, i){
26365 m.dom.xmonth = 5 + Math.round(i * .5);
26367 m.dom.xmonth = Math.round((i-1) * .5);
26373 showMonthPicker : function(){
26374 this.createMonthPicker();
26375 var size = this.el.getSize();
26376 this.monthPicker.setSize(size);
26377 this.monthPicker.child('table').setSize(size);
26379 this.mpSelMonth = (this.activeDate || this.value).getMonth();
26380 this.updateMPMonth(this.mpSelMonth);
26381 this.mpSelYear = (this.activeDate || this.value).getFullYear();
26382 this.updateMPYear(this.mpSelYear);
26384 this.monthPicker.slideIn('t', {duration:.2});
26387 updateMPYear : function(y){
26389 var ys = this.mpYears.elements;
26390 for(var i = 1; i <= 10; i++){
26391 var td = ys[i-1], y2;
26393 y2 = y + Math.round(i * .5);
26394 td.firstChild.innerHTML = y2;
26397 y2 = y - (5-Math.round(i * .5));
26398 td.firstChild.innerHTML = y2;
26401 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
26405 updateMPMonth : function(sm){
26406 this.mpMonths.each(function(m, a, i){
26407 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
26411 selectMPMonth: function(m){
26415 onMonthClick : function(e, t){
26417 var el = new Roo.Element(t), pn;
26418 if(el.is('button.x-date-mp-cancel')){
26419 this.hideMonthPicker();
26421 else if(el.is('button.x-date-mp-ok')){
26422 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
26423 this.hideMonthPicker();
26425 else if(pn = el.up('td.x-date-mp-month', 2)){
26426 this.mpMonths.removeClass('x-date-mp-sel');
26427 pn.addClass('x-date-mp-sel');
26428 this.mpSelMonth = pn.dom.xmonth;
26430 else if(pn = el.up('td.x-date-mp-year', 2)){
26431 this.mpYears.removeClass('x-date-mp-sel');
26432 pn.addClass('x-date-mp-sel');
26433 this.mpSelYear = pn.dom.xyear;
26435 else if(el.is('a.x-date-mp-prev')){
26436 this.updateMPYear(this.mpyear-10);
26438 else if(el.is('a.x-date-mp-next')){
26439 this.updateMPYear(this.mpyear+10);
26443 onMonthDblClick : function(e, t){
26445 var el = new Roo.Element(t), pn;
26446 if(pn = el.up('td.x-date-mp-month', 2)){
26447 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
26448 this.hideMonthPicker();
26450 else if(pn = el.up('td.x-date-mp-year', 2)){
26451 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
26452 this.hideMonthPicker();
26456 hideMonthPicker : function(disableAnim){
26457 if(this.monthPicker){
26458 if(disableAnim === true){
26459 this.monthPicker.hide();
26461 this.monthPicker.slideOut('t', {duration:.2});
26467 showPrevMonth : function(e){
26468 this.update(this.activeDate.add("mo", -1));
26472 showNextMonth : function(e){
26473 this.update(this.activeDate.add("mo", 1));
26477 showPrevYear : function(){
26478 this.update(this.activeDate.add("y", -1));
26482 showNextYear : function(){
26483 this.update(this.activeDate.add("y", 1));
26487 handleMouseWheel : function(e){
26488 var delta = e.getWheelDelta();
26490 this.showPrevMonth();
26492 } else if(delta < 0){
26493 this.showNextMonth();
26499 handleDateClick : function(e, t){
26501 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
26502 this.setValue(new Date(t.dateValue));
26503 this.fireEvent("select", this, this.value);
26508 selectToday : function(){
26509 this.setValue(new Date().clearTime());
26510 this.fireEvent("select", this, this.value);
26514 update : function(date)
26516 var vd = this.activeDate;
26517 this.activeDate = date;
26519 var t = date.getTime();
26520 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
26521 this.cells.removeClass("x-date-selected");
26522 this.cells.each(function(c){
26523 if(c.dom.firstChild.dateValue == t){
26524 c.addClass("x-date-selected");
26525 setTimeout(function(){
26526 try{c.dom.firstChild.focus();}catch(e){}
26535 var days = date.getDaysInMonth();
26536 var firstOfMonth = date.getFirstDateOfMonth();
26537 var startingPos = firstOfMonth.getDay()-this.startDay;
26539 if(startingPos <= this.startDay){
26543 var pm = date.add("mo", -1);
26544 var prevStart = pm.getDaysInMonth()-startingPos;
26546 var cells = this.cells.elements;
26547 var textEls = this.textNodes;
26548 days += startingPos;
26550 // convert everything to numbers so it's fast
26551 var day = 86400000;
26552 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
26553 var today = new Date().clearTime().getTime();
26554 var sel = date.clearTime().getTime();
26555 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
26556 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
26557 var ddMatch = this.disabledDatesRE;
26558 var ddText = this.disabledDatesText;
26559 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
26560 var ddaysText = this.disabledDaysText;
26561 var format = this.format;
26563 var setCellClass = function(cal, cell){
26565 var t = d.getTime();
26566 cell.firstChild.dateValue = t;
26568 cell.className += " x-date-today";
26569 cell.title = cal.todayText;
26572 cell.className += " x-date-selected";
26573 setTimeout(function(){
26574 try{cell.firstChild.focus();}catch(e){}
26579 cell.className = " x-date-disabled";
26580 cell.title = cal.minText;
26584 cell.className = " x-date-disabled";
26585 cell.title = cal.maxText;
26589 if(ddays.indexOf(d.getDay()) != -1){
26590 cell.title = ddaysText;
26591 cell.className = " x-date-disabled";
26594 if(ddMatch && format){
26595 var fvalue = d.dateFormat(format);
26596 if(ddMatch.test(fvalue)){
26597 cell.title = ddText.replace("%0", fvalue);
26598 cell.className = " x-date-disabled";
26604 for(; i < startingPos; i++) {
26605 textEls[i].innerHTML = (++prevStart);
26606 d.setDate(d.getDate()+1);
26607 cells[i].className = "x-date-prevday";
26608 setCellClass(this, cells[i]);
26610 for(; i < days; i++){
26611 intDay = i - startingPos + 1;
26612 textEls[i].innerHTML = (intDay);
26613 d.setDate(d.getDate()+1);
26614 cells[i].className = "x-date-active";
26615 setCellClass(this, cells[i]);
26618 for(; i < 42; i++) {
26619 textEls[i].innerHTML = (++extraDays);
26620 d.setDate(d.getDate()+1);
26621 cells[i].className = "x-date-nextday";
26622 setCellClass(this, cells[i]);
26625 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
26626 this.fireEvent('monthchange', this, date);
26628 if(!this.internalRender){
26629 var main = this.el.dom.firstChild;
26630 var w = main.offsetWidth;
26631 this.el.setWidth(w + this.el.getBorderWidth("lr"));
26632 Roo.fly(main).setWidth(w);
26633 this.internalRender = true;
26634 // opera does not respect the auto grow header center column
26635 // then, after it gets a width opera refuses to recalculate
26636 // without a second pass
26637 if(Roo.isOpera && !this.secondPass){
26638 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
26639 this.secondPass = true;
26640 this.update.defer(10, this, [date]);
26648 * Ext JS Library 1.1.1
26649 * Copyright(c) 2006-2007, Ext JS, LLC.
26651 * Originally Released Under LGPL - original licence link has changed is not relivant.
26654 * <script type="text/javascript">
26657 * @class Roo.TabPanel
26658 * @extends Roo.util.Observable
26659 * A lightweight tab container.
26663 // basic tabs 1, built from existing content
26664 var tabs = new Roo.TabPanel("tabs1");
26665 tabs.addTab("script", "View Script");
26666 tabs.addTab("markup", "View Markup");
26667 tabs.activate("script");
26669 // more advanced tabs, built from javascript
26670 var jtabs = new Roo.TabPanel("jtabs");
26671 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
26673 // set up the UpdateManager
26674 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
26675 var updater = tab2.getUpdateManager();
26676 updater.setDefaultUrl("ajax1.htm");
26677 tab2.on('activate', updater.refresh, updater, true);
26679 // Use setUrl for Ajax loading
26680 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
26681 tab3.setUrl("ajax2.htm", null, true);
26684 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
26687 jtabs.activate("jtabs-1");
26690 * Create a new TabPanel.
26691 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
26692 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
26694 Roo.TabPanel = function(container, config){
26696 * The container element for this TabPanel.
26697 * @type Roo.Element
26699 this.el = Roo.get(container, true);
26701 if(typeof config == "boolean"){
26702 this.tabPosition = config ? "bottom" : "top";
26704 Roo.apply(this, config);
26707 if(this.tabPosition == "bottom"){
26708 this.bodyEl = Roo.get(this.createBody(this.el.dom));
26709 this.el.addClass("x-tabs-bottom");
26711 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
26712 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
26713 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
26715 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
26717 if(this.tabPosition != "bottom"){
26718 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
26719 * @type Roo.Element
26721 this.bodyEl = Roo.get(this.createBody(this.el.dom));
26722 this.el.addClass("x-tabs-top");
26726 this.bodyEl.setStyle("position", "relative");
26728 this.active = null;
26729 this.activateDelegate = this.activate.createDelegate(this);
26734 * Fires when the active tab changes
26735 * @param {Roo.TabPanel} this
26736 * @param {Roo.TabPanelItem} activePanel The new active tab
26740 * @event beforetabchange
26741 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
26742 * @param {Roo.TabPanel} this
26743 * @param {Object} e Set cancel to true on this object to cancel the tab change
26744 * @param {Roo.TabPanelItem} tab The tab being changed to
26746 "beforetabchange" : true
26749 Roo.EventManager.onWindowResize(this.onResize, this);
26750 this.cpad = this.el.getPadding("lr");
26751 this.hiddenCount = 0;
26754 // toolbar on the tabbar support...
26755 if (this.toolbar) {
26756 var tcfg = this.toolbar;
26757 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
26758 this.toolbar = new Roo.Toolbar(tcfg);
26759 if (Roo.isSafari) {
26760 var tbl = tcfg.container.child('table', true);
26761 tbl.setAttribute('width', '100%');
26768 Roo.TabPanel.superclass.constructor.call(this);
26771 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
26773 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
26775 tabPosition : "top",
26777 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
26779 currentTabWidth : 0,
26781 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
26785 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
26789 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
26791 preferredTabWidth : 175,
26793 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
26795 resizeTabs : false,
26797 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
26799 monitorResize : true,
26801 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
26806 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
26807 * @param {String} id The id of the div to use <b>or create</b>
26808 * @param {String} text The text for the tab
26809 * @param {String} content (optional) Content to put in the TabPanelItem body
26810 * @param {Boolean} closable (optional) True to create a close icon on the tab
26811 * @return {Roo.TabPanelItem} The created TabPanelItem
26813 addTab : function(id, text, content, closable){
26814 var item = new Roo.TabPanelItem(this, id, text, closable);
26815 this.addTabItem(item);
26817 item.setContent(content);
26823 * Returns the {@link Roo.TabPanelItem} with the specified id/index
26824 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
26825 * @return {Roo.TabPanelItem}
26827 getTab : function(id){
26828 return this.items[id];
26832 * Hides the {@link Roo.TabPanelItem} with the specified id/index
26833 * @param {String/Number} id The id or index of the TabPanelItem to hide.
26835 hideTab : function(id){
26836 var t = this.items[id];
26839 this.hiddenCount++;
26840 this.autoSizeTabs();
26845 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
26846 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
26848 unhideTab : function(id){
26849 var t = this.items[id];
26851 t.setHidden(false);
26852 this.hiddenCount--;
26853 this.autoSizeTabs();
26858 * Adds an existing {@link Roo.TabPanelItem}.
26859 * @param {Roo.TabPanelItem} item The TabPanelItem to add
26861 addTabItem : function(item){
26862 this.items[item.id] = item;
26863 this.items.push(item);
26864 if(this.resizeTabs){
26865 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
26866 this.autoSizeTabs();
26873 * Removes a {@link Roo.TabPanelItem}.
26874 * @param {String/Number} id The id or index of the TabPanelItem to remove.
26876 removeTab : function(id){
26877 var items = this.items;
26878 var tab = items[id];
26879 if(!tab) { return; }
26880 var index = items.indexOf(tab);
26881 if(this.active == tab && items.length > 1){
26882 var newTab = this.getNextAvailable(index);
26887 this.stripEl.dom.removeChild(tab.pnode.dom);
26888 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
26889 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
26891 items.splice(index, 1);
26892 delete this.items[tab.id];
26893 tab.fireEvent("close", tab);
26894 tab.purgeListeners();
26895 this.autoSizeTabs();
26898 getNextAvailable : function(start){
26899 var items = this.items;
26901 // look for a next tab that will slide over to
26902 // replace the one being removed
26903 while(index < items.length){
26904 var item = items[++index];
26905 if(item && !item.isHidden()){
26909 // if one isn't found select the previous tab (on the left)
26912 var item = items[--index];
26913 if(item && !item.isHidden()){
26921 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
26922 * @param {String/Number} id The id or index of the TabPanelItem to disable.
26924 disableTab : function(id){
26925 var tab = this.items[id];
26926 if(tab && this.active != tab){
26932 * Enables a {@link Roo.TabPanelItem} that is disabled.
26933 * @param {String/Number} id The id or index of the TabPanelItem to enable.
26935 enableTab : function(id){
26936 var tab = this.items[id];
26941 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
26942 * @param {String/Number} id The id or index of the TabPanelItem to activate.
26943 * @return {Roo.TabPanelItem} The TabPanelItem.
26945 activate : function(id){
26946 var tab = this.items[id];
26950 if(tab == this.active || tab.disabled){
26954 this.fireEvent("beforetabchange", this, e, tab);
26955 if(e.cancel !== true && !tab.disabled){
26957 this.active.hide();
26959 this.active = this.items[id];
26960 this.active.show();
26961 this.fireEvent("tabchange", this, this.active);
26967 * Gets the active {@link Roo.TabPanelItem}.
26968 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
26970 getActiveTab : function(){
26971 return this.active;
26975 * Updates the tab body element to fit the height of the container element
26976 * for overflow scrolling
26977 * @param {Number} targetHeight (optional) Override the starting height from the elements height
26979 syncHeight : function(targetHeight){
26980 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
26981 var bm = this.bodyEl.getMargins();
26982 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
26983 this.bodyEl.setHeight(newHeight);
26987 onResize : function(){
26988 if(this.monitorResize){
26989 this.autoSizeTabs();
26994 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
26996 beginUpdate : function(){
26997 this.updating = true;
27001 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
27003 endUpdate : function(){
27004 this.updating = false;
27005 this.autoSizeTabs();
27009 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
27011 autoSizeTabs : function(){
27012 var count = this.items.length;
27013 var vcount = count - this.hiddenCount;
27014 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) return;
27015 var w = Math.max(this.el.getWidth() - this.cpad, 10);
27016 var availWidth = Math.floor(w / vcount);
27017 var b = this.stripBody;
27018 if(b.getWidth() > w){
27019 var tabs = this.items;
27020 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
27021 if(availWidth < this.minTabWidth){
27022 /*if(!this.sleft){ // incomplete scrolling code
27023 this.createScrollButtons();
27026 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
27029 if(this.currentTabWidth < this.preferredTabWidth){
27030 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
27036 * Returns the number of tabs in this TabPanel.
27039 getCount : function(){
27040 return this.items.length;
27044 * Resizes all the tabs to the passed width
27045 * @param {Number} The new width
27047 setTabWidth : function(width){
27048 this.currentTabWidth = width;
27049 for(var i = 0, len = this.items.length; i < len; i++) {
27050 if(!this.items[i].isHidden())this.items[i].setWidth(width);
27055 * Destroys this TabPanel
27056 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
27058 destroy : function(removeEl){
27059 Roo.EventManager.removeResizeListener(this.onResize, this);
27060 for(var i = 0, len = this.items.length; i < len; i++){
27061 this.items[i].purgeListeners();
27063 if(removeEl === true){
27064 this.el.update("");
27071 * @class Roo.TabPanelItem
27072 * @extends Roo.util.Observable
27073 * Represents an individual item (tab plus body) in a TabPanel.
27074 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
27075 * @param {String} id The id of this TabPanelItem
27076 * @param {String} text The text for the tab of this TabPanelItem
27077 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
27079 Roo.TabPanelItem = function(tabPanel, id, text, closable){
27081 * The {@link Roo.TabPanel} this TabPanelItem belongs to
27082 * @type Roo.TabPanel
27084 this.tabPanel = tabPanel;
27086 * The id for this TabPanelItem
27091 this.disabled = false;
27095 this.loaded = false;
27096 this.closable = closable;
27099 * The body element for this TabPanelItem.
27100 * @type Roo.Element
27102 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
27103 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
27104 this.bodyEl.setStyle("display", "block");
27105 this.bodyEl.setStyle("zoom", "1");
27108 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
27110 this.el = Roo.get(els.el, true);
27111 this.inner = Roo.get(els.inner, true);
27112 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
27113 this.pnode = Roo.get(els.el.parentNode, true);
27114 this.el.on("mousedown", this.onTabMouseDown, this);
27115 this.el.on("click", this.onTabClick, this);
27118 var c = Roo.get(els.close, true);
27119 c.dom.title = this.closeText;
27120 c.addClassOnOver("close-over");
27121 c.on("click", this.closeClick, this);
27127 * Fires when this tab becomes the active tab.
27128 * @param {Roo.TabPanel} tabPanel The parent TabPanel
27129 * @param {Roo.TabPanelItem} this
27133 * @event beforeclose
27134 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
27135 * @param {Roo.TabPanelItem} this
27136 * @param {Object} e Set cancel to true on this object to cancel the close.
27138 "beforeclose": true,
27141 * Fires when this tab is closed.
27142 * @param {Roo.TabPanelItem} this
27146 * @event deactivate
27147 * Fires when this tab is no longer the active tab.
27148 * @param {Roo.TabPanel} tabPanel The parent TabPanel
27149 * @param {Roo.TabPanelItem} this
27151 "deactivate" : true
27153 this.hidden = false;
27155 Roo.TabPanelItem.superclass.constructor.call(this);
27158 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
27159 purgeListeners : function(){
27160 Roo.util.Observable.prototype.purgeListeners.call(this);
27161 this.el.removeAllListeners();
27164 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
27167 this.pnode.addClass("on");
27170 this.tabPanel.stripWrap.repaint();
27172 this.fireEvent("activate", this.tabPanel, this);
27176 * Returns true if this tab is the active tab.
27177 * @return {Boolean}
27179 isActive : function(){
27180 return this.tabPanel.getActiveTab() == this;
27184 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
27187 this.pnode.removeClass("on");
27189 this.fireEvent("deactivate", this.tabPanel, this);
27192 hideAction : function(){
27193 this.bodyEl.hide();
27194 this.bodyEl.setStyle("position", "absolute");
27195 this.bodyEl.setLeft("-20000px");
27196 this.bodyEl.setTop("-20000px");
27199 showAction : function(){
27200 this.bodyEl.setStyle("position", "relative");
27201 this.bodyEl.setTop("");
27202 this.bodyEl.setLeft("");
27203 this.bodyEl.show();
27207 * Set the tooltip for the tab.
27208 * @param {String} tooltip The tab's tooltip
27210 setTooltip : function(text){
27211 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
27212 this.textEl.dom.qtip = text;
27213 this.textEl.dom.removeAttribute('title');
27215 this.textEl.dom.title = text;
27219 onTabClick : function(e){
27220 e.preventDefault();
27221 this.tabPanel.activate(this.id);
27224 onTabMouseDown : function(e){
27225 e.preventDefault();
27226 this.tabPanel.activate(this.id);
27229 getWidth : function(){
27230 return this.inner.getWidth();
27233 setWidth : function(width){
27234 var iwidth = width - this.pnode.getPadding("lr");
27235 this.inner.setWidth(iwidth);
27236 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
27237 this.pnode.setWidth(width);
27241 * Show or hide the tab
27242 * @param {Boolean} hidden True to hide or false to show.
27244 setHidden : function(hidden){
27245 this.hidden = hidden;
27246 this.pnode.setStyle("display", hidden ? "none" : "");
27250 * Returns true if this tab is "hidden"
27251 * @return {Boolean}
27253 isHidden : function(){
27254 return this.hidden;
27258 * Returns the text for this tab
27261 getText : function(){
27265 autoSize : function(){
27266 //this.el.beginMeasure();
27267 this.textEl.setWidth(1);
27269 * #2804 [new] Tabs in Roojs
27270 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
27272 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
27273 //this.el.endMeasure();
27277 * Sets the text for the tab (Note: this also sets the tooltip text)
27278 * @param {String} text The tab's text and tooltip
27280 setText : function(text){
27282 this.textEl.update(text);
27283 this.setTooltip(text);
27284 if(!this.tabPanel.resizeTabs){
27289 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
27291 activate : function(){
27292 this.tabPanel.activate(this.id);
27296 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
27298 disable : function(){
27299 if(this.tabPanel.active != this){
27300 this.disabled = true;
27301 this.pnode.addClass("disabled");
27306 * Enables this TabPanelItem if it was previously disabled.
27308 enable : function(){
27309 this.disabled = false;
27310 this.pnode.removeClass("disabled");
27314 * Sets the content for this TabPanelItem.
27315 * @param {String} content The content
27316 * @param {Boolean} loadScripts true to look for and load scripts
27318 setContent : function(content, loadScripts){
27319 this.bodyEl.update(content, loadScripts);
27323 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
27324 * @return {Roo.UpdateManager} The UpdateManager
27326 getUpdateManager : function(){
27327 return this.bodyEl.getUpdateManager();
27331 * Set a URL to be used to load the content for this TabPanelItem.
27332 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
27333 * @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)
27334 * @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)
27335 * @return {Roo.UpdateManager} The UpdateManager
27337 setUrl : function(url, params, loadOnce){
27338 if(this.refreshDelegate){
27339 this.un('activate', this.refreshDelegate);
27341 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
27342 this.on("activate", this.refreshDelegate);
27343 return this.bodyEl.getUpdateManager();
27347 _handleRefresh : function(url, params, loadOnce){
27348 if(!loadOnce || !this.loaded){
27349 var updater = this.bodyEl.getUpdateManager();
27350 updater.update(url, params, this._setLoaded.createDelegate(this));
27355 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
27356 * Will fail silently if the setUrl method has not been called.
27357 * This does not activate the panel, just updates its content.
27359 refresh : function(){
27360 if(this.refreshDelegate){
27361 this.loaded = false;
27362 this.refreshDelegate();
27367 _setLoaded : function(){
27368 this.loaded = true;
27372 closeClick : function(e){
27375 this.fireEvent("beforeclose", this, o);
27376 if(o.cancel !== true){
27377 this.tabPanel.removeTab(this.id);
27381 * The text displayed in the tooltip for the close icon.
27384 closeText : "Close this tab"
27388 Roo.TabPanel.prototype.createStrip = function(container){
27389 var strip = document.createElement("div");
27390 strip.className = "x-tabs-wrap";
27391 container.appendChild(strip);
27395 Roo.TabPanel.prototype.createStripList = function(strip){
27396 // div wrapper for retard IE
27397 // returns the "tr" element.
27398 strip.innerHTML = '<div class="x-tabs-strip-wrap">'+
27399 '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
27400 '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
27401 return strip.firstChild.firstChild.firstChild.firstChild;
27404 Roo.TabPanel.prototype.createBody = function(container){
27405 var body = document.createElement("div");
27406 Roo.id(body, "tab-body");
27407 Roo.fly(body).addClass("x-tabs-body");
27408 container.appendChild(body);
27412 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
27413 var body = Roo.getDom(id);
27415 body = document.createElement("div");
27418 Roo.fly(body).addClass("x-tabs-item-body");
27419 bodyEl.insertBefore(body, bodyEl.firstChild);
27423 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
27424 var td = document.createElement("td");
27425 stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
27426 //stripEl.appendChild(td);
27428 td.className = "x-tabs-closable";
27429 if(!this.closeTpl){
27430 this.closeTpl = new Roo.Template(
27431 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
27432 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
27433 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
27436 var el = this.closeTpl.overwrite(td, {"text": text});
27437 var close = el.getElementsByTagName("div")[0];
27438 var inner = el.getElementsByTagName("em")[0];
27439 return {"el": el, "close": close, "inner": inner};
27442 this.tabTpl = new Roo.Template(
27443 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
27444 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
27447 var el = this.tabTpl.overwrite(td, {"text": text});
27448 var inner = el.getElementsByTagName("em")[0];
27449 return {"el": el, "inner": inner};
27453 * Ext JS Library 1.1.1
27454 * Copyright(c) 2006-2007, Ext JS, LLC.
27456 * Originally Released Under LGPL - original licence link has changed is not relivant.
27459 * <script type="text/javascript">
27463 * @class Roo.Button
27464 * @extends Roo.util.Observable
27465 * Simple Button class
27466 * @cfg {String} text The button text
27467 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
27468 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
27469 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
27470 * @cfg {Object} scope The scope of the handler
27471 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
27472 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
27473 * @cfg {Boolean} hidden True to start hidden (defaults to false)
27474 * @cfg {Boolean} disabled True to start disabled (defaults to false)
27475 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
27476 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
27477 applies if enableToggle = true)
27478 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
27479 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
27480 an {@link Roo.util.ClickRepeater} config object (defaults to false).
27482 * Create a new button
27483 * @param {Object} config The config object
27485 Roo.Button = function(renderTo, config)
27489 renderTo = config.renderTo || false;
27492 Roo.apply(this, config);
27496 * Fires when this button is clicked
27497 * @param {Button} this
27498 * @param {EventObject} e The click event
27503 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
27504 * @param {Button} this
27505 * @param {Boolean} pressed
27510 * Fires when the mouse hovers over the button
27511 * @param {Button} this
27512 * @param {Event} e The event object
27514 'mouseover' : true,
27517 * Fires when the mouse exits the button
27518 * @param {Button} this
27519 * @param {Event} e The event object
27524 * Fires when the button is rendered
27525 * @param {Button} this
27530 this.menu = Roo.menu.MenuMgr.get(this.menu);
27532 // register listeners first!! - so render can be captured..
27533 Roo.util.Observable.call(this);
27535 this.render(renderTo);
27541 Roo.extend(Roo.Button, Roo.util.Observable, {
27547 * Read-only. True if this button is hidden
27552 * Read-only. True if this button is disabled
27557 * Read-only. True if this button is pressed (only if enableToggle = true)
27563 * @cfg {Number} tabIndex
27564 * The DOM tabIndex for this button (defaults to undefined)
27566 tabIndex : undefined,
27569 * @cfg {Boolean} enableToggle
27570 * True to enable pressed/not pressed toggling (defaults to false)
27572 enableToggle: false,
27574 * @cfg {Mixed} menu
27575 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
27579 * @cfg {String} menuAlign
27580 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
27582 menuAlign : "tl-bl?",
27585 * @cfg {String} iconCls
27586 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
27588 iconCls : undefined,
27590 * @cfg {String} type
27591 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
27596 menuClassTarget: 'tr',
27599 * @cfg {String} clickEvent
27600 * The type of event to map to the button's event handler (defaults to 'click')
27602 clickEvent : 'click',
27605 * @cfg {Boolean} handleMouseEvents
27606 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
27608 handleMouseEvents : true,
27611 * @cfg {String} tooltipType
27612 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
27614 tooltipType : 'qtip',
27617 * @cfg {String} cls
27618 * A CSS class to apply to the button's main element.
27622 * @cfg {Roo.Template} template (Optional)
27623 * An {@link Roo.Template} with which to create the Button's main element. This Template must
27624 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
27625 * require code modifications if required elements (e.g. a button) aren't present.
27629 render : function(renderTo){
27631 if(this.hideParent){
27632 this.parentEl = Roo.get(renderTo);
27634 if(!this.dhconfig){
27635 if(!this.template){
27636 if(!Roo.Button.buttonTemplate){
27637 // hideous table template
27638 Roo.Button.buttonTemplate = new Roo.Template(
27639 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
27640 '<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>',
27641 "</tr></tbody></table>");
27643 this.template = Roo.Button.buttonTemplate;
27645 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
27646 var btnEl = btn.child("button:first");
27647 btnEl.on('focus', this.onFocus, this);
27648 btnEl.on('blur', this.onBlur, this);
27650 btn.addClass(this.cls);
27653 btnEl.setStyle('background-image', 'url(' +this.icon +')');
27656 btnEl.addClass(this.iconCls);
27658 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
27661 if(this.tabIndex !== undefined){
27662 btnEl.dom.tabIndex = this.tabIndex;
27665 if(typeof this.tooltip == 'object'){
27666 Roo.QuickTips.tips(Roo.apply({
27670 btnEl.dom[this.tooltipType] = this.tooltip;
27674 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
27678 this.el.dom.id = this.el.id = this.id;
27681 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
27682 this.menu.on("show", this.onMenuShow, this);
27683 this.menu.on("hide", this.onMenuHide, this);
27685 btn.addClass("x-btn");
27686 if(Roo.isIE && !Roo.isIE7){
27687 this.autoWidth.defer(1, this);
27691 if(this.handleMouseEvents){
27692 btn.on("mouseover", this.onMouseOver, this);
27693 btn.on("mouseout", this.onMouseOut, this);
27694 btn.on("mousedown", this.onMouseDown, this);
27696 btn.on(this.clickEvent, this.onClick, this);
27697 //btn.on("mouseup", this.onMouseUp, this);
27704 Roo.ButtonToggleMgr.register(this);
27706 this.el.addClass("x-btn-pressed");
27709 var repeater = new Roo.util.ClickRepeater(btn,
27710 typeof this.repeat == "object" ? this.repeat : {}
27712 repeater.on("click", this.onClick, this);
27715 this.fireEvent('render', this);
27719 * Returns the button's underlying element
27720 * @return {Roo.Element} The element
27722 getEl : function(){
27727 * Destroys this Button and removes any listeners.
27729 destroy : function(){
27730 Roo.ButtonToggleMgr.unregister(this);
27731 this.el.removeAllListeners();
27732 this.purgeListeners();
27737 autoWidth : function(){
27739 this.el.setWidth("auto");
27740 if(Roo.isIE7 && Roo.isStrict){
27741 var ib = this.el.child('button');
27742 if(ib && ib.getWidth() > 20){
27744 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
27749 this.el.beginMeasure();
27751 if(this.el.getWidth() < this.minWidth){
27752 this.el.setWidth(this.minWidth);
27755 this.el.endMeasure();
27762 * Assigns this button's click handler
27763 * @param {Function} handler The function to call when the button is clicked
27764 * @param {Object} scope (optional) Scope for the function passed in
27766 setHandler : function(handler, scope){
27767 this.handler = handler;
27768 this.scope = scope;
27772 * Sets this button's text
27773 * @param {String} text The button text
27775 setText : function(text){
27778 this.el.child("td.x-btn-center button.x-btn-text").update(text);
27784 * Gets the text for this button
27785 * @return {String} The button text
27787 getText : function(){
27795 this.hidden = false;
27797 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
27805 this.hidden = true;
27807 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
27812 * Convenience function for boolean show/hide
27813 * @param {Boolean} visible True to show, false to hide
27815 setVisible: function(visible){
27824 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
27825 * @param {Boolean} state (optional) Force a particular state
27827 toggle : function(state){
27828 state = state === undefined ? !this.pressed : state;
27829 if(state != this.pressed){
27831 this.el.addClass("x-btn-pressed");
27832 this.pressed = true;
27833 this.fireEvent("toggle", this, true);
27835 this.el.removeClass("x-btn-pressed");
27836 this.pressed = false;
27837 this.fireEvent("toggle", this, false);
27839 if(this.toggleHandler){
27840 this.toggleHandler.call(this.scope || this, this, state);
27848 focus : function(){
27849 this.el.child('button:first').focus();
27853 * Disable this button
27855 disable : function(){
27857 this.el.addClass("x-btn-disabled");
27859 this.disabled = true;
27863 * Enable this button
27865 enable : function(){
27867 this.el.removeClass("x-btn-disabled");
27869 this.disabled = false;
27873 * Convenience function for boolean enable/disable
27874 * @param {Boolean} enabled True to enable, false to disable
27876 setDisabled : function(v){
27877 this[v !== true ? "enable" : "disable"]();
27881 onClick : function(e)
27884 e.preventDefault();
27889 if(!this.disabled){
27890 if(this.enableToggle){
27893 if(this.menu && !this.menu.isVisible()){
27894 this.menu.show(this.el, this.menuAlign);
27896 this.fireEvent("click", this, e);
27898 this.el.removeClass("x-btn-over");
27899 this.handler.call(this.scope || this, this, e);
27904 onMouseOver : function(e){
27905 if(!this.disabled){
27906 this.el.addClass("x-btn-over");
27907 this.fireEvent('mouseover', this, e);
27911 onMouseOut : function(e){
27912 if(!e.within(this.el, true)){
27913 this.el.removeClass("x-btn-over");
27914 this.fireEvent('mouseout', this, e);
27918 onFocus : function(e){
27919 if(!this.disabled){
27920 this.el.addClass("x-btn-focus");
27924 onBlur : function(e){
27925 this.el.removeClass("x-btn-focus");
27928 onMouseDown : function(e){
27929 if(!this.disabled && e.button == 0){
27930 this.el.addClass("x-btn-click");
27931 Roo.get(document).on('mouseup', this.onMouseUp, this);
27935 onMouseUp : function(e){
27937 this.el.removeClass("x-btn-click");
27938 Roo.get(document).un('mouseup', this.onMouseUp, this);
27942 onMenuShow : function(e){
27943 this.el.addClass("x-btn-menu-active");
27946 onMenuHide : function(e){
27947 this.el.removeClass("x-btn-menu-active");
27951 // Private utility class used by Button
27952 Roo.ButtonToggleMgr = function(){
27955 function toggleGroup(btn, state){
27957 var g = groups[btn.toggleGroup];
27958 for(var i = 0, l = g.length; i < l; i++){
27960 g[i].toggle(false);
27967 register : function(btn){
27968 if(!btn.toggleGroup){
27971 var g = groups[btn.toggleGroup];
27973 g = groups[btn.toggleGroup] = [];
27976 btn.on("toggle", toggleGroup);
27979 unregister : function(btn){
27980 if(!btn.toggleGroup){
27983 var g = groups[btn.toggleGroup];
27986 btn.un("toggle", toggleGroup);
27992 * Ext JS Library 1.1.1
27993 * Copyright(c) 2006-2007, Ext JS, LLC.
27995 * Originally Released Under LGPL - original licence link has changed is not relivant.
27998 * <script type="text/javascript">
28002 * @class Roo.SplitButton
28003 * @extends Roo.Button
28004 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
28005 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
28006 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
28007 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
28008 * @cfg {String} arrowTooltip The title attribute of the arrow
28010 * Create a new menu button
28011 * @param {String/HTMLElement/Element} renderTo The element to append the button to
28012 * @param {Object} config The config object
28014 Roo.SplitButton = function(renderTo, config){
28015 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
28017 * @event arrowclick
28018 * Fires when this button's arrow is clicked
28019 * @param {SplitButton} this
28020 * @param {EventObject} e The click event
28022 this.addEvents({"arrowclick":true});
28025 Roo.extend(Roo.SplitButton, Roo.Button, {
28026 render : function(renderTo){
28027 // this is one sweet looking template!
28028 var tpl = new Roo.Template(
28029 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
28030 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
28031 '<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>',
28032 "</tbody></table></td><td>",
28033 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
28034 '<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>',
28035 "</tbody></table></td></tr></table>"
28037 var btn = tpl.append(renderTo, [this.text, this.type], true);
28038 var btnEl = btn.child("button");
28040 btn.addClass(this.cls);
28043 btnEl.setStyle('background-image', 'url(' +this.icon +')');
28046 btnEl.addClass(this.iconCls);
28048 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
28052 if(this.handleMouseEvents){
28053 btn.on("mouseover", this.onMouseOver, this);
28054 btn.on("mouseout", this.onMouseOut, this);
28055 btn.on("mousedown", this.onMouseDown, this);
28056 btn.on("mouseup", this.onMouseUp, this);
28058 btn.on(this.clickEvent, this.onClick, this);
28060 if(typeof this.tooltip == 'object'){
28061 Roo.QuickTips.tips(Roo.apply({
28065 btnEl.dom[this.tooltipType] = this.tooltip;
28068 if(this.arrowTooltip){
28069 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
28078 this.el.addClass("x-btn-pressed");
28080 if(Roo.isIE && !Roo.isIE7){
28081 this.autoWidth.defer(1, this);
28086 this.menu.on("show", this.onMenuShow, this);
28087 this.menu.on("hide", this.onMenuHide, this);
28089 this.fireEvent('render', this);
28093 autoWidth : function(){
28095 var tbl = this.el.child("table:first");
28096 var tbl2 = this.el.child("table:last");
28097 this.el.setWidth("auto");
28098 tbl.setWidth("auto");
28099 if(Roo.isIE7 && Roo.isStrict){
28100 var ib = this.el.child('button:first');
28101 if(ib && ib.getWidth() > 20){
28103 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
28108 this.el.beginMeasure();
28110 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
28111 tbl.setWidth(this.minWidth-tbl2.getWidth());
28114 this.el.endMeasure();
28117 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
28121 * Sets this button's click handler
28122 * @param {Function} handler The function to call when the button is clicked
28123 * @param {Object} scope (optional) Scope for the function passed above
28125 setHandler : function(handler, scope){
28126 this.handler = handler;
28127 this.scope = scope;
28131 * Sets this button's arrow click handler
28132 * @param {Function} handler The function to call when the arrow is clicked
28133 * @param {Object} scope (optional) Scope for the function passed above
28135 setArrowHandler : function(handler, scope){
28136 this.arrowHandler = handler;
28137 this.scope = scope;
28143 focus : function(){
28145 this.el.child("button:first").focus();
28150 onClick : function(e){
28151 e.preventDefault();
28152 if(!this.disabled){
28153 if(e.getTarget(".x-btn-menu-arrow-wrap")){
28154 if(this.menu && !this.menu.isVisible()){
28155 this.menu.show(this.el, this.menuAlign);
28157 this.fireEvent("arrowclick", this, e);
28158 if(this.arrowHandler){
28159 this.arrowHandler.call(this.scope || this, this, e);
28162 this.fireEvent("click", this, e);
28164 this.handler.call(this.scope || this, this, e);
28170 onMouseDown : function(e){
28171 if(!this.disabled){
28172 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
28176 onMouseUp : function(e){
28177 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
28182 // backwards compat
28183 Roo.MenuButton = Roo.SplitButton;/*
28185 * Ext JS Library 1.1.1
28186 * Copyright(c) 2006-2007, Ext JS, LLC.
28188 * Originally Released Under LGPL - original licence link has changed is not relivant.
28191 * <script type="text/javascript">
28195 * @class Roo.Toolbar
28196 * Basic Toolbar class.
28198 * Creates a new Toolbar
28199 * @param {Object} container The config object
28201 Roo.Toolbar = function(container, buttons, config)
28203 /// old consturctor format still supported..
28204 if(container instanceof Array){ // omit the container for later rendering
28205 buttons = container;
28209 if (typeof(container) == 'object' && container.xtype) {
28210 config = container;
28211 container = config.container;
28212 buttons = config.buttons || []; // not really - use items!!
28215 if (config && config.items) {
28216 xitems = config.items;
28217 delete config.items;
28219 Roo.apply(this, config);
28220 this.buttons = buttons;
28223 this.render(container);
28225 this.xitems = xitems;
28226 Roo.each(xitems, function(b) {
28232 Roo.Toolbar.prototype = {
28234 * @cfg {Array} items
28235 * array of button configs or elements to add (will be converted to a MixedCollection)
28239 * @cfg {String/HTMLElement/Element} container
28240 * The id or element that will contain the toolbar
28243 render : function(ct){
28244 this.el = Roo.get(ct);
28246 this.el.addClass(this.cls);
28248 // using a table allows for vertical alignment
28249 // 100% width is needed by Safari...
28250 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
28251 this.tr = this.el.child("tr", true);
28253 this.items = new Roo.util.MixedCollection(false, function(o){
28254 return o.id || ("item" + (++autoId));
28257 this.add.apply(this, this.buttons);
28258 delete this.buttons;
28263 * Adds element(s) to the toolbar -- this function takes a variable number of
28264 * arguments of mixed type and adds them to the toolbar.
28265 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
28267 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
28268 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
28269 * <li>Field: Any form field (equivalent to {@link #addField})</li>
28270 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
28271 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
28272 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
28273 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
28274 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
28275 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
28277 * @param {Mixed} arg2
28278 * @param {Mixed} etc.
28281 var a = arguments, l = a.length;
28282 for(var i = 0; i < l; i++){
28287 _add : function(el) {
28290 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
28293 if (el.applyTo){ // some kind of form field
28294 return this.addField(el);
28296 if (el.render){ // some kind of Toolbar.Item
28297 return this.addItem(el);
28299 if (typeof el == "string"){ // string
28300 if(el == "separator" || el == "-"){
28301 return this.addSeparator();
28304 return this.addSpacer();
28307 return this.addFill();
28309 return this.addText(el);
28312 if(el.tagName){ // element
28313 return this.addElement(el);
28315 if(typeof el == "object"){ // must be button config?
28316 return this.addButton(el);
28318 // and now what?!?!
28324 * Add an Xtype element
28325 * @param {Object} xtype Xtype Object
28326 * @return {Object} created Object
28328 addxtype : function(e){
28329 return this.add(e);
28333 * Returns the Element for this toolbar.
28334 * @return {Roo.Element}
28336 getEl : function(){
28342 * @return {Roo.Toolbar.Item} The separator item
28344 addSeparator : function(){
28345 return this.addItem(new Roo.Toolbar.Separator());
28349 * Adds a spacer element
28350 * @return {Roo.Toolbar.Spacer} The spacer item
28352 addSpacer : function(){
28353 return this.addItem(new Roo.Toolbar.Spacer());
28357 * Adds a fill element that forces subsequent additions to the right side of the toolbar
28358 * @return {Roo.Toolbar.Fill} The fill item
28360 addFill : function(){
28361 return this.addItem(new Roo.Toolbar.Fill());
28365 * Adds any standard HTML element to the toolbar
28366 * @param {String/HTMLElement/Element} el The element or id of the element to add
28367 * @return {Roo.Toolbar.Item} The element's item
28369 addElement : function(el){
28370 return this.addItem(new Roo.Toolbar.Item(el));
28373 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
28374 * @type Roo.util.MixedCollection
28379 * Adds any Toolbar.Item or subclass
28380 * @param {Roo.Toolbar.Item} item
28381 * @return {Roo.Toolbar.Item} The item
28383 addItem : function(item){
28384 var td = this.nextBlock();
28386 this.items.add(item);
28391 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
28392 * @param {Object/Array} config A button config or array of configs
28393 * @return {Roo.Toolbar.Button/Array}
28395 addButton : function(config){
28396 if(config instanceof Array){
28398 for(var i = 0, len = config.length; i < len; i++) {
28399 buttons.push(this.addButton(config[i]));
28404 if(!(config instanceof Roo.Toolbar.Button)){
28406 new Roo.Toolbar.SplitButton(config) :
28407 new Roo.Toolbar.Button(config);
28409 var td = this.nextBlock();
28416 * Adds text to the toolbar
28417 * @param {String} text The text to add
28418 * @return {Roo.Toolbar.Item} The element's item
28420 addText : function(text){
28421 return this.addItem(new Roo.Toolbar.TextItem(text));
28425 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
28426 * @param {Number} index The index where the item is to be inserted
28427 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
28428 * @return {Roo.Toolbar.Button/Item}
28430 insertButton : function(index, item){
28431 if(item instanceof Array){
28433 for(var i = 0, len = item.length; i < len; i++) {
28434 buttons.push(this.insertButton(index + i, item[i]));
28438 if (!(item instanceof Roo.Toolbar.Button)){
28439 item = new Roo.Toolbar.Button(item);
28441 var td = document.createElement("td");
28442 this.tr.insertBefore(td, this.tr.childNodes[index]);
28444 this.items.insert(index, item);
28449 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
28450 * @param {Object} config
28451 * @return {Roo.Toolbar.Item} The element's item
28453 addDom : function(config, returnEl){
28454 var td = this.nextBlock();
28455 Roo.DomHelper.overwrite(td, config);
28456 var ti = new Roo.Toolbar.Item(td.firstChild);
28458 this.items.add(ti);
28463 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
28464 * @type Roo.util.MixedCollection
28469 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc).
28470 * Note: the field should not have been rendered yet. For a field that has already been
28471 * rendered, use {@link #addElement}.
28472 * @param {Roo.form.Field} field
28473 * @return {Roo.ToolbarItem}
28477 addField : function(field) {
28478 if (!this.fields) {
28480 this.fields = new Roo.util.MixedCollection(false, function(o){
28481 return o.id || ("item" + (++autoId));
28486 var td = this.nextBlock();
28488 var ti = new Roo.Toolbar.Item(td.firstChild);
28490 this.items.add(ti);
28491 this.fields.add(field);
28502 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
28503 this.el.child('div').hide();
28511 this.el.child('div').show();
28515 nextBlock : function(){
28516 var td = document.createElement("td");
28517 this.tr.appendChild(td);
28522 destroy : function(){
28523 if(this.items){ // rendered?
28524 Roo.destroy.apply(Roo, this.items.items);
28526 if(this.fields){ // rendered?
28527 Roo.destroy.apply(Roo, this.fields.items);
28529 Roo.Element.uncache(this.el, this.tr);
28534 * @class Roo.Toolbar.Item
28535 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
28537 * Creates a new Item
28538 * @param {HTMLElement} el
28540 Roo.Toolbar.Item = function(el){
28542 if (typeof (el.xtype) != 'undefined') {
28547 this.el = Roo.getDom(el);
28548 this.id = Roo.id(this.el);
28549 this.hidden = false;
28554 * Fires when the button is rendered
28555 * @param {Button} this
28559 Roo.Toolbar.Item.superclass.constructor.call(this,cfg);
28561 Roo.extend(Roo.Toolbar.Item, Roo.util.Observable, {
28562 //Roo.Toolbar.Item.prototype = {
28565 * Get this item's HTML Element
28566 * @return {HTMLElement}
28568 getEl : function(){
28573 render : function(td){
28576 td.appendChild(this.el);
28578 this.fireEvent('render', this);
28582 * Removes and destroys this item.
28584 destroy : function(){
28585 this.td.parentNode.removeChild(this.td);
28592 this.hidden = false;
28593 this.td.style.display = "";
28600 this.hidden = true;
28601 this.td.style.display = "none";
28605 * Convenience function for boolean show/hide.
28606 * @param {Boolean} visible true to show/false to hide
28608 setVisible: function(visible){
28617 * Try to focus this item.
28619 focus : function(){
28620 Roo.fly(this.el).focus();
28624 * Disables this item.
28626 disable : function(){
28627 Roo.fly(this.td).addClass("x-item-disabled");
28628 this.disabled = true;
28629 this.el.disabled = true;
28633 * Enables this item.
28635 enable : function(){
28636 Roo.fly(this.td).removeClass("x-item-disabled");
28637 this.disabled = false;
28638 this.el.disabled = false;
28644 * @class Roo.Toolbar.Separator
28645 * @extends Roo.Toolbar.Item
28646 * A simple toolbar separator class
28648 * Creates a new Separator
28650 Roo.Toolbar.Separator = function(cfg){
28652 var s = document.createElement("span");
28653 s.className = "ytb-sep";
28658 Roo.Toolbar.Separator.superclass.constructor.call(this, cfg || s);
28660 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
28661 enable:Roo.emptyFn,
28662 disable:Roo.emptyFn,
28667 * @class Roo.Toolbar.Spacer
28668 * @extends Roo.Toolbar.Item
28669 * A simple element that adds extra horizontal space to a toolbar.
28671 * Creates a new Spacer
28673 Roo.Toolbar.Spacer = function(cfg){
28674 var s = document.createElement("div");
28675 s.className = "ytb-spacer";
28679 Roo.Toolbar.Spacer.superclass.constructor.call(this, cfg || s);
28681 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
28682 enable:Roo.emptyFn,
28683 disable:Roo.emptyFn,
28688 * @class Roo.Toolbar.Fill
28689 * @extends Roo.Toolbar.Spacer
28690 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
28692 * Creates a new Spacer
28694 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
28696 render : function(td){
28697 td.style.width = '100%';
28698 Roo.Toolbar.Fill.superclass.render.call(this, td);
28703 * @class Roo.Toolbar.TextItem
28704 * @extends Roo.Toolbar.Item
28705 * A simple class that renders text directly into a toolbar.
28707 * Creates a new TextItem
28708 * @param {String} text
28710 Roo.Toolbar.TextItem = function(cfg){
28711 var text = cfg || "";
28712 if (typeof(cfg) == 'object') {
28713 text = cfg.text || "";
28717 var s = document.createElement("span");
28718 s.className = "ytb-text";
28719 s.innerHTML = text;
28724 Roo.Toolbar.TextItem.superclass.constructor.call(this, cfg || s);
28726 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
28729 enable:Roo.emptyFn,
28730 disable:Roo.emptyFn,
28735 * @class Roo.Toolbar.Button
28736 * @extends Roo.Button
28737 * A button that renders into a toolbar.
28739 * Creates a new Button
28740 * @param {Object} config A standard {@link Roo.Button} config object
28742 Roo.Toolbar.Button = function(config){
28743 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
28745 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
28746 render : function(td){
28748 Roo.Toolbar.Button.superclass.render.call(this, td);
28752 * Removes and destroys this button
28754 destroy : function(){
28755 Roo.Toolbar.Button.superclass.destroy.call(this);
28756 this.td.parentNode.removeChild(this.td);
28760 * Shows this button
28763 this.hidden = false;
28764 this.td.style.display = "";
28768 * Hides this button
28771 this.hidden = true;
28772 this.td.style.display = "none";
28776 * Disables this item
28778 disable : function(){
28779 Roo.fly(this.td).addClass("x-item-disabled");
28780 this.disabled = true;
28784 * Enables this item
28786 enable : function(){
28787 Roo.fly(this.td).removeClass("x-item-disabled");
28788 this.disabled = false;
28791 // backwards compat
28792 Roo.ToolbarButton = Roo.Toolbar.Button;
28795 * @class Roo.Toolbar.SplitButton
28796 * @extends Roo.SplitButton
28797 * A menu button that renders into a toolbar.
28799 * Creates a new SplitButton
28800 * @param {Object} config A standard {@link Roo.SplitButton} config object
28802 Roo.Toolbar.SplitButton = function(config){
28803 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
28805 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
28806 render : function(td){
28808 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
28812 * Removes and destroys this button
28814 destroy : function(){
28815 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
28816 this.td.parentNode.removeChild(this.td);
28820 * Shows this button
28823 this.hidden = false;
28824 this.td.style.display = "";
28828 * Hides this button
28831 this.hidden = true;
28832 this.td.style.display = "none";
28836 // backwards compat
28837 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
28839 * Ext JS Library 1.1.1
28840 * Copyright(c) 2006-2007, Ext JS, LLC.
28842 * Originally Released Under LGPL - original licence link has changed is not relivant.
28845 * <script type="text/javascript">
28849 * @class Roo.PagingToolbar
28850 * @extends Roo.Toolbar
28851 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
28853 * Create a new PagingToolbar
28854 * @param {Object} config The config object
28856 Roo.PagingToolbar = function(el, ds, config)
28858 // old args format still supported... - xtype is prefered..
28859 if (typeof(el) == 'object' && el.xtype) {
28860 // created from xtype...
28862 ds = el.dataSource;
28863 el = config.container;
28866 if (config.items) {
28867 items = config.items;
28871 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
28874 this.renderButtons(this.el);
28877 // supprot items array.
28879 Roo.each(items, function(e) {
28880 this.add(Roo.factory(e));
28885 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
28887 * @cfg {Roo.data.Store} dataSource
28888 * The underlying data store providing the paged data
28891 * @cfg {String/HTMLElement/Element} container
28892 * container The id or element that will contain the toolbar
28895 * @cfg {Boolean} displayInfo
28896 * True to display the displayMsg (defaults to false)
28899 * @cfg {Number} pageSize
28900 * The number of records to display per page (defaults to 20)
28904 * @cfg {String} displayMsg
28905 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
28907 displayMsg : 'Displaying {0} - {1} of {2}',
28909 * @cfg {String} emptyMsg
28910 * The message to display when no records are found (defaults to "No data to display")
28912 emptyMsg : 'No data to display',
28914 * Customizable piece of the default paging text (defaults to "Page")
28917 beforePageText : "Page",
28919 * Customizable piece of the default paging text (defaults to "of %0")
28922 afterPageText : "of {0}",
28924 * Customizable piece of the default paging text (defaults to "First Page")
28927 firstText : "First Page",
28929 * Customizable piece of the default paging text (defaults to "Previous Page")
28932 prevText : "Previous Page",
28934 * Customizable piece of the default paging text (defaults to "Next Page")
28937 nextText : "Next Page",
28939 * Customizable piece of the default paging text (defaults to "Last Page")
28942 lastText : "Last Page",
28944 * Customizable piece of the default paging text (defaults to "Refresh")
28947 refreshText : "Refresh",
28950 renderButtons : function(el){
28951 Roo.PagingToolbar.superclass.render.call(this, el);
28952 this.first = this.addButton({
28953 tooltip: this.firstText,
28954 cls: "x-btn-icon x-grid-page-first",
28956 handler: this.onClick.createDelegate(this, ["first"])
28958 this.prev = this.addButton({
28959 tooltip: this.prevText,
28960 cls: "x-btn-icon x-grid-page-prev",
28962 handler: this.onClick.createDelegate(this, ["prev"])
28964 //this.addSeparator();
28965 this.add(this.beforePageText);
28966 this.field = Roo.get(this.addDom({
28971 cls: "x-grid-page-number"
28973 this.field.on("keydown", this.onPagingKeydown, this);
28974 this.field.on("focus", function(){this.dom.select();});
28975 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
28976 this.field.setHeight(18);
28977 //this.addSeparator();
28978 this.next = this.addButton({
28979 tooltip: this.nextText,
28980 cls: "x-btn-icon x-grid-page-next",
28982 handler: this.onClick.createDelegate(this, ["next"])
28984 this.last = this.addButton({
28985 tooltip: this.lastText,
28986 cls: "x-btn-icon x-grid-page-last",
28988 handler: this.onClick.createDelegate(this, ["last"])
28990 //this.addSeparator();
28991 this.loading = this.addButton({
28992 tooltip: this.refreshText,
28993 cls: "x-btn-icon x-grid-loading",
28994 handler: this.onClick.createDelegate(this, ["refresh"])
28997 if(this.displayInfo){
28998 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
29003 updateInfo : function(){
29004 if(this.displayEl){
29005 var count = this.ds.getCount();
29006 var msg = count == 0 ?
29010 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
29012 this.displayEl.update(msg);
29017 onLoad : function(ds, r, o){
29018 this.cursor = o.params ? o.params.start : 0;
29019 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
29021 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
29022 this.field.dom.value = ap;
29023 this.first.setDisabled(ap == 1);
29024 this.prev.setDisabled(ap == 1);
29025 this.next.setDisabled(ap == ps);
29026 this.last.setDisabled(ap == ps);
29027 this.loading.enable();
29032 getPageData : function(){
29033 var total = this.ds.getTotalCount();
29036 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
29037 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
29042 onLoadError : function(){
29043 this.loading.enable();
29047 onPagingKeydown : function(e){
29048 var k = e.getKey();
29049 var d = this.getPageData();
29051 var v = this.field.dom.value, pageNum;
29052 if(!v || isNaN(pageNum = parseInt(v, 10))){
29053 this.field.dom.value = d.activePage;
29056 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
29057 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
29060 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))
29062 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
29063 this.field.dom.value = pageNum;
29064 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
29067 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
29069 var v = this.field.dom.value, pageNum;
29070 var increment = (e.shiftKey) ? 10 : 1;
29071 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
29073 if(!v || isNaN(pageNum = parseInt(v, 10))) {
29074 this.field.dom.value = d.activePage;
29077 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
29079 this.field.dom.value = parseInt(v, 10) + increment;
29080 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
29081 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
29088 beforeLoad : function(){
29090 this.loading.disable();
29095 onClick : function(which){
29099 ds.load({params:{start: 0, limit: this.pageSize}});
29102 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
29105 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
29108 var total = ds.getTotalCount();
29109 var extra = total % this.pageSize;
29110 var lastStart = extra ? (total - extra) : total-this.pageSize;
29111 ds.load({params:{start: lastStart, limit: this.pageSize}});
29114 ds.load({params:{start: this.cursor, limit: this.pageSize}});
29120 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
29121 * @param {Roo.data.Store} store The data store to unbind
29123 unbind : function(ds){
29124 ds.un("beforeload", this.beforeLoad, this);
29125 ds.un("load", this.onLoad, this);
29126 ds.un("loadexception", this.onLoadError, this);
29127 ds.un("remove", this.updateInfo, this);
29128 ds.un("add", this.updateInfo, this);
29129 this.ds = undefined;
29133 * Binds the paging toolbar to the specified {@link Roo.data.Store}
29134 * @param {Roo.data.Store} store The data store to bind
29136 bind : function(ds){
29137 ds.on("beforeload", this.beforeLoad, this);
29138 ds.on("load", this.onLoad, this);
29139 ds.on("loadexception", this.onLoadError, this);
29140 ds.on("remove", this.updateInfo, this);
29141 ds.on("add", this.updateInfo, this);
29146 * Ext JS Library 1.1.1
29147 * Copyright(c) 2006-2007, Ext JS, LLC.
29149 * Originally Released Under LGPL - original licence link has changed is not relivant.
29152 * <script type="text/javascript">
29156 * @class Roo.Resizable
29157 * @extends Roo.util.Observable
29158 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
29159 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
29160 * 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
29161 * the element will be wrapped for you automatically.</p>
29162 * <p>Here is the list of valid resize handles:</p>
29165 ------ -------------------
29174 'hd' horizontal drag
29177 * <p>Here's an example showing the creation of a typical Resizable:</p>
29179 var resizer = new Roo.Resizable("element-id", {
29187 resizer.on("resize", myHandler);
29189 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
29190 * resizer.east.setDisplayed(false);</p>
29191 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
29192 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
29193 * resize operation's new size (defaults to [0, 0])
29194 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
29195 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
29196 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
29197 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
29198 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
29199 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
29200 * @cfg {Number} width The width of the element in pixels (defaults to null)
29201 * @cfg {Number} height The height of the element in pixels (defaults to null)
29202 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
29203 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
29204 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
29205 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
29206 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
29207 * in favor of the handles config option (defaults to false)
29208 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
29209 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
29210 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
29211 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
29212 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
29213 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
29214 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
29215 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
29216 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
29217 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
29218 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
29220 * Create a new resizable component
29221 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
29222 * @param {Object} config configuration options
29224 Roo.Resizable = function(el, config)
29226 this.el = Roo.get(el);
29228 if(config && config.wrap){
29229 config.resizeChild = this.el;
29230 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
29231 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
29232 this.el.setStyle("overflow", "hidden");
29233 this.el.setPositioning(config.resizeChild.getPositioning());
29234 config.resizeChild.clearPositioning();
29235 if(!config.width || !config.height){
29236 var csize = config.resizeChild.getSize();
29237 this.el.setSize(csize.width, csize.height);
29239 if(config.pinned && !config.adjustments){
29240 config.adjustments = "auto";
29244 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
29245 this.proxy.unselectable();
29246 this.proxy.enableDisplayMode('block');
29248 Roo.apply(this, config);
29251 this.disableTrackOver = true;
29252 this.el.addClass("x-resizable-pinned");
29254 // if the element isn't positioned, make it relative
29255 var position = this.el.getStyle("position");
29256 if(position != "absolute" && position != "fixed"){
29257 this.el.setStyle("position", "relative");
29259 if(!this.handles){ // no handles passed, must be legacy style
29260 this.handles = 's,e,se';
29261 if(this.multiDirectional){
29262 this.handles += ',n,w';
29265 if(this.handles == "all"){
29266 this.handles = "n s e w ne nw se sw";
29268 var hs = this.handles.split(/\s*?[,;]\s*?| /);
29269 var ps = Roo.Resizable.positions;
29270 for(var i = 0, len = hs.length; i < len; i++){
29271 if(hs[i] && ps[hs[i]]){
29272 var pos = ps[hs[i]];
29273 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
29277 this.corner = this.southeast;
29279 // updateBox = the box can move..
29280 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1 || this.handles.indexOf("hd") != -1) {
29281 this.updateBox = true;
29284 this.activeHandle = null;
29286 if(this.resizeChild){
29287 if(typeof this.resizeChild == "boolean"){
29288 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
29290 this.resizeChild = Roo.get(this.resizeChild, true);
29294 if(this.adjustments == "auto"){
29295 var rc = this.resizeChild;
29296 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
29297 if(rc && (hw || hn)){
29298 rc.position("relative");
29299 rc.setLeft(hw ? hw.el.getWidth() : 0);
29300 rc.setTop(hn ? hn.el.getHeight() : 0);
29302 this.adjustments = [
29303 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
29304 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
29308 if(this.draggable){
29309 this.dd = this.dynamic ?
29310 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
29311 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
29317 * @event beforeresize
29318 * Fired before resize is allowed. Set enabled to false to cancel resize.
29319 * @param {Roo.Resizable} this
29320 * @param {Roo.EventObject} e The mousedown event
29322 "beforeresize" : true,
29325 * Fired a resizing.
29326 * @param {Roo.Resizable} this
29327 * @param {Number} x The new x position
29328 * @param {Number} y The new y position
29329 * @param {Number} w The new w width
29330 * @param {Number} h The new h hight
29331 * @param {Roo.EventObject} e The mouseup event
29336 * Fired after a resize.
29337 * @param {Roo.Resizable} this
29338 * @param {Number} width The new width
29339 * @param {Number} height The new height
29340 * @param {Roo.EventObject} e The mouseup event
29345 if(this.width !== null && this.height !== null){
29346 this.resizeTo(this.width, this.height);
29348 this.updateChildSize();
29351 this.el.dom.style.zoom = 1;
29353 Roo.Resizable.superclass.constructor.call(this);
29356 Roo.extend(Roo.Resizable, Roo.util.Observable, {
29357 resizeChild : false,
29358 adjustments : [0, 0],
29368 multiDirectional : false,
29369 disableTrackOver : false,
29370 easing : 'easeOutStrong',
29371 widthIncrement : 0,
29372 heightIncrement : 0,
29376 preserveRatio : false,
29377 transparent: false,
29383 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
29385 constrainTo: undefined,
29387 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
29389 resizeRegion: undefined,
29393 * Perform a manual resize
29394 * @param {Number} width
29395 * @param {Number} height
29397 resizeTo : function(width, height){
29398 this.el.setSize(width, height);
29399 this.updateChildSize();
29400 this.fireEvent("resize", this, width, height, null);
29404 startSizing : function(e, handle){
29405 this.fireEvent("beforeresize", this, e);
29406 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
29409 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
29410 this.overlay.unselectable();
29411 this.overlay.enableDisplayMode("block");
29412 this.overlay.on("mousemove", this.onMouseMove, this);
29413 this.overlay.on("mouseup", this.onMouseUp, this);
29415 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
29417 this.resizing = true;
29418 this.startBox = this.el.getBox();
29419 this.startPoint = e.getXY();
29420 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
29421 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
29423 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
29424 this.overlay.show();
29426 if(this.constrainTo) {
29427 var ct = Roo.get(this.constrainTo);
29428 this.resizeRegion = ct.getRegion().adjust(
29429 ct.getFrameWidth('t'),
29430 ct.getFrameWidth('l'),
29431 -ct.getFrameWidth('b'),
29432 -ct.getFrameWidth('r')
29436 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
29438 this.proxy.setBox(this.startBox);
29440 this.proxy.setStyle('visibility', 'visible');
29446 onMouseDown : function(handle, e){
29449 this.activeHandle = handle;
29450 this.startSizing(e, handle);
29455 onMouseUp : function(e){
29456 var size = this.resizeElement();
29457 this.resizing = false;
29459 this.overlay.hide();
29461 this.fireEvent("resize", this, size.width, size.height, e);
29465 updateChildSize : function(){
29467 if(this.resizeChild){
29469 var child = this.resizeChild;
29470 var adj = this.adjustments;
29471 if(el.dom.offsetWidth){
29472 var b = el.getSize(true);
29473 child.setSize(b.width+adj[0], b.height+adj[1]);
29475 // Second call here for IE
29476 // The first call enables instant resizing and
29477 // the second call corrects scroll bars if they
29480 setTimeout(function(){
29481 if(el.dom.offsetWidth){
29482 var b = el.getSize(true);
29483 child.setSize(b.width+adj[0], b.height+adj[1]);
29491 snap : function(value, inc, min){
29492 if(!inc || !value) return value;
29493 var newValue = value;
29494 var m = value % inc;
29497 newValue = value + (inc-m);
29499 newValue = value - m;
29502 return Math.max(min, newValue);
29506 resizeElement : function(){
29507 var box = this.proxy.getBox();
29508 if(this.updateBox){
29509 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
29511 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
29513 this.updateChildSize();
29521 constrain : function(v, diff, m, mx){
29524 }else if(v - diff > mx){
29531 onMouseMove : function(e){
29534 try{// try catch so if something goes wrong the user doesn't get hung
29536 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
29540 //var curXY = this.startPoint;
29541 var curSize = this.curSize || this.startBox;
29542 var x = this.startBox.x, y = this.startBox.y;
29543 var ox = x, oy = y;
29544 var w = curSize.width, h = curSize.height;
29545 var ow = w, oh = h;
29546 var mw = this.minWidth, mh = this.minHeight;
29547 var mxw = this.maxWidth, mxh = this.maxHeight;
29548 var wi = this.widthIncrement;
29549 var hi = this.heightIncrement;
29551 var eventXY = e.getXY();
29552 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
29553 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
29555 var pos = this.activeHandle.position;
29560 w = Math.min(Math.max(mw, w), mxw);
29565 h = Math.min(Math.max(mh, h), mxh);
29570 w = Math.min(Math.max(mw, w), mxw);
29571 h = Math.min(Math.max(mh, h), mxh);
29574 diffY = this.constrain(h, diffY, mh, mxh);
29581 var adiffX = Math.abs(diffX);
29582 var sub = (adiffX % wi); // how much
29583 if (sub > (wi/2)) { // far enough to snap
29584 diffX = (diffX > 0) ? diffX-sub + wi : diffX+sub - wi;
29586 // remove difference..
29587 diffX = (diffX > 0) ? diffX-sub : diffX+sub;
29591 x = Math.max(this.minX, x);
29594 diffX = this.constrain(w, diffX, mw, mxw);
29600 w = Math.min(Math.max(mw, w), mxw);
29601 diffY = this.constrain(h, diffY, mh, mxh);
29606 diffX = this.constrain(w, diffX, mw, mxw);
29607 diffY = this.constrain(h, diffY, mh, mxh);
29614 diffX = this.constrain(w, diffX, mw, mxw);
29616 h = Math.min(Math.max(mh, h), mxh);
29622 var sw = this.snap(w, wi, mw);
29623 var sh = this.snap(h, hi, mh);
29624 if(sw != w || sh != h){
29647 if(this.preserveRatio){
29652 h = Math.min(Math.max(mh, h), mxh);
29657 w = Math.min(Math.max(mw, w), mxw);
29662 w = Math.min(Math.max(mw, w), mxw);
29668 w = Math.min(Math.max(mw, w), mxw);
29674 h = Math.min(Math.max(mh, h), mxh);
29682 h = Math.min(Math.max(mh, h), mxh);
29692 h = Math.min(Math.max(mh, h), mxh);
29700 if (pos == 'hdrag') {
29703 this.proxy.setBounds(x, y, w, h);
29705 this.resizeElement();
29709 this.fireEvent("resizing", this, x, y, w, h, e);
29713 handleOver : function(){
29715 this.el.addClass("x-resizable-over");
29720 handleOut : function(){
29721 if(!this.resizing){
29722 this.el.removeClass("x-resizable-over");
29727 * Returns the element this component is bound to.
29728 * @return {Roo.Element}
29730 getEl : function(){
29735 * Returns the resizeChild element (or null).
29736 * @return {Roo.Element}
29738 getResizeChild : function(){
29739 return this.resizeChild;
29741 groupHandler : function()
29746 * Destroys this resizable. If the element was wrapped and
29747 * removeEl is not true then the element remains.
29748 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
29750 destroy : function(removeEl){
29751 this.proxy.remove();
29753 this.overlay.removeAllListeners();
29754 this.overlay.remove();
29756 var ps = Roo.Resizable.positions;
29758 if(typeof ps[k] != "function" && this[ps[k]]){
29759 var h = this[ps[k]];
29760 h.el.removeAllListeners();
29765 this.el.update("");
29772 // hash to map config positions to true positions
29773 Roo.Resizable.positions = {
29774 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast",
29779 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
29781 // only initialize the template if resizable is used
29782 var tpl = Roo.DomHelper.createTemplate(
29783 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
29786 Roo.Resizable.Handle.prototype.tpl = tpl;
29788 this.position = pos;
29790 // show north drag fro topdra
29791 var handlepos = pos == 'hdrag' ? 'north' : pos;
29793 this.el = this.tpl.append(rz.el.dom, [handlepos], true);
29794 if (pos == 'hdrag') {
29795 this.el.setStyle('cursor', 'pointer');
29797 this.el.unselectable();
29799 this.el.setOpacity(0);
29801 this.el.on("mousedown", this.onMouseDown, this);
29802 if(!disableTrackOver){
29803 this.el.on("mouseover", this.onMouseOver, this);
29804 this.el.on("mouseout", this.onMouseOut, this);
29809 Roo.Resizable.Handle.prototype = {
29810 afterResize : function(rz){
29815 onMouseDown : function(e){
29816 this.rz.onMouseDown(this, e);
29819 onMouseOver : function(e){
29820 this.rz.handleOver(this, e);
29823 onMouseOut : function(e){
29824 this.rz.handleOut(this, e);
29828 * Ext JS Library 1.1.1
29829 * Copyright(c) 2006-2007, Ext JS, LLC.
29831 * Originally Released Under LGPL - original licence link has changed is not relivant.
29834 * <script type="text/javascript">
29838 * @class Roo.Editor
29839 * @extends Roo.Component
29840 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
29842 * Create a new Editor
29843 * @param {Roo.form.Field} field The Field object (or descendant)
29844 * @param {Object} config The config object
29846 Roo.Editor = function(field, config){
29847 Roo.Editor.superclass.constructor.call(this, config);
29848 this.field = field;
29851 * @event beforestartedit
29852 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
29853 * false from the handler of this event.
29854 * @param {Editor} this
29855 * @param {Roo.Element} boundEl The underlying element bound to this editor
29856 * @param {Mixed} value The field value being set
29858 "beforestartedit" : true,
29861 * Fires when this editor is displayed
29862 * @param {Roo.Element} boundEl The underlying element bound to this editor
29863 * @param {Mixed} value The starting field value
29865 "startedit" : true,
29867 * @event beforecomplete
29868 * Fires after a change has been made to the field, but before the change is reflected in the underlying
29869 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
29870 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
29871 * event will not fire since no edit actually occurred.
29872 * @param {Editor} this
29873 * @param {Mixed} value The current field value
29874 * @param {Mixed} startValue The original field value
29876 "beforecomplete" : true,
29879 * Fires after editing is complete and any changed value has been written to the underlying field.
29880 * @param {Editor} this
29881 * @param {Mixed} value The current field value
29882 * @param {Mixed} startValue The original field value
29886 * @event specialkey
29887 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
29888 * {@link Roo.EventObject#getKey} to determine which key was pressed.
29889 * @param {Roo.form.Field} this
29890 * @param {Roo.EventObject} e The event object
29892 "specialkey" : true
29896 Roo.extend(Roo.Editor, Roo.Component, {
29898 * @cfg {Boolean/String} autosize
29899 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
29900 * or "height" to adopt the height only (defaults to false)
29903 * @cfg {Boolean} revertInvalid
29904 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
29905 * validation fails (defaults to true)
29908 * @cfg {Boolean} ignoreNoChange
29909 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
29910 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
29911 * will never be ignored.
29914 * @cfg {Boolean} hideEl
29915 * False to keep the bound element visible while the editor is displayed (defaults to true)
29918 * @cfg {Mixed} value
29919 * The data value of the underlying field (defaults to "")
29923 * @cfg {String} alignment
29924 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
29928 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
29929 * for bottom-right shadow (defaults to "frame")
29933 * @cfg {Boolean} constrain True to constrain the editor to the viewport
29937 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
29939 completeOnEnter : false,
29941 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
29943 cancelOnEsc : false,
29945 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
29950 onRender : function(ct, position){
29951 this.el = new Roo.Layer({
29952 shadow: this.shadow,
29958 constrain: this.constrain
29960 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
29961 if(this.field.msgTarget != 'title'){
29962 this.field.msgTarget = 'qtip';
29964 this.field.render(this.el);
29966 this.field.el.dom.setAttribute('autocomplete', 'off');
29968 this.field.on("specialkey", this.onSpecialKey, this);
29969 if(this.swallowKeys){
29970 this.field.el.swallowEvent(['keydown','keypress']);
29973 this.field.on("blur", this.onBlur, this);
29974 if(this.field.grow){
29975 this.field.on("autosize", this.el.sync, this.el, {delay:1});
29979 onSpecialKey : function(field, e)
29981 //Roo.log('editor onSpecialKey');
29982 if(this.completeOnEnter && e.getKey() == e.ENTER){
29984 this.completeEdit();
29987 // do not fire special key otherwise it might hide close the editor...
29988 if(e.getKey() == e.ENTER){
29991 if(this.cancelOnEsc && e.getKey() == e.ESC){
29995 this.fireEvent('specialkey', field, e);
30000 * Starts the editing process and shows the editor.
30001 * @param {String/HTMLElement/Element} el The element to edit
30002 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
30003 * to the innerHTML of el.
30005 startEdit : function(el, value){
30007 this.completeEdit();
30009 this.boundEl = Roo.get(el);
30010 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
30011 if(!this.rendered){
30012 this.render(this.parentEl || document.body);
30014 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
30017 this.startValue = v;
30018 this.field.setValue(v);
30020 var sz = this.boundEl.getSize();
30021 switch(this.autoSize){
30023 this.setSize(sz.width, "");
30026 this.setSize("", sz.height);
30029 this.setSize(sz.width, sz.height);
30032 this.el.alignTo(this.boundEl, this.alignment);
30033 this.editing = true;
30035 Roo.QuickTips.disable();
30041 * Sets the height and width of this editor.
30042 * @param {Number} width The new width
30043 * @param {Number} height The new height
30045 setSize : function(w, h){
30046 this.field.setSize(w, h);
30053 * Realigns the editor to the bound field based on the current alignment config value.
30055 realign : function(){
30056 this.el.alignTo(this.boundEl, this.alignment);
30060 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
30061 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
30063 completeEdit : function(remainVisible){
30067 var v = this.getValue();
30068 if(this.revertInvalid !== false && !this.field.isValid()){
30069 v = this.startValue;
30070 this.cancelEdit(true);
30072 if(String(v) === String(this.startValue) && this.ignoreNoChange){
30073 this.editing = false;
30077 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
30078 this.editing = false;
30079 if(this.updateEl && this.boundEl){
30080 this.boundEl.update(v);
30082 if(remainVisible !== true){
30085 this.fireEvent("complete", this, v, this.startValue);
30090 onShow : function(){
30092 if(this.hideEl !== false){
30093 this.boundEl.hide();
30096 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
30097 this.fixIEFocus = true;
30098 this.deferredFocus.defer(50, this);
30100 this.field.focus();
30102 this.fireEvent("startedit", this.boundEl, this.startValue);
30105 deferredFocus : function(){
30107 this.field.focus();
30112 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
30113 * reverted to the original starting value.
30114 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
30115 * cancel (defaults to false)
30117 cancelEdit : function(remainVisible){
30119 this.setValue(this.startValue);
30120 if(remainVisible !== true){
30127 onBlur : function(){
30128 if(this.allowBlur !== true && this.editing){
30129 this.completeEdit();
30134 onHide : function(){
30136 this.completeEdit();
30140 if(this.field.collapse){
30141 this.field.collapse();
30144 if(this.hideEl !== false){
30145 this.boundEl.show();
30148 Roo.QuickTips.enable();
30153 * Sets the data value of the editor
30154 * @param {Mixed} value Any valid value supported by the underlying field
30156 setValue : function(v){
30157 this.field.setValue(v);
30161 * Gets the data value of the editor
30162 * @return {Mixed} The data value
30164 getValue : function(){
30165 return this.field.getValue();
30169 * Ext JS Library 1.1.1
30170 * Copyright(c) 2006-2007, Ext JS, LLC.
30172 * Originally Released Under LGPL - original licence link has changed is not relivant.
30175 * <script type="text/javascript">
30179 * @class Roo.BasicDialog
30180 * @extends Roo.util.Observable
30181 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
30183 var dlg = new Roo.BasicDialog("my-dlg", {
30192 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
30193 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
30194 dlg.addButton('Cancel', dlg.hide, dlg);
30197 <b>A Dialog should always be a direct child of the body element.</b>
30198 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
30199 * @cfg {String} title Default text to display in the title bar (defaults to null)
30200 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
30201 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
30202 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
30203 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
30204 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
30205 * (defaults to null with no animation)
30206 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
30207 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
30208 * property for valid values (defaults to 'all')
30209 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
30210 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
30211 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
30212 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
30213 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
30214 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
30215 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
30216 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
30217 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
30218 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
30219 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
30220 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
30221 * draggable = true (defaults to false)
30222 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
30223 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
30224 * shadow (defaults to false)
30225 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
30226 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
30227 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
30228 * @cfg {Array} buttons Array of buttons
30229 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
30231 * Create a new BasicDialog.
30232 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
30233 * @param {Object} config Configuration options
30235 Roo.BasicDialog = function(el, config){
30236 this.el = Roo.get(el);
30237 var dh = Roo.DomHelper;
30238 if(!this.el && config && config.autoCreate){
30239 if(typeof config.autoCreate == "object"){
30240 if(!config.autoCreate.id){
30241 config.autoCreate.id = el;
30243 this.el = dh.append(document.body,
30244 config.autoCreate, true);
30246 this.el = dh.append(document.body,
30247 {tag: "div", id: el, style:'visibility:hidden;'}, true);
30251 el.setDisplayed(true);
30252 el.hide = this.hideAction;
30254 el.addClass("x-dlg");
30256 Roo.apply(this, config);
30258 this.proxy = el.createProxy("x-dlg-proxy");
30259 this.proxy.hide = this.hideAction;
30260 this.proxy.setOpacity(.5);
30264 el.setWidth(config.width);
30267 el.setHeight(config.height);
30269 this.size = el.getSize();
30270 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
30271 this.xy = [config.x,config.y];
30273 this.xy = el.getCenterXY(true);
30275 /** The header element @type Roo.Element */
30276 this.header = el.child("> .x-dlg-hd");
30277 /** The body element @type Roo.Element */
30278 this.body = el.child("> .x-dlg-bd");
30279 /** The footer element @type Roo.Element */
30280 this.footer = el.child("> .x-dlg-ft");
30283 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
30286 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
30289 this.header.unselectable();
30291 this.header.update(this.title);
30293 // this element allows the dialog to be focused for keyboard event
30294 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
30295 this.focusEl.swallowEvent("click", true);
30297 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
30299 // wrap the body and footer for special rendering
30300 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
30302 this.bwrap.dom.appendChild(this.footer.dom);
30305 this.bg = this.el.createChild({
30306 tag: "div", cls:"x-dlg-bg",
30307 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
30309 this.centerBg = this.bg.child("div.x-dlg-bg-center");
30312 if(this.autoScroll !== false && !this.autoTabs){
30313 this.body.setStyle("overflow", "auto");
30316 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
30318 if(this.closable !== false){
30319 this.el.addClass("x-dlg-closable");
30320 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
30321 this.close.on("click", this.closeClick, this);
30322 this.close.addClassOnOver("x-dlg-close-over");
30324 if(this.collapsible !== false){
30325 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
30326 this.collapseBtn.on("click", this.collapseClick, this);
30327 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
30328 this.header.on("dblclick", this.collapseClick, this);
30330 if(this.resizable !== false){
30331 this.el.addClass("x-dlg-resizable");
30332 this.resizer = new Roo.Resizable(el, {
30333 minWidth: this.minWidth || 80,
30334 minHeight:this.minHeight || 80,
30335 handles: this.resizeHandles || "all",
30338 this.resizer.on("beforeresize", this.beforeResize, this);
30339 this.resizer.on("resize", this.onResize, this);
30341 if(this.draggable !== false){
30342 el.addClass("x-dlg-draggable");
30343 if (!this.proxyDrag) {
30344 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
30347 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
30349 dd.setHandleElId(this.header.id);
30350 dd.endDrag = this.endMove.createDelegate(this);
30351 dd.startDrag = this.startMove.createDelegate(this);
30352 dd.onDrag = this.onDrag.createDelegate(this);
30357 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
30358 this.mask.enableDisplayMode("block");
30360 this.el.addClass("x-dlg-modal");
30363 this.shadow = new Roo.Shadow({
30364 mode : typeof this.shadow == "string" ? this.shadow : "sides",
30365 offset : this.shadowOffset
30368 this.shadowOffset = 0;
30370 if(Roo.useShims && this.shim !== false){
30371 this.shim = this.el.createShim();
30372 this.shim.hide = this.hideAction;
30380 if (this.buttons) {
30381 var bts= this.buttons;
30383 Roo.each(bts, function(b) {
30392 * Fires when a key is pressed
30393 * @param {Roo.BasicDialog} this
30394 * @param {Roo.EventObject} e
30399 * Fires when this dialog is moved by the user.
30400 * @param {Roo.BasicDialog} this
30401 * @param {Number} x The new page X
30402 * @param {Number} y The new page Y
30407 * Fires when this dialog is resized by the user.
30408 * @param {Roo.BasicDialog} this
30409 * @param {Number} width The new width
30410 * @param {Number} height The new height
30414 * @event beforehide
30415 * Fires before this dialog is hidden.
30416 * @param {Roo.BasicDialog} this
30418 "beforehide" : true,
30421 * Fires when this dialog is hidden.
30422 * @param {Roo.BasicDialog} this
30426 * @event beforeshow
30427 * Fires before this dialog is shown.
30428 * @param {Roo.BasicDialog} this
30430 "beforeshow" : true,
30433 * Fires when this dialog is shown.
30434 * @param {Roo.BasicDialog} this
30438 el.on("keydown", this.onKeyDown, this);
30439 el.on("mousedown", this.toFront, this);
30440 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
30442 Roo.DialogManager.register(this);
30443 Roo.BasicDialog.superclass.constructor.call(this);
30446 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
30447 shadowOffset: Roo.isIE ? 6 : 5,
30450 minButtonWidth: 75,
30451 defaultButton: null,
30452 buttonAlign: "right",
30457 * Sets the dialog title text
30458 * @param {String} text The title text to display
30459 * @return {Roo.BasicDialog} this
30461 setTitle : function(text){
30462 this.header.update(text);
30467 closeClick : function(){
30472 collapseClick : function(){
30473 this[this.collapsed ? "expand" : "collapse"]();
30477 * Collapses the dialog to its minimized state (only the title bar is visible).
30478 * Equivalent to the user clicking the collapse dialog button.
30480 collapse : function(){
30481 if(!this.collapsed){
30482 this.collapsed = true;
30483 this.el.addClass("x-dlg-collapsed");
30484 this.restoreHeight = this.el.getHeight();
30485 this.resizeTo(this.el.getWidth(), this.header.getHeight());
30490 * Expands a collapsed dialog back to its normal state. Equivalent to the user
30491 * clicking the expand dialog button.
30493 expand : function(){
30494 if(this.collapsed){
30495 this.collapsed = false;
30496 this.el.removeClass("x-dlg-collapsed");
30497 this.resizeTo(this.el.getWidth(), this.restoreHeight);
30502 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
30503 * @return {Roo.TabPanel} The tabs component
30505 initTabs : function(){
30506 var tabs = this.getTabs();
30507 while(tabs.getTab(0)){
30510 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
30512 tabs.addTab(Roo.id(dom), dom.title);
30520 beforeResize : function(){
30521 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
30525 onResize : function(){
30526 this.refreshSize();
30527 this.syncBodyHeight();
30528 this.adjustAssets();
30530 this.fireEvent("resize", this, this.size.width, this.size.height);
30534 onKeyDown : function(e){
30535 if(this.isVisible()){
30536 this.fireEvent("keydown", this, e);
30541 * Resizes the dialog.
30542 * @param {Number} width
30543 * @param {Number} height
30544 * @return {Roo.BasicDialog} this
30546 resizeTo : function(width, height){
30547 this.el.setSize(width, height);
30548 this.size = {width: width, height: height};
30549 this.syncBodyHeight();
30550 if(this.fixedcenter){
30553 if(this.isVisible()){
30554 this.constrainXY();
30555 this.adjustAssets();
30557 this.fireEvent("resize", this, width, height);
30563 * Resizes the dialog to fit the specified content size.
30564 * @param {Number} width
30565 * @param {Number} height
30566 * @return {Roo.BasicDialog} this
30568 setContentSize : function(w, h){
30569 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
30570 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
30571 //if(!this.el.isBorderBox()){
30572 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
30573 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
30576 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
30577 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
30579 this.resizeTo(w, h);
30584 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
30585 * executed in response to a particular key being pressed while the dialog is active.
30586 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
30587 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
30588 * @param {Function} fn The function to call
30589 * @param {Object} scope (optional) The scope of the function
30590 * @return {Roo.BasicDialog} this
30592 addKeyListener : function(key, fn, scope){
30593 var keyCode, shift, ctrl, alt;
30594 if(typeof key == "object" && !(key instanceof Array)){
30595 keyCode = key["key"];
30596 shift = key["shift"];
30597 ctrl = key["ctrl"];
30602 var handler = function(dlg, e){
30603 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
30604 var k = e.getKey();
30605 if(keyCode instanceof Array){
30606 for(var i = 0, len = keyCode.length; i < len; i++){
30607 if(keyCode[i] == k){
30608 fn.call(scope || window, dlg, k, e);
30614 fn.call(scope || window, dlg, k, e);
30619 this.on("keydown", handler);
30624 * Returns the TabPanel component (creates it if it doesn't exist).
30625 * Note: If you wish to simply check for the existence of tabs without creating them,
30626 * check for a null 'tabs' property.
30627 * @return {Roo.TabPanel} The tabs component
30629 getTabs : function(){
30631 this.el.addClass("x-dlg-auto-tabs");
30632 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
30633 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
30639 * Adds a button to the footer section of the dialog.
30640 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
30641 * object or a valid Roo.DomHelper element config
30642 * @param {Function} handler The function called when the button is clicked
30643 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
30644 * @return {Roo.Button} The new button
30646 addButton : function(config, handler, scope){
30647 var dh = Roo.DomHelper;
30649 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
30651 if(!this.btnContainer){
30652 var tb = this.footer.createChild({
30654 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
30655 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
30657 this.btnContainer = tb.firstChild.firstChild.firstChild;
30662 minWidth: this.minButtonWidth,
30665 if(typeof config == "string"){
30666 bconfig.text = config;
30669 bconfig.dhconfig = config;
30671 Roo.apply(bconfig, config);
30675 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
30676 bconfig.position = Math.max(0, bconfig.position);
30677 fc = this.btnContainer.childNodes[bconfig.position];
30680 var btn = new Roo.Button(
30682 this.btnContainer.insertBefore(document.createElement("td"),fc)
30683 : this.btnContainer.appendChild(document.createElement("td")),
30684 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
30687 this.syncBodyHeight();
30690 * Array of all the buttons that have been added to this dialog via addButton
30695 this.buttons.push(btn);
30700 * Sets the default button to be focused when the dialog is displayed.
30701 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
30702 * @return {Roo.BasicDialog} this
30704 setDefaultButton : function(btn){
30705 this.defaultButton = btn;
30710 getHeaderFooterHeight : function(safe){
30713 height += this.header.getHeight();
30716 var fm = this.footer.getMargins();
30717 height += (this.footer.getHeight()+fm.top+fm.bottom);
30719 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
30720 height += this.centerBg.getPadding("tb");
30725 syncBodyHeight : function()
30727 var bd = this.body, // the text
30728 cb = this.centerBg, // wrapper around bottom.. but does not seem to be used..
30730 var height = this.size.height - this.getHeaderFooterHeight(false);
30731 bd.setHeight(height-bd.getMargins("tb"));
30732 var hh = this.header.getHeight();
30733 var h = this.size.height-hh;
30736 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
30737 bw.setHeight(h-cb.getPadding("tb"));
30739 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
30740 bd.setWidth(bw.getWidth(true));
30742 this.tabs.syncHeight();
30744 this.tabs.el.repaint();
30750 * Restores the previous state of the dialog if Roo.state is configured.
30751 * @return {Roo.BasicDialog} this
30753 restoreState : function(){
30754 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
30755 if(box && box.width){
30756 this.xy = [box.x, box.y];
30757 this.resizeTo(box.width, box.height);
30763 beforeShow : function(){
30765 if(this.fixedcenter){
30766 this.xy = this.el.getCenterXY(true);
30769 Roo.get(document.body).addClass("x-body-masked");
30770 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
30773 this.constrainXY();
30777 animShow : function(){
30778 var b = Roo.get(this.animateTarget).getBox();
30779 this.proxy.setSize(b.width, b.height);
30780 this.proxy.setLocation(b.x, b.y);
30782 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
30783 true, .35, this.showEl.createDelegate(this));
30787 * Shows the dialog.
30788 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
30789 * @return {Roo.BasicDialog} this
30791 show : function(animateTarget){
30792 if (this.fireEvent("beforeshow", this) === false){
30795 if(this.syncHeightBeforeShow){
30796 this.syncBodyHeight();
30797 }else if(this.firstShow){
30798 this.firstShow = false;
30799 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
30801 this.animateTarget = animateTarget || this.animateTarget;
30802 if(!this.el.isVisible()){
30804 if(this.animateTarget && Roo.get(this.animateTarget)){
30814 showEl : function(){
30816 this.el.setXY(this.xy);
30818 this.adjustAssets(true);
30821 // IE peekaboo bug - fix found by Dave Fenwick
30825 this.fireEvent("show", this);
30829 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
30830 * dialog itself will receive focus.
30832 focus : function(){
30833 if(this.defaultButton){
30834 this.defaultButton.focus();
30836 this.focusEl.focus();
30841 constrainXY : function(){
30842 if(this.constraintoviewport !== false){
30843 if(!this.viewSize){
30844 if(this.container){
30845 var s = this.container.getSize();
30846 this.viewSize = [s.width, s.height];
30848 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
30851 var s = Roo.get(this.container||document).getScroll();
30853 var x = this.xy[0], y = this.xy[1];
30854 var w = this.size.width, h = this.size.height;
30855 var vw = this.viewSize[0], vh = this.viewSize[1];
30856 // only move it if it needs it
30858 // first validate right/bottom
30859 if(x + w > vw+s.left){
30863 if(y + h > vh+s.top){
30867 // then make sure top/left isn't negative
30879 if(this.isVisible()){
30880 this.el.setLocation(x, y);
30881 this.adjustAssets();
30888 onDrag : function(){
30889 if(!this.proxyDrag){
30890 this.xy = this.el.getXY();
30891 this.adjustAssets();
30896 adjustAssets : function(doShow){
30897 var x = this.xy[0], y = this.xy[1];
30898 var w = this.size.width, h = this.size.height;
30899 if(doShow === true){
30901 this.shadow.show(this.el);
30907 if(this.shadow && this.shadow.isVisible()){
30908 this.shadow.show(this.el);
30910 if(this.shim && this.shim.isVisible()){
30911 this.shim.setBounds(x, y, w, h);
30916 adjustViewport : function(w, h){
30918 w = Roo.lib.Dom.getViewWidth();
30919 h = Roo.lib.Dom.getViewHeight();
30922 this.viewSize = [w, h];
30923 if(this.modal && this.mask.isVisible()){
30924 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
30925 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
30927 if(this.isVisible()){
30928 this.constrainXY();
30933 * Destroys this dialog and all its supporting elements (including any tabs, shim,
30934 * shadow, proxy, mask, etc.) Also removes all event listeners.
30935 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
30937 destroy : function(removeEl){
30938 if(this.isVisible()){
30939 this.animateTarget = null;
30942 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
30944 this.tabs.destroy(removeEl);
30957 for(var i = 0, len = this.buttons.length; i < len; i++){
30958 this.buttons[i].destroy();
30961 this.el.removeAllListeners();
30962 if(removeEl === true){
30963 this.el.update("");
30966 Roo.DialogManager.unregister(this);
30970 startMove : function(){
30971 if(this.proxyDrag){
30974 if(this.constraintoviewport !== false){
30975 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
30980 endMove : function(){
30981 if(!this.proxyDrag){
30982 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
30984 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
30987 this.refreshSize();
30988 this.adjustAssets();
30990 this.fireEvent("move", this, this.xy[0], this.xy[1]);
30994 * Brings this dialog to the front of any other visible dialogs
30995 * @return {Roo.BasicDialog} this
30997 toFront : function(){
30998 Roo.DialogManager.bringToFront(this);
31003 * Sends this dialog to the back (under) of any other visible dialogs
31004 * @return {Roo.BasicDialog} this
31006 toBack : function(){
31007 Roo.DialogManager.sendToBack(this);
31012 * Centers this dialog in the viewport
31013 * @return {Roo.BasicDialog} this
31015 center : function(){
31016 var xy = this.el.getCenterXY(true);
31017 this.moveTo(xy[0], xy[1]);
31022 * Moves the dialog's top-left corner to the specified point
31023 * @param {Number} x
31024 * @param {Number} y
31025 * @return {Roo.BasicDialog} this
31027 moveTo : function(x, y){
31029 if(this.isVisible()){
31030 this.el.setXY(this.xy);
31031 this.adjustAssets();
31037 * Aligns the dialog to the specified element
31038 * @param {String/HTMLElement/Roo.Element} element The element to align to.
31039 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
31040 * @param {Array} offsets (optional) Offset the positioning by [x, y]
31041 * @return {Roo.BasicDialog} this
31043 alignTo : function(element, position, offsets){
31044 this.xy = this.el.getAlignToXY(element, position, offsets);
31045 if(this.isVisible()){
31046 this.el.setXY(this.xy);
31047 this.adjustAssets();
31053 * Anchors an element to another element and realigns it when the window is resized.
31054 * @param {String/HTMLElement/Roo.Element} element The element to align to.
31055 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
31056 * @param {Array} offsets (optional) Offset the positioning by [x, y]
31057 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
31058 * is a number, it is used as the buffer delay (defaults to 50ms).
31059 * @return {Roo.BasicDialog} this
31061 anchorTo : function(el, alignment, offsets, monitorScroll){
31062 var action = function(){
31063 this.alignTo(el, alignment, offsets);
31065 Roo.EventManager.onWindowResize(action, this);
31066 var tm = typeof monitorScroll;
31067 if(tm != 'undefined'){
31068 Roo.EventManager.on(window, 'scroll', action, this,
31069 {buffer: tm == 'number' ? monitorScroll : 50});
31076 * Returns true if the dialog is visible
31077 * @return {Boolean}
31079 isVisible : function(){
31080 return this.el.isVisible();
31084 animHide : function(callback){
31085 var b = Roo.get(this.animateTarget).getBox();
31087 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
31089 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
31090 this.hideEl.createDelegate(this, [callback]));
31094 * Hides the dialog.
31095 * @param {Function} callback (optional) Function to call when the dialog is hidden
31096 * @return {Roo.BasicDialog} this
31098 hide : function(callback){
31099 if (this.fireEvent("beforehide", this) === false){
31103 this.shadow.hide();
31108 // sometimes animateTarget seems to get set.. causing problems...
31109 // this just double checks..
31110 if(this.animateTarget && Roo.get(this.animateTarget)) {
31111 this.animHide(callback);
31114 this.hideEl(callback);
31120 hideEl : function(callback){
31124 Roo.get(document.body).removeClass("x-body-masked");
31126 this.fireEvent("hide", this);
31127 if(typeof callback == "function"){
31133 hideAction : function(){
31134 this.setLeft("-10000px");
31135 this.setTop("-10000px");
31136 this.setStyle("visibility", "hidden");
31140 refreshSize : function(){
31141 this.size = this.el.getSize();
31142 this.xy = this.el.getXY();
31143 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
31147 // z-index is managed by the DialogManager and may be overwritten at any time
31148 setZIndex : function(index){
31150 this.mask.setStyle("z-index", index);
31153 this.shim.setStyle("z-index", ++index);
31156 this.shadow.setZIndex(++index);
31158 this.el.setStyle("z-index", ++index);
31160 this.proxy.setStyle("z-index", ++index);
31163 this.resizer.proxy.setStyle("z-index", ++index);
31166 this.lastZIndex = index;
31170 * Returns the element for this dialog
31171 * @return {Roo.Element} The underlying dialog Element
31173 getEl : function(){
31179 * @class Roo.DialogManager
31180 * Provides global access to BasicDialogs that have been created and
31181 * support for z-indexing (layering) multiple open dialogs.
31183 Roo.DialogManager = function(){
31185 var accessList = [];
31189 var sortDialogs = function(d1, d2){
31190 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
31194 var orderDialogs = function(){
31195 accessList.sort(sortDialogs);
31196 var seed = Roo.DialogManager.zseed;
31197 for(var i = 0, len = accessList.length; i < len; i++){
31198 var dlg = accessList[i];
31200 dlg.setZIndex(seed + (i*10));
31207 * The starting z-index for BasicDialogs (defaults to 9000)
31208 * @type Number The z-index value
31213 register : function(dlg){
31214 list[dlg.id] = dlg;
31215 accessList.push(dlg);
31219 unregister : function(dlg){
31220 delete list[dlg.id];
31223 if(!accessList.indexOf){
31224 for( i = 0, len = accessList.length; i < len; i++){
31225 if(accessList[i] == dlg){
31226 accessList.splice(i, 1);
31231 i = accessList.indexOf(dlg);
31233 accessList.splice(i, 1);
31239 * Gets a registered dialog by id
31240 * @param {String/Object} id The id of the dialog or a dialog
31241 * @return {Roo.BasicDialog} this
31243 get : function(id){
31244 return typeof id == "object" ? id : list[id];
31248 * Brings the specified dialog to the front
31249 * @param {String/Object} dlg The id of the dialog or a dialog
31250 * @return {Roo.BasicDialog} this
31252 bringToFront : function(dlg){
31253 dlg = this.get(dlg);
31256 dlg._lastAccess = new Date().getTime();
31263 * Sends the specified dialog to the back
31264 * @param {String/Object} dlg The id of the dialog or a dialog
31265 * @return {Roo.BasicDialog} this
31267 sendToBack : function(dlg){
31268 dlg = this.get(dlg);
31269 dlg._lastAccess = -(new Date().getTime());
31275 * Hides all dialogs
31277 hideAll : function(){
31278 for(var id in list){
31279 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
31288 * @class Roo.LayoutDialog
31289 * @extends Roo.BasicDialog
31290 * Dialog which provides adjustments for working with a layout in a Dialog.
31291 * Add your necessary layout config options to the dialog's config.<br>
31292 * Example usage (including a nested layout):
31295 dialog = new Roo.LayoutDialog("download-dlg", {
31304 // layout config merges with the dialog config
31306 tabPosition: "top",
31307 alwaysShowTabs: true
31310 dialog.addKeyListener(27, dialog.hide, dialog);
31311 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
31312 dialog.addButton("Build It!", this.getDownload, this);
31314 // we can even add nested layouts
31315 var innerLayout = new Roo.BorderLayout("dl-inner", {
31325 innerLayout.beginUpdate();
31326 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
31327 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
31328 innerLayout.endUpdate(true);
31330 var layout = dialog.getLayout();
31331 layout.beginUpdate();
31332 layout.add("center", new Roo.ContentPanel("standard-panel",
31333 {title: "Download the Source", fitToFrame:true}));
31334 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
31335 {title: "Build your own roo.js"}));
31336 layout.getRegion("center").showPanel(sp);
31337 layout.endUpdate();
31341 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
31342 * @param {Object} config configuration options
31344 Roo.LayoutDialog = function(el, cfg){
31347 if (typeof(cfg) == 'undefined') {
31348 config = Roo.apply({}, el);
31349 // not sure why we use documentElement here.. - it should always be body.
31350 // IE7 borks horribly if we use documentElement.
31351 // webkit also does not like documentElement - it creates a body element...
31352 el = Roo.get( document.body || document.documentElement ).createChild();
31353 //config.autoCreate = true;
31357 config.autoTabs = false;
31358 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
31359 this.body.setStyle({overflow:"hidden", position:"relative"});
31360 this.layout = new Roo.BorderLayout(this.body.dom, config);
31361 this.layout.monitorWindowResize = false;
31362 this.el.addClass("x-dlg-auto-layout");
31363 // fix case when center region overwrites center function
31364 this.center = Roo.BasicDialog.prototype.center;
31365 this.on("show", this.layout.layout, this.layout, true);
31366 if (config.items) {
31367 var xitems = config.items;
31368 delete config.items;
31369 Roo.each(xitems, this.addxtype, this);
31374 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
31376 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
31379 endUpdate : function(){
31380 this.layout.endUpdate();
31384 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
31387 beginUpdate : function(){
31388 this.layout.beginUpdate();
31392 * Get the BorderLayout for this dialog
31393 * @return {Roo.BorderLayout}
31395 getLayout : function(){
31396 return this.layout;
31399 showEl : function(){
31400 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
31402 this.layout.layout();
31407 // Use the syncHeightBeforeShow config option to control this automatically
31408 syncBodyHeight : function(){
31409 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
31410 if(this.layout){this.layout.layout();}
31414 * Add an xtype element (actually adds to the layout.)
31415 * @return {Object} xdata xtype object data.
31418 addxtype : function(c) {
31419 return this.layout.addxtype(c);
31423 * Ext JS Library 1.1.1
31424 * Copyright(c) 2006-2007, Ext JS, LLC.
31426 * Originally Released Under LGPL - original licence link has changed is not relivant.
31429 * <script type="text/javascript">
31433 * @class Roo.MessageBox
31434 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
31438 Roo.Msg.alert('Status', 'Changes saved successfully.');
31440 // Prompt for user data:
31441 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
31443 // process text value...
31447 // Show a dialog using config options:
31449 title:'Save Changes?',
31450 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
31451 buttons: Roo.Msg.YESNOCANCEL,
31458 Roo.MessageBox = function(){
31459 var dlg, opt, mask, waitTimer;
31460 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
31461 var buttons, activeTextEl, bwidth;
31464 var handleButton = function(button){
31466 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
31470 var handleHide = function(){
31471 if(opt && opt.cls){
31472 dlg.el.removeClass(opt.cls);
31475 Roo.TaskMgr.stop(waitTimer);
31481 var updateButtons = function(b){
31484 buttons["ok"].hide();
31485 buttons["cancel"].hide();
31486 buttons["yes"].hide();
31487 buttons["no"].hide();
31488 dlg.footer.dom.style.display = 'none';
31491 dlg.footer.dom.style.display = '';
31492 for(var k in buttons){
31493 if(typeof buttons[k] != "function"){
31496 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
31497 width += buttons[k].el.getWidth()+15;
31507 var handleEsc = function(d, k, e){
31508 if(opt && opt.closable !== false){
31518 * Returns a reference to the underlying {@link Roo.BasicDialog} element
31519 * @return {Roo.BasicDialog} The BasicDialog element
31521 getDialog : function(){
31523 dlg = new Roo.BasicDialog("x-msg-box", {
31528 constraintoviewport:false,
31530 collapsible : false,
31533 width:400, height:100,
31534 buttonAlign:"center",
31535 closeClick : function(){
31536 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
31537 handleButton("no");
31539 handleButton("cancel");
31543 dlg.on("hide", handleHide);
31545 dlg.addKeyListener(27, handleEsc);
31547 var bt = this.buttonText;
31548 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
31549 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
31550 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
31551 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
31552 bodyEl = dlg.body.createChild({
31554 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>'
31556 msgEl = bodyEl.dom.firstChild;
31557 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
31558 textboxEl.enableDisplayMode();
31559 textboxEl.addKeyListener([10,13], function(){
31560 if(dlg.isVisible() && opt && opt.buttons){
31561 if(opt.buttons.ok){
31562 handleButton("ok");
31563 }else if(opt.buttons.yes){
31564 handleButton("yes");
31568 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
31569 textareaEl.enableDisplayMode();
31570 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
31571 progressEl.enableDisplayMode();
31572 var pf = progressEl.dom.firstChild;
31574 pp = Roo.get(pf.firstChild);
31575 pp.setHeight(pf.offsetHeight);
31583 * Updates the message box body text
31584 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
31585 * the XHTML-compliant non-breaking space character '&#160;')
31586 * @return {Roo.MessageBox} This message box
31588 updateText : function(text){
31589 if(!dlg.isVisible() && !opt.width){
31590 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
31592 msgEl.innerHTML = text || ' ';
31594 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
31595 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
31597 Math.min(opt.width || cw , this.maxWidth),
31598 Math.max(opt.minWidth || this.minWidth, bwidth)
31601 activeTextEl.setWidth(w);
31603 if(dlg.isVisible()){
31604 dlg.fixedcenter = false;
31606 // to big, make it scroll. = But as usual stupid IE does not support
31609 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
31610 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
31611 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
31613 bodyEl.dom.style.height = '';
31614 bodyEl.dom.style.overflowY = '';
31617 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
31619 bodyEl.dom.style.overflowX = '';
31622 dlg.setContentSize(w, bodyEl.getHeight());
31623 if(dlg.isVisible()){
31624 dlg.fixedcenter = true;
31630 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
31631 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
31632 * @param {Number} value Any number between 0 and 1 (e.g., .5)
31633 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
31634 * @return {Roo.MessageBox} This message box
31636 updateProgress : function(value, text){
31638 this.updateText(text);
31640 if (pp) { // weird bug on my firefox - for some reason this is not defined
31641 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
31647 * Returns true if the message box is currently displayed
31648 * @return {Boolean} True if the message box is visible, else false
31650 isVisible : function(){
31651 return dlg && dlg.isVisible();
31655 * Hides the message box if it is displayed
31658 if(this.isVisible()){
31664 * Displays a new message box, or reinitializes an existing message box, based on the config options
31665 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
31666 * The following config object properties are supported:
31668 Property Type Description
31669 ---------- --------------- ------------------------------------------------------------------------------------
31670 animEl String/Element An id or Element from which the message box should animate as it opens and
31671 closes (defaults to undefined)
31672 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
31673 cancel:'Bar'}), or false to not show any buttons (defaults to false)
31674 closable Boolean False to hide the top-right close button (defaults to true). Note that
31675 progress and wait dialogs will ignore this property and always hide the
31676 close button as they can only be closed programmatically.
31677 cls String A custom CSS class to apply to the message box element
31678 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
31679 displayed (defaults to 75)
31680 fn Function A callback function to execute after closing the dialog. The arguments to the
31681 function will be btn (the name of the button that was clicked, if applicable,
31682 e.g. "ok"), and text (the value of the active text field, if applicable).
31683 Progress and wait dialogs will ignore this option since they do not respond to
31684 user actions and can only be closed programmatically, so any required function
31685 should be called by the same code after it closes the dialog.
31686 icon String A CSS class that provides a background image to be used as an icon for
31687 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
31688 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
31689 minWidth Number The minimum width in pixels of the message box (defaults to 100)
31690 modal Boolean False to allow user interaction with the page while the message box is
31691 displayed (defaults to true)
31692 msg String A string that will replace the existing message box body text (defaults
31693 to the XHTML-compliant non-breaking space character ' ')
31694 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
31695 progress Boolean True to display a progress bar (defaults to false)
31696 progressText String The text to display inside the progress bar if progress = true (defaults to '')
31697 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
31698 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
31699 title String The title text
31700 value String The string value to set into the active textbox element if displayed
31701 wait Boolean True to display a progress bar (defaults to false)
31702 width Number The width of the dialog in pixels
31709 msg: 'Please enter your address:',
31711 buttons: Roo.MessageBox.OKCANCEL,
31714 animEl: 'addAddressBtn'
31717 * @param {Object} config Configuration options
31718 * @return {Roo.MessageBox} This message box
31720 show : function(options)
31723 // this causes nightmares if you show one dialog after another
31724 // especially on callbacks..
31726 if(this.isVisible()){
31729 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
31730 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
31731 Roo.log("New Dialog Message:" + options.msg )
31732 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
31733 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
31736 var d = this.getDialog();
31738 d.setTitle(opt.title || " ");
31739 d.close.setDisplayed(opt.closable !== false);
31740 activeTextEl = textboxEl;
31741 opt.prompt = opt.prompt || (opt.multiline ? true : false);
31746 textareaEl.setHeight(typeof opt.multiline == "number" ?
31747 opt.multiline : this.defaultTextHeight);
31748 activeTextEl = textareaEl;
31757 progressEl.setDisplayed(opt.progress === true);
31758 this.updateProgress(0);
31759 activeTextEl.dom.value = opt.value || "";
31761 dlg.setDefaultButton(activeTextEl);
31763 var bs = opt.buttons;
31766 db = buttons["ok"];
31767 }else if(bs && bs.yes){
31768 db = buttons["yes"];
31770 dlg.setDefaultButton(db);
31772 bwidth = updateButtons(opt.buttons);
31773 this.updateText(opt.msg);
31775 d.el.addClass(opt.cls);
31777 d.proxyDrag = opt.proxyDrag === true;
31778 d.modal = opt.modal !== false;
31779 d.mask = opt.modal !== false ? mask : false;
31780 if(!d.isVisible()){
31781 // force it to the end of the z-index stack so it gets a cursor in FF
31782 document.body.appendChild(dlg.el.dom);
31783 d.animateTarget = null;
31784 d.show(options.animEl);
31790 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
31791 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
31792 * and closing the message box when the process is complete.
31793 * @param {String} title The title bar text
31794 * @param {String} msg The message box body text
31795 * @return {Roo.MessageBox} This message box
31797 progress : function(title, msg){
31804 minWidth: this.minProgressWidth,
31811 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
31812 * If a callback function is passed it will be called after the user clicks the button, and the
31813 * id of the button that was clicked will be passed as the only parameter to the callback
31814 * (could also be the top-right close button).
31815 * @param {String} title The title bar text
31816 * @param {String} msg The message box body text
31817 * @param {Function} fn (optional) The callback function invoked after the message box is closed
31818 * @param {Object} scope (optional) The scope of the callback function
31819 * @return {Roo.MessageBox} This message box
31821 alert : function(title, msg, fn, scope){
31834 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
31835 * interaction while waiting for a long-running process to complete that does not have defined intervals.
31836 * You are responsible for closing the message box when the process is complete.
31837 * @param {String} msg The message box body text
31838 * @param {String} title (optional) The title bar text
31839 * @return {Roo.MessageBox} This message box
31841 wait : function(msg, title){
31852 waitTimer = Roo.TaskMgr.start({
31854 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
31862 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
31863 * If a callback function is passed it will be called after the user clicks either button, and the id of the
31864 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
31865 * @param {String} title The title bar text
31866 * @param {String} msg The message box body text
31867 * @param {Function} fn (optional) The callback function invoked after the message box is closed
31868 * @param {Object} scope (optional) The scope of the callback function
31869 * @return {Roo.MessageBox} This message box
31871 confirm : function(title, msg, fn, scope){
31875 buttons: this.YESNO,
31884 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
31885 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
31886 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
31887 * (could also be the top-right close button) and the text that was entered will be passed as the two
31888 * parameters to the callback.
31889 * @param {String} title The title bar text
31890 * @param {String} msg The message box body text
31891 * @param {Function} fn (optional) The callback function invoked after the message box is closed
31892 * @param {Object} scope (optional) The scope of the callback function
31893 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
31894 * property, or the height in pixels to create the textbox (defaults to false / single-line)
31895 * @return {Roo.MessageBox} This message box
31897 prompt : function(title, msg, fn, scope, multiline){
31901 buttons: this.OKCANCEL,
31906 multiline: multiline,
31913 * Button config that displays a single OK button
31918 * Button config that displays Yes and No buttons
31921 YESNO : {yes:true, no:true},
31923 * Button config that displays OK and Cancel buttons
31926 OKCANCEL : {ok:true, cancel:true},
31928 * Button config that displays Yes, No and Cancel buttons
31931 YESNOCANCEL : {yes:true, no:true, cancel:true},
31934 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
31937 defaultTextHeight : 75,
31939 * The maximum width in pixels of the message box (defaults to 600)
31944 * The minimum width in pixels of the message box (defaults to 100)
31949 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
31950 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
31953 minProgressWidth : 250,
31955 * An object containing the default button text strings that can be overriden for localized language support.
31956 * Supported properties are: ok, cancel, yes and no.
31957 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
31970 * Shorthand for {@link Roo.MessageBox}
31972 Roo.Msg = Roo.MessageBox;/*
31974 * Ext JS Library 1.1.1
31975 * Copyright(c) 2006-2007, Ext JS, LLC.
31977 * Originally Released Under LGPL - original licence link has changed is not relivant.
31980 * <script type="text/javascript">
31983 * @class Roo.QuickTips
31984 * Provides attractive and customizable tooltips for any element.
31987 Roo.QuickTips = function(){
31988 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
31989 var ce, bd, xy, dd;
31990 var visible = false, disabled = true, inited = false;
31991 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
31993 var onOver = function(e){
31997 var t = e.getTarget();
31998 if(!t || t.nodeType !== 1 || t == document || t == document.body){
32001 if(ce && t == ce.el){
32002 clearTimeout(hideProc);
32005 if(t && tagEls[t.id]){
32006 tagEls[t.id].el = t;
32007 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
32010 var ttp, et = Roo.fly(t);
32011 var ns = cfg.namespace;
32012 if(tm.interceptTitles && t.title){
32015 t.removeAttribute("title");
32016 e.preventDefault();
32018 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute);
32021 showProc = show.defer(tm.showDelay, tm, [{
32024 width: et.getAttributeNS(ns, cfg.width),
32025 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
32026 title: et.getAttributeNS(ns, cfg.title),
32027 cls: et.getAttributeNS(ns, cfg.cls)
32032 var onOut = function(e){
32033 clearTimeout(showProc);
32034 var t = e.getTarget();
32035 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
32036 hideProc = setTimeout(hide, tm.hideDelay);
32040 var onMove = function(e){
32046 if(tm.trackMouse && ce){
32051 var onDown = function(e){
32052 clearTimeout(showProc);
32053 clearTimeout(hideProc);
32055 if(tm.hideOnClick){
32058 tm.enable.defer(100, tm);
32063 var getPad = function(){
32064 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
32067 var show = function(o){
32071 clearTimeout(dismissProc);
32073 if(removeCls){ // in case manually hidden
32074 el.removeClass(removeCls);
32078 el.addClass(ce.cls);
32079 removeCls = ce.cls;
32082 tipTitle.update(ce.title);
32085 tipTitle.update('');
32088 el.dom.style.width = tm.maxWidth+'px';
32089 //tipBody.dom.style.width = '';
32090 tipBodyText.update(o.text);
32091 var p = getPad(), w = ce.width;
32093 var td = tipBodyText.dom;
32094 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
32095 if(aw > tm.maxWidth){
32097 }else if(aw < tm.minWidth){
32103 //tipBody.setWidth(w);
32104 el.setWidth(parseInt(w, 10) + p);
32105 if(ce.autoHide === false){
32106 close.setDisplayed(true);
32111 close.setDisplayed(false);
32117 el.avoidY = xy[1]-18;
32122 el.setStyle("visibility", "visible");
32123 el.fadeIn({callback: afterShow});
32129 var afterShow = function(){
32133 if(tm.autoDismiss && ce.autoHide !== false){
32134 dismissProc = setTimeout(hide, tm.autoDismissDelay);
32139 var hide = function(noanim){
32140 clearTimeout(dismissProc);
32141 clearTimeout(hideProc);
32143 if(el.isVisible()){
32145 if(noanim !== true && tm.animate){
32146 el.fadeOut({callback: afterHide});
32153 var afterHide = function(){
32156 el.removeClass(removeCls);
32163 * @cfg {Number} minWidth
32164 * The minimum width of the quick tip (defaults to 40)
32168 * @cfg {Number} maxWidth
32169 * The maximum width of the quick tip (defaults to 300)
32173 * @cfg {Boolean} interceptTitles
32174 * True to automatically use the element's DOM title value if available (defaults to false)
32176 interceptTitles : false,
32178 * @cfg {Boolean} trackMouse
32179 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
32181 trackMouse : false,
32183 * @cfg {Boolean} hideOnClick
32184 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
32186 hideOnClick : true,
32188 * @cfg {Number} showDelay
32189 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
32193 * @cfg {Number} hideDelay
32194 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
32198 * @cfg {Boolean} autoHide
32199 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
32200 * Used in conjunction with hideDelay.
32205 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
32206 * (defaults to true). Used in conjunction with autoDismissDelay.
32208 autoDismiss : true,
32211 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
32213 autoDismissDelay : 5000,
32215 * @cfg {Boolean} animate
32216 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
32221 * @cfg {String} title
32222 * Title text to display (defaults to ''). This can be any valid HTML markup.
32226 * @cfg {String} text
32227 * Body text to display (defaults to ''). This can be any valid HTML markup.
32231 * @cfg {String} cls
32232 * A CSS class to apply to the base quick tip element (defaults to '').
32236 * @cfg {Number} width
32237 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
32238 * minWidth or maxWidth.
32243 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
32244 * or display QuickTips in a page.
32247 tm = Roo.QuickTips;
32248 cfg = tm.tagConfig;
32250 if(!Roo.isReady){ // allow calling of init() before onReady
32251 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
32254 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
32255 el.fxDefaults = {stopFx: true};
32256 // maximum custom styling
32257 //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>');
32258 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>');
32259 tipTitle = el.child('h3');
32260 tipTitle.enableDisplayMode("block");
32261 tipBody = el.child('div.x-tip-bd');
32262 tipBodyText = el.child('div.x-tip-bd-inner');
32263 //bdLeft = el.child('div.x-tip-bd-left');
32264 //bdRight = el.child('div.x-tip-bd-right');
32265 close = el.child('div.x-tip-close');
32266 close.enableDisplayMode("block");
32267 close.on("click", hide);
32268 var d = Roo.get(document);
32269 d.on("mousedown", onDown);
32270 d.on("mouseover", onOver);
32271 d.on("mouseout", onOut);
32272 d.on("mousemove", onMove);
32273 esc = d.addKeyListener(27, hide);
32276 dd = el.initDD("default", null, {
32277 onDrag : function(){
32281 dd.setHandleElId(tipTitle.id);
32290 * Configures a new quick tip instance and assigns it to a target element. The following config options
32293 Property Type Description
32294 ---------- --------------------- ------------------------------------------------------------------------
32295 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
32297 * @param {Object} config The config object
32299 register : function(config){
32300 var cs = config instanceof Array ? config : arguments;
32301 for(var i = 0, len = cs.length; i < len; i++) {
32303 var target = c.target;
32305 if(target instanceof Array){
32306 for(var j = 0, jlen = target.length; j < jlen; j++){
32307 tagEls[target[j]] = c;
32310 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
32317 * Removes this quick tip from its element and destroys it.
32318 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
32320 unregister : function(el){
32321 delete tagEls[Roo.id(el)];
32325 * Enable this quick tip.
32327 enable : function(){
32328 if(inited && disabled){
32330 if(locks.length < 1){
32337 * Disable this quick tip.
32339 disable : function(){
32341 clearTimeout(showProc);
32342 clearTimeout(hideProc);
32343 clearTimeout(dismissProc);
32351 * Returns true if the quick tip is enabled, else false.
32353 isEnabled : function(){
32360 attribute : "qtip",
32370 // backwards compat
32371 Roo.QuickTips.tips = Roo.QuickTips.register;/*
32373 * Ext JS Library 1.1.1
32374 * Copyright(c) 2006-2007, Ext JS, LLC.
32376 * Originally Released Under LGPL - original licence link has changed is not relivant.
32379 * <script type="text/javascript">
32384 * @class Roo.tree.TreePanel
32385 * @extends Roo.data.Tree
32387 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
32388 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
32389 * @cfg {Boolean} enableDD true to enable drag and drop
32390 * @cfg {Boolean} enableDrag true to enable just drag
32391 * @cfg {Boolean} enableDrop true to enable just drop
32392 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
32393 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
32394 * @cfg {String} ddGroup The DD group this TreePanel belongs to
32395 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
32396 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
32397 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
32398 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
32399 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
32400 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
32401 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
32402 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
32403 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
32404 * @cfg {Object|Roo.tree.TreeEditor} editor The TreeEditor or xtype data to display when clicked.
32405 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
32406 * @cfg {Function} renderer DEPRECATED - use TreeLoader:create event / Sets the rendering (formatting) function for the nodes. to return HTML markup for the tree view. The render function is called with the following parameters:<ul><li>The {Object} The data for the node.</li></ul>
32407 * @cfg {Function} rendererTip DEPRECATED - use TreeLoader:create event / Sets the rendering (formatting) function for the nodes hovertip to return HTML markup for the tree view. The render function is called with the following parameters:<ul><li>The {Object} The data for the node.</li></ul>
32410 * @param {String/HTMLElement/Element} el The container element
32411 * @param {Object} config
32413 Roo.tree.TreePanel = function(el, config){
32415 var loader = false;
32417 root = config.root;
32418 delete config.root;
32420 if (config.loader) {
32421 loader = config.loader;
32422 delete config.loader;
32425 Roo.apply(this, config);
32426 Roo.tree.TreePanel.superclass.constructor.call(this);
32427 this.el = Roo.get(el);
32428 this.el.addClass('x-tree');
32429 //console.log(root);
32431 this.setRootNode( Roo.factory(root, Roo.tree));
32434 this.loader = Roo.factory(loader, Roo.tree);
32437 * Read-only. The id of the container element becomes this TreePanel's id.
32439 this.id = this.el.id;
32442 * @event beforeload
32443 * Fires before a node is loaded, return false to cancel
32444 * @param {Node} node The node being loaded
32446 "beforeload" : true,
32449 * Fires when a node is loaded
32450 * @param {Node} node The node that was loaded
32454 * @event textchange
32455 * Fires when the text for a node is changed
32456 * @param {Node} node The node
32457 * @param {String} text The new text
32458 * @param {String} oldText The old text
32460 "textchange" : true,
32462 * @event beforeexpand
32463 * Fires before a node is expanded, return false to cancel.
32464 * @param {Node} node The node
32465 * @param {Boolean} deep
32466 * @param {Boolean} anim
32468 "beforeexpand" : true,
32470 * @event beforecollapse
32471 * Fires before a node is collapsed, return false to cancel.
32472 * @param {Node} node The node
32473 * @param {Boolean} deep
32474 * @param {Boolean} anim
32476 "beforecollapse" : true,
32479 * Fires when a node is expanded
32480 * @param {Node} node The node
32484 * @event disabledchange
32485 * Fires when the disabled status of a node changes
32486 * @param {Node} node The node
32487 * @param {Boolean} disabled
32489 "disabledchange" : true,
32492 * Fires when a node is collapsed
32493 * @param {Node} node The node
32497 * @event beforeclick
32498 * Fires before click processing on a node. Return false to cancel the default action.
32499 * @param {Node} node The node
32500 * @param {Roo.EventObject} e The event object
32502 "beforeclick":true,
32504 * @event checkchange
32505 * Fires when a node with a checkbox's checked property changes
32506 * @param {Node} this This node
32507 * @param {Boolean} checked
32509 "checkchange":true,
32512 * Fires when a node is clicked
32513 * @param {Node} node The node
32514 * @param {Roo.EventObject} e The event object
32519 * Fires when a node is double clicked
32520 * @param {Node} node The node
32521 * @param {Roo.EventObject} e The event object
32525 * @event contextmenu
32526 * Fires when a node is right clicked
32527 * @param {Node} node The node
32528 * @param {Roo.EventObject} e The event object
32530 "contextmenu":true,
32532 * @event beforechildrenrendered
32533 * Fires right before the child nodes for a node are rendered
32534 * @param {Node} node The node
32536 "beforechildrenrendered":true,
32539 * Fires when a node starts being dragged
32540 * @param {Roo.tree.TreePanel} this
32541 * @param {Roo.tree.TreeNode} node
32542 * @param {event} e The raw browser event
32544 "startdrag" : true,
32547 * Fires when a drag operation is complete
32548 * @param {Roo.tree.TreePanel} this
32549 * @param {Roo.tree.TreeNode} node
32550 * @param {event} e The raw browser event
32555 * Fires when a dragged node is dropped on a valid DD target
32556 * @param {Roo.tree.TreePanel} this
32557 * @param {Roo.tree.TreeNode} node
32558 * @param {DD} dd The dd it was dropped on
32559 * @param {event} e The raw browser event
32563 * @event beforenodedrop
32564 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
32565 * passed to handlers has the following properties:<br />
32566 * <ul style="padding:5px;padding-left:16px;">
32567 * <li>tree - The TreePanel</li>
32568 * <li>target - The node being targeted for the drop</li>
32569 * <li>data - The drag data from the drag source</li>
32570 * <li>point - The point of the drop - append, above or below</li>
32571 * <li>source - The drag source</li>
32572 * <li>rawEvent - Raw mouse event</li>
32573 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
32574 * to be inserted by setting them on this object.</li>
32575 * <li>cancel - Set this to true to cancel the drop.</li>
32577 * @param {Object} dropEvent
32579 "beforenodedrop" : true,
32582 * Fires after a DD object is dropped on a node in this tree. The dropEvent
32583 * passed to handlers has the following properties:<br />
32584 * <ul style="padding:5px;padding-left:16px;">
32585 * <li>tree - The TreePanel</li>
32586 * <li>target - The node being targeted for the drop</li>
32587 * <li>data - The drag data from the drag source</li>
32588 * <li>point - The point of the drop - append, above or below</li>
32589 * <li>source - The drag source</li>
32590 * <li>rawEvent - Raw mouse event</li>
32591 * <li>dropNode - Dropped node(s).</li>
32593 * @param {Object} dropEvent
32597 * @event nodedragover
32598 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
32599 * passed to handlers has the following properties:<br />
32600 * <ul style="padding:5px;padding-left:16px;">
32601 * <li>tree - The TreePanel</li>
32602 * <li>target - The node being targeted for the drop</li>
32603 * <li>data - The drag data from the drag source</li>
32604 * <li>point - The point of the drop - append, above or below</li>
32605 * <li>source - The drag source</li>
32606 * <li>rawEvent - Raw mouse event</li>
32607 * <li>dropNode - Drop node(s) provided by the source.</li>
32608 * <li>cancel - Set this to true to signal drop not allowed.</li>
32610 * @param {Object} dragOverEvent
32612 "nodedragover" : true
32615 if(this.singleExpand){
32616 this.on("beforeexpand", this.restrictExpand, this);
32619 this.editor.tree = this;
32620 this.editor = Roo.factory(this.editor, Roo.tree);
32623 if (this.selModel) {
32624 this.selModel = Roo.factory(this.selModel, Roo.tree);
32628 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
32629 rootVisible : true,
32630 animate: Roo.enableFx,
32633 hlDrop : Roo.enableFx,
32637 rendererTip: false,
32639 restrictExpand : function(node){
32640 var p = node.parentNode;
32642 if(p.expandedChild && p.expandedChild.parentNode == p){
32643 p.expandedChild.collapse();
32645 p.expandedChild = node;
32649 // private override
32650 setRootNode : function(node){
32651 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
32652 if(!this.rootVisible){
32653 node.ui = new Roo.tree.RootTreeNodeUI(node);
32659 * Returns the container element for this TreePanel
32661 getEl : function(){
32666 * Returns the default TreeLoader for this TreePanel
32668 getLoader : function(){
32669 return this.loader;
32675 expandAll : function(){
32676 this.root.expand(true);
32680 * Collapse all nodes
32682 collapseAll : function(){
32683 this.root.collapse(true);
32687 * Returns the selection model used by this TreePanel
32689 getSelectionModel : function(){
32690 if(!this.selModel){
32691 this.selModel = new Roo.tree.DefaultSelectionModel();
32693 return this.selModel;
32697 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
32698 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
32699 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
32702 getChecked : function(a, startNode){
32703 startNode = startNode || this.root;
32705 var f = function(){
32706 if(this.attributes.checked){
32707 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
32710 startNode.cascade(f);
32715 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
32716 * @param {String} path
32717 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
32718 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
32719 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
32721 expandPath : function(path, attr, callback){
32722 attr = attr || "id";
32723 var keys = path.split(this.pathSeparator);
32724 var curNode = this.root;
32725 if(curNode.attributes[attr] != keys[1]){ // invalid root
32727 callback(false, null);
32732 var f = function(){
32733 if(++index == keys.length){
32735 callback(true, curNode);
32739 var c = curNode.findChild(attr, keys[index]);
32742 callback(false, curNode);
32747 c.expand(false, false, f);
32749 curNode.expand(false, false, f);
32753 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
32754 * @param {String} path
32755 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
32756 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
32757 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
32759 selectPath : function(path, attr, callback){
32760 attr = attr || "id";
32761 var keys = path.split(this.pathSeparator);
32762 var v = keys.pop();
32763 if(keys.length > 0){
32764 var f = function(success, node){
32765 if(success && node){
32766 var n = node.findChild(attr, v);
32772 }else if(callback){
32773 callback(false, n);
32777 callback(false, n);
32781 this.expandPath(keys.join(this.pathSeparator), attr, f);
32783 this.root.select();
32785 callback(true, this.root);
32790 getTreeEl : function(){
32795 * Trigger rendering of this TreePanel
32797 render : function(){
32798 if (this.innerCt) {
32799 return this; // stop it rendering more than once!!
32802 this.innerCt = this.el.createChild({tag:"ul",
32803 cls:"x-tree-root-ct " +
32804 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
32806 if(this.containerScroll){
32807 Roo.dd.ScrollManager.register(this.el);
32809 if((this.enableDD || this.enableDrop) && !this.dropZone){
32811 * The dropZone used by this tree if drop is enabled
32812 * @type Roo.tree.TreeDropZone
32814 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
32815 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
32818 if((this.enableDD || this.enableDrag) && !this.dragZone){
32820 * The dragZone used by this tree if drag is enabled
32821 * @type Roo.tree.TreeDragZone
32823 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
32824 ddGroup: this.ddGroup || "TreeDD",
32825 scroll: this.ddScroll
32828 this.getSelectionModel().init(this);
32830 Roo.log("ROOT not set in tree");
32833 this.root.render();
32834 if(!this.rootVisible){
32835 this.root.renderChildren();
32841 * Ext JS Library 1.1.1
32842 * Copyright(c) 2006-2007, Ext JS, LLC.
32844 * Originally Released Under LGPL - original licence link has changed is not relivant.
32847 * <script type="text/javascript">
32852 * @class Roo.tree.DefaultSelectionModel
32853 * @extends Roo.util.Observable
32854 * The default single selection for a TreePanel.
32855 * @param {Object} cfg Configuration
32857 Roo.tree.DefaultSelectionModel = function(cfg){
32858 this.selNode = null;
32864 * @event selectionchange
32865 * Fires when the selected node changes
32866 * @param {DefaultSelectionModel} this
32867 * @param {TreeNode} node the new selection
32869 "selectionchange" : true,
32872 * @event beforeselect
32873 * Fires before the selected node changes, return false to cancel the change
32874 * @param {DefaultSelectionModel} this
32875 * @param {TreeNode} node the new selection
32876 * @param {TreeNode} node the old selection
32878 "beforeselect" : true
32881 Roo.tree.DefaultSelectionModel.superclass.constructor.call(this,cfg);
32884 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
32885 init : function(tree){
32887 tree.getTreeEl().on("keydown", this.onKeyDown, this);
32888 tree.on("click", this.onNodeClick, this);
32891 onNodeClick : function(node, e){
32892 if (e.ctrlKey && this.selNode == node) {
32893 this.unselect(node);
32901 * @param {TreeNode} node The node to select
32902 * @return {TreeNode} The selected node
32904 select : function(node){
32905 var last = this.selNode;
32906 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
32908 last.ui.onSelectedChange(false);
32910 this.selNode = node;
32911 node.ui.onSelectedChange(true);
32912 this.fireEvent("selectionchange", this, node, last);
32919 * @param {TreeNode} node The node to unselect
32921 unselect : function(node){
32922 if(this.selNode == node){
32923 this.clearSelections();
32928 * Clear all selections
32930 clearSelections : function(){
32931 var n = this.selNode;
32933 n.ui.onSelectedChange(false);
32934 this.selNode = null;
32935 this.fireEvent("selectionchange", this, null);
32941 * Get the selected node
32942 * @return {TreeNode} The selected node
32944 getSelectedNode : function(){
32945 return this.selNode;
32949 * Returns true if the node is selected
32950 * @param {TreeNode} node The node to check
32951 * @return {Boolean}
32953 isSelected : function(node){
32954 return this.selNode == node;
32958 * Selects the node above the selected node in the tree, intelligently walking the nodes
32959 * @return TreeNode The new selection
32961 selectPrevious : function(){
32962 var s = this.selNode || this.lastSelNode;
32966 var ps = s.previousSibling;
32968 if(!ps.isExpanded() || ps.childNodes.length < 1){
32969 return this.select(ps);
32971 var lc = ps.lastChild;
32972 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
32975 return this.select(lc);
32977 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
32978 return this.select(s.parentNode);
32984 * Selects the node above the selected node in the tree, intelligently walking the nodes
32985 * @return TreeNode The new selection
32987 selectNext : function(){
32988 var s = this.selNode || this.lastSelNode;
32992 if(s.firstChild && s.isExpanded()){
32993 return this.select(s.firstChild);
32994 }else if(s.nextSibling){
32995 return this.select(s.nextSibling);
32996 }else if(s.parentNode){
32998 s.parentNode.bubble(function(){
32999 if(this.nextSibling){
33000 newS = this.getOwnerTree().selModel.select(this.nextSibling);
33009 onKeyDown : function(e){
33010 var s = this.selNode || this.lastSelNode;
33011 // undesirable, but required
33016 var k = e.getKey();
33024 this.selectPrevious();
33027 e.preventDefault();
33028 if(s.hasChildNodes()){
33029 if(!s.isExpanded()){
33031 }else if(s.firstChild){
33032 this.select(s.firstChild, e);
33037 e.preventDefault();
33038 if(s.hasChildNodes() && s.isExpanded()){
33040 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
33041 this.select(s.parentNode, e);
33049 * @class Roo.tree.MultiSelectionModel
33050 * @extends Roo.util.Observable
33051 * Multi selection for a TreePanel.
33052 * @param {Object} cfg Configuration
33054 Roo.tree.MultiSelectionModel = function(){
33055 this.selNodes = [];
33059 * @event selectionchange
33060 * Fires when the selected nodes change
33061 * @param {MultiSelectionModel} this
33062 * @param {Array} nodes Array of the selected nodes
33064 "selectionchange" : true
33066 Roo.tree.MultiSelectionModel.superclass.constructor.call(this,cfg);
33070 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
33071 init : function(tree){
33073 tree.getTreeEl().on("keydown", this.onKeyDown, this);
33074 tree.on("click", this.onNodeClick, this);
33077 onNodeClick : function(node, e){
33078 this.select(node, e, e.ctrlKey);
33083 * @param {TreeNode} node The node to select
33084 * @param {EventObject} e (optional) An event associated with the selection
33085 * @param {Boolean} keepExisting True to retain existing selections
33086 * @return {TreeNode} The selected node
33088 select : function(node, e, keepExisting){
33089 if(keepExisting !== true){
33090 this.clearSelections(true);
33092 if(this.isSelected(node)){
33093 this.lastSelNode = node;
33096 this.selNodes.push(node);
33097 this.selMap[node.id] = node;
33098 this.lastSelNode = node;
33099 node.ui.onSelectedChange(true);
33100 this.fireEvent("selectionchange", this, this.selNodes);
33106 * @param {TreeNode} node The node to unselect
33108 unselect : function(node){
33109 if(this.selMap[node.id]){
33110 node.ui.onSelectedChange(false);
33111 var sn = this.selNodes;
33114 index = sn.indexOf(node);
33116 for(var i = 0, len = sn.length; i < len; i++){
33124 this.selNodes.splice(index, 1);
33126 delete this.selMap[node.id];
33127 this.fireEvent("selectionchange", this, this.selNodes);
33132 * Clear all selections
33134 clearSelections : function(suppressEvent){
33135 var sn = this.selNodes;
33137 for(var i = 0, len = sn.length; i < len; i++){
33138 sn[i].ui.onSelectedChange(false);
33140 this.selNodes = [];
33142 if(suppressEvent !== true){
33143 this.fireEvent("selectionchange", this, this.selNodes);
33149 * Returns true if the node is selected
33150 * @param {TreeNode} node The node to check
33151 * @return {Boolean}
33153 isSelected : function(node){
33154 return this.selMap[node.id] ? true : false;
33158 * Returns an array of the selected nodes
33161 getSelectedNodes : function(){
33162 return this.selNodes;
33165 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
33167 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
33169 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
33172 * Ext JS Library 1.1.1
33173 * Copyright(c) 2006-2007, Ext JS, LLC.
33175 * Originally Released Under LGPL - original licence link has changed is not relivant.
33178 * <script type="text/javascript">
33182 * @class Roo.tree.TreeNode
33183 * @extends Roo.data.Node
33184 * @cfg {String} text The text for this node
33185 * @cfg {Boolean} expanded true to start the node expanded
33186 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
33187 * @cfg {Boolean} allowDrop false if this node cannot be drop on
33188 * @cfg {Boolean} disabled true to start the node disabled
33189 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
33190 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
33191 * @cfg {String} cls A css class to be added to the node
33192 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
33193 * @cfg {String} href URL of the link used for the node (defaults to #)
33194 * @cfg {String} hrefTarget target frame for the link
33195 * @cfg {String} qtip An Ext QuickTip for the node
33196 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
33197 * @cfg {Boolean} singleClickExpand True for single click expand on this node
33198 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
33199 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
33200 * (defaults to undefined with no checkbox rendered)
33202 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
33204 Roo.tree.TreeNode = function(attributes){
33205 attributes = attributes || {};
33206 if(typeof attributes == "string"){
33207 attributes = {text: attributes};
33209 this.childrenRendered = false;
33210 this.rendered = false;
33211 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
33212 this.expanded = attributes.expanded === true;
33213 this.isTarget = attributes.isTarget !== false;
33214 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
33215 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
33218 * Read-only. The text for this node. To change it use setText().
33221 this.text = attributes.text;
33223 * True if this node is disabled.
33226 this.disabled = attributes.disabled === true;
33230 * @event textchange
33231 * Fires when the text for this node is changed
33232 * @param {Node} this This node
33233 * @param {String} text The new text
33234 * @param {String} oldText The old text
33236 "textchange" : true,
33238 * @event beforeexpand
33239 * Fires before this node is expanded, return false to cancel.
33240 * @param {Node} this This node
33241 * @param {Boolean} deep
33242 * @param {Boolean} anim
33244 "beforeexpand" : true,
33246 * @event beforecollapse
33247 * Fires before this node is collapsed, return false to cancel.
33248 * @param {Node} this This node
33249 * @param {Boolean} deep
33250 * @param {Boolean} anim
33252 "beforecollapse" : true,
33255 * Fires when this node is expanded
33256 * @param {Node} this This node
33260 * @event disabledchange
33261 * Fires when the disabled status of this node changes
33262 * @param {Node} this This node
33263 * @param {Boolean} disabled
33265 "disabledchange" : true,
33268 * Fires when this node is collapsed
33269 * @param {Node} this This node
33273 * @event beforeclick
33274 * Fires before click processing. Return false to cancel the default action.
33275 * @param {Node} this This node
33276 * @param {Roo.EventObject} e The event object
33278 "beforeclick":true,
33280 * @event checkchange
33281 * Fires when a node with a checkbox's checked property changes
33282 * @param {Node} this This node
33283 * @param {Boolean} checked
33285 "checkchange":true,
33288 * Fires when this node is clicked
33289 * @param {Node} this This node
33290 * @param {Roo.EventObject} e The event object
33295 * Fires when this node is double clicked
33296 * @param {Node} this This node
33297 * @param {Roo.EventObject} e The event object
33301 * @event contextmenu
33302 * Fires when this node is right clicked
33303 * @param {Node} this This node
33304 * @param {Roo.EventObject} e The event object
33306 "contextmenu":true,
33308 * @event beforechildrenrendered
33309 * Fires right before the child nodes for this node are rendered
33310 * @param {Node} this This node
33312 "beforechildrenrendered":true
33315 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
33318 * Read-only. The UI for this node
33321 this.ui = new uiClass(this);
33323 // finally support items[]
33324 if (typeof(this.attributes.items) == 'undefined' || !this.attributes.items) {
33329 Roo.each(this.attributes.items, function(c) {
33330 this.appendChild(Roo.factory(c,Roo.Tree));
33332 delete this.attributes.items;
33337 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
33338 preventHScroll: true,
33340 * Returns true if this node is expanded
33341 * @return {Boolean}
33343 isExpanded : function(){
33344 return this.expanded;
33348 * Returns the UI object for this node
33349 * @return {TreeNodeUI}
33351 getUI : function(){
33355 // private override
33356 setFirstChild : function(node){
33357 var of = this.firstChild;
33358 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
33359 if(this.childrenRendered && of && node != of){
33360 of.renderIndent(true, true);
33363 this.renderIndent(true, true);
33367 // private override
33368 setLastChild : function(node){
33369 var ol = this.lastChild;
33370 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
33371 if(this.childrenRendered && ol && node != ol){
33372 ol.renderIndent(true, true);
33375 this.renderIndent(true, true);
33379 // these methods are overridden to provide lazy rendering support
33380 // private override
33381 appendChild : function()
33383 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
33384 if(node && this.childrenRendered){
33387 this.ui.updateExpandIcon();
33391 // private override
33392 removeChild : function(node){
33393 this.ownerTree.getSelectionModel().unselect(node);
33394 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
33395 // if it's been rendered remove dom node
33396 if(this.childrenRendered){
33399 if(this.childNodes.length < 1){
33400 this.collapse(false, false);
33402 this.ui.updateExpandIcon();
33404 if(!this.firstChild) {
33405 this.childrenRendered = false;
33410 // private override
33411 insertBefore : function(node, refNode){
33412 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
33413 if(newNode && refNode && this.childrenRendered){
33416 this.ui.updateExpandIcon();
33421 * Sets the text for this node
33422 * @param {String} text
33424 setText : function(text){
33425 var oldText = this.text;
33427 this.attributes.text = text;
33428 if(this.rendered){ // event without subscribing
33429 this.ui.onTextChange(this, text, oldText);
33431 this.fireEvent("textchange", this, text, oldText);
33435 * Triggers selection of this node
33437 select : function(){
33438 this.getOwnerTree().getSelectionModel().select(this);
33442 * Triggers deselection of this node
33444 unselect : function(){
33445 this.getOwnerTree().getSelectionModel().unselect(this);
33449 * Returns true if this node is selected
33450 * @return {Boolean}
33452 isSelected : function(){
33453 return this.getOwnerTree().getSelectionModel().isSelected(this);
33457 * Expand this node.
33458 * @param {Boolean} deep (optional) True to expand all children as well
33459 * @param {Boolean} anim (optional) false to cancel the default animation
33460 * @param {Function} callback (optional) A callback to be called when
33461 * expanding this node completes (does not wait for deep expand to complete).
33462 * Called with 1 parameter, this node.
33464 expand : function(deep, anim, callback){
33465 if(!this.expanded){
33466 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
33469 if(!this.childrenRendered){
33470 this.renderChildren();
33472 this.expanded = true;
33473 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
33474 this.ui.animExpand(function(){
33475 this.fireEvent("expand", this);
33476 if(typeof callback == "function"){
33480 this.expandChildNodes(true);
33482 }.createDelegate(this));
33486 this.fireEvent("expand", this);
33487 if(typeof callback == "function"){
33492 if(typeof callback == "function"){
33497 this.expandChildNodes(true);
33501 isHiddenRoot : function(){
33502 return this.isRoot && !this.getOwnerTree().rootVisible;
33506 * Collapse this node.
33507 * @param {Boolean} deep (optional) True to collapse all children as well
33508 * @param {Boolean} anim (optional) false to cancel the default animation
33510 collapse : function(deep, anim){
33511 if(this.expanded && !this.isHiddenRoot()){
33512 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
33515 this.expanded = false;
33516 if((this.getOwnerTree().animate && anim !== false) || anim){
33517 this.ui.animCollapse(function(){
33518 this.fireEvent("collapse", this);
33520 this.collapseChildNodes(true);
33522 }.createDelegate(this));
33525 this.ui.collapse();
33526 this.fireEvent("collapse", this);
33530 var cs = this.childNodes;
33531 for(var i = 0, len = cs.length; i < len; i++) {
33532 cs[i].collapse(true, false);
33538 delayedExpand : function(delay){
33539 if(!this.expandProcId){
33540 this.expandProcId = this.expand.defer(delay, this);
33545 cancelExpand : function(){
33546 if(this.expandProcId){
33547 clearTimeout(this.expandProcId);
33549 this.expandProcId = false;
33553 * Toggles expanded/collapsed state of the node
33555 toggle : function(){
33564 * Ensures all parent nodes are expanded
33566 ensureVisible : function(callback){
33567 var tree = this.getOwnerTree();
33568 tree.expandPath(this.parentNode.getPath(), false, function(){
33569 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
33570 Roo.callback(callback);
33571 }.createDelegate(this));
33575 * Expand all child nodes
33576 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
33578 expandChildNodes : function(deep){
33579 var cs = this.childNodes;
33580 for(var i = 0, len = cs.length; i < len; i++) {
33581 cs[i].expand(deep);
33586 * Collapse all child nodes
33587 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
33589 collapseChildNodes : function(deep){
33590 var cs = this.childNodes;
33591 for(var i = 0, len = cs.length; i < len; i++) {
33592 cs[i].collapse(deep);
33597 * Disables this node
33599 disable : function(){
33600 this.disabled = true;
33602 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
33603 this.ui.onDisableChange(this, true);
33605 this.fireEvent("disabledchange", this, true);
33609 * Enables this node
33611 enable : function(){
33612 this.disabled = false;
33613 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
33614 this.ui.onDisableChange(this, false);
33616 this.fireEvent("disabledchange", this, false);
33620 renderChildren : function(suppressEvent){
33621 if(suppressEvent !== false){
33622 this.fireEvent("beforechildrenrendered", this);
33624 var cs = this.childNodes;
33625 for(var i = 0, len = cs.length; i < len; i++){
33626 cs[i].render(true);
33628 this.childrenRendered = true;
33632 sort : function(fn, scope){
33633 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
33634 if(this.childrenRendered){
33635 var cs = this.childNodes;
33636 for(var i = 0, len = cs.length; i < len; i++){
33637 cs[i].render(true);
33643 render : function(bulkRender){
33644 this.ui.render(bulkRender);
33645 if(!this.rendered){
33646 this.rendered = true;
33648 this.expanded = false;
33649 this.expand(false, false);
33655 renderIndent : function(deep, refresh){
33657 this.ui.childIndent = null;
33659 this.ui.renderIndent();
33660 if(deep === true && this.childrenRendered){
33661 var cs = this.childNodes;
33662 for(var i = 0, len = cs.length; i < len; i++){
33663 cs[i].renderIndent(true, refresh);
33669 * Ext JS Library 1.1.1
33670 * Copyright(c) 2006-2007, Ext JS, LLC.
33672 * Originally Released Under LGPL - original licence link has changed is not relivant.
33675 * <script type="text/javascript">
33679 * @class Roo.tree.AsyncTreeNode
33680 * @extends Roo.tree.TreeNode
33681 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
33683 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
33685 Roo.tree.AsyncTreeNode = function(config){
33686 this.loaded = false;
33687 this.loading = false;
33688 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
33690 * @event beforeload
33691 * Fires before this node is loaded, return false to cancel
33692 * @param {Node} this This node
33694 this.addEvents({'beforeload':true, 'load': true});
33697 * Fires when this node is loaded
33698 * @param {Node} this This node
33701 * The loader used by this node (defaults to using the tree's defined loader)
33706 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
33707 expand : function(deep, anim, callback){
33708 if(this.loading){ // if an async load is already running, waiting til it's done
33710 var f = function(){
33711 if(!this.loading){ // done loading
33712 clearInterval(timer);
33713 this.expand(deep, anim, callback);
33715 }.createDelegate(this);
33716 timer = setInterval(f, 200);
33720 if(this.fireEvent("beforeload", this) === false){
33723 this.loading = true;
33724 this.ui.beforeLoad(this);
33725 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
33727 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
33731 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
33735 * Returns true if this node is currently loading
33736 * @return {Boolean}
33738 isLoading : function(){
33739 return this.loading;
33742 loadComplete : function(deep, anim, callback){
33743 this.loading = false;
33744 this.loaded = true;
33745 this.ui.afterLoad(this);
33746 this.fireEvent("load", this);
33747 this.expand(deep, anim, callback);
33751 * Returns true if this node has been loaded
33752 * @return {Boolean}
33754 isLoaded : function(){
33755 return this.loaded;
33758 hasChildNodes : function(){
33759 if(!this.isLeaf() && !this.loaded){
33762 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
33767 * Trigger a reload for this node
33768 * @param {Function} callback
33770 reload : function(callback){
33771 this.collapse(false, false);
33772 while(this.firstChild){
33773 this.removeChild(this.firstChild);
33775 this.childrenRendered = false;
33776 this.loaded = false;
33777 if(this.isHiddenRoot()){
33778 this.expanded = false;
33780 this.expand(false, false, callback);
33784 * Ext JS Library 1.1.1
33785 * Copyright(c) 2006-2007, Ext JS, LLC.
33787 * Originally Released Under LGPL - original licence link has changed is not relivant.
33790 * <script type="text/javascript">
33794 * @class Roo.tree.TreeNodeUI
33796 * @param {Object} node The node to render
33797 * The TreeNode UI implementation is separate from the
33798 * tree implementation. Unless you are customizing the tree UI,
33799 * you should never have to use this directly.
33801 Roo.tree.TreeNodeUI = function(node){
33803 this.rendered = false;
33804 this.animating = false;
33805 this.emptyIcon = Roo.BLANK_IMAGE_URL;
33808 Roo.tree.TreeNodeUI.prototype = {
33809 removeChild : function(node){
33811 this.ctNode.removeChild(node.ui.getEl());
33815 beforeLoad : function(){
33816 this.addClass("x-tree-node-loading");
33819 afterLoad : function(){
33820 this.removeClass("x-tree-node-loading");
33823 onTextChange : function(node, text, oldText){
33825 this.textNode.innerHTML = text;
33829 onDisableChange : function(node, state){
33830 this.disabled = state;
33832 this.addClass("x-tree-node-disabled");
33834 this.removeClass("x-tree-node-disabled");
33838 onSelectedChange : function(state){
33841 this.addClass("x-tree-selected");
33844 this.removeClass("x-tree-selected");
33848 onMove : function(tree, node, oldParent, newParent, index, refNode){
33849 this.childIndent = null;
33851 var targetNode = newParent.ui.getContainer();
33852 if(!targetNode){//target not rendered
33853 this.holder = document.createElement("div");
33854 this.holder.appendChild(this.wrap);
33857 var insertBefore = refNode ? refNode.ui.getEl() : null;
33859 targetNode.insertBefore(this.wrap, insertBefore);
33861 targetNode.appendChild(this.wrap);
33863 this.node.renderIndent(true);
33867 addClass : function(cls){
33869 Roo.fly(this.elNode).addClass(cls);
33873 removeClass : function(cls){
33875 Roo.fly(this.elNode).removeClass(cls);
33879 remove : function(){
33881 this.holder = document.createElement("div");
33882 this.holder.appendChild(this.wrap);
33886 fireEvent : function(){
33887 return this.node.fireEvent.apply(this.node, arguments);
33890 initEvents : function(){
33891 this.node.on("move", this.onMove, this);
33892 var E = Roo.EventManager;
33893 var a = this.anchor;
33895 var el = Roo.fly(a, '_treeui');
33897 if(Roo.isOpera){ // opera render bug ignores the CSS
33898 el.setStyle("text-decoration", "none");
33901 el.on("click", this.onClick, this);
33902 el.on("dblclick", this.onDblClick, this);
33905 Roo.EventManager.on(this.checkbox,
33906 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
33909 el.on("contextmenu", this.onContextMenu, this);
33911 var icon = Roo.fly(this.iconNode);
33912 icon.on("click", this.onClick, this);
33913 icon.on("dblclick", this.onDblClick, this);
33914 icon.on("contextmenu", this.onContextMenu, this);
33915 E.on(this.ecNode, "click", this.ecClick, this, true);
33917 if(this.node.disabled){
33918 this.addClass("x-tree-node-disabled");
33920 if(this.node.hidden){
33921 this.addClass("x-tree-node-disabled");
33923 var ot = this.node.getOwnerTree();
33924 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
33925 if(dd && (!this.node.isRoot || ot.rootVisible)){
33926 Roo.dd.Registry.register(this.elNode, {
33928 handles: this.getDDHandles(),
33934 getDDHandles : function(){
33935 return [this.iconNode, this.textNode];
33940 this.wrap.style.display = "none";
33946 this.wrap.style.display = "";
33950 onContextMenu : function(e){
33951 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
33952 e.preventDefault();
33954 this.fireEvent("contextmenu", this.node, e);
33958 onClick : function(e){
33963 if(this.fireEvent("beforeclick", this.node, e) !== false){
33964 if(!this.disabled && this.node.attributes.href){
33965 this.fireEvent("click", this.node, e);
33968 e.preventDefault();
33973 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
33974 this.node.toggle();
33977 this.fireEvent("click", this.node, e);
33983 onDblClick : function(e){
33984 e.preventDefault();
33989 this.toggleCheck();
33991 if(!this.animating && this.node.hasChildNodes()){
33992 this.node.toggle();
33994 this.fireEvent("dblclick", this.node, e);
33997 onCheckChange : function(){
33998 var checked = this.checkbox.checked;
33999 this.node.attributes.checked = checked;
34000 this.fireEvent('checkchange', this.node, checked);
34003 ecClick : function(e){
34004 if(!this.animating && this.node.hasChildNodes()){
34005 this.node.toggle();
34009 startDrop : function(){
34010 this.dropping = true;
34013 // delayed drop so the click event doesn't get fired on a drop
34014 endDrop : function(){
34015 setTimeout(function(){
34016 this.dropping = false;
34017 }.createDelegate(this), 50);
34020 expand : function(){
34021 this.updateExpandIcon();
34022 this.ctNode.style.display = "";
34025 focus : function(){
34026 if(!this.node.preventHScroll){
34027 try{this.anchor.focus();
34029 }else if(!Roo.isIE){
34031 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
34032 var l = noscroll.scrollLeft;
34033 this.anchor.focus();
34034 noscroll.scrollLeft = l;
34039 toggleCheck : function(value){
34040 var cb = this.checkbox;
34042 cb.checked = (value === undefined ? !cb.checked : value);
34048 this.anchor.blur();
34052 animExpand : function(callback){
34053 var ct = Roo.get(this.ctNode);
34055 if(!this.node.hasChildNodes()){
34056 this.updateExpandIcon();
34057 this.ctNode.style.display = "";
34058 Roo.callback(callback);
34061 this.animating = true;
34062 this.updateExpandIcon();
34065 callback : function(){
34066 this.animating = false;
34067 Roo.callback(callback);
34070 duration: this.node.ownerTree.duration || .25
34074 highlight : function(){
34075 var tree = this.node.getOwnerTree();
34076 Roo.fly(this.wrap).highlight(
34077 tree.hlColor || "C3DAF9",
34078 {endColor: tree.hlBaseColor}
34082 collapse : function(){
34083 this.updateExpandIcon();
34084 this.ctNode.style.display = "none";
34087 animCollapse : function(callback){
34088 var ct = Roo.get(this.ctNode);
34089 ct.enableDisplayMode('block');
34092 this.animating = true;
34093 this.updateExpandIcon();
34096 callback : function(){
34097 this.animating = false;
34098 Roo.callback(callback);
34101 duration: this.node.ownerTree.duration || .25
34105 getContainer : function(){
34106 return this.ctNode;
34109 getEl : function(){
34113 appendDDGhost : function(ghostNode){
34114 ghostNode.appendChild(this.elNode.cloneNode(true));
34117 getDDRepairXY : function(){
34118 return Roo.lib.Dom.getXY(this.iconNode);
34121 onRender : function(){
34125 render : function(bulkRender){
34126 var n = this.node, a = n.attributes;
34127 var targetNode = n.parentNode ?
34128 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
34130 if(!this.rendered){
34131 this.rendered = true;
34133 this.renderElements(n, a, targetNode, bulkRender);
34136 if(this.textNode.setAttributeNS){
34137 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
34139 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
34142 this.textNode.setAttribute("ext:qtip", a.qtip);
34144 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
34147 }else if(a.qtipCfg){
34148 a.qtipCfg.target = Roo.id(this.textNode);
34149 Roo.QuickTips.register(a.qtipCfg);
34152 if(!this.node.expanded){
34153 this.updateExpandIcon();
34156 if(bulkRender === true) {
34157 targetNode.appendChild(this.wrap);
34162 renderElements : function(n, a, targetNode, bulkRender)
34164 // add some indent caching, this helps performance when rendering a large tree
34165 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
34166 var t = n.getOwnerTree();
34167 var txt = t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
34168 if (typeof(n.attributes.html) != 'undefined') {
34169 txt = n.attributes.html;
34171 var tip = t.rendererTip ? t.rendererTip(n.attributes) : txt;
34172 var cb = typeof a.checked == 'boolean';
34173 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
34174 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
34175 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
34176 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
34177 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
34178 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
34179 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
34180 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
34181 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
34182 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
34185 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
34186 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
34187 n.nextSibling.ui.getEl(), buf.join(""));
34189 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
34192 this.elNode = this.wrap.childNodes[0];
34193 this.ctNode = this.wrap.childNodes[1];
34194 var cs = this.elNode.childNodes;
34195 this.indentNode = cs[0];
34196 this.ecNode = cs[1];
34197 this.iconNode = cs[2];
34200 this.checkbox = cs[3];
34203 this.anchor = cs[index];
34204 this.textNode = cs[index].firstChild;
34207 getAnchor : function(){
34208 return this.anchor;
34211 getTextEl : function(){
34212 return this.textNode;
34215 getIconEl : function(){
34216 return this.iconNode;
34219 isChecked : function(){
34220 return this.checkbox ? this.checkbox.checked : false;
34223 updateExpandIcon : function(){
34225 var n = this.node, c1, c2;
34226 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
34227 var hasChild = n.hasChildNodes();
34231 c1 = "x-tree-node-collapsed";
34232 c2 = "x-tree-node-expanded";
34235 c1 = "x-tree-node-expanded";
34236 c2 = "x-tree-node-collapsed";
34239 this.removeClass("x-tree-node-leaf");
34240 this.wasLeaf = false;
34242 if(this.c1 != c1 || this.c2 != c2){
34243 Roo.fly(this.elNode).replaceClass(c1, c2);
34244 this.c1 = c1; this.c2 = c2;
34247 // this changes non-leafs into leafs if they have no children.
34248 // it's not very rational behaviour..
34250 if(!this.wasLeaf && this.node.leaf){
34251 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
34254 this.wasLeaf = true;
34257 var ecc = "x-tree-ec-icon "+cls;
34258 if(this.ecc != ecc){
34259 this.ecNode.className = ecc;
34265 getChildIndent : function(){
34266 if(!this.childIndent){
34270 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
34272 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
34274 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
34279 this.childIndent = buf.join("");
34281 return this.childIndent;
34284 renderIndent : function(){
34287 var p = this.node.parentNode;
34289 indent = p.ui.getChildIndent();
34291 if(this.indentMarkup != indent){ // don't rerender if not required
34292 this.indentNode.innerHTML = indent;
34293 this.indentMarkup = indent;
34295 this.updateExpandIcon();
34300 Roo.tree.RootTreeNodeUI = function(){
34301 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
34303 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
34304 render : function(){
34305 if(!this.rendered){
34306 var targetNode = this.node.ownerTree.innerCt.dom;
34307 this.node.expanded = true;
34308 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
34309 this.wrap = this.ctNode = targetNode.firstChild;
34312 collapse : function(){
34314 expand : function(){
34318 * Ext JS Library 1.1.1
34319 * Copyright(c) 2006-2007, Ext JS, LLC.
34321 * Originally Released Under LGPL - original licence link has changed is not relivant.
34324 * <script type="text/javascript">
34327 * @class Roo.tree.TreeLoader
34328 * @extends Roo.util.Observable
34329 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
34330 * nodes from a specified URL. The response must be a javascript Array definition
34331 * who's elements are node definition objects. eg:
34336 { 'id': 1, 'text': 'A folder Node', 'leaf': false },
34337 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }
34344 * The old style respose with just an array is still supported, but not recommended.
34347 * A server request is sent, and child nodes are loaded only when a node is expanded.
34348 * The loading node's id is passed to the server under the parameter name "node" to
34349 * enable the server to produce the correct child nodes.
34351 * To pass extra parameters, an event handler may be attached to the "beforeload"
34352 * event, and the parameters specified in the TreeLoader's baseParams property:
34354 myTreeLoader.on("beforeload", function(treeLoader, node) {
34355 this.baseParams.category = node.attributes.category;
34358 * This would pass an HTTP parameter called "category" to the server containing
34359 * the value of the Node's "category" attribute.
34361 * Creates a new Treeloader.
34362 * @param {Object} config A config object containing config properties.
34364 Roo.tree.TreeLoader = function(config){
34365 this.baseParams = {};
34366 this.requestMethod = "POST";
34367 Roo.apply(this, config);
34372 * @event beforeload
34373 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
34374 * @param {Object} This TreeLoader object.
34375 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
34376 * @param {Object} callback The callback function specified in the {@link #load} call.
34381 * Fires when the node has been successfuly loaded.
34382 * @param {Object} This TreeLoader object.
34383 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
34384 * @param {Object} response The response object containing the data from the server.
34388 * @event loadexception
34389 * Fires if the network request failed.
34390 * @param {Object} This TreeLoader object.
34391 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
34392 * @param {Object} response The response object containing the data from the server.
34394 loadexception : true,
34397 * Fires before a node is created, enabling you to return custom Node types
34398 * @param {Object} This TreeLoader object.
34399 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
34404 Roo.tree.TreeLoader.superclass.constructor.call(this);
34407 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
34409 * @cfg {String} dataUrl The URL from which to request a Json string which
34410 * specifies an array of node definition object representing the child nodes
34414 * @cfg {String} requestMethod either GET or POST
34415 * defaults to POST (due to BC)
34419 * @cfg {Object} baseParams (optional) An object containing properties which
34420 * specify HTTP parameters to be passed to each request for child nodes.
34423 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
34424 * created by this loader. If the attributes sent by the server have an attribute in this object,
34425 * they take priority.
34428 * @cfg {Object} uiProviders (optional) An object containing properties which
34430 * DEPRECATED - use 'create' event handler to modify attributes - which affect creation.
34431 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
34432 * <i>uiProvider</i> attribute of a returned child node is a string rather
34433 * than a reference to a TreeNodeUI implementation, this that string value
34434 * is used as a property name in the uiProviders object. You can define the provider named
34435 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
34440 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
34441 * child nodes before loading.
34443 clearOnLoad : true,
34446 * @cfg {String} root (optional) Default to false. Use this to read data from an object
34447 * property on loading, rather than expecting an array. (eg. more compatible to a standard
34448 * Grid query { data : [ .....] }
34453 * @cfg {String} queryParam (optional)
34454 * Name of the query as it will be passed on the querystring (defaults to 'node')
34455 * eg. the request will be ?node=[id]
34462 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
34463 * This is called automatically when a node is expanded, but may be used to reload
34464 * a node (or append new children if the {@link #clearOnLoad} option is false.)
34465 * @param {Roo.tree.TreeNode} node
34466 * @param {Function} callback
34468 load : function(node, callback){
34469 if(this.clearOnLoad){
34470 while(node.firstChild){
34471 node.removeChild(node.firstChild);
34474 if(node.attributes.children){ // preloaded json children
34475 var cs = node.attributes.children;
34476 for(var i = 0, len = cs.length; i < len; i++){
34477 node.appendChild(this.createNode(cs[i]));
34479 if(typeof callback == "function"){
34482 }else if(this.dataUrl){
34483 this.requestData(node, callback);
34487 getParams: function(node){
34488 var buf = [], bp = this.baseParams;
34489 for(var key in bp){
34490 if(typeof bp[key] != "function"){
34491 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
34494 var n = this.queryParam === false ? 'node' : this.queryParam;
34495 buf.push(n + "=", encodeURIComponent(node.id));
34496 return buf.join("");
34499 requestData : function(node, callback){
34500 if(this.fireEvent("beforeload", this, node, callback) !== false){
34501 this.transId = Roo.Ajax.request({
34502 method:this.requestMethod,
34503 url: this.dataUrl||this.url,
34504 success: this.handleResponse,
34505 failure: this.handleFailure,
34507 argument: {callback: callback, node: node},
34508 params: this.getParams(node)
34511 // if the load is cancelled, make sure we notify
34512 // the node that we are done
34513 if(typeof callback == "function"){
34519 isLoading : function(){
34520 return this.transId ? true : false;
34523 abort : function(){
34524 if(this.isLoading()){
34525 Roo.Ajax.abort(this.transId);
34530 createNode : function(attr)
34532 // apply baseAttrs, nice idea Corey!
34533 if(this.baseAttrs){
34534 Roo.applyIf(attr, this.baseAttrs);
34536 if(this.applyLoader !== false){
34537 attr.loader = this;
34539 // uiProvider = depreciated..
34541 if(typeof(attr.uiProvider) == 'string'){
34542 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
34543 /** eval:var:attr */ eval(attr.uiProvider);
34545 if(typeof(this.uiProviders['default']) != 'undefined') {
34546 attr.uiProvider = this.uiProviders['default'];
34549 this.fireEvent('create', this, attr);
34551 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
34553 new Roo.tree.TreeNode(attr) :
34554 new Roo.tree.AsyncTreeNode(attr));
34557 processResponse : function(response, node, callback)
34559 var json = response.responseText;
34562 var o = Roo.decode(json);
34564 if (this.root === false && typeof(o.success) != undefined) {
34565 this.root = 'data'; // the default behaviour for list like data..
34568 if (this.root !== false && !o.success) {
34569 // it's a failure condition.
34570 var a = response.argument;
34571 this.fireEvent("loadexception", this, a.node, response);
34572 Roo.log("Load failed - should have a handler really");
34578 if (this.root !== false) {
34582 for(var i = 0, len = o.length; i < len; i++){
34583 var n = this.createNode(o[i]);
34585 node.appendChild(n);
34588 if(typeof callback == "function"){
34589 callback(this, node);
34592 this.handleFailure(response);
34596 handleResponse : function(response){
34597 this.transId = false;
34598 var a = response.argument;
34599 this.processResponse(response, a.node, a.callback);
34600 this.fireEvent("load", this, a.node, response);
34603 handleFailure : function(response)
34605 // should handle failure better..
34606 this.transId = false;
34607 var a = response.argument;
34608 this.fireEvent("loadexception", this, a.node, response);
34609 if(typeof a.callback == "function"){
34610 a.callback(this, a.node);
34615 * Ext JS Library 1.1.1
34616 * Copyright(c) 2006-2007, Ext JS, LLC.
34618 * Originally Released Under LGPL - original licence link has changed is not relivant.
34621 * <script type="text/javascript">
34625 * @class Roo.tree.TreeFilter
34626 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
34627 * @param {TreePanel} tree
34628 * @param {Object} config (optional)
34630 Roo.tree.TreeFilter = function(tree, config){
34632 this.filtered = {};
34633 Roo.apply(this, config);
34636 Roo.tree.TreeFilter.prototype = {
34643 * Filter the data by a specific attribute.
34644 * @param {String/RegExp} value Either string that the attribute value
34645 * should start with or a RegExp to test against the attribute
34646 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
34647 * @param {TreeNode} startNode (optional) The node to start the filter at.
34649 filter : function(value, attr, startNode){
34650 attr = attr || "text";
34652 if(typeof value == "string"){
34653 var vlen = value.length;
34654 // auto clear empty filter
34655 if(vlen == 0 && this.clearBlank){
34659 value = value.toLowerCase();
34661 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
34663 }else if(value.exec){ // regex?
34665 return value.test(n.attributes[attr]);
34668 throw 'Illegal filter type, must be string or regex';
34670 this.filterBy(f, null, startNode);
34674 * Filter by a function. The passed function will be called with each
34675 * node in the tree (or from the startNode). If the function returns true, the node is kept
34676 * otherwise it is filtered. If a node is filtered, its children are also filtered.
34677 * @param {Function} fn The filter function
34678 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
34680 filterBy : function(fn, scope, startNode){
34681 startNode = startNode || this.tree.root;
34682 if(this.autoClear){
34685 var af = this.filtered, rv = this.reverse;
34686 var f = function(n){
34687 if(n == startNode){
34693 var m = fn.call(scope || n, n);
34701 startNode.cascade(f);
34704 if(typeof id != "function"){
34706 if(n && n.parentNode){
34707 n.parentNode.removeChild(n);
34715 * Clears the current filter. Note: with the "remove" option
34716 * set a filter cannot be cleared.
34718 clear : function(){
34720 var af = this.filtered;
34722 if(typeof id != "function"){
34729 this.filtered = {};
34734 * Ext JS Library 1.1.1
34735 * Copyright(c) 2006-2007, Ext JS, LLC.
34737 * Originally Released Under LGPL - original licence link has changed is not relivant.
34740 * <script type="text/javascript">
34745 * @class Roo.tree.TreeSorter
34746 * Provides sorting of nodes in a TreePanel
34748 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
34749 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
34750 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
34751 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
34752 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
34753 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
34755 * @param {TreePanel} tree
34756 * @param {Object} config
34758 Roo.tree.TreeSorter = function(tree, config){
34759 Roo.apply(this, config);
34760 tree.on("beforechildrenrendered", this.doSort, this);
34761 tree.on("append", this.updateSort, this);
34762 tree.on("insert", this.updateSort, this);
34764 var dsc = this.dir && this.dir.toLowerCase() == "desc";
34765 var p = this.property || "text";
34766 var sortType = this.sortType;
34767 var fs = this.folderSort;
34768 var cs = this.caseSensitive === true;
34769 var leafAttr = this.leafAttr || 'leaf';
34771 this.sortFn = function(n1, n2){
34773 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
34776 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
34780 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
34781 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
34783 return dsc ? +1 : -1;
34785 return dsc ? -1 : +1;
34792 Roo.tree.TreeSorter.prototype = {
34793 doSort : function(node){
34794 node.sort(this.sortFn);
34797 compareNodes : function(n1, n2){
34798 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
34801 updateSort : function(tree, node){
34802 if(node.childrenRendered){
34803 this.doSort.defer(1, this, [node]);
34808 * Ext JS Library 1.1.1
34809 * Copyright(c) 2006-2007, Ext JS, LLC.
34811 * Originally Released Under LGPL - original licence link has changed is not relivant.
34814 * <script type="text/javascript">
34817 if(Roo.dd.DropZone){
34819 Roo.tree.TreeDropZone = function(tree, config){
34820 this.allowParentInsert = false;
34821 this.allowContainerDrop = false;
34822 this.appendOnly = false;
34823 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
34825 this.lastInsertClass = "x-tree-no-status";
34826 this.dragOverData = {};
34829 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
34830 ddGroup : "TreeDD",
34833 expandDelay : 1000,
34835 expandNode : function(node){
34836 if(node.hasChildNodes() && !node.isExpanded()){
34837 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
34841 queueExpand : function(node){
34842 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
34845 cancelExpand : function(){
34846 if(this.expandProcId){
34847 clearTimeout(this.expandProcId);
34848 this.expandProcId = false;
34852 isValidDropPoint : function(n, pt, dd, e, data){
34853 if(!n || !data){ return false; }
34854 var targetNode = n.node;
34855 var dropNode = data.node;
34856 // default drop rules
34857 if(!(targetNode && targetNode.isTarget && pt)){
34860 if(pt == "append" && targetNode.allowChildren === false){
34863 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
34866 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
34869 // reuse the object
34870 var overEvent = this.dragOverData;
34871 overEvent.tree = this.tree;
34872 overEvent.target = targetNode;
34873 overEvent.data = data;
34874 overEvent.point = pt;
34875 overEvent.source = dd;
34876 overEvent.rawEvent = e;
34877 overEvent.dropNode = dropNode;
34878 overEvent.cancel = false;
34879 var result = this.tree.fireEvent("nodedragover", overEvent);
34880 return overEvent.cancel === false && result !== false;
34883 getDropPoint : function(e, n, dd)
34887 return tn.allowChildren !== false ? "append" : false; // always append for root
34889 var dragEl = n.ddel;
34890 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
34891 var y = Roo.lib.Event.getPageY(e);
34892 //var noAppend = tn.allowChildren === false || tn.isLeaf();
34894 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
34895 var noAppend = tn.allowChildren === false;
34896 if(this.appendOnly || tn.parentNode.allowChildren === false){
34897 return noAppend ? false : "append";
34899 var noBelow = false;
34900 if(!this.allowParentInsert){
34901 noBelow = tn.hasChildNodes() && tn.isExpanded();
34903 var q = (b - t) / (noAppend ? 2 : 3);
34904 if(y >= t && y < (t + q)){
34906 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
34913 onNodeEnter : function(n, dd, e, data)
34915 this.cancelExpand();
34918 onNodeOver : function(n, dd, e, data)
34921 var pt = this.getDropPoint(e, n, dd);
34924 // auto node expand check
34925 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
34926 this.queueExpand(node);
34927 }else if(pt != "append"){
34928 this.cancelExpand();
34931 // set the insert point style on the target node
34932 var returnCls = this.dropNotAllowed;
34933 if(this.isValidDropPoint(n, pt, dd, e, data)){
34938 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
34939 cls = "x-tree-drag-insert-above";
34940 }else if(pt == "below"){
34941 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
34942 cls = "x-tree-drag-insert-below";
34944 returnCls = "x-tree-drop-ok-append";
34945 cls = "x-tree-drag-append";
34947 if(this.lastInsertClass != cls){
34948 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
34949 this.lastInsertClass = cls;
34956 onNodeOut : function(n, dd, e, data){
34958 this.cancelExpand();
34959 this.removeDropIndicators(n);
34962 onNodeDrop : function(n, dd, e, data){
34963 var point = this.getDropPoint(e, n, dd);
34964 var targetNode = n.node;
34965 targetNode.ui.startDrop();
34966 if(!this.isValidDropPoint(n, point, dd, e, data)){
34967 targetNode.ui.endDrop();
34970 // first try to find the drop node
34971 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
34974 target: targetNode,
34979 dropNode: dropNode,
34982 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
34983 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
34984 targetNode.ui.endDrop();
34987 // allow target changing
34988 targetNode = dropEvent.target;
34989 if(point == "append" && !targetNode.isExpanded()){
34990 targetNode.expand(false, null, function(){
34991 this.completeDrop(dropEvent);
34992 }.createDelegate(this));
34994 this.completeDrop(dropEvent);
34999 completeDrop : function(de){
35000 var ns = de.dropNode, p = de.point, t = de.target;
35001 if(!(ns instanceof Array)){
35005 for(var i = 0, len = ns.length; i < len; i++){
35008 t.parentNode.insertBefore(n, t);
35009 }else if(p == "below"){
35010 t.parentNode.insertBefore(n, t.nextSibling);
35016 if(this.tree.hlDrop){
35020 this.tree.fireEvent("nodedrop", de);
35023 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
35024 if(this.tree.hlDrop){
35025 dropNode.ui.focus();
35026 dropNode.ui.highlight();
35028 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
35031 getTree : function(){
35035 removeDropIndicators : function(n){
35038 Roo.fly(el).removeClass([
35039 "x-tree-drag-insert-above",
35040 "x-tree-drag-insert-below",
35041 "x-tree-drag-append"]);
35042 this.lastInsertClass = "_noclass";
35046 beforeDragDrop : function(target, e, id){
35047 this.cancelExpand();
35051 afterRepair : function(data){
35052 if(data && Roo.enableFx){
35053 data.node.ui.highlight();
35063 * Ext JS Library 1.1.1
35064 * Copyright(c) 2006-2007, Ext JS, LLC.
35066 * Originally Released Under LGPL - original licence link has changed is not relivant.
35069 * <script type="text/javascript">
35073 if(Roo.dd.DragZone){
35074 Roo.tree.TreeDragZone = function(tree, config){
35075 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
35079 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
35080 ddGroup : "TreeDD",
35082 onBeforeDrag : function(data, e){
35084 return n && n.draggable && !n.disabled;
35088 onInitDrag : function(e){
35089 var data = this.dragData;
35090 this.tree.getSelectionModel().select(data.node);
35091 this.proxy.update("");
35092 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
35093 this.tree.fireEvent("startdrag", this.tree, data.node, e);
35096 getRepairXY : function(e, data){
35097 return data.node.ui.getDDRepairXY();
35100 onEndDrag : function(data, e){
35101 this.tree.fireEvent("enddrag", this.tree, data.node, e);
35106 onValidDrop : function(dd, e, id){
35107 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
35111 beforeInvalidDrop : function(e, id){
35112 // this scrolls the original position back into view
35113 var sm = this.tree.getSelectionModel();
35114 sm.clearSelections();
35115 sm.select(this.dragData.node);
35120 * Ext JS Library 1.1.1
35121 * Copyright(c) 2006-2007, Ext JS, LLC.
35123 * Originally Released Under LGPL - original licence link has changed is not relivant.
35126 * <script type="text/javascript">
35129 * @class Roo.tree.TreeEditor
35130 * @extends Roo.Editor
35131 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
35132 * as the editor field.
35134 * @param {Object} config (used to be the tree panel.)
35135 * @param {Object} oldconfig DEPRECIATED Either a prebuilt {@link Roo.form.Field} instance or a Field config object
35137 * @cfg {Roo.tree.TreePanel} tree The tree to bind to.
35138 * @cfg {Roo.form.TextField|Object} field The field configuration
35142 Roo.tree.TreeEditor = function(config, oldconfig) { // was -- (tree, config){
35145 if (oldconfig) { // old style..
35146 field = oldconfig.events ? oldconfig : new Roo.form.TextField(oldconfig);
35149 tree = config.tree;
35150 config.field = config.field || {};
35151 config.field.xtype = 'TextField';
35152 field = Roo.factory(config.field, Roo.form);
35154 config = config || {};
35159 * @event beforenodeedit
35160 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
35161 * false from the handler of this event.
35162 * @param {Editor} this
35163 * @param {Roo.tree.Node} node
35165 "beforenodeedit" : true
35169 Roo.tree.TreeEditor.superclass.constructor.call(this, field, config);
35173 tree.on('beforeclick', this.beforeNodeClick, this);
35174 tree.getTreeEl().on('mousedown', this.hide, this);
35175 this.on('complete', this.updateNode, this);
35176 this.on('beforestartedit', this.fitToTree, this);
35177 this.on('startedit', this.bindScroll, this, {delay:10});
35178 this.on('specialkey', this.onSpecialKey, this);
35181 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
35183 * @cfg {String} alignment
35184 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
35190 * @cfg {Boolean} hideEl
35191 * True to hide the bound element while the editor is displayed (defaults to false)
35195 * @cfg {String} cls
35196 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
35198 cls: "x-small-editor x-tree-editor",
35200 * @cfg {Boolean} shim
35201 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
35207 * @cfg {Number} maxWidth
35208 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
35209 * the containing tree element's size, it will be automatically limited for you to the container width, taking
35210 * scroll and client offsets into account prior to each edit.
35217 fitToTree : function(ed, el){
35218 var td = this.tree.getTreeEl().dom, nd = el.dom;
35219 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
35220 td.scrollLeft = nd.offsetLeft;
35224 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
35225 this.setSize(w, '');
35227 return this.fireEvent('beforenodeedit', this, this.editNode);
35232 triggerEdit : function(node){
35233 this.completeEdit();
35234 this.editNode = node;
35235 this.startEdit(node.ui.textNode, node.text);
35239 bindScroll : function(){
35240 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
35244 beforeNodeClick : function(node, e){
35245 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
35246 this.lastClick = new Date();
35247 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
35249 this.triggerEdit(node);
35256 updateNode : function(ed, value){
35257 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
35258 this.editNode.setText(value);
35262 onHide : function(){
35263 Roo.tree.TreeEditor.superclass.onHide.call(this);
35265 this.editNode.ui.focus();
35270 onSpecialKey : function(field, e){
35271 var k = e.getKey();
35275 }else if(k == e.ENTER && !e.hasModifier()){
35277 this.completeEdit();
35280 });//<Script type="text/javascript">
35283 * Ext JS Library 1.1.1
35284 * Copyright(c) 2006-2007, Ext JS, LLC.
35286 * Originally Released Under LGPL - original licence link has changed is not relivant.
35289 * <script type="text/javascript">
35293 * Not documented??? - probably should be...
35296 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
35297 //focus: Roo.emptyFn, // prevent odd scrolling behavior
35299 renderElements : function(n, a, targetNode, bulkRender){
35300 //consel.log("renderElements?");
35301 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
35303 var t = n.getOwnerTree();
35304 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
35306 var cols = t.columns;
35307 var bw = t.borderWidth;
35309 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
35310 var cb = typeof a.checked == "boolean";
35311 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
35312 var colcls = 'x-t-' + tid + '-c0';
35314 '<li class="x-tree-node">',
35317 '<div class="x-tree-node-el ', a.cls,'">',
35319 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
35322 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
35323 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
35324 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
35325 (a.icon ? ' x-tree-node-inline-icon' : ''),
35326 (a.iconCls ? ' '+a.iconCls : ''),
35327 '" unselectable="on" />',
35328 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
35329 (a.checked ? 'checked="checked" />' : ' />')) : ''),
35331 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
35332 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
35333 '<span unselectable="on" qtip="' + tx + '">',
35337 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
35338 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>'
35340 for(var i = 1, len = cols.length; i < len; i++){
35342 colcls = 'x-t-' + tid + '-c' +i;
35343 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
35344 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
35345 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
35351 '<div class="x-clear"></div></div>',
35352 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
35355 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
35356 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
35357 n.nextSibling.ui.getEl(), buf.join(""));
35359 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
35361 var el = this.wrap.firstChild;
35363 this.elNode = el.firstChild;
35364 this.ranchor = el.childNodes[1];
35365 this.ctNode = this.wrap.childNodes[1];
35366 var cs = el.firstChild.childNodes;
35367 this.indentNode = cs[0];
35368 this.ecNode = cs[1];
35369 this.iconNode = cs[2];
35372 this.checkbox = cs[3];
35375 this.anchor = cs[index];
35377 this.textNode = cs[index].firstChild;
35379 //el.on("click", this.onClick, this);
35380 //el.on("dblclick", this.onDblClick, this);
35383 // console.log(this);
35385 initEvents : function(){
35386 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
35389 var a = this.ranchor;
35391 var el = Roo.get(a);
35393 if(Roo.isOpera){ // opera render bug ignores the CSS
35394 el.setStyle("text-decoration", "none");
35397 el.on("click", this.onClick, this);
35398 el.on("dblclick", this.onDblClick, this);
35399 el.on("contextmenu", this.onContextMenu, this);
35403 /*onSelectedChange : function(state){
35406 this.addClass("x-tree-selected");
35409 this.removeClass("x-tree-selected");
35412 addClass : function(cls){
35414 Roo.fly(this.elRow).addClass(cls);
35420 removeClass : function(cls){
35422 Roo.fly(this.elRow).removeClass(cls);
35428 });//<Script type="text/javascript">
35432 * Ext JS Library 1.1.1
35433 * Copyright(c) 2006-2007, Ext JS, LLC.
35435 * Originally Released Under LGPL - original licence link has changed is not relivant.
35438 * <script type="text/javascript">
35443 * @class Roo.tree.ColumnTree
35444 * @extends Roo.data.TreePanel
35445 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
35446 * @cfg {int} borderWidth compined right/left border allowance
35448 * @param {String/HTMLElement/Element} el The container element
35449 * @param {Object} config
35451 Roo.tree.ColumnTree = function(el, config)
35453 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
35457 * Fire this event on a container when it resizes
35458 * @param {int} w Width
35459 * @param {int} h Height
35463 this.on('resize', this.onResize, this);
35466 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
35470 borderWidth: Roo.isBorderBox ? 0 : 2,
35473 render : function(){
35474 // add the header.....
35476 Roo.tree.ColumnTree.superclass.render.apply(this);
35478 this.el.addClass('x-column-tree');
35480 this.headers = this.el.createChild(
35481 {cls:'x-tree-headers'},this.innerCt.dom);
35483 var cols = this.columns, c;
35484 var totalWidth = 0;
35486 var len = cols.length;
35487 for(var i = 0; i < len; i++){
35489 totalWidth += c.width;
35490 this.headEls.push(this.headers.createChild({
35491 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
35493 cls:'x-tree-hd-text',
35496 style:'width:'+(c.width-this.borderWidth)+'px;'
35499 this.headers.createChild({cls:'x-clear'});
35500 // prevent floats from wrapping when clipped
35501 this.headers.setWidth(totalWidth);
35502 //this.innerCt.setWidth(totalWidth);
35503 this.innerCt.setStyle({ overflow: 'auto' });
35504 this.onResize(this.width, this.height);
35508 onResize : function(w,h)
35513 this.innerCt.setWidth(this.width);
35514 this.innerCt.setHeight(this.height-20);
35517 var cols = this.columns, c;
35518 var totalWidth = 0;
35520 var len = cols.length;
35521 for(var i = 0; i < len; i++){
35523 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
35524 // it's the expander..
35525 expEl = this.headEls[i];
35528 totalWidth += c.width;
35532 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
35534 this.headers.setWidth(w-20);
35543 * Ext JS Library 1.1.1
35544 * Copyright(c) 2006-2007, Ext JS, LLC.
35546 * Originally Released Under LGPL - original licence link has changed is not relivant.
35549 * <script type="text/javascript">
35553 * @class Roo.menu.Menu
35554 * @extends Roo.util.Observable
35555 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
35556 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
35558 * Creates a new Menu
35559 * @param {Object} config Configuration options
35561 Roo.menu.Menu = function(config){
35562 Roo.apply(this, config);
35563 this.id = this.id || Roo.id();
35566 * @event beforeshow
35567 * Fires before this menu is displayed
35568 * @param {Roo.menu.Menu} this
35572 * @event beforehide
35573 * Fires before this menu is hidden
35574 * @param {Roo.menu.Menu} this
35579 * Fires after this menu is displayed
35580 * @param {Roo.menu.Menu} this
35585 * Fires after this menu is hidden
35586 * @param {Roo.menu.Menu} this
35591 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
35592 * @param {Roo.menu.Menu} this
35593 * @param {Roo.menu.Item} menuItem The menu item that was clicked
35594 * @param {Roo.EventObject} e
35599 * Fires when the mouse is hovering over this menu
35600 * @param {Roo.menu.Menu} this
35601 * @param {Roo.EventObject} e
35602 * @param {Roo.menu.Item} menuItem The menu item that was clicked
35607 * Fires when the mouse exits this menu
35608 * @param {Roo.menu.Menu} this
35609 * @param {Roo.EventObject} e
35610 * @param {Roo.menu.Item} menuItem The menu item that was clicked
35615 * Fires when a menu item contained in this menu is clicked
35616 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
35617 * @param {Roo.EventObject} e
35621 if (this.registerMenu) {
35622 Roo.menu.MenuMgr.register(this);
35625 var mis = this.items;
35626 this.items = new Roo.util.MixedCollection();
35628 this.add.apply(this, mis);
35632 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
35634 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
35638 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
35639 * for bottom-right shadow (defaults to "sides")
35643 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
35644 * this menu (defaults to "tl-tr?")
35646 subMenuAlign : "tl-tr?",
35648 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
35649 * relative to its element of origin (defaults to "tl-bl?")
35651 defaultAlign : "tl-bl?",
35653 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
35655 allowOtherMenus : false,
35657 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
35659 registerMenu : true,
35664 render : function(){
35668 var el = this.el = new Roo.Layer({
35670 shadow:this.shadow,
35672 parentEl: this.parentEl || document.body,
35676 this.keyNav = new Roo.menu.MenuNav(this);
35679 el.addClass("x-menu-plain");
35682 el.addClass(this.cls);
35684 // generic focus element
35685 this.focusEl = el.createChild({
35686 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
35688 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
35689 ul.on(Roo.isTouch ? 'touchstart' : 'click' , this.onClick, this);
35691 ul.on("mouseover", this.onMouseOver, this);
35692 ul.on("mouseout", this.onMouseOut, this);
35693 this.items.each(function(item){
35698 var li = document.createElement("li");
35699 li.className = "x-menu-list-item";
35700 ul.dom.appendChild(li);
35701 item.render(li, this);
35708 autoWidth : function(){
35709 var el = this.el, ul = this.ul;
35713 var w = this.width;
35716 }else if(Roo.isIE){
35717 el.setWidth(this.minWidth);
35718 var t = el.dom.offsetWidth; // force recalc
35719 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
35724 delayAutoWidth : function(){
35727 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
35729 this.awTask.delay(20);
35734 findTargetItem : function(e){
35735 var t = e.getTarget(".x-menu-list-item", this.ul, true);
35736 if(t && t.menuItemId){
35737 return this.items.get(t.menuItemId);
35742 onClick : function(e){
35743 Roo.log("menu.onClick");
35744 var t = this.findTargetItem(e);
35749 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
35750 if(t == this.activeItem && t.shouldDeactivate(e)){
35751 this.activeItem.deactivate();
35752 delete this.activeItem;
35756 this.setActiveItem(t, true);
35764 this.fireEvent("click", this, t, e);
35768 setActiveItem : function(item, autoExpand){
35769 if(item != this.activeItem){
35770 if(this.activeItem){
35771 this.activeItem.deactivate();
35773 this.activeItem = item;
35774 item.activate(autoExpand);
35775 }else if(autoExpand){
35781 tryActivate : function(start, step){
35782 var items = this.items;
35783 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
35784 var item = items.get(i);
35785 if(!item.disabled && item.canActivate){
35786 this.setActiveItem(item, false);
35794 onMouseOver : function(e){
35796 if(t = this.findTargetItem(e)){
35797 if(t.canActivate && !t.disabled){
35798 this.setActiveItem(t, true);
35801 this.fireEvent("mouseover", this, e, t);
35805 onMouseOut : function(e){
35807 if(t = this.findTargetItem(e)){
35808 if(t == this.activeItem && t.shouldDeactivate(e)){
35809 this.activeItem.deactivate();
35810 delete this.activeItem;
35813 this.fireEvent("mouseout", this, e, t);
35817 * Read-only. Returns true if the menu is currently displayed, else false.
35820 isVisible : function(){
35821 return this.el && !this.hidden;
35825 * Displays this menu relative to another element
35826 * @param {String/HTMLElement/Roo.Element} element The element to align to
35827 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
35828 * the element (defaults to this.defaultAlign)
35829 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
35831 show : function(el, pos, parentMenu){
35832 this.parentMenu = parentMenu;
35836 this.fireEvent("beforeshow", this);
35837 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
35841 * Displays this menu at a specific xy position
35842 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
35843 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
35845 showAt : function(xy, parentMenu, /* private: */_e){
35846 this.parentMenu = parentMenu;
35851 this.fireEvent("beforeshow", this);
35852 xy = this.el.adjustForConstraints(xy);
35856 this.hidden = false;
35858 this.fireEvent("show", this);
35861 focus : function(){
35863 this.doFocus.defer(50, this);
35867 doFocus : function(){
35869 this.focusEl.focus();
35874 * Hides this menu and optionally all parent menus
35875 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
35877 hide : function(deep){
35878 if(this.el && this.isVisible()){
35879 this.fireEvent("beforehide", this);
35880 if(this.activeItem){
35881 this.activeItem.deactivate();
35882 this.activeItem = null;
35885 this.hidden = true;
35886 this.fireEvent("hide", this);
35888 if(deep === true && this.parentMenu){
35889 this.parentMenu.hide(true);
35894 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
35895 * Any of the following are valid:
35897 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
35898 * <li>An HTMLElement object which will be converted to a menu item</li>
35899 * <li>A menu item config object that will be created as a new menu item</li>
35900 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
35901 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
35906 var menu = new Roo.menu.Menu();
35908 // Create a menu item to add by reference
35909 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
35911 // Add a bunch of items at once using different methods.
35912 // Only the last item added will be returned.
35913 var item = menu.add(
35914 menuItem, // add existing item by ref
35915 'Dynamic Item', // new TextItem
35916 '-', // new separator
35917 { text: 'Config Item' } // new item by config
35920 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
35921 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
35924 var a = arguments, l = a.length, item;
35925 for(var i = 0; i < l; i++){
35927 if ((typeof(el) == "object") && el.xtype && el.xns) {
35928 el = Roo.factory(el, Roo.menu);
35931 if(el.render){ // some kind of Item
35932 item = this.addItem(el);
35933 }else if(typeof el == "string"){ // string
35934 if(el == "separator" || el == "-"){
35935 item = this.addSeparator();
35937 item = this.addText(el);
35939 }else if(el.tagName || el.el){ // element
35940 item = this.addElement(el);
35941 }else if(typeof el == "object"){ // must be menu item config?
35942 item = this.addMenuItem(el);
35949 * Returns this menu's underlying {@link Roo.Element} object
35950 * @return {Roo.Element} The element
35952 getEl : function(){
35960 * Adds a separator bar to the menu
35961 * @return {Roo.menu.Item} The menu item that was added
35963 addSeparator : function(){
35964 return this.addItem(new Roo.menu.Separator());
35968 * Adds an {@link Roo.Element} object to the menu
35969 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
35970 * @return {Roo.menu.Item} The menu item that was added
35972 addElement : function(el){
35973 return this.addItem(new Roo.menu.BaseItem(el));
35977 * Adds an existing object based on {@link Roo.menu.Item} to the menu
35978 * @param {Roo.menu.Item} item The menu item to add
35979 * @return {Roo.menu.Item} The menu item that was added
35981 addItem : function(item){
35982 this.items.add(item);
35984 var li = document.createElement("li");
35985 li.className = "x-menu-list-item";
35986 this.ul.dom.appendChild(li);
35987 item.render(li, this);
35988 this.delayAutoWidth();
35994 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
35995 * @param {Object} config A MenuItem config object
35996 * @return {Roo.menu.Item} The menu item that was added
35998 addMenuItem : function(config){
35999 if(!(config instanceof Roo.menu.Item)){
36000 if(typeof config.checked == "boolean"){ // must be check menu item config?
36001 config = new Roo.menu.CheckItem(config);
36003 config = new Roo.menu.Item(config);
36006 return this.addItem(config);
36010 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
36011 * @param {String} text The text to display in the menu item
36012 * @return {Roo.menu.Item} The menu item that was added
36014 addText : function(text){
36015 return this.addItem(new Roo.menu.TextItem({ text : text }));
36019 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
36020 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
36021 * @param {Roo.menu.Item} item The menu item to add
36022 * @return {Roo.menu.Item} The menu item that was added
36024 insert : function(index, item){
36025 this.items.insert(index, item);
36027 var li = document.createElement("li");
36028 li.className = "x-menu-list-item";
36029 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
36030 item.render(li, this);
36031 this.delayAutoWidth();
36037 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
36038 * @param {Roo.menu.Item} item The menu item to remove
36040 remove : function(item){
36041 this.items.removeKey(item.id);
36046 * Removes and destroys all items in the menu
36048 removeAll : function(){
36050 while(f = this.items.first()){
36056 // MenuNav is a private utility class used internally by the Menu
36057 Roo.menu.MenuNav = function(menu){
36058 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
36059 this.scope = this.menu = menu;
36062 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
36063 doRelay : function(e, h){
36064 var k = e.getKey();
36065 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
36066 this.menu.tryActivate(0, 1);
36069 return h.call(this.scope || this, e, this.menu);
36072 up : function(e, m){
36073 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
36074 m.tryActivate(m.items.length-1, -1);
36078 down : function(e, m){
36079 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
36080 m.tryActivate(0, 1);
36084 right : function(e, m){
36086 m.activeItem.expandMenu(true);
36090 left : function(e, m){
36092 if(m.parentMenu && m.parentMenu.activeItem){
36093 m.parentMenu.activeItem.activate();
36097 enter : function(e, m){
36099 e.stopPropagation();
36100 m.activeItem.onClick(e);
36101 m.fireEvent("click", this, m.activeItem);
36107 * Ext JS Library 1.1.1
36108 * Copyright(c) 2006-2007, Ext JS, LLC.
36110 * Originally Released Under LGPL - original licence link has changed is not relivant.
36113 * <script type="text/javascript">
36117 * @class Roo.menu.MenuMgr
36118 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
36121 Roo.menu.MenuMgr = function(){
36122 var menus, active, groups = {}, attached = false, lastShow = new Date();
36124 // private - called when first menu is created
36127 active = new Roo.util.MixedCollection();
36128 Roo.get(document).addKeyListener(27, function(){
36129 if(active.length > 0){
36136 function hideAll(){
36137 if(active && active.length > 0){
36138 var c = active.clone();
36139 c.each(function(m){
36146 function onHide(m){
36148 if(active.length < 1){
36149 Roo.get(document).un("mousedown", onMouseDown);
36155 function onShow(m){
36156 var last = active.last();
36157 lastShow = new Date();
36160 Roo.get(document).on("mousedown", onMouseDown);
36164 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
36165 m.parentMenu.activeChild = m;
36166 }else if(last && last.isVisible()){
36167 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
36172 function onBeforeHide(m){
36174 m.activeChild.hide();
36176 if(m.autoHideTimer){
36177 clearTimeout(m.autoHideTimer);
36178 delete m.autoHideTimer;
36183 function onBeforeShow(m){
36184 var pm = m.parentMenu;
36185 if(!pm && !m.allowOtherMenus){
36187 }else if(pm && pm.activeChild && active != m){
36188 pm.activeChild.hide();
36193 function onMouseDown(e){
36194 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
36200 function onBeforeCheck(mi, state){
36202 var g = groups[mi.group];
36203 for(var i = 0, l = g.length; i < l; i++){
36205 g[i].setChecked(false);
36214 * Hides all menus that are currently visible
36216 hideAll : function(){
36221 register : function(menu){
36225 menus[menu.id] = menu;
36226 menu.on("beforehide", onBeforeHide);
36227 menu.on("hide", onHide);
36228 menu.on("beforeshow", onBeforeShow);
36229 menu.on("show", onShow);
36230 var g = menu.group;
36231 if(g && menu.events["checkchange"]){
36235 groups[g].push(menu);
36236 menu.on("checkchange", onCheck);
36241 * Returns a {@link Roo.menu.Menu} object
36242 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
36243 * be used to generate and return a new Menu instance.
36245 get : function(menu){
36246 if(typeof menu == "string"){ // menu id
36247 return menus[menu];
36248 }else if(menu.events){ // menu instance
36250 }else if(typeof menu.length == 'number'){ // array of menu items?
36251 return new Roo.menu.Menu({items:menu});
36252 }else{ // otherwise, must be a config
36253 return new Roo.menu.Menu(menu);
36258 unregister : function(menu){
36259 delete menus[menu.id];
36260 menu.un("beforehide", onBeforeHide);
36261 menu.un("hide", onHide);
36262 menu.un("beforeshow", onBeforeShow);
36263 menu.un("show", onShow);
36264 var g = menu.group;
36265 if(g && menu.events["checkchange"]){
36266 groups[g].remove(menu);
36267 menu.un("checkchange", onCheck);
36272 registerCheckable : function(menuItem){
36273 var g = menuItem.group;
36278 groups[g].push(menuItem);
36279 menuItem.on("beforecheckchange", onBeforeCheck);
36284 unregisterCheckable : function(menuItem){
36285 var g = menuItem.group;
36287 groups[g].remove(menuItem);
36288 menuItem.un("beforecheckchange", onBeforeCheck);
36294 * Ext JS Library 1.1.1
36295 * Copyright(c) 2006-2007, Ext JS, LLC.
36297 * Originally Released Under LGPL - original licence link has changed is not relivant.
36300 * <script type="text/javascript">
36305 * @class Roo.menu.BaseItem
36306 * @extends Roo.Component
36307 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
36308 * management and base configuration options shared by all menu components.
36310 * Creates a new BaseItem
36311 * @param {Object} config Configuration options
36313 Roo.menu.BaseItem = function(config){
36314 Roo.menu.BaseItem.superclass.constructor.call(this, config);
36319 * Fires when this item is clicked
36320 * @param {Roo.menu.BaseItem} this
36321 * @param {Roo.EventObject} e
36326 * Fires when this item is activated
36327 * @param {Roo.menu.BaseItem} this
36331 * @event deactivate
36332 * Fires when this item is deactivated
36333 * @param {Roo.menu.BaseItem} this
36339 this.on("click", this.handler, this.scope, true);
36343 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
36345 * @cfg {Function} handler
36346 * A function that will handle the click event of this menu item (defaults to undefined)
36349 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
36351 canActivate : false,
36354 * @cfg {Boolean} hidden True to prevent creation of this menu item (defaults to false)
36359 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
36361 activeClass : "x-menu-item-active",
36363 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
36365 hideOnClick : true,
36367 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
36372 ctype: "Roo.menu.BaseItem",
36375 actionMode : "container",
36378 render : function(container, parentMenu){
36379 this.parentMenu = parentMenu;
36380 Roo.menu.BaseItem.superclass.render.call(this, container);
36381 this.container.menuItemId = this.id;
36385 onRender : function(container, position){
36386 this.el = Roo.get(this.el);
36387 container.dom.appendChild(this.el.dom);
36391 onClick : function(e){
36392 if(!this.disabled && this.fireEvent("click", this, e) !== false
36393 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
36394 this.handleClick(e);
36401 activate : function(){
36405 var li = this.container;
36406 li.addClass(this.activeClass);
36407 this.region = li.getRegion().adjust(2, 2, -2, -2);
36408 this.fireEvent("activate", this);
36413 deactivate : function(){
36414 this.container.removeClass(this.activeClass);
36415 this.fireEvent("deactivate", this);
36419 shouldDeactivate : function(e){
36420 return !this.region || !this.region.contains(e.getPoint());
36424 handleClick : function(e){
36425 if(this.hideOnClick){
36426 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
36431 expandMenu : function(autoActivate){
36436 hideMenu : function(){
36441 * Ext JS Library 1.1.1
36442 * Copyright(c) 2006-2007, Ext JS, LLC.
36444 * Originally Released Under LGPL - original licence link has changed is not relivant.
36447 * <script type="text/javascript">
36451 * @class Roo.menu.Adapter
36452 * @extends Roo.menu.BaseItem
36453 * 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.
36454 * It provides basic rendering, activation management and enable/disable logic required to work in menus.
36456 * Creates a new Adapter
36457 * @param {Object} config Configuration options
36459 Roo.menu.Adapter = function(component, config){
36460 Roo.menu.Adapter.superclass.constructor.call(this, config);
36461 this.component = component;
36463 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
36465 canActivate : true,
36468 onRender : function(container, position){
36469 this.component.render(container);
36470 this.el = this.component.getEl();
36474 activate : function(){
36478 this.component.focus();
36479 this.fireEvent("activate", this);
36484 deactivate : function(){
36485 this.fireEvent("deactivate", this);
36489 disable : function(){
36490 this.component.disable();
36491 Roo.menu.Adapter.superclass.disable.call(this);
36495 enable : function(){
36496 this.component.enable();
36497 Roo.menu.Adapter.superclass.enable.call(this);
36501 * Ext JS Library 1.1.1
36502 * Copyright(c) 2006-2007, Ext JS, LLC.
36504 * Originally Released Under LGPL - original licence link has changed is not relivant.
36507 * <script type="text/javascript">
36511 * @class Roo.menu.TextItem
36512 * @extends Roo.menu.BaseItem
36513 * Adds a static text string to a menu, usually used as either a heading or group separator.
36514 * Note: old style constructor with text is still supported.
36517 * Creates a new TextItem
36518 * @param {Object} cfg Configuration
36520 Roo.menu.TextItem = function(cfg){
36521 if (typeof(cfg) == 'string') {
36524 Roo.apply(this,cfg);
36527 Roo.menu.TextItem.superclass.constructor.call(this);
36530 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
36532 * @cfg {Boolean} text Text to show on item.
36537 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
36539 hideOnClick : false,
36541 * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
36543 itemCls : "x-menu-text",
36546 onRender : function(){
36547 var s = document.createElement("span");
36548 s.className = this.itemCls;
36549 s.innerHTML = this.text;
36551 Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
36555 * Ext JS Library 1.1.1
36556 * Copyright(c) 2006-2007, Ext JS, LLC.
36558 * Originally Released Under LGPL - original licence link has changed is not relivant.
36561 * <script type="text/javascript">
36565 * @class Roo.menu.Separator
36566 * @extends Roo.menu.BaseItem
36567 * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
36568 * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
36570 * @param {Object} config Configuration options
36572 Roo.menu.Separator = function(config){
36573 Roo.menu.Separator.superclass.constructor.call(this, config);
36576 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
36578 * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
36580 itemCls : "x-menu-sep",
36582 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
36584 hideOnClick : false,
36587 onRender : function(li){
36588 var s = document.createElement("span");
36589 s.className = this.itemCls;
36590 s.innerHTML = " ";
36592 li.addClass("x-menu-sep-li");
36593 Roo.menu.Separator.superclass.onRender.apply(this, arguments);
36597 * Ext JS Library 1.1.1
36598 * Copyright(c) 2006-2007, Ext JS, LLC.
36600 * Originally Released Under LGPL - original licence link has changed is not relivant.
36603 * <script type="text/javascript">
36606 * @class Roo.menu.Item
36607 * @extends Roo.menu.BaseItem
36608 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
36609 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
36610 * activation and click handling.
36612 * Creates a new Item
36613 * @param {Object} config Configuration options
36615 Roo.menu.Item = function(config){
36616 Roo.menu.Item.superclass.constructor.call(this, config);
36618 this.menu = Roo.menu.MenuMgr.get(this.menu);
36621 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
36624 * @cfg {String} text
36625 * The text to show on the menu item.
36629 * @cfg {String} HTML to render in menu
36630 * The text to show on the menu item (HTML version).
36634 * @cfg {String} icon
36635 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
36639 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
36641 itemCls : "x-menu-item",
36643 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
36645 canActivate : true,
36647 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
36650 // doc'd in BaseItem
36654 ctype: "Roo.menu.Item",
36657 onRender : function(container, position){
36658 var el = document.createElement("a");
36659 el.hideFocus = true;
36660 el.unselectable = "on";
36661 el.href = this.href || "#";
36662 if(this.hrefTarget){
36663 el.target = this.hrefTarget;
36665 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
36667 var html = this.html.length ? this.html : String.format('{0}',this.text);
36669 el.innerHTML = String.format(
36670 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
36671 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
36673 Roo.menu.Item.superclass.onRender.call(this, container, position);
36677 * Sets the text to display in this menu item
36678 * @param {String} text The text to display
36679 * @param {Boolean} isHTML true to indicate text is pure html.
36681 setText : function(text, isHTML){
36689 var html = this.html.length ? this.html : String.format('{0}',this.text);
36691 this.el.update(String.format(
36692 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
36693 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
36694 this.parentMenu.autoWidth();
36699 handleClick : function(e){
36700 if(!this.href){ // if no link defined, stop the event automatically
36703 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
36707 activate : function(autoExpand){
36708 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
36718 shouldDeactivate : function(e){
36719 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
36720 if(this.menu && this.menu.isVisible()){
36721 return !this.menu.getEl().getRegion().contains(e.getPoint());
36729 deactivate : function(){
36730 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
36735 expandMenu : function(autoActivate){
36736 if(!this.disabled && this.menu){
36737 clearTimeout(this.hideTimer);
36738 delete this.hideTimer;
36739 if(!this.menu.isVisible() && !this.showTimer){
36740 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
36741 }else if (this.menu.isVisible() && autoActivate){
36742 this.menu.tryActivate(0, 1);
36748 deferExpand : function(autoActivate){
36749 delete this.showTimer;
36750 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
36752 this.menu.tryActivate(0, 1);
36757 hideMenu : function(){
36758 clearTimeout(this.showTimer);
36759 delete this.showTimer;
36760 if(!this.hideTimer && this.menu && this.menu.isVisible()){
36761 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
36766 deferHide : function(){
36767 delete this.hideTimer;
36772 * Ext JS Library 1.1.1
36773 * Copyright(c) 2006-2007, Ext JS, LLC.
36775 * Originally Released Under LGPL - original licence link has changed is not relivant.
36778 * <script type="text/javascript">
36782 * @class Roo.menu.CheckItem
36783 * @extends Roo.menu.Item
36784 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
36786 * Creates a new CheckItem
36787 * @param {Object} config Configuration options
36789 Roo.menu.CheckItem = function(config){
36790 Roo.menu.CheckItem.superclass.constructor.call(this, config);
36793 * @event beforecheckchange
36794 * Fires before the checked value is set, providing an opportunity to cancel if needed
36795 * @param {Roo.menu.CheckItem} this
36796 * @param {Boolean} checked The new checked value that will be set
36798 "beforecheckchange" : true,
36800 * @event checkchange
36801 * Fires after the checked value has been set
36802 * @param {Roo.menu.CheckItem} this
36803 * @param {Boolean} checked The checked value that was set
36805 "checkchange" : true
36807 if(this.checkHandler){
36808 this.on('checkchange', this.checkHandler, this.scope);
36811 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
36813 * @cfg {String} group
36814 * All check items with the same group name will automatically be grouped into a single-select
36815 * radio button group (defaults to '')
36818 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
36820 itemCls : "x-menu-item x-menu-check-item",
36822 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
36824 groupClass : "x-menu-group-item",
36827 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
36828 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
36829 * initialized with checked = true will be rendered as checked.
36834 ctype: "Roo.menu.CheckItem",
36837 onRender : function(c){
36838 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
36840 this.el.addClass(this.groupClass);
36842 Roo.menu.MenuMgr.registerCheckable(this);
36844 this.checked = false;
36845 this.setChecked(true, true);
36850 destroy : function(){
36852 Roo.menu.MenuMgr.unregisterCheckable(this);
36854 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
36858 * Set the checked state of this item
36859 * @param {Boolean} checked The new checked value
36860 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
36862 setChecked : function(state, suppressEvent){
36863 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
36864 if(this.container){
36865 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
36867 this.checked = state;
36868 if(suppressEvent !== true){
36869 this.fireEvent("checkchange", this, state);
36875 handleClick : function(e){
36876 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
36877 this.setChecked(!this.checked);
36879 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
36883 * Ext JS Library 1.1.1
36884 * Copyright(c) 2006-2007, Ext JS, LLC.
36886 * Originally Released Under LGPL - original licence link has changed is not relivant.
36889 * <script type="text/javascript">
36893 * @class Roo.menu.DateItem
36894 * @extends Roo.menu.Adapter
36895 * A menu item that wraps the {@link Roo.DatPicker} component.
36897 * Creates a new DateItem
36898 * @param {Object} config Configuration options
36900 Roo.menu.DateItem = function(config){
36901 Roo.menu.DateItem.superclass.constructor.call(this, new Roo.DatePicker(config), config);
36902 /** The Roo.DatePicker object @type Roo.DatePicker */
36903 this.picker = this.component;
36904 this.addEvents({select: true});
36906 this.picker.on("render", function(picker){
36907 picker.getEl().swallowEvent("click");
36908 picker.container.addClass("x-menu-date-item");
36911 this.picker.on("select", this.onSelect, this);
36914 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
36916 onSelect : function(picker, date){
36917 this.fireEvent("select", this, date, picker);
36918 Roo.menu.DateItem.superclass.handleClick.call(this);
36922 * Ext JS Library 1.1.1
36923 * Copyright(c) 2006-2007, Ext JS, LLC.
36925 * Originally Released Under LGPL - original licence link has changed is not relivant.
36928 * <script type="text/javascript">
36932 * @class Roo.menu.ColorItem
36933 * @extends Roo.menu.Adapter
36934 * A menu item that wraps the {@link Roo.ColorPalette} component.
36936 * Creates a new ColorItem
36937 * @param {Object} config Configuration options
36939 Roo.menu.ColorItem = function(config){
36940 Roo.menu.ColorItem.superclass.constructor.call(this, new Roo.ColorPalette(config), config);
36941 /** The Roo.ColorPalette object @type Roo.ColorPalette */
36942 this.palette = this.component;
36943 this.relayEvents(this.palette, ["select"]);
36944 if(this.selectHandler){
36945 this.on('select', this.selectHandler, this.scope);
36948 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);/*
36950 * Ext JS Library 1.1.1
36951 * Copyright(c) 2006-2007, Ext JS, LLC.
36953 * Originally Released Under LGPL - original licence link has changed is not relivant.
36956 * <script type="text/javascript">
36961 * @class Roo.menu.DateMenu
36962 * @extends Roo.menu.Menu
36963 * A menu containing a {@link Roo.menu.DateItem} component (which provides a date picker).
36965 * Creates a new DateMenu
36966 * @param {Object} config Configuration options
36968 Roo.menu.DateMenu = function(config){
36969 Roo.menu.DateMenu.superclass.constructor.call(this, config);
36971 var di = new Roo.menu.DateItem(config);
36974 * The {@link Roo.DatePicker} instance for this DateMenu
36977 this.picker = di.picker;
36980 * @param {DatePicker} picker
36981 * @param {Date} date
36983 this.relayEvents(di, ["select"]);
36984 this.on('beforeshow', function(){
36986 this.picker.hideMonthPicker(false);
36990 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
36994 * Ext JS Library 1.1.1
36995 * Copyright(c) 2006-2007, Ext JS, LLC.
36997 * Originally Released Under LGPL - original licence link has changed is not relivant.
37000 * <script type="text/javascript">
37005 * @class Roo.menu.ColorMenu
37006 * @extends Roo.menu.Menu
37007 * A menu containing a {@link Roo.menu.ColorItem} component (which provides a basic color picker).
37009 * Creates a new ColorMenu
37010 * @param {Object} config Configuration options
37012 Roo.menu.ColorMenu = function(config){
37013 Roo.menu.ColorMenu.superclass.constructor.call(this, config);
37015 var ci = new Roo.menu.ColorItem(config);
37018 * The {@link Roo.ColorPalette} instance for this ColorMenu
37019 * @type ColorPalette
37021 this.palette = ci.palette;
37024 * @param {ColorPalette} palette
37025 * @param {String} color
37027 this.relayEvents(ci, ["select"]);
37029 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);/*
37031 * Ext JS Library 1.1.1
37032 * Copyright(c) 2006-2007, Ext JS, LLC.
37034 * Originally Released Under LGPL - original licence link has changed is not relivant.
37037 * <script type="text/javascript">
37041 * @class Roo.form.Field
37042 * @extends Roo.BoxComponent
37043 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
37045 * Creates a new Field
37046 * @param {Object} config Configuration options
37048 Roo.form.Field = function(config){
37049 Roo.form.Field.superclass.constructor.call(this, config);
37052 Roo.extend(Roo.form.Field, Roo.BoxComponent, {
37054 * @cfg {String} fieldLabel Label to use when rendering a form.
37057 * @cfg {String} qtip Mouse over tip
37061 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
37063 invalidClass : "x-form-invalid",
37065 * @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")
37067 invalidText : "The value in this field is invalid",
37069 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
37071 focusClass : "x-form-focus",
37073 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
37074 automatic validation (defaults to "keyup").
37076 validationEvent : "keyup",
37078 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
37080 validateOnBlur : true,
37082 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
37084 validationDelay : 250,
37086 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
37087 * {tag: "input", type: "text", size: "20", autocomplete: "off"})
37089 defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "new-password"},
37091 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field")
37093 fieldClass : "x-form-field",
37095 * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'):
37098 ----------- ----------------------------------------------------------------------
37099 qtip Display a quick tip when the user hovers over the field
37100 title Display a default browser title attribute popup
37101 under Add a block div beneath the field containing the error text
37102 side Add an error icon to the right of the field with a popup on hover
37103 [element id] Add the error text directly to the innerHTML of the specified element
37106 msgTarget : 'qtip',
37108 * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal').
37113 * @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.
37118 * @cfg {Boolean} disabled True to disable the field (defaults to false).
37123 * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password (defaults to "text").
37125 inputType : undefined,
37128 * @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).
37130 tabIndex : undefined,
37133 isFormField : true,
37138 * @property {Roo.Element} fieldEl
37139 * Element Containing the rendered Field (with label etc.)
37142 * @cfg {Mixed} value A value to initialize this field with.
37147 * @cfg {String} name The field's HTML name attribute.
37150 * @cfg {String} cls A CSS class to apply to the field's underlying element.
37154 initComponent : function(){
37155 Roo.form.Field.superclass.initComponent.call(this);
37159 * Fires when this field receives input focus.
37160 * @param {Roo.form.Field} this
37165 * Fires when this field loses input focus.
37166 * @param {Roo.form.Field} this
37170 * @event specialkey
37171 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
37172 * {@link Roo.EventObject#getKey} to determine which key was pressed.
37173 * @param {Roo.form.Field} this
37174 * @param {Roo.EventObject} e The event object
37179 * Fires just before the field blurs if the field value has changed.
37180 * @param {Roo.form.Field} this
37181 * @param {Mixed} newValue The new value
37182 * @param {Mixed} oldValue The original value
37187 * Fires after the field has been marked as invalid.
37188 * @param {Roo.form.Field} this
37189 * @param {String} msg The validation message
37194 * Fires after the field has been validated with no errors.
37195 * @param {Roo.form.Field} this
37200 * Fires after the key up
37201 * @param {Roo.form.Field} this
37202 * @param {Roo.EventObject} e The event Object
37209 * Returns the name attribute of the field if available
37210 * @return {String} name The field name
37212 getName: function(){
37213 return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
37217 onRender : function(ct, position){
37218 Roo.form.Field.superclass.onRender.call(this, ct, position);
37220 var cfg = this.getAutoCreate();
37222 cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
37224 if (!cfg.name.length) {
37227 if(this.inputType){
37228 cfg.type = this.inputType;
37230 this.el = ct.createChild(cfg, position);
37232 var type = this.el.dom.type;
37234 if(type == 'password'){
37237 this.el.addClass('x-form-'+type);
37240 this.el.dom.readOnly = true;
37242 if(this.tabIndex !== undefined){
37243 this.el.dom.setAttribute('tabIndex', this.tabIndex);
37246 this.el.addClass([this.fieldClass, this.cls]);
37251 * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b>
37252 * @param {String/HTMLElement/Element} el The id of the node, a DOM node or an existing Element
37253 * @return {Roo.form.Field} this
37255 applyTo : function(target){
37256 this.allowDomMove = false;
37257 this.el = Roo.get(target);
37258 this.render(this.el.dom.parentNode);
37263 initValue : function(){
37264 if(this.value !== undefined){
37265 this.setValue(this.value);
37266 }else if(this.el.dom.value.length > 0){
37267 this.setValue(this.el.dom.value);
37272 * Returns true if this field has been changed since it was originally loaded and is not disabled.
37274 isDirty : function() {
37275 if(this.disabled) {
37278 return String(this.getValue()) !== String(this.originalValue);
37282 afterRender : function(){
37283 Roo.form.Field.superclass.afterRender.call(this);
37288 fireKey : function(e){
37289 //Roo.log('field ' + e.getKey());
37290 if(e.isNavKeyPress()){
37291 this.fireEvent("specialkey", this, e);
37296 * Resets the current field value to the originally loaded value and clears any validation messages
37298 reset : function(){
37299 this.setValue(this.resetValue);
37300 this.clearInvalid();
37304 initEvents : function(){
37305 // safari killled keypress - so keydown is now used..
37306 this.el.on("keydown" , this.fireKey, this);
37307 this.el.on("focus", this.onFocus, this);
37308 this.el.on("blur", this.onBlur, this);
37309 this.el.relayEvent('keyup', this);
37311 // reference to original value for reset
37312 this.originalValue = this.getValue();
37313 this.resetValue = this.getValue();
37317 onFocus : function(){
37318 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
37319 this.el.addClass(this.focusClass);
37321 if(!this.hasFocus){
37322 this.hasFocus = true;
37323 this.startValue = this.getValue();
37324 this.fireEvent("focus", this);
37328 beforeBlur : Roo.emptyFn,
37331 onBlur : function(){
37333 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
37334 this.el.removeClass(this.focusClass);
37336 this.hasFocus = false;
37337 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
37340 var v = this.getValue();
37341 if(String(v) !== String(this.startValue)){
37342 this.fireEvent('change', this, v, this.startValue);
37344 this.fireEvent("blur", this);
37348 * Returns whether or not the field value is currently valid
37349 * @param {Boolean} preventMark True to disable marking the field invalid
37350 * @return {Boolean} True if the value is valid, else false
37352 isValid : function(preventMark){
37356 var restore = this.preventMark;
37357 this.preventMark = preventMark === true;
37358 var v = this.validateValue(this.processValue(this.getRawValue()));
37359 this.preventMark = restore;
37364 * Validates the field value
37365 * @return {Boolean} True if the value is valid, else false
37367 validate : function(){
37368 if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
37369 this.clearInvalid();
37375 processValue : function(value){
37380 // Subclasses should provide the validation implementation by overriding this
37381 validateValue : function(value){
37386 * Mark this field as invalid
37387 * @param {String} msg The validation message
37389 markInvalid : function(msg){
37390 if(!this.rendered || this.preventMark){ // not rendered
37394 var obj = (typeof(this.combo) != 'undefined') ? this.combo : this; // fix the combox array!!
37396 obj.el.addClass(this.invalidClass);
37397 msg = msg || this.invalidText;
37398 switch(this.msgTarget){
37400 obj.el.dom.qtip = msg;
37401 obj.el.dom.qclass = 'x-form-invalid-tip';
37402 if(Roo.QuickTips){ // fix for floating editors interacting with DND
37403 Roo.QuickTips.enable();
37407 this.el.dom.title = msg;
37411 var elp = this.el.findParent('.x-form-element', 5, true);
37412 this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
37413 this.errorEl.setWidth(elp.getWidth(true)-20);
37415 this.errorEl.update(msg);
37416 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
37419 if(!this.errorIcon){
37420 var elp = this.el.findParent('.x-form-element', 5, true);
37421 this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
37423 this.alignErrorIcon();
37424 this.errorIcon.dom.qtip = msg;
37425 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
37426 this.errorIcon.show();
37427 this.on('resize', this.alignErrorIcon, this);
37430 var t = Roo.getDom(this.msgTarget);
37432 t.style.display = this.msgDisplay;
37435 this.fireEvent('invalid', this, msg);
37439 alignErrorIcon : function(){
37440 this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
37444 * Clear any invalid styles/messages for this field
37446 clearInvalid : function(){
37447 if(!this.rendered || this.preventMark){ // not rendered
37450 var obj = (typeof(this.combo) != 'undefined') ? this.combo : this; // fix the combox array!!
37452 obj.el.removeClass(this.invalidClass);
37453 switch(this.msgTarget){
37455 obj.el.dom.qtip = '';
37458 this.el.dom.title = '';
37462 Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
37466 if(this.errorIcon){
37467 this.errorIcon.dom.qtip = '';
37468 this.errorIcon.hide();
37469 this.un('resize', this.alignErrorIcon, this);
37473 var t = Roo.getDom(this.msgTarget);
37475 t.style.display = 'none';
37478 this.fireEvent('valid', this);
37482 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
37483 * @return {Mixed} value The field value
37485 getRawValue : function(){
37486 var v = this.el.getValue();
37492 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
37493 * @return {Mixed} value The field value
37495 getValue : function(){
37496 var v = this.el.getValue();
37502 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
37503 * @param {Mixed} value The value to set
37505 setRawValue : function(v){
37506 return this.el.dom.value = (v === null || v === undefined ? '' : v);
37510 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
37511 * @param {Mixed} value The value to set
37513 setValue : function(v){
37516 this.el.dom.value = (v === null || v === undefined ? '' : v);
37521 adjustSize : function(w, h){
37522 var s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
37523 s.width = this.adjustWidth(this.el.dom.tagName, s.width);
37527 adjustWidth : function(tag, w){
37528 tag = tag.toLowerCase();
37529 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
37530 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
37531 if(tag == 'input'){
37534 if(tag == 'textarea'){
37537 }else if(Roo.isOpera){
37538 if(tag == 'input'){
37541 if(tag == 'textarea'){
37551 // anything other than normal should be considered experimental
37552 Roo.form.Field.msgFx = {
37554 show: function(msgEl, f){
37555 msgEl.setDisplayed('block');
37558 hide : function(msgEl, f){
37559 msgEl.setDisplayed(false).update('');
37564 show: function(msgEl, f){
37565 msgEl.slideIn('t', {stopFx:true});
37568 hide : function(msgEl, f){
37569 msgEl.slideOut('t', {stopFx:true,useDisplay:true});
37574 show: function(msgEl, f){
37575 msgEl.fixDisplay();
37576 msgEl.alignTo(f.el, 'tl-tr');
37577 msgEl.slideIn('l', {stopFx:true});
37580 hide : function(msgEl, f){
37581 msgEl.slideOut('l', {stopFx:true,useDisplay:true});
37586 * Ext JS Library 1.1.1
37587 * Copyright(c) 2006-2007, Ext JS, LLC.
37589 * Originally Released Under LGPL - original licence link has changed is not relivant.
37592 * <script type="text/javascript">
37597 * @class Roo.form.TextField
37598 * @extends Roo.form.Field
37599 * Basic text field. Can be used as a direct replacement for traditional text inputs, or as the base
37600 * class for more sophisticated input controls (like {@link Roo.form.TextArea} and {@link Roo.form.ComboBox}).
37602 * Creates a new TextField
37603 * @param {Object} config Configuration options
37605 Roo.form.TextField = function(config){
37606 Roo.form.TextField.superclass.constructor.call(this, config);
37610 * Fires when the autosize function is triggered. The field may or may not have actually changed size
37611 * according to the default logic, but this event provides a hook for the developer to apply additional
37612 * logic at runtime to resize the field if needed.
37613 * @param {Roo.form.Field} this This text field
37614 * @param {Number} width The new field width
37620 Roo.extend(Roo.form.TextField, Roo.form.Field, {
37622 * @cfg {Boolean} grow True if this field should automatically grow and shrink to its content
37626 * @cfg {Number} growMin The minimum width to allow when grow = true (defaults to 30)
37630 * @cfg {Number} growMax The maximum width to allow when grow = true (defaults to 800)
37634 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
37638 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
37642 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
37644 disableKeyFilter : false,
37646 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
37650 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
37654 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
37656 maxLength : Number.MAX_VALUE,
37658 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
37660 minLengthText : "The minimum length for this field is {0}",
37662 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
37664 maxLengthText : "The maximum length for this field is {0}",
37666 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
37668 selectOnFocus : false,
37670 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
37672 blankText : "This field is required",
37674 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
37675 * If available, this function will be called only after the basic validators all return true, and will be passed the
37676 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
37680 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
37681 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
37682 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
37686 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
37690 * @cfg {String} emptyText The default text to display in an empty field - placeholder... (defaults to null).
37696 initEvents : function()
37698 if (this.emptyText) {
37699 this.el.attr('placeholder', this.emptyText);
37702 Roo.form.TextField.superclass.initEvents.call(this);
37703 if(this.validationEvent == 'keyup'){
37704 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
37705 this.el.on('keyup', this.filterValidation, this);
37707 else if(this.validationEvent !== false){
37708 this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
37711 if(this.selectOnFocus){
37712 this.on("focus", this.preFocus, this);
37715 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
37716 this.el.on("keypress", this.filterKeys, this);
37719 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
37720 this.el.on("click", this.autoSize, this);
37722 if(this.el.is('input[type=password]') && Roo.isSafari){
37723 this.el.on('keydown', this.SafariOnKeyDown, this);
37727 processValue : function(value){
37728 if(this.stripCharsRe){
37729 var newValue = value.replace(this.stripCharsRe, '');
37730 if(newValue !== value){
37731 this.setRawValue(newValue);
37738 filterValidation : function(e){
37739 if(!e.isNavKeyPress()){
37740 this.validationTask.delay(this.validationDelay);
37745 onKeyUp : function(e){
37746 if(!e.isNavKeyPress()){
37752 * Resets the current field value to the originally-loaded value and clears any validation messages.
37755 reset : function(){
37756 Roo.form.TextField.superclass.reset.call(this);
37762 preFocus : function(){
37764 if(this.selectOnFocus){
37765 this.el.dom.select();
37771 filterKeys : function(e){
37772 var k = e.getKey();
37773 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
37776 var c = e.getCharCode(), cc = String.fromCharCode(c);
37777 if(Roo.isIE && (e.isSpecialKey() || !cc)){
37780 if(!this.maskRe.test(cc)){
37785 setValue : function(v){
37787 Roo.form.TextField.superclass.setValue.apply(this, arguments);
37793 * Validates a value according to the field's validation rules and marks the field as invalid
37794 * if the validation fails
37795 * @param {Mixed} value The value to validate
37796 * @return {Boolean} True if the value is valid, else false
37798 validateValue : function(value){
37799 if(value.length < 1) { // if it's blank
37800 if(this.allowBlank){
37801 this.clearInvalid();
37804 this.markInvalid(this.blankText);
37808 if(value.length < this.minLength){
37809 this.markInvalid(String.format(this.minLengthText, this.minLength));
37812 if(value.length > this.maxLength){
37813 this.markInvalid(String.format(this.maxLengthText, this.maxLength));
37817 var vt = Roo.form.VTypes;
37818 if(!vt[this.vtype](value, this)){
37819 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
37823 if(typeof this.validator == "function"){
37824 var msg = this.validator(value);
37826 this.markInvalid(msg);
37830 if(this.regex && !this.regex.test(value)){
37831 this.markInvalid(this.regexText);
37838 * Selects text in this field
37839 * @param {Number} start (optional) The index where the selection should start (defaults to 0)
37840 * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
37842 selectText : function(start, end){
37843 var v = this.getRawValue();
37845 start = start === undefined ? 0 : start;
37846 end = end === undefined ? v.length : end;
37847 var d = this.el.dom;
37848 if(d.setSelectionRange){
37849 d.setSelectionRange(start, end);
37850 }else if(d.createTextRange){
37851 var range = d.createTextRange();
37852 range.moveStart("character", start);
37853 range.moveEnd("character", v.length-end);
37860 * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
37861 * This only takes effect if grow = true, and fires the autosize event.
37863 autoSize : function(){
37864 if(!this.grow || !this.rendered){
37868 this.metrics = Roo.util.TextMetrics.createInstance(this.el);
37871 var v = el.dom.value;
37872 var d = document.createElement('div');
37873 d.appendChild(document.createTextNode(v));
37877 var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
37878 this.el.setWidth(w);
37879 this.fireEvent("autosize", this, w);
37883 SafariOnKeyDown : function(event)
37885 // this is a workaround for a password hang bug on chrome/ webkit.
37887 var isSelectAll = false;
37889 if(this.el.dom.selectionEnd > 0){
37890 isSelectAll = (this.el.dom.selectionEnd - this.el.dom.selectionStart - this.getValue().length == 0) ? true : false;
37892 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
37893 event.preventDefault();
37898 if(isSelectAll && event.getCharCode() > 31){ // backspace and delete key
37900 event.preventDefault();
37901 // this is very hacky as keydown always get's upper case.
37903 var cc = String.fromCharCode(event.getCharCode());
37906 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
37914 * Ext JS Library 1.1.1
37915 * Copyright(c) 2006-2007, Ext JS, LLC.
37917 * Originally Released Under LGPL - original licence link has changed is not relivant.
37920 * <script type="text/javascript">
37924 * @class Roo.form.Hidden
37925 * @extends Roo.form.TextField
37926 * Simple Hidden element used on forms
37928 * usage: form.add(new Roo.form.HiddenField({ 'name' : 'test1' }));
37931 * Creates a new Hidden form element.
37932 * @param {Object} config Configuration options
37937 // easy hidden field...
37938 Roo.form.Hidden = function(config){
37939 Roo.form.Hidden.superclass.constructor.call(this, config);
37942 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
37944 inputType: 'hidden',
37947 labelSeparator: '',
37949 itemCls : 'x-form-item-display-none'
37957 * Ext JS Library 1.1.1
37958 * Copyright(c) 2006-2007, Ext JS, LLC.
37960 * Originally Released Under LGPL - original licence link has changed is not relivant.
37963 * <script type="text/javascript">
37967 * @class Roo.form.TriggerField
37968 * @extends Roo.form.TextField
37969 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
37970 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
37971 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
37972 * for which you can provide a custom implementation. For example:
37974 var trigger = new Roo.form.TriggerField();
37975 trigger.onTriggerClick = myTriggerFn;
37976 trigger.applyTo('my-field');
37979 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
37980 * {@link Roo.form.DateField} and {@link Roo.form.ComboBox} are perfect examples of this.
37981 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
37982 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
37984 * Create a new TriggerField.
37985 * @param {Object} config Configuration options (valid {@Roo.form.TextField} config options will also be applied
37986 * to the base TextField)
37988 Roo.form.TriggerField = function(config){
37989 this.mimicing = false;
37990 Roo.form.TriggerField.superclass.constructor.call(this, config);
37993 Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
37995 * @cfg {String} triggerClass A CSS class to apply to the trigger
37998 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
37999 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
38001 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "new-password"},
38003 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
38007 /** @cfg {Boolean} grow @hide */
38008 /** @cfg {Number} growMin @hide */
38009 /** @cfg {Number} growMax @hide */
38015 autoSize: Roo.emptyFn,
38019 deferHeight : true,
38022 actionMode : 'wrap',
38024 onResize : function(w, h){
38025 Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
38026 if(typeof w == 'number'){
38027 var x = w - this.trigger.getWidth();
38028 this.el.setWidth(this.adjustWidth('input', x));
38029 this.trigger.setStyle('left', x+'px');
38034 adjustSize : Roo.BoxComponent.prototype.adjustSize,
38037 getResizeEl : function(){
38042 getPositionEl : function(){
38047 alignErrorIcon : function(){
38048 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
38052 onRender : function(ct, position){
38053 Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
38054 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
38055 this.trigger = this.wrap.createChild(this.triggerConfig ||
38056 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
38057 if(this.hideTrigger){
38058 this.trigger.setDisplayed(false);
38060 this.initTrigger();
38062 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
38067 initTrigger : function(){
38068 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
38069 this.trigger.addClassOnOver('x-form-trigger-over');
38070 this.trigger.addClassOnClick('x-form-trigger-click');
38074 onDestroy : function(){
38076 this.trigger.removeAllListeners();
38077 this.trigger.remove();
38080 this.wrap.remove();
38082 Roo.form.TriggerField.superclass.onDestroy.call(this);
38086 onFocus : function(){
38087 Roo.form.TriggerField.superclass.onFocus.call(this);
38088 if(!this.mimicing){
38089 this.wrap.addClass('x-trigger-wrap-focus');
38090 this.mimicing = true;
38091 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
38092 if(this.monitorTab){
38093 this.el.on("keydown", this.checkTab, this);
38099 checkTab : function(e){
38100 if(e.getKey() == e.TAB){
38101 this.triggerBlur();
38106 onBlur : function(){
38111 mimicBlur : function(e, t){
38112 if(!this.wrap.contains(t) && this.validateBlur()){
38113 this.triggerBlur();
38118 triggerBlur : function(){
38119 this.mimicing = false;
38120 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
38121 if(this.monitorTab){
38122 this.el.un("keydown", this.checkTab, this);
38124 this.wrap.removeClass('x-trigger-wrap-focus');
38125 Roo.form.TriggerField.superclass.onBlur.call(this);
38129 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
38130 validateBlur : function(e, t){
38135 onDisable : function(){
38136 Roo.form.TriggerField.superclass.onDisable.call(this);
38138 this.wrap.addClass('x-item-disabled');
38143 onEnable : function(){
38144 Roo.form.TriggerField.superclass.onEnable.call(this);
38146 this.wrap.removeClass('x-item-disabled');
38151 onShow : function(){
38152 var ae = this.getActionEl();
38155 ae.dom.style.display = '';
38156 ae.dom.style.visibility = 'visible';
38162 onHide : function(){
38163 var ae = this.getActionEl();
38164 ae.dom.style.display = 'none';
38168 * The function that should handle the trigger's click event. This method does nothing by default until overridden
38169 * by an implementing function.
38171 * @param {EventObject} e
38173 onTriggerClick : Roo.emptyFn
38176 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
38177 // to be extended by an implementing class. For an example of implementing this class, see the custom
38178 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
38179 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
38180 initComponent : function(){
38181 Roo.form.TwinTriggerField.superclass.initComponent.call(this);
38183 this.triggerConfig = {
38184 tag:'span', cls:'x-form-twin-triggers', cn:[
38185 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
38186 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
38190 getTrigger : function(index){
38191 return this.triggers[index];
38194 initTrigger : function(){
38195 var ts = this.trigger.select('.x-form-trigger', true);
38196 this.wrap.setStyle('overflow', 'hidden');
38197 var triggerField = this;
38198 ts.each(function(t, all, index){
38199 t.hide = function(){
38200 var w = triggerField.wrap.getWidth();
38201 this.dom.style.display = 'none';
38202 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
38204 t.show = function(){
38205 var w = triggerField.wrap.getWidth();
38206 this.dom.style.display = '';
38207 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
38209 var triggerIndex = 'Trigger'+(index+1);
38211 if(this['hide'+triggerIndex]){
38212 t.dom.style.display = 'none';
38214 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
38215 t.addClassOnOver('x-form-trigger-over');
38216 t.addClassOnClick('x-form-trigger-click');
38218 this.triggers = ts.elements;
38221 onTrigger1Click : Roo.emptyFn,
38222 onTrigger2Click : Roo.emptyFn
38225 * Ext JS Library 1.1.1
38226 * Copyright(c) 2006-2007, Ext JS, LLC.
38228 * Originally Released Under LGPL - original licence link has changed is not relivant.
38231 * <script type="text/javascript">
38235 * @class Roo.form.TextArea
38236 * @extends Roo.form.TextField
38237 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
38238 * support for auto-sizing.
38240 * Creates a new TextArea
38241 * @param {Object} config Configuration options
38243 Roo.form.TextArea = function(config){
38244 Roo.form.TextArea.superclass.constructor.call(this, config);
38245 // these are provided exchanges for backwards compat
38246 // minHeight/maxHeight were replaced by growMin/growMax to be
38247 // compatible with TextField growing config values
38248 if(this.minHeight !== undefined){
38249 this.growMin = this.minHeight;
38251 if(this.maxHeight !== undefined){
38252 this.growMax = this.maxHeight;
38256 Roo.extend(Roo.form.TextArea, Roo.form.TextField, {
38258 * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
38262 * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
38266 * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
38267 * in the field (equivalent to setting overflow: hidden, defaults to false)
38269 preventScrollbars: false,
38271 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
38272 * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"})
38276 onRender : function(ct, position){
38278 this.defaultAutoCreate = {
38280 style:"width:300px;height:60px;",
38281 autocomplete: "new-password"
38284 Roo.form.TextArea.superclass.onRender.call(this, ct, position);
38286 this.textSizeEl = Roo.DomHelper.append(document.body, {
38287 tag: "pre", cls: "x-form-grow-sizer"
38289 if(this.preventScrollbars){
38290 this.el.setStyle("overflow", "hidden");
38292 this.el.setHeight(this.growMin);
38296 onDestroy : function(){
38297 if(this.textSizeEl){
38298 this.textSizeEl.parentNode.removeChild(this.textSizeEl);
38300 Roo.form.TextArea.superclass.onDestroy.call(this);
38304 onKeyUp : function(e){
38305 if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
38311 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
38312 * This only takes effect if grow = true, and fires the autosize event if the height changes.
38314 autoSize : function(){
38315 if(!this.grow || !this.textSizeEl){
38319 var v = el.dom.value;
38320 var ts = this.textSizeEl;
38323 ts.appendChild(document.createTextNode(v));
38326 Roo.fly(ts).setWidth(this.el.getWidth());
38328 v = "  ";
38331 v = v.replace(/\n/g, '<p> </p>');
38333 v += " \n ";
38336 var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
38337 if(h != this.lastHeight){
38338 this.lastHeight = h;
38339 this.el.setHeight(h);
38340 this.fireEvent("autosize", this, h);
38345 * Ext JS Library 1.1.1
38346 * Copyright(c) 2006-2007, Ext JS, LLC.
38348 * Originally Released Under LGPL - original licence link has changed is not relivant.
38351 * <script type="text/javascript">
38356 * @class Roo.form.NumberField
38357 * @extends Roo.form.TextField
38358 * Numeric text field that provides automatic keystroke filtering and numeric validation.
38360 * Creates a new NumberField
38361 * @param {Object} config Configuration options
38363 Roo.form.NumberField = function(config){
38364 Roo.form.NumberField.superclass.constructor.call(this, config);
38367 Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
38369 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
38371 fieldClass: "x-form-field x-form-num-field",
38373 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
38375 allowDecimals : true,
38377 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
38379 decimalSeparator : ".",
38381 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
38383 decimalPrecision : 2,
38385 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
38387 allowNegative : true,
38389 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
38391 minValue : Number.NEGATIVE_INFINITY,
38393 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
38395 maxValue : Number.MAX_VALUE,
38397 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
38399 minText : "The minimum value for this field is {0}",
38401 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
38403 maxText : "The maximum value for this field is {0}",
38405 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
38406 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
38408 nanText : "{0} is not a valid number",
38411 initEvents : function(){
38412 Roo.form.NumberField.superclass.initEvents.call(this);
38413 var allowed = "0123456789";
38414 if(this.allowDecimals){
38415 allowed += this.decimalSeparator;
38417 if(this.allowNegative){
38420 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
38421 var keyPress = function(e){
38422 var k = e.getKey();
38423 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
38426 var c = e.getCharCode();
38427 if(allowed.indexOf(String.fromCharCode(c)) === -1){
38431 this.el.on("keypress", keyPress, this);
38435 validateValue : function(value){
38436 if(!Roo.form.NumberField.superclass.validateValue.call(this, value)){
38439 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
38442 var num = this.parseValue(value);
38444 this.markInvalid(String.format(this.nanText, value));
38447 if(num < this.minValue){
38448 this.markInvalid(String.format(this.minText, this.minValue));
38451 if(num > this.maxValue){
38452 this.markInvalid(String.format(this.maxText, this.maxValue));
38458 getValue : function(){
38459 return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
38463 parseValue : function(value){
38464 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
38465 return isNaN(value) ? '' : value;
38469 fixPrecision : function(value){
38470 var nan = isNaN(value);
38471 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
38472 return nan ? '' : value;
38474 return parseFloat(value).toFixed(this.decimalPrecision);
38477 setValue : function(v){
38478 v = this.fixPrecision(v);
38479 Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
38483 decimalPrecisionFcn : function(v){
38484 return Math.floor(v);
38487 beforeBlur : function(){
38488 var v = this.parseValue(this.getRawValue());
38495 * Ext JS Library 1.1.1
38496 * Copyright(c) 2006-2007, Ext JS, LLC.
38498 * Originally Released Under LGPL - original licence link has changed is not relivant.
38501 * <script type="text/javascript">
38505 * @class Roo.form.DateField
38506 * @extends Roo.form.TriggerField
38507 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
38509 * Create a new DateField
38510 * @param {Object} config
38512 Roo.form.DateField = function(config){
38513 Roo.form.DateField.superclass.constructor.call(this, config);
38519 * Fires when a date is selected
38520 * @param {Roo.form.DateField} combo This combo box
38521 * @param {Date} date The date selected
38528 if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
38529 if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
38530 this.ddMatch = null;
38531 if(this.disabledDates){
38532 var dd = this.disabledDates;
38534 for(var i = 0; i < dd.length; i++){
38536 if(i != dd.length-1) re += "|";
38538 this.ddMatch = new RegExp(re + ")");
38542 Roo.extend(Roo.form.DateField, Roo.form.TriggerField, {
38544 * @cfg {String} format
38545 * The default date format string which can be overriden for localization support. The format must be
38546 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
38550 * @cfg {String} altFormats
38551 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
38552 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
38554 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
38556 * @cfg {Array} disabledDays
38557 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
38559 disabledDays : null,
38561 * @cfg {String} disabledDaysText
38562 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
38564 disabledDaysText : "Disabled",
38566 * @cfg {Array} disabledDates
38567 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
38568 * expression so they are very powerful. Some examples:
38570 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
38571 * <li>["03/08", "09/16"] would disable those days for every year</li>
38572 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
38573 * <li>["03/../2006"] would disable every day in March 2006</li>
38574 * <li>["^03"] would disable every day in every March</li>
38576 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
38577 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
38579 disabledDates : null,
38581 * @cfg {String} disabledDatesText
38582 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
38584 disabledDatesText : "Disabled",
38586 * @cfg {Date/String} minValue
38587 * The minimum allowed date. Can be either a Javascript date object or a string date in a
38588 * valid format (defaults to null).
38592 * @cfg {Date/String} maxValue
38593 * The maximum allowed date. Can be either a Javascript date object or a string date in a
38594 * valid format (defaults to null).
38598 * @cfg {String} minText
38599 * The error text to display when the date in the cell is before minValue (defaults to
38600 * 'The date in this field must be after {minValue}').
38602 minText : "The date in this field must be equal to or after {0}",
38604 * @cfg {String} maxText
38605 * The error text to display when the date in the cell is after maxValue (defaults to
38606 * 'The date in this field must be before {maxValue}').
38608 maxText : "The date in this field must be equal to or before {0}",
38610 * @cfg {String} invalidText
38611 * The error text to display when the date in the field is invalid (defaults to
38612 * '{value} is not a valid date - it must be in the format {format}').
38614 invalidText : "{0} is not a valid date - it must be in the format {1}",
38616 * @cfg {String} triggerClass
38617 * An additional CSS class used to style the trigger button. The trigger will always get the
38618 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
38619 * which displays a calendar icon).
38621 triggerClass : 'x-form-date-trigger',
38625 * @cfg {Boolean} useIso
38626 * if enabled, then the date field will use a hidden field to store the
38627 * real value as iso formated date. default (false)
38631 * @cfg {String/Object} autoCreate
38632 * A DomHelper element spec, or true for a default element spec (defaults to
38633 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
38636 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
38639 hiddenField: false,
38641 onRender : function(ct, position)
38643 Roo.form.DateField.superclass.onRender.call(this, ct, position);
38645 //this.el.dom.removeAttribute('name');
38646 Roo.log("Changing name?");
38647 this.el.dom.setAttribute('name', this.name + '____hidden___' );
38648 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
38650 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
38651 // prevent input submission
38652 this.hiddenName = this.name;
38659 validateValue : function(value)
38661 value = this.formatDate(value);
38662 if(!Roo.form.DateField.superclass.validateValue.call(this, value)){
38663 Roo.log('super failed');
38666 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
38669 var svalue = value;
38670 value = this.parseDate(value);
38672 Roo.log('parse date failed' + svalue);
38673 this.markInvalid(String.format(this.invalidText, svalue, this.format));
38676 var time = value.getTime();
38677 if(this.minValue && time < this.minValue.getTime()){
38678 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
38681 if(this.maxValue && time > this.maxValue.getTime()){
38682 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
38685 if(this.disabledDays){
38686 var day = value.getDay();
38687 for(var i = 0; i < this.disabledDays.length; i++) {
38688 if(day === this.disabledDays[i]){
38689 this.markInvalid(this.disabledDaysText);
38694 var fvalue = this.formatDate(value);
38695 if(this.ddMatch && this.ddMatch.test(fvalue)){
38696 this.markInvalid(String.format(this.disabledDatesText, fvalue));
38703 // Provides logic to override the default TriggerField.validateBlur which just returns true
38704 validateBlur : function(){
38705 return !this.menu || !this.menu.isVisible();
38708 getName: function()
38710 // returns hidden if it's set..
38711 if (!this.rendered) {return ''};
38712 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
38717 * Returns the current date value of the date field.
38718 * @return {Date} The date value
38720 getValue : function(){
38722 return this.hiddenField ?
38723 this.hiddenField.value :
38724 this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
38728 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
38729 * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}
38730 * (the default format used is "m/d/y").
38733 //All of these calls set the same date value (May 4, 2006)
38735 //Pass a date object:
38736 var dt = new Date('5/4/06');
38737 dateField.setValue(dt);
38739 //Pass a date string (default format):
38740 dateField.setValue('5/4/06');
38742 //Pass a date string (custom format):
38743 dateField.format = 'Y-m-d';
38744 dateField.setValue('2006-5-4');
38746 * @param {String/Date} date The date or valid date string
38748 setValue : function(date){
38749 if (this.hiddenField) {
38750 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
38752 Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
38753 // make sure the value field is always stored as a date..
38754 this.value = this.parseDate(date);
38760 parseDate : function(value){
38761 if(!value || value instanceof Date){
38764 var v = Date.parseDate(value, this.format);
38765 if (!v && this.useIso) {
38766 v = Date.parseDate(value, 'Y-m-d');
38768 if(!v && this.altFormats){
38769 if(!this.altFormatsArray){
38770 this.altFormatsArray = this.altFormats.split("|");
38772 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
38773 v = Date.parseDate(value, this.altFormatsArray[i]);
38780 formatDate : function(date, fmt){
38781 return (!date || !(date instanceof Date)) ?
38782 date : date.dateFormat(fmt || this.format);
38787 select: function(m, d){
38790 this.fireEvent('select', this, d);
38792 show : function(){ // retain focus styling
38796 this.focus.defer(10, this);
38797 var ml = this.menuListeners;
38798 this.menu.un("select", ml.select, this);
38799 this.menu.un("show", ml.show, this);
38800 this.menu.un("hide", ml.hide, this);
38805 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
38806 onTriggerClick : function(){
38810 if(this.menu == null){
38811 this.menu = new Roo.menu.DateMenu();
38813 Roo.apply(this.menu.picker, {
38814 showClear: this.allowBlank,
38815 minDate : this.minValue,
38816 maxDate : this.maxValue,
38817 disabledDatesRE : this.ddMatch,
38818 disabledDatesText : this.disabledDatesText,
38819 disabledDays : this.disabledDays,
38820 disabledDaysText : this.disabledDaysText,
38821 format : this.useIso ? 'Y-m-d' : this.format,
38822 minText : String.format(this.minText, this.formatDate(this.minValue)),
38823 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
38825 this.menu.on(Roo.apply({}, this.menuListeners, {
38828 this.menu.picker.setValue(this.getValue() || new Date());
38829 this.menu.show(this.el, "tl-bl?");
38832 beforeBlur : function(){
38833 var v = this.parseDate(this.getRawValue());
38843 isDirty : function() {
38844 if(this.disabled) {
38848 if(typeof(this.startValue) === 'undefined'){
38852 return String(this.getValue()) !== String(this.startValue);
38857 * Ext JS Library 1.1.1
38858 * Copyright(c) 2006-2007, Ext JS, LLC.
38860 * Originally Released Under LGPL - original licence link has changed is not relivant.
38863 * <script type="text/javascript">
38867 * @class Roo.form.MonthField
38868 * @extends Roo.form.TriggerField
38869 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
38871 * Create a new MonthField
38872 * @param {Object} config
38874 Roo.form.MonthField = function(config){
38876 Roo.form.MonthField.superclass.constructor.call(this, config);
38882 * Fires when a date is selected
38883 * @param {Roo.form.MonthFieeld} combo This combo box
38884 * @param {Date} date The date selected
38891 if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
38892 if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
38893 this.ddMatch = null;
38894 if(this.disabledDates){
38895 var dd = this.disabledDates;
38897 for(var i = 0; i < dd.length; i++){
38899 if(i != dd.length-1) re += "|";
38901 this.ddMatch = new RegExp(re + ")");
38905 Roo.extend(Roo.form.MonthField, Roo.form.TriggerField, {
38907 * @cfg {String} format
38908 * The default date format string which can be overriden for localization support. The format must be
38909 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
38913 * @cfg {String} altFormats
38914 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
38915 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
38917 altFormats : "M Y|m/Y|m-y|m-Y|my|mY",
38919 * @cfg {Array} disabledDays
38920 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
38922 disabledDays : [0,1,2,3,4,5,6],
38924 * @cfg {String} disabledDaysText
38925 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
38927 disabledDaysText : "Disabled",
38929 * @cfg {Array} disabledDates
38930 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
38931 * expression so they are very powerful. Some examples:
38933 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
38934 * <li>["03/08", "09/16"] would disable those days for every year</li>
38935 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
38936 * <li>["03/../2006"] would disable every day in March 2006</li>
38937 * <li>["^03"] would disable every day in every March</li>
38939 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
38940 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
38942 disabledDates : null,
38944 * @cfg {String} disabledDatesText
38945 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
38947 disabledDatesText : "Disabled",
38949 * @cfg {Date/String} minValue
38950 * The minimum allowed date. Can be either a Javascript date object or a string date in a
38951 * valid format (defaults to null).
38955 * @cfg {Date/String} maxValue
38956 * The maximum allowed date. Can be either a Javascript date object or a string date in a
38957 * valid format (defaults to null).
38961 * @cfg {String} minText
38962 * The error text to display when the date in the cell is before minValue (defaults to
38963 * 'The date in this field must be after {minValue}').
38965 minText : "The date in this field must be equal to or after {0}",
38967 * @cfg {String} maxTextf
38968 * The error text to display when the date in the cell is after maxValue (defaults to
38969 * 'The date in this field must be before {maxValue}').
38971 maxText : "The date in this field must be equal to or before {0}",
38973 * @cfg {String} invalidText
38974 * The error text to display when the date in the field is invalid (defaults to
38975 * '{value} is not a valid date - it must be in the format {format}').
38977 invalidText : "{0} is not a valid date - it must be in the format {1}",
38979 * @cfg {String} triggerClass
38980 * An additional CSS class used to style the trigger button. The trigger will always get the
38981 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
38982 * which displays a calendar icon).
38984 triggerClass : 'x-form-date-trigger',
38988 * @cfg {Boolean} useIso
38989 * if enabled, then the date field will use a hidden field to store the
38990 * real value as iso formated date. default (true)
38994 * @cfg {String/Object} autoCreate
38995 * A DomHelper element spec, or true for a default element spec (defaults to
38996 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
38999 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "new-password"},
39002 hiddenField: false,
39004 hideMonthPicker : false,
39006 onRender : function(ct, position)
39008 Roo.form.MonthField.superclass.onRender.call(this, ct, position);
39010 this.el.dom.removeAttribute('name');
39011 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
39013 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
39014 // prevent input submission
39015 this.hiddenName = this.name;
39022 validateValue : function(value)
39024 value = this.formatDate(value);
39025 if(!Roo.form.MonthField.superclass.validateValue.call(this, value)){
39028 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
39031 var svalue = value;
39032 value = this.parseDate(value);
39034 this.markInvalid(String.format(this.invalidText, svalue, this.format));
39037 var time = value.getTime();
39038 if(this.minValue && time < this.minValue.getTime()){
39039 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
39042 if(this.maxValue && time > this.maxValue.getTime()){
39043 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
39046 /*if(this.disabledDays){
39047 var day = value.getDay();
39048 for(var i = 0; i < this.disabledDays.length; i++) {
39049 if(day === this.disabledDays[i]){
39050 this.markInvalid(this.disabledDaysText);
39056 var fvalue = this.formatDate(value);
39057 /*if(this.ddMatch && this.ddMatch.test(fvalue)){
39058 this.markInvalid(String.format(this.disabledDatesText, fvalue));
39066 // Provides logic to override the default TriggerField.validateBlur which just returns true
39067 validateBlur : function(){
39068 return !this.menu || !this.menu.isVisible();
39072 * Returns the current date value of the date field.
39073 * @return {Date} The date value
39075 getValue : function(){
39079 return this.hiddenField ?
39080 this.hiddenField.value :
39081 this.parseDate(Roo.form.MonthField.superclass.getValue.call(this)) || "";
39085 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
39086 * date, using MonthField.format as the date format, according to the same rules as {@link Date#parseDate}
39087 * (the default format used is "m/d/y").
39090 //All of these calls set the same date value (May 4, 2006)
39092 //Pass a date object:
39093 var dt = new Date('5/4/06');
39094 monthField.setValue(dt);
39096 //Pass a date string (default format):
39097 monthField.setValue('5/4/06');
39099 //Pass a date string (custom format):
39100 monthField.format = 'Y-m-d';
39101 monthField.setValue('2006-5-4');
39103 * @param {String/Date} date The date or valid date string
39105 setValue : function(date){
39106 Roo.log('month setValue' + date);
39107 // can only be first of month..
39109 var val = this.parseDate(date);
39111 if (this.hiddenField) {
39112 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
39114 Roo.form.MonthField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
39115 this.value = this.parseDate(date);
39119 parseDate : function(value){
39120 if(!value || value instanceof Date){
39121 value = value ? Date.parseDate(value.format('Y-m') + '-01', 'Y-m-d') : null;
39124 var v = Date.parseDate(value, this.format);
39125 if (!v && this.useIso) {
39126 v = Date.parseDate(value, 'Y-m-d');
39130 v = Date.parseDate(v.format('Y-m') +'-01', 'Y-m-d');
39134 if(!v && this.altFormats){
39135 if(!this.altFormatsArray){
39136 this.altFormatsArray = this.altFormats.split("|");
39138 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
39139 v = Date.parseDate(value, this.altFormatsArray[i]);
39146 formatDate : function(date, fmt){
39147 return (!date || !(date instanceof Date)) ?
39148 date : date.dateFormat(fmt || this.format);
39153 select: function(m, d){
39155 this.fireEvent('select', this, d);
39157 show : function(){ // retain focus styling
39161 this.focus.defer(10, this);
39162 var ml = this.menuListeners;
39163 this.menu.un("select", ml.select, this);
39164 this.menu.un("show", ml.show, this);
39165 this.menu.un("hide", ml.hide, this);
39169 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
39170 onTriggerClick : function(){
39174 if(this.menu == null){
39175 this.menu = new Roo.menu.DateMenu();
39179 Roo.apply(this.menu.picker, {
39181 showClear: this.allowBlank,
39182 minDate : this.minValue,
39183 maxDate : this.maxValue,
39184 disabledDatesRE : this.ddMatch,
39185 disabledDatesText : this.disabledDatesText,
39187 format : this.useIso ? 'Y-m-d' : this.format,
39188 minText : String.format(this.minText, this.formatDate(this.minValue)),
39189 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
39192 this.menu.on(Roo.apply({}, this.menuListeners, {
39200 // hide month picker get's called when we called by 'before hide';
39202 var ignorehide = true;
39203 p.hideMonthPicker = function(disableAnim){
39207 if(this.monthPicker){
39208 Roo.log("hideMonthPicker called");
39209 if(disableAnim === true){
39210 this.monthPicker.hide();
39212 this.monthPicker.slideOut('t', {duration:.2});
39213 p.setValue(new Date(m.picker.mpSelYear, m.picker.mpSelMonth, 1));
39214 p.fireEvent("select", this, this.value);
39220 Roo.log('picker set value');
39221 Roo.log(this.getValue());
39222 p.setValue(this.getValue() ? this.parseDate(this.getValue()) : new Date());
39223 m.show(this.el, 'tl-bl?');
39224 ignorehide = false;
39225 // this will trigger hideMonthPicker..
39228 // hidden the day picker
39229 Roo.select('.x-date-picker table', true).first().dom.style.visibility = "hidden";
39235 p.showMonthPicker.defer(100, p);
39241 beforeBlur : function(){
39242 var v = this.parseDate(this.getRawValue());
39248 /** @cfg {Boolean} grow @hide */
39249 /** @cfg {Number} growMin @hide */
39250 /** @cfg {Number} growMax @hide */
39257 * Ext JS Library 1.1.1
39258 * Copyright(c) 2006-2007, Ext JS, LLC.
39260 * Originally Released Under LGPL - original licence link has changed is not relivant.
39263 * <script type="text/javascript">
39268 * @class Roo.form.ComboBox
39269 * @extends Roo.form.TriggerField
39270 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
39272 * Create a new ComboBox.
39273 * @param {Object} config Configuration options
39275 Roo.form.ComboBox = function(config){
39276 Roo.form.ComboBox.superclass.constructor.call(this, config);
39280 * Fires when the dropdown list is expanded
39281 * @param {Roo.form.ComboBox} combo This combo box
39286 * Fires when the dropdown list is collapsed
39287 * @param {Roo.form.ComboBox} combo This combo box
39291 * @event beforeselect
39292 * Fires before a list item is selected. Return false to cancel the selection.
39293 * @param {Roo.form.ComboBox} combo This combo box
39294 * @param {Roo.data.Record} record The data record returned from the underlying store
39295 * @param {Number} index The index of the selected item in the dropdown list
39297 'beforeselect' : true,
39300 * Fires when a list item is selected
39301 * @param {Roo.form.ComboBox} combo This combo box
39302 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
39303 * @param {Number} index The index of the selected item in the dropdown list
39307 * @event beforequery
39308 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
39309 * The event object passed has these properties:
39310 * @param {Roo.form.ComboBox} combo This combo box
39311 * @param {String} query The query
39312 * @param {Boolean} forceAll true to force "all" query
39313 * @param {Boolean} cancel true to cancel the query
39314 * @param {Object} e The query event object
39316 'beforequery': true,
39319 * Fires when the 'add' icon is pressed (add a listener to enable add button)
39320 * @param {Roo.form.ComboBox} combo This combo box
39325 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
39326 * @param {Roo.form.ComboBox} combo This combo box
39327 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
39333 if(this.transform){
39334 this.allowDomMove = false;
39335 var s = Roo.getDom(this.transform);
39336 if(!this.hiddenName){
39337 this.hiddenName = s.name;
39340 this.mode = 'local';
39341 var d = [], opts = s.options;
39342 for(var i = 0, len = opts.length;i < len; i++){
39344 var value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
39346 this.value = value;
39348 d.push([value, o.text]);
39350 this.store = new Roo.data.SimpleStore({
39352 fields: ['value', 'text'],
39355 this.valueField = 'value';
39356 this.displayField = 'text';
39358 s.name = Roo.id(); // wipe out the name in case somewhere else they have a reference
39359 if(!this.lazyRender){
39360 this.target = true;
39361 this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
39362 s.parentNode.removeChild(s); // remove it
39363 this.render(this.el.parentNode);
39365 s.parentNode.removeChild(s); // remove it
39370 this.store = Roo.factory(this.store, Roo.data);
39373 this.selectedIndex = -1;
39374 if(this.mode == 'local'){
39375 if(config.queryDelay === undefined){
39376 this.queryDelay = 10;
39378 if(config.minChars === undefined){
39384 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
39386 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
39389 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
39390 * rendering into an Roo.Editor, defaults to false)
39393 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
39394 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
39397 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
39400 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
39401 * the dropdown list (defaults to undefined, with no header element)
39405 * @cfg {String/Roo.Template} tpl The template to use to render the output
39409 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
39411 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
39413 listWidth: undefined,
39415 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
39416 * mode = 'remote' or 'text' if mode = 'local')
39418 displayField: undefined,
39420 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
39421 * mode = 'remote' or 'value' if mode = 'local').
39422 * Note: use of a valueField requires the user make a selection
39423 * in order for a value to be mapped.
39425 valueField: undefined,
39429 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
39430 * field's data value (defaults to the underlying DOM element's name)
39432 hiddenName: undefined,
39434 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
39438 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
39440 selectedClass: 'x-combo-selected',
39442 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
39443 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
39444 * which displays a downward arrow icon).
39446 triggerClass : 'x-form-arrow-trigger',
39448 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
39452 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
39453 * anchor positions (defaults to 'tl-bl')
39455 listAlign: 'tl-bl?',
39457 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
39461 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
39462 * query specified by the allQuery config option (defaults to 'query')
39464 triggerAction: 'query',
39466 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
39467 * (defaults to 4, does not apply if editable = false)
39471 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
39472 * delay (typeAheadDelay) if it matches a known value (defaults to false)
39476 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
39477 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
39481 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
39482 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
39486 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
39487 * when editable = true (defaults to false)
39489 selectOnFocus:false,
39491 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
39493 queryParam: 'query',
39495 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
39496 * when mode = 'remote' (defaults to 'Loading...')
39498 loadingText: 'Loading...',
39500 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
39504 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
39508 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
39509 * traditional select (defaults to true)
39513 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
39517 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
39521 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
39522 * listWidth has a higher value)
39526 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
39527 * allow the user to set arbitrary text into the field (defaults to false)
39529 forceSelection:false,
39531 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
39532 * if typeAhead = true (defaults to 250)
39534 typeAheadDelay : 250,
39536 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
39537 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
39539 valueNotFoundText : undefined,
39541 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
39543 blockFocus : false,
39546 * @cfg {Boolean} disableClear Disable showing of clear button.
39548 disableClear : false,
39550 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
39552 alwaysQuery : false,
39558 // element that contains real text value.. (when hidden is used..)
39561 onRender : function(ct, position){
39562 Roo.form.ComboBox.superclass.onRender.call(this, ct, position);
39563 if(this.hiddenName){
39564 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
39566 this.hiddenField.value =
39567 this.hiddenValue !== undefined ? this.hiddenValue :
39568 this.value !== undefined ? this.value : '';
39570 // prevent input submission
39571 this.el.dom.removeAttribute('name');
39576 this.el.dom.setAttribute('autocomplete', 'off');
39579 var cls = 'x-combo-list';
39581 this.list = new Roo.Layer({
39582 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
39585 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
39586 this.list.setWidth(lw);
39587 this.list.swallowEvent('mousewheel');
39588 this.assetHeight = 0;
39591 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
39592 this.assetHeight += this.header.getHeight();
39595 this.innerList = this.list.createChild({cls:cls+'-inner'});
39596 this.innerList.on('mouseover', this.onViewOver, this);
39597 this.innerList.on('mousemove', this.onViewMove, this);
39598 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
39600 if(this.allowBlank && !this.pageSize && !this.disableClear){
39601 this.footer = this.list.createChild({cls:cls+'-ft'});
39602 this.pageTb = new Roo.Toolbar(this.footer);
39606 this.footer = this.list.createChild({cls:cls+'-ft'});
39607 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
39608 {pageSize: this.pageSize});
39612 if (this.pageTb && this.allowBlank && !this.disableClear) {
39614 this.pageTb.add(new Roo.Toolbar.Fill(), {
39615 cls: 'x-btn-icon x-btn-clear',
39617 handler: function()
39620 _this.clearValue();
39621 _this.onSelect(false, -1);
39626 this.assetHeight += this.footer.getHeight();
39631 this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
39634 this.view = new Roo.View(this.innerList, this.tpl, {
39635 singleSelect:true, store: this.store, selectedClass: this.selectedClass
39638 this.view.on('click', this.onViewClick, this);
39640 this.store.on('beforeload', this.onBeforeLoad, this);
39641 this.store.on('load', this.onLoad, this);
39642 this.store.on('loadexception', this.onLoadException, this);
39644 if(this.resizable){
39645 this.resizer = new Roo.Resizable(this.list, {
39646 pinned:true, handles:'se'
39648 this.resizer.on('resize', function(r, w, h){
39649 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
39650 this.listWidth = w;
39651 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
39652 this.restrictHeight();
39654 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
39656 if(!this.editable){
39657 this.editable = true;
39658 this.setEditable(false);
39662 if (typeof(this.events.add.listeners) != 'undefined') {
39664 this.addicon = this.wrap.createChild(
39665 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
39667 this.addicon.on('click', function(e) {
39668 this.fireEvent('add', this);
39671 if (typeof(this.events.edit.listeners) != 'undefined') {
39673 this.editicon = this.wrap.createChild(
39674 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
39675 if (this.addicon) {
39676 this.editicon.setStyle('margin-left', '40px');
39678 this.editicon.on('click', function(e) {
39680 // we fire even if inothing is selected..
39681 this.fireEvent('edit', this, this.lastData );
39691 initEvents : function(){
39692 Roo.form.ComboBox.superclass.initEvents.call(this);
39694 this.keyNav = new Roo.KeyNav(this.el, {
39695 "up" : function(e){
39696 this.inKeyMode = true;
39700 "down" : function(e){
39701 if(!this.isExpanded()){
39702 this.onTriggerClick();
39704 this.inKeyMode = true;
39709 "enter" : function(e){
39710 this.onViewClick();
39714 "esc" : function(e){
39718 "tab" : function(e){
39719 this.onViewClick(false);
39720 this.fireEvent("specialkey", this, e);
39726 doRelay : function(foo, bar, hname){
39727 if(hname == 'down' || this.scope.isExpanded()){
39728 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
39735 this.queryDelay = Math.max(this.queryDelay || 10,
39736 this.mode == 'local' ? 10 : 250);
39737 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
39738 if(this.typeAhead){
39739 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
39741 if(this.editable !== false){
39742 this.el.on("keyup", this.onKeyUp, this);
39744 if(this.forceSelection){
39745 this.on('blur', this.doForce, this);
39749 onDestroy : function(){
39751 this.view.setStore(null);
39752 this.view.el.removeAllListeners();
39753 this.view.el.remove();
39754 this.view.purgeListeners();
39757 this.list.destroy();
39760 this.store.un('beforeload', this.onBeforeLoad, this);
39761 this.store.un('load', this.onLoad, this);
39762 this.store.un('loadexception', this.onLoadException, this);
39764 Roo.form.ComboBox.superclass.onDestroy.call(this);
39768 fireKey : function(e){
39769 if(e.isNavKeyPress() && !this.list.isVisible()){
39770 this.fireEvent("specialkey", this, e);
39775 onResize: function(w, h){
39776 Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
39778 if(typeof w != 'number'){
39779 // we do not handle it!?!?
39782 var tw = this.trigger.getWidth();
39783 tw += this.addicon ? this.addicon.getWidth() : 0;
39784 tw += this.editicon ? this.editicon.getWidth() : 0;
39786 this.el.setWidth( this.adjustWidth('input', x));
39788 this.trigger.setStyle('left', x+'px');
39790 if(this.list && this.listWidth === undefined){
39791 var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
39792 this.list.setWidth(lw);
39793 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
39801 * Allow or prevent the user from directly editing the field text. If false is passed,
39802 * the user will only be able to select from the items defined in the dropdown list. This method
39803 * is the runtime equivalent of setting the 'editable' config option at config time.
39804 * @param {Boolean} value True to allow the user to directly edit the field text
39806 setEditable : function(value){
39807 if(value == this.editable){
39810 this.editable = value;
39812 this.el.dom.setAttribute('readOnly', true);
39813 this.el.on('mousedown', this.onTriggerClick, this);
39814 this.el.addClass('x-combo-noedit');
39816 this.el.dom.setAttribute('readOnly', false);
39817 this.el.un('mousedown', this.onTriggerClick, this);
39818 this.el.removeClass('x-combo-noedit');
39823 onBeforeLoad : function(){
39824 if(!this.hasFocus){
39827 this.innerList.update(this.loadingText ?
39828 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
39829 this.restrictHeight();
39830 this.selectedIndex = -1;
39834 onLoad : function(){
39835 if(!this.hasFocus){
39838 if(this.store.getCount() > 0){
39840 this.restrictHeight();
39841 if(this.lastQuery == this.allQuery){
39843 this.el.dom.select();
39845 if(!this.selectByValue(this.value, true)){
39846 this.select(0, true);
39850 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
39851 this.taTask.delay(this.typeAheadDelay);
39855 this.onEmptyResults();
39860 onLoadException : function()
39863 Roo.log(this.store.reader.jsonData);
39864 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
39865 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
39871 onTypeAhead : function(){
39872 if(this.store.getCount() > 0){
39873 var r = this.store.getAt(0);
39874 var newValue = r.data[this.displayField];
39875 var len = newValue.length;
39876 var selStart = this.getRawValue().length;
39877 if(selStart != len){
39878 this.setRawValue(newValue);
39879 this.selectText(selStart, newValue.length);
39885 onSelect : function(record, index){
39886 if(this.fireEvent('beforeselect', this, record, index) !== false){
39887 this.setFromData(index > -1 ? record.data : false);
39889 this.fireEvent('select', this, record, index);
39894 * Returns the currently selected field value or empty string if no value is set.
39895 * @return {String} value The selected value
39897 getValue : function(){
39898 if(this.valueField){
39899 return typeof this.value != 'undefined' ? this.value : '';
39901 return Roo.form.ComboBox.superclass.getValue.call(this);
39905 * Clears any text/value currently set in the field
39907 clearValue : function(){
39908 if(this.hiddenField){
39909 this.hiddenField.value = '';
39912 this.setRawValue('');
39913 this.lastSelectionText = '';
39918 * Sets the specified value into the field. If the value finds a match, the corresponding record text
39919 * will be displayed in the field. If the value does not match the data value of an existing item,
39920 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
39921 * Otherwise the field will be blank (although the value will still be set).
39922 * @param {String} value The value to match
39924 setValue : function(v){
39926 if(this.valueField){
39927 var r = this.findRecord(this.valueField, v);
39929 text = r.data[this.displayField];
39930 }else if(this.valueNotFoundText !== undefined){
39931 text = this.valueNotFoundText;
39934 this.lastSelectionText = text;
39935 if(this.hiddenField){
39936 this.hiddenField.value = v;
39938 Roo.form.ComboBox.superclass.setValue.call(this, text);
39942 * @property {Object} the last set data for the element
39947 * Sets the value of the field based on a object which is related to the record format for the store.
39948 * @param {Object} value the value to set as. or false on reset?
39950 setFromData : function(o){
39951 var dv = ''; // display value
39952 var vv = ''; // value value..
39954 if (this.displayField) {
39955 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
39957 // this is an error condition!!!
39958 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
39961 if(this.valueField){
39962 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
39964 if(this.hiddenField){
39965 this.hiddenField.value = vv;
39967 this.lastSelectionText = dv;
39968 Roo.form.ComboBox.superclass.setValue.call(this, dv);
39972 // no hidden field.. - we store the value in 'value', but still display
39973 // display field!!!!
39974 this.lastSelectionText = dv;
39975 Roo.form.ComboBox.superclass.setValue.call(this, dv);
39981 reset : function(){
39982 // overridden so that last data is reset..
39983 this.setValue(this.resetValue);
39984 this.clearInvalid();
39985 this.lastData = false;
39987 this.view.clearSelections();
39991 findRecord : function(prop, value){
39993 if(this.store.getCount() > 0){
39994 this.store.each(function(r){
39995 if(r.data[prop] == value){
40005 getName: function()
40007 // returns hidden if it's set..
40008 if (!this.rendered) {return ''};
40009 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
40013 onViewMove : function(e, t){
40014 this.inKeyMode = false;
40018 onViewOver : function(e, t){
40019 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
40022 var item = this.view.findItemFromChild(t);
40024 var index = this.view.indexOf(item);
40025 this.select(index, false);
40030 onViewClick : function(doFocus)
40032 var index = this.view.getSelectedIndexes()[0];
40033 var r = this.store.getAt(index);
40035 this.onSelect(r, index);
40037 if(doFocus !== false && !this.blockFocus){
40043 restrictHeight : function(){
40044 this.innerList.dom.style.height = '';
40045 var inner = this.innerList.dom;
40046 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
40047 this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
40048 this.list.beginUpdate();
40049 this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
40050 this.list.alignTo(this.el, this.listAlign);
40051 this.list.endUpdate();
40055 onEmptyResults : function(){
40060 * Returns true if the dropdown list is expanded, else false.
40062 isExpanded : function(){
40063 return this.list.isVisible();
40067 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
40068 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
40069 * @param {String} value The data value of the item to select
40070 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
40071 * selected item if it is not currently in view (defaults to true)
40072 * @return {Boolean} True if the value matched an item in the list, else false
40074 selectByValue : function(v, scrollIntoView){
40075 if(v !== undefined && v !== null){
40076 var r = this.findRecord(this.valueField || this.displayField, v);
40078 this.select(this.store.indexOf(r), scrollIntoView);
40086 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
40087 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
40088 * @param {Number} index The zero-based index of the list item to select
40089 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
40090 * selected item if it is not currently in view (defaults to true)
40092 select : function(index, scrollIntoView){
40093 this.selectedIndex = index;
40094 this.view.select(index);
40095 if(scrollIntoView !== false){
40096 var el = this.view.getNode(index);
40098 this.innerList.scrollChildIntoView(el, false);
40104 selectNext : function(){
40105 var ct = this.store.getCount();
40107 if(this.selectedIndex == -1){
40109 }else if(this.selectedIndex < ct-1){
40110 this.select(this.selectedIndex+1);
40116 selectPrev : function(){
40117 var ct = this.store.getCount();
40119 if(this.selectedIndex == -1){
40121 }else if(this.selectedIndex != 0){
40122 this.select(this.selectedIndex-1);
40128 onKeyUp : function(e){
40129 if(this.editable !== false && !e.isSpecialKey()){
40130 this.lastKey = e.getKey();
40131 this.dqTask.delay(this.queryDelay);
40136 validateBlur : function(){
40137 return !this.list || !this.list.isVisible();
40141 initQuery : function(){
40142 this.doQuery(this.getRawValue());
40146 doForce : function(){
40147 if(this.el.dom.value.length > 0){
40148 this.el.dom.value =
40149 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
40155 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
40156 * query allowing the query action to be canceled if needed.
40157 * @param {String} query The SQL query to execute
40158 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
40159 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
40160 * saved in the current store (defaults to false)
40162 doQuery : function(q, forceAll){
40163 if(q === undefined || q === null){
40168 forceAll: forceAll,
40172 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
40176 forceAll = qe.forceAll;
40177 if(forceAll === true || (q.length >= this.minChars)){
40178 if(this.lastQuery != q || this.alwaysQuery){
40179 this.lastQuery = q;
40180 if(this.mode == 'local'){
40181 this.selectedIndex = -1;
40183 this.store.clearFilter();
40185 this.store.filter(this.displayField, q);
40189 this.store.baseParams[this.queryParam] = q;
40191 params: this.getParams(q)
40196 this.selectedIndex = -1;
40203 getParams : function(q){
40205 //p[this.queryParam] = q;
40208 p.limit = this.pageSize;
40214 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
40216 collapse : function(){
40217 if(!this.isExpanded()){
40221 Roo.get(document).un('mousedown', this.collapseIf, this);
40222 Roo.get(document).un('mousewheel', this.collapseIf, this);
40223 if (!this.editable) {
40224 Roo.get(document).un('keydown', this.listKeyPress, this);
40226 this.fireEvent('collapse', this);
40230 collapseIf : function(e){
40231 if(!e.within(this.wrap) && !e.within(this.list)){
40237 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
40239 expand : function(){
40240 if(this.isExpanded() || !this.hasFocus){
40243 this.list.alignTo(this.el, this.listAlign);
40245 Roo.get(document).on('mousedown', this.collapseIf, this);
40246 Roo.get(document).on('mousewheel', this.collapseIf, this);
40247 if (!this.editable) {
40248 Roo.get(document).on('keydown', this.listKeyPress, this);
40251 this.fireEvent('expand', this);
40255 // Implements the default empty TriggerField.onTriggerClick function
40256 onTriggerClick : function(){
40260 if(this.isExpanded()){
40262 if (!this.blockFocus) {
40267 this.hasFocus = true;
40268 if(this.triggerAction == 'all') {
40269 this.doQuery(this.allQuery, true);
40271 this.doQuery(this.getRawValue());
40273 if (!this.blockFocus) {
40278 listKeyPress : function(e)
40280 //Roo.log('listkeypress');
40281 // scroll to first matching element based on key pres..
40282 if (e.isSpecialKey()) {
40285 var k = String.fromCharCode(e.getKey()).toUpperCase();
40288 var csel = this.view.getSelectedNodes();
40289 var cselitem = false;
40291 var ix = this.view.indexOf(csel[0]);
40292 cselitem = this.store.getAt(ix);
40293 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
40299 this.store.each(function(v) {
40301 // start at existing selection.
40302 if (cselitem.id == v.id) {
40308 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
40309 match = this.store.indexOf(v);
40314 if (match === false) {
40315 return true; // no more action?
40318 this.view.select(match);
40319 var sn = Roo.get(this.view.getSelectedNodes()[0])
40320 sn.scrollIntoView(sn.dom.parentNode, false);
40324 * @cfg {Boolean} grow
40328 * @cfg {Number} growMin
40332 * @cfg {Number} growMax
40340 * Copyright(c) 2010-2012, Roo J Solutions Limited
40347 * @class Roo.form.ComboBoxArray
40348 * @extends Roo.form.TextField
40349 * A facebook style adder... for lists of email / people / countries etc...
40350 * pick multiple items from a combo box, and shows each one.
40352 * Fred [x] Brian [x] [Pick another |v]
40355 * For this to work: it needs various extra information
40356 * - normal combo problay has
40358 * + displayField, valueField
40360 * For our purpose...
40363 * If we change from 'extends' to wrapping...
40370 * Create a new ComboBoxArray.
40371 * @param {Object} config Configuration options
40375 Roo.form.ComboBoxArray = function(config)
40379 * @event beforeremove
40380 * Fires before remove the value from the list
40381 * @param {Roo.form.ComboBoxArray} _self This combo box array
40382 * @param {Roo.form.ComboBoxArray.Item} item removed item
40384 'beforeremove' : true,
40387 * Fires when remove the value from the list
40388 * @param {Roo.form.ComboBoxArray} _self This combo box array
40389 * @param {Roo.form.ComboBoxArray.Item} item removed item
40396 Roo.form.ComboBoxArray.superclass.constructor.call(this, config);
40398 this.items = new Roo.util.MixedCollection(false);
40400 // construct the child combo...
40410 Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField,
40413 * @cfg {Roo.form.Combo} combo The combo box that is wrapped
40418 // behavies liek a hiddne field
40419 inputType: 'hidden',
40421 * @cfg {Number} width The width of the box that displays the selected element
40428 * @cfg {String} name The name of the visable items on this form (eg. titles not ids)
40432 * @cfg {String} hiddenName The hidden name of the field, often contains an comma seperated list of names
40434 hiddenName : false,
40437 // private the array of items that are displayed..
40439 // private - the hidden field el.
40441 // private - the filed el..
40444 //validateValue : function() { return true; }, // all values are ok!
40445 //onAddClick: function() { },
40447 onRender : function(ct, position)
40450 // create the standard hidden element
40451 //Roo.form.ComboBoxArray.superclass.onRender.call(this, ct, position);
40454 // give fake names to child combo;
40455 this.combo.hiddenName = this.hiddenName ? (this.hiddenName+'-subcombo') : this.hiddenName;
40456 this.combo.name = this.name? (this.name+'-subcombo') : this.name;
40458 this.combo = Roo.factory(this.combo, Roo.form);
40459 this.combo.onRender(ct, position);
40460 if (typeof(this.combo.width) != 'undefined') {
40461 this.combo.onResize(this.combo.width,0);
40464 this.combo.initEvents();
40466 // assigned so form know we need to do this..
40467 this.store = this.combo.store;
40468 this.valueField = this.combo.valueField;
40469 this.displayField = this.combo.displayField ;
40472 this.combo.wrap.addClass('x-cbarray-grp');
40474 var cbwrap = this.combo.wrap.createChild(
40475 {tag: 'div', cls: 'x-cbarray-cb'},
40480 this.hiddenEl = this.combo.wrap.createChild({
40481 tag: 'input', type:'hidden' , name: this.hiddenName, value : ''
40483 this.el = this.combo.wrap.createChild({
40484 tag: 'input', type:'hidden' , name: this.name, value : ''
40486 // this.el.dom.removeAttribute("name");
40489 this.outerWrap = this.combo.wrap;
40490 this.wrap = cbwrap;
40492 this.outerWrap.setWidth(this.width);
40493 this.outerWrap.dom.removeChild(this.el.dom);
40495 this.wrap.dom.appendChild(this.el.dom);
40496 this.outerWrap.dom.removeChild(this.combo.trigger.dom);
40497 this.combo.wrap.dom.appendChild(this.combo.trigger.dom);
40499 this.combo.trigger.setStyle('position','relative');
40500 this.combo.trigger.setStyle('left', '0px');
40501 this.combo.trigger.setStyle('top', '2px');
40503 this.combo.el.setStyle('vertical-align', 'text-bottom');
40505 //this.trigger.setStyle('vertical-align', 'top');
40507 // this should use the code from combo really... on('add' ....)
40511 this.adder = this.outerWrap.createChild(
40512 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-adder', style: 'margin-left:2px'});
40514 this.adder.on('click', function(e) {
40515 _t.fireEvent('adderclick', this, e);
40519 //this.adder.on('click', this.onAddClick, _t);
40522 this.combo.on('select', function(cb, rec, ix) {
40523 this.addItem(rec.data);
40526 cb.el.dom.value = '';
40527 //cb.lastData = rec.data;
40536 getName: function()
40538 // returns hidden if it's set..
40539 if (!this.rendered) {return ''};
40540 return this.hiddenName ? this.hiddenName : this.name;
40545 onResize: function(w, h){
40548 // not sure if this is needed..
40549 //this.combo.onResize(w,h);
40551 if(typeof w != 'number'){
40552 // we do not handle it!?!?
40555 var tw = this.combo.trigger.getWidth();
40556 tw += this.addicon ? this.addicon.getWidth() : 0;
40557 tw += this.editicon ? this.editicon.getWidth() : 0;
40559 this.combo.el.setWidth( this.combo.adjustWidth('input', x));
40561 this.combo.trigger.setStyle('left', '0px');
40563 if(this.list && this.listWidth === undefined){
40564 var lw = Math.max(x + this.combo.trigger.getWidth(), this.combo.minListWidth);
40565 this.list.setWidth(lw);
40566 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
40573 addItem: function(rec)
40575 var valueField = this.combo.valueField;
40576 var displayField = this.combo.displayField;
40577 if (this.items.indexOfKey(rec[valueField]) > -1) {
40578 //console.log("GOT " + rec.data.id);
40582 var x = new Roo.form.ComboBoxArray.Item({
40583 //id : rec[this.idField],
40585 displayField : displayField ,
40586 tipField : displayField ,
40590 this.items.add(rec[valueField],x);
40591 // add it before the element..
40592 this.updateHiddenEl();
40593 x.render(this.outerWrap, this.wrap.dom);
40594 // add the image handler..
40597 updateHiddenEl : function()
40600 if (!this.hiddenEl) {
40604 var idField = this.combo.valueField;
40606 this.items.each(function(f) {
40607 ar.push(f.data[idField]);
40610 this.hiddenEl.dom.value = ar.join(',');
40616 //Roo.form.ComboBoxArray.superclass.reset.call(this);
40617 this.items.each(function(f) {
40620 this.el.dom.value = '';
40621 if (this.hiddenEl) {
40622 this.hiddenEl.dom.value = '';
40626 getValue: function()
40628 return this.hiddenEl ? this.hiddenEl.dom.value : '';
40630 setValue: function(v) // not a valid action - must use addItems..
40637 if (this.store.isLocal && (typeof(v) == 'string')) {
40638 // then we can use the store to find the values..
40639 // comma seperated at present.. this needs to allow JSON based encoding..
40640 this.hiddenEl.value = v;
40642 Roo.each(v.split(','), function(k) {
40643 Roo.log("CHECK " + this.valueField + ',' + k);
40644 var li = this.store.query(this.valueField, k);
40649 add[this.valueField] = k;
40650 add[this.displayField] = li.item(0).data[this.displayField];
40656 if (typeof(v) == 'object' ) {
40657 // then let's assume it's an array of objects..
40658 Roo.each(v, function(l) {
40666 setFromData: function(v)
40668 // this recieves an object, if setValues is called.
40670 this.el.dom.value = v[this.displayField];
40671 this.hiddenEl.dom.value = v[this.valueField];
40672 if (typeof(v[this.valueField]) != 'string' || !v[this.valueField].length) {
40675 var kv = v[this.valueField];
40676 var dv = v[this.displayField];
40677 kv = typeof(kv) != 'string' ? '' : kv;
40678 dv = typeof(dv) != 'string' ? '' : dv;
40681 var keys = kv.split(',');
40682 var display = dv.split(',');
40683 for (var i = 0 ; i < keys.length; i++) {
40686 add[this.valueField] = keys[i];
40687 add[this.displayField] = display[i];
40695 * Validates the combox array value
40696 * @return {Boolean} True if the value is valid, else false
40698 validate : function(){
40699 if(this.disabled || this.validateValue(this.processValue(this.getValue()))){
40700 this.clearInvalid();
40706 validateValue : function(value){
40707 return Roo.form.ComboBoxArray.superclass.validateValue.call(this, this.getValue());
40715 isDirty : function() {
40716 if(this.disabled) {
40721 var d = Roo.decode(String(this.originalValue));
40723 return String(this.getValue()) !== String(this.originalValue);
40726 var originalValue = [];
40728 for (var i = 0; i < d.length; i++){
40729 originalValue.push(d[i][this.valueField]);
40732 return String(this.getValue()) !== String(originalValue.join(','));
40741 * @class Roo.form.ComboBoxArray.Item
40742 * @extends Roo.BoxComponent
40743 * A selected item in the list
40744 * Fred [x] Brian [x] [Pick another |v]
40747 * Create a new item.
40748 * @param {Object} config Configuration options
40751 Roo.form.ComboBoxArray.Item = function(config) {
40752 config.id = Roo.id();
40753 Roo.form.ComboBoxArray.Item.superclass.constructor.call(this, config);
40756 Roo.extend(Roo.form.ComboBoxArray.Item, Roo.BoxComponent, {
40759 displayField : false,
40763 defaultAutoCreate : {
40765 cls: 'x-cbarray-item',
40772 src : Roo.BLANK_IMAGE_URL ,
40780 onRender : function(ct, position)
40782 Roo.form.Field.superclass.onRender.call(this, ct, position);
40785 var cfg = this.getAutoCreate();
40786 this.el = ct.createChild(cfg, position);
40789 this.el.child('img').dom.setAttribute('src', Roo.BLANK_IMAGE_URL);
40791 this.el.child('div').dom.innerHTML = this.cb.renderer ?
40792 this.cb.renderer(this.data) :
40793 String.format('{0}',this.data[this.displayField]);
40796 this.el.child('div').dom.setAttribute('qtip',
40797 String.format('{0}',this.data[this.tipField])
40800 this.el.child('img').on('click', this.remove, this);
40804 remove : function()
40806 if(this.cb.disabled){
40810 if(false !== this.cb.fireEvent('beforeremove', this.cb, this)){
40811 this.cb.items.remove(this);
40812 this.el.child('img').un('click', this.remove, this);
40814 this.cb.updateHiddenEl();
40816 this.cb.fireEvent('remove', this.cb, this);
40822 * Ext JS Library 1.1.1
40823 * Copyright(c) 2006-2007, Ext JS, LLC.
40825 * Originally Released Under LGPL - original licence link has changed is not relivant.
40828 * <script type="text/javascript">
40831 * @class Roo.form.Checkbox
40832 * @extends Roo.form.Field
40833 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
40835 * Creates a new Checkbox
40836 * @param {Object} config Configuration options
40838 Roo.form.Checkbox = function(config){
40839 Roo.form.Checkbox.superclass.constructor.call(this, config);
40843 * Fires when the checkbox is checked or unchecked.
40844 * @param {Roo.form.Checkbox} this This checkbox
40845 * @param {Boolean} checked The new checked value
40851 Roo.extend(Roo.form.Checkbox, Roo.form.Field, {
40853 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
40855 focusClass : undefined,
40857 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
40859 fieldClass: "x-form-field",
40861 * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
40865 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
40866 * {tag: "input", type: "checkbox", autocomplete: "off"})
40868 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
40870 * @cfg {String} boxLabel The text that appears beside the checkbox
40874 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
40878 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
40880 valueOff: '0', // value when not checked..
40882 actionMode : 'viewEl',
40885 itemCls : 'x-menu-check-item x-form-item',
40886 groupClass : 'x-menu-group-item',
40887 inputType : 'hidden',
40890 inSetChecked: false, // check that we are not calling self...
40892 inputElement: false, // real input element?
40893 basedOn: false, // ????
40895 isFormField: true, // not sure where this is needed!!!!
40897 onResize : function(){
40898 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
40899 if(!this.boxLabel){
40900 this.el.alignTo(this.wrap, 'c-c');
40904 initEvents : function(){
40905 Roo.form.Checkbox.superclass.initEvents.call(this);
40906 this.el.on("click", this.onClick, this);
40907 this.el.on("change", this.onClick, this);
40911 getResizeEl : function(){
40915 getPositionEl : function(){
40920 onRender : function(ct, position){
40921 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
40923 if(this.inputValue !== undefined){
40924 this.el.dom.value = this.inputValue;
40927 //this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
40928 this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
40929 var viewEl = this.wrap.createChild({
40930 tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
40931 this.viewEl = viewEl;
40932 this.wrap.on('click', this.onClick, this);
40934 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
40935 this.el.on('propertychange', this.setFromHidden, this); //ie
40940 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
40941 // viewEl.on('click', this.onClick, this);
40943 //if(this.checked){
40944 this.setChecked(this.checked);
40946 //this.checked = this.el.dom;
40952 initValue : Roo.emptyFn,
40955 * Returns the checked state of the checkbox.
40956 * @return {Boolean} True if checked, else false
40958 getValue : function(){
40960 return String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
40962 return this.valueOff;
40967 onClick : function(){
40968 if (this.disabled) {
40971 this.setChecked(!this.checked);
40973 //if(this.el.dom.checked != this.checked){
40974 // this.setValue(this.el.dom.checked);
40979 * Sets the checked state of the checkbox.
40980 * On is always based on a string comparison between inputValue and the param.
40981 * @param {Boolean/String} value - the value to set
40982 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
40984 setValue : function(v,suppressEvent){
40987 //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
40988 //if(this.el && this.el.dom){
40989 // this.el.dom.checked = this.checked;
40990 // this.el.dom.defaultChecked = this.checked;
40992 this.setChecked(String(v) === String(this.inputValue), suppressEvent);
40993 //this.fireEvent("check", this, this.checked);
40996 setChecked : function(state,suppressEvent)
40998 if (this.inSetChecked) {
40999 this.checked = state;
41005 this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked');
41007 this.checked = state;
41008 if(suppressEvent !== true){
41009 this.fireEvent('check', this, state);
41011 this.inSetChecked = true;
41012 this.el.dom.value = state ? this.inputValue : this.valueOff;
41013 this.inSetChecked = false;
41016 // handle setting of hidden value by some other method!!?!?
41017 setFromHidden: function()
41022 //console.log("SET FROM HIDDEN");
41023 //alert('setFrom hidden');
41024 this.setValue(this.el.dom.value);
41027 onDestroy : function()
41030 Roo.get(this.viewEl).remove();
41033 Roo.form.Checkbox.superclass.onDestroy.call(this);
41038 * Ext JS Library 1.1.1
41039 * Copyright(c) 2006-2007, Ext JS, LLC.
41041 * Originally Released Under LGPL - original licence link has changed is not relivant.
41044 * <script type="text/javascript">
41048 * @class Roo.form.Radio
41049 * @extends Roo.form.Checkbox
41050 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
41051 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
41053 * Creates a new Radio
41054 * @param {Object} config Configuration options
41056 Roo.form.Radio = function(){
41057 Roo.form.Radio.superclass.constructor.apply(this, arguments);
41059 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
41060 inputType: 'radio',
41063 * If this radio is part of a group, it will return the selected value
41066 getGroupValue : function(){
41067 return this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
41071 onRender : function(ct, position){
41072 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
41074 if(this.inputValue !== undefined){
41075 this.el.dom.value = this.inputValue;
41078 this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
41079 //this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
41080 //var viewEl = this.wrap.createChild({
41081 // tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
41082 //this.viewEl = viewEl;
41083 //this.wrap.on('click', this.onClick, this);
41085 //this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
41086 //this.el.on('propertychange', this.setFromHidden, this); //ie
41091 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
41092 // viewEl.on('click', this.onClick, this);
41095 this.el.dom.checked = 'checked' ;
41101 });//<script type="text/javascript">
41104 * Based Ext JS Library 1.1.1
41105 * Copyright(c) 2006-2007, Ext JS, LLC.
41111 * @class Roo.HtmlEditorCore
41112 * @extends Roo.Component
41113 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
41115 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
41118 Roo.HtmlEditorCore = function(config){
41121 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
41126 * @event initialize
41127 * Fires when the editor is fully initialized (including the iframe)
41128 * @param {Roo.HtmlEditorCore} this
41133 * Fires when the editor is first receives the focus. Any insertion must wait
41134 * until after this event.
41135 * @param {Roo.HtmlEditorCore} this
41139 * @event beforesync
41140 * Fires before the textarea is updated with content from the editor iframe. Return false
41141 * to cancel the sync.
41142 * @param {Roo.HtmlEditorCore} this
41143 * @param {String} html
41147 * @event beforepush
41148 * Fires before the iframe editor is updated with content from the textarea. Return false
41149 * to cancel the push.
41150 * @param {Roo.HtmlEditorCore} this
41151 * @param {String} html
41156 * Fires when the textarea is updated with content from the editor iframe.
41157 * @param {Roo.HtmlEditorCore} this
41158 * @param {String} html
41163 * Fires when the iframe editor is updated with content from the textarea.
41164 * @param {Roo.HtmlEditorCore} this
41165 * @param {String} html
41170 * @event editorevent
41171 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
41172 * @param {Roo.HtmlEditorCore} this
41178 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
41180 // defaults : white / black...
41181 this.applyBlacklists();
41188 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
41192 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
41198 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
41203 * @cfg {Number} height (in pixels)
41207 * @cfg {Number} width (in pixels)
41212 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
41215 stylesheets: false,
41220 // private properties
41221 validationEvent : false,
41223 initialized : false,
41225 sourceEditMode : false,
41226 onFocus : Roo.emptyFn,
41228 hideMode:'offsets',
41232 // blacklist + whitelisted elements..
41239 * Protected method that will not generally be called directly. It
41240 * is called when the editor initializes the iframe with HTML contents. Override this method if you
41241 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
41243 getDocMarkup : function(){
41247 // inherit styels from page...??
41248 if (this.stylesheets === false) {
41250 Roo.get(document.head).select('style').each(function(node) {
41251 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
41254 Roo.get(document.head).select('link').each(function(node) {
41255 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
41258 } else if (!this.stylesheets.length) {
41260 st = '<style type="text/css">' +
41261 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
41267 st += '<style type="text/css">' +
41268 'IMG { cursor: pointer } ' +
41272 return '<html><head>' + st +
41273 //<style type="text/css">' +
41274 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
41276 ' </head><body class="roo-htmleditor-body"></body></html>';
41280 onRender : function(ct, position)
41283 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
41284 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
41287 this.el.dom.style.border = '0 none';
41288 this.el.dom.setAttribute('tabIndex', -1);
41289 this.el.addClass('x-hidden hide');
41293 if(Roo.isIE){ // fix IE 1px bogus margin
41294 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
41298 this.frameId = Roo.id();
41302 var iframe = this.owner.wrap.createChild({
41304 cls: 'form-control', // bootstrap..
41306 name: this.frameId,
41307 frameBorder : 'no',
41308 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
41313 this.iframe = iframe.dom;
41315 this.assignDocWin();
41317 this.doc.designMode = 'on';
41320 this.doc.write(this.getDocMarkup());
41324 var task = { // must defer to wait for browser to be ready
41326 //console.log("run task?" + this.doc.readyState);
41327 this.assignDocWin();
41328 if(this.doc.body || this.doc.readyState == 'complete'){
41330 this.doc.designMode="on";
41334 Roo.TaskMgr.stop(task);
41335 this.initEditor.defer(10, this);
41342 Roo.TaskMgr.start(task);
41347 onResize : function(w, h)
41349 Roo.log('resize: ' +w + ',' + h );
41350 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
41354 if(typeof w == 'number'){
41356 this.iframe.style.width = w + 'px';
41358 if(typeof h == 'number'){
41360 this.iframe.style.height = h + 'px';
41362 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
41369 * Toggles the editor between standard and source edit mode.
41370 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
41372 toggleSourceEdit : function(sourceEditMode){
41374 this.sourceEditMode = sourceEditMode === true;
41376 if(this.sourceEditMode){
41378 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
41381 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
41382 //this.iframe.className = '';
41385 //this.setSize(this.owner.wrap.getSize());
41386 //this.fireEvent('editmodechange', this, this.sourceEditMode);
41393 * Protected method that will not generally be called directly. If you need/want
41394 * custom HTML cleanup, this is the method you should override.
41395 * @param {String} html The HTML to be cleaned
41396 * return {String} The cleaned HTML
41398 cleanHtml : function(html){
41399 html = String(html);
41400 if(html.length > 5){
41401 if(Roo.isSafari){ // strip safari nonsense
41402 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
41405 if(html == ' '){
41412 * HTML Editor -> Textarea
41413 * Protected method that will not generally be called directly. Syncs the contents
41414 * of the editor iframe with the textarea.
41416 syncValue : function(){
41417 if(this.initialized){
41418 var bd = (this.doc.body || this.doc.documentElement);
41419 //this.cleanUpPaste(); -- this is done else where and causes havoc..
41420 var html = bd.innerHTML;
41422 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
41423 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
41425 html = '<div style="'+m[0]+'">' + html + '</div>';
41428 html = this.cleanHtml(html);
41429 // fix up the special chars.. normaly like back quotes in word...
41430 // however we do not want to do this with chinese..
41431 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
41432 var cc = b.charCodeAt();
41434 (cc >= 0x4E00 && cc < 0xA000 ) ||
41435 (cc >= 0x3400 && cc < 0x4E00 ) ||
41436 (cc >= 0xf900 && cc < 0xfb00 )
41442 if(this.owner.fireEvent('beforesync', this, html) !== false){
41443 this.el.dom.value = html;
41444 this.owner.fireEvent('sync', this, html);
41450 * Protected method that will not generally be called directly. Pushes the value of the textarea
41451 * into the iframe editor.
41453 pushValue : function(){
41454 if(this.initialized){
41455 var v = this.el.dom.value.trim();
41457 // if(v.length < 1){
41461 if(this.owner.fireEvent('beforepush', this, v) !== false){
41462 var d = (this.doc.body || this.doc.documentElement);
41464 this.cleanUpPaste();
41465 this.el.dom.value = d.innerHTML;
41466 this.owner.fireEvent('push', this, v);
41472 deferFocus : function(){
41473 this.focus.defer(10, this);
41477 focus : function(){
41478 if(this.win && !this.sourceEditMode){
41485 assignDocWin: function()
41487 var iframe = this.iframe;
41490 this.doc = iframe.contentWindow.document;
41491 this.win = iframe.contentWindow;
41493 // if (!Roo.get(this.frameId)) {
41496 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
41497 // this.win = Roo.get(this.frameId).dom.contentWindow;
41499 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
41503 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
41504 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
41509 initEditor : function(){
41510 //console.log("INIT EDITOR");
41511 this.assignDocWin();
41515 this.doc.designMode="on";
41517 this.doc.write(this.getDocMarkup());
41520 var dbody = (this.doc.body || this.doc.documentElement);
41521 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
41522 // this copies styles from the containing element into thsi one..
41523 // not sure why we need all of this..
41524 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
41526 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
41527 //ss['background-attachment'] = 'fixed'; // w3c
41528 dbody.bgProperties = 'fixed'; // ie
41529 //Roo.DomHelper.applyStyles(dbody, ss);
41530 Roo.EventManager.on(this.doc, {
41531 //'mousedown': this.onEditorEvent,
41532 'mouseup': this.onEditorEvent,
41533 'dblclick': this.onEditorEvent,
41534 'click': this.onEditorEvent,
41535 'keyup': this.onEditorEvent,
41540 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
41542 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
41543 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
41545 this.initialized = true;
41547 this.owner.fireEvent('initialize', this);
41552 onDestroy : function(){
41558 //for (var i =0; i < this.toolbars.length;i++) {
41559 // // fixme - ask toolbars for heights?
41560 // this.toolbars[i].onDestroy();
41563 //this.wrap.dom.innerHTML = '';
41564 //this.wrap.remove();
41569 onFirstFocus : function(){
41571 this.assignDocWin();
41574 this.activated = true;
41577 if(Roo.isGecko){ // prevent silly gecko errors
41579 var s = this.win.getSelection();
41580 if(!s.focusNode || s.focusNode.nodeType != 3){
41581 var r = s.getRangeAt(0);
41582 r.selectNodeContents((this.doc.body || this.doc.documentElement));
41587 this.execCmd('useCSS', true);
41588 this.execCmd('styleWithCSS', false);
41591 this.owner.fireEvent('activate', this);
41595 adjustFont: function(btn){
41596 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
41597 //if(Roo.isSafari){ // safari
41600 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
41601 if(Roo.isSafari){ // safari
41602 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
41603 v = (v < 10) ? 10 : v;
41604 v = (v > 48) ? 48 : v;
41605 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
41610 v = Math.max(1, v+adjust);
41612 this.execCmd('FontSize', v );
41615 onEditorEvent : function(e)
41617 this.owner.fireEvent('editorevent', this, e);
41618 // this.updateToolbar();
41619 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
41622 insertTag : function(tg)
41624 // could be a bit smarter... -> wrap the current selected tRoo..
41625 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
41627 range = this.createRange(this.getSelection());
41628 var wrappingNode = this.doc.createElement(tg.toLowerCase());
41629 wrappingNode.appendChild(range.extractContents());
41630 range.insertNode(wrappingNode);
41637 this.execCmd("formatblock", tg);
41641 insertText : function(txt)
41645 var range = this.createRange();
41646 range.deleteContents();
41647 //alert(Sender.getAttribute('label'));
41649 range.insertNode(this.doc.createTextNode(txt));
41655 * Executes a Midas editor command on the editor document and performs necessary focus and
41656 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
41657 * @param {String} cmd The Midas command
41658 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
41660 relayCmd : function(cmd, value){
41662 this.execCmd(cmd, value);
41663 this.owner.fireEvent('editorevent', this);
41664 //this.updateToolbar();
41665 this.owner.deferFocus();
41669 * Executes a Midas editor command directly on the editor document.
41670 * For visual commands, you should use {@link #relayCmd} instead.
41671 * <b>This should only be called after the editor is initialized.</b>
41672 * @param {String} cmd The Midas command
41673 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
41675 execCmd : function(cmd, value){
41676 this.doc.execCommand(cmd, false, value === undefined ? null : value);
41683 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
41685 * @param {String} text | dom node..
41687 insertAtCursor : function(text)
41692 if(!this.activated){
41698 var r = this.doc.selection.createRange();
41709 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
41713 // from jquery ui (MIT licenced)
41715 var win = this.win;
41717 if (win.getSelection && win.getSelection().getRangeAt) {
41718 range = win.getSelection().getRangeAt(0);
41719 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
41720 range.insertNode(node);
41721 } else if (win.document.selection && win.document.selection.createRange) {
41722 // no firefox support
41723 var txt = typeof(text) == 'string' ? text : text.outerHTML;
41724 win.document.selection.createRange().pasteHTML(txt);
41726 // no firefox support
41727 var txt = typeof(text) == 'string' ? text : text.outerHTML;
41728 this.execCmd('InsertHTML', txt);
41737 mozKeyPress : function(e){
41739 var c = e.getCharCode(), cmd;
41742 c = String.fromCharCode(c).toLowerCase();
41756 this.cleanUpPaste.defer(100, this);
41764 e.preventDefault();
41772 fixKeys : function(){ // load time branching for fastest keydown performance
41774 return function(e){
41775 var k = e.getKey(), r;
41778 r = this.doc.selection.createRange();
41781 r.pasteHTML('    ');
41788 r = this.doc.selection.createRange();
41790 var target = r.parentElement();
41791 if(!target || target.tagName.toLowerCase() != 'li'){
41793 r.pasteHTML('<br />');
41799 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
41800 this.cleanUpPaste.defer(100, this);
41806 }else if(Roo.isOpera){
41807 return function(e){
41808 var k = e.getKey();
41812 this.execCmd('InsertHTML','    ');
41815 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
41816 this.cleanUpPaste.defer(100, this);
41821 }else if(Roo.isSafari){
41822 return function(e){
41823 var k = e.getKey();
41827 this.execCmd('InsertText','\t');
41831 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
41832 this.cleanUpPaste.defer(100, this);
41840 getAllAncestors: function()
41842 var p = this.getSelectedNode();
41845 a.push(p); // push blank onto stack..
41846 p = this.getParentElement();
41850 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
41854 a.push(this.doc.body);
41858 lastSelNode : false,
41861 getSelection : function()
41863 this.assignDocWin();
41864 return Roo.isIE ? this.doc.selection : this.win.getSelection();
41867 getSelectedNode: function()
41869 // this may only work on Gecko!!!
41871 // should we cache this!!!!
41876 var range = this.createRange(this.getSelection()).cloneRange();
41879 var parent = range.parentElement();
41881 var testRange = range.duplicate();
41882 testRange.moveToElementText(parent);
41883 if (testRange.inRange(range)) {
41886 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
41889 parent = parent.parentElement;
41894 // is ancestor a text element.
41895 var ac = range.commonAncestorContainer;
41896 if (ac.nodeType == 3) {
41897 ac = ac.parentNode;
41900 var ar = ac.childNodes;
41903 var other_nodes = [];
41904 var has_other_nodes = false;
41905 for (var i=0;i<ar.length;i++) {
41906 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
41909 // fullly contained node.
41911 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
41916 // probably selected..
41917 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
41918 other_nodes.push(ar[i]);
41922 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
41927 has_other_nodes = true;
41929 if (!nodes.length && other_nodes.length) {
41930 nodes= other_nodes;
41932 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
41938 createRange: function(sel)
41940 // this has strange effects when using with
41941 // top toolbar - not sure if it's a great idea.
41942 //this.editor.contentWindow.focus();
41943 if (typeof sel != "undefined") {
41945 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
41947 return this.doc.createRange();
41950 return this.doc.createRange();
41953 getParentElement: function()
41956 this.assignDocWin();
41957 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
41959 var range = this.createRange(sel);
41962 var p = range.commonAncestorContainer;
41963 while (p.nodeType == 3) { // text node
41974 * Range intersection.. the hard stuff...
41978 * [ -- selected range --- ]
41982 * if end is before start or hits it. fail.
41983 * if start is after end or hits it fail.
41985 * if either hits (but other is outside. - then it's not
41991 // @see http://www.thismuchiknow.co.uk/?p=64.
41992 rangeIntersectsNode : function(range, node)
41994 var nodeRange = node.ownerDocument.createRange();
41996 nodeRange.selectNode(node);
41998 nodeRange.selectNodeContents(node);
42001 var rangeStartRange = range.cloneRange();
42002 rangeStartRange.collapse(true);
42004 var rangeEndRange = range.cloneRange();
42005 rangeEndRange.collapse(false);
42007 var nodeStartRange = nodeRange.cloneRange();
42008 nodeStartRange.collapse(true);
42010 var nodeEndRange = nodeRange.cloneRange();
42011 nodeEndRange.collapse(false);
42013 return rangeStartRange.compareBoundaryPoints(
42014 Range.START_TO_START, nodeEndRange) == -1 &&
42015 rangeEndRange.compareBoundaryPoints(
42016 Range.START_TO_START, nodeStartRange) == 1;
42020 rangeCompareNode : function(range, node)
42022 var nodeRange = node.ownerDocument.createRange();
42024 nodeRange.selectNode(node);
42026 nodeRange.selectNodeContents(node);
42030 range.collapse(true);
42032 nodeRange.collapse(true);
42034 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
42035 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
42037 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
42039 var nodeIsBefore = ss == 1;
42040 var nodeIsAfter = ee == -1;
42042 if (nodeIsBefore && nodeIsAfter)
42044 if (!nodeIsBefore && nodeIsAfter)
42045 return 1; //right trailed.
42047 if (nodeIsBefore && !nodeIsAfter)
42048 return 2; // left trailed.
42053 // private? - in a new class?
42054 cleanUpPaste : function()
42056 // cleans up the whole document..
42057 Roo.log('cleanuppaste');
42059 this.cleanUpChildren(this.doc.body);
42060 var clean = this.cleanWordChars(this.doc.body.innerHTML);
42061 if (clean != this.doc.body.innerHTML) {
42062 this.doc.body.innerHTML = clean;
42067 cleanWordChars : function(input) {// change the chars to hex code
42068 var he = Roo.HtmlEditorCore;
42070 var output = input;
42071 Roo.each(he.swapCodes, function(sw) {
42072 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
42074 output = output.replace(swapper, sw[1]);
42081 cleanUpChildren : function (n)
42083 if (!n.childNodes.length) {
42086 for (var i = n.childNodes.length-1; i > -1 ; i--) {
42087 this.cleanUpChild(n.childNodes[i]);
42094 cleanUpChild : function (node)
42097 //console.log(node);
42098 if (node.nodeName == "#text") {
42099 // clean up silly Windows -- stuff?
42102 if (node.nodeName == "#comment") {
42103 node.parentNode.removeChild(node);
42104 // clean up silly Windows -- stuff?
42107 var lcname = node.tagName.toLowerCase();
42108 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
42109 // whitelist of tags..
42111 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
42113 node.parentNode.removeChild(node);
42118 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
42120 // remove <a name=....> as rendering on yahoo mailer is borked with this.
42121 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
42123 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
42124 // remove_keep_children = true;
42127 if (remove_keep_children) {
42128 this.cleanUpChildren(node);
42129 // inserts everything just before this node...
42130 while (node.childNodes.length) {
42131 var cn = node.childNodes[0];
42132 node.removeChild(cn);
42133 node.parentNode.insertBefore(cn, node);
42135 node.parentNode.removeChild(node);
42139 if (!node.attributes || !node.attributes.length) {
42140 this.cleanUpChildren(node);
42144 function cleanAttr(n,v)
42147 if (v.match(/^\./) || v.match(/^\//)) {
42150 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
42153 if (v.match(/^#/)) {
42156 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
42157 node.removeAttribute(n);
42161 var cwhite = this.cwhite;
42162 var cblack = this.cblack;
42164 function cleanStyle(n,v)
42166 if (v.match(/expression/)) { //XSS?? should we even bother..
42167 node.removeAttribute(n);
42171 var parts = v.split(/;/);
42174 Roo.each(parts, function(p) {
42175 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
42179 var l = p.split(':').shift().replace(/\s+/g,'');
42180 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
42182 if ( cwhite.length && cblack.indexOf(l) > -1) {
42183 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
42184 //node.removeAttribute(n);
42188 // only allow 'c whitelisted system attributes'
42189 if ( cwhite.length && cwhite.indexOf(l) < 0) {
42190 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
42191 //node.removeAttribute(n);
42201 if (clean.length) {
42202 node.setAttribute(n, clean.join(';'));
42204 node.removeAttribute(n);
42210 for (var i = node.attributes.length-1; i > -1 ; i--) {
42211 var a = node.attributes[i];
42214 if (a.name.toLowerCase().substr(0,2)=='on') {
42215 node.removeAttribute(a.name);
42218 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
42219 node.removeAttribute(a.name);
42222 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
42223 cleanAttr(a.name,a.value); // fixme..
42226 if (a.name == 'style') {
42227 cleanStyle(a.name,a.value);
42230 /// clean up MS crap..
42231 // tecnically this should be a list of valid class'es..
42234 if (a.name == 'class') {
42235 if (a.value.match(/^Mso/)) {
42236 node.className = '';
42239 if (a.value.match(/body/)) {
42240 node.className = '';
42251 this.cleanUpChildren(node);
42257 * Clean up MS wordisms...
42259 cleanWord : function(node)
42264 this.cleanWord(this.doc.body);
42267 if (node.nodeName == "#text") {
42268 // clean up silly Windows -- stuff?
42271 if (node.nodeName == "#comment") {
42272 node.parentNode.removeChild(node);
42273 // clean up silly Windows -- stuff?
42277 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
42278 node.parentNode.removeChild(node);
42282 // remove - but keep children..
42283 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
42284 while (node.childNodes.length) {
42285 var cn = node.childNodes[0];
42286 node.removeChild(cn);
42287 node.parentNode.insertBefore(cn, node);
42289 node.parentNode.removeChild(node);
42290 this.iterateChildren(node, this.cleanWord);
42294 if (node.className.length) {
42296 var cn = node.className.split(/\W+/);
42298 Roo.each(cn, function(cls) {
42299 if (cls.match(/Mso[a-zA-Z]+/)) {
42304 node.className = cna.length ? cna.join(' ') : '';
42306 node.removeAttribute("class");
42310 if (node.hasAttribute("lang")) {
42311 node.removeAttribute("lang");
42314 if (node.hasAttribute("style")) {
42316 var styles = node.getAttribute("style").split(";");
42318 Roo.each(styles, function(s) {
42319 if (!s.match(/:/)) {
42322 var kv = s.split(":");
42323 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
42326 // what ever is left... we allow.
42329 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
42330 if (!nstyle.length) {
42331 node.removeAttribute('style');
42334 this.iterateChildren(node, this.cleanWord);
42340 * iterateChildren of a Node, calling fn each time, using this as the scole..
42341 * @param {DomNode} node node to iterate children of.
42342 * @param {Function} fn method of this class to call on each item.
42344 iterateChildren : function(node, fn)
42346 if (!node.childNodes.length) {
42349 for (var i = node.childNodes.length-1; i > -1 ; i--) {
42350 fn.call(this, node.childNodes[i])
42356 * cleanTableWidths.
42358 * Quite often pasting from word etc.. results in tables with column and widths.
42359 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
42362 cleanTableWidths : function(node)
42367 this.cleanTableWidths(this.doc.body);
42372 if (node.nodeName == "#text" || node.nodeName == "#comment") {
42375 Roo.log(node.tagName);
42376 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
42377 this.iterateChildren(node, this.cleanTableWidths);
42380 if (node.hasAttribute('width')) {
42381 node.removeAttribute('width');
42385 if (node.hasAttribute("style")) {
42388 var styles = node.getAttribute("style").split(";");
42390 Roo.each(styles, function(s) {
42391 if (!s.match(/:/)) {
42394 var kv = s.split(":");
42395 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
42398 // what ever is left... we allow.
42401 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
42402 if (!nstyle.length) {
42403 node.removeAttribute('style');
42407 this.iterateChildren(node, this.cleanTableWidths);
42415 domToHTML : function(currentElement, depth, nopadtext) {
42417 depth = depth || 0;
42418 nopadtext = nopadtext || false;
42420 if (!currentElement) {
42421 return this.domToHTML(this.doc.body);
42424 //Roo.log(currentElement);
42426 var allText = false;
42427 var nodeName = currentElement.nodeName;
42428 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
42430 if (nodeName == '#text') {
42432 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
42437 if (nodeName != 'BODY') {
42440 // Prints the node tagName, such as <A>, <IMG>, etc
42443 for(i = 0; i < currentElement.attributes.length;i++) {
42445 var aname = currentElement.attributes.item(i).name;
42446 if (!currentElement.attributes.item(i).value.length) {
42449 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
42452 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
42461 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
42464 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
42469 // Traverse the tree
42471 var currentElementChild = currentElement.childNodes.item(i);
42472 var allText = true;
42473 var innerHTML = '';
42475 while (currentElementChild) {
42476 // Formatting code (indent the tree so it looks nice on the screen)
42477 var nopad = nopadtext;
42478 if (lastnode == 'SPAN') {
42482 if (currentElementChild.nodeName == '#text') {
42483 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
42484 toadd = nopadtext ? toadd : toadd.trim();
42485 if (!nopad && toadd.length > 80) {
42486 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
42488 innerHTML += toadd;
42491 currentElementChild = currentElement.childNodes.item(i);
42497 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
42499 // Recursively traverse the tree structure of the child node
42500 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
42501 lastnode = currentElementChild.nodeName;
42503 currentElementChild=currentElement.childNodes.item(i);
42509 // The remaining code is mostly for formatting the tree
42510 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
42515 ret+= "</"+tagName+">";
42521 applyBlacklists : function()
42523 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
42524 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
42528 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
42529 if (b.indexOf(tag) > -1) {
42532 this.white.push(tag);
42536 Roo.each(w, function(tag) {
42537 if (b.indexOf(tag) > -1) {
42540 if (this.white.indexOf(tag) > -1) {
42543 this.white.push(tag);
42548 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
42549 if (w.indexOf(tag) > -1) {
42552 this.black.push(tag);
42556 Roo.each(b, function(tag) {
42557 if (w.indexOf(tag) > -1) {
42560 if (this.black.indexOf(tag) > -1) {
42563 this.black.push(tag);
42568 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
42569 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
42573 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
42574 if (b.indexOf(tag) > -1) {
42577 this.cwhite.push(tag);
42581 Roo.each(w, function(tag) {
42582 if (b.indexOf(tag) > -1) {
42585 if (this.cwhite.indexOf(tag) > -1) {
42588 this.cwhite.push(tag);
42593 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
42594 if (w.indexOf(tag) > -1) {
42597 this.cblack.push(tag);
42601 Roo.each(b, function(tag) {
42602 if (w.indexOf(tag) > -1) {
42605 if (this.cblack.indexOf(tag) > -1) {
42608 this.cblack.push(tag);
42613 setStylesheets : function(stylesheets)
42615 if(typeof(stylesheets) == 'string'){
42616 Roo.get(this.iframe.contentDocument.head).createChild({
42618 rel : 'stylesheet',
42627 Roo.each(stylesheets, function(s) {
42632 Roo.get(_this.iframe.contentDocument.head).createChild({
42634 rel : 'stylesheet',
42643 removeStylesheets : function()
42647 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
42652 // hide stuff that is not compatible
42666 * @event specialkey
42670 * @cfg {String} fieldClass @hide
42673 * @cfg {String} focusClass @hide
42676 * @cfg {String} autoCreate @hide
42679 * @cfg {String} inputType @hide
42682 * @cfg {String} invalidClass @hide
42685 * @cfg {String} invalidText @hide
42688 * @cfg {String} msgFx @hide
42691 * @cfg {String} validateOnBlur @hide
42695 Roo.HtmlEditorCore.white = [
42696 'area', 'br', 'img', 'input', 'hr', 'wbr',
42698 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
42699 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
42700 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
42701 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
42702 'table', 'ul', 'xmp',
42704 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
42707 'dir', 'menu', 'ol', 'ul', 'dl',
42713 Roo.HtmlEditorCore.black = [
42714 // 'embed', 'object', // enable - backend responsiblity to clean thiese
42716 'base', 'basefont', 'bgsound', 'blink', 'body',
42717 'frame', 'frameset', 'head', 'html', 'ilayer',
42718 'iframe', 'layer', 'link', 'meta', 'object',
42719 'script', 'style' ,'title', 'xml' // clean later..
42721 Roo.HtmlEditorCore.clean = [
42722 'script', 'style', 'title', 'xml'
42724 Roo.HtmlEditorCore.remove = [
42729 Roo.HtmlEditorCore.ablack = [
42733 Roo.HtmlEditorCore.aclean = [
42734 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
42738 Roo.HtmlEditorCore.pwhite= [
42739 'http', 'https', 'mailto'
42742 // white listed style attributes.
42743 Roo.HtmlEditorCore.cwhite= [
42744 // 'text-align', /// default is to allow most things..
42750 // black listed style attributes.
42751 Roo.HtmlEditorCore.cblack= [
42752 // 'font-size' -- this can be set by the project
42756 Roo.HtmlEditorCore.swapCodes =[
42767 //<script type="text/javascript">
42770 * Ext JS Library 1.1.1
42771 * Copyright(c) 2006-2007, Ext JS, LLC.
42777 Roo.form.HtmlEditor = function(config){
42781 Roo.form.HtmlEditor.superclass.constructor.call(this, config);
42783 if (!this.toolbars) {
42784 this.toolbars = [];
42786 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
42792 * @class Roo.form.HtmlEditor
42793 * @extends Roo.form.Field
42794 * Provides a lightweight HTML Editor component.
42796 * This has been tested on Fireforx / Chrome.. IE may not be so great..
42798 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
42799 * supported by this editor.</b><br/><br/>
42800 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
42801 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
42803 Roo.extend(Roo.form.HtmlEditor, Roo.form.Field, {
42805 * @cfg {Boolean} clearUp
42809 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
42814 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
42819 * @cfg {Number} height (in pixels)
42823 * @cfg {Number} width (in pixels)
42828 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
42831 stylesheets: false,
42835 * @cfg {Array} blacklist of css styles style attributes (blacklist overrides whitelist)
42840 * @cfg {Array} whitelist of css styles style attributes (blacklist overrides whitelist)
42846 * @cfg {Array} blacklist of html tags - in addition to standard blacklist.
42851 * @cfg {Array} whitelist of html tags - in addition to statndard whitelist
42859 // private properties
42860 validationEvent : false,
42862 initialized : false,
42865 onFocus : Roo.emptyFn,
42867 hideMode:'offsets',
42869 actionMode : 'container', // defaults to hiding it...
42871 defaultAutoCreate : { // modified by initCompnoent..
42873 style:"width:500px;height:300px;",
42874 autocomplete: "new-password"
42878 initComponent : function(){
42881 * @event initialize
42882 * Fires when the editor is fully initialized (including the iframe)
42883 * @param {HtmlEditor} this
42888 * Fires when the editor is first receives the focus. Any insertion must wait
42889 * until after this event.
42890 * @param {HtmlEditor} this
42894 * @event beforesync
42895 * Fires before the textarea is updated with content from the editor iframe. Return false
42896 * to cancel the sync.
42897 * @param {HtmlEditor} this
42898 * @param {String} html
42902 * @event beforepush
42903 * Fires before the iframe editor is updated with content from the textarea. Return false
42904 * to cancel the push.
42905 * @param {HtmlEditor} this
42906 * @param {String} html
42911 * Fires when the textarea is updated with content from the editor iframe.
42912 * @param {HtmlEditor} this
42913 * @param {String} html
42918 * Fires when the iframe editor is updated with content from the textarea.
42919 * @param {HtmlEditor} this
42920 * @param {String} html
42924 * @event editmodechange
42925 * Fires when the editor switches edit modes
42926 * @param {HtmlEditor} this
42927 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
42929 editmodechange: true,
42931 * @event editorevent
42932 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
42933 * @param {HtmlEditor} this
42937 * @event firstfocus
42938 * Fires when on first focus - needed by toolbars..
42939 * @param {HtmlEditor} this
42944 * Auto save the htmlEditor value as a file into Events
42945 * @param {HtmlEditor} this
42949 * @event savedpreview
42950 * preview the saved version of htmlEditor
42951 * @param {HtmlEditor} this
42953 savedpreview: true,
42956 * @event stylesheetsclick
42957 * Fires when press the Sytlesheets button
42958 * @param {Roo.HtmlEditorCore} this
42960 stylesheetsclick: true
42962 this.defaultAutoCreate = {
42964 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
42965 autocomplete: "new-password"
42970 * Protected method that will not generally be called directly. It
42971 * is called when the editor creates its toolbar. Override this method if you need to
42972 * add custom toolbar buttons.
42973 * @param {HtmlEditor} editor
42975 createToolbar : function(editor){
42976 Roo.log("create toolbars");
42977 if (!editor.toolbars || !editor.toolbars.length) {
42978 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
42981 for (var i =0 ; i < editor.toolbars.length;i++) {
42982 editor.toolbars[i] = Roo.factory(
42983 typeof(editor.toolbars[i]) == 'string' ?
42984 { xtype: editor.toolbars[i]} : editor.toolbars[i],
42985 Roo.form.HtmlEditor);
42986 editor.toolbars[i].init(editor);
42994 onRender : function(ct, position)
42997 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
42999 this.wrap = this.el.wrap({
43000 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
43003 this.editorcore.onRender(ct, position);
43005 if (this.resizable) {
43006 this.resizeEl = new Roo.Resizable(this.wrap, {
43010 minHeight : this.height,
43011 height: this.height,
43012 handles : this.resizable,
43015 resize : function(r, w, h) {
43016 _t.onResize(w,h); // -something
43022 this.createToolbar(this);
43026 this.setSize(this.wrap.getSize());
43028 if (this.resizeEl) {
43029 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
43030 // should trigger onReize..
43033 this.keyNav = new Roo.KeyNav(this.el, {
43035 "tab" : function(e){
43036 e.preventDefault();
43038 var value = this.getValue();
43040 var start = this.el.dom.selectionStart;
43041 var end = this.el.dom.selectionEnd;
43045 this.setValue(value.substring(0, start) + "\t" + value.substring(end));
43046 this.el.dom.setSelectionRange(end + 1, end + 1);
43050 var f = value.substring(0, start).split("\t");
43052 if(f.pop().length != 0){
43056 this.setValue(f.join("\t") + value.substring(end));
43057 this.el.dom.setSelectionRange(start - 1, start - 1);
43061 "home" : function(e){
43062 e.preventDefault();
43064 var curr = this.el.dom.selectionStart;
43065 var lines = this.getValue().split("\n");
43072 this.el.dom.setSelectionRange(0, 0);
43078 for (var i = 0; i < lines.length;i++) {
43079 pos += lines[i].length;
43089 pos -= lines[i].length;
43095 this.el.dom.setSelectionRange(pos, pos);
43099 this.el.dom.selectionStart = pos;
43100 this.el.dom.selectionEnd = curr;
43103 "end" : function(e){
43104 e.preventDefault();
43106 var curr = this.el.dom.selectionStart;
43107 var lines = this.getValue().split("\n");
43114 this.el.dom.setSelectionRange(this.getValue().length, this.getValue().length);
43120 for (var i = 0; i < lines.length;i++) {
43122 pos += lines[i].length;
43136 this.el.dom.setSelectionRange(pos, pos);
43140 this.el.dom.selectionStart = curr;
43141 this.el.dom.selectionEnd = pos;
43146 doRelay : function(foo, bar, hname){
43147 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
43153 // if(this.autosave && this.w){
43154 // this.autoSaveFn = setInterval(this.autosave, 1000);
43159 onResize : function(w, h)
43161 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
43166 if(typeof w == 'number'){
43167 var aw = w - this.wrap.getFrameWidth('lr');
43168 this.el.setWidth(this.adjustWidth('textarea', aw));
43171 if(typeof h == 'number'){
43173 for (var i =0; i < this.toolbars.length;i++) {
43174 // fixme - ask toolbars for heights?
43175 tbh += this.toolbars[i].tb.el.getHeight();
43176 if (this.toolbars[i].footer) {
43177 tbh += this.toolbars[i].footer.el.getHeight();
43184 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
43185 ah -= 5; // knock a few pixes off for look..
43187 this.el.setHeight(this.adjustWidth('textarea', ah));
43191 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
43192 this.editorcore.onResize(ew,eh);
43197 * Toggles the editor between standard and source edit mode.
43198 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
43200 toggleSourceEdit : function(sourceEditMode)
43202 this.editorcore.toggleSourceEdit(sourceEditMode);
43204 if(this.editorcore.sourceEditMode){
43205 Roo.log('editor - showing textarea');
43208 // Roo.log(this.syncValue());
43209 this.editorcore.syncValue();
43210 this.el.removeClass('x-hidden');
43211 this.el.dom.removeAttribute('tabIndex');
43214 for (var i = 0; i < this.toolbars.length; i++) {
43215 if(this.toolbars[i] instanceof Roo.form.HtmlEditor.ToolbarContext){
43216 this.toolbars[i].tb.hide();
43217 this.toolbars[i].footer.hide();
43222 Roo.log('editor - hiding textarea');
43224 // Roo.log(this.pushValue());
43225 this.editorcore.pushValue();
43227 this.el.addClass('x-hidden');
43228 this.el.dom.setAttribute('tabIndex', -1);
43230 for (var i = 0; i < this.toolbars.length; i++) {
43231 if(this.toolbars[i] instanceof Roo.form.HtmlEditor.ToolbarContext){
43232 this.toolbars[i].tb.show();
43233 this.toolbars[i].footer.show();
43237 //this.deferFocus();
43240 this.setSize(this.wrap.getSize());
43241 this.onResize(this.wrap.getSize().width, this.wrap.getSize().height);
43243 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
43246 // private (for BoxComponent)
43247 adjustSize : Roo.BoxComponent.prototype.adjustSize,
43249 // private (for BoxComponent)
43250 getResizeEl : function(){
43254 // private (for BoxComponent)
43255 getPositionEl : function(){
43260 initEvents : function(){
43261 this.originalValue = this.getValue();
43265 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
43268 markInvalid : Roo.emptyFn,
43270 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
43273 clearInvalid : Roo.emptyFn,
43275 setValue : function(v){
43276 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
43277 this.editorcore.pushValue();
43282 deferFocus : function(){
43283 this.focus.defer(10, this);
43287 focus : function(){
43288 this.editorcore.focus();
43294 onDestroy : function(){
43300 for (var i =0; i < this.toolbars.length;i++) {
43301 // fixme - ask toolbars for heights?
43302 this.toolbars[i].onDestroy();
43305 this.wrap.dom.innerHTML = '';
43306 this.wrap.remove();
43311 onFirstFocus : function(){
43312 //Roo.log("onFirstFocus");
43313 this.editorcore.onFirstFocus();
43314 for (var i =0; i < this.toolbars.length;i++) {
43315 this.toolbars[i].onFirstFocus();
43321 syncValue : function()
43323 this.editorcore.syncValue();
43326 pushValue : function()
43328 this.editorcore.pushValue();
43331 setStylesheets : function(stylesheets)
43333 this.editorcore.setStylesheets(stylesheets);
43336 removeStylesheets : function()
43338 this.editorcore.removeStylesheets();
43342 // hide stuff that is not compatible
43356 * @event specialkey
43360 * @cfg {String} fieldClass @hide
43363 * @cfg {String} focusClass @hide
43366 * @cfg {String} autoCreate @hide
43369 * @cfg {String} inputType @hide
43372 * @cfg {String} invalidClass @hide
43375 * @cfg {String} invalidText @hide
43378 * @cfg {String} msgFx @hide
43381 * @cfg {String} validateOnBlur @hide
43385 // <script type="text/javascript">
43388 * Ext JS Library 1.1.1
43389 * Copyright(c) 2006-2007, Ext JS, LLC.
43395 * @class Roo.form.HtmlEditorToolbar1
43400 new Roo.form.HtmlEditor({
43403 new Roo.form.HtmlEditorToolbar1({
43404 disable : { fonts: 1 , format: 1, ..., ... , ...],
43410 * @cfg {Object} disable List of elements to disable..
43411 * @cfg {Array} btns List of additional buttons.
43415 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
43418 Roo.form.HtmlEditor.ToolbarStandard = function(config)
43421 Roo.apply(this, config);
43423 // default disabled, based on 'good practice'..
43424 this.disable = this.disable || {};
43425 Roo.applyIf(this.disable, {
43428 specialElements : true
43432 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
43433 // dont call parent... till later.
43436 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
43443 editorcore : false,
43445 * @cfg {Object} disable List of toolbar elements to disable
43452 * @cfg {String} createLinkText The default text for the create link prompt
43454 createLinkText : 'Please enter the URL for the link:',
43456 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
43458 defaultLinkValue : 'http:/'+'/',
43462 * @cfg {Array} fontFamilies An array of available font families
43480 // "á" , ?? a acute?
43485 "°" // , // degrees
43487 // "é" , // e ecute
43488 // "ú" , // u ecute?
43491 specialElements : [
43493 text: "Insert Table",
43496 ihtml : '<table><tr><td>Cell</td></tr></table>'
43500 text: "Insert Image",
43503 ihtml : '<img src="about:blank"/>'
43512 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
43513 "input:submit", "input:button", "select", "textarea", "label" ],
43516 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
43518 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"],
43526 * @cfg {String} defaultFont default font to use.
43528 defaultFont: 'tahoma',
43530 fontSelect : false,
43533 formatCombo : false,
43535 init : function(editor)
43537 this.editor = editor;
43538 this.editorcore = editor.editorcore ? editor.editorcore : editor;
43539 var editorcore = this.editorcore;
43543 var fid = editorcore.frameId;
43545 function btn(id, toggle, handler){
43546 var xid = fid + '-'+ id ;
43550 cls : 'x-btn-icon x-edit-'+id,
43551 enableToggle:toggle !== false,
43552 scope: _t, // was editor...
43553 handler:handler||_t.relayBtnCmd,
43554 clickEvent:'mousedown',
43555 tooltip: etb.buttonTips[id] || undefined, ///tips ???
43562 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
43564 // stop form submits
43565 tb.el.on('click', function(e){
43566 e.preventDefault(); // what does this do?
43569 if(!this.disable.font) { // && !Roo.isSafari){
43570 /* why no safari for fonts
43571 editor.fontSelect = tb.el.createChild({
43574 cls:'x-font-select',
43575 html: this.createFontOptions()
43578 editor.fontSelect.on('change', function(){
43579 var font = editor.fontSelect.dom.value;
43580 editor.relayCmd('fontname', font);
43581 editor.deferFocus();
43585 editor.fontSelect.dom,
43591 if(!this.disable.formats){
43592 this.formatCombo = new Roo.form.ComboBox({
43593 store: new Roo.data.SimpleStore({
43596 data : this.formats // from states.js
43600 //autoCreate : {tag: "div", size: "20"},
43601 displayField:'tag',
43605 triggerAction: 'all',
43606 emptyText:'Add tag',
43607 selectOnFocus:true,
43610 'select': function(c, r, i) {
43611 editorcore.insertTag(r.get('tag'));
43617 tb.addField(this.formatCombo);
43621 if(!this.disable.format){
43628 if(!this.disable.fontSize){
43633 btn('increasefontsize', false, editorcore.adjustFont),
43634 btn('decreasefontsize', false, editorcore.adjustFont)
43639 if(!this.disable.colors){
43642 id:editorcore.frameId +'-forecolor',
43643 cls:'x-btn-icon x-edit-forecolor',
43644 clickEvent:'mousedown',
43645 tooltip: this.buttonTips['forecolor'] || undefined,
43647 menu : new Roo.menu.ColorMenu({
43648 allowReselect: true,
43649 focus: Roo.emptyFn,
43652 selectHandler: function(cp, color){
43653 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
43654 editor.deferFocus();
43657 clickEvent:'mousedown'
43660 id:editorcore.frameId +'backcolor',
43661 cls:'x-btn-icon x-edit-backcolor',
43662 clickEvent:'mousedown',
43663 tooltip: this.buttonTips['backcolor'] || undefined,
43665 menu : new Roo.menu.ColorMenu({
43666 focus: Roo.emptyFn,
43669 allowReselect: true,
43670 selectHandler: function(cp, color){
43672 editorcore.execCmd('useCSS', false);
43673 editorcore.execCmd('hilitecolor', color);
43674 editorcore.execCmd('useCSS', true);
43675 editor.deferFocus();
43677 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
43678 Roo.isSafari || Roo.isIE ? '#'+color : color);
43679 editor.deferFocus();
43683 clickEvent:'mousedown'
43688 // now add all the items...
43691 if(!this.disable.alignments){
43694 btn('justifyleft'),
43695 btn('justifycenter'),
43696 btn('justifyright')
43700 //if(!Roo.isSafari){
43701 if(!this.disable.links){
43704 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
43708 if(!this.disable.lists){
43711 btn('insertorderedlist'),
43712 btn('insertunorderedlist')
43715 if(!this.disable.sourceEdit){
43718 btn('sourceedit', true, function(btn){
43719 this.toggleSourceEdit(btn.pressed);
43726 // special menu.. - needs to be tidied up..
43727 if (!this.disable.special) {
43730 cls: 'x-edit-none',
43736 for (var i =0; i < this.specialChars.length; i++) {
43737 smenu.menu.items.push({
43739 html: this.specialChars[i],
43740 handler: function(a,b) {
43741 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
43742 //editor.insertAtCursor(a.html);
43756 if (!this.disable.cleanStyles) {
43758 cls: 'x-btn-icon x-btn-clear',
43764 for (var i =0; i < this.cleanStyles.length; i++) {
43765 cmenu.menu.items.push({
43766 actiontype : this.cleanStyles[i],
43767 html: 'Remove ' + this.cleanStyles[i],
43768 handler: function(a,b) {
43771 var c = Roo.get(editorcore.doc.body);
43772 c.select('[style]').each(function(s) {
43773 s.dom.style.removeProperty(a.actiontype);
43775 editorcore.syncValue();
43780 cmenu.menu.items.push({
43781 actiontype : 'tablewidths',
43782 html: 'Remove Table Widths',
43783 handler: function(a,b) {
43784 editorcore.cleanTableWidths();
43785 editorcore.syncValue();
43789 cmenu.menu.items.push({
43790 actiontype : 'word',
43791 html: 'Remove MS Word Formating',
43792 handler: function(a,b) {
43793 editorcore.cleanWord();
43794 editorcore.syncValue();
43799 cmenu.menu.items.push({
43800 actiontype : 'all',
43801 html: 'Remove All Styles',
43802 handler: function(a,b) {
43804 var c = Roo.get(editorcore.doc.body);
43805 c.select('[style]').each(function(s) {
43806 s.dom.removeAttribute('style');
43808 editorcore.syncValue();
43812 cmenu.menu.items.push({
43813 actiontype : 'tidy',
43814 html: 'Tidy HTML Source',
43815 handler: function(a,b) {
43816 editorcore.doc.body.innerHTML = editorcore.domToHTML();
43817 editorcore.syncValue();
43826 if (!this.disable.specialElements) {
43829 cls: 'x-edit-none',
43834 for (var i =0; i < this.specialElements.length; i++) {
43835 semenu.menu.items.push(
43837 handler: function(a,b) {
43838 editor.insertAtCursor(this.ihtml);
43840 }, this.specialElements[i])
43852 for(var i =0; i< this.btns.length;i++) {
43853 var b = Roo.factory(this.btns[i],Roo.form);
43854 b.cls = 'x-edit-none';
43856 if(typeof(this.btns[i].cls) != 'undefined' && this.btns[i].cls.indexOf('x-init-enable') !== -1){
43857 b.cls += ' x-init-enable';
43860 b.scope = editorcore;
43868 // disable everything...
43870 this.tb.items.each(function(item){
43873 item.id != editorcore.frameId+ '-sourceedit' &&
43874 (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)
43880 this.rendered = true;
43882 // the all the btns;
43883 editor.on('editorevent', this.updateToolbar, this);
43884 // other toolbars need to implement this..
43885 //editor.on('editmodechange', this.updateToolbar, this);
43889 relayBtnCmd : function(btn) {
43890 this.editorcore.relayCmd(btn.cmd);
43892 // private used internally
43893 createLink : function(){
43894 Roo.log("create link?");
43895 var url = prompt(this.createLinkText, this.defaultLinkValue);
43896 if(url && url != 'http:/'+'/'){
43897 this.editorcore.relayCmd('createlink', url);
43903 * Protected method that will not generally be called directly. It triggers
43904 * a toolbar update by reading the markup state of the current selection in the editor.
43906 updateToolbar: function(){
43908 if(!this.editorcore.activated){
43909 this.editor.onFirstFocus();
43913 var btns = this.tb.items.map,
43914 doc = this.editorcore.doc,
43915 frameId = this.editorcore.frameId;
43917 if(!this.disable.font && !Roo.isSafari){
43919 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
43920 if(name != this.fontSelect.dom.value){
43921 this.fontSelect.dom.value = name;
43925 if(!this.disable.format){
43926 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
43927 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
43928 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
43930 if(!this.disable.alignments){
43931 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
43932 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
43933 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
43935 if(!Roo.isSafari && !this.disable.lists){
43936 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
43937 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
43940 var ans = this.editorcore.getAllAncestors();
43941 if (this.formatCombo) {
43944 var store = this.formatCombo.store;
43945 this.formatCombo.setValue("");
43946 for (var i =0; i < ans.length;i++) {
43947 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
43949 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
43957 // hides menus... - so this cant be on a menu...
43958 Roo.menu.MenuMgr.hideAll();
43960 //this.editorsyncValue();
43964 createFontOptions : function(){
43965 var buf = [], fs = this.fontFamilies, ff, lc;
43969 for(var i = 0, len = fs.length; i< len; i++){
43971 lc = ff.toLowerCase();
43973 '<option value="',lc,'" style="font-family:',ff,';"',
43974 (this.defaultFont == lc ? ' selected="true">' : '>'),
43979 return buf.join('');
43982 toggleSourceEdit : function(sourceEditMode){
43984 Roo.log("toolbar toogle");
43985 if(sourceEditMode === undefined){
43986 sourceEditMode = !this.sourceEditMode;
43988 this.sourceEditMode = sourceEditMode === true;
43989 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
43990 // just toggle the button?
43991 if(btn.pressed !== this.sourceEditMode){
43992 btn.toggle(this.sourceEditMode);
43996 if(sourceEditMode){
43997 Roo.log("disabling buttons");
43998 this.tb.items.each(function(item){
43999 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
44005 Roo.log("enabling buttons");
44006 if(this.editorcore.initialized){
44007 this.tb.items.each(function(item){
44013 Roo.log("calling toggole on editor");
44014 // tell the editor that it's been pressed..
44015 this.editor.toggleSourceEdit(sourceEditMode);
44019 * Object collection of toolbar tooltips for the buttons in the editor. The key
44020 * is the command id associated with that button and the value is a valid QuickTips object.
44025 title: 'Bold (Ctrl+B)',
44026 text: 'Make the selected text bold.',
44027 cls: 'x-html-editor-tip'
44030 title: 'Italic (Ctrl+I)',
44031 text: 'Make the selected text italic.',
44032 cls: 'x-html-editor-tip'
44040 title: 'Bold (Ctrl+B)',
44041 text: 'Make the selected text bold.',
44042 cls: 'x-html-editor-tip'
44045 title: 'Italic (Ctrl+I)',
44046 text: 'Make the selected text italic.',
44047 cls: 'x-html-editor-tip'
44050 title: 'Underline (Ctrl+U)',
44051 text: 'Underline the selected text.',
44052 cls: 'x-html-editor-tip'
44054 increasefontsize : {
44055 title: 'Grow Text',
44056 text: 'Increase the font size.',
44057 cls: 'x-html-editor-tip'
44059 decreasefontsize : {
44060 title: 'Shrink Text',
44061 text: 'Decrease the font size.',
44062 cls: 'x-html-editor-tip'
44065 title: 'Text Highlight Color',
44066 text: 'Change the background color of the selected text.',
44067 cls: 'x-html-editor-tip'
44070 title: 'Font Color',
44071 text: 'Change the color of the selected text.',
44072 cls: 'x-html-editor-tip'
44075 title: 'Align Text Left',
44076 text: 'Align text to the left.',
44077 cls: 'x-html-editor-tip'
44080 title: 'Center Text',
44081 text: 'Center text in the editor.',
44082 cls: 'x-html-editor-tip'
44085 title: 'Align Text Right',
44086 text: 'Align text to the right.',
44087 cls: 'x-html-editor-tip'
44089 insertunorderedlist : {
44090 title: 'Bullet List',
44091 text: 'Start a bulleted list.',
44092 cls: 'x-html-editor-tip'
44094 insertorderedlist : {
44095 title: 'Numbered List',
44096 text: 'Start a numbered list.',
44097 cls: 'x-html-editor-tip'
44100 title: 'Hyperlink',
44101 text: 'Make the selected text a hyperlink.',
44102 cls: 'x-html-editor-tip'
44105 title: 'Source Edit',
44106 text: 'Switch to source editing mode.',
44107 cls: 'x-html-editor-tip'
44111 onDestroy : function(){
44114 this.tb.items.each(function(item){
44116 item.menu.removeAll();
44118 item.menu.el.destroy();
44126 onFirstFocus: function() {
44127 this.tb.items.each(function(item){
44136 // <script type="text/javascript">
44139 * Ext JS Library 1.1.1
44140 * Copyright(c) 2006-2007, Ext JS, LLC.
44147 * @class Roo.form.HtmlEditor.ToolbarContext
44152 new Roo.form.HtmlEditor({
44155 { xtype: 'ToolbarStandard', styles : {} }
44156 { xtype: 'ToolbarContext', disable : {} }
44162 * @config : {Object} disable List of elements to disable.. (not done yet.)
44163 * @config : {Object} styles Map of styles available.
44167 Roo.form.HtmlEditor.ToolbarContext = function(config)
44170 Roo.apply(this, config);
44171 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
44172 // dont call parent... till later.
44173 this.styles = this.styles || {};
44178 Roo.form.HtmlEditor.ToolbarContext.types = {
44190 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
44256 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
44261 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
44271 style : 'fontFamily',
44272 displayField: 'display',
44273 optname : 'font-family',
44322 // should we really allow this??
44323 // should this just be
44334 style : 'fontFamily',
44335 displayField: 'display',
44336 optname : 'font-family',
44343 style : 'fontFamily',
44344 displayField: 'display',
44345 optname : 'font-family',
44352 style : 'fontFamily',
44353 displayField: 'display',
44354 optname : 'font-family',
44365 // this should be configurable.. - you can either set it up using stores, or modify options somehwere..
44366 Roo.form.HtmlEditor.ToolbarContext.stores = false;
44368 Roo.form.HtmlEditor.ToolbarContext.options = {
44370 [ 'Helvetica,Arial,sans-serif', 'Helvetica'],
44371 [ 'Courier New', 'Courier New'],
44372 [ 'Tahoma', 'Tahoma'],
44373 [ 'Times New Roman,serif', 'Times'],
44374 [ 'Verdana','Verdana' ]
44378 // fixme - these need to be configurable..
44381 Roo.form.HtmlEditor.ToolbarContext.types
44384 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
44391 editorcore : false,
44393 * @cfg {Object} disable List of toolbar elements to disable
44398 * @cfg {Object} styles List of styles
44399 * eg. { '*' : [ 'headline' ] , 'TD' : [ 'underline', 'double-underline' ] }
44401 * These must be defined in the page, so they get rendered correctly..
44412 init : function(editor)
44414 this.editor = editor;
44415 this.editorcore = editor.editorcore ? editor.editorcore : editor;
44416 var editorcore = this.editorcore;
44418 var fid = editorcore.frameId;
44420 function btn(id, toggle, handler){
44421 var xid = fid + '-'+ id ;
44425 cls : 'x-btn-icon x-edit-'+id,
44426 enableToggle:toggle !== false,
44427 scope: editorcore, // was editor...
44428 handler:handler||editorcore.relayBtnCmd,
44429 clickEvent:'mousedown',
44430 tooltip: etb.buttonTips[id] || undefined, ///tips ???
44434 // create a new element.
44435 var wdiv = editor.wrap.createChild({
44437 }, editor.wrap.dom.firstChild.nextSibling, true);
44439 // can we do this more than once??
44441 // stop form submits
44444 // disable everything...
44445 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
44446 this.toolbars = {};
44448 for (var i in ty) {
44450 this.toolbars[i] = this.buildToolbar(ty[i],i);
44452 this.tb = this.toolbars.BODY;
44454 this.buildFooter();
44455 this.footer.show();
44456 editor.on('hide', function( ) { this.footer.hide() }, this);
44457 editor.on('show', function( ) { this.footer.show() }, this);
44460 this.rendered = true;
44462 // the all the btns;
44463 editor.on('editorevent', this.updateToolbar, this);
44464 // other toolbars need to implement this..
44465 //editor.on('editmodechange', this.updateToolbar, this);
44471 * Protected method that will not generally be called directly. It triggers
44472 * a toolbar update by reading the markup state of the current selection in the editor.
44474 * Note you can force an update by calling on('editorevent', scope, false)
44476 updateToolbar: function(editor,ev,sel){
44479 // capture mouse up - this is handy for selecting images..
44480 // perhaps should go somewhere else...
44481 if(!this.editorcore.activated){
44482 this.editor.onFirstFocus();
44488 // http://developer.yahoo.com/yui/docs/simple-editor.js.html
44489 // selectNode - might want to handle IE?
44491 (ev.type == 'mouseup' || ev.type == 'click' ) &&
44492 ev.target && ev.target.tagName == 'IMG') {
44493 // they have click on an image...
44494 // let's see if we can change the selection...
44497 var nodeRange = sel.ownerDocument.createRange();
44499 nodeRange.selectNode(sel);
44501 nodeRange.selectNodeContents(sel);
44503 //nodeRange.collapse(true);
44504 var s = this.editorcore.win.getSelection();
44505 s.removeAllRanges();
44506 s.addRange(nodeRange);
44510 var updateFooter = sel ? false : true;
44513 var ans = this.editorcore.getAllAncestors();
44516 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
44519 sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editorcore.doc.body;
44520 sel = sel ? sel : this.editorcore.doc.body;
44521 sel = sel.tagName.length ? sel : this.editorcore.doc.body;
44524 // pick a menu that exists..
44525 var tn = sel.tagName.toUpperCase();
44526 //sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
44528 tn = sel.tagName.toUpperCase();
44530 var lastSel = this.tb.selectedNode
44532 this.tb.selectedNode = sel;
44534 // if current menu does not match..
44536 if ((this.tb.name != tn) || (lastSel != this.tb.selectedNode) || ev === false) {
44539 ///console.log("show: " + tn);
44540 this.tb = typeof(ty[tn]) != 'undefined' ? this.toolbars[tn] : this.toolbars['*'];
44543 this.tb.items.first().el.innerHTML = tn + ': ';
44546 // update attributes
44547 if (this.tb.fields) {
44548 this.tb.fields.each(function(e) {
44550 e.setValue(sel.style[e.stylename]);
44553 e.setValue(sel.getAttribute(e.attrname));
44557 var hasStyles = false;
44558 for(var i in this.styles) {
44565 var st = this.tb.fields.item(0);
44567 st.store.removeAll();
44570 var cn = sel.className.split(/\s+/);
44573 if (this.styles['*']) {
44575 Roo.each(this.styles['*'], function(v) {
44576 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
44579 if (this.styles[tn]) {
44580 Roo.each(this.styles[tn], function(v) {
44581 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
44585 st.store.loadData(avs);
44589 // flag our selected Node.
44590 this.tb.selectedNode = sel;
44593 Roo.menu.MenuMgr.hideAll();
44597 if (!updateFooter) {
44598 //this.footDisp.dom.innerHTML = '';
44601 // update the footer
44605 this.footerEls = ans.reverse();
44606 Roo.each(this.footerEls, function(a,i) {
44607 if (!a) { return; }
44608 html += html.length ? ' > ' : '';
44610 html += '<span class="x-ed-loc-' + i + '">' + a.tagName + '</span>';
44615 var sz = this.footDisp.up('td').getSize();
44616 this.footDisp.dom.style.width = (sz.width -10) + 'px';
44617 this.footDisp.dom.style.marginLeft = '5px';
44619 this.footDisp.dom.style.overflow = 'hidden';
44621 this.footDisp.dom.innerHTML = html;
44623 //this.editorsyncValue();
44630 onDestroy : function(){
44633 this.tb.items.each(function(item){
44635 item.menu.removeAll();
44637 item.menu.el.destroy();
44645 onFirstFocus: function() {
44646 // need to do this for all the toolbars..
44647 this.tb.items.each(function(item){
44651 buildToolbar: function(tlist, nm)
44653 var editor = this.editor;
44654 var editorcore = this.editorcore;
44655 // create a new element.
44656 var wdiv = editor.wrap.createChild({
44658 }, editor.wrap.dom.firstChild.nextSibling, true);
44661 var tb = new Roo.Toolbar(wdiv);
44664 tb.add(nm+ ": ");
44667 for(var i in this.styles) {
44672 if (styles && styles.length) {
44674 // this needs a multi-select checkbox...
44675 tb.addField( new Roo.form.ComboBox({
44676 store: new Roo.data.SimpleStore({
44678 fields: ['val', 'selected'],
44681 name : '-roo-edit-className',
44682 attrname : 'className',
44683 displayField: 'val',
44687 triggerAction: 'all',
44688 emptyText:'Select Style',
44689 selectOnFocus:true,
44692 'select': function(c, r, i) {
44693 // initial support only for on class per el..
44694 tb.selectedNode.className = r ? r.get('val') : '';
44695 editorcore.syncValue();
44702 var tbc = Roo.form.HtmlEditor.ToolbarContext;
44703 var tbops = tbc.options;
44705 for (var i in tlist) {
44707 var item = tlist[i];
44708 tb.add(item.title + ": ");
44711 //optname == used so you can configure the options available..
44712 var opts = item.opts ? item.opts : false;
44713 if (item.optname) {
44714 opts = tbops[item.optname];
44719 // opts == pulldown..
44720 tb.addField( new Roo.form.ComboBox({
44721 store: typeof(tbc.stores[i]) != 'undefined' ? Roo.factory(tbc.stores[i],Roo.data) : new Roo.data.SimpleStore({
44723 fields: ['val', 'display'],
44726 name : '-roo-edit-' + i,
44728 stylename : item.style ? item.style : false,
44729 displayField: item.displayField ? item.displayField : 'val',
44730 valueField : 'val',
44732 mode: typeof(tbc.stores[i]) != 'undefined' ? 'remote' : 'local',
44734 triggerAction: 'all',
44735 emptyText:'Select',
44736 selectOnFocus:true,
44737 width: item.width ? item.width : 130,
44739 'select': function(c, r, i) {
44741 tb.selectedNode.style[c.stylename] = r.get('val');
44744 tb.selectedNode.setAttribute(c.attrname, r.get('val'));
44753 tb.addField( new Roo.form.TextField({
44756 //allowBlank:false,
44761 tb.addField( new Roo.form.TextField({
44762 name: '-roo-edit-' + i,
44769 'change' : function(f, nv, ov) {
44770 tb.selectedNode.setAttribute(f.attrname, nv);
44783 text: 'Stylesheets',
44786 click : function ()
44788 _this.editor.fireEvent('stylesheetsclick', _this.editor);
44796 text: 'Remove Tag',
44799 click : function ()
44802 // undo does not work.
44804 var sn = tb.selectedNode;
44806 var pn = sn.parentNode;
44808 var stn = sn.childNodes[0];
44809 var en = sn.childNodes[sn.childNodes.length - 1 ];
44810 while (sn.childNodes.length) {
44811 var node = sn.childNodes[0];
44812 sn.removeChild(node);
44814 pn.insertBefore(node, sn);
44817 pn.removeChild(sn);
44818 var range = editorcore.createRange();
44820 range.setStart(stn,0);
44821 range.setEnd(en,0); //????
44822 //range.selectNode(sel);
44825 var selection = editorcore.getSelection();
44826 selection.removeAllRanges();
44827 selection.addRange(range);
44831 //_this.updateToolbar(null, null, pn);
44832 _this.updateToolbar(null, null, null);
44833 _this.footDisp.dom.innerHTML = '';
44843 tb.el.on('click', function(e){
44844 e.preventDefault(); // what does this do?
44846 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
44849 // dont need to disable them... as they will get hidden
44854 buildFooter : function()
44857 var fel = this.editor.wrap.createChild();
44858 this.footer = new Roo.Toolbar(fel);
44859 // toolbar has scrolly on left / right?
44860 var footDisp= new Roo.Toolbar.Fill();
44866 handler : function() {
44867 _t.footDisp.scrollTo('left',0,true)
44871 this.footer.add( footDisp );
44876 handler : function() {
44878 _t.footDisp.select('span').last().scrollIntoView(_t.footDisp,true);
44882 var fel = Roo.get(footDisp.el);
44883 fel.addClass('x-editor-context');
44884 this.footDispWrap = fel;
44885 this.footDispWrap.overflow = 'hidden';
44887 this.footDisp = fel.createChild();
44888 this.footDispWrap.on('click', this.onContextClick, this)
44892 onContextClick : function (ev,dom)
44894 ev.preventDefault();
44895 var cn = dom.className;
44897 if (!cn.match(/x-ed-loc-/)) {
44900 var n = cn.split('-').pop();
44901 var ans = this.footerEls;
44905 var range = this.editorcore.createRange();
44907 range.selectNodeContents(sel);
44908 //range.selectNode(sel);
44911 var selection = this.editorcore.getSelection();
44912 selection.removeAllRanges();
44913 selection.addRange(range);
44917 this.updateToolbar(null, null, sel);
44934 * Ext JS Library 1.1.1
44935 * Copyright(c) 2006-2007, Ext JS, LLC.
44937 * Originally Released Under LGPL - original licence link has changed is not relivant.
44940 * <script type="text/javascript">
44944 * @class Roo.form.BasicForm
44945 * @extends Roo.util.Observable
44946 * Supplies the functionality to do "actions" on forms and initialize Roo.form.Field types on existing markup.
44948 * @param {String/HTMLElement/Roo.Element} el The form element or its id
44949 * @param {Object} config Configuration options
44951 Roo.form.BasicForm = function(el, config){
44952 this.allItems = [];
44953 this.childForms = [];
44954 Roo.apply(this, config);
44956 * The Roo.form.Field items in this form.
44957 * @type MixedCollection
44961 this.items = new Roo.util.MixedCollection(false, function(o){
44962 return o.id || (o.id = Roo.id());
44966 * @event beforeaction
44967 * Fires before any action is performed. Return false to cancel the action.
44968 * @param {Form} this
44969 * @param {Action} action The action to be performed
44971 beforeaction: true,
44973 * @event actionfailed
44974 * Fires when an action fails.
44975 * @param {Form} this
44976 * @param {Action} action The action that failed
44978 actionfailed : true,
44980 * @event actioncomplete
44981 * Fires when an action is completed.
44982 * @param {Form} this
44983 * @param {Action} action The action that completed
44985 actioncomplete : true
44990 Roo.form.BasicForm.superclass.constructor.call(this);
44993 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
44995 * @cfg {String} method
44996 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
44999 * @cfg {DataReader} reader
45000 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when executing "load" actions.
45001 * This is optional as there is built-in support for processing JSON.
45004 * @cfg {DataReader} errorReader
45005 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
45006 * This is completely optional as there is built-in support for processing JSON.
45009 * @cfg {String} url
45010 * The URL to use for form actions if one isn't supplied in the action options.
45013 * @cfg {Boolean} fileUpload
45014 * Set to true if this form is a file upload.
45018 * @cfg {Object} baseParams
45019 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
45024 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
45029 activeAction : null,
45032 * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded
45033 * or setValues() data instead of when the form was first created.
45035 trackResetOnLoad : false,
45039 * childForms - used for multi-tab forms
45042 childForms : false,
45045 * allItems - full list of fields.
45051 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
45052 * element by passing it or its id or mask the form itself by passing in true.
45055 waitMsgTarget : false,
45058 initEl : function(el){
45059 this.el = Roo.get(el);
45060 this.id = this.el.id || Roo.id();
45061 this.el.on('submit', this.onSubmit, this);
45062 this.el.addClass('x-form');
45066 onSubmit : function(e){
45071 * Returns true if client-side validation on the form is successful.
45074 isValid : function(){
45076 this.items.each(function(f){
45085 * Returns true if any fields in this form have changed since their original load.
45088 isDirty : function(){
45090 this.items.each(function(f){
45100 * Performs a predefined action (submit or load) or custom actions you define on this form.
45101 * @param {String} actionName The name of the action type
45102 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
45103 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
45104 * accept other config options):
45106 Property Type Description
45107 ---------------- --------------- ----------------------------------------------------------------------------------
45108 url String The url for the action (defaults to the form's url)
45109 method String The form method to use (defaults to the form's method, or POST if not defined)
45110 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
45111 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
45112 validate the form on the client (defaults to false)
45114 * @return {BasicForm} this
45116 doAction : function(action, options){
45117 if(typeof action == 'string'){
45118 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
45120 if(this.fireEvent('beforeaction', this, action) !== false){
45121 this.beforeAction(action);
45122 action.run.defer(100, action);
45128 * Shortcut to do a submit action.
45129 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
45130 * @return {BasicForm} this
45132 submit : function(options){
45133 this.doAction('submit', options);
45138 * Shortcut to do a load action.
45139 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
45140 * @return {BasicForm} this
45142 load : function(options){
45143 this.doAction('load', options);
45148 * Persists the values in this form into the passed Roo.data.Record object in a beginEdit/endEdit block.
45149 * @param {Record} record The record to edit
45150 * @return {BasicForm} this
45152 updateRecord : function(record){
45153 record.beginEdit();
45154 var fs = record.fields;
45155 fs.each(function(f){
45156 var field = this.findField(f.name);
45158 record.set(f.name, field.getValue());
45166 * Loads an Roo.data.Record into this form.
45167 * @param {Record} record The record to load
45168 * @return {BasicForm} this
45170 loadRecord : function(record){
45171 this.setValues(record.data);
45176 beforeAction : function(action){
45177 var o = action.options;
45180 if(this.waitMsgTarget === true){
45181 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
45182 }else if(this.waitMsgTarget){
45183 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
45184 this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
45186 Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
45192 afterAction : function(action, success){
45193 this.activeAction = null;
45194 var o = action.options;
45196 if(this.waitMsgTarget === true){
45198 }else if(this.waitMsgTarget){
45199 this.waitMsgTarget.unmask();
45201 Roo.MessageBox.updateProgress(1);
45202 Roo.MessageBox.hide();
45209 Roo.callback(o.success, o.scope, [this, action]);
45210 this.fireEvent('actioncomplete', this, action);
45214 // failure condition..
45215 // we have a scenario where updates need confirming.
45216 // eg. if a locking scenario exists..
45217 // we look for { errors : { needs_confirm : true }} in the response.
45219 (typeof(action.result) != 'undefined') &&
45220 (typeof(action.result.errors) != 'undefined') &&
45221 (typeof(action.result.errors.needs_confirm) != 'undefined')
45224 Roo.MessageBox.confirm(
45225 "Change requires confirmation",
45226 action.result.errorMsg,
45231 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
45241 Roo.callback(o.failure, o.scope, [this, action]);
45242 // show an error message if no failed handler is set..
45243 if (!this.hasListener('actionfailed')) {
45244 Roo.MessageBox.alert("Error",
45245 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
45246 action.result.errorMsg :
45247 "Saving Failed, please check your entries or try again"
45251 this.fireEvent('actionfailed', this, action);
45257 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
45258 * @param {String} id The value to search for
45261 findField : function(id){
45262 var field = this.items.get(id);
45264 this.items.each(function(f){
45265 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
45271 return field || null;
45275 * Add a secondary form to this one,
45276 * Used to provide tabbed forms. One form is primary, with hidden values
45277 * which mirror the elements from the other forms.
45279 * @param {Roo.form.Form} form to add.
45282 addForm : function(form)
45285 if (this.childForms.indexOf(form) > -1) {
45289 this.childForms.push(form);
45291 Roo.each(form.allItems, function (fe) {
45293 n = typeof(fe.getName) == 'undefined' ? fe.name : fe.getName();
45294 if (this.findField(n)) { // already added..
45297 var add = new Roo.form.Hidden({
45300 add.render(this.el);
45307 * Mark fields in this form invalid in bulk.
45308 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
45309 * @return {BasicForm} this
45311 markInvalid : function(errors){
45312 if(errors instanceof Array){
45313 for(var i = 0, len = errors.length; i < len; i++){
45314 var fieldError = errors[i];
45315 var f = this.findField(fieldError.id);
45317 f.markInvalid(fieldError.msg);
45323 if(typeof errors[id] != 'function' && (field = this.findField(id))){
45324 field.markInvalid(errors[id]);
45328 Roo.each(this.childForms || [], function (f) {
45329 f.markInvalid(errors);
45336 * Set values for fields in this form in bulk.
45337 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
45338 * @return {BasicForm} this
45340 setValues : function(values){
45341 if(values instanceof Array){ // array of objects
45342 for(var i = 0, len = values.length; i < len; i++){
45344 var f = this.findField(v.id);
45346 f.setValue(v.value);
45347 if(this.trackResetOnLoad){
45348 f.originalValue = f.getValue();
45352 }else{ // object hash
45355 if(typeof values[id] != 'function' && (field = this.findField(id))){
45357 if (field.setFromData &&
45358 field.valueField &&
45359 field.displayField &&
45360 // combos' with local stores can
45361 // be queried via setValue()
45362 // to set their value..
45363 (field.store && !field.store.isLocal)
45367 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
45368 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
45369 field.setFromData(sd);
45372 field.setValue(values[id]);
45376 if(this.trackResetOnLoad){
45377 field.originalValue = field.getValue();
45383 Roo.each(this.childForms || [], function (f) {
45384 f.setValues(values);
45391 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
45392 * they are returned as an array.
45393 * @param {Boolean} asString
45396 getValues : function(asString){
45397 if (this.childForms) {
45398 // copy values from the child forms
45399 Roo.each(this.childForms, function (f) {
45400 this.setValues(f.getValues());
45406 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
45407 if(asString === true){
45410 return Roo.urlDecode(fs);
45414 * Returns the fields in this form as an object with key/value pairs.
45415 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
45418 getFieldValues : function(with_hidden)
45420 if (this.childForms) {
45421 // copy values from the child forms
45422 // should this call getFieldValues - probably not as we do not currently copy
45423 // hidden fields when we generate..
45424 Roo.each(this.childForms, function (f) {
45425 this.setValues(f.getValues());
45430 this.items.each(function(f){
45431 if (!f.getName()) {
45434 var v = f.getValue();
45435 if (f.inputType =='radio') {
45436 if (typeof(ret[f.getName()]) == 'undefined') {
45437 ret[f.getName()] = ''; // empty..
45440 if (!f.el.dom.checked) {
45444 v = f.el.dom.value;
45448 // not sure if this supported any more..
45449 if ((typeof(v) == 'object') && f.getRawValue) {
45450 v = f.getRawValue() ; // dates..
45452 // combo boxes where name != hiddenName...
45453 if (f.name != f.getName()) {
45454 ret[f.name] = f.getRawValue();
45456 ret[f.getName()] = v;
45463 * Clears all invalid messages in this form.
45464 * @return {BasicForm} this
45466 clearInvalid : function(){
45467 this.items.each(function(f){
45471 Roo.each(this.childForms || [], function (f) {
45480 * Resets this form.
45481 * @return {BasicForm} this
45483 reset : function(){
45484 this.items.each(function(f){
45488 Roo.each(this.childForms || [], function (f) {
45497 * Add Roo.form components to this form.
45498 * @param {Field} field1
45499 * @param {Field} field2 (optional)
45500 * @param {Field} etc (optional)
45501 * @return {BasicForm} this
45504 this.items.addAll(Array.prototype.slice.call(arguments, 0));
45510 * Removes a field from the items collection (does NOT remove its markup).
45511 * @param {Field} field
45512 * @return {BasicForm} this
45514 remove : function(field){
45515 this.items.remove(field);
45520 * Looks at the fields in this form, checks them for an id attribute,
45521 * and calls applyTo on the existing dom element with that id.
45522 * @return {BasicForm} this
45524 render : function(){
45525 this.items.each(function(f){
45526 if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
45534 * Calls {@link Ext#apply} for all fields in this form with the passed object.
45535 * @param {Object} values
45536 * @return {BasicForm} this
45538 applyToFields : function(o){
45539 this.items.each(function(f){
45546 * Calls {@link Ext#applyIf} for all field in this form with the passed object.
45547 * @param {Object} values
45548 * @return {BasicForm} this
45550 applyIfToFields : function(o){
45551 this.items.each(function(f){
45559 Roo.BasicForm = Roo.form.BasicForm;/*
45561 * Ext JS Library 1.1.1
45562 * Copyright(c) 2006-2007, Ext JS, LLC.
45564 * Originally Released Under LGPL - original licence link has changed is not relivant.
45567 * <script type="text/javascript">
45571 * @class Roo.form.Form
45572 * @extends Roo.form.BasicForm
45573 * Adds the ability to dynamically render forms with JavaScript to {@link Roo.form.BasicForm}.
45575 * @param {Object} config Configuration options
45577 Roo.form.Form = function(config){
45579 if (config.items) {
45580 xitems = config.items;
45581 delete config.items;
45585 Roo.form.Form.superclass.constructor.call(this, null, config);
45586 this.url = this.url || this.action;
45588 this.root = new Roo.form.Layout(Roo.applyIf({
45592 this.active = this.root;
45594 * Array of all the buttons that have been added to this form via {@link addButton}
45598 this.allItems = [];
45601 * @event clientvalidation
45602 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
45603 * @param {Form} this
45604 * @param {Boolean} valid true if the form has passed client-side validation
45606 clientvalidation: true,
45609 * Fires when the form is rendered
45610 * @param {Roo.form.Form} form
45615 if (this.progressUrl) {
45616 // push a hidden field onto the list of fields..
45620 name : 'UPLOAD_IDENTIFIER'
45625 Roo.each(xitems, this.addxtype, this);
45631 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
45633 * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
45636 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
45639 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
45641 buttonAlign:'center',
45644 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
45649 * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
45650 * This property cascades to child containers if not set.
45655 * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
45656 * fires a looping event with that state. This is required to bind buttons to the valid
45657 * state using the config value formBind:true on the button.
45659 monitorValid : false,
45662 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
45667 * @cfg {String} progressUrl - Url to return progress data
45670 progressUrl : false,
45673 * Opens a new {@link Roo.form.Column} container in the layout stack. If fields are passed after the config, the
45674 * fields are added and the column is closed. If no fields are passed the column remains open
45675 * until end() is called.
45676 * @param {Object} config The config to pass to the column
45677 * @param {Field} field1 (optional)
45678 * @param {Field} field2 (optional)
45679 * @param {Field} etc (optional)
45680 * @return Column The column container object
45682 column : function(c){
45683 var col = new Roo.form.Column(c);
45685 if(arguments.length > 1){ // duplicate code required because of Opera
45686 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
45693 * Opens a new {@link Roo.form.FieldSet} container in the layout stack. If fields are passed after the config, the
45694 * fields are added and the fieldset is closed. If no fields are passed the fieldset remains open
45695 * until end() is called.
45696 * @param {Object} config The config to pass to the fieldset
45697 * @param {Field} field1 (optional)
45698 * @param {Field} field2 (optional)
45699 * @param {Field} etc (optional)
45700 * @return FieldSet The fieldset container object
45702 fieldset : function(c){
45703 var fs = new Roo.form.FieldSet(c);
45705 if(arguments.length > 1){ // duplicate code required because of Opera
45706 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
45713 * Opens a new {@link Roo.form.Layout} container in the layout stack. If fields are passed after the config, the
45714 * fields are added and the container is closed. If no fields are passed the container remains open
45715 * until end() is called.
45716 * @param {Object} config The config to pass to the Layout
45717 * @param {Field} field1 (optional)
45718 * @param {Field} field2 (optional)
45719 * @param {Field} etc (optional)
45720 * @return Layout The container object
45722 container : function(c){
45723 var l = new Roo.form.Layout(c);
45725 if(arguments.length > 1){ // duplicate code required because of Opera
45726 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
45733 * Opens the passed container in the layout stack. The container can be any {@link Roo.form.Layout} or subclass.
45734 * @param {Object} container A Roo.form.Layout or subclass of Layout
45735 * @return {Form} this
45737 start : function(c){
45738 // cascade label info
45739 Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
45740 this.active.stack.push(c);
45741 c.ownerCt = this.active;
45747 * Closes the current open container
45748 * @return {Form} this
45751 if(this.active == this.root){
45754 this.active = this.active.ownerCt;
45759 * Add Roo.form components to the current open container (e.g. column, fieldset, etc.). Fields added via this method
45760 * can also be passed with an additional property of fieldLabel, which if supplied, will provide the text to display
45761 * as the label of the field.
45762 * @param {Field} field1
45763 * @param {Field} field2 (optional)
45764 * @param {Field} etc. (optional)
45765 * @return {Form} this
45768 this.active.stack.push.apply(this.active.stack, arguments);
45769 this.allItems.push.apply(this.allItems,arguments);
45771 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
45772 if(a[i].isFormField){
45777 Roo.form.Form.superclass.add.apply(this, r);
45787 * Find any element that has been added to a form, using it's ID or name
45788 * This can include framesets, columns etc. along with regular fields..
45789 * @param {String} id - id or name to find.
45791 * @return {Element} e - or false if nothing found.
45793 findbyId : function(id)
45799 Roo.each(this.allItems, function(f){
45800 if (f.id == id || f.name == id ){
45811 * Render this form into the passed container. This should only be called once!
45812 * @param {String/HTMLElement/Element} container The element this component should be rendered into
45813 * @return {Form} this
45815 render : function(ct)
45821 var o = this.autoCreate || {
45823 method : this.method || 'POST',
45824 id : this.id || Roo.id()
45826 this.initEl(ct.createChild(o));
45828 this.root.render(this.el);
45832 this.items.each(function(f){
45833 f.render('x-form-el-'+f.id);
45836 if(this.buttons.length > 0){
45837 // tables are required to maintain order and for correct IE layout
45838 var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
45839 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
45840 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
45842 var tr = tb.getElementsByTagName('tr')[0];
45843 for(var i = 0, len = this.buttons.length; i < len; i++) {
45844 var b = this.buttons[i];
45845 var td = document.createElement('td');
45846 td.className = 'x-form-btn-td';
45847 b.render(tr.appendChild(td));
45850 if(this.monitorValid){ // initialize after render
45851 this.startMonitoring();
45853 this.fireEvent('rendered', this);
45858 * Adds a button to the footer of the form - this <b>must</b> be called before the form is rendered.
45859 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
45860 * object or a valid Roo.DomHelper element config
45861 * @param {Function} handler The function called when the button is clicked
45862 * @param {Object} scope (optional) The scope of the handler function
45863 * @return {Roo.Button}
45865 addButton : function(config, handler, scope){
45869 minWidth: this.minButtonWidth,
45872 if(typeof config == "string"){
45875 Roo.apply(bc, config);
45877 var btn = new Roo.Button(null, bc);
45878 this.buttons.push(btn);
45883 * Adds a series of form elements (using the xtype property as the factory method.
45884 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column, (and 'end' to close a block)
45885 * @param {Object} config
45888 addxtype : function()
45890 var ar = Array.prototype.slice.call(arguments, 0);
45892 for(var i = 0; i < ar.length; i++) {
45894 continue; // skip -- if this happends something invalid got sent, we
45895 // should ignore it, as basically that interface element will not show up
45896 // and that should be pretty obvious!!
45899 if (Roo.form[ar[i].xtype]) {
45901 var fe = Roo.factory(ar[i], Roo.form);
45907 fe.store.form = this;
45912 this.allItems.push(fe);
45913 if (fe.items && fe.addxtype) {
45914 fe.addxtype.apply(fe, fe.items);
45924 // console.log('adding ' + ar[i].xtype);
45926 if (ar[i].xtype == 'Button') {
45927 //console.log('adding button');
45928 //console.log(ar[i]);
45929 this.addButton(ar[i]);
45930 this.allItems.push(fe);
45934 if (ar[i].xtype == 'end') { // so we can add fieldsets... / layout etc.
45935 alert('end is not supported on xtype any more, use items');
45937 // //console.log('adding end');
45945 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
45946 * option "monitorValid"
45948 startMonitoring : function(){
45951 Roo.TaskMgr.start({
45952 run : this.bindHandler,
45953 interval : this.monitorPoll || 200,
45960 * Stops monitoring of the valid state of this form
45962 stopMonitoring : function(){
45963 this.bound = false;
45967 bindHandler : function(){
45969 return false; // stops binding
45972 this.items.each(function(f){
45973 if(!f.isValid(true)){
45978 for(var i = 0, len = this.buttons.length; i < len; i++){
45979 var btn = this.buttons[i];
45980 if(btn.formBind === true && btn.disabled === valid){
45981 btn.setDisabled(!valid);
45984 this.fireEvent('clientvalidation', this, valid);
45998 Roo.Form = Roo.form.Form;
46001 * Ext JS Library 1.1.1
46002 * Copyright(c) 2006-2007, Ext JS, LLC.
46004 * Originally Released Under LGPL - original licence link has changed is not relivant.
46007 * <script type="text/javascript">
46010 // as we use this in bootstrap.
46011 Roo.namespace('Roo.form');
46013 * @class Roo.form.Action
46014 * Internal Class used to handle form actions
46016 * @param {Roo.form.BasicForm} el The form element or its id
46017 * @param {Object} config Configuration options
46022 // define the action interface
46023 Roo.form.Action = function(form, options){
46025 this.options = options || {};
46028 * Client Validation Failed
46031 Roo.form.Action.CLIENT_INVALID = 'client';
46033 * Server Validation Failed
46036 Roo.form.Action.SERVER_INVALID = 'server';
46038 * Connect to Server Failed
46041 Roo.form.Action.CONNECT_FAILURE = 'connect';
46043 * Reading Data from Server Failed
46046 Roo.form.Action.LOAD_FAILURE = 'load';
46048 Roo.form.Action.prototype = {
46050 failureType : undefined,
46051 response : undefined,
46052 result : undefined,
46054 // interface method
46055 run : function(options){
46059 // interface method
46060 success : function(response){
46064 // interface method
46065 handleResponse : function(response){
46069 // default connection failure
46070 failure : function(response){
46072 this.response = response;
46073 this.failureType = Roo.form.Action.CONNECT_FAILURE;
46074 this.form.afterAction(this, false);
46077 processResponse : function(response){
46078 this.response = response;
46079 if(!response.responseText){
46082 this.result = this.handleResponse(response);
46083 return this.result;
46086 // utility functions used internally
46087 getUrl : function(appendParams){
46088 var url = this.options.url || this.form.url || this.form.el.dom.action;
46090 var p = this.getParams();
46092 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
46098 getMethod : function(){
46099 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
46102 getParams : function(){
46103 var bp = this.form.baseParams;
46104 var p = this.options.params;
46106 if(typeof p == "object"){
46107 p = Roo.urlEncode(Roo.applyIf(p, bp));
46108 }else if(typeof p == 'string' && bp){
46109 p += '&' + Roo.urlEncode(bp);
46112 p = Roo.urlEncode(bp);
46117 createCallback : function(){
46119 success: this.success,
46120 failure: this.failure,
46122 timeout: (this.form.timeout*1000),
46123 upload: this.form.fileUpload ? this.success : undefined
46128 Roo.form.Action.Submit = function(form, options){
46129 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
46132 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
46135 haveProgress : false,
46136 uploadComplete : false,
46138 // uploadProgress indicator.
46139 uploadProgress : function()
46141 if (!this.form.progressUrl) {
46145 if (!this.haveProgress) {
46146 Roo.MessageBox.progress("Uploading", "Uploading");
46148 if (this.uploadComplete) {
46149 Roo.MessageBox.hide();
46153 this.haveProgress = true;
46155 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
46157 var c = new Roo.data.Connection();
46159 url : this.form.progressUrl,
46164 success : function(req){
46165 //console.log(data);
46169 rdata = Roo.decode(req.responseText)
46171 Roo.log("Invalid data from server..");
46175 if (!rdata || !rdata.success) {
46177 Roo.MessageBox.alert(Roo.encode(rdata));
46180 var data = rdata.data;
46182 if (this.uploadComplete) {
46183 Roo.MessageBox.hide();
46188 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
46189 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
46192 this.uploadProgress.defer(2000,this);
46195 failure: function(data) {
46196 Roo.log('progress url failed ');
46207 // run get Values on the form, so it syncs any secondary forms.
46208 this.form.getValues();
46210 var o = this.options;
46211 var method = this.getMethod();
46212 var isPost = method == 'POST';
46213 if(o.clientValidation === false || this.form.isValid()){
46215 if (this.form.progressUrl) {
46216 this.form.findField('UPLOAD_IDENTIFIER').setValue(
46217 (new Date() * 1) + '' + Math.random());
46222 Roo.Ajax.request(Roo.apply(this.createCallback(), {
46223 form:this.form.el.dom,
46224 url:this.getUrl(!isPost),
46226 params:isPost ? this.getParams() : null,
46227 isUpload: this.form.fileUpload
46230 this.uploadProgress();
46232 }else if (o.clientValidation !== false){ // client validation failed
46233 this.failureType = Roo.form.Action.CLIENT_INVALID;
46234 this.form.afterAction(this, false);
46238 success : function(response)
46240 this.uploadComplete= true;
46241 if (this.haveProgress) {
46242 Roo.MessageBox.hide();
46246 var result = this.processResponse(response);
46247 if(result === true || result.success){
46248 this.form.afterAction(this, true);
46252 this.form.markInvalid(result.errors);
46253 this.failureType = Roo.form.Action.SERVER_INVALID;
46255 this.form.afterAction(this, false);
46257 failure : function(response)
46259 this.uploadComplete= true;
46260 if (this.haveProgress) {
46261 Roo.MessageBox.hide();
46264 this.response = response;
46265 this.failureType = Roo.form.Action.CONNECT_FAILURE;
46266 this.form.afterAction(this, false);
46269 handleResponse : function(response){
46270 if(this.form.errorReader){
46271 var rs = this.form.errorReader.read(response);
46274 for(var i = 0, len = rs.records.length; i < len; i++) {
46275 var r = rs.records[i];
46276 errors[i] = r.data;
46279 if(errors.length < 1){
46283 success : rs.success,
46289 ret = Roo.decode(response.responseText);
46293 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
46303 Roo.form.Action.Load = function(form, options){
46304 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
46305 this.reader = this.form.reader;
46308 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
46313 Roo.Ajax.request(Roo.apply(
46314 this.createCallback(), {
46315 method:this.getMethod(),
46316 url:this.getUrl(false),
46317 params:this.getParams()
46321 success : function(response){
46323 var result = this.processResponse(response);
46324 if(result === true || !result.success || !result.data){
46325 this.failureType = Roo.form.Action.LOAD_FAILURE;
46326 this.form.afterAction(this, false);
46329 this.form.clearInvalid();
46330 this.form.setValues(result.data);
46331 this.form.afterAction(this, true);
46334 handleResponse : function(response){
46335 if(this.form.reader){
46336 var rs = this.form.reader.read(response);
46337 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
46339 success : rs.success,
46343 return Roo.decode(response.responseText);
46347 Roo.form.Action.ACTION_TYPES = {
46348 'load' : Roo.form.Action.Load,
46349 'submit' : Roo.form.Action.Submit
46352 * Ext JS Library 1.1.1
46353 * Copyright(c) 2006-2007, Ext JS, LLC.
46355 * Originally Released Under LGPL - original licence link has changed is not relivant.
46358 * <script type="text/javascript">
46362 * @class Roo.form.Layout
46363 * @extends Roo.Component
46364 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
46366 * @param {Object} config Configuration options
46368 Roo.form.Layout = function(config){
46370 if (config.items) {
46371 xitems = config.items;
46372 delete config.items;
46374 Roo.form.Layout.superclass.constructor.call(this, config);
46376 Roo.each(xitems, this.addxtype, this);
46380 Roo.extend(Roo.form.Layout, Roo.Component, {
46382 * @cfg {String/Object} autoCreate
46383 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
46386 * @cfg {String/Object/Function} style
46387 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
46388 * a function which returns such a specification.
46391 * @cfg {String} labelAlign
46392 * Valid values are "left," "top" and "right" (defaults to "left")
46395 * @cfg {Number} labelWidth
46396 * Fixed width in pixels of all field labels (defaults to undefined)
46399 * @cfg {Boolean} clear
46400 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
46404 * @cfg {String} labelSeparator
46405 * The separator to use after field labels (defaults to ':')
46407 labelSeparator : ':',
46409 * @cfg {Boolean} hideLabels
46410 * True to suppress the display of field labels in this layout (defaults to false)
46412 hideLabels : false,
46415 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
46420 onRender : function(ct, position){
46421 if(this.el){ // from markup
46422 this.el = Roo.get(this.el);
46423 }else { // generate
46424 var cfg = this.getAutoCreate();
46425 this.el = ct.createChild(cfg, position);
46428 this.el.applyStyles(this.style);
46430 if(this.labelAlign){
46431 this.el.addClass('x-form-label-'+this.labelAlign);
46433 if(this.hideLabels){
46434 this.labelStyle = "display:none";
46435 this.elementStyle = "padding-left:0;";
46437 if(typeof this.labelWidth == 'number'){
46438 this.labelStyle = "width:"+this.labelWidth+"px;";
46439 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
46441 if(this.labelAlign == 'top'){
46442 this.labelStyle = "width:auto;";
46443 this.elementStyle = "padding-left:0;";
46446 var stack = this.stack;
46447 var slen = stack.length;
46449 if(!this.fieldTpl){
46450 var t = new Roo.Template(
46451 '<div class="x-form-item {5}">',
46452 '<label for="{0}" style="{2}">{1}{4}</label>',
46453 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
46455 '</div><div class="x-form-clear-left"></div>'
46457 t.disableFormats = true;
46459 Roo.form.Layout.prototype.fieldTpl = t;
46461 for(var i = 0; i < slen; i++) {
46462 if(stack[i].isFormField){
46463 this.renderField(stack[i]);
46465 this.renderComponent(stack[i]);
46470 this.el.createChild({cls:'x-form-clear'});
46475 renderField : function(f){
46476 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
46479 f.labelStyle||this.labelStyle||'', //2
46480 this.elementStyle||'', //3
46481 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
46482 f.itemCls||this.itemCls||'' //5
46483 ], true).getPrevSibling());
46487 renderComponent : function(c){
46488 c.render(c.isLayout ? this.el : this.el.createChild());
46491 * Adds a object form elements (using the xtype property as the factory method.)
46492 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
46493 * @param {Object} config
46495 addxtype : function(o)
46497 // create the lement.
46498 o.form = this.form;
46499 var fe = Roo.factory(o, Roo.form);
46500 this.form.allItems.push(fe);
46501 this.stack.push(fe);
46503 if (fe.isFormField) {
46504 this.form.items.add(fe);
46512 * @class Roo.form.Column
46513 * @extends Roo.form.Layout
46514 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
46516 * @param {Object} config Configuration options
46518 Roo.form.Column = function(config){
46519 Roo.form.Column.superclass.constructor.call(this, config);
46522 Roo.extend(Roo.form.Column, Roo.form.Layout, {
46524 * @cfg {Number/String} width
46525 * The fixed width of the column in pixels or CSS value (defaults to "auto")
46528 * @cfg {String/Object} autoCreate
46529 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
46533 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
46536 onRender : function(ct, position){
46537 Roo.form.Column.superclass.onRender.call(this, ct, position);
46539 this.el.setWidth(this.width);
46546 * @class Roo.form.Row
46547 * @extends Roo.form.Layout
46548 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
46550 * @param {Object} config Configuration options
46554 Roo.form.Row = function(config){
46555 Roo.form.Row.superclass.constructor.call(this, config);
46558 Roo.extend(Roo.form.Row, Roo.form.Layout, {
46560 * @cfg {Number/String} width
46561 * The fixed width of the column in pixels or CSS value (defaults to "auto")
46564 * @cfg {Number/String} height
46565 * The fixed height of the column in pixels or CSS value (defaults to "auto")
46567 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
46571 onRender : function(ct, position){
46572 //console.log('row render');
46574 var t = new Roo.Template(
46575 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
46576 '<label for="{0}" style="{2}">{1}{4}</label>',
46577 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
46581 t.disableFormats = true;
46583 Roo.form.Layout.prototype.rowTpl = t;
46585 this.fieldTpl = this.rowTpl;
46587 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
46588 var labelWidth = 100;
46590 if ((this.labelAlign != 'top')) {
46591 if (typeof this.labelWidth == 'number') {
46592 labelWidth = this.labelWidth
46594 this.padWidth = 20 + labelWidth;
46598 Roo.form.Column.superclass.onRender.call(this, ct, position);
46600 this.el.setWidth(this.width);
46603 this.el.setHeight(this.height);
46608 renderField : function(f){
46609 f.fieldEl = this.fieldTpl.append(this.el, [
46610 f.id, f.fieldLabel,
46611 f.labelStyle||this.labelStyle||'',
46612 this.elementStyle||'',
46613 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
46614 f.itemCls||this.itemCls||'',
46615 f.width ? f.width + this.padWidth : 160 + this.padWidth
46622 * @class Roo.form.FieldSet
46623 * @extends Roo.form.Layout
46624 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
46626 * @param {Object} config Configuration options
46628 Roo.form.FieldSet = function(config){
46629 Roo.form.FieldSet.superclass.constructor.call(this, config);
46632 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
46634 * @cfg {String} legend
46635 * The text to display as the legend for the FieldSet (defaults to '')
46638 * @cfg {String/Object} autoCreate
46639 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
46643 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
46646 onRender : function(ct, position){
46647 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
46649 this.setLegend(this.legend);
46654 setLegend : function(text){
46656 this.el.child('legend').update(text);
46661 * Ext JS Library 1.1.1
46662 * Copyright(c) 2006-2007, Ext JS, LLC.
46664 * Originally Released Under LGPL - original licence link has changed is not relivant.
46667 * <script type="text/javascript">
46670 * @class Roo.form.VTypes
46671 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
46674 Roo.form.VTypes = function(){
46675 // closure these in so they are only created once.
46676 var alpha = /^[a-zA-Z_]+$/;
46677 var alphanum = /^[a-zA-Z0-9_]+$/;
46678 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
46679 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
46681 // All these messages and functions are configurable
46684 * The function used to validate email addresses
46685 * @param {String} value The email address
46687 'email' : function(v){
46688 return email.test(v);
46691 * The error text to display when the email validation function returns false
46694 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
46696 * The keystroke filter mask to be applied on email input
46699 'emailMask' : /[a-z0-9_\.\-@]/i,
46702 * The function used to validate URLs
46703 * @param {String} value The URL
46705 'url' : function(v){
46706 return url.test(v);
46709 * The error text to display when the url validation function returns false
46712 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
46715 * The function used to validate alpha values
46716 * @param {String} value The value
46718 'alpha' : function(v){
46719 return alpha.test(v);
46722 * The error text to display when the alpha validation function returns false
46725 'alphaText' : 'This field should only contain letters and _',
46727 * The keystroke filter mask to be applied on alpha input
46730 'alphaMask' : /[a-z_]/i,
46733 * The function used to validate alphanumeric values
46734 * @param {String} value The value
46736 'alphanum' : function(v){
46737 return alphanum.test(v);
46740 * The error text to display when the alphanumeric validation function returns false
46743 'alphanumText' : 'This field should only contain letters, numbers and _',
46745 * The keystroke filter mask to be applied on alphanumeric input
46748 'alphanumMask' : /[a-z0-9_]/i
46750 }();//<script type="text/javascript">
46753 * @class Roo.form.FCKeditor
46754 * @extends Roo.form.TextArea
46755 * Wrapper around the FCKEditor http://www.fckeditor.net
46757 * Creates a new FCKeditor
46758 * @param {Object} config Configuration options
46760 Roo.form.FCKeditor = function(config){
46761 Roo.form.FCKeditor.superclass.constructor.call(this, config);
46764 * @event editorinit
46765 * Fired when the editor is initialized - you can add extra handlers here..
46766 * @param {FCKeditor} this
46767 * @param {Object} the FCK object.
46774 Roo.form.FCKeditor.editors = { };
46775 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
46777 //defaultAutoCreate : {
46778 // tag : "textarea",style : "width:100px;height:60px;" ,autocomplete : "off"
46782 * @cfg {Object} fck options - see fck manual for details.
46787 * @cfg {Object} fck toolbar set (Basic or Default)
46789 toolbarSet : 'Basic',
46791 * @cfg {Object} fck BasePath
46793 basePath : '/fckeditor/',
46801 onRender : function(ct, position)
46804 this.defaultAutoCreate = {
46806 style:"width:300px;height:60px;",
46807 autocomplete: "new-password"
46810 Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
46813 this.textSizeEl = Roo.DomHelper.append(document.body, {tag: "pre", cls: "x-form-grow-sizer"});
46814 if(this.preventScrollbars){
46815 this.el.setStyle("overflow", "hidden");
46817 this.el.setHeight(this.growMin);
46820 //console.log('onrender' + this.getId() );
46821 Roo.form.FCKeditor.editors[this.getId()] = this;
46824 this.replaceTextarea() ;
46828 getEditor : function() {
46829 return this.fckEditor;
46832 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
46833 * @param {Mixed} value The value to set
46837 setValue : function(value)
46839 //console.log('setValue: ' + value);
46841 if(typeof(value) == 'undefined') { // not sure why this is happending...
46844 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
46846 //if(!this.el || !this.getEditor()) {
46847 // this.value = value;
46848 //this.setValue.defer(100,this,[value]);
46852 if(!this.getEditor()) {
46856 this.getEditor().SetData(value);
46863 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
46864 * @return {Mixed} value The field value
46866 getValue : function()
46869 if (this.frame && this.frame.dom.style.display == 'none') {
46870 return Roo.form.FCKeditor.superclass.getValue.call(this);
46873 if(!this.el || !this.getEditor()) {
46875 // this.getValue.defer(100,this);
46880 var value=this.getEditor().GetData();
46881 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
46882 return Roo.form.FCKeditor.superclass.getValue.call(this);
46888 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
46889 * @return {Mixed} value The field value
46891 getRawValue : function()
46893 if (this.frame && this.frame.dom.style.display == 'none') {
46894 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
46897 if(!this.el || !this.getEditor()) {
46898 //this.getRawValue.defer(100,this);
46905 var value=this.getEditor().GetData();
46906 Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
46907 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
46911 setSize : function(w,h) {
46915 //if (this.frame && this.frame.dom.style.display == 'none') {
46916 // Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
46919 //if(!this.el || !this.getEditor()) {
46920 // this.setSize.defer(100,this, [w,h]);
46926 Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
46928 this.frame.dom.setAttribute('width', w);
46929 this.frame.dom.setAttribute('height', h);
46930 this.frame.setSize(w,h);
46934 toggleSourceEdit : function(value) {
46938 this.el.dom.style.display = value ? '' : 'none';
46939 this.frame.dom.style.display = value ? 'none' : '';
46944 focus: function(tag)
46946 if (this.frame.dom.style.display == 'none') {
46947 return Roo.form.FCKeditor.superclass.focus.call(this);
46949 if(!this.el || !this.getEditor()) {
46950 this.focus.defer(100,this, [tag]);
46957 var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
46958 this.getEditor().Focus();
46960 if (!this.getEditor().Selection.GetSelection()) {
46961 this.focus.defer(100,this, [tag]);
46966 var r = this.getEditor().EditorDocument.createRange();
46967 r.setStart(tgs[0],0);
46968 r.setEnd(tgs[0],0);
46969 this.getEditor().Selection.GetSelection().removeAllRanges();
46970 this.getEditor().Selection.GetSelection().addRange(r);
46971 this.getEditor().Focus();
46978 replaceTextarea : function()
46980 if ( document.getElementById( this.getId() + '___Frame' ) )
46982 //if ( !this.checkBrowser || this._isCompatibleBrowser() )
46984 // We must check the elements firstly using the Id and then the name.
46985 var oTextarea = document.getElementById( this.getId() );
46987 var colElementsByName = document.getElementsByName( this.getId() ) ;
46989 oTextarea.style.display = 'none' ;
46991 if ( oTextarea.tabIndex ) {
46992 this.TabIndex = oTextarea.tabIndex ;
46995 this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
46996 this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
46997 this.frame = Roo.get(this.getId() + '___Frame')
47000 _getConfigHtml : function()
47004 for ( var o in this.fckconfig ) {
47005 sConfig += sConfig.length > 0 ? '&' : '';
47006 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
47009 return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
47013 _getIFrameHtml : function()
47015 var sFile = 'fckeditor.html' ;
47016 /* no idea what this is about..
47019 if ( (/fcksource=true/i).test( window.top.location.search ) )
47020 sFile = 'fckeditor.original.html' ;
47025 var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
47026 sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
47029 var html = '<iframe id="' + this.getId() +
47030 '___Frame" src="' + sLink +
47031 '" width="' + this.width +
47032 '" height="' + this.height + '"' +
47033 (this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
47034 ' frameborder="0" scrolling="no"></iframe>' ;
47039 _insertHtmlBefore : function( html, element )
47041 if ( element.insertAdjacentHTML ) {
47043 element.insertAdjacentHTML( 'beforeBegin', html ) ;
47045 var oRange = document.createRange() ;
47046 oRange.setStartBefore( element ) ;
47047 var oFragment = oRange.createContextualFragment( html );
47048 element.parentNode.insertBefore( oFragment, element ) ;
47061 //Roo.reg('fckeditor', Roo.form.FCKeditor);
47063 function FCKeditor_OnComplete(editorInstance){
47064 var f = Roo.form.FCKeditor.editors[editorInstance.Name];
47065 f.fckEditor = editorInstance;
47066 //console.log("loaded");
47067 f.fireEvent('editorinit', f, editorInstance);
47087 //<script type="text/javascript">
47089 * @class Roo.form.GridField
47090 * @extends Roo.form.Field
47091 * Embed a grid (or editable grid into a form)
47094 * This embeds a grid in a form, the value of the field should be the json encoded array of rows
47096 * xgrid.store = Roo.data.Store
47097 * xgrid.store.proxy = Roo.data.MemoryProxy (data = [] )
47098 * xgrid.store.reader = Roo.data.JsonReader
47102 * Creates a new GridField
47103 * @param {Object} config Configuration options
47105 Roo.form.GridField = function(config){
47106 Roo.form.GridField.superclass.constructor.call(this, config);
47110 Roo.extend(Roo.form.GridField, Roo.form.Field, {
47112 * @cfg {Number} width - used to restrict width of grid..
47116 * @cfg {Number} height - used to restrict height of grid..
47120 * @cfg {Object} xgrid (xtype'd description of grid) { xtype : 'Grid', dataSource: .... }
47126 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
47127 * {tag: "input", type: "checkbox", autocomplete: "off"})
47129 // defaultAutoCreate : { tag: 'div' },
47130 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'new-password'},
47132 * @cfg {String} addTitle Text to include for adding a title.
47136 onResize : function(){
47137 Roo.form.Field.superclass.onResize.apply(this, arguments);
47140 initEvents : function(){
47141 // Roo.form.Checkbox.superclass.initEvents.call(this);
47142 // has no events...
47147 getResizeEl : function(){
47151 getPositionEl : function(){
47156 onRender : function(ct, position){
47158 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
47159 var style = this.style;
47162 Roo.form.GridField.superclass.onRender.call(this, ct, position);
47163 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
47164 this.viewEl = this.wrap.createChild({ tag: 'div' });
47166 this.viewEl.applyStyles(style);
47169 this.viewEl.setWidth(this.width);
47172 this.viewEl.setHeight(this.height);
47174 //if(this.inputValue !== undefined){
47175 //this.setValue(this.value);
47178 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
47181 this.grid.render();
47182 this.grid.getDataSource().on('remove', this.refreshValue, this);
47183 this.grid.getDataSource().on('update', this.refreshValue, this);
47184 this.grid.on('afteredit', this.refreshValue, this);
47190 * Sets the value of the item.
47191 * @param {String} either an object or a string..
47193 setValue : function(v){
47195 v = v || []; // empty set..
47196 // this does not seem smart - it really only affects memoryproxy grids..
47197 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
47198 var ds = this.grid.getDataSource();
47199 // assumes a json reader..
47201 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
47202 ds.loadData( data);
47204 // clear selection so it does not get stale.
47205 if (this.grid.sm) {
47206 this.grid.sm.clearSelections();
47209 Roo.form.GridField.superclass.setValue.call(this, v);
47210 this.refreshValue();
47211 // should load data in the grid really....
47215 refreshValue: function() {
47217 this.grid.getDataSource().each(function(r) {
47220 this.el.dom.value = Roo.encode(val);
47228 * Ext JS Library 1.1.1
47229 * Copyright(c) 2006-2007, Ext JS, LLC.
47231 * Originally Released Under LGPL - original licence link has changed is not relivant.
47234 * <script type="text/javascript">
47237 * @class Roo.form.DisplayField
47238 * @extends Roo.form.Field
47239 * A generic Field to display non-editable data.
47241 * Creates a new Display Field item.
47242 * @param {Object} config Configuration options
47244 Roo.form.DisplayField = function(config){
47245 Roo.form.DisplayField.superclass.constructor.call(this, config);
47249 Roo.extend(Roo.form.DisplayField, Roo.form.TextField, {
47250 inputType: 'hidden',
47256 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
47258 focusClass : undefined,
47260 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
47262 fieldClass: 'x-form-field',
47265 * @cfg {Function} valueRenderer The renderer for the field (so you can reformat output). should return raw HTML
47267 valueRenderer: undefined,
47271 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
47272 * {tag: "input", type: "checkbox", autocomplete: "off"})
47275 // defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
47277 onResize : function(){
47278 Roo.form.DisplayField.superclass.onResize.apply(this, arguments);
47282 initEvents : function(){
47283 // Roo.form.Checkbox.superclass.initEvents.call(this);
47284 // has no events...
47289 getResizeEl : function(){
47293 getPositionEl : function(){
47298 onRender : function(ct, position){
47300 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
47301 //if(this.inputValue !== undefined){
47302 this.wrap = this.el.wrap();
47304 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
47306 if (this.bodyStyle) {
47307 this.viewEl.applyStyles(this.bodyStyle);
47309 //this.viewEl.setStyle('padding', '2px');
47311 this.setValue(this.value);
47316 initValue : Roo.emptyFn,
47321 onClick : function(){
47326 * Sets the checked state of the checkbox.
47327 * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
47329 setValue : function(v){
47331 var html = this.valueRenderer ? this.valueRenderer(v) : String.format('{0}', v);
47332 // this might be called before we have a dom element..
47333 if (!this.viewEl) {
47336 this.viewEl.dom.innerHTML = html;
47337 Roo.form.DisplayField.superclass.setValue.call(this, v);
47347 * @class Roo.form.DayPicker
47348 * @extends Roo.form.Field
47349 * A Day picker show [M] [T] [W] ....
47351 * Creates a new Day Picker
47352 * @param {Object} config Configuration options
47354 Roo.form.DayPicker= function(config){
47355 Roo.form.DayPicker.superclass.constructor.call(this, config);
47359 Roo.extend(Roo.form.DayPicker, Roo.form.Field, {
47361 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
47363 focusClass : undefined,
47365 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
47367 fieldClass: "x-form-field",
47370 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
47371 * {tag: "input", type: "checkbox", autocomplete: "off"})
47373 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "new-password"},
47376 actionMode : 'viewEl',
47380 inputType : 'hidden',
47383 inputElement: false, // real input element?
47384 basedOn: false, // ????
47386 isFormField: true, // not sure where this is needed!!!!
47388 onResize : function(){
47389 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
47390 if(!this.boxLabel){
47391 this.el.alignTo(this.wrap, 'c-c');
47395 initEvents : function(){
47396 Roo.form.Checkbox.superclass.initEvents.call(this);
47397 this.el.on("click", this.onClick, this);
47398 this.el.on("change", this.onClick, this);
47402 getResizeEl : function(){
47406 getPositionEl : function(){
47412 onRender : function(ct, position){
47413 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
47415 this.wrap = this.el.wrap({cls: 'x-form-daypick-item '});
47417 var r1 = '<table><tr>';
47418 var r2 = '<tr class="x-form-daypick-icons">';
47419 for (var i=0; i < 7; i++) {
47420 r1+= '<td><div>' + Date.dayNames[i].substring(0,3) + '</div></td>';
47421 r2+= '<td><img class="x-menu-item-icon" src="' + Roo.BLANK_IMAGE_URL +'"></td>';
47424 var viewEl = this.wrap.createChild( r1 + '</tr>' + r2 + '</tr></table>');
47425 viewEl.select('img').on('click', this.onClick, this);
47426 this.viewEl = viewEl;
47429 // this will not work on Chrome!!!
47430 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
47431 this.el.on('propertychange', this.setFromHidden, this); //ie
47439 initValue : Roo.emptyFn,
47442 * Returns the checked state of the checkbox.
47443 * @return {Boolean} True if checked, else false
47445 getValue : function(){
47446 return this.el.dom.value;
47451 onClick : function(e){
47452 //this.setChecked(!this.checked);
47453 Roo.get(e.target).toggleClass('x-menu-item-checked');
47454 this.refreshValue();
47455 //if(this.el.dom.checked != this.checked){
47456 // this.setValue(this.el.dom.checked);
47461 refreshValue : function()
47464 this.viewEl.select('img',true).each(function(e,i,n) {
47465 val += e.is(".x-menu-item-checked") ? String(n) : '';
47467 this.setValue(val, true);
47471 * Sets the checked state of the checkbox.
47472 * On is always based on a string comparison between inputValue and the param.
47473 * @param {Boolean/String} value - the value to set
47474 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
47476 setValue : function(v,suppressEvent){
47477 if (!this.el.dom) {
47480 var old = this.el.dom.value ;
47481 this.el.dom.value = v;
47482 if (suppressEvent) {
47486 // update display..
47487 this.viewEl.select('img',true).each(function(e,i,n) {
47489 var on = e.is(".x-menu-item-checked");
47490 var newv = v.indexOf(String(n)) > -1;
47492 e.toggleClass('x-menu-item-checked');
47498 this.fireEvent('change', this, v, old);
47503 // handle setting of hidden value by some other method!!?!?
47504 setFromHidden: function()
47509 //console.log("SET FROM HIDDEN");
47510 //alert('setFrom hidden');
47511 this.setValue(this.el.dom.value);
47514 onDestroy : function()
47517 Roo.get(this.viewEl).remove();
47520 Roo.form.DayPicker.superclass.onDestroy.call(this);
47524 * RooJS Library 1.1.1
47525 * Copyright(c) 2008-2011 Alan Knowles
47532 * @class Roo.form.ComboCheck
47533 * @extends Roo.form.ComboBox
47534 * A combobox for multiple select items.
47536 * FIXME - could do with a reset button..
47539 * Create a new ComboCheck
47540 * @param {Object} config Configuration options
47542 Roo.form.ComboCheck = function(config){
47543 Roo.form.ComboCheck.superclass.constructor.call(this, config);
47544 // should verify some data...
47546 // hiddenName = required..
47547 // displayField = required
47548 // valudField == required
47549 var req= [ 'hiddenName', 'displayField', 'valueField' ];
47551 Roo.each(req, function(e) {
47552 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
47553 throw "Roo.form.ComboCheck : missing value for: " + e;
47560 Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
47565 selectedClass: 'x-menu-item-checked',
47568 onRender : function(ct, position){
47574 var cls = 'x-combo-list';
47577 this.tpl = new Roo.Template({
47578 html : '<div class="'+cls+'-item x-menu-check-item">' +
47579 '<img class="x-menu-item-icon" style="margin: 0px;" src="' + Roo.BLANK_IMAGE_URL + '">' +
47580 '<span>{' + this.displayField + '}</span>' +
47587 Roo.form.ComboCheck.superclass.onRender.call(this, ct, position);
47588 this.view.singleSelect = false;
47589 this.view.multiSelect = true;
47590 this.view.toggleSelect = true;
47591 this.pageTb.add(new Roo.Toolbar.Fill(), {
47594 handler: function()
47601 onViewOver : function(e, t){
47607 onViewClick : function(doFocus,index){
47611 select: function () {
47612 //Roo.log("SELECT CALLED");
47615 selectByValue : function(xv, scrollIntoView){
47616 var ar = this.getValueArray();
47619 Roo.each(ar, function(v) {
47620 if(v === undefined || v === null){
47623 var r = this.findRecord(this.valueField, v);
47625 sels.push(this.store.indexOf(r))
47629 this.view.select(sels);
47635 onSelect : function(record, index){
47636 // Roo.log("onselect Called");
47637 // this is only called by the clear button now..
47638 this.view.clearSelections();
47639 this.setValue('[]');
47640 if (this.value != this.valueBefore) {
47641 this.fireEvent('change', this, this.value, this.valueBefore);
47642 this.valueBefore = this.value;
47645 getValueArray : function()
47650 //Roo.log(this.value);
47651 if (typeof(this.value) == 'undefined') {
47654 var ar = Roo.decode(this.value);
47655 return ar instanceof Array ? ar : []; //?? valid?
47658 Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
47663 expand : function ()
47666 Roo.form.ComboCheck.superclass.expand.call(this);
47667 this.valueBefore = typeof(this.value) == 'undefined' ? '' : this.value;
47668 //this.valueBefore = typeof(this.valueBefore) == 'undefined' ? '' : this.valueBefore;
47673 collapse : function(){
47674 Roo.form.ComboCheck.superclass.collapse.call(this);
47675 var sl = this.view.getSelectedIndexes();
47676 var st = this.store;
47680 Roo.each(sl, function(i) {
47682 nv.push(r.get(this.valueField));
47684 this.setValue(Roo.encode(nv));
47685 if (this.value != this.valueBefore) {
47687 this.fireEvent('change', this, this.value, this.valueBefore);
47688 this.valueBefore = this.value;
47693 setValue : function(v){
47697 var vals = this.getValueArray();
47699 Roo.each(vals, function(k) {
47700 var r = this.findRecord(this.valueField, k);
47702 tv.push(r.data[this.displayField]);
47703 }else if(this.valueNotFoundText !== undefined){
47704 tv.push( this.valueNotFoundText );
47709 Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
47710 this.hiddenField.value = v;
47716 * Ext JS Library 1.1.1
47717 * Copyright(c) 2006-2007, Ext JS, LLC.
47719 * Originally Released Under LGPL - original licence link has changed is not relivant.
47722 * <script type="text/javascript">
47726 * @class Roo.form.Signature
47727 * @extends Roo.form.Field
47731 * @param {Object} config Configuration options
47734 Roo.form.Signature = function(config){
47735 Roo.form.Signature.superclass.constructor.call(this, config);
47737 this.addEvents({// not in used??
47740 * Fires when the 'confirm' icon is pressed (add a listener to enable add button)
47741 * @param {Roo.form.Signature} combo This combo box
47746 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
47747 * @param {Roo.form.ComboBox} combo This combo box
47748 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
47754 Roo.extend(Roo.form.Signature, Roo.form.Field, {
47756 * @cfg {Object} labels Label to use when rendering a form.
47760 * confirm : "Confirm"
47765 confirm : "Confirm"
47768 * @cfg {Number} width The signature panel width (defaults to 300)
47772 * @cfg {Number} height The signature panel height (defaults to 100)
47776 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to false)
47778 allowBlank : false,
47781 // {Object} signPanel The signature SVG panel element (defaults to {})
47783 // {Boolean} isMouseDown False to validate that the mouse down event (defaults to false)
47784 isMouseDown : false,
47785 // {Boolean} isConfirmed validate the signature is confirmed or not for submitting form (defaults to false)
47786 isConfirmed : false,
47787 // {String} signatureTmp SVG mapping string (defaults to empty string)
47791 defaultAutoCreate : { // modified by initCompnoent..
47797 onRender : function(ct, position){
47799 Roo.form.Signature.superclass.onRender.call(this, ct, position);
47801 this.wrap = this.el.wrap({
47802 cls:'x-form-signature-wrap', style : 'width: ' + this.width + 'px', cn:{cls:'x-form-signature'}
47805 this.createToolbar(this);
47806 this.signPanel = this.wrap.createChild({
47808 style: 'width: ' + this.width + 'px; height: ' + this.height + 'px; border: 0;'
47812 this.svgID = Roo.id();
47813 this.svgEl = this.signPanel.createChild({
47814 xmlns : 'http://www.w3.org/2000/svg',
47816 id : this.svgID + "-svg",
47818 height: this.height,
47819 viewBox: '0 0 '+this.width+' '+this.height,
47823 id: this.svgID + "-svg-r",
47825 height: this.height,
47830 id: this.svgID + "-svg-l",
47832 y1: (this.height*0.8), // start set the line in 80% of height
47833 x2: this.width, // end
47834 y2: (this.height*0.8), // end set the line in 80% of height
47836 'stroke-width': "1",
47837 'stroke-dasharray': "3",
47838 'shape-rendering': "crispEdges",
47839 'pointer-events': "none"
47843 id: this.svgID + "-svg-p",
47845 'stroke-width': "3",
47847 'pointer-events': 'none'
47852 this.svgBox = this.svgEl.dom.getScreenCTM();
47854 createSVG : function(){
47855 var svg = this.signPanel;
47856 var r = svg.select('#'+ this.svgID + '-svg-r', true).first().dom;
47859 r.addEventListener('mousedown', function(e) { return t.down(e); }, false);
47860 r.addEventListener('mousemove', function(e) { return t.move(e); }, false);
47861 r.addEventListener('mouseup', function(e) { return t.up(e); }, false);
47862 r.addEventListener('mouseout', function(e) { return t.up(e); }, false);
47863 r.addEventListener('touchstart', function(e) { return t.down(e); }, false);
47864 r.addEventListener('touchmove', function(e) { return t.move(e); }, false);
47865 r.addEventListener('touchend', function(e) { return t.up(e); }, false);
47868 isTouchEvent : function(e){
47869 return e.type.match(/^touch/);
47871 getCoords : function (e) {
47872 var pt = this.svgEl.dom.createSVGPoint();
47875 if (this.isTouchEvent(e)) {
47876 pt.x = e.targetTouches[0].clientX
47877 pt.y = e.targetTouches[0].clientY;
47879 var a = this.svgEl.dom.getScreenCTM();
47880 var b = a.inverse();
47881 var mx = pt.matrixTransform(b);
47882 return mx.x + ',' + mx.y;
47884 //mouse event headler
47885 down : function (e) {
47886 this.signatureTmp += 'M' + this.getCoords(e) + ' ';
47887 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr('d', this.signatureTmp);
47889 this.isMouseDown = true;
47891 e.preventDefault();
47893 move : function (e) {
47894 if (this.isMouseDown) {
47895 this.signatureTmp += 'L' + this.getCoords(e) + ' ';
47896 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', this.signatureTmp);
47899 e.preventDefault();
47901 up : function (e) {
47902 this.isMouseDown = false;
47903 var sp = this.signatureTmp.split(' ');
47906 if(!sp[sp.length-2].match(/^L/)){
47910 this.signatureTmp = sp.join(" ");
47913 if(this.getValue() != this.signatureTmp){
47914 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
47915 this.isConfirmed = false;
47917 e.preventDefault();
47921 * Protected method that will not generally be called directly. It
47922 * is called when the editor creates its toolbar. Override this method if you need to
47923 * add custom toolbar buttons.
47924 * @param {HtmlEditor} editor
47926 createToolbar : function(editor){
47927 function btn(id, toggle, handler){
47928 var xid = fid + '-'+ id ;
47932 cls : 'x-btn-icon x-edit-'+id,
47933 enableToggle:toggle !== false,
47934 scope: editor, // was editor...
47935 handler:handler||editor.relayBtnCmd,
47936 clickEvent:'mousedown',
47937 tooltip: etb.buttonTips[id] || undefined, ///tips ???
47943 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
47947 cls : ' x-signature-btn x-signature-'+id,
47948 scope: editor, // was editor...
47949 handler: this.reset,
47950 clickEvent:'mousedown',
47951 text: this.labels.clear
47958 cls : ' x-signature-btn x-signature-'+id,
47959 scope: editor, // was editor...
47960 handler: this.confirmHandler,
47961 clickEvent:'mousedown',
47962 text: this.labels.confirm
47969 * when user is clicked confirm then show this image.....
47971 * @return {String} Image Data URI
47973 getImageDataURI : function(){
47974 var svg = this.svgEl.dom.parentNode.innerHTML;
47975 var src = 'data:image/svg+xml;base64,'+window.btoa(svg);
47980 * @return {Boolean} this.isConfirmed
47982 getConfirmed : function(){
47983 return this.isConfirmed;
47987 * @return {Number} this.width
47989 getWidth : function(){
47994 * @return {Number} this.height
47996 getHeight : function(){
47997 return this.height;
48000 getSignature : function(){
48001 return this.signatureTmp;
48004 reset : function(){
48005 this.signatureTmp = '';
48006 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
48007 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', '');
48008 this.isConfirmed = false;
48009 Roo.form.Signature.superclass.reset.call(this);
48011 setSignature : function(s){
48012 this.signatureTmp = s;
48013 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
48014 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', s);
48016 this.isConfirmed = false;
48017 Roo.form.Signature.superclass.reset.call(this);
48020 // Roo.log(this.signPanel.dom.contentWindow.up())
48023 setConfirmed : function(){
48027 // Roo.log(Roo.get(this.signPanel.dom.contentWindow.r).attr('fill', '#cfc'));
48030 confirmHandler : function(){
48031 if(!this.getSignature()){
48035 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#cfc');
48036 this.setValue(this.getSignature());
48037 this.isConfirmed = true;
48039 this.fireEvent('confirm', this);
48042 // Subclasses should provide the validation implementation by overriding this
48043 validateValue : function(value){
48044 if(this.allowBlank){
48048 if(this.isConfirmed){
48055 * Ext JS Library 1.1.1
48056 * Copyright(c) 2006-2007, Ext JS, LLC.
48058 * Originally Released Under LGPL - original licence link has changed is not relivant.
48061 * <script type="text/javascript">
48066 * @class Roo.form.ComboBox
48067 * @extends Roo.form.TriggerField
48068 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
48070 * Create a new ComboBox.
48071 * @param {Object} config Configuration options
48073 Roo.form.Select = function(config){
48074 Roo.form.Select.superclass.constructor.call(this, config);
48078 Roo.extend(Roo.form.Select , Roo.form.ComboBox, {
48080 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
48083 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
48084 * rendering into an Roo.Editor, defaults to false)
48087 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
48088 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
48091 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
48094 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
48095 * the dropdown list (defaults to undefined, with no header element)
48099 * @cfg {String/Roo.Template} tpl The template to use to render the output
48103 defaultAutoCreate : {tag: "select" },
48105 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
48107 listWidth: undefined,
48109 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
48110 * mode = 'remote' or 'text' if mode = 'local')
48112 displayField: undefined,
48114 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
48115 * mode = 'remote' or 'value' if mode = 'local').
48116 * Note: use of a valueField requires the user make a selection
48117 * in order for a value to be mapped.
48119 valueField: undefined,
48123 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
48124 * field's data value (defaults to the underlying DOM element's name)
48126 hiddenName: undefined,
48128 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
48132 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
48134 selectedClass: 'x-combo-selected',
48136 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
48137 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
48138 * which displays a downward arrow icon).
48140 triggerClass : 'x-form-arrow-trigger',
48142 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
48146 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
48147 * anchor positions (defaults to 'tl-bl')
48149 listAlign: 'tl-bl?',
48151 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
48155 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
48156 * query specified by the allQuery config option (defaults to 'query')
48158 triggerAction: 'query',
48160 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
48161 * (defaults to 4, does not apply if editable = false)
48165 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
48166 * delay (typeAheadDelay) if it matches a known value (defaults to false)
48170 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
48171 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
48175 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
48176 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
48180 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
48181 * when editable = true (defaults to false)
48183 selectOnFocus:false,
48185 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
48187 queryParam: 'query',
48189 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
48190 * when mode = 'remote' (defaults to 'Loading...')
48192 loadingText: 'Loading...',
48194 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
48198 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
48202 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
48203 * traditional select (defaults to true)
48207 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
48211 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
48215 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
48216 * listWidth has a higher value)
48220 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
48221 * allow the user to set arbitrary text into the field (defaults to false)
48223 forceSelection:false,
48225 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
48226 * if typeAhead = true (defaults to 250)
48228 typeAheadDelay : 250,
48230 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
48231 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
48233 valueNotFoundText : undefined,
48236 * @cfg {String} defaultValue The value displayed after loading the store.
48241 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
48243 blockFocus : false,
48246 * @cfg {Boolean} disableClear Disable showing of clear button.
48248 disableClear : false,
48250 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
48252 alwaysQuery : false,
48258 // element that contains real text value.. (when hidden is used..)
48261 onRender : function(ct, position){
48262 Roo.form.Field.prototype.onRender.call(this, ct, position);
48265 this.store.on('beforeload', this.onBeforeLoad, this);
48266 this.store.on('load', this.onLoad, this);
48267 this.store.on('loadexception', this.onLoadException, this);
48268 this.store.load({});
48276 initEvents : function(){
48277 //Roo.form.ComboBox.superclass.initEvents.call(this);
48281 onDestroy : function(){
48284 this.store.un('beforeload', this.onBeforeLoad, this);
48285 this.store.un('load', this.onLoad, this);
48286 this.store.un('loadexception', this.onLoadException, this);
48288 //Roo.form.ComboBox.superclass.onDestroy.call(this);
48292 fireKey : function(e){
48293 if(e.isNavKeyPress() && !this.list.isVisible()){
48294 this.fireEvent("specialkey", this, e);
48299 onResize: function(w, h){
48307 * Allow or prevent the user from directly editing the field text. If false is passed,
48308 * the user will only be able to select from the items defined in the dropdown list. This method
48309 * is the runtime equivalent of setting the 'editable' config option at config time.
48310 * @param {Boolean} value True to allow the user to directly edit the field text
48312 setEditable : function(value){
48317 onBeforeLoad : function(){
48319 Roo.log("Select before load");
48322 this.innerList.update(this.loadingText ?
48323 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
48324 //this.restrictHeight();
48325 this.selectedIndex = -1;
48329 onLoad : function(){
48332 var dom = this.el.dom;
48333 dom.innerHTML = '';
48334 var od = dom.ownerDocument;
48336 if (this.emptyText) {
48337 var op = od.createElement('option');
48338 op.setAttribute('value', '');
48339 op.innerHTML = String.format('{0}', this.emptyText);
48340 dom.appendChild(op);
48342 if(this.store.getCount() > 0){
48344 var vf = this.valueField;
48345 var df = this.displayField;
48346 this.store.data.each(function(r) {
48347 // which colmsn to use... testing - cdoe / title..
48348 var op = od.createElement('option');
48349 op.setAttribute('value', r.data[vf]);
48350 op.innerHTML = String.format('{0}', r.data[df]);
48351 dom.appendChild(op);
48353 if (typeof(this.defaultValue != 'undefined')) {
48354 this.setValue(this.defaultValue);
48359 //this.onEmptyResults();
48364 onLoadException : function()
48366 dom.innerHTML = '';
48368 Roo.log("Select on load exception");
48372 Roo.log(this.store.reader.jsonData);
48373 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
48374 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
48380 onTypeAhead : function(){
48385 onSelect : function(record, index){
48386 Roo.log('on select?');
48388 if(this.fireEvent('beforeselect', this, record, index) !== false){
48389 this.setFromData(index > -1 ? record.data : false);
48391 this.fireEvent('select', this, record, index);
48396 * Returns the currently selected field value or empty string if no value is set.
48397 * @return {String} value The selected value
48399 getValue : function(){
48400 var dom = this.el.dom;
48401 this.value = dom.options[dom.selectedIndex].value;
48407 * Clears any text/value currently set in the field
48409 clearValue : function(){
48411 this.el.dom.selectedIndex = this.emptyText ? 0 : -1;
48416 * Sets the specified value into the field. If the value finds a match, the corresponding record text
48417 * will be displayed in the field. If the value does not match the data value of an existing item,
48418 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
48419 * Otherwise the field will be blank (although the value will still be set).
48420 * @param {String} value The value to match
48422 setValue : function(v){
48423 var d = this.el.dom;
48424 for (var i =0; i < d.options.length;i++) {
48425 if (v == d.options[i].value) {
48426 d.selectedIndex = i;
48434 * @property {Object} the last set data for the element
48439 * Sets the value of the field based on a object which is related to the record format for the store.
48440 * @param {Object} value the value to set as. or false on reset?
48442 setFromData : function(o){
48443 Roo.log('setfrom data?');
48449 reset : function(){
48453 findRecord : function(prop, value){
48458 if(this.store.getCount() > 0){
48459 this.store.each(function(r){
48460 if(r.data[prop] == value){
48470 getName: function()
48472 // returns hidden if it's set..
48473 if (!this.rendered) {return ''};
48474 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
48482 onEmptyResults : function(){
48483 Roo.log('empty results');
48488 * Returns true if the dropdown list is expanded, else false.
48490 isExpanded : function(){
48495 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
48496 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
48497 * @param {String} value The data value of the item to select
48498 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
48499 * selected item if it is not currently in view (defaults to true)
48500 * @return {Boolean} True if the value matched an item in the list, else false
48502 selectByValue : function(v, scrollIntoView){
48503 Roo.log('select By Value');
48506 if(v !== undefined && v !== null){
48507 var r = this.findRecord(this.valueField || this.displayField, v);
48509 this.select(this.store.indexOf(r), scrollIntoView);
48517 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
48518 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
48519 * @param {Number} index The zero-based index of the list item to select
48520 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
48521 * selected item if it is not currently in view (defaults to true)
48523 select : function(index, scrollIntoView){
48524 Roo.log('select ');
48527 this.selectedIndex = index;
48528 this.view.select(index);
48529 if(scrollIntoView !== false){
48530 var el = this.view.getNode(index);
48532 this.innerList.scrollChildIntoView(el, false);
48540 validateBlur : function(){
48547 initQuery : function(){
48548 this.doQuery(this.getRawValue());
48552 doForce : function(){
48553 if(this.el.dom.value.length > 0){
48554 this.el.dom.value =
48555 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
48561 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
48562 * query allowing the query action to be canceled if needed.
48563 * @param {String} query The SQL query to execute
48564 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
48565 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
48566 * saved in the current store (defaults to false)
48568 doQuery : function(q, forceAll){
48570 Roo.log('doQuery?');
48571 if(q === undefined || q === null){
48576 forceAll: forceAll,
48580 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
48584 forceAll = qe.forceAll;
48585 if(forceAll === true || (q.length >= this.minChars)){
48586 if(this.lastQuery != q || this.alwaysQuery){
48587 this.lastQuery = q;
48588 if(this.mode == 'local'){
48589 this.selectedIndex = -1;
48591 this.store.clearFilter();
48593 this.store.filter(this.displayField, q);
48597 this.store.baseParams[this.queryParam] = q;
48599 params: this.getParams(q)
48604 this.selectedIndex = -1;
48611 getParams : function(q){
48613 //p[this.queryParam] = q;
48616 p.limit = this.pageSize;
48622 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
48624 collapse : function(){
48629 collapseIf : function(e){
48634 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
48636 expand : function(){
48644 * @cfg {Boolean} grow
48648 * @cfg {Number} growMin
48652 * @cfg {Number} growMax
48660 setWidth : function()
48664 getResizeEl : function(){
48667 });//<script type="text/javasscript">
48671 * @class Roo.DDView
48672 * A DnD enabled version of Roo.View.
48673 * @param {Element/String} container The Element in which to create the View.
48674 * @param {String} tpl The template string used to create the markup for each element of the View
48675 * @param {Object} config The configuration properties. These include all the config options of
48676 * {@link Roo.View} plus some specific to this class.<br>
48678 * Drag/drop is implemented by adding {@link Roo.data.Record}s to the target DDView. If copying is
48679 * not being performed, the original {@link Roo.data.Record} is removed from the source DDView.<br>
48681 * The following extra CSS rules are needed to provide insertion point highlighting:<pre><code>
48682 .x-view-drag-insert-above {
48683 border-top:1px dotted #3366cc;
48685 .x-view-drag-insert-below {
48686 border-bottom:1px dotted #3366cc;
48692 Roo.DDView = function(container, tpl, config) {
48693 Roo.DDView.superclass.constructor.apply(this, arguments);
48694 this.getEl().setStyle("outline", "0px none");
48695 this.getEl().unselectable();
48696 if (this.dragGroup) {
48697 this.setDraggable(this.dragGroup.split(","));
48699 if (this.dropGroup) {
48700 this.setDroppable(this.dropGroup.split(","));
48702 if (this.deletable) {
48703 this.setDeletable();
48705 this.isDirtyFlag = false;
48711 Roo.extend(Roo.DDView, Roo.View, {
48712 /** @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone. */
48713 /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
48714 /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
48715 /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
48719 reset: Roo.emptyFn,
48721 clearInvalid: Roo.form.Field.prototype.clearInvalid,
48723 validate: function() {
48727 destroy: function() {
48728 this.purgeListeners();
48729 this.getEl.removeAllListeners();
48730 this.getEl().remove();
48731 if (this.dragZone) {
48732 if (this.dragZone.destroy) {
48733 this.dragZone.destroy();
48736 if (this.dropZone) {
48737 if (this.dropZone.destroy) {
48738 this.dropZone.destroy();
48743 /** Allows this class to be an Roo.form.Field so it can be found using {@link Roo.form.BasicForm#findField}. */
48744 getName: function() {
48748 /** Loads the View from a JSON string representing the Records to put into the Store. */
48749 setValue: function(v) {
48751 throw "DDView.setValue(). DDView must be constructed with a valid Store";
48754 data[this.store.reader.meta.root] = v ? [].concat(v) : [];
48755 this.store.proxy = new Roo.data.MemoryProxy(data);
48759 /** @return {String} a parenthesised list of the ids of the Records in the View. */
48760 getValue: function() {
48762 this.store.each(function(rec) {
48763 result += rec.id + ',';
48765 return result.substr(0, result.length - 1) + ')';
48768 getIds: function() {
48769 var i = 0, result = new Array(this.store.getCount());
48770 this.store.each(function(rec) {
48771 result[i++] = rec.id;
48776 isDirty: function() {
48777 return this.isDirtyFlag;
48781 * Part of the Roo.dd.DropZone interface. If no target node is found, the
48782 * whole Element becomes the target, and this causes the drop gesture to append.
48784 getTargetFromEvent : function(e) {
48785 var target = e.getTarget();
48786 while ((target !== null) && (target.parentNode != this.el.dom)) {
48787 target = target.parentNode;
48790 target = this.el.dom.lastChild || this.el.dom;
48796 * Create the drag data which consists of an object which has the property "ddel" as
48797 * the drag proxy element.
48799 getDragData : function(e) {
48800 var target = this.findItemFromChild(e.getTarget());
48802 this.handleSelection(e);
48803 var selNodes = this.getSelectedNodes();
48806 copy: this.copy || (this.allowCopy && e.ctrlKey),
48810 var selectedIndices = this.getSelectedIndexes();
48811 for (var i = 0; i < selectedIndices.length; i++) {
48812 dragData.records.push(this.store.getAt(selectedIndices[i]));
48814 if (selNodes.length == 1) {
48815 dragData.ddel = target.cloneNode(true); // the div element
48817 var div = document.createElement('div'); // create the multi element drag "ghost"
48818 div.className = 'multi-proxy';
48819 for (var i = 0, len = selNodes.length; i < len; i++) {
48820 div.appendChild(selNodes[i].cloneNode(true));
48822 dragData.ddel = div;
48824 //console.log(dragData)
48825 //console.log(dragData.ddel.innerHTML)
48828 //console.log('nodragData')
48832 /** Specify to which ddGroup items in this DDView may be dragged. */
48833 setDraggable: function(ddGroup) {
48834 if (ddGroup instanceof Array) {
48835 Roo.each(ddGroup, this.setDraggable, this);
48838 if (this.dragZone) {
48839 this.dragZone.addToGroup(ddGroup);
48841 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
48842 containerScroll: true,
48846 // Draggability implies selection. DragZone's mousedown selects the element.
48847 if (!this.multiSelect) { this.singleSelect = true; }
48849 // Wire the DragZone's handlers up to methods in *this*
48850 this.dragZone.getDragData = this.getDragData.createDelegate(this);
48854 /** Specify from which ddGroup this DDView accepts drops. */
48855 setDroppable: function(ddGroup) {
48856 if (ddGroup instanceof Array) {
48857 Roo.each(ddGroup, this.setDroppable, this);
48860 if (this.dropZone) {
48861 this.dropZone.addToGroup(ddGroup);
48863 this.dropZone = new Roo.dd.DropZone(this.getEl(), {
48864 containerScroll: true,
48868 // Wire the DropZone's handlers up to methods in *this*
48869 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
48870 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
48871 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
48872 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
48873 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
48877 /** Decide whether to drop above or below a View node. */
48878 getDropPoint : function(e, n, dd){
48879 if (n == this.el.dom) { return "above"; }
48880 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
48881 var c = t + (b - t) / 2;
48882 var y = Roo.lib.Event.getPageY(e);
48890 onNodeEnter : function(n, dd, e, data){
48894 onNodeOver : function(n, dd, e, data){
48895 var pt = this.getDropPoint(e, n, dd);
48896 // set the insert point style on the target node
48897 var dragElClass = this.dropNotAllowed;
48900 if (pt == "above"){
48901 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
48902 targetElClass = "x-view-drag-insert-above";
48904 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
48905 targetElClass = "x-view-drag-insert-below";
48907 if (this.lastInsertClass != targetElClass){
48908 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
48909 this.lastInsertClass = targetElClass;
48912 return dragElClass;
48915 onNodeOut : function(n, dd, e, data){
48916 this.removeDropIndicators(n);
48919 onNodeDrop : function(n, dd, e, data){
48920 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
48923 var pt = this.getDropPoint(e, n, dd);
48924 var insertAt = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
48925 if (pt == "below") { insertAt++; }
48926 for (var i = 0; i < data.records.length; i++) {
48927 var r = data.records[i];
48928 var dup = this.store.getById(r.id);
48929 if (dup && (dd != this.dragZone)) {
48930 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
48933 this.store.insert(insertAt++, r.copy());
48935 data.source.isDirtyFlag = true;
48937 this.store.insert(insertAt++, r);
48939 this.isDirtyFlag = true;
48942 this.dragZone.cachedTarget = null;
48946 removeDropIndicators : function(n){
48948 Roo.fly(n).removeClass([
48949 "x-view-drag-insert-above",
48950 "x-view-drag-insert-below"]);
48951 this.lastInsertClass = "_noclass";
48956 * Utility method. Add a delete option to the DDView's context menu.
48957 * @param {String} imageUrl The URL of the "delete" icon image.
48959 setDeletable: function(imageUrl) {
48960 if (!this.singleSelect && !this.multiSelect) {
48961 this.singleSelect = true;
48963 var c = this.getContextMenu();
48964 this.contextMenu.on("itemclick", function(item) {
48967 this.remove(this.getSelectedIndexes());
48971 this.contextMenu.add({
48978 /** Return the context menu for this DDView. */
48979 getContextMenu: function() {
48980 if (!this.contextMenu) {
48981 // Create the View's context menu
48982 this.contextMenu = new Roo.menu.Menu({
48983 id: this.id + "-contextmenu"
48985 this.el.on("contextmenu", this.showContextMenu, this);
48987 return this.contextMenu;
48990 disableContextMenu: function() {
48991 if (this.contextMenu) {
48992 this.el.un("contextmenu", this.showContextMenu, this);
48996 showContextMenu: function(e, item) {
48997 item = this.findItemFromChild(e.getTarget());
49000 this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true);
49001 this.contextMenu.showAt(e.getXY());
49006 * Remove {@link Roo.data.Record}s at the specified indices.
49007 * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove.
49009 remove: function(selectedIndices) {
49010 selectedIndices = [].concat(selectedIndices);
49011 for (var i = 0; i < selectedIndices.length; i++) {
49012 var rec = this.store.getAt(selectedIndices[i]);
49013 this.store.remove(rec);
49018 * Double click fires the event, but also, if this is draggable, and there is only one other
49019 * related DropZone, it transfers the selected node.
49021 onDblClick : function(e){
49022 var item = this.findItemFromChild(e.getTarget());
49024 if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) {
49027 if (this.dragGroup) {
49028 var targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
49029 while (targets.indexOf(this.dropZone) > -1) {
49030 targets.remove(this.dropZone);
49032 if (targets.length == 1) {
49033 this.dragZone.cachedTarget = null;
49034 var el = Roo.get(targets[0].getEl());
49035 var box = el.getBox(true);
49036 targets[0].onNodeDrop(el.dom, {
49038 xy: [box.x, box.y + box.height - 1]
49039 }, null, this.getDragData(e));
49045 handleSelection: function(e) {
49046 this.dragZone.cachedTarget = null;
49047 var item = this.findItemFromChild(e.getTarget());
49049 this.clearSelections(true);
49052 if (item && (this.multiSelect || this.singleSelect)){
49053 if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
49054 this.select(this.getNodes(this.indexOf(this.lastSelection), item.nodeIndex), false);
49055 }else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
49056 this.unselect(item);
49058 this.select(item, this.multiSelect && e.ctrlKey);
49059 this.lastSelection = item;
49064 onItemClick : function(item, index, e){
49065 if(this.fireEvent("beforeclick", this, index, item, e) === false){
49071 unselect : function(nodeInfo, suppressEvent){
49072 var node = this.getNode(nodeInfo);
49073 if(node && this.isSelected(node)){
49074 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
49075 Roo.fly(node).removeClass(this.selectedClass);
49076 this.selections.remove(node);
49077 if(!suppressEvent){
49078 this.fireEvent("selectionchange", this, this.selections);
49086 * Ext JS Library 1.1.1
49087 * Copyright(c) 2006-2007, Ext JS, LLC.
49089 * Originally Released Under LGPL - original licence link has changed is not relivant.
49092 * <script type="text/javascript">
49096 * @class Roo.LayoutManager
49097 * @extends Roo.util.Observable
49098 * Base class for layout managers.
49100 Roo.LayoutManager = function(container, config){
49101 Roo.LayoutManager.superclass.constructor.call(this);
49102 this.el = Roo.get(container);
49103 // ie scrollbar fix
49104 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
49105 document.body.scroll = "no";
49106 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
49107 this.el.position('relative');
49109 this.id = this.el.id;
49110 this.el.addClass("x-layout-container");
49111 /** false to disable window resize monitoring @type Boolean */
49112 this.monitorWindowResize = true;
49117 * Fires when a layout is performed.
49118 * @param {Roo.LayoutManager} this
49122 * @event regionresized
49123 * Fires when the user resizes a region.
49124 * @param {Roo.LayoutRegion} region The resized region
49125 * @param {Number} newSize The new size (width for east/west, height for north/south)
49127 "regionresized" : true,
49129 * @event regioncollapsed
49130 * Fires when a region is collapsed.
49131 * @param {Roo.LayoutRegion} region The collapsed region
49133 "regioncollapsed" : true,
49135 * @event regionexpanded
49136 * Fires when a region is expanded.
49137 * @param {Roo.LayoutRegion} region The expanded region
49139 "regionexpanded" : true
49141 this.updating = false;
49142 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
49145 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
49147 * Returns true if this layout is currently being updated
49148 * @return {Boolean}
49150 isUpdating : function(){
49151 return this.updating;
49155 * Suspend the LayoutManager from doing auto-layouts while
49156 * making multiple add or remove calls
49158 beginUpdate : function(){
49159 this.updating = true;
49163 * Restore auto-layouts and optionally disable the manager from performing a layout
49164 * @param {Boolean} noLayout true to disable a layout update
49166 endUpdate : function(noLayout){
49167 this.updating = false;
49173 layout: function(){
49177 onRegionResized : function(region, newSize){
49178 this.fireEvent("regionresized", region, newSize);
49182 onRegionCollapsed : function(region){
49183 this.fireEvent("regioncollapsed", region);
49186 onRegionExpanded : function(region){
49187 this.fireEvent("regionexpanded", region);
49191 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
49192 * performs box-model adjustments.
49193 * @return {Object} The size as an object {width: (the width), height: (the height)}
49195 getViewSize : function(){
49197 if(this.el.dom != document.body){
49198 size = this.el.getSize();
49200 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
49202 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
49203 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
49208 * Returns the Element this layout is bound to.
49209 * @return {Roo.Element}
49211 getEl : function(){
49216 * Returns the specified region.
49217 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
49218 * @return {Roo.LayoutRegion}
49220 getRegion : function(target){
49221 return this.regions[target.toLowerCase()];
49224 onWindowResize : function(){
49225 if(this.monitorWindowResize){
49231 * Ext JS Library 1.1.1
49232 * Copyright(c) 2006-2007, Ext JS, LLC.
49234 * Originally Released Under LGPL - original licence link has changed is not relivant.
49237 * <script type="text/javascript">
49240 * @class Roo.BorderLayout
49241 * @extends Roo.LayoutManager
49242 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
49243 * please see: <br><br>
49244 * <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>
49245 * <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>
49248 var layout = new Roo.BorderLayout(document.body, {
49282 preferredTabWidth: 150
49287 var CP = Roo.ContentPanel;
49289 layout.beginUpdate();
49290 layout.add("north", new CP("north", "North"));
49291 layout.add("south", new CP("south", {title: "South", closable: true}));
49292 layout.add("west", new CP("west", {title: "West"}));
49293 layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
49294 layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
49295 layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
49296 layout.getRegion("center").showPanel("center1");
49297 layout.endUpdate();
49300 <b>The container the layout is rendered into can be either the body element or any other element.
49301 If it is not the body element, the container needs to either be an absolute positioned element,
49302 or you will need to add "position:relative" to the css of the container. You will also need to specify
49303 the container size if it is not the body element.</b>
49306 * Create a new BorderLayout
49307 * @param {String/HTMLElement/Element} container The container this layout is bound to
49308 * @param {Object} config Configuration options
49310 Roo.BorderLayout = function(container, config){
49311 config = config || {};
49312 Roo.BorderLayout.superclass.constructor.call(this, container, config);
49313 this.factory = config.factory || Roo.BorderLayout.RegionFactory;
49314 for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
49315 var target = this.factory.validRegions[i];
49316 if(config[target]){
49317 this.addRegion(target, config[target]);
49322 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
49324 * Creates and adds a new region if it doesn't already exist.
49325 * @param {String} target The target region key (north, south, east, west or center).
49326 * @param {Object} config The regions config object
49327 * @return {BorderLayoutRegion} The new region
49329 addRegion : function(target, config){
49330 if(!this.regions[target]){
49331 var r = this.factory.create(target, this, config);
49332 this.bindRegion(target, r);
49334 return this.regions[target];
49338 bindRegion : function(name, r){
49339 this.regions[name] = r;
49340 r.on("visibilitychange", this.layout, this);
49341 r.on("paneladded", this.layout, this);
49342 r.on("panelremoved", this.layout, this);
49343 r.on("invalidated", this.layout, this);
49344 r.on("resized", this.onRegionResized, this);
49345 r.on("collapsed", this.onRegionCollapsed, this);
49346 r.on("expanded", this.onRegionExpanded, this);
49350 * Performs a layout update.
49352 layout : function(){
49353 if(this.updating) return;
49354 var size = this.getViewSize();
49355 var w = size.width;
49356 var h = size.height;
49361 //var x = 0, y = 0;
49363 var rs = this.regions;
49364 var north = rs["north"];
49365 var south = rs["south"];
49366 var west = rs["west"];
49367 var east = rs["east"];
49368 var center = rs["center"];
49369 //if(this.hideOnLayout){ // not supported anymore
49370 //c.el.setStyle("display", "none");
49372 if(north && north.isVisible()){
49373 var b = north.getBox();
49374 var m = north.getMargins();
49375 b.width = w - (m.left+m.right);
49378 centerY = b.height + b.y + m.bottom;
49379 centerH -= centerY;
49380 north.updateBox(this.safeBox(b));
49382 if(south && south.isVisible()){
49383 var b = south.getBox();
49384 var m = south.getMargins();
49385 b.width = w - (m.left+m.right);
49387 var totalHeight = (b.height + m.top + m.bottom);
49388 b.y = h - totalHeight + m.top;
49389 centerH -= totalHeight;
49390 south.updateBox(this.safeBox(b));
49392 if(west && west.isVisible()){
49393 var b = west.getBox();
49394 var m = west.getMargins();
49395 b.height = centerH - (m.top+m.bottom);
49397 b.y = centerY + m.top;
49398 var totalWidth = (b.width + m.left + m.right);
49399 centerX += totalWidth;
49400 centerW -= totalWidth;
49401 west.updateBox(this.safeBox(b));
49403 if(east && east.isVisible()){
49404 var b = east.getBox();
49405 var m = east.getMargins();
49406 b.height = centerH - (m.top+m.bottom);
49407 var totalWidth = (b.width + m.left + m.right);
49408 b.x = w - totalWidth + m.left;
49409 b.y = centerY + m.top;
49410 centerW -= totalWidth;
49411 east.updateBox(this.safeBox(b));
49414 var m = center.getMargins();
49416 x: centerX + m.left,
49417 y: centerY + m.top,
49418 width: centerW - (m.left+m.right),
49419 height: centerH - (m.top+m.bottom)
49421 //if(this.hideOnLayout){
49422 //center.el.setStyle("display", "block");
49424 center.updateBox(this.safeBox(centerBox));
49427 this.fireEvent("layout", this);
49431 safeBox : function(box){
49432 box.width = Math.max(0, box.width);
49433 box.height = Math.max(0, box.height);
49438 * Adds a ContentPanel (or subclass) to this layout.
49439 * @param {String} target The target region key (north, south, east, west or center).
49440 * @param {Roo.ContentPanel} panel The panel to add
49441 * @return {Roo.ContentPanel} The added panel
49443 add : function(target, panel){
49445 target = target.toLowerCase();
49446 return this.regions[target].add(panel);
49450 * Remove a ContentPanel (or subclass) to this layout.
49451 * @param {String} target The target region key (north, south, east, west or center).
49452 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
49453 * @return {Roo.ContentPanel} The removed panel
49455 remove : function(target, panel){
49456 target = target.toLowerCase();
49457 return this.regions[target].remove(panel);
49461 * Searches all regions for a panel with the specified id
49462 * @param {String} panelId
49463 * @return {Roo.ContentPanel} The panel or null if it wasn't found
49465 findPanel : function(panelId){
49466 var rs = this.regions;
49467 for(var target in rs){
49468 if(typeof rs[target] != "function"){
49469 var p = rs[target].getPanel(panelId);
49479 * Searches all regions for a panel with the specified id and activates (shows) it.
49480 * @param {String/ContentPanel} panelId The panels id or the panel itself
49481 * @return {Roo.ContentPanel} The shown panel or null
49483 showPanel : function(panelId) {
49484 var rs = this.regions;
49485 for(var target in rs){
49486 var r = rs[target];
49487 if(typeof r != "function"){
49488 if(r.hasPanel(panelId)){
49489 return r.showPanel(panelId);
49497 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
49498 * @param {Roo.state.Provider} provider (optional) An alternate state provider
49500 restoreState : function(provider){
49502 provider = Roo.state.Manager;
49504 var sm = new Roo.LayoutStateManager();
49505 sm.init(this, provider);
49509 * Adds a batch of multiple ContentPanels dynamically by passing a special regions config object. This config
49510 * object should contain properties for each region to add ContentPanels to, and each property's value should be
49511 * a valid ContentPanel config object. Example:
49513 // Create the main layout
49514 var layout = new Roo.BorderLayout('main-ct', {
49525 // Create and add multiple ContentPanels at once via configs
49528 id: 'source-files',
49530 title:'Ext Source Files',
49543 * @param {Object} regions An object containing ContentPanel configs by region name
49545 batchAdd : function(regions){
49546 this.beginUpdate();
49547 for(var rname in regions){
49548 var lr = this.regions[rname];
49550 this.addTypedPanels(lr, regions[rname]);
49557 addTypedPanels : function(lr, ps){
49558 if(typeof ps == 'string'){
49559 lr.add(new Roo.ContentPanel(ps));
49561 else if(ps instanceof Array){
49562 for(var i =0, len = ps.length; i < len; i++){
49563 this.addTypedPanels(lr, ps[i]);
49566 else if(!ps.events){ // raw config?
49568 delete ps.el; // prevent conflict
49569 lr.add(new Roo.ContentPanel(el || Roo.id(), ps));
49571 else { // panel object assumed!
49576 * Adds a xtype elements to the layout.
49580 xtype : 'ContentPanel',
49587 xtype : 'NestedLayoutPanel',
49593 items : [ ... list of content panels or nested layout panels.. ]
49597 * @param {Object} cfg Xtype definition of item to add.
49599 addxtype : function(cfg)
49601 // basically accepts a pannel...
49602 // can accept a layout region..!?!?
49603 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
49605 if (!cfg.xtype.match(/Panel$/)) {
49610 if (typeof(cfg.region) == 'undefined') {
49611 Roo.log("Failed to add Panel, region was not set");
49615 var region = cfg.region;
49621 xitems = cfg.items;
49628 case 'ContentPanel': // ContentPanel (el, cfg)
49629 case 'ScrollPanel': // ContentPanel (el, cfg)
49631 if(cfg.autoCreate) {
49632 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
49634 var el = this.el.createChild();
49635 ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
49638 this.add(region, ret);
49642 case 'TreePanel': // our new panel!
49643 cfg.el = this.el.createChild();
49644 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
49645 this.add(region, ret);
49648 case 'NestedLayoutPanel':
49649 // create a new Layout (which is a Border Layout...
49650 var el = this.el.createChild();
49651 var clayout = cfg.layout;
49653 clayout.items = clayout.items || [];
49654 // replace this exitems with the clayout ones..
49655 xitems = clayout.items;
49658 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
49659 cfg.background = false;
49661 var layout = new Roo.BorderLayout(el, clayout);
49663 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
49664 //console.log('adding nested layout panel ' + cfg.toSource());
49665 this.add(region, ret);
49666 nb = {}; /// find first...
49671 // needs grid and region
49673 //var el = this.getRegion(region).el.createChild();
49674 var el = this.el.createChild();
49675 // create the grid first...
49677 var grid = new Roo.grid[cfg.grid.xtype](el, cfg.grid);
49679 if (region == 'center' && this.active ) {
49680 cfg.background = false;
49682 ret = new Roo[cfg.xtype](grid, cfg); // new panel!!!!!
49684 this.add(region, ret);
49685 if (cfg.background) {
49686 ret.on('activate', function(gp) {
49687 if (!gp.grid.rendered) {
49702 if (typeof(Roo[cfg.xtype]) != 'undefined') {
49704 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
49705 this.add(region, ret);
49708 alert("Can not add '" + cfg.xtype + "' to BorderLayout");
49712 // GridPanel (grid, cfg)
49715 this.beginUpdate();
49719 Roo.each(xitems, function(i) {
49720 region = nb && i.region ? i.region : false;
49722 var add = ret.addxtype(i);
49725 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
49726 if (!i.background) {
49727 abn[region] = nb[region] ;
49734 // make the last non-background panel active..
49735 //if (nb) { Roo.log(abn); }
49738 for(var r in abn) {
49739 region = this.getRegion(r);
49741 // tried using nb[r], but it does not work..
49743 region.showPanel(abn[r]);
49754 * Shortcut for creating a new BorderLayout object and adding one or more ContentPanels to it in a single step, handling
49755 * the beginUpdate and endUpdate calls internally. The key to this method is the <b>panels</b> property that can be
49756 * provided with each region config, which allows you to add ContentPanel configs in addition to the region configs
49757 * during creation. The following code is equivalent to the constructor-based example at the beginning of this class:
49760 var CP = Roo.ContentPanel;
49762 var layout = Roo.BorderLayout.create({
49766 panels: [new CP("north", "North")]
49775 panels: [new CP("west", {title: "West"})]
49784 panels: [new CP("autoTabs", {title: "Auto Tabs", closable: true})]
49793 panels: [new CP("south", {title: "South", closable: true})]
49800 preferredTabWidth: 150,
49802 new CP("center1", {title: "Close Me", closable: true}),
49803 new CP("center2", {title: "Center Panel", closable: false})
49808 layout.getRegion("center").showPanel("center1");
49813 Roo.BorderLayout.create = function(config, targetEl){
49814 var layout = new Roo.BorderLayout(targetEl || document.body, config);
49815 layout.beginUpdate();
49816 var regions = Roo.BorderLayout.RegionFactory.validRegions;
49817 for(var j = 0, jlen = regions.length; j < jlen; j++){
49818 var lr = regions[j];
49819 if(layout.regions[lr] && config[lr].panels){
49820 var r = layout.regions[lr];
49821 var ps = config[lr].panels;
49822 layout.addTypedPanels(r, ps);
49825 layout.endUpdate();
49830 Roo.BorderLayout.RegionFactory = {
49832 validRegions : ["north","south","east","west","center"],
49835 create : function(target, mgr, config){
49836 target = target.toLowerCase();
49837 if(config.lightweight || config.basic){
49838 return new Roo.BasicLayoutRegion(mgr, config, target);
49842 return new Roo.NorthLayoutRegion(mgr, config);
49844 return new Roo.SouthLayoutRegion(mgr, config);
49846 return new Roo.EastLayoutRegion(mgr, config);
49848 return new Roo.WestLayoutRegion(mgr, config);
49850 return new Roo.CenterLayoutRegion(mgr, config);
49852 throw 'Layout region "'+target+'" not supported.';
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">
49866 * @class Roo.BasicLayoutRegion
49867 * @extends Roo.util.Observable
49868 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
49869 * and does not have a titlebar, tabs or any other features. All it does is size and position
49870 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
49872 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
49874 this.position = pos;
49877 * @scope Roo.BasicLayoutRegion
49881 * @event beforeremove
49882 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
49883 * @param {Roo.LayoutRegion} this
49884 * @param {Roo.ContentPanel} panel The panel
49885 * @param {Object} e The cancel event object
49887 "beforeremove" : true,
49889 * @event invalidated
49890 * Fires when the layout for this region is changed.
49891 * @param {Roo.LayoutRegion} this
49893 "invalidated" : true,
49895 * @event visibilitychange
49896 * Fires when this region is shown or hidden
49897 * @param {Roo.LayoutRegion} this
49898 * @param {Boolean} visibility true or false
49900 "visibilitychange" : true,
49902 * @event paneladded
49903 * Fires when a panel is added.
49904 * @param {Roo.LayoutRegion} this
49905 * @param {Roo.ContentPanel} panel The panel
49907 "paneladded" : true,
49909 * @event panelremoved
49910 * Fires when a panel is removed.
49911 * @param {Roo.LayoutRegion} this
49912 * @param {Roo.ContentPanel} panel The panel
49914 "panelremoved" : true,
49917 * Fires when this region is collapsed.
49918 * @param {Roo.LayoutRegion} this
49920 "collapsed" : true,
49923 * Fires when this region is expanded.
49924 * @param {Roo.LayoutRegion} this
49929 * Fires when this region is slid into view.
49930 * @param {Roo.LayoutRegion} this
49932 "slideshow" : true,
49935 * Fires when this region slides out of view.
49936 * @param {Roo.LayoutRegion} this
49938 "slidehide" : true,
49940 * @event panelactivated
49941 * Fires when a panel is activated.
49942 * @param {Roo.LayoutRegion} this
49943 * @param {Roo.ContentPanel} panel The activated panel
49945 "panelactivated" : true,
49948 * Fires when the user resizes this region.
49949 * @param {Roo.LayoutRegion} this
49950 * @param {Number} newSize The new size (width for east/west, height for north/south)
49954 /** A collection of panels in this region. @type Roo.util.MixedCollection */
49955 this.panels = new Roo.util.MixedCollection();
49956 this.panels.getKey = this.getPanelId.createDelegate(this);
49958 this.activePanel = null;
49959 // ensure listeners are added...
49961 if (config.listeners || config.events) {
49962 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
49963 listeners : config.listeners || {},
49964 events : config.events || {}
49968 if(skipConfig !== true){
49969 this.applyConfig(config);
49973 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
49974 getPanelId : function(p){
49978 applyConfig : function(config){
49979 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
49980 this.config = config;
49985 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
49986 * the width, for horizontal (north, south) the height.
49987 * @param {Number} newSize The new width or height
49989 resizeTo : function(newSize){
49990 var el = this.el ? this.el :
49991 (this.activePanel ? this.activePanel.getEl() : null);
49993 switch(this.position){
49996 el.setWidth(newSize);
49997 this.fireEvent("resized", this, newSize);
50001 el.setHeight(newSize);
50002 this.fireEvent("resized", this, newSize);
50008 getBox : function(){
50009 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
50012 getMargins : function(){
50013 return this.margins;
50016 updateBox : function(box){
50018 var el = this.activePanel.getEl();
50019 el.dom.style.left = box.x + "px";
50020 el.dom.style.top = box.y + "px";
50021 this.activePanel.setSize(box.width, box.height);
50025 * Returns the container element for this region.
50026 * @return {Roo.Element}
50028 getEl : function(){
50029 return this.activePanel;
50033 * Returns true if this region is currently visible.
50034 * @return {Boolean}
50036 isVisible : function(){
50037 return this.activePanel ? true : false;
50040 setActivePanel : function(panel){
50041 panel = this.getPanel(panel);
50042 if(this.activePanel && this.activePanel != panel){
50043 this.activePanel.setActiveState(false);
50044 this.activePanel.getEl().setLeftTop(-10000,-10000);
50046 this.activePanel = panel;
50047 panel.setActiveState(true);
50049 panel.setSize(this.box.width, this.box.height);
50051 this.fireEvent("panelactivated", this, panel);
50052 this.fireEvent("invalidated");
50056 * Show the specified panel.
50057 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
50058 * @return {Roo.ContentPanel} The shown panel or null
50060 showPanel : function(panel){
50061 if(panel = this.getPanel(panel)){
50062 this.setActivePanel(panel);
50068 * Get the active panel for this region.
50069 * @return {Roo.ContentPanel} The active panel or null
50071 getActivePanel : function(){
50072 return this.activePanel;
50076 * Add the passed ContentPanel(s)
50077 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
50078 * @return {Roo.ContentPanel} The panel added (if only one was added)
50080 add : function(panel){
50081 if(arguments.length > 1){
50082 for(var i = 0, len = arguments.length; i < len; i++) {
50083 this.add(arguments[i]);
50087 if(this.hasPanel(panel)){
50088 this.showPanel(panel);
50091 var el = panel.getEl();
50092 if(el.dom.parentNode != this.mgr.el.dom){
50093 this.mgr.el.dom.appendChild(el.dom);
50095 if(panel.setRegion){
50096 panel.setRegion(this);
50098 this.panels.add(panel);
50099 el.setStyle("position", "absolute");
50100 if(!panel.background){
50101 this.setActivePanel(panel);
50102 if(this.config.initialSize && this.panels.getCount()==1){
50103 this.resizeTo(this.config.initialSize);
50106 this.fireEvent("paneladded", this, panel);
50111 * Returns true if the panel is in this region.
50112 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
50113 * @return {Boolean}
50115 hasPanel : function(panel){
50116 if(typeof panel == "object"){ // must be panel obj
50117 panel = panel.getId();
50119 return this.getPanel(panel) ? true : false;
50123 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
50124 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
50125 * @param {Boolean} preservePanel Overrides the config preservePanel option
50126 * @return {Roo.ContentPanel} The panel that was removed
50128 remove : function(panel, preservePanel){
50129 panel = this.getPanel(panel);
50134 this.fireEvent("beforeremove", this, panel, e);
50135 if(e.cancel === true){
50138 var panelId = panel.getId();
50139 this.panels.removeKey(panelId);
50144 * Returns the panel specified or null if it's not in this region.
50145 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
50146 * @return {Roo.ContentPanel}
50148 getPanel : function(id){
50149 if(typeof id == "object"){ // must be panel obj
50152 return this.panels.get(id);
50156 * Returns this regions position (north/south/east/west/center).
50159 getPosition: function(){
50160 return this.position;
50164 * Ext JS Library 1.1.1
50165 * Copyright(c) 2006-2007, Ext JS, LLC.
50167 * Originally Released Under LGPL - original licence link has changed is not relivant.
50170 * <script type="text/javascript">
50174 * @class Roo.LayoutRegion
50175 * @extends Roo.BasicLayoutRegion
50176 * This class represents a region in a layout manager.
50177 * @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
50178 * @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
50179 * @cfg {Boolean} floatable False to disable floating (defaults to true)
50180 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
50181 * @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})
50182 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
50183 * @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
50184 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
50185 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
50186 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
50187 * @cfg {String} title The title for the region (overrides panel titles)
50188 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
50189 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
50190 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
50191 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
50192 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
50193 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
50194 * the space available, similar to FireFox 1.5 tabs (defaults to false)
50195 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
50196 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
50197 * @cfg {Boolean} showPin True to show a pin button
50198 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
50199 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
50200 * @cfg {Boolean} disableTabTips True to disable tab tooltips
50201 * @cfg {Number} width For East/West panels
50202 * @cfg {Number} height For North/South panels
50203 * @cfg {Boolean} split To show the splitter
50204 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
50206 Roo.LayoutRegion = function(mgr, config, pos){
50207 Roo.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
50208 var dh = Roo.DomHelper;
50209 /** This region's container element
50210 * @type Roo.Element */
50211 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
50212 /** This region's title element
50213 * @type Roo.Element */
50215 this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
50216 {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
50217 {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
50219 this.titleEl.enableDisplayMode();
50220 /** This region's title text element
50221 * @type HTMLElement */
50222 this.titleTextEl = this.titleEl.dom.firstChild;
50223 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
50224 this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
50225 this.closeBtn.enableDisplayMode();
50226 this.closeBtn.on("click", this.closeClicked, this);
50227 this.closeBtn.hide();
50229 this.createBody(config);
50230 this.visible = true;
50231 this.collapsed = false;
50233 if(config.hideWhenEmpty){
50235 this.on("paneladded", this.validateVisibility, this);
50236 this.on("panelremoved", this.validateVisibility, this);
50238 this.applyConfig(config);
50241 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
50243 createBody : function(){
50244 /** This region's body element
50245 * @type Roo.Element */
50246 this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
50249 applyConfig : function(c){
50250 if(c.collapsible && this.position != "center" && !this.collapsedEl){
50251 var dh = Roo.DomHelper;
50252 if(c.titlebar !== false){
50253 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
50254 this.collapseBtn.on("click", this.collapse, this);
50255 this.collapseBtn.enableDisplayMode();
50257 if(c.showPin === true || this.showPin){
50258 this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
50259 this.stickBtn.enableDisplayMode();
50260 this.stickBtn.on("click", this.expand, this);
50261 this.stickBtn.hide();
50264 /** This region's collapsed element
50265 * @type Roo.Element */
50266 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
50267 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
50269 if(c.floatable !== false){
50270 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
50271 this.collapsedEl.on("click", this.collapseClick, this);
50274 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
50275 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
50276 id: "message", unselectable: "on", style:{"float":"left"}});
50277 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
50279 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
50280 this.expandBtn.on("click", this.expand, this);
50282 if(this.collapseBtn){
50283 this.collapseBtn.setVisible(c.collapsible == true);
50285 this.cmargins = c.cmargins || this.cmargins ||
50286 (this.position == "west" || this.position == "east" ?
50287 {top: 0, left: 2, right:2, bottom: 0} :
50288 {top: 2, left: 0, right:0, bottom: 2});
50289 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
50290 this.bottomTabs = c.tabPosition != "top";
50291 this.autoScroll = c.autoScroll || false;
50292 if(this.autoScroll){
50293 this.bodyEl.setStyle("overflow", "auto");
50295 this.bodyEl.setStyle("overflow", "hidden");
50297 //if(c.titlebar !== false){
50298 if((!c.titlebar && !c.title) || c.titlebar === false){
50299 this.titleEl.hide();
50301 this.titleEl.show();
50303 this.titleTextEl.innerHTML = c.title;
50307 this.duration = c.duration || .30;
50308 this.slideDuration = c.slideDuration || .45;
50311 this.collapse(true);
50318 * Returns true if this region is currently visible.
50319 * @return {Boolean}
50321 isVisible : function(){
50322 return this.visible;
50326 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
50327 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
50329 setCollapsedTitle : function(title){
50330 title = title || " ";
50331 if(this.collapsedTitleTextEl){
50332 this.collapsedTitleTextEl.innerHTML = title;
50336 getBox : function(){
50338 if(!this.collapsed){
50339 b = this.el.getBox(false, true);
50341 b = this.collapsedEl.getBox(false, true);
50346 getMargins : function(){
50347 return this.collapsed ? this.cmargins : this.margins;
50350 highlight : function(){
50351 this.el.addClass("x-layout-panel-dragover");
50354 unhighlight : function(){
50355 this.el.removeClass("x-layout-panel-dragover");
50358 updateBox : function(box){
50360 if(!this.collapsed){
50361 this.el.dom.style.left = box.x + "px";
50362 this.el.dom.style.top = box.y + "px";
50363 this.updateBody(box.width, box.height);
50365 this.collapsedEl.dom.style.left = box.x + "px";
50366 this.collapsedEl.dom.style.top = box.y + "px";
50367 this.collapsedEl.setSize(box.width, box.height);
50370 this.tabs.autoSizeTabs();
50374 updateBody : function(w, h){
50376 this.el.setWidth(w);
50377 w -= this.el.getBorderWidth("rl");
50378 if(this.config.adjustments){
50379 w += this.config.adjustments[0];
50383 this.el.setHeight(h);
50384 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
50385 h -= this.el.getBorderWidth("tb");
50386 if(this.config.adjustments){
50387 h += this.config.adjustments[1];
50389 this.bodyEl.setHeight(h);
50391 h = this.tabs.syncHeight(h);
50394 if(this.panelSize){
50395 w = w !== null ? w : this.panelSize.width;
50396 h = h !== null ? h : this.panelSize.height;
50398 if(this.activePanel){
50399 var el = this.activePanel.getEl();
50400 w = w !== null ? w : el.getWidth();
50401 h = h !== null ? h : el.getHeight();
50402 this.panelSize = {width: w, height: h};
50403 this.activePanel.setSize(w, h);
50405 if(Roo.isIE && this.tabs){
50406 this.tabs.el.repaint();
50411 * Returns the container element for this region.
50412 * @return {Roo.Element}
50414 getEl : function(){
50419 * Hides this region.
50422 if(!this.collapsed){
50423 this.el.dom.style.left = "-2000px";
50426 this.collapsedEl.dom.style.left = "-2000px";
50427 this.collapsedEl.hide();
50429 this.visible = false;
50430 this.fireEvent("visibilitychange", this, false);
50434 * Shows this region if it was previously hidden.
50437 if(!this.collapsed){
50440 this.collapsedEl.show();
50442 this.visible = true;
50443 this.fireEvent("visibilitychange", this, true);
50446 closeClicked : function(){
50447 if(this.activePanel){
50448 this.remove(this.activePanel);
50452 collapseClick : function(e){
50454 e.stopPropagation();
50457 e.stopPropagation();
50463 * Collapses this region.
50464 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
50466 collapse : function(skipAnim){
50467 if(this.collapsed) return;
50468 this.collapsed = true;
50470 this.split.el.hide();
50472 if(this.config.animate && skipAnim !== true){
50473 this.fireEvent("invalidated", this);
50474 this.animateCollapse();
50476 this.el.setLocation(-20000,-20000);
50478 this.collapsedEl.show();
50479 this.fireEvent("collapsed", this);
50480 this.fireEvent("invalidated", this);
50484 animateCollapse : function(){
50489 * Expands this region if it was previously collapsed.
50490 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
50491 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
50493 expand : function(e, skipAnim){
50494 if(e) e.stopPropagation();
50495 if(!this.collapsed || this.el.hasActiveFx()) return;
50497 this.afterSlideIn();
50500 this.collapsed = false;
50501 if(this.config.animate && skipAnim !== true){
50502 this.animateExpand();
50506 this.split.el.show();
50508 this.collapsedEl.setLocation(-2000,-2000);
50509 this.collapsedEl.hide();
50510 this.fireEvent("invalidated", this);
50511 this.fireEvent("expanded", this);
50515 animateExpand : function(){
50519 initTabs : function()
50521 this.bodyEl.setStyle("overflow", "hidden");
50522 var ts = new Roo.TabPanel(
50525 tabPosition: this.bottomTabs ? 'bottom' : 'top',
50526 disableTooltips: this.config.disableTabTips,
50527 toolbar : this.config.toolbar
50530 if(this.config.hideTabs){
50531 ts.stripWrap.setDisplayed(false);
50534 ts.resizeTabs = this.config.resizeTabs === true;
50535 ts.minTabWidth = this.config.minTabWidth || 40;
50536 ts.maxTabWidth = this.config.maxTabWidth || 250;
50537 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
50538 ts.monitorResize = false;
50539 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
50540 ts.bodyEl.addClass('x-layout-tabs-body');
50541 this.panels.each(this.initPanelAsTab, this);
50544 initPanelAsTab : function(panel){
50545 var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
50546 this.config.closeOnTab && panel.isClosable());
50547 if(panel.tabTip !== undefined){
50548 ti.setTooltip(panel.tabTip);
50550 ti.on("activate", function(){
50551 this.setActivePanel(panel);
50553 if(this.config.closeOnTab){
50554 ti.on("beforeclose", function(t, e){
50556 this.remove(panel);
50562 updatePanelTitle : function(panel, title){
50563 if(this.activePanel == panel){
50564 this.updateTitle(title);
50567 var ti = this.tabs.getTab(panel.getEl().id);
50569 if(panel.tabTip !== undefined){
50570 ti.setTooltip(panel.tabTip);
50575 updateTitle : function(title){
50576 if(this.titleTextEl && !this.config.title){
50577 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
50581 setActivePanel : function(panel){
50582 panel = this.getPanel(panel);
50583 if(this.activePanel && this.activePanel != panel){
50584 this.activePanel.setActiveState(false);
50586 this.activePanel = panel;
50587 panel.setActiveState(true);
50588 if(this.panelSize){
50589 panel.setSize(this.panelSize.width, this.panelSize.height);
50592 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
50594 this.updateTitle(panel.getTitle());
50596 this.fireEvent("invalidated", this);
50598 this.fireEvent("panelactivated", this, panel);
50602 * Shows the specified panel.
50603 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
50604 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
50606 showPanel : function(panel)
50608 panel = this.getPanel(panel);
50611 var tab = this.tabs.getTab(panel.getEl().id);
50612 if(tab.isHidden()){
50613 this.tabs.unhideTab(tab.id);
50617 this.setActivePanel(panel);
50624 * Get the active panel for this region.
50625 * @return {Roo.ContentPanel} The active panel or null
50627 getActivePanel : function(){
50628 return this.activePanel;
50631 validateVisibility : function(){
50632 if(this.panels.getCount() < 1){
50633 this.updateTitle(" ");
50634 this.closeBtn.hide();
50637 if(!this.isVisible()){
50644 * Adds the passed ContentPanel(s) to this region.
50645 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
50646 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
50648 add : function(panel){
50649 if(arguments.length > 1){
50650 for(var i = 0, len = arguments.length; i < len; i++) {
50651 this.add(arguments[i]);
50655 if(this.hasPanel(panel)){
50656 this.showPanel(panel);
50659 panel.setRegion(this);
50660 this.panels.add(panel);
50661 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
50662 this.bodyEl.dom.appendChild(panel.getEl().dom);
50663 if(panel.background !== true){
50664 this.setActivePanel(panel);
50666 this.fireEvent("paneladded", this, panel);
50672 this.initPanelAsTab(panel);
50674 if(panel.background !== true){
50675 this.tabs.activate(panel.getEl().id);
50677 this.fireEvent("paneladded", this, panel);
50682 * Hides the tab for the specified panel.
50683 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
50685 hidePanel : function(panel){
50686 if(this.tabs && (panel = this.getPanel(panel))){
50687 this.tabs.hideTab(panel.getEl().id);
50692 * Unhides the tab for a previously hidden panel.
50693 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
50695 unhidePanel : function(panel){
50696 if(this.tabs && (panel = this.getPanel(panel))){
50697 this.tabs.unhideTab(panel.getEl().id);
50701 clearPanels : function(){
50702 while(this.panels.getCount() > 0){
50703 this.remove(this.panels.first());
50708 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
50709 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
50710 * @param {Boolean} preservePanel Overrides the config preservePanel option
50711 * @return {Roo.ContentPanel} The panel that was removed
50713 remove : function(panel, preservePanel){
50714 panel = this.getPanel(panel);
50719 this.fireEvent("beforeremove", this, panel, e);
50720 if(e.cancel === true){
50723 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
50724 var panelId = panel.getId();
50725 this.panels.removeKey(panelId);
50727 document.body.appendChild(panel.getEl().dom);
50730 this.tabs.removeTab(panel.getEl().id);
50731 }else if (!preservePanel){
50732 this.bodyEl.dom.removeChild(panel.getEl().dom);
50734 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
50735 var p = this.panels.first();
50736 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
50737 tempEl.appendChild(p.getEl().dom);
50738 this.bodyEl.update("");
50739 this.bodyEl.dom.appendChild(p.getEl().dom);
50741 this.updateTitle(p.getTitle());
50743 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
50744 this.setActivePanel(p);
50746 panel.setRegion(null);
50747 if(this.activePanel == panel){
50748 this.activePanel = null;
50750 if(this.config.autoDestroy !== false && preservePanel !== true){
50751 try{panel.destroy();}catch(e){}
50753 this.fireEvent("panelremoved", this, panel);
50758 * Returns the TabPanel component used by this region
50759 * @return {Roo.TabPanel}
50761 getTabs : function(){
50765 createTool : function(parentEl, className){
50766 var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
50767 children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
50768 btn.addClassOnOver("x-layout-tools-button-over");
50773 * Ext JS Library 1.1.1
50774 * Copyright(c) 2006-2007, Ext JS, LLC.
50776 * Originally Released Under LGPL - original licence link has changed is not relivant.
50779 * <script type="text/javascript">
50785 * @class Roo.SplitLayoutRegion
50786 * @extends Roo.LayoutRegion
50787 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
50789 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
50790 this.cursor = cursor;
50791 Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
50794 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
50795 splitTip : "Drag to resize.",
50796 collapsibleSplitTip : "Drag to resize. Double click to hide.",
50797 useSplitTips : false,
50799 applyConfig : function(config){
50800 Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
50803 var splitEl = Roo.DomHelper.append(this.mgr.el.dom,
50804 {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: " "});
50805 /** The SplitBar for this region
50806 * @type Roo.SplitBar */
50807 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
50808 this.split.on("moved", this.onSplitMove, this);
50809 this.split.useShim = config.useShim === true;
50810 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
50811 if(this.useSplitTips){
50812 this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
50814 if(config.collapsible){
50815 this.split.el.on("dblclick", this.collapse, this);
50818 if(typeof config.minSize != "undefined"){
50819 this.split.minSize = config.minSize;
50821 if(typeof config.maxSize != "undefined"){
50822 this.split.maxSize = config.maxSize;
50824 if(config.hideWhenEmpty || config.hidden || config.collapsed){
50825 this.hideSplitter();
50830 getHMaxSize : function(){
50831 var cmax = this.config.maxSize || 10000;
50832 var center = this.mgr.getRegion("center");
50833 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
50836 getVMaxSize : function(){
50837 var cmax = this.config.maxSize || 10000;
50838 var center = this.mgr.getRegion("center");
50839 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
50842 onSplitMove : function(split, newSize){
50843 this.fireEvent("resized", this, newSize);
50847 * Returns the {@link Roo.SplitBar} for this region.
50848 * @return {Roo.SplitBar}
50850 getSplitBar : function(){
50855 this.hideSplitter();
50856 Roo.SplitLayoutRegion.superclass.hide.call(this);
50859 hideSplitter : function(){
50861 this.split.el.setLocation(-2000,-2000);
50862 this.split.el.hide();
50868 this.split.el.show();
50870 Roo.SplitLayoutRegion.superclass.show.call(this);
50873 beforeSlide: function(){
50874 if(Roo.isGecko){// firefox overflow auto bug workaround
50875 this.bodyEl.clip();
50876 if(this.tabs) this.tabs.bodyEl.clip();
50877 if(this.activePanel){
50878 this.activePanel.getEl().clip();
50880 if(this.activePanel.beforeSlide){
50881 this.activePanel.beforeSlide();
50887 afterSlide : function(){
50888 if(Roo.isGecko){// firefox overflow auto bug workaround
50889 this.bodyEl.unclip();
50890 if(this.tabs) this.tabs.bodyEl.unclip();
50891 if(this.activePanel){
50892 this.activePanel.getEl().unclip();
50893 if(this.activePanel.afterSlide){
50894 this.activePanel.afterSlide();
50900 initAutoHide : function(){
50901 if(this.autoHide !== false){
50902 if(!this.autoHideHd){
50903 var st = new Roo.util.DelayedTask(this.slideIn, this);
50904 this.autoHideHd = {
50905 "mouseout": function(e){
50906 if(!e.within(this.el, true)){
50910 "mouseover" : function(e){
50916 this.el.on(this.autoHideHd);
50920 clearAutoHide : function(){
50921 if(this.autoHide !== false){
50922 this.el.un("mouseout", this.autoHideHd.mouseout);
50923 this.el.un("mouseover", this.autoHideHd.mouseover);
50927 clearMonitor : function(){
50928 Roo.get(document).un("click", this.slideInIf, this);
50931 // these names are backwards but not changed for compat
50932 slideOut : function(){
50933 if(this.isSlid || this.el.hasActiveFx()){
50936 this.isSlid = true;
50937 if(this.collapseBtn){
50938 this.collapseBtn.hide();
50940 this.closeBtnState = this.closeBtn.getStyle('display');
50941 this.closeBtn.hide();
50943 this.stickBtn.show();
50946 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
50947 this.beforeSlide();
50948 this.el.setStyle("z-index", 10001);
50949 this.el.slideIn(this.getSlideAnchor(), {
50950 callback: function(){
50952 this.initAutoHide();
50953 Roo.get(document).on("click", this.slideInIf, this);
50954 this.fireEvent("slideshow", this);
50961 afterSlideIn : function(){
50962 this.clearAutoHide();
50963 this.isSlid = false;
50964 this.clearMonitor();
50965 this.el.setStyle("z-index", "");
50966 if(this.collapseBtn){
50967 this.collapseBtn.show();
50969 this.closeBtn.setStyle('display', this.closeBtnState);
50971 this.stickBtn.hide();
50973 this.fireEvent("slidehide", this);
50976 slideIn : function(cb){
50977 if(!this.isSlid || this.el.hasActiveFx()){
50981 this.isSlid = false;
50982 this.beforeSlide();
50983 this.el.slideOut(this.getSlideAnchor(), {
50984 callback: function(){
50985 this.el.setLeftTop(-10000, -10000);
50987 this.afterSlideIn();
50995 slideInIf : function(e){
50996 if(!e.within(this.el)){
51001 animateCollapse : function(){
51002 this.beforeSlide();
51003 this.el.setStyle("z-index", 20000);
51004 var anchor = this.getSlideAnchor();
51005 this.el.slideOut(anchor, {
51006 callback : function(){
51007 this.el.setStyle("z-index", "");
51008 this.collapsedEl.slideIn(anchor, {duration:.3});
51010 this.el.setLocation(-10000,-10000);
51012 this.fireEvent("collapsed", this);
51019 animateExpand : function(){
51020 this.beforeSlide();
51021 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
51022 this.el.setStyle("z-index", 20000);
51023 this.collapsedEl.hide({
51026 this.el.slideIn(this.getSlideAnchor(), {
51027 callback : function(){
51028 this.el.setStyle("z-index", "");
51031 this.split.el.show();
51033 this.fireEvent("invalidated", this);
51034 this.fireEvent("expanded", this);
51062 getAnchor : function(){
51063 return this.anchors[this.position];
51066 getCollapseAnchor : function(){
51067 return this.canchors[this.position];
51070 getSlideAnchor : function(){
51071 return this.sanchors[this.position];
51074 getAlignAdj : function(){
51075 var cm = this.cmargins;
51076 switch(this.position){
51092 getExpandAdj : function(){
51093 var c = this.collapsedEl, cm = this.cmargins;
51094 switch(this.position){
51096 return [-(cm.right+c.getWidth()+cm.left), 0];
51099 return [cm.right+c.getWidth()+cm.left, 0];
51102 return [0, -(cm.top+cm.bottom+c.getHeight())];
51105 return [0, cm.top+cm.bottom+c.getHeight()];
51111 * Ext JS Library 1.1.1
51112 * Copyright(c) 2006-2007, Ext JS, LLC.
51114 * Originally Released Under LGPL - original licence link has changed is not relivant.
51117 * <script type="text/javascript">
51120 * These classes are private internal classes
51122 Roo.CenterLayoutRegion = function(mgr, config){
51123 Roo.LayoutRegion.call(this, mgr, config, "center");
51124 this.visible = true;
51125 this.minWidth = config.minWidth || 20;
51126 this.minHeight = config.minHeight || 20;
51129 Roo.extend(Roo.CenterLayoutRegion, Roo.LayoutRegion, {
51131 // center panel can't be hidden
51135 // center panel can't be hidden
51138 getMinWidth: function(){
51139 return this.minWidth;
51142 getMinHeight: function(){
51143 return this.minHeight;
51148 Roo.NorthLayoutRegion = function(mgr, config){
51149 Roo.LayoutRegion.call(this, mgr, config, "north", "n-resize");
51151 this.split.placement = Roo.SplitBar.TOP;
51152 this.split.orientation = Roo.SplitBar.VERTICAL;
51153 this.split.el.addClass("x-layout-split-v");
51155 var size = config.initialSize || config.height;
51156 if(typeof size != "undefined"){
51157 this.el.setHeight(size);
51160 Roo.extend(Roo.NorthLayoutRegion, Roo.SplitLayoutRegion, {
51161 orientation: Roo.SplitBar.VERTICAL,
51162 getBox : function(){
51163 if(this.collapsed){
51164 return this.collapsedEl.getBox();
51166 var box = this.el.getBox();
51168 box.height += this.split.el.getHeight();
51173 updateBox : function(box){
51174 if(this.split && !this.collapsed){
51175 box.height -= this.split.el.getHeight();
51176 this.split.el.setLeft(box.x);
51177 this.split.el.setTop(box.y+box.height);
51178 this.split.el.setWidth(box.width);
51180 if(this.collapsed){
51181 this.updateBody(box.width, null);
51183 Roo.LayoutRegion.prototype.updateBox.call(this, box);
51187 Roo.SouthLayoutRegion = function(mgr, config){
51188 Roo.SplitLayoutRegion.call(this, mgr, config, "south", "s-resize");
51190 this.split.placement = Roo.SplitBar.BOTTOM;
51191 this.split.orientation = Roo.SplitBar.VERTICAL;
51192 this.split.el.addClass("x-layout-split-v");
51194 var size = config.initialSize || config.height;
51195 if(typeof size != "undefined"){
51196 this.el.setHeight(size);
51199 Roo.extend(Roo.SouthLayoutRegion, Roo.SplitLayoutRegion, {
51200 orientation: Roo.SplitBar.VERTICAL,
51201 getBox : function(){
51202 if(this.collapsed){
51203 return this.collapsedEl.getBox();
51205 var box = this.el.getBox();
51207 var sh = this.split.el.getHeight();
51214 updateBox : function(box){
51215 if(this.split && !this.collapsed){
51216 var sh = this.split.el.getHeight();
51219 this.split.el.setLeft(box.x);
51220 this.split.el.setTop(box.y-sh);
51221 this.split.el.setWidth(box.width);
51223 if(this.collapsed){
51224 this.updateBody(box.width, null);
51226 Roo.LayoutRegion.prototype.updateBox.call(this, box);
51230 Roo.EastLayoutRegion = function(mgr, config){
51231 Roo.SplitLayoutRegion.call(this, mgr, config, "east", "e-resize");
51233 this.split.placement = Roo.SplitBar.RIGHT;
51234 this.split.orientation = Roo.SplitBar.HORIZONTAL;
51235 this.split.el.addClass("x-layout-split-h");
51237 var size = config.initialSize || config.width;
51238 if(typeof size != "undefined"){
51239 this.el.setWidth(size);
51242 Roo.extend(Roo.EastLayoutRegion, Roo.SplitLayoutRegion, {
51243 orientation: Roo.SplitBar.HORIZONTAL,
51244 getBox : function(){
51245 if(this.collapsed){
51246 return this.collapsedEl.getBox();
51248 var box = this.el.getBox();
51250 var sw = this.split.el.getWidth();
51257 updateBox : function(box){
51258 if(this.split && !this.collapsed){
51259 var sw = this.split.el.getWidth();
51261 this.split.el.setLeft(box.x);
51262 this.split.el.setTop(box.y);
51263 this.split.el.setHeight(box.height);
51266 if(this.collapsed){
51267 this.updateBody(null, box.height);
51269 Roo.LayoutRegion.prototype.updateBox.call(this, box);
51273 Roo.WestLayoutRegion = function(mgr, config){
51274 Roo.SplitLayoutRegion.call(this, mgr, config, "west", "w-resize");
51276 this.split.placement = Roo.SplitBar.LEFT;
51277 this.split.orientation = Roo.SplitBar.HORIZONTAL;
51278 this.split.el.addClass("x-layout-split-h");
51280 var size = config.initialSize || config.width;
51281 if(typeof size != "undefined"){
51282 this.el.setWidth(size);
51285 Roo.extend(Roo.WestLayoutRegion, Roo.SplitLayoutRegion, {
51286 orientation: Roo.SplitBar.HORIZONTAL,
51287 getBox : function(){
51288 if(this.collapsed){
51289 return this.collapsedEl.getBox();
51291 var box = this.el.getBox();
51293 box.width += this.split.el.getWidth();
51298 updateBox : function(box){
51299 if(this.split && !this.collapsed){
51300 var sw = this.split.el.getWidth();
51302 this.split.el.setLeft(box.x+box.width);
51303 this.split.el.setTop(box.y);
51304 this.split.el.setHeight(box.height);
51306 if(this.collapsed){
51307 this.updateBody(null, box.height);
51309 Roo.LayoutRegion.prototype.updateBox.call(this, box);
51314 * Ext JS Library 1.1.1
51315 * Copyright(c) 2006-2007, Ext JS, LLC.
51317 * Originally Released Under LGPL - original licence link has changed is not relivant.
51320 * <script type="text/javascript">
51325 * Private internal class for reading and applying state
51327 Roo.LayoutStateManager = function(layout){
51328 // default empty state
51337 Roo.LayoutStateManager.prototype = {
51338 init : function(layout, provider){
51339 this.provider = provider;
51340 var state = provider.get(layout.id+"-layout-state");
51342 var wasUpdating = layout.isUpdating();
51344 layout.beginUpdate();
51346 for(var key in state){
51347 if(typeof state[key] != "function"){
51348 var rstate = state[key];
51349 var r = layout.getRegion(key);
51352 r.resizeTo(rstate.size);
51354 if(rstate.collapsed == true){
51357 r.expand(null, true);
51363 layout.endUpdate();
51365 this.state = state;
51367 this.layout = layout;
51368 layout.on("regionresized", this.onRegionResized, this);
51369 layout.on("regioncollapsed", this.onRegionCollapsed, this);
51370 layout.on("regionexpanded", this.onRegionExpanded, this);
51373 storeState : function(){
51374 this.provider.set(this.layout.id+"-layout-state", this.state);
51377 onRegionResized : function(region, newSize){
51378 this.state[region.getPosition()].size = newSize;
51382 onRegionCollapsed : function(region){
51383 this.state[region.getPosition()].collapsed = true;
51387 onRegionExpanded : function(region){
51388 this.state[region.getPosition()].collapsed = false;
51393 * Ext JS Library 1.1.1
51394 * Copyright(c) 2006-2007, Ext JS, LLC.
51396 * Originally Released Under LGPL - original licence link has changed is not relivant.
51399 * <script type="text/javascript">
51402 * @class Roo.ContentPanel
51403 * @extends Roo.util.Observable
51404 * A basic ContentPanel element.
51405 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
51406 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
51407 * @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
51408 * @cfg {Boolean} closable True if the panel can be closed/removed
51409 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
51410 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
51411 * @cfg {Toolbar} toolbar A toolbar for this panel
51412 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
51413 * @cfg {String} title The title for this panel
51414 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
51415 * @cfg {String} url Calls {@link #setUrl} with this value
51416 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
51417 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
51418 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
51419 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
51422 * Create a new ContentPanel.
51423 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
51424 * @param {String/Object} config A string to set only the title or a config object
51425 * @param {String} content (optional) Set the HTML content for this panel
51426 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
51428 Roo.ContentPanel = function(el, config, content){
51432 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
51436 if (config && config.parentLayout) {
51437 el = config.parentLayout.el.createChild();
51440 if(el.autoCreate){ // xtype is available if this is called from factory
51444 this.el = Roo.get(el);
51445 if(!this.el && config && config.autoCreate){
51446 if(typeof config.autoCreate == "object"){
51447 if(!config.autoCreate.id){
51448 config.autoCreate.id = config.id||el;
51450 this.el = Roo.DomHelper.append(document.body,
51451 config.autoCreate, true);
51453 this.el = Roo.DomHelper.append(document.body,
51454 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
51457 this.closable = false;
51458 this.loaded = false;
51459 this.active = false;
51460 if(typeof config == "string"){
51461 this.title = config;
51463 Roo.apply(this, config);
51466 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
51467 this.wrapEl = this.el.wrap();
51468 this.toolbar.container = this.el.insertSibling(false, 'before');
51469 this.toolbar = new Roo.Toolbar(this.toolbar);
51472 // xtype created footer. - not sure if will work as we normally have to render first..
51473 if (this.footer && !this.footer.el && this.footer.xtype) {
51474 if (!this.wrapEl) {
51475 this.wrapEl = this.el.wrap();
51478 this.footer.container = this.wrapEl.createChild();
51480 this.footer = Roo.factory(this.footer, Roo);
51485 this.resizeEl = Roo.get(this.resizeEl, true);
51487 this.resizeEl = this.el;
51489 // handle view.xtype
51497 * Fires when this panel is activated.
51498 * @param {Roo.ContentPanel} this
51502 * @event deactivate
51503 * Fires when this panel is activated.
51504 * @param {Roo.ContentPanel} this
51506 "deactivate" : true,
51510 * Fires when this panel is resized if fitToFrame is true.
51511 * @param {Roo.ContentPanel} this
51512 * @param {Number} width The width after any component adjustments
51513 * @param {Number} height The height after any component adjustments
51519 * Fires when this tab is created
51520 * @param {Roo.ContentPanel} this
51531 if(this.autoScroll){
51532 this.resizeEl.setStyle("overflow", "auto");
51534 // fix randome scrolling
51535 this.el.on('scroll', function() {
51536 Roo.log('fix random scolling');
51537 this.scrollTo('top',0);
51540 content = content || this.content;
51542 this.setContent(content);
51544 if(config && config.url){
51545 this.setUrl(this.url, this.params, this.loadOnce);
51550 Roo.ContentPanel.superclass.constructor.call(this);
51552 if (this.view && typeof(this.view.xtype) != 'undefined') {
51553 this.view.el = this.el.appendChild(document.createElement("div"));
51554 this.view = Roo.factory(this.view);
51555 this.view.render && this.view.render(false, '');
51559 this.fireEvent('render', this);
51562 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
51564 setRegion : function(region){
51565 this.region = region;
51567 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
51569 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
51574 * Returns the toolbar for this Panel if one was configured.
51575 * @return {Roo.Toolbar}
51577 getToolbar : function(){
51578 return this.toolbar;
51581 setActiveState : function(active){
51582 this.active = active;
51584 this.fireEvent("deactivate", this);
51586 this.fireEvent("activate", this);
51590 * Updates this panel's element
51591 * @param {String} content The new content
51592 * @param {Boolean} loadScripts (optional) true to look for and process scripts
51594 setContent : function(content, loadScripts){
51595 this.el.update(content, loadScripts);
51598 ignoreResize : function(w, h){
51599 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
51602 this.lastSize = {width: w, height: h};
51607 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
51608 * @return {Roo.UpdateManager} The UpdateManager
51610 getUpdateManager : function(){
51611 return this.el.getUpdateManager();
51614 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
51615 * @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:
51618 url: "your-url.php",
51619 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
51620 callback: yourFunction,
51621 scope: yourObject, //(optional scope)
51624 text: "Loading...",
51629 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
51630 * 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.
51631 * @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}
51632 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
51633 * @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.
51634 * @return {Roo.ContentPanel} this
51637 var um = this.el.getUpdateManager();
51638 um.update.apply(um, arguments);
51644 * 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.
51645 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
51646 * @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)
51647 * @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)
51648 * @return {Roo.UpdateManager} The UpdateManager
51650 setUrl : function(url, params, loadOnce){
51651 if(this.refreshDelegate){
51652 this.removeListener("activate", this.refreshDelegate);
51654 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
51655 this.on("activate", this.refreshDelegate);
51656 return this.el.getUpdateManager();
51659 _handleRefresh : function(url, params, loadOnce){
51660 if(!loadOnce || !this.loaded){
51661 var updater = this.el.getUpdateManager();
51662 updater.update(url, params, this._setLoaded.createDelegate(this));
51666 _setLoaded : function(){
51667 this.loaded = true;
51671 * Returns this panel's id
51674 getId : function(){
51679 * Returns this panel's element - used by regiosn to add.
51680 * @return {Roo.Element}
51682 getEl : function(){
51683 return this.wrapEl || this.el;
51686 adjustForComponents : function(width, height)
51688 //Roo.log('adjustForComponents ');
51689 if(this.resizeEl != this.el){
51690 width -= this.el.getFrameWidth('lr');
51691 height -= this.el.getFrameWidth('tb');
51694 var te = this.toolbar.getEl();
51695 height -= te.getHeight();
51696 te.setWidth(width);
51699 var te = this.footer.getEl();
51700 Roo.log("footer:" + te.getHeight());
51702 height -= te.getHeight();
51703 te.setWidth(width);
51707 if(this.adjustments){
51708 width += this.adjustments[0];
51709 height += this.adjustments[1];
51711 return {"width": width, "height": height};
51714 setSize : function(width, height){
51715 if(this.fitToFrame && !this.ignoreResize(width, height)){
51716 if(this.fitContainer && this.resizeEl != this.el){
51717 this.el.setSize(width, height);
51719 var size = this.adjustForComponents(width, height);
51720 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
51721 this.fireEvent('resize', this, size.width, size.height);
51726 * Returns this panel's title
51729 getTitle : function(){
51734 * Set this panel's title
51735 * @param {String} title
51737 setTitle : function(title){
51738 this.title = title;
51740 this.region.updatePanelTitle(this, title);
51745 * Returns true is this panel was configured to be closable
51746 * @return {Boolean}
51748 isClosable : function(){
51749 return this.closable;
51752 beforeSlide : function(){
51754 this.resizeEl.clip();
51757 afterSlide : function(){
51759 this.resizeEl.unclip();
51763 * Force a content refresh from the URL specified in the {@link #setUrl} method.
51764 * Will fail silently if the {@link #setUrl} method has not been called.
51765 * This does not activate the panel, just updates its content.
51767 refresh : function(){
51768 if(this.refreshDelegate){
51769 this.loaded = false;
51770 this.refreshDelegate();
51775 * Destroys this panel
51777 destroy : function(){
51778 this.el.removeAllListeners();
51779 var tempEl = document.createElement("span");
51780 tempEl.appendChild(this.el.dom);
51781 tempEl.innerHTML = "";
51787 * form - if the content panel contains a form - this is a reference to it.
51788 * @type {Roo.form.Form}
51792 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
51793 * This contains a reference to it.
51799 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
51809 * @param {Object} cfg Xtype definition of item to add.
51812 addxtype : function(cfg) {
51814 if (cfg.xtype.match(/^Form$/)) {
51817 //if (this.footer) {
51818 // el = this.footer.container.insertSibling(false, 'before');
51820 el = this.el.createChild();
51823 this.form = new Roo.form.Form(cfg);
51826 if ( this.form.allItems.length) this.form.render(el.dom);
51829 // should only have one of theses..
51830 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
51831 // views.. should not be just added - used named prop 'view''
51833 cfg.el = this.el.appendChild(document.createElement("div"));
51836 var ret = new Roo.factory(cfg);
51838 ret.render && ret.render(false, ''); // render blank..
51847 * @class Roo.GridPanel
51848 * @extends Roo.ContentPanel
51850 * Create a new GridPanel.
51851 * @param {Roo.grid.Grid} grid The grid for this panel
51852 * @param {String/Object} config A string to set only the panel's title, or a config object
51854 Roo.GridPanel = function(grid, config){
51857 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
51858 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
51860 this.wrapper.dom.appendChild(grid.getGridEl().dom);
51862 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
51865 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
51867 // xtype created footer. - not sure if will work as we normally have to render first..
51868 if (this.footer && !this.footer.el && this.footer.xtype) {
51870 this.footer.container = this.grid.getView().getFooterPanel(true);
51871 this.footer.dataSource = this.grid.dataSource;
51872 this.footer = Roo.factory(this.footer, Roo);
51876 grid.monitorWindowResize = false; // turn off autosizing
51877 grid.autoHeight = false;
51878 grid.autoWidth = false;
51880 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
51883 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
51884 getId : function(){
51885 return this.grid.id;
51889 * Returns the grid for this panel
51890 * @return {Roo.grid.Grid}
51892 getGrid : function(){
51896 setSize : function(width, height){
51897 if(!this.ignoreResize(width, height)){
51898 var grid = this.grid;
51899 var size = this.adjustForComponents(width, height);
51900 grid.getGridEl().setSize(size.width, size.height);
51905 beforeSlide : function(){
51906 this.grid.getView().scroller.clip();
51909 afterSlide : function(){
51910 this.grid.getView().scroller.unclip();
51913 destroy : function(){
51914 this.grid.destroy();
51916 Roo.GridPanel.superclass.destroy.call(this);
51922 * @class Roo.NestedLayoutPanel
51923 * @extends Roo.ContentPanel
51925 * Create a new NestedLayoutPanel.
51928 * @param {Roo.BorderLayout} layout The layout for this panel
51929 * @param {String/Object} config A string to set only the title or a config object
51931 Roo.NestedLayoutPanel = function(layout, config)
51933 // construct with only one argument..
51934 /* FIXME - implement nicer consturctors
51935 if (layout.layout) {
51937 layout = config.layout;
51938 delete config.layout;
51940 if (layout.xtype && !layout.getEl) {
51941 // then layout needs constructing..
51942 layout = Roo.factory(layout, Roo);
51947 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
51949 layout.monitorWindowResize = false; // turn off autosizing
51950 this.layout = layout;
51951 this.layout.getEl().addClass("x-layout-nested-layout");
51958 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
51960 setSize : function(width, height){
51961 if(!this.ignoreResize(width, height)){
51962 var size = this.adjustForComponents(width, height);
51963 var el = this.layout.getEl();
51964 el.setSize(size.width, size.height);
51965 var touch = el.dom.offsetWidth;
51966 this.layout.layout();
51967 // ie requires a double layout on the first pass
51968 if(Roo.isIE && !this.initialized){
51969 this.initialized = true;
51970 this.layout.layout();
51975 // activate all subpanels if not currently active..
51977 setActiveState : function(active){
51978 this.active = active;
51980 this.fireEvent("deactivate", this);
51984 this.fireEvent("activate", this);
51985 // not sure if this should happen before or after..
51986 if (!this.layout) {
51987 return; // should not happen..
51990 for (var r in this.layout.regions) {
51991 reg = this.layout.getRegion(r);
51992 if (reg.getActivePanel()) {
51993 //reg.showPanel(reg.getActivePanel()); // force it to activate..
51994 reg.setActivePanel(reg.getActivePanel());
51997 if (!reg.panels.length) {
52000 reg.showPanel(reg.getPanel(0));
52009 * Returns the nested BorderLayout for this panel
52010 * @return {Roo.BorderLayout}
52012 getLayout : function(){
52013 return this.layout;
52017 * Adds a xtype elements to the layout of the nested panel
52021 xtype : 'ContentPanel',
52028 xtype : 'NestedLayoutPanel',
52034 items : [ ... list of content panels or nested layout panels.. ]
52038 * @param {Object} cfg Xtype definition of item to add.
52040 addxtype : function(cfg) {
52041 return this.layout.addxtype(cfg);
52046 Roo.ScrollPanel = function(el, config, content){
52047 config = config || {};
52048 config.fitToFrame = true;
52049 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
52051 this.el.dom.style.overflow = "hidden";
52052 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
52053 this.el.removeClass("x-layout-inactive-content");
52054 this.el.on("mousewheel", this.onWheel, this);
52056 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
52057 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
52058 up.unselectable(); down.unselectable();
52059 up.on("click", this.scrollUp, this);
52060 down.on("click", this.scrollDown, this);
52061 up.addClassOnOver("x-scroller-btn-over");
52062 down.addClassOnOver("x-scroller-btn-over");
52063 up.addClassOnClick("x-scroller-btn-click");
52064 down.addClassOnClick("x-scroller-btn-click");
52065 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
52067 this.resizeEl = this.el;
52068 this.el = wrap; this.up = up; this.down = down;
52071 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
52073 wheelIncrement : 5,
52074 scrollUp : function(){
52075 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
52078 scrollDown : function(){
52079 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
52082 afterScroll : function(){
52083 var el = this.resizeEl;
52084 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
52085 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
52086 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
52089 setSize : function(){
52090 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
52091 this.afterScroll();
52094 onWheel : function(e){
52095 var d = e.getWheelDelta();
52096 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
52097 this.afterScroll();
52101 setContent : function(content, loadScripts){
52102 this.resizeEl.update(content, loadScripts);
52116 * @class Roo.TreePanel
52117 * @extends Roo.ContentPanel
52119 * Create a new TreePanel. - defaults to fit/scoll contents.
52120 * @param {String/Object} config A string to set only the panel's title, or a config object
52121 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
52123 Roo.TreePanel = function(config){
52124 var el = config.el;
52125 var tree = config.tree;
52126 delete config.tree;
52127 delete config.el; // hopefull!
52129 // wrapper for IE7 strict & safari scroll issue
52131 var treeEl = el.createChild();
52132 config.resizeEl = treeEl;
52136 Roo.TreePanel.superclass.constructor.call(this, el, config);
52139 this.tree = new Roo.tree.TreePanel(treeEl , tree);
52140 //console.log(tree);
52141 this.on('activate', function()
52143 if (this.tree.rendered) {
52146 //console.log('render tree');
52147 this.tree.render();
52149 // this should not be needed.. - it's actually the 'el' that resizes?
52150 // actuall it breaks the containerScroll - dragging nodes auto scroll at top
52152 //this.on('resize', function (cp, w, h) {
52153 // this.tree.innerCt.setWidth(w);
52154 // this.tree.innerCt.setHeight(h);
52155 // //this.tree.innerCt.setStyle('overflow-y', 'auto');
52162 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {
52179 * Ext JS Library 1.1.1
52180 * Copyright(c) 2006-2007, Ext JS, LLC.
52182 * Originally Released Under LGPL - original licence link has changed is not relivant.
52185 * <script type="text/javascript">
52190 * @class Roo.ReaderLayout
52191 * @extends Roo.BorderLayout
52192 * This is a pre-built layout that represents a classic, 5-pane application. It consists of a header, a primary
52193 * center region containing two nested regions (a top one for a list view and one for item preview below),
52194 * and regions on either side that can be used for navigation, application commands, informational displays, etc.
52195 * The setup and configuration work exactly the same as it does for a {@link Roo.BorderLayout} - this class simply
52196 * expedites the setup of the overall layout and regions for this common application style.
52199 var reader = new Roo.ReaderLayout();
52200 var CP = Roo.ContentPanel; // shortcut for adding
52202 reader.beginUpdate();
52203 reader.add("north", new CP("north", "North"));
52204 reader.add("west", new CP("west", {title: "West"}));
52205 reader.add("east", new CP("east", {title: "East"}));
52207 reader.regions.listView.add(new CP("listView", "List"));
52208 reader.regions.preview.add(new CP("preview", "Preview"));
52209 reader.endUpdate();
52212 * Create a new ReaderLayout
52213 * @param {Object} config Configuration options
52214 * @param {String/HTMLElement/Element} container (optional) The container this layout is bound to (defaults to
52215 * document.body if omitted)
52217 Roo.ReaderLayout = function(config, renderTo){
52218 var c = config || {size:{}};
52219 Roo.ReaderLayout.superclass.constructor.call(this, renderTo || document.body, {
52220 north: c.north !== false ? Roo.apply({
52224 }, c.north) : false,
52225 west: c.west !== false ? Roo.apply({
52233 margins:{left:5,right:0,bottom:5,top:5},
52234 cmargins:{left:5,right:5,bottom:5,top:5}
52235 }, c.west) : false,
52236 east: c.east !== false ? Roo.apply({
52244 margins:{left:0,right:5,bottom:5,top:5},
52245 cmargins:{left:5,right:5,bottom:5,top:5}
52246 }, c.east) : false,
52247 center: Roo.apply({
52248 tabPosition: 'top',
52252 margins:{left:c.west!==false ? 0 : 5,right:c.east!==false ? 0 : 5,bottom:5,top:2}
52256 this.el.addClass('x-reader');
52258 this.beginUpdate();
52260 var inner = new Roo.BorderLayout(Roo.get(document.body).createChild(), {
52261 south: c.preview !== false ? Roo.apply({
52268 cmargins:{top:5,left:0, right:0, bottom:0}
52269 }, c.preview) : false,
52270 center: Roo.apply({
52276 this.add('center', new Roo.NestedLayoutPanel(inner,
52277 Roo.apply({title: c.mainTitle || '',tabTip:''},c.innerPanelCfg)));
52281 this.regions.preview = inner.getRegion('south');
52282 this.regions.listView = inner.getRegion('center');
52285 Roo.extend(Roo.ReaderLayout, Roo.BorderLayout);/*
52287 * Ext JS Library 1.1.1
52288 * Copyright(c) 2006-2007, Ext JS, LLC.
52290 * Originally Released Under LGPL - original licence link has changed is not relivant.
52293 * <script type="text/javascript">
52297 * @class Roo.grid.Grid
52298 * @extends Roo.util.Observable
52299 * This class represents the primary interface of a component based grid control.
52300 * <br><br>Usage:<pre><code>
52301 var grid = new Roo.grid.Grid("my-container-id", {
52304 selModel: mySelectionModel,
52305 autoSizeColumns: true,
52306 monitorWindowResize: false,
52307 trackMouseOver: true
52312 * <b>Common Problems:</b><br/>
52313 * - Grid does not resize properly when going smaller: Setting overflow hidden on the container
52314 * element will correct this<br/>
52315 * - If you get el.style[camel]= NaNpx or -2px or something related, be certain you have given your container element
52316 * dimensions. The grid adapts to your container's size, if your container has no size defined then the results
52317 * are unpredictable.<br/>
52318 * - Do not render the grid into an element with display:none. Try using visibility:hidden. Otherwise there is no way for the
52319 * grid to calculate dimensions/offsets.<br/>
52321 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
52322 * The container MUST have some type of size defined for the grid to fill. The container will be
52323 * automatically set to position relative if it isn't already.
52324 * @param {Object} config A config object that sets properties on this grid.
52326 Roo.grid.Grid = function(container, config){
52327 // initialize the container
52328 this.container = Roo.get(container);
52329 this.container.update("");
52330 this.container.setStyle("overflow", "hidden");
52331 this.container.addClass('x-grid-container');
52333 this.id = this.container.id;
52335 Roo.apply(this, config);
52336 // check and correct shorthanded configs
52338 this.dataSource = this.ds;
52342 this.colModel = this.cm;
52346 this.selModel = this.sm;
52350 if (this.selModel) {
52351 this.selModel = Roo.factory(this.selModel, Roo.grid);
52352 this.sm = this.selModel;
52353 this.sm.xmodule = this.xmodule || false;
52355 if (typeof(this.colModel.config) == 'undefined') {
52356 this.colModel = new Roo.grid.ColumnModel(this.colModel);
52357 this.cm = this.colModel;
52358 this.cm.xmodule = this.xmodule || false;
52360 if (this.dataSource) {
52361 this.dataSource= Roo.factory(this.dataSource, Roo.data);
52362 this.ds = this.dataSource;
52363 this.ds.xmodule = this.xmodule || false;
52370 this.container.setWidth(this.width);
52374 this.container.setHeight(this.height);
52381 * The raw click event for the entire grid.
52382 * @param {Roo.EventObject} e
52387 * The raw dblclick event for the entire grid.
52388 * @param {Roo.EventObject} e
52392 * @event contextmenu
52393 * The raw contextmenu event for the entire grid.
52394 * @param {Roo.EventObject} e
52396 "contextmenu" : true,
52399 * The raw mousedown event for the entire grid.
52400 * @param {Roo.EventObject} e
52402 "mousedown" : true,
52405 * The raw mouseup event for the entire grid.
52406 * @param {Roo.EventObject} e
52411 * The raw mouseover event for the entire grid.
52412 * @param {Roo.EventObject} e
52414 "mouseover" : true,
52417 * The raw mouseout event for the entire grid.
52418 * @param {Roo.EventObject} e
52423 * The raw keypress event for the entire grid.
52424 * @param {Roo.EventObject} e
52429 * The raw keydown event for the entire grid.
52430 * @param {Roo.EventObject} e
52438 * Fires when a cell is clicked
52439 * @param {Grid} this
52440 * @param {Number} rowIndex
52441 * @param {Number} columnIndex
52442 * @param {Roo.EventObject} e
52444 "cellclick" : true,
52446 * @event celldblclick
52447 * Fires when a cell is double clicked
52448 * @param {Grid} this
52449 * @param {Number} rowIndex
52450 * @param {Number} columnIndex
52451 * @param {Roo.EventObject} e
52453 "celldblclick" : true,
52456 * Fires when a row is clicked
52457 * @param {Grid} this
52458 * @param {Number} rowIndex
52459 * @param {Roo.EventObject} e
52463 * @event rowdblclick
52464 * Fires when a row is double clicked
52465 * @param {Grid} this
52466 * @param {Number} rowIndex
52467 * @param {Roo.EventObject} e
52469 "rowdblclick" : true,
52471 * @event headerclick
52472 * Fires when a header is clicked
52473 * @param {Grid} this
52474 * @param {Number} columnIndex
52475 * @param {Roo.EventObject} e
52477 "headerclick" : true,
52479 * @event headerdblclick
52480 * Fires when a header cell is double clicked
52481 * @param {Grid} this
52482 * @param {Number} columnIndex
52483 * @param {Roo.EventObject} e
52485 "headerdblclick" : true,
52487 * @event rowcontextmenu
52488 * Fires when a row is right clicked
52489 * @param {Grid} this
52490 * @param {Number} rowIndex
52491 * @param {Roo.EventObject} e
52493 "rowcontextmenu" : true,
52495 * @event cellcontextmenu
52496 * Fires when a cell is right clicked
52497 * @param {Grid} this
52498 * @param {Number} rowIndex
52499 * @param {Number} cellIndex
52500 * @param {Roo.EventObject} e
52502 "cellcontextmenu" : true,
52504 * @event headercontextmenu
52505 * Fires when a header is right clicked
52506 * @param {Grid} this
52507 * @param {Number} columnIndex
52508 * @param {Roo.EventObject} e
52510 "headercontextmenu" : true,
52512 * @event bodyscroll
52513 * Fires when the body element is scrolled
52514 * @param {Number} scrollLeft
52515 * @param {Number} scrollTop
52517 "bodyscroll" : true,
52519 * @event columnresize
52520 * Fires when the user resizes a column
52521 * @param {Number} columnIndex
52522 * @param {Number} newSize
52524 "columnresize" : true,
52526 * @event columnmove
52527 * Fires when the user moves a column
52528 * @param {Number} oldIndex
52529 * @param {Number} newIndex
52531 "columnmove" : true,
52534 * Fires when row(s) start being dragged
52535 * @param {Grid} this
52536 * @param {Roo.GridDD} dd The drag drop object
52537 * @param {event} e The raw browser event
52539 "startdrag" : true,
52542 * Fires when a drag operation is complete
52543 * @param {Grid} this
52544 * @param {Roo.GridDD} dd The drag drop object
52545 * @param {event} e The raw browser event
52550 * Fires when dragged row(s) are dropped on a valid DD target
52551 * @param {Grid} this
52552 * @param {Roo.GridDD} dd The drag drop object
52553 * @param {String} targetId The target drag drop object
52554 * @param {event} e The raw browser event
52559 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
52560 * @param {Grid} this
52561 * @param {Roo.GridDD} dd The drag drop object
52562 * @param {String} targetId The target drag drop object
52563 * @param {event} e The raw browser event
52568 * Fires when the dragged row(s) first cross another DD target while being dragged
52569 * @param {Grid} this
52570 * @param {Roo.GridDD} dd The drag drop object
52571 * @param {String} targetId The target drag drop object
52572 * @param {event} e The raw browser event
52574 "dragenter" : true,
52577 * Fires when the dragged row(s) leave another DD target while being dragged
52578 * @param {Grid} this
52579 * @param {Roo.GridDD} dd The drag drop object
52580 * @param {String} targetId The target drag drop object
52581 * @param {event} e The raw browser event
52586 * Fires when a row is rendered, so you can change add a style to it.
52587 * @param {GridView} gridview The grid view
52588 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
52594 * Fires when the grid is rendered
52595 * @param {Grid} grid
52600 Roo.grid.Grid.superclass.constructor.call(this);
52602 Roo.extend(Roo.grid.Grid, Roo.util.Observable, {
52605 * @cfg {String} ddGroup - drag drop group.
52609 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Default is 25.
52611 minColumnWidth : 25,
52614 * @cfg {Boolean} autoSizeColumns True to automatically resize the columns to fit their content
52615 * <b>on initial render.</b> It is more efficient to explicitly size the columns
52616 * through the ColumnModel's {@link Roo.grid.ColumnModel#width} config option. Default is false.
52618 autoSizeColumns : false,
52621 * @cfg {Boolean} autoSizeHeaders True to measure headers with column data when auto sizing columns. Default is true.
52623 autoSizeHeaders : true,
52626 * @cfg {Boolean} monitorWindowResize True to autoSize the grid when the window resizes. Default is true.
52628 monitorWindowResize : true,
52631 * @cfg {Boolean} maxRowsToMeasure If autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of
52632 * rows measured to get a columns size. Default is 0 (all rows).
52634 maxRowsToMeasure : 0,
52637 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is true.
52639 trackMouseOver : true,
52642 * @cfg {Boolean} enableDrag True to enable drag of rows. Default is false. (double check if this is needed?)
52646 * @cfg {Boolean} enableDragDrop True to enable drag and drop of rows. Default is false.
52648 enableDragDrop : false,
52651 * @cfg {Boolean} enableColumnMove True to enable drag and drop reorder of columns. Default is true.
52653 enableColumnMove : true,
52656 * @cfg {Boolean} enableColumnHide True to enable hiding of columns with the header context menu. Default is true.
52658 enableColumnHide : true,
52661 * @cfg {Boolean} enableRowHeightSync True to manually sync row heights across locked and not locked rows. Default is false.
52663 enableRowHeightSync : false,
52666 * @cfg {Boolean} stripeRows True to stripe the rows. Default is true.
52671 * @cfg {Boolean} autoHeight True to fit the height of the grid container to the height of the data. Default is false.
52673 autoHeight : false,
52676 * @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.
52678 autoExpandColumn : false,
52681 * @cfg {Number} autoExpandMin The minimum width the autoExpandColumn can have (if enabled).
52684 autoExpandMin : 50,
52687 * @cfg {Number} autoExpandMax The maximum width the autoExpandColumn can have (if enabled). Default is 1000.
52689 autoExpandMax : 1000,
52692 * @cfg {Object} view The {@link Roo.grid.GridView} used by the grid. This can be set before a call to render().
52697 * @cfg {Object} loadMask An {@link Roo.LoadMask} config or true to mask the grid while loading. Default is false.
52701 * @cfg {Roo.dd.DropTarget} dropTarget An {@link Roo.dd.DropTarget} config
52711 * @cfg {Boolean} autoWidth True to set the grid's width to the default total width of the grid's columns instead
52712 * of a fixed width. Default is false.
52715 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if autoHeight is not on.
52718 * Called once after all setup has been completed and the grid is ready to be rendered.
52719 * @return {Roo.grid.Grid} this
52721 render : function()
52723 var c = this.container;
52724 // try to detect autoHeight/width mode
52725 if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
52726 this.autoHeight = true;
52728 var view = this.getView();
52731 c.on("click", this.onClick, this);
52732 c.on("dblclick", this.onDblClick, this);
52733 c.on("contextmenu", this.onContextMenu, this);
52734 c.on("keydown", this.onKeyDown, this);
52736 c.on("touchstart", this.onTouchStart, this);
52739 this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
52741 this.getSelectionModel().init(this);
52746 this.loadMask = new Roo.LoadMask(this.container,
52747 Roo.apply({store:this.dataSource}, this.loadMask));
52751 if (this.toolbar && this.toolbar.xtype) {
52752 this.toolbar.container = this.getView().getHeaderPanel(true);
52753 this.toolbar = new Roo.Toolbar(this.toolbar);
52755 if (this.footer && this.footer.xtype) {
52756 this.footer.dataSource = this.getDataSource();
52757 this.footer.container = this.getView().getFooterPanel(true);
52758 this.footer = Roo.factory(this.footer, Roo);
52760 if (this.dropTarget && this.dropTarget.xtype) {
52761 delete this.dropTarget.xtype;
52762 this.dropTarget = new Roo.dd.DropTarget(this.getView().mainBody, this.dropTarget);
52766 this.rendered = true;
52767 this.fireEvent('render', this);
52772 * Reconfigures the grid to use a different Store and Column Model.
52773 * The View will be bound to the new objects and refreshed.
52774 * @param {Roo.data.Store} dataSource The new {@link Roo.data.Store} object
52775 * @param {Roo.grid.ColumnModel} The new {@link Roo.grid.ColumnModel} object
52777 reconfigure : function(dataSource, colModel){
52779 this.loadMask.destroy();
52780 this.loadMask = new Roo.LoadMask(this.container,
52781 Roo.apply({store:dataSource}, this.loadMask));
52783 this.view.bind(dataSource, colModel);
52784 this.dataSource = dataSource;
52785 this.colModel = colModel;
52786 this.view.refresh(true);
52790 onKeyDown : function(e){
52791 this.fireEvent("keydown", e);
52795 * Destroy this grid.
52796 * @param {Boolean} removeEl True to remove the element
52798 destroy : function(removeEl, keepListeners){
52800 this.loadMask.destroy();
52802 var c = this.container;
52803 c.removeAllListeners();
52804 this.view.destroy();
52805 this.colModel.purgeListeners();
52806 if(!keepListeners){
52807 this.purgeListeners();
52810 if(removeEl === true){
52816 processEvent : function(name, e){
52817 // does this fire select???
52818 //Roo.log('grid:processEvent ' + name);
52820 if (name != 'touchstart' ) {
52821 this.fireEvent(name, e);
52824 var t = e.getTarget();
52826 var header = v.findHeaderIndex(t);
52827 if(header !== false){
52828 var ename = name == 'touchstart' ? 'click' : name;
52830 this.fireEvent("header" + ename, this, header, e);
52832 var row = v.findRowIndex(t);
52833 var cell = v.findCellIndex(t);
52834 if (name == 'touchstart') {
52835 // first touch is always a click.
52836 // hopefull this happens after selection is updated.?
52839 if (typeof(this.selModel.getSelectedCell) != 'undefined') {
52840 var cs = this.selModel.getSelectedCell();
52841 if (row == cs[0] && cell == cs[1]){
52845 if (typeof(this.selModel.getSelections) != 'undefined') {
52846 var cs = this.selModel.getSelections();
52847 var ds = this.dataSource;
52848 if (cs.length == 1 && ds.getAt(row) == cs[0]){
52859 this.fireEvent("row" + name, this, row, e);
52860 if(cell !== false){
52861 this.fireEvent("cell" + name, this, row, cell, e);
52868 onClick : function(e){
52869 this.processEvent("click", e);
52872 onTouchStart : function(e){
52873 this.processEvent("touchstart", e);
52877 onContextMenu : function(e, t){
52878 this.processEvent("contextmenu", e);
52882 onDblClick : function(e){
52883 this.processEvent("dblclick", e);
52887 walkCells : function(row, col, step, fn, scope){
52888 var cm = this.colModel, clen = cm.getColumnCount();
52889 var ds = this.dataSource, rlen = ds.getCount(), first = true;
52901 if(fn.call(scope || this, row, col, cm) === true){
52919 if(fn.call(scope || this, row, col, cm) === true){
52931 getSelections : function(){
52932 return this.selModel.getSelections();
52936 * Causes the grid to manually recalculate its dimensions. Generally this is done automatically,
52937 * but if manual update is required this method will initiate it.
52939 autoSize : function(){
52941 this.view.layout();
52942 if(this.view.adjustForScroll){
52943 this.view.adjustForScroll();
52949 * Returns the grid's underlying element.
52950 * @return {Element} The element
52952 getGridEl : function(){
52953 return this.container;
52956 // private for compatibility, overridden by editor grid
52957 stopEditing : function(){},
52960 * Returns the grid's SelectionModel.
52961 * @return {SelectionModel}
52963 getSelectionModel : function(){
52964 if(!this.selModel){
52965 this.selModel = new Roo.grid.RowSelectionModel();
52967 return this.selModel;
52971 * Returns the grid's DataSource.
52972 * @return {DataSource}
52974 getDataSource : function(){
52975 return this.dataSource;
52979 * Returns the grid's ColumnModel.
52980 * @return {ColumnModel}
52982 getColumnModel : function(){
52983 return this.colModel;
52987 * Returns the grid's GridView object.
52988 * @return {GridView}
52990 getView : function(){
52992 this.view = new Roo.grid.GridView(this.viewConfig);
52997 * Called to get grid's drag proxy text, by default returns this.ddText.
53000 getDragDropText : function(){
53001 var count = this.selModel.getCount();
53002 return String.format(this.ddText, count, count == 1 ? '' : 's');
53006 * Configures the text is the drag proxy (defaults to "%0 selected row(s)").
53007 * %0 is replaced with the number of selected rows.
53010 Roo.grid.Grid.prototype.ddText = "{0} selected row{1}";/*
53012 * Ext JS Library 1.1.1
53013 * Copyright(c) 2006-2007, Ext JS, LLC.
53015 * Originally Released Under LGPL - original licence link has changed is not relivant.
53018 * <script type="text/javascript">
53021 Roo.grid.AbstractGridView = function(){
53025 "beforerowremoved" : true,
53026 "beforerowsinserted" : true,
53027 "beforerefresh" : true,
53028 "rowremoved" : true,
53029 "rowsinserted" : true,
53030 "rowupdated" : true,
53033 Roo.grid.AbstractGridView.superclass.constructor.call(this);
53036 Roo.extend(Roo.grid.AbstractGridView, Roo.util.Observable, {
53037 rowClass : "x-grid-row",
53038 cellClass : "x-grid-cell",
53039 tdClass : "x-grid-td",
53040 hdClass : "x-grid-hd",
53041 splitClass : "x-grid-hd-split",
53043 init: function(grid){
53045 var cid = this.grid.getGridEl().id;
53046 this.colSelector = "#" + cid + " ." + this.cellClass + "-";
53047 this.tdSelector = "#" + cid + " ." + this.tdClass + "-";
53048 this.hdSelector = "#" + cid + " ." + this.hdClass + "-";
53049 this.splitSelector = "#" + cid + " ." + this.splitClass + "-";
53052 getColumnRenderers : function(){
53053 var renderers = [];
53054 var cm = this.grid.colModel;
53055 var colCount = cm.getColumnCount();
53056 for(var i = 0; i < colCount; i++){
53057 renderers[i] = cm.getRenderer(i);
53062 getColumnIds : function(){
53064 var cm = this.grid.colModel;
53065 var colCount = cm.getColumnCount();
53066 for(var i = 0; i < colCount; i++){
53067 ids[i] = cm.getColumnId(i);
53072 getDataIndexes : function(){
53073 if(!this.indexMap){
53074 this.indexMap = this.buildIndexMap();
53076 return this.indexMap.colToData;
53079 getColumnIndexByDataIndex : function(dataIndex){
53080 if(!this.indexMap){
53081 this.indexMap = this.buildIndexMap();
53083 return this.indexMap.dataToCol[dataIndex];
53087 * Set a css style for a column dynamically.
53088 * @param {Number} colIndex The index of the column
53089 * @param {String} name The css property name
53090 * @param {String} value The css value
53092 setCSSStyle : function(colIndex, name, value){
53093 var selector = "#" + this.grid.id + " .x-grid-col-" + colIndex;
53094 Roo.util.CSS.updateRule(selector, name, value);
53097 generateRules : function(cm){
53098 var ruleBuf = [], rulesId = this.grid.id + '-cssrules';
53099 Roo.util.CSS.removeStyleSheet(rulesId);
53100 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
53101 var cid = cm.getColumnId(i);
53102 ruleBuf.push(this.colSelector, cid, " {\n", cm.config[i].css, "}\n",
53103 this.tdSelector, cid, " {\n}\n",
53104 this.hdSelector, cid, " {\n}\n",
53105 this.splitSelector, cid, " {\n}\n");
53107 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
53111 * Ext JS Library 1.1.1
53112 * Copyright(c) 2006-2007, Ext JS, LLC.
53114 * Originally Released Under LGPL - original licence link has changed is not relivant.
53117 * <script type="text/javascript">
53121 // This is a support class used internally by the Grid components
53122 Roo.grid.HeaderDragZone = function(grid, hd, hd2){
53124 this.view = grid.getView();
53125 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
53126 Roo.grid.HeaderDragZone.superclass.constructor.call(this, hd);
53128 this.setHandleElId(Roo.id(hd));
53129 this.setOuterHandleElId(Roo.id(hd2));
53131 this.scroll = false;
53133 Roo.extend(Roo.grid.HeaderDragZone, Roo.dd.DragZone, {
53135 getDragData : function(e){
53136 var t = Roo.lib.Event.getTarget(e);
53137 var h = this.view.findHeaderCell(t);
53139 return {ddel: h.firstChild, header:h};
53144 onInitDrag : function(e){
53145 this.view.headersDisabled = true;
53146 var clone = this.dragData.ddel.cloneNode(true);
53147 clone.id = Roo.id();
53148 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
53149 this.proxy.update(clone);
53153 afterValidDrop : function(){
53155 setTimeout(function(){
53156 v.headersDisabled = false;
53160 afterInvalidDrop : function(){
53162 setTimeout(function(){
53163 v.headersDisabled = false;
53169 * Ext JS Library 1.1.1
53170 * Copyright(c) 2006-2007, Ext JS, LLC.
53172 * Originally Released Under LGPL - original licence link has changed is not relivant.
53175 * <script type="text/javascript">
53178 // This is a support class used internally by the Grid components
53179 Roo.grid.HeaderDropZone = function(grid, hd, hd2){
53181 this.view = grid.getView();
53182 // split the proxies so they don't interfere with mouse events
53183 this.proxyTop = Roo.DomHelper.append(document.body, {
53184 cls:"col-move-top", html:" "
53186 this.proxyBottom = Roo.DomHelper.append(document.body, {
53187 cls:"col-move-bottom", html:" "
53189 this.proxyTop.hide = this.proxyBottom.hide = function(){
53190 this.setLeftTop(-100,-100);
53191 this.setStyle("visibility", "hidden");
53193 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
53194 // temporarily disabled
53195 //Roo.dd.ScrollManager.register(this.view.scroller.dom);
53196 Roo.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
53198 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
53199 proxyOffsets : [-4, -9],
53200 fly: Roo.Element.fly,
53202 getTargetFromEvent : function(e){
53203 var t = Roo.lib.Event.getTarget(e);
53204 var cindex = this.view.findCellIndex(t);
53205 if(cindex !== false){
53206 return this.view.getHeaderCell(cindex);
53211 nextVisible : function(h){
53212 var v = this.view, cm = this.grid.colModel;
53215 if(!cm.isHidden(v.getCellIndex(h))){
53223 prevVisible : function(h){
53224 var v = this.view, cm = this.grid.colModel;
53227 if(!cm.isHidden(v.getCellIndex(h))){
53235 positionIndicator : function(h, n, e){
53236 var x = Roo.lib.Event.getPageX(e);
53237 var r = Roo.lib.Dom.getRegion(n.firstChild);
53238 var px, pt, py = r.top + this.proxyOffsets[1];
53239 if((r.right - x) <= (r.right-r.left)/2){
53240 px = r.right+this.view.borderWidth;
53246 var oldIndex = this.view.getCellIndex(h);
53247 var newIndex = this.view.getCellIndex(n);
53249 if(this.grid.colModel.isFixed(newIndex)){
53253 var locked = this.grid.colModel.isLocked(newIndex);
53258 if(oldIndex < newIndex){
53261 if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){
53264 px += this.proxyOffsets[0];
53265 this.proxyTop.setLeftTop(px, py);
53266 this.proxyTop.show();
53267 if(!this.bottomOffset){
53268 this.bottomOffset = this.view.mainHd.getHeight();
53270 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
53271 this.proxyBottom.show();
53275 onNodeEnter : function(n, dd, e, data){
53276 if(data.header != n){
53277 this.positionIndicator(data.header, n, e);
53281 onNodeOver : function(n, dd, e, data){
53282 var result = false;
53283 if(data.header != n){
53284 result = this.positionIndicator(data.header, n, e);
53287 this.proxyTop.hide();
53288 this.proxyBottom.hide();
53290 return result ? this.dropAllowed : this.dropNotAllowed;
53293 onNodeOut : function(n, dd, e, data){
53294 this.proxyTop.hide();
53295 this.proxyBottom.hide();
53298 onNodeDrop : function(n, dd, e, data){
53299 var h = data.header;
53301 var cm = this.grid.colModel;
53302 var x = Roo.lib.Event.getPageX(e);
53303 var r = Roo.lib.Dom.getRegion(n.firstChild);
53304 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
53305 var oldIndex = this.view.getCellIndex(h);
53306 var newIndex = this.view.getCellIndex(n);
53307 var locked = cm.isLocked(newIndex);
53311 if(oldIndex < newIndex){
53314 if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){
53317 cm.setLocked(oldIndex, locked, true);
53318 cm.moveColumn(oldIndex, newIndex);
53319 this.grid.fireEvent("columnmove", oldIndex, newIndex);
53327 * Ext JS Library 1.1.1
53328 * Copyright(c) 2006-2007, Ext JS, LLC.
53330 * Originally Released Under LGPL - original licence link has changed is not relivant.
53333 * <script type="text/javascript">
53337 * @class Roo.grid.GridView
53338 * @extends Roo.util.Observable
53341 * @param {Object} config
53343 Roo.grid.GridView = function(config){
53344 Roo.grid.GridView.superclass.constructor.call(this);
53347 Roo.apply(this, config);
53350 Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
53352 unselectable : 'unselectable="on"',
53353 unselectableCls : 'x-unselectable',
53356 rowClass : "x-grid-row",
53358 cellClass : "x-grid-col",
53360 tdClass : "x-grid-td",
53362 hdClass : "x-grid-hd",
53364 splitClass : "x-grid-split",
53366 sortClasses : ["sort-asc", "sort-desc"],
53368 enableMoveAnim : false,
53372 dh : Roo.DomHelper,
53374 fly : Roo.Element.fly,
53376 css : Roo.util.CSS,
53382 scrollIncrement : 22,
53384 cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
53386 findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
53388 bind : function(ds, cm){
53390 this.ds.un("load", this.onLoad, this);
53391 this.ds.un("datachanged", this.onDataChange, this);
53392 this.ds.un("add", this.onAdd, this);
53393 this.ds.un("remove", this.onRemove, this);
53394 this.ds.un("update", this.onUpdate, this);
53395 this.ds.un("clear", this.onClear, this);
53398 ds.on("load", this.onLoad, this);
53399 ds.on("datachanged", this.onDataChange, this);
53400 ds.on("add", this.onAdd, this);
53401 ds.on("remove", this.onRemove, this);
53402 ds.on("update", this.onUpdate, this);
53403 ds.on("clear", this.onClear, this);
53408 this.cm.un("widthchange", this.onColWidthChange, this);
53409 this.cm.un("headerchange", this.onHeaderChange, this);
53410 this.cm.un("hiddenchange", this.onHiddenChange, this);
53411 this.cm.un("columnmoved", this.onColumnMove, this);
53412 this.cm.un("columnlockchange", this.onColumnLock, this);
53415 this.generateRules(cm);
53416 cm.on("widthchange", this.onColWidthChange, this);
53417 cm.on("headerchange", this.onHeaderChange, this);
53418 cm.on("hiddenchange", this.onHiddenChange, this);
53419 cm.on("columnmoved", this.onColumnMove, this);
53420 cm.on("columnlockchange", this.onColumnLock, this);
53425 init: function(grid){
53426 Roo.grid.GridView.superclass.init.call(this, grid);
53428 this.bind(grid.dataSource, grid.colModel);
53430 grid.on("headerclick", this.handleHeaderClick, this);
53432 if(grid.trackMouseOver){
53433 grid.on("mouseover", this.onRowOver, this);
53434 grid.on("mouseout", this.onRowOut, this);
53436 grid.cancelTextSelection = function(){};
53437 this.gridId = grid.id;
53439 var tpls = this.templates || {};
53442 tpls.master = new Roo.Template(
53443 '<div class="x-grid" hidefocus="true">',
53444 '<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
53445 '<div class="x-grid-topbar"></div>',
53446 '<div class="x-grid-scroller"><div></div></div>',
53447 '<div class="x-grid-locked">',
53448 '<div class="x-grid-header">{lockedHeader}</div>',
53449 '<div class="x-grid-body">{lockedBody}</div>',
53451 '<div class="x-grid-viewport">',
53452 '<div class="x-grid-header">{header}</div>',
53453 '<div class="x-grid-body">{body}</div>',
53455 '<div class="x-grid-bottombar"></div>',
53457 '<div class="x-grid-resize-proxy"> </div>',
53460 tpls.master.disableformats = true;
53464 tpls.header = new Roo.Template(
53465 '<table border="0" cellspacing="0" cellpadding="0">',
53466 '<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
53469 tpls.header.disableformats = true;
53471 tpls.header.compile();
53474 tpls.hcell = new Roo.Template(
53475 '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
53476 '<div class="x-grid-hd-text ' + this.unselectableCls + '" ' + this.unselectable +'>{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
53479 tpls.hcell.disableFormats = true;
53481 tpls.hcell.compile();
53484 tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style} ' +
53485 this.unselectableCls + '" ' + this.unselectable +'> </div>');
53486 tpls.hsplit.disableFormats = true;
53488 tpls.hsplit.compile();
53491 tpls.body = new Roo.Template(
53492 '<table border="0" cellspacing="0" cellpadding="0">',
53493 "<tbody>{rows}</tbody>",
53496 tpls.body.disableFormats = true;
53498 tpls.body.compile();
53501 tpls.row = new Roo.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
53502 tpls.row.disableFormats = true;
53504 tpls.row.compile();
53507 tpls.cell = new Roo.Template(
53508 '<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
53509 '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text ' +
53510 this.unselectableCls + '" ' + this.unselectable +'" {attr}>{value}</div></div>',
53513 tpls.cell.disableFormats = true;
53515 tpls.cell.compile();
53517 this.templates = tpls;
53520 // remap these for backwards compat
53521 onColWidthChange : function(){
53522 this.updateColumns.apply(this, arguments);
53524 onHeaderChange : function(){
53525 this.updateHeaders.apply(this, arguments);
53527 onHiddenChange : function(){
53528 this.handleHiddenChange.apply(this, arguments);
53530 onColumnMove : function(){
53531 this.handleColumnMove.apply(this, arguments);
53533 onColumnLock : function(){
53534 this.handleLockChange.apply(this, arguments);
53537 onDataChange : function(){
53539 this.updateHeaderSortState();
53542 onClear : function(){
53546 onUpdate : function(ds, record){
53547 this.refreshRow(record);
53550 refreshRow : function(record){
53551 var ds = this.ds, index;
53552 if(typeof record == 'number'){
53554 record = ds.getAt(index);
53556 index = ds.indexOf(record);
53558 this.insertRows(ds, index, index, true);
53559 this.onRemove(ds, record, index+1, true);
53560 this.syncRowHeights(index, index);
53562 this.fireEvent("rowupdated", this, index, record);
53565 onAdd : function(ds, records, index){
53566 this.insertRows(ds, index, index + (records.length-1));
53569 onRemove : function(ds, record, index, isUpdate){
53570 if(isUpdate !== true){
53571 this.fireEvent("beforerowremoved", this, index, record);
53573 var bt = this.getBodyTable(), lt = this.getLockedTable();
53574 if(bt.rows[index]){
53575 bt.firstChild.removeChild(bt.rows[index]);
53577 if(lt.rows[index]){
53578 lt.firstChild.removeChild(lt.rows[index]);
53580 if(isUpdate !== true){
53581 this.stripeRows(index);
53582 this.syncRowHeights(index, index);
53584 this.fireEvent("rowremoved", this, index, record);
53588 onLoad : function(){
53589 this.scrollToTop();
53593 * Scrolls the grid to the top
53595 scrollToTop : function(){
53597 this.scroller.dom.scrollTop = 0;
53603 * Gets a panel in the header of the grid that can be used for toolbars etc.
53604 * After modifying the contents of this panel a call to grid.autoSize() may be
53605 * required to register any changes in size.
53606 * @param {Boolean} doShow By default the header is hidden. Pass true to show the panel
53607 * @return Roo.Element
53609 getHeaderPanel : function(doShow){
53611 this.headerPanel.show();
53613 return this.headerPanel;
53617 * Gets a panel in the footer of the grid that can be used for toolbars etc.
53618 * After modifying the contents of this panel a call to grid.autoSize() may be
53619 * required to register any changes in size.
53620 * @param {Boolean} doShow By default the footer is hidden. Pass true to show the panel
53621 * @return Roo.Element
53623 getFooterPanel : function(doShow){
53625 this.footerPanel.show();
53627 return this.footerPanel;
53630 initElements : function(){
53631 var E = Roo.Element;
53632 var el = this.grid.getGridEl().dom.firstChild;
53633 var cs = el.childNodes;
53635 this.el = new E(el);
53637 this.focusEl = new E(el.firstChild);
53638 this.focusEl.swallowEvent("click", true);
53640 this.headerPanel = new E(cs[1]);
53641 this.headerPanel.enableDisplayMode("block");
53643 this.scroller = new E(cs[2]);
53644 this.scrollSizer = new E(this.scroller.dom.firstChild);
53646 this.lockedWrap = new E(cs[3]);
53647 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
53648 this.lockedBody = new E(this.lockedWrap.dom.childNodes[1]);
53650 this.mainWrap = new E(cs[4]);
53651 this.mainHd = new E(this.mainWrap.dom.firstChild);
53652 this.mainBody = new E(this.mainWrap.dom.childNodes[1]);
53654 this.footerPanel = new E(cs[5]);
53655 this.footerPanel.enableDisplayMode("block");
53657 this.resizeProxy = new E(cs[6]);
53659 this.headerSelector = String.format(
53660 '#{0} td.x-grid-hd, #{1} td.x-grid-hd',
53661 this.lockedHd.id, this.mainHd.id
53664 this.splitterSelector = String.format(
53665 '#{0} div.x-grid-split, #{1} div.x-grid-split',
53666 this.idToCssName(this.lockedHd.id), this.idToCssName(this.mainHd.id)
53669 idToCssName : function(s)
53671 return s.replace(/[^a-z0-9]+/ig, '-');
53674 getHeaderCell : function(index){
53675 return Roo.DomQuery.select(this.headerSelector)[index];
53678 getHeaderCellMeasure : function(index){
53679 return this.getHeaderCell(index).firstChild;
53682 getHeaderCellText : function(index){
53683 return this.getHeaderCell(index).firstChild.firstChild;
53686 getLockedTable : function(){
53687 return this.lockedBody.dom.firstChild;
53690 getBodyTable : function(){
53691 return this.mainBody.dom.firstChild;
53694 getLockedRow : function(index){
53695 return this.getLockedTable().rows[index];
53698 getRow : function(index){
53699 return this.getBodyTable().rows[index];
53702 getRowComposite : function(index){
53704 this.rowEl = new Roo.CompositeElementLite();
53706 var els = [], lrow, mrow;
53707 if(lrow = this.getLockedRow(index)){
53710 if(mrow = this.getRow(index)){
53713 this.rowEl.elements = els;
53717 * Gets the 'td' of the cell
53719 * @param {Integer} rowIndex row to select
53720 * @param {Integer} colIndex column to select
53724 getCell : function(rowIndex, colIndex){
53725 var locked = this.cm.getLockedCount();
53727 if(colIndex < locked){
53728 source = this.lockedBody.dom.firstChild;
53730 source = this.mainBody.dom.firstChild;
53731 colIndex -= locked;
53733 return source.rows[rowIndex].childNodes[colIndex];
53736 getCellText : function(rowIndex, colIndex){
53737 return this.getCell(rowIndex, colIndex).firstChild.firstChild;
53740 getCellBox : function(cell){
53741 var b = this.fly(cell).getBox();
53742 if(Roo.isOpera){ // opera fails to report the Y
53743 b.y = cell.offsetTop + this.mainBody.getY();
53748 getCellIndex : function(cell){
53749 var id = String(cell.className).match(this.cellRE);
53751 return parseInt(id[1], 10);
53756 findHeaderIndex : function(n){
53757 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
53758 return r ? this.getCellIndex(r) : false;
53761 findHeaderCell : function(n){
53762 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
53763 return r ? r : false;
53766 findRowIndex : function(n){
53770 var r = Roo.fly(n).findParent("tr." + this.rowClass, 6);
53771 return r ? r.rowIndex : false;
53774 findCellIndex : function(node){
53775 var stop = this.el.dom;
53776 while(node && node != stop){
53777 if(this.findRE.test(node.className)){
53778 return this.getCellIndex(node);
53780 node = node.parentNode;
53785 getColumnId : function(index){
53786 return this.cm.getColumnId(index);
53789 getSplitters : function()
53791 if(this.splitterSelector){
53792 return Roo.DomQuery.select(this.splitterSelector);
53798 getSplitter : function(index){
53799 return this.getSplitters()[index];
53802 onRowOver : function(e, t){
53804 if((row = this.findRowIndex(t)) !== false){
53805 this.getRowComposite(row).addClass("x-grid-row-over");
53809 onRowOut : function(e, t){
53811 if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){
53812 this.getRowComposite(row).removeClass("x-grid-row-over");
53816 renderHeaders : function(){
53818 var ct = this.templates.hcell, ht = this.templates.header, st = this.templates.hsplit;
53819 var cb = [], lb = [], sb = [], lsb = [], p = {};
53820 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
53821 p.cellId = "x-grid-hd-0-" + i;
53822 p.splitId = "x-grid-csplit-0-" + i;
53823 p.id = cm.getColumnId(i);
53824 p.title = cm.getColumnTooltip(i) || "";
53825 p.value = cm.getColumnHeader(i) || "";
53826 p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
53827 if(!cm.isLocked(i)){
53828 cb[cb.length] = ct.apply(p);
53829 sb[sb.length] = st.apply(p);
53831 lb[lb.length] = ct.apply(p);
53832 lsb[lsb.length] = st.apply(p);
53835 return [ht.apply({cells: lb.join(""), splits:lsb.join("")}),
53836 ht.apply({cells: cb.join(""), splits:sb.join("")})];
53839 updateHeaders : function(){
53840 var html = this.renderHeaders();
53841 this.lockedHd.update(html[0]);
53842 this.mainHd.update(html[1]);
53846 * Focuses the specified row.
53847 * @param {Number} row The row index
53849 focusRow : function(row)
53851 //Roo.log('GridView.focusRow');
53852 var x = this.scroller.dom.scrollLeft;
53853 this.focusCell(row, 0, false);
53854 this.scroller.dom.scrollLeft = x;
53858 * Focuses the specified cell.
53859 * @param {Number} row The row index
53860 * @param {Number} col The column index
53861 * @param {Boolean} hscroll false to disable horizontal scrolling
53863 focusCell : function(row, col, hscroll)
53865 //Roo.log('GridView.focusCell');
53866 var el = this.ensureVisible(row, col, hscroll);
53867 this.focusEl.alignTo(el, "tl-tl");
53869 this.focusEl.focus();
53871 this.focusEl.focus.defer(1, this.focusEl);
53876 * Scrolls the specified cell into view
53877 * @param {Number} row The row index
53878 * @param {Number} col The column index
53879 * @param {Boolean} hscroll false to disable horizontal scrolling
53881 ensureVisible : function(row, col, hscroll)
53883 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
53884 //return null; //disable for testing.
53885 if(typeof row != "number"){
53886 row = row.rowIndex;
53888 if(row < 0 && row >= this.ds.getCount()){
53891 col = (col !== undefined ? col : 0);
53892 var cm = this.grid.colModel;
53893 while(cm.isHidden(col)){
53897 var el = this.getCell(row, col);
53901 var c = this.scroller.dom;
53903 var ctop = parseInt(el.offsetTop, 10);
53904 var cleft = parseInt(el.offsetLeft, 10);
53905 var cbot = ctop + el.offsetHeight;
53906 var cright = cleft + el.offsetWidth;
53908 var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
53909 var stop = parseInt(c.scrollTop, 10);
53910 var sleft = parseInt(c.scrollLeft, 10);
53911 var sbot = stop + ch;
53912 var sright = sleft + c.clientWidth;
53914 Roo.log('GridView.ensureVisible:' +
53916 ' c.clientHeight:' + c.clientHeight +
53917 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
53925 c.scrollTop = ctop;
53926 //Roo.log("set scrolltop to ctop DISABLE?");
53927 }else if(cbot > sbot){
53928 //Roo.log("set scrolltop to cbot-ch");
53929 c.scrollTop = cbot-ch;
53932 if(hscroll !== false){
53934 c.scrollLeft = cleft;
53935 }else if(cright > sright){
53936 c.scrollLeft = cright-c.clientWidth;
53943 updateColumns : function(){
53944 this.grid.stopEditing();
53945 var cm = this.grid.colModel, colIds = this.getColumnIds();
53946 //var totalWidth = cm.getTotalWidth();
53948 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
53949 //if(cm.isHidden(i)) continue;
53950 var w = cm.getColumnWidth(i);
53951 this.css.updateRule(this.colSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
53952 this.css.updateRule(this.hdSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
53954 this.updateSplitters();
53957 generateRules : function(cm){
53958 var ruleBuf = [], rulesId = this.idToCssName(this.grid.id)+ '-cssrules';
53959 Roo.util.CSS.removeStyleSheet(rulesId);
53960 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
53961 var cid = cm.getColumnId(i);
53963 if(cm.config[i].align){
53964 align = 'text-align:'+cm.config[i].align+';';
53967 if(cm.isHidden(i)){
53968 hidden = 'display:none;';
53970 var width = "width:" + (cm.getColumnWidth(i) - this.borderWidth) + "px;";
53972 this.colSelector, cid, " {\n", cm.config[i].css, align, width, "\n}\n",
53973 this.hdSelector, cid, " {\n", align, width, "}\n",
53974 this.tdSelector, cid, " {\n",hidden,"\n}\n",
53975 this.splitSelector, cid, " {\n", hidden , "\n}\n");
53977 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
53980 updateSplitters : function(){
53981 var cm = this.cm, s = this.getSplitters();
53982 if(s){ // splitters not created yet
53983 var pos = 0, locked = true;
53984 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
53985 if(cm.isHidden(i)) continue;
53986 var w = cm.getColumnWidth(i); // make sure it's a number
53987 if(!cm.isLocked(i) && locked){
53992 s[i].style.left = (pos-this.splitOffset) + "px";
53997 handleHiddenChange : function(colModel, colIndex, hidden){
53999 this.hideColumn(colIndex);
54001 this.unhideColumn(colIndex);
54005 hideColumn : function(colIndex){
54006 var cid = this.getColumnId(colIndex);
54007 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "none");
54008 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "none");
54010 this.updateHeaders();
54012 this.updateSplitters();
54016 unhideColumn : function(colIndex){
54017 var cid = this.getColumnId(colIndex);
54018 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "");
54019 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "");
54022 this.updateHeaders();
54024 this.updateSplitters();
54028 insertRows : function(dm, firstRow, lastRow, isUpdate){
54029 if(firstRow == 0 && lastRow == dm.getCount()-1){
54033 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
54035 var s = this.getScrollState();
54036 var markup = this.renderRows(firstRow, lastRow);
54037 this.bufferRows(markup[0], this.getLockedTable(), firstRow);
54038 this.bufferRows(markup[1], this.getBodyTable(), firstRow);
54039 this.restoreScroll(s);
54041 this.fireEvent("rowsinserted", this, firstRow, lastRow);
54042 this.syncRowHeights(firstRow, lastRow);
54043 this.stripeRows(firstRow);
54049 bufferRows : function(markup, target, index){
54050 var before = null, trows = target.rows, tbody = target.tBodies[0];
54051 if(index < trows.length){
54052 before = trows[index];
54054 var b = document.createElement("div");
54055 b.innerHTML = "<table><tbody>"+markup+"</tbody></table>";
54056 var rows = b.firstChild.rows;
54057 for(var i = 0, len = rows.length; i < len; i++){
54059 tbody.insertBefore(rows[0], before);
54061 tbody.appendChild(rows[0]);
54068 deleteRows : function(dm, firstRow, lastRow){
54069 if(dm.getRowCount()<1){
54070 this.fireEvent("beforerefresh", this);
54071 this.mainBody.update("");
54072 this.lockedBody.update("");
54073 this.fireEvent("refresh", this);
54075 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
54076 var bt = this.getBodyTable();
54077 var tbody = bt.firstChild;
54078 var rows = bt.rows;
54079 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
54080 tbody.removeChild(rows[firstRow]);
54082 this.stripeRows(firstRow);
54083 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
54087 updateRows : function(dataSource, firstRow, lastRow){
54088 var s = this.getScrollState();
54090 this.restoreScroll(s);
54093 handleSort : function(dataSource, sortColumnIndex, sortDir, noRefresh){
54097 this.updateHeaderSortState();
54100 getScrollState : function(){
54102 var sb = this.scroller.dom;
54103 return {left: sb.scrollLeft, top: sb.scrollTop};
54106 stripeRows : function(startRow){
54107 if(!this.grid.stripeRows || this.ds.getCount() < 1){
54110 startRow = startRow || 0;
54111 var rows = this.getBodyTable().rows;
54112 var lrows = this.getLockedTable().rows;
54113 var cls = ' x-grid-row-alt ';
54114 for(var i = startRow, len = rows.length; i < len; i++){
54115 var row = rows[i], lrow = lrows[i];
54116 var isAlt = ((i+1) % 2 == 0);
54117 var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
54118 if(isAlt == hasAlt){
54122 row.className += " x-grid-row-alt";
54124 row.className = row.className.replace("x-grid-row-alt", "");
54127 lrow.className = row.className;
54132 restoreScroll : function(state){
54133 //Roo.log('GridView.restoreScroll');
54134 var sb = this.scroller.dom;
54135 sb.scrollLeft = state.left;
54136 sb.scrollTop = state.top;
54140 syncScroll : function(){
54141 //Roo.log('GridView.syncScroll');
54142 var sb = this.scroller.dom;
54143 var sh = this.mainHd.dom;
54144 var bs = this.mainBody.dom;
54145 var lv = this.lockedBody.dom;
54146 sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
54147 lv.scrollTop = bs.scrollTop = sb.scrollTop;
54150 handleScroll : function(e){
54152 var sb = this.scroller.dom;
54153 this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
54157 handleWheel : function(e){
54158 var d = e.getWheelDelta();
54159 this.scroller.dom.scrollTop -= d*22;
54160 // set this here to prevent jumpy scrolling on large tables
54161 this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
54165 renderRows : function(startRow, endRow){
54166 // pull in all the crap needed to render rows
54167 var g = this.grid, cm = g.colModel, ds = g.dataSource, stripe = g.stripeRows;
54168 var colCount = cm.getColumnCount();
54170 if(ds.getCount() < 1){
54174 // build a map for all the columns
54176 for(var i = 0; i < colCount; i++){
54177 var name = cm.getDataIndex(i);
54179 name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
54180 renderer : cm.getRenderer(i),
54181 id : cm.getColumnId(i),
54182 locked : cm.isLocked(i)
54186 startRow = startRow || 0;
54187 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
54189 // records to render
54190 var rs = ds.getRange(startRow, endRow);
54192 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
54195 // As much as I hate to duplicate code, this was branched because FireFox really hates
54196 // [].join("") on strings. The performance difference was substantial enough to
54197 // branch this function
54198 doRender : Roo.isGecko ?
54199 function(cs, rs, ds, startRow, colCount, stripe){
54200 var ts = this.templates, ct = ts.cell, rt = ts.row;
54202 var buf = "", lbuf = "", cb, lcb, c, p = {}, rp = {}, r, rowIndex;
54204 var hasListener = this.grid.hasListener('rowclass');
54206 for(var j = 0, len = rs.length; j < len; j++){
54207 r = rs[j]; cb = ""; lcb = ""; rowIndex = (j+startRow);
54208 for(var i = 0; i < colCount; i++){
54210 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
54212 p.css = p.attr = "";
54213 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
54214 if(p.value == undefined || p.value === "") p.value = " ";
54215 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
54216 p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
54218 var markup = ct.apply(p);
54226 if(stripe && ((rowIndex+1) % 2 == 0)){
54227 alt.push("x-grid-row-alt")
54230 alt.push( " x-grid-dirty-row");
54233 if(this.getRowClass){
54234 alt.push(this.getRowClass(r, rowIndex));
54240 rowIndex : rowIndex,
54243 this.grid.fireEvent('rowclass', this, rowcfg);
54244 alt.push(rowcfg.rowClass);
54246 rp.alt = alt.join(" ");
54247 lbuf+= rt.apply(rp);
54249 buf+= rt.apply(rp);
54251 return [lbuf, buf];
54253 function(cs, rs, ds, startRow, colCount, stripe){
54254 var ts = this.templates, ct = ts.cell, rt = ts.row;
54256 var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
54257 var hasListener = this.grid.hasListener('rowclass');
54260 for(var j = 0, len = rs.length; j < len; j++){
54261 r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
54262 for(var i = 0; i < colCount; i++){
54264 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
54266 p.css = p.attr = "";
54267 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
54268 if(p.value == undefined || p.value === "") p.value = " ";
54269 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
54270 p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
54273 var markup = ct.apply(p);
54275 cb[cb.length] = markup;
54277 lcb[lcb.length] = markup;
54281 if(stripe && ((rowIndex+1) % 2 == 0)){
54282 alt.push( "x-grid-row-alt");
54285 alt.push(" x-grid-dirty-row");
54288 if(this.getRowClass){
54289 alt.push( this.getRowClass(r, rowIndex));
54295 rowIndex : rowIndex,
54298 this.grid.fireEvent('rowclass', this, rowcfg);
54299 alt.push(rowcfg.rowClass);
54301 rp.alt = alt.join(" ");
54302 rp.cells = lcb.join("");
54303 lbuf[lbuf.length] = rt.apply(rp);
54304 rp.cells = cb.join("");
54305 buf[buf.length] = rt.apply(rp);
54307 return [lbuf.join(""), buf.join("")];
54310 renderBody : function(){
54311 var markup = this.renderRows();
54312 var bt = this.templates.body;
54313 return [bt.apply({rows: markup[0]}), bt.apply({rows: markup[1]})];
54317 * Refreshes the grid
54318 * @param {Boolean} headersToo
54320 refresh : function(headersToo){
54321 this.fireEvent("beforerefresh", this);
54322 this.grid.stopEditing();
54323 var result = this.renderBody();
54324 this.lockedBody.update(result[0]);
54325 this.mainBody.update(result[1]);
54326 if(headersToo === true){
54327 this.updateHeaders();
54328 this.updateColumns();
54329 this.updateSplitters();
54330 this.updateHeaderSortState();
54332 this.syncRowHeights();
54334 this.fireEvent("refresh", this);
54337 handleColumnMove : function(cm, oldIndex, newIndex){
54338 this.indexMap = null;
54339 var s = this.getScrollState();
54340 this.refresh(true);
54341 this.restoreScroll(s);
54342 this.afterMove(newIndex);
54345 afterMove : function(colIndex){
54346 if(this.enableMoveAnim && Roo.enableFx){
54347 this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
54349 // if multisort - fix sortOrder, and reload..
54350 if (this.grid.dataSource.multiSort) {
54351 // the we can call sort again..
54352 var dm = this.grid.dataSource;
54353 var cm = this.grid.colModel;
54355 for(var i = 0; i < cm.config.length; i++ ) {
54357 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined')) {
54358 continue; // dont' bother, it's not in sort list or being set.
54361 so.push(cm.config[i].dataIndex);
54364 dm.load(dm.lastOptions);
54371 updateCell : function(dm, rowIndex, dataIndex){
54372 var colIndex = this.getColumnIndexByDataIndex(dataIndex);
54373 if(typeof colIndex == "undefined"){ // not present in grid
54376 var cm = this.grid.colModel;
54377 var cell = this.getCell(rowIndex, colIndex);
54378 var cellText = this.getCellText(rowIndex, colIndex);
54381 cellId : "x-grid-cell-" + rowIndex + "-" + colIndex,
54382 id : cm.getColumnId(colIndex),
54383 css: colIndex == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
54385 var renderer = cm.getRenderer(colIndex);
54386 var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
54387 if(typeof val == "undefined" || val === "") val = " ";
54388 cellText.innerHTML = val;
54389 cell.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
54390 this.syncRowHeights(rowIndex, rowIndex);
54393 calcColumnWidth : function(colIndex, maxRowsToMeasure){
54395 if(this.grid.autoSizeHeaders){
54396 var h = this.getHeaderCellMeasure(colIndex);
54397 maxWidth = Math.max(maxWidth, h.scrollWidth);
54400 if(this.cm.isLocked(colIndex)){
54401 tb = this.getLockedTable();
54404 tb = this.getBodyTable();
54405 index = colIndex - this.cm.getLockedCount();
54408 var rows = tb.rows;
54409 var stopIndex = Math.min(maxRowsToMeasure || rows.length, rows.length);
54410 for(var i = 0; i < stopIndex; i++){
54411 var cell = rows[i].childNodes[index].firstChild;
54412 maxWidth = Math.max(maxWidth, cell.scrollWidth);
54415 return maxWidth + /*margin for error in IE*/ 5;
54418 * Autofit a column to its content.
54419 * @param {Number} colIndex
54420 * @param {Boolean} forceMinSize true to force the column to go smaller if possible
54422 autoSizeColumn : function(colIndex, forceMinSize, suppressEvent){
54423 if(this.cm.isHidden(colIndex)){
54424 return; // can't calc a hidden column
54427 var cid = this.cm.getColumnId(colIndex);
54428 this.css.updateRule(this.colSelector +this.idToCssName( cid), "width", this.grid.minColumnWidth + "px");
54429 if(this.grid.autoSizeHeaders){
54430 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", this.grid.minColumnWidth + "px");
54433 var newWidth = this.calcColumnWidth(colIndex);
54434 this.cm.setColumnWidth(colIndex,
54435 Math.max(this.grid.minColumnWidth, newWidth), suppressEvent);
54436 if(!suppressEvent){
54437 this.grid.fireEvent("columnresize", colIndex, newWidth);
54442 * Autofits all columns to their content and then expands to fit any extra space in the grid
54444 autoSizeColumns : function(){
54445 var cm = this.grid.colModel;
54446 var colCount = cm.getColumnCount();
54447 for(var i = 0; i < colCount; i++){
54448 this.autoSizeColumn(i, true, true);
54450 if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
54453 this.updateColumns();
54459 * Autofits all columns to the grid's width proportionate with their current size
54460 * @param {Boolean} reserveScrollSpace Reserve space for a scrollbar
54462 fitColumns : function(reserveScrollSpace){
54463 var cm = this.grid.colModel;
54464 var colCount = cm.getColumnCount();
54468 for (i = 0; i < colCount; i++){
54469 if(!cm.isHidden(i) && !cm.isFixed(i)){
54470 w = cm.getColumnWidth(i);
54476 var avail = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
54477 if(reserveScrollSpace){
54480 var frac = (avail - cm.getTotalWidth())/width;
54481 while (cols.length){
54484 cm.setColumnWidth(i, Math.floor(w + w*frac), true);
54486 this.updateColumns();
54490 onRowSelect : function(rowIndex){
54491 var row = this.getRowComposite(rowIndex);
54492 row.addClass("x-grid-row-selected");
54495 onRowDeselect : function(rowIndex){
54496 var row = this.getRowComposite(rowIndex);
54497 row.removeClass("x-grid-row-selected");
54500 onCellSelect : function(row, col){
54501 var cell = this.getCell(row, col);
54503 Roo.fly(cell).addClass("x-grid-cell-selected");
54507 onCellDeselect : function(row, col){
54508 var cell = this.getCell(row, col);
54510 Roo.fly(cell).removeClass("x-grid-cell-selected");
54514 updateHeaderSortState : function(){
54516 // sort state can be single { field: xxx, direction : yyy}
54517 // or { xxx=>ASC , yyy : DESC ..... }
54520 if (!this.ds.multiSort) {
54521 var state = this.ds.getSortState();
54525 mstate[state.field] = state.direction;
54526 // FIXME... - this is not used here.. but might be elsewhere..
54527 this.sortState = state;
54530 mstate = this.ds.sortToggle;
54532 //remove existing sort classes..
54534 var sc = this.sortClasses;
54535 var hds = this.el.select(this.headerSelector).removeClass(sc);
54537 for(var f in mstate) {
54539 var sortColumn = this.cm.findColumnIndex(f);
54541 if(sortColumn != -1){
54542 var sortDir = mstate[f];
54543 hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
54552 handleHeaderClick : function(g, index,e){
54554 Roo.log("header click");
54557 // touch events on header are handled by context
54558 this.handleHdCtx(g,index,e);
54563 if(this.headersDisabled){
54566 var dm = g.dataSource, cm = g.colModel;
54567 if(!cm.isSortable(index)){
54572 if (dm.multiSort) {
54573 // update the sortOrder
54575 for(var i = 0; i < cm.config.length; i++ ) {
54577 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined') && (index != i)) {
54578 continue; // dont' bother, it's not in sort list or being set.
54581 so.push(cm.config[i].dataIndex);
54587 dm.sort(cm.getDataIndex(index));
54591 destroy : function(){
54593 this.colMenu.removeAll();
54594 Roo.menu.MenuMgr.unregister(this.colMenu);
54595 this.colMenu.getEl().remove();
54596 delete this.colMenu;
54599 this.hmenu.removeAll();
54600 Roo.menu.MenuMgr.unregister(this.hmenu);
54601 this.hmenu.getEl().remove();
54604 if(this.grid.enableColumnMove){
54605 var dds = Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
54607 for(var dd in dds){
54608 if(!dds[dd].config.isTarget && dds[dd].dragElId){
54609 var elid = dds[dd].dragElId;
54611 Roo.get(elid).remove();
54612 } else if(dds[dd].config.isTarget){
54613 dds[dd].proxyTop.remove();
54614 dds[dd].proxyBottom.remove();
54617 if(Roo.dd.DDM.locationCache[dd]){
54618 delete Roo.dd.DDM.locationCache[dd];
54621 delete Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
54624 Roo.util.CSS.removeStyleSheet(this.idToCssName(this.grid.id) + '-cssrules');
54625 this.bind(null, null);
54626 Roo.EventManager.removeResizeListener(this.onWindowResize, this);
54629 handleLockChange : function(){
54630 this.refresh(true);
54633 onDenyColumnLock : function(){
54637 onDenyColumnHide : function(){
54641 handleHdMenuClick : function(item){
54642 var index = this.hdCtxIndex;
54643 var cm = this.cm, ds = this.ds;
54646 ds.sort(cm.getDataIndex(index), "ASC");
54649 ds.sort(cm.getDataIndex(index), "DESC");
54652 var lc = cm.getLockedCount();
54653 if(cm.getColumnCount(true) <= lc+1){
54654 this.onDenyColumnLock();
54658 cm.setLocked(index, true, true);
54659 cm.moveColumn(index, lc);
54660 this.grid.fireEvent("columnmove", index, lc);
54662 cm.setLocked(index, true);
54666 var lc = cm.getLockedCount();
54667 if((lc-1) != index){
54668 cm.setLocked(index, false, true);
54669 cm.moveColumn(index, lc-1);
54670 this.grid.fireEvent("columnmove", index, lc-1);
54672 cm.setLocked(index, false);
54675 case 'wider': // used to expand cols on touch..
54677 var cw = cm.getColumnWidth(index);
54678 cw += (item.id == 'wider' ? 1 : -1) * 50;
54679 cw = Math.max(0, cw);
54680 cw = Math.min(cw,4000);
54681 cm.setColumnWidth(index, cw);
54685 index = cm.getIndexById(item.id.substr(4));
54687 if(item.checked && cm.getColumnCount(true) <= 1){
54688 this.onDenyColumnHide();
54691 cm.setHidden(index, item.checked);
54697 beforeColMenuShow : function(){
54698 var cm = this.cm, colCount = cm.getColumnCount();
54699 this.colMenu.removeAll();
54700 for(var i = 0; i < colCount; i++){
54701 this.colMenu.add(new Roo.menu.CheckItem({
54702 id: "col-"+cm.getColumnId(i),
54703 text: cm.getColumnHeader(i),
54704 checked: !cm.isHidden(i),
54710 handleHdCtx : function(g, index, e){
54712 var hd = this.getHeaderCell(index);
54713 this.hdCtxIndex = index;
54714 var ms = this.hmenu.items, cm = this.cm;
54715 ms.get("asc").setDisabled(!cm.isSortable(index));
54716 ms.get("desc").setDisabled(!cm.isSortable(index));
54717 if(this.grid.enableColLock !== false){
54718 ms.get("lock").setDisabled(cm.isLocked(index));
54719 ms.get("unlock").setDisabled(!cm.isLocked(index));
54721 this.hmenu.show(hd, "tl-bl");
54724 handleHdOver : function(e){
54725 var hd = this.findHeaderCell(e.getTarget());
54726 if(hd && !this.headersDisabled){
54727 if(this.grid.colModel.isSortable(this.getCellIndex(hd))){
54728 this.fly(hd).addClass("x-grid-hd-over");
54733 handleHdOut : function(e){
54734 var hd = this.findHeaderCell(e.getTarget());
54736 this.fly(hd).removeClass("x-grid-hd-over");
54740 handleSplitDblClick : function(e, t){
54741 var i = this.getCellIndex(t);
54742 if(this.grid.enableColumnResize !== false && this.cm.isResizable(i) && !this.cm.isFixed(i)){
54743 this.autoSizeColumn(i, true);
54748 render : function(){
54751 var colCount = cm.getColumnCount();
54753 if(this.grid.monitorWindowResize === true){
54754 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
54756 var header = this.renderHeaders();
54757 var body = this.templates.body.apply({rows:""});
54758 var html = this.templates.master.apply({
54761 lockedHeader: header[0],
54765 //this.updateColumns();
54767 this.grid.getGridEl().dom.innerHTML = html;
54769 this.initElements();
54771 // a kludge to fix the random scolling effect in webkit
54772 this.el.on("scroll", function() {
54773 this.el.dom.scrollTop=0; // hopefully not recursive..
54776 this.scroller.on("scroll", this.handleScroll, this);
54777 this.lockedBody.on("mousewheel", this.handleWheel, this);
54778 this.mainBody.on("mousewheel", this.handleWheel, this);
54780 this.mainHd.on("mouseover", this.handleHdOver, this);
54781 this.mainHd.on("mouseout", this.handleHdOut, this);
54782 this.mainHd.on("dblclick", this.handleSplitDblClick, this,
54783 {delegate: "."+this.splitClass});
54785 this.lockedHd.on("mouseover", this.handleHdOver, this);
54786 this.lockedHd.on("mouseout", this.handleHdOut, this);
54787 this.lockedHd.on("dblclick", this.handleSplitDblClick, this,
54788 {delegate: "."+this.splitClass});
54790 if(this.grid.enableColumnResize !== false && Roo.grid.SplitDragZone){
54791 new Roo.grid.SplitDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
54794 this.updateSplitters();
54796 if(this.grid.enableColumnMove && Roo.grid.HeaderDragZone){
54797 new Roo.grid.HeaderDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
54798 new Roo.grid.HeaderDropZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
54801 if(this.grid.enableCtxMenu !== false && Roo.menu.Menu){
54802 this.hmenu = new Roo.menu.Menu({id: this.grid.id + "-hctx"});
54804 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
54805 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
54807 if(this.grid.enableColLock !== false){
54808 this.hmenu.add('-',
54809 {id:"lock", text: this.lockText, cls: "xg-hmenu-lock"},
54810 {id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
54814 this.hmenu.add('-',
54815 {id:"wider", text: this.columnsWiderText},
54816 {id:"narrow", text: this.columnsNarrowText }
54822 if(this.grid.enableColumnHide !== false){
54824 this.colMenu = new Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
54825 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
54826 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
54828 this.hmenu.add('-',
54829 {id:"columns", text: this.columnsText, menu: this.colMenu}
54832 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
54834 this.grid.on("headercontextmenu", this.handleHdCtx, this);
54837 if((this.grid.enableDragDrop || this.grid.enableDrag) && Roo.grid.GridDragZone){
54838 this.dd = new Roo.grid.GridDragZone(this.grid, {
54839 ddGroup : this.grid.ddGroup || 'GridDD'
54845 for(var i = 0; i < colCount; i++){
54846 if(cm.isHidden(i)){
54847 this.hideColumn(i);
54849 if(cm.config[i].align){
54850 this.css.updateRule(this.colSelector + i, "textAlign", cm.config[i].align);
54851 this.css.updateRule(this.hdSelector + i, "textAlign", cm.config[i].align);
54855 this.updateHeaderSortState();
54857 this.beforeInitialResize();
54860 // two part rendering gives faster view to the user
54861 this.renderPhase2.defer(1, this);
54864 renderPhase2 : function(){
54865 // render the rows now
54867 if(this.grid.autoSizeColumns){
54868 this.autoSizeColumns();
54872 beforeInitialResize : function(){
54876 onColumnSplitterMoved : function(i, w){
54877 this.userResized = true;
54878 var cm = this.grid.colModel;
54879 cm.setColumnWidth(i, w, true);
54880 var cid = cm.getColumnId(i);
54881 this.css.updateRule(this.colSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
54882 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
54883 this.updateSplitters();
54885 this.grid.fireEvent("columnresize", i, w);
54888 syncRowHeights : function(startIndex, endIndex){
54889 if(this.grid.enableRowHeightSync === true && this.cm.getLockedCount() > 0){
54890 startIndex = startIndex || 0;
54891 var mrows = this.getBodyTable().rows;
54892 var lrows = this.getLockedTable().rows;
54893 var len = mrows.length-1;
54894 endIndex = Math.min(endIndex || len, len);
54895 for(var i = startIndex; i <= endIndex; i++){
54896 var m = mrows[i], l = lrows[i];
54897 var h = Math.max(m.offsetHeight, l.offsetHeight);
54898 m.style.height = l.style.height = h + "px";
54903 layout : function(initialRender, is2ndPass){
54905 var auto = g.autoHeight;
54906 var scrollOffset = 16;
54907 var c = g.getGridEl(), cm = this.cm,
54908 expandCol = g.autoExpandColumn,
54910 //c.beginMeasure();
54912 if(!c.dom.offsetWidth){ // display:none?
54914 this.lockedWrap.show();
54915 this.mainWrap.show();
54920 var hasLock = this.cm.isLocked(0);
54922 var tbh = this.headerPanel.getHeight();
54923 var bbh = this.footerPanel.getHeight();
54926 var ch = this.getBodyTable().offsetHeight + tbh + bbh + this.mainHd.getHeight();
54927 var newHeight = ch + c.getBorderWidth("tb");
54929 newHeight = Math.min(g.maxHeight, newHeight);
54931 c.setHeight(newHeight);
54935 c.setWidth(cm.getTotalWidth()+c.getBorderWidth('lr'));
54938 var s = this.scroller;
54940 var csize = c.getSize(true);
54942 this.el.setSize(csize.width, csize.height);
54944 this.headerPanel.setWidth(csize.width);
54945 this.footerPanel.setWidth(csize.width);
54947 var hdHeight = this.mainHd.getHeight();
54948 var vw = csize.width;
54949 var vh = csize.height - (tbh + bbh);
54953 var bt = this.getBodyTable();
54954 var ltWidth = hasLock ?
54955 Math.max(this.getLockedTable().offsetWidth, this.lockedHd.dom.firstChild.offsetWidth) : 0;
54957 var scrollHeight = bt.offsetHeight;
54958 var scrollWidth = ltWidth + bt.offsetWidth;
54959 var vscroll = false, hscroll = false;
54961 this.scrollSizer.setSize(scrollWidth, scrollHeight+hdHeight);
54963 var lw = this.lockedWrap, mw = this.mainWrap;
54964 var lb = this.lockedBody, mb = this.mainBody;
54966 setTimeout(function(){
54967 var t = s.dom.offsetTop;
54968 var w = s.dom.clientWidth,
54969 h = s.dom.clientHeight;
54972 lw.setSize(ltWidth, h);
54974 mw.setLeftTop(ltWidth, t);
54975 mw.setSize(w-ltWidth, h);
54977 lb.setHeight(h-hdHeight);
54978 mb.setHeight(h-hdHeight);
54980 if(is2ndPass !== true && !gv.userResized && expandCol){
54981 // high speed resize without full column calculation
54983 var ci = cm.getIndexById(expandCol);
54985 ci = cm.findColumnIndex(expandCol);
54987 ci = Math.max(0, ci); // make sure it's got at least the first col.
54988 var expandId = cm.getColumnId(ci);
54989 var tw = cm.getTotalWidth(false);
54990 var currentWidth = cm.getColumnWidth(ci);
54991 var cw = Math.min(Math.max(((w-tw)+currentWidth-2)-/*scrollbar*/(w <= s.dom.offsetWidth ? 0 : 18), g.autoExpandMin), g.autoExpandMax);
54992 if(currentWidth != cw){
54993 cm.setColumnWidth(ci, cw, true);
54994 gv.css.updateRule(gv.colSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
54995 gv.css.updateRule(gv.hdSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
54996 gv.updateSplitters();
54997 gv.layout(false, true);
55009 onWindowResize : function(){
55010 if(!this.grid.monitorWindowResize || this.grid.autoHeight){
55016 appendFooter : function(parentEl){
55020 sortAscText : "Sort Ascending",
55021 sortDescText : "Sort Descending",
55022 lockText : "Lock Column",
55023 unlockText : "Unlock Column",
55024 columnsText : "Columns",
55026 columnsWiderText : "Wider",
55027 columnsNarrowText : "Thinner"
55031 Roo.grid.GridView.ColumnDragZone = function(grid, hd){
55032 Roo.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
55033 this.proxy.el.addClass('x-grid3-col-dd');
55036 Roo.extend(Roo.grid.GridView.ColumnDragZone, Roo.grid.HeaderDragZone, {
55037 handleMouseDown : function(e){
55041 callHandleMouseDown : function(e){
55042 Roo.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
55047 * Ext JS Library 1.1.1
55048 * Copyright(c) 2006-2007, Ext JS, LLC.
55050 * Originally Released Under LGPL - original licence link has changed is not relivant.
55053 * <script type="text/javascript">
55057 // This is a support class used internally by the Grid components
55058 Roo.grid.SplitDragZone = function(grid, hd, hd2){
55060 this.view = grid.getView();
55061 this.proxy = this.view.resizeProxy;
55062 Roo.grid.SplitDragZone.superclass.constructor.call(this, hd,
55063 "gridSplitters" + this.grid.getGridEl().id, {
55064 dragElId : Roo.id(this.proxy.dom), resizeFrame:false
55066 this.setHandleElId(Roo.id(hd));
55067 this.setOuterHandleElId(Roo.id(hd2));
55068 this.scroll = false;
55070 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
55071 fly: Roo.Element.fly,
55073 b4StartDrag : function(x, y){
55074 this.view.headersDisabled = true;
55075 this.proxy.setHeight(this.view.mainWrap.getHeight());
55076 var w = this.cm.getColumnWidth(this.cellIndex);
55077 var minw = Math.max(w-this.grid.minColumnWidth, 0);
55078 this.resetConstraints();
55079 this.setXConstraint(minw, 1000);
55080 this.setYConstraint(0, 0);
55081 this.minX = x - minw;
55082 this.maxX = x + 1000;
55084 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
55088 handleMouseDown : function(e){
55089 ev = Roo.EventObject.setEvent(e);
55090 var t = this.fly(ev.getTarget());
55091 if(t.hasClass("x-grid-split")){
55092 this.cellIndex = this.view.getCellIndex(t.dom);
55093 this.split = t.dom;
55094 this.cm = this.grid.colModel;
55095 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
55096 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
55101 endDrag : function(e){
55102 this.view.headersDisabled = false;
55103 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
55104 var diff = endX - this.startPos;
55105 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
55108 autoOffset : function(){
55109 this.setDelta(0,0);
55113 * Ext JS Library 1.1.1
55114 * Copyright(c) 2006-2007, Ext JS, LLC.
55116 * Originally Released Under LGPL - original licence link has changed is not relivant.
55119 * <script type="text/javascript">
55123 // This is a support class used internally by the Grid components
55124 Roo.grid.GridDragZone = function(grid, config){
55125 this.view = grid.getView();
55126 Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
55127 if(this.view.lockedBody){
55128 this.setHandleElId(Roo.id(this.view.mainBody.dom));
55129 this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
55131 this.scroll = false;
55133 this.ddel = document.createElement('div');
55134 this.ddel.className = 'x-grid-dd-wrap';
55137 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
55138 ddGroup : "GridDD",
55140 getDragData : function(e){
55141 var t = Roo.lib.Event.getTarget(e);
55142 var rowIndex = this.view.findRowIndex(t);
55143 var sm = this.grid.selModel;
55145 //Roo.log(rowIndex);
55147 if (sm.getSelectedCell) {
55148 // cell selection..
55149 if (!sm.getSelectedCell()) {
55152 if (rowIndex != sm.getSelectedCell()[0]) {
55158 if(rowIndex !== false){
55163 //Roo.log([ sm.getSelectedCell() ? sm.getSelectedCell()[0] : 'NO' , rowIndex ]);
55165 //if(!sm.isSelected(rowIndex) || e.hasModifier()){
55168 if (e.hasModifier()){
55169 sm.handleMouseDown(e, t); // non modifier buttons are handled by row select.
55172 Roo.log("getDragData");
55177 rowIndex: rowIndex,
55178 selections:sm.getSelections ? sm.getSelections() : (
55179 sm.getSelectedCell() ? [ this.grid.ds.getAt(sm.getSelectedCell()[0]) ] : []
55186 onInitDrag : function(e){
55187 var data = this.dragData;
55188 this.ddel.innerHTML = this.grid.getDragDropText();
55189 this.proxy.update(this.ddel);
55190 // fire start drag?
55193 afterRepair : function(){
55194 this.dragging = false;
55197 getRepairXY : function(e, data){
55201 onEndDrag : function(data, e){
55205 onValidDrop : function(dd, e, id){
55210 beforeInvalidDrop : function(e, id){
55215 * Ext JS Library 1.1.1
55216 * Copyright(c) 2006-2007, Ext JS, LLC.
55218 * Originally Released Under LGPL - original licence link has changed is not relivant.
55221 * <script type="text/javascript">
55226 * @class Roo.grid.ColumnModel
55227 * @extends Roo.util.Observable
55228 * This is the default implementation of a ColumnModel used by the Grid. It defines
55229 * the columns in the grid.
55232 var colModel = new Roo.grid.ColumnModel([
55233 {header: "Ticker", width: 60, sortable: true, locked: true},
55234 {header: "Company Name", width: 150, sortable: true},
55235 {header: "Market Cap.", width: 100, sortable: true},
55236 {header: "$ Sales", width: 100, sortable: true, renderer: money},
55237 {header: "Employees", width: 100, sortable: true, resizable: false}
55242 * The config options listed for this class are options which may appear in each
55243 * individual column definition.
55244 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
55246 * @param {Object} config An Array of column config objects. See this class's
55247 * config objects for details.
55249 Roo.grid.ColumnModel = function(config){
55251 * The config passed into the constructor
55253 this.config = config;
55256 // if no id, create one
55257 // if the column does not have a dataIndex mapping,
55258 // map it to the order it is in the config
55259 for(var i = 0, len = config.length; i < len; i++){
55261 if(typeof c.dataIndex == "undefined"){
55264 if(typeof c.renderer == "string"){
55265 c.renderer = Roo.util.Format[c.renderer];
55267 if(typeof c.id == "undefined"){
55270 if(c.editor && c.editor.xtype){
55271 c.editor = Roo.factory(c.editor, Roo.grid);
55273 if(c.editor && c.editor.isFormField){
55274 c.editor = new Roo.grid.GridEditor(c.editor);
55276 this.lookup[c.id] = c;
55280 * The width of columns which have no width specified (defaults to 100)
55283 this.defaultWidth = 100;
55286 * Default sortable of columns which have no sortable specified (defaults to false)
55289 this.defaultSortable = false;
55293 * @event widthchange
55294 * Fires when the width of a column changes.
55295 * @param {ColumnModel} this
55296 * @param {Number} columnIndex The column index
55297 * @param {Number} newWidth The new width
55299 "widthchange": true,
55301 * @event headerchange
55302 * Fires when the text of a header changes.
55303 * @param {ColumnModel} this
55304 * @param {Number} columnIndex The column index
55305 * @param {Number} newText The new header text
55307 "headerchange": true,
55309 * @event hiddenchange
55310 * Fires when a column is hidden or "unhidden".
55311 * @param {ColumnModel} this
55312 * @param {Number} columnIndex The column index
55313 * @param {Boolean} hidden true if hidden, false otherwise
55315 "hiddenchange": true,
55317 * @event columnmoved
55318 * Fires when a column is moved.
55319 * @param {ColumnModel} this
55320 * @param {Number} oldIndex
55321 * @param {Number} newIndex
55323 "columnmoved" : true,
55325 * @event columlockchange
55326 * Fires when a column's locked state is changed
55327 * @param {ColumnModel} this
55328 * @param {Number} colIndex
55329 * @param {Boolean} locked true if locked
55331 "columnlockchange" : true
55333 Roo.grid.ColumnModel.superclass.constructor.call(this);
55335 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
55337 * @cfg {String} header The header text to display in the Grid view.
55340 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
55341 * {@link Roo.data.Record} definition from which to draw the column's value. If not
55342 * specified, the column's index is used as an index into the Record's data Array.
55345 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
55346 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
55349 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
55350 * Defaults to the value of the {@link #defaultSortable} property.
55351 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
55354 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
55357 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
55360 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
55363 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
55366 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
55367 * given the cell's data value. See {@link #setRenderer}. If not specified, the
55368 * default renderer uses the raw data value. If an object is returned (bootstrap only)
55369 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
55372 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
55375 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
55378 * @cfg {String} cursor (Optional)
55381 * @cfg {String} tooltip (Optional)
55384 * Returns the id of the column at the specified index.
55385 * @param {Number} index The column index
55386 * @return {String} the id
55388 getColumnId : function(index){
55389 return this.config[index].id;
55393 * Returns the column for a specified id.
55394 * @param {String} id The column id
55395 * @return {Object} the column
55397 getColumnById : function(id){
55398 return this.lookup[id];
55403 * Returns the column for a specified dataIndex.
55404 * @param {String} dataIndex The column dataIndex
55405 * @return {Object|Boolean} the column or false if not found
55407 getColumnByDataIndex: function(dataIndex){
55408 var index = this.findColumnIndex(dataIndex);
55409 return index > -1 ? this.config[index] : false;
55413 * Returns the index for a specified column id.
55414 * @param {String} id The column id
55415 * @return {Number} the index, or -1 if not found
55417 getIndexById : function(id){
55418 for(var i = 0, len = this.config.length; i < len; i++){
55419 if(this.config[i].id == id){
55427 * Returns the index for a specified column dataIndex.
55428 * @param {String} dataIndex The column dataIndex
55429 * @return {Number} the index, or -1 if not found
55432 findColumnIndex : function(dataIndex){
55433 for(var i = 0, len = this.config.length; i < len; i++){
55434 if(this.config[i].dataIndex == dataIndex){
55442 moveColumn : function(oldIndex, newIndex){
55443 var c = this.config[oldIndex];
55444 this.config.splice(oldIndex, 1);
55445 this.config.splice(newIndex, 0, c);
55446 this.dataMap = null;
55447 this.fireEvent("columnmoved", this, oldIndex, newIndex);
55450 isLocked : function(colIndex){
55451 return this.config[colIndex].locked === true;
55454 setLocked : function(colIndex, value, suppressEvent){
55455 if(this.isLocked(colIndex) == value){
55458 this.config[colIndex].locked = value;
55459 if(!suppressEvent){
55460 this.fireEvent("columnlockchange", this, colIndex, value);
55464 getTotalLockedWidth : function(){
55465 var totalWidth = 0;
55466 for(var i = 0; i < this.config.length; i++){
55467 if(this.isLocked(i) && !this.isHidden(i)){
55468 this.totalWidth += this.getColumnWidth(i);
55474 getLockedCount : function(){
55475 for(var i = 0, len = this.config.length; i < len; i++){
55476 if(!this.isLocked(i)){
55483 * Returns the number of columns.
55486 getColumnCount : function(visibleOnly){
55487 if(visibleOnly === true){
55489 for(var i = 0, len = this.config.length; i < len; i++){
55490 if(!this.isHidden(i)){
55496 return this.config.length;
55500 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
55501 * @param {Function} fn
55502 * @param {Object} scope (optional)
55503 * @return {Array} result
55505 getColumnsBy : function(fn, scope){
55507 for(var i = 0, len = this.config.length; i < len; i++){
55508 var c = this.config[i];
55509 if(fn.call(scope||this, c, i) === true){
55517 * Returns true if the specified column is sortable.
55518 * @param {Number} col The column index
55519 * @return {Boolean}
55521 isSortable : function(col){
55522 if(typeof this.config[col].sortable == "undefined"){
55523 return this.defaultSortable;
55525 return this.config[col].sortable;
55529 * Returns the rendering (formatting) function defined for the column.
55530 * @param {Number} col The column index.
55531 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
55533 getRenderer : function(col){
55534 if(!this.config[col].renderer){
55535 return Roo.grid.ColumnModel.defaultRenderer;
55537 return this.config[col].renderer;
55541 * Sets the rendering (formatting) function for a column.
55542 * @param {Number} col The column index
55543 * @param {Function} fn The function to use to process the cell's raw data
55544 * to return HTML markup for the grid view. The render function is called with
55545 * the following parameters:<ul>
55546 * <li>Data value.</li>
55547 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
55548 * <li>css A CSS style string to apply to the table cell.</li>
55549 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
55550 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
55551 * <li>Row index</li>
55552 * <li>Column index</li>
55553 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
55555 setRenderer : function(col, fn){
55556 this.config[col].renderer = fn;
55560 * Returns the width for the specified column.
55561 * @param {Number} col The column index
55564 getColumnWidth : function(col){
55565 return this.config[col].width * 1 || this.defaultWidth;
55569 * Sets the width for a column.
55570 * @param {Number} col The column index
55571 * @param {Number} width The new width
55573 setColumnWidth : function(col, width, suppressEvent){
55574 this.config[col].width = width;
55575 this.totalWidth = null;
55576 if(!suppressEvent){
55577 this.fireEvent("widthchange", this, col, width);
55582 * Returns the total width of all columns.
55583 * @param {Boolean} includeHidden True to include hidden column widths
55586 getTotalWidth : function(includeHidden){
55587 if(!this.totalWidth){
55588 this.totalWidth = 0;
55589 for(var i = 0, len = this.config.length; i < len; i++){
55590 if(includeHidden || !this.isHidden(i)){
55591 this.totalWidth += this.getColumnWidth(i);
55595 return this.totalWidth;
55599 * Returns the header for the specified column.
55600 * @param {Number} col The column index
55603 getColumnHeader : function(col){
55604 return this.config[col].header;
55608 * Sets the header for a column.
55609 * @param {Number} col The column index
55610 * @param {String} header The new header
55612 setColumnHeader : function(col, header){
55613 this.config[col].header = header;
55614 this.fireEvent("headerchange", this, col, header);
55618 * Returns the tooltip for the specified column.
55619 * @param {Number} col The column index
55622 getColumnTooltip : function(col){
55623 return this.config[col].tooltip;
55626 * Sets the tooltip for a column.
55627 * @param {Number} col The column index
55628 * @param {String} tooltip The new tooltip
55630 setColumnTooltip : function(col, tooltip){
55631 this.config[col].tooltip = tooltip;
55635 * Returns the dataIndex for the specified column.
55636 * @param {Number} col The column index
55639 getDataIndex : function(col){
55640 return this.config[col].dataIndex;
55644 * Sets the dataIndex for a column.
55645 * @param {Number} col The column index
55646 * @param {Number} dataIndex The new dataIndex
55648 setDataIndex : function(col, dataIndex){
55649 this.config[col].dataIndex = dataIndex;
55655 * Returns true if the cell is editable.
55656 * @param {Number} colIndex The column index
55657 * @param {Number} rowIndex The row index
55658 * @return {Boolean}
55660 isCellEditable : function(colIndex, rowIndex){
55661 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
55665 * Returns the editor defined for the cell/column.
55666 * return false or null to disable editing.
55667 * @param {Number} colIndex The column index
55668 * @param {Number} rowIndex The row index
55671 getCellEditor : function(colIndex, rowIndex){
55672 return this.config[colIndex].editor;
55676 * Sets if a column is editable.
55677 * @param {Number} col The column index
55678 * @param {Boolean} editable True if the column is editable
55680 setEditable : function(col, editable){
55681 this.config[col].editable = editable;
55686 * Returns true if the column is hidden.
55687 * @param {Number} colIndex The column index
55688 * @return {Boolean}
55690 isHidden : function(colIndex){
55691 return this.config[colIndex].hidden;
55696 * Returns true if the column width cannot be changed
55698 isFixed : function(colIndex){
55699 return this.config[colIndex].fixed;
55703 * Returns true if the column can be resized
55704 * @return {Boolean}
55706 isResizable : function(colIndex){
55707 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
55710 * Sets if a column is hidden.
55711 * @param {Number} colIndex The column index
55712 * @param {Boolean} hidden True if the column is hidden
55714 setHidden : function(colIndex, hidden){
55715 this.config[colIndex].hidden = hidden;
55716 this.totalWidth = null;
55717 this.fireEvent("hiddenchange", this, colIndex, hidden);
55721 * Sets the editor for a column.
55722 * @param {Number} col The column index
55723 * @param {Object} editor The editor object
55725 setEditor : function(col, editor){
55726 this.config[col].editor = editor;
55730 Roo.grid.ColumnModel.defaultRenderer = function(value){
55731 if(typeof value == "string" && value.length < 1){
55737 // Alias for backwards compatibility
55738 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
55741 * Ext JS Library 1.1.1
55742 * Copyright(c) 2006-2007, Ext JS, LLC.
55744 * Originally Released Under LGPL - original licence link has changed is not relivant.
55747 * <script type="text/javascript">
55751 * @class Roo.grid.AbstractSelectionModel
55752 * @extends Roo.util.Observable
55753 * Abstract base class for grid SelectionModels. It provides the interface that should be
55754 * implemented by descendant classes. This class should not be directly instantiated.
55757 Roo.grid.AbstractSelectionModel = function(){
55758 this.locked = false;
55759 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
55762 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
55763 /** @ignore Called by the grid automatically. Do not call directly. */
55764 init : function(grid){
55770 * Locks the selections.
55773 this.locked = true;
55777 * Unlocks the selections.
55779 unlock : function(){
55780 this.locked = false;
55784 * Returns true if the selections are locked.
55785 * @return {Boolean}
55787 isLocked : function(){
55788 return this.locked;
55792 * Ext JS Library 1.1.1
55793 * Copyright(c) 2006-2007, Ext JS, LLC.
55795 * Originally Released Under LGPL - original licence link has changed is not relivant.
55798 * <script type="text/javascript">
55801 * @extends Roo.grid.AbstractSelectionModel
55802 * @class Roo.grid.RowSelectionModel
55803 * The default SelectionModel used by {@link Roo.grid.Grid}.
55804 * It supports multiple selections and keyboard selection/navigation.
55806 * @param {Object} config
55808 Roo.grid.RowSelectionModel = function(config){
55809 Roo.apply(this, config);
55810 this.selections = new Roo.util.MixedCollection(false, function(o){
55815 this.lastActive = false;
55819 * @event selectionchange
55820 * Fires when the selection changes
55821 * @param {SelectionModel} this
55823 "selectionchange" : true,
55825 * @event afterselectionchange
55826 * Fires after the selection changes (eg. by key press or clicking)
55827 * @param {SelectionModel} this
55829 "afterselectionchange" : true,
55831 * @event beforerowselect
55832 * Fires when a row is selected being selected, return false to cancel.
55833 * @param {SelectionModel} this
55834 * @param {Number} rowIndex The selected index
55835 * @param {Boolean} keepExisting False if other selections will be cleared
55837 "beforerowselect" : true,
55840 * Fires when a row is selected.
55841 * @param {SelectionModel} this
55842 * @param {Number} rowIndex The selected index
55843 * @param {Roo.data.Record} r The record
55845 "rowselect" : true,
55847 * @event rowdeselect
55848 * Fires when a row is deselected.
55849 * @param {SelectionModel} this
55850 * @param {Number} rowIndex The selected index
55852 "rowdeselect" : true
55854 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
55855 this.locked = false;
55858 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
55860 * @cfg {Boolean} singleSelect
55861 * True to allow selection of only one row at a time (defaults to false)
55863 singleSelect : false,
55866 initEvents : function(){
55868 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
55869 this.grid.on("mousedown", this.handleMouseDown, this);
55870 }else{ // allow click to work like normal
55871 this.grid.on("rowclick", this.handleDragableRowClick, this);
55874 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
55875 "up" : function(e){
55877 this.selectPrevious(e.shiftKey);
55878 }else if(this.last !== false && this.lastActive !== false){
55879 var last = this.last;
55880 this.selectRange(this.last, this.lastActive-1);
55881 this.grid.getView().focusRow(this.lastActive);
55882 if(last !== false){
55886 this.selectFirstRow();
55888 this.fireEvent("afterselectionchange", this);
55890 "down" : function(e){
55892 this.selectNext(e.shiftKey);
55893 }else if(this.last !== false && this.lastActive !== false){
55894 var last = this.last;
55895 this.selectRange(this.last, this.lastActive+1);
55896 this.grid.getView().focusRow(this.lastActive);
55897 if(last !== false){
55901 this.selectFirstRow();
55903 this.fireEvent("afterselectionchange", this);
55908 var view = this.grid.view;
55909 view.on("refresh", this.onRefresh, this);
55910 view.on("rowupdated", this.onRowUpdated, this);
55911 view.on("rowremoved", this.onRemove, this);
55915 onRefresh : function(){
55916 var ds = this.grid.dataSource, i, v = this.grid.view;
55917 var s = this.selections;
55918 s.each(function(r){
55919 if((i = ds.indexOfId(r.id)) != -1){
55928 onRemove : function(v, index, r){
55929 this.selections.remove(r);
55933 onRowUpdated : function(v, index, r){
55934 if(this.isSelected(r)){
55935 v.onRowSelect(index);
55941 * @param {Array} records The records to select
55942 * @param {Boolean} keepExisting (optional) True to keep existing selections
55944 selectRecords : function(records, keepExisting){
55946 this.clearSelections();
55948 var ds = this.grid.dataSource;
55949 for(var i = 0, len = records.length; i < len; i++){
55950 this.selectRow(ds.indexOf(records[i]), true);
55955 * Gets the number of selected rows.
55958 getCount : function(){
55959 return this.selections.length;
55963 * Selects the first row in the grid.
55965 selectFirstRow : function(){
55970 * Select the last row.
55971 * @param {Boolean} keepExisting (optional) True to keep existing selections
55973 selectLastRow : function(keepExisting){
55974 this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
55978 * Selects the row immediately following the last selected row.
55979 * @param {Boolean} keepExisting (optional) True to keep existing selections
55981 selectNext : function(keepExisting){
55982 if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
55983 this.selectRow(this.last+1, keepExisting);
55984 this.grid.getView().focusRow(this.last);
55989 * Selects the row that precedes the last selected row.
55990 * @param {Boolean} keepExisting (optional) True to keep existing selections
55992 selectPrevious : function(keepExisting){
55994 this.selectRow(this.last-1, keepExisting);
55995 this.grid.getView().focusRow(this.last);
56000 * Returns the selected records
56001 * @return {Array} Array of selected records
56003 getSelections : function(){
56004 return [].concat(this.selections.items);
56008 * Returns the first selected record.
56011 getSelected : function(){
56012 return this.selections.itemAt(0);
56017 * Clears all selections.
56019 clearSelections : function(fast){
56020 if(this.locked) return;
56022 var ds = this.grid.dataSource;
56023 var s = this.selections;
56024 s.each(function(r){
56025 this.deselectRow(ds.indexOfId(r.id));
56029 this.selections.clear();
56036 * Selects all rows.
56038 selectAll : function(){
56039 if(this.locked) return;
56040 this.selections.clear();
56041 for(var i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
56042 this.selectRow(i, true);
56047 * Returns True if there is a selection.
56048 * @return {Boolean}
56050 hasSelection : function(){
56051 return this.selections.length > 0;
56055 * Returns True if the specified row is selected.
56056 * @param {Number/Record} record The record or index of the record to check
56057 * @return {Boolean}
56059 isSelected : function(index){
56060 var r = typeof index == "number" ? this.grid.dataSource.getAt(index) : index;
56061 return (r && this.selections.key(r.id) ? true : false);
56065 * Returns True if the specified record id is selected.
56066 * @param {String} id The id of record to check
56067 * @return {Boolean}
56069 isIdSelected : function(id){
56070 return (this.selections.key(id) ? true : false);
56074 handleMouseDown : function(e, t){
56075 var view = this.grid.getView(), rowIndex;
56076 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
56079 if(e.shiftKey && this.last !== false){
56080 var last = this.last;
56081 this.selectRange(last, rowIndex, e.ctrlKey);
56082 this.last = last; // reset the last
56083 view.focusRow(rowIndex);
56085 var isSelected = this.isSelected(rowIndex);
56086 if(e.button !== 0 && isSelected){
56087 view.focusRow(rowIndex);
56088 }else if(e.ctrlKey && isSelected){
56089 this.deselectRow(rowIndex);
56090 }else if(!isSelected){
56091 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
56092 view.focusRow(rowIndex);
56095 this.fireEvent("afterselectionchange", this);
56098 handleDragableRowClick : function(grid, rowIndex, e)
56100 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
56101 this.selectRow(rowIndex, false);
56102 grid.view.focusRow(rowIndex);
56103 this.fireEvent("afterselectionchange", this);
56108 * Selects multiple rows.
56109 * @param {Array} rows Array of the indexes of the row to select
56110 * @param {Boolean} keepExisting (optional) True to keep existing selections
56112 selectRows : function(rows, keepExisting){
56114 this.clearSelections();
56116 for(var i = 0, len = rows.length; i < len; i++){
56117 this.selectRow(rows[i], true);
56122 * Selects a range of rows. All rows in between startRow and endRow are also selected.
56123 * @param {Number} startRow The index of the first row in the range
56124 * @param {Number} endRow The index of the last row in the range
56125 * @param {Boolean} keepExisting (optional) True to retain existing selections
56127 selectRange : function(startRow, endRow, keepExisting){
56128 if(this.locked) return;
56130 this.clearSelections();
56132 if(startRow <= endRow){
56133 for(var i = startRow; i <= endRow; i++){
56134 this.selectRow(i, true);
56137 for(var i = startRow; i >= endRow; i--){
56138 this.selectRow(i, true);
56144 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
56145 * @param {Number} startRow The index of the first row in the range
56146 * @param {Number} endRow The index of the last row in the range
56148 deselectRange : function(startRow, endRow, preventViewNotify){
56149 if(this.locked) return;
56150 for(var i = startRow; i <= endRow; i++){
56151 this.deselectRow(i, preventViewNotify);
56157 * @param {Number} row The index of the row to select
56158 * @param {Boolean} keepExisting (optional) True to keep existing selections
56160 selectRow : function(index, keepExisting, preventViewNotify){
56161 if(this.locked || (index < 0 || index >= this.grid.dataSource.getCount())) return;
56162 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
56163 if(!keepExisting || this.singleSelect){
56164 this.clearSelections();
56166 var r = this.grid.dataSource.getAt(index);
56167 this.selections.add(r);
56168 this.last = this.lastActive = index;
56169 if(!preventViewNotify){
56170 this.grid.getView().onRowSelect(index);
56172 this.fireEvent("rowselect", this, index, r);
56173 this.fireEvent("selectionchange", this);
56179 * @param {Number} row The index of the row to deselect
56181 deselectRow : function(index, preventViewNotify){
56182 if(this.locked) return;
56183 if(this.last == index){
56186 if(this.lastActive == index){
56187 this.lastActive = false;
56189 var r = this.grid.dataSource.getAt(index);
56190 this.selections.remove(r);
56191 if(!preventViewNotify){
56192 this.grid.getView().onRowDeselect(index);
56194 this.fireEvent("rowdeselect", this, index);
56195 this.fireEvent("selectionchange", this);
56199 restoreLast : function(){
56201 this.last = this._last;
56206 acceptsNav : function(row, col, cm){
56207 return !cm.isHidden(col) && cm.isCellEditable(col, row);
56211 onEditorKey : function(field, e){
56212 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
56217 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
56219 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
56221 }else if(k == e.ENTER && !e.ctrlKey){
56225 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
56227 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
56229 }else if(k == e.ESC){
56233 g.startEditing(newCell[0], newCell[1]);
56238 * Ext JS Library 1.1.1
56239 * Copyright(c) 2006-2007, Ext JS, LLC.
56241 * Originally Released Under LGPL - original licence link has changed is not relivant.
56244 * <script type="text/javascript">
56247 * @class Roo.grid.CellSelectionModel
56248 * @extends Roo.grid.AbstractSelectionModel
56249 * This class provides the basic implementation for cell selection in a grid.
56251 * @param {Object} config The object containing the configuration of this model.
56252 * @cfg {Boolean} enter_is_tab Enter behaves the same as tab. (eg. goes to next cell) default: false
56254 Roo.grid.CellSelectionModel = function(config){
56255 Roo.apply(this, config);
56257 this.selection = null;
56261 * @event beforerowselect
56262 * Fires before a cell is selected.
56263 * @param {SelectionModel} this
56264 * @param {Number} rowIndex The selected row index
56265 * @param {Number} colIndex The selected cell index
56267 "beforecellselect" : true,
56269 * @event cellselect
56270 * Fires when a cell is selected.
56271 * @param {SelectionModel} this
56272 * @param {Number} rowIndex The selected row index
56273 * @param {Number} colIndex The selected cell index
56275 "cellselect" : true,
56277 * @event selectionchange
56278 * Fires when the active selection changes.
56279 * @param {SelectionModel} this
56280 * @param {Object} selection null for no selection or an object (o) with two properties
56282 <li>o.record: the record object for the row the selection is in</li>
56283 <li>o.cell: An array of [rowIndex, columnIndex]</li>
56286 "selectionchange" : true,
56289 * Fires when the tab (or enter) was pressed on the last editable cell
56290 * You can use this to trigger add new row.
56291 * @param {SelectionModel} this
56295 * @event beforeeditnext
56296 * Fires before the next editable sell is made active
56297 * You can use this to skip to another cell or fire the tabend
56298 * if you set cell to false
56299 * @param {Object} eventdata object : { cell : [ row, col ] }
56301 "beforeeditnext" : true
56303 Roo.grid.CellSelectionModel.superclass.constructor.call(this);
56306 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel, {
56308 enter_is_tab: false,
56311 initEvents : function(){
56312 this.grid.on("mousedown", this.handleMouseDown, this);
56313 this.grid.getGridEl().on(Roo.isIE ? "keydown" : "keypress", this.handleKeyDown, this);
56314 var view = this.grid.view;
56315 view.on("refresh", this.onViewChange, this);
56316 view.on("rowupdated", this.onRowUpdated, this);
56317 view.on("beforerowremoved", this.clearSelections, this);
56318 view.on("beforerowsinserted", this.clearSelections, this);
56319 if(this.grid.isEditor){
56320 this.grid.on("beforeedit", this.beforeEdit, this);
56325 beforeEdit : function(e){
56326 this.select(e.row, e.column, false, true, e.record);
56330 onRowUpdated : function(v, index, r){
56331 if(this.selection && this.selection.record == r){
56332 v.onCellSelect(index, this.selection.cell[1]);
56337 onViewChange : function(){
56338 this.clearSelections(true);
56342 * Returns the currently selected cell,.
56343 * @return {Array} The selected cell (row, column) or null if none selected.
56345 getSelectedCell : function(){
56346 return this.selection ? this.selection.cell : null;
56350 * Clears all selections.
56351 * @param {Boolean} true to prevent the gridview from being notified about the change.
56353 clearSelections : function(preventNotify){
56354 var s = this.selection;
56356 if(preventNotify !== true){
56357 this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
56359 this.selection = null;
56360 this.fireEvent("selectionchange", this, null);
56365 * Returns true if there is a selection.
56366 * @return {Boolean}
56368 hasSelection : function(){
56369 return this.selection ? true : false;
56373 handleMouseDown : function(e, t){
56374 var v = this.grid.getView();
56375 if(this.isLocked()){
56378 var row = v.findRowIndex(t);
56379 var cell = v.findCellIndex(t);
56380 if(row !== false && cell !== false){
56381 this.select(row, cell);
56387 * @param {Number} rowIndex
56388 * @param {Number} collIndex
56390 select : function(rowIndex, colIndex, preventViewNotify, preventFocus, /*internal*/ r){
56391 if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
56392 this.clearSelections();
56393 r = r || this.grid.dataSource.getAt(rowIndex);
56396 cell : [rowIndex, colIndex]
56398 if(!preventViewNotify){
56399 var v = this.grid.getView();
56400 v.onCellSelect(rowIndex, colIndex);
56401 if(preventFocus !== true){
56402 v.focusCell(rowIndex, colIndex);
56405 this.fireEvent("cellselect", this, rowIndex, colIndex);
56406 this.fireEvent("selectionchange", this, this.selection);
56411 isSelectable : function(rowIndex, colIndex, cm){
56412 return !cm.isHidden(colIndex);
56416 handleKeyDown : function(e){
56417 //Roo.log('Cell Sel Model handleKeyDown');
56418 if(!e.isNavKeyPress()){
56421 var g = this.grid, s = this.selection;
56424 var cell = g.walkCells(0, 0, 1, this.isSelectable, this);
56426 this.select(cell[0], cell[1]);
56431 var walk = function(row, col, step){
56432 return g.walkCells(row, col, step, sm.isSelectable, sm);
56434 var k = e.getKey(), r = s.cell[0], c = s.cell[1];
56441 // handled by onEditorKey
56442 if (g.isEditor && g.editing) {
56446 newCell = walk(r, c-1, -1);
56448 newCell = walk(r, c+1, 1);
56453 newCell = walk(r+1, c, 1);
56457 newCell = walk(r-1, c, -1);
56461 newCell = walk(r, c+1, 1);
56465 newCell = walk(r, c-1, -1);
56470 if(g.isEditor && !g.editing){
56471 g.startEditing(r, c);
56480 this.select(newCell[0], newCell[1]);
56486 acceptsNav : function(row, col, cm){
56487 return !cm.isHidden(col) && cm.isCellEditable(col, row);
56491 * @param {Number} field (not used) - as it's normally used as a listener
56492 * @param {Number} e - event - fake it by using
56494 * var e = Roo.EventObjectImpl.prototype;
56495 * e.keyCode = e.TAB
56499 onEditorKey : function(field, e){
56501 var k = e.getKey(),
56504 ed = g.activeEditor,
56506 ///Roo.log('onEditorKey' + k);
56509 if (this.enter_is_tab && k == e.ENTER) {
56515 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
56517 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
56523 } else if(k == e.ENTER && !e.ctrlKey){
56526 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
56528 } else if(k == e.ESC){
56533 var ecall = { cell : newCell, forward : forward };
56534 this.fireEvent('beforeeditnext', ecall );
56535 newCell = ecall.cell;
56536 forward = ecall.forward;
56540 //Roo.log('next cell after edit');
56541 g.startEditing.defer(100, g, [newCell[0], newCell[1]]);
56542 } else if (forward) {
56543 // tabbed past last
56544 this.fireEvent.defer(100, this, ['tabend',this]);
56549 * Ext JS Library 1.1.1
56550 * Copyright(c) 2006-2007, Ext JS, LLC.
56552 * Originally Released Under LGPL - original licence link has changed is not relivant.
56555 * <script type="text/javascript">
56559 * @class Roo.grid.EditorGrid
56560 * @extends Roo.grid.Grid
56561 * Class for creating and editable grid.
56562 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
56563 * The container MUST have some type of size defined for the grid to fill. The container will be
56564 * automatically set to position relative if it isn't already.
56565 * @param {Object} dataSource The data model to bind to
56566 * @param {Object} colModel The column model with info about this grid's columns
56568 Roo.grid.EditorGrid = function(container, config){
56569 Roo.grid.EditorGrid.superclass.constructor.call(this, container, config);
56570 this.getGridEl().addClass("xedit-grid");
56572 if(!this.selModel){
56573 this.selModel = new Roo.grid.CellSelectionModel();
56576 this.activeEditor = null;
56580 * @event beforeedit
56581 * Fires before cell editing is triggered. The edit event object has the following properties <br />
56582 * <ul style="padding:5px;padding-left:16px;">
56583 * <li>grid - This grid</li>
56584 * <li>record - The record being edited</li>
56585 * <li>field - The field name being edited</li>
56586 * <li>value - The value for the field being edited.</li>
56587 * <li>row - The grid row index</li>
56588 * <li>column - The grid column index</li>
56589 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
56591 * @param {Object} e An edit event (see above for description)
56593 "beforeedit" : true,
56596 * Fires after a cell is edited. <br />
56597 * <ul style="padding:5px;padding-left:16px;">
56598 * <li>grid - This grid</li>
56599 * <li>record - The record being edited</li>
56600 * <li>field - The field name being edited</li>
56601 * <li>value - The value being set</li>
56602 * <li>originalValue - The original value for the field, before the edit.</li>
56603 * <li>row - The grid row index</li>
56604 * <li>column - The grid column index</li>
56606 * @param {Object} e An edit event (see above for description)
56608 "afteredit" : true,
56610 * @event validateedit
56611 * Fires after a cell is edited, but before the value is set in the record.
56612 * You can use this to modify the value being set in the field, Return false
56613 * to cancel the change. The edit event object has the following properties <br />
56614 * <ul style="padding:5px;padding-left:16px;">
56615 * <li>editor - This editor</li>
56616 * <li>grid - This grid</li>
56617 * <li>record - The record being edited</li>
56618 * <li>field - The field name being edited</li>
56619 * <li>value - The value being set</li>
56620 * <li>originalValue - The original value for the field, before the edit.</li>
56621 * <li>row - The grid row index</li>
56622 * <li>column - The grid column index</li>
56623 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
56625 * @param {Object} e An edit event (see above for description)
56627 "validateedit" : true
56629 this.on("bodyscroll", this.stopEditing, this);
56630 this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick, this);
56633 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
56635 * @cfg {Number} clicksToEdit
56636 * The number of clicks on a cell required to display the cell's editor (defaults to 2)
56643 trackMouseOver: false, // causes very odd FF errors
56645 onCellDblClick : function(g, row, col){
56646 this.startEditing(row, col);
56649 onEditComplete : function(ed, value, startValue){
56650 this.editing = false;
56651 this.activeEditor = null;
56652 ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
56654 var field = this.colModel.getDataIndex(ed.col);
56659 originalValue: startValue,
56666 var cell = Roo.get(this.view.getCell(ed.row,ed.col))
56669 if(String(value) !== String(startValue)){
56671 if(this.fireEvent("validateedit", e) !== false && !e.cancel){
56672 r.set(field, e.value);
56673 // if we are dealing with a combo box..
56674 // then we also set the 'name' colum to be the displayField
56675 if (ed.field.displayField && ed.field.name) {
56676 r.set(ed.field.name, ed.field.el.dom.value);
56679 delete e.cancel; //?? why!!!
56680 this.fireEvent("afteredit", e);
56683 this.fireEvent("afteredit", e); // always fire it!
56685 this.view.focusCell(ed.row, ed.col);
56689 * Starts editing the specified for the specified row/column
56690 * @param {Number} rowIndex
56691 * @param {Number} colIndex
56693 startEditing : function(row, col){
56694 this.stopEditing();
56695 if(this.colModel.isCellEditable(col, row)){
56696 this.view.ensureVisible(row, col, true);
56698 var r = this.dataSource.getAt(row);
56699 var field = this.colModel.getDataIndex(col);
56700 var cell = Roo.get(this.view.getCell(row,col));
56705 value: r.data[field],
56710 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
56711 this.editing = true;
56712 var ed = this.colModel.getCellEditor(col, row);
56718 ed.render(ed.parentEl || document.body);
56724 (function(){ // complex but required for focus issues in safari, ie and opera
56728 ed.on("complete", this.onEditComplete, this, {single: true});
56729 ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
56730 this.activeEditor = ed;
56731 var v = r.data[field];
56732 ed.startEdit(this.view.getCell(row, col), v);
56733 // combo's with 'displayField and name set
56734 if (ed.field.displayField && ed.field.name) {
56735 ed.field.el.dom.value = r.data[ed.field.name];
56739 }).defer(50, this);
56745 * Stops any active editing
56747 stopEditing : function(){
56748 if(this.activeEditor){
56749 this.activeEditor.completeEdit();
56751 this.activeEditor = null;
56755 * Called to get grid's drag proxy text, by default returns this.ddText.
56758 getDragDropText : function(){
56759 var count = this.selModel.getSelectedCell() ? 1 : 0;
56760 return String.format(this.ddText, count, count == 1 ? '' : 's');
56765 * Ext JS Library 1.1.1
56766 * Copyright(c) 2006-2007, Ext JS, LLC.
56768 * Originally Released Under LGPL - original licence link has changed is not relivant.
56771 * <script type="text/javascript">
56774 // private - not really -- you end up using it !
56775 // This is a support class used internally by the Grid components
56778 * @class Roo.grid.GridEditor
56779 * @extends Roo.Editor
56780 * Class for creating and editable grid elements.
56781 * @param {Object} config any settings (must include field)
56783 Roo.grid.GridEditor = function(field, config){
56784 if (!config && field.field) {
56786 field = Roo.factory(config.field, Roo.form);
56788 Roo.grid.GridEditor.superclass.constructor.call(this, field, config);
56789 field.monitorTab = false;
56792 Roo.extend(Roo.grid.GridEditor, Roo.Editor, {
56795 * @cfg {Roo.form.Field} field Field to wrap (or xtyped)
56798 alignment: "tl-tl",
56801 cls: "x-small-editor x-grid-editor",
56806 * Ext JS Library 1.1.1
56807 * Copyright(c) 2006-2007, Ext JS, LLC.
56809 * Originally Released Under LGPL - original licence link has changed is not relivant.
56812 * <script type="text/javascript">
56817 Roo.grid.PropertyRecord = Roo.data.Record.create([
56818 {name:'name',type:'string'}, 'value'
56822 Roo.grid.PropertyStore = function(grid, source){
56824 this.store = new Roo.data.Store({
56825 recordType : Roo.grid.PropertyRecord
56827 this.store.on('update', this.onUpdate, this);
56829 this.setSource(source);
56831 Roo.grid.PropertyStore.superclass.constructor.call(this);
56836 Roo.extend(Roo.grid.PropertyStore, Roo.util.Observable, {
56837 setSource : function(o){
56839 this.store.removeAll();
56842 if(this.isEditableValue(o[k])){
56843 data.push(new Roo.grid.PropertyRecord({name: k, value: o[k]}, k));
56846 this.store.loadRecords({records: data}, {}, true);
56849 onUpdate : function(ds, record, type){
56850 if(type == Roo.data.Record.EDIT){
56851 var v = record.data['value'];
56852 var oldValue = record.modified['value'];
56853 if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
56854 this.source[record.id] = v;
56856 this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
56863 getProperty : function(row){
56864 return this.store.getAt(row);
56867 isEditableValue: function(val){
56868 if(val && val instanceof Date){
56870 }else if(typeof val == 'object' || typeof val == 'function'){
56876 setValue : function(prop, value){
56877 this.source[prop] = value;
56878 this.store.getById(prop).set('value', value);
56881 getSource : function(){
56882 return this.source;
56886 Roo.grid.PropertyColumnModel = function(grid, store){
56889 g.PropertyColumnModel.superclass.constructor.call(this, [
56890 {header: this.nameText, sortable: true, dataIndex:'name', id: 'name'},
56891 {header: this.valueText, resizable:false, dataIndex: 'value', id: 'value'}
56893 this.store = store;
56894 this.bselect = Roo.DomHelper.append(document.body, {
56895 tag: 'select', style:'display:none', cls: 'x-grid-editor', children: [
56896 {tag: 'option', value: 'true', html: 'true'},
56897 {tag: 'option', value: 'false', html: 'false'}
56900 Roo.id(this.bselect);
56903 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
56904 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
56905 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
56906 'int' : new g.GridEditor(new f.NumberField({selectOnFocus:true, allowDecimals:false, style:'text-align:left;'})),
56907 'boolean' : new g.GridEditor(new f.Field({el:this.bselect,selectOnFocus:true}))
56909 this.renderCellDelegate = this.renderCell.createDelegate(this);
56910 this.renderPropDelegate = this.renderProp.createDelegate(this);
56913 Roo.extend(Roo.grid.PropertyColumnModel, Roo.grid.ColumnModel, {
56917 valueText : 'Value',
56919 dateFormat : 'm/j/Y',
56922 renderDate : function(dateVal){
56923 return dateVal.dateFormat(this.dateFormat);
56926 renderBool : function(bVal){
56927 return bVal ? 'true' : 'false';
56930 isCellEditable : function(colIndex, rowIndex){
56931 return colIndex == 1;
56934 getRenderer : function(col){
56936 this.renderCellDelegate : this.renderPropDelegate;
56939 renderProp : function(v){
56940 return this.getPropertyName(v);
56943 renderCell : function(val){
56945 if(val instanceof Date){
56946 rv = this.renderDate(val);
56947 }else if(typeof val == 'boolean'){
56948 rv = this.renderBool(val);
56950 return Roo.util.Format.htmlEncode(rv);
56953 getPropertyName : function(name){
56954 var pn = this.grid.propertyNames;
56955 return pn && pn[name] ? pn[name] : name;
56958 getCellEditor : function(colIndex, rowIndex){
56959 var p = this.store.getProperty(rowIndex);
56960 var n = p.data['name'], val = p.data['value'];
56962 if(typeof(this.grid.customEditors[n]) == 'string'){
56963 return this.editors[this.grid.customEditors[n]];
56965 if(typeof(this.grid.customEditors[n]) != 'undefined'){
56966 return this.grid.customEditors[n];
56968 if(val instanceof Date){
56969 return this.editors['date'];
56970 }else if(typeof val == 'number'){
56971 return this.editors['number'];
56972 }else if(typeof val == 'boolean'){
56973 return this.editors['boolean'];
56975 return this.editors['string'];
56981 * @class Roo.grid.PropertyGrid
56982 * @extends Roo.grid.EditorGrid
56983 * This class represents the interface of a component based property grid control.
56984 * <br><br>Usage:<pre><code>
56985 var grid = new Roo.grid.PropertyGrid("my-container-id", {
56993 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
56994 * The container MUST have some type of size defined for the grid to fill. The container will be
56995 * automatically set to position relative if it isn't already.
56996 * @param {Object} config A config object that sets properties on this grid.
56998 Roo.grid.PropertyGrid = function(container, config){
56999 config = config || {};
57000 var store = new Roo.grid.PropertyStore(this);
57001 this.store = store;
57002 var cm = new Roo.grid.PropertyColumnModel(this, store);
57003 store.store.sort('name', 'ASC');
57004 Roo.grid.PropertyGrid.superclass.constructor.call(this, container, Roo.apply({
57007 enableColLock:false,
57008 enableColumnMove:false,
57010 trackMouseOver: false,
57013 this.getGridEl().addClass('x-props-grid');
57014 this.lastEditRow = null;
57015 this.on('columnresize', this.onColumnResize, this);
57018 * @event beforepropertychange
57019 * Fires before a property changes (return false to stop?)
57020 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
57021 * @param {String} id Record Id
57022 * @param {String} newval New Value
57023 * @param {String} oldval Old Value
57025 "beforepropertychange": true,
57027 * @event propertychange
57028 * Fires after a property changes
57029 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
57030 * @param {String} id Record Id
57031 * @param {String} newval New Value
57032 * @param {String} oldval Old Value
57034 "propertychange": true
57036 this.customEditors = this.customEditors || {};
57038 Roo.extend(Roo.grid.PropertyGrid, Roo.grid.EditorGrid, {
57041 * @cfg {Object} customEditors map of colnames=> custom editors.
57042 * the custom editor can be one of the standard ones (date|string|number|int|boolean), or a
57043 * grid editor eg. Roo.grid.GridEditor(new Roo.form.TextArea({selectOnFocus:true})),
57044 * false disables editing of the field.
57048 * @cfg {Object} propertyNames map of property Names to their displayed value
57051 render : function(){
57052 Roo.grid.PropertyGrid.superclass.render.call(this);
57053 this.autoSize.defer(100, this);
57056 autoSize : function(){
57057 Roo.grid.PropertyGrid.superclass.autoSize.call(this);
57059 this.view.fitColumns();
57063 onColumnResize : function(){
57064 this.colModel.setColumnWidth(1, this.container.getWidth(true)-this.colModel.getColumnWidth(0));
57068 * Sets the data for the Grid
57069 * accepts a Key => Value object of all the elements avaiable.
57070 * @param {Object} data to appear in grid.
57072 setSource : function(source){
57073 this.store.setSource(source);
57077 * Gets all the data from the grid.
57078 * @return {Object} data data stored in grid
57080 getSource : function(){
57081 return this.store.getSource();
57090 * @class Roo.grid.Calendar
57091 * @extends Roo.util.Grid
57092 * This class extends the Grid to provide a calendar widget
57093 * <br><br>Usage:<pre><code>
57094 var grid = new Roo.grid.Calendar("my-container-id", {
57097 selModel: mySelectionModel,
57098 autoSizeColumns: true,
57099 monitorWindowResize: false,
57100 trackMouseOver: true
57101 eventstore : real data store..
57107 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
57108 * The container MUST have some type of size defined for the grid to fill. The container will be
57109 * automatically set to position relative if it isn't already.
57110 * @param {Object} config A config object that sets properties on this grid.
57112 Roo.grid.Calendar = function(container, config){
57113 // initialize the container
57114 this.container = Roo.get(container);
57115 this.container.update("");
57116 this.container.setStyle("overflow", "hidden");
57117 this.container.addClass('x-grid-container');
57119 this.id = this.container.id;
57121 Roo.apply(this, config);
57122 // check and correct shorthanded configs
57126 for (var r = 0;r < 6;r++) {
57129 for (var c =0;c < 7;c++) {
57133 if (this.eventStore) {
57134 this.eventStore= Roo.factory(this.eventStore, Roo.data);
57135 this.eventStore.on('load',this.onLoad, this);
57136 this.eventStore.on('beforeload',this.clearEvents, this);
57140 this.dataSource = new Roo.data.Store({
57141 proxy: new Roo.data.MemoryProxy(rows),
57142 reader: new Roo.data.ArrayReader({}, [
57143 'weekday0', 'weekday1', 'weekday2', 'weekday3', 'weekday4', 'weekday5', 'weekday6' ])
57146 this.dataSource.load();
57147 this.ds = this.dataSource;
57148 this.ds.xmodule = this.xmodule || false;
57151 var cellRender = function(v,x,r)
57153 return String.format(
57154 '<div class="fc-day fc-widget-content"><div>' +
57155 '<div class="fc-event-container"></div>' +
57156 '<div class="fc-day-number">{0}</div>'+
57158 '<div class="fc-day-content"><div style="position:relative"></div></div>' +
57159 '</div></div>', v);
57164 this.colModel = new Roo.grid.ColumnModel( [
57166 xtype: 'ColumnModel',
57168 dataIndex : 'weekday0',
57170 renderer : cellRender
57173 xtype: 'ColumnModel',
57175 dataIndex : 'weekday1',
57177 renderer : cellRender
57180 xtype: 'ColumnModel',
57182 dataIndex : 'weekday2',
57183 header : 'Tuesday',
57184 renderer : cellRender
57187 xtype: 'ColumnModel',
57189 dataIndex : 'weekday3',
57190 header : 'Wednesday',
57191 renderer : cellRender
57194 xtype: 'ColumnModel',
57196 dataIndex : 'weekday4',
57197 header : 'Thursday',
57198 renderer : cellRender
57201 xtype: 'ColumnModel',
57203 dataIndex : 'weekday5',
57205 renderer : cellRender
57208 xtype: 'ColumnModel',
57210 dataIndex : 'weekday6',
57211 header : 'Saturday',
57212 renderer : cellRender
57215 this.cm = this.colModel;
57216 this.cm.xmodule = this.xmodule || false;
57220 //this.selModel = new Roo.grid.CellSelectionModel();
57221 //this.sm = this.selModel;
57222 //this.selModel.init(this);
57226 this.container.setWidth(this.width);
57230 this.container.setHeight(this.height);
57237 * The raw click event for the entire grid.
57238 * @param {Roo.EventObject} e
57243 * The raw dblclick event for the entire grid.
57244 * @param {Roo.EventObject} e
57248 * @event contextmenu
57249 * The raw contextmenu event for the entire grid.
57250 * @param {Roo.EventObject} e
57252 "contextmenu" : true,
57255 * The raw mousedown event for the entire grid.
57256 * @param {Roo.EventObject} e
57258 "mousedown" : true,
57261 * The raw mouseup event for the entire grid.
57262 * @param {Roo.EventObject} e
57267 * The raw mouseover event for the entire grid.
57268 * @param {Roo.EventObject} e
57270 "mouseover" : true,
57273 * The raw mouseout event for the entire grid.
57274 * @param {Roo.EventObject} e
57279 * The raw keypress event for the entire grid.
57280 * @param {Roo.EventObject} e
57285 * The raw keydown event for the entire grid.
57286 * @param {Roo.EventObject} e
57294 * Fires when a cell is clicked
57295 * @param {Grid} this
57296 * @param {Number} rowIndex
57297 * @param {Number} columnIndex
57298 * @param {Roo.EventObject} e
57300 "cellclick" : true,
57302 * @event celldblclick
57303 * Fires when a cell is double clicked
57304 * @param {Grid} this
57305 * @param {Number} rowIndex
57306 * @param {Number} columnIndex
57307 * @param {Roo.EventObject} e
57309 "celldblclick" : true,
57312 * Fires when a row is clicked
57313 * @param {Grid} this
57314 * @param {Number} rowIndex
57315 * @param {Roo.EventObject} e
57319 * @event rowdblclick
57320 * Fires when a row is double clicked
57321 * @param {Grid} this
57322 * @param {Number} rowIndex
57323 * @param {Roo.EventObject} e
57325 "rowdblclick" : true,
57327 * @event headerclick
57328 * Fires when a header is clicked
57329 * @param {Grid} this
57330 * @param {Number} columnIndex
57331 * @param {Roo.EventObject} e
57333 "headerclick" : true,
57335 * @event headerdblclick
57336 * Fires when a header cell is double clicked
57337 * @param {Grid} this
57338 * @param {Number} columnIndex
57339 * @param {Roo.EventObject} e
57341 "headerdblclick" : true,
57343 * @event rowcontextmenu
57344 * Fires when a row is right clicked
57345 * @param {Grid} this
57346 * @param {Number} rowIndex
57347 * @param {Roo.EventObject} e
57349 "rowcontextmenu" : true,
57351 * @event cellcontextmenu
57352 * Fires when a cell is right clicked
57353 * @param {Grid} this
57354 * @param {Number} rowIndex
57355 * @param {Number} cellIndex
57356 * @param {Roo.EventObject} e
57358 "cellcontextmenu" : true,
57360 * @event headercontextmenu
57361 * Fires when a header is right clicked
57362 * @param {Grid} this
57363 * @param {Number} columnIndex
57364 * @param {Roo.EventObject} e
57366 "headercontextmenu" : true,
57368 * @event bodyscroll
57369 * Fires when the body element is scrolled
57370 * @param {Number} scrollLeft
57371 * @param {Number} scrollTop
57373 "bodyscroll" : true,
57375 * @event columnresize
57376 * Fires when the user resizes a column
57377 * @param {Number} columnIndex
57378 * @param {Number} newSize
57380 "columnresize" : true,
57382 * @event columnmove
57383 * Fires when the user moves a column
57384 * @param {Number} oldIndex
57385 * @param {Number} newIndex
57387 "columnmove" : true,
57390 * Fires when row(s) start being dragged
57391 * @param {Grid} this
57392 * @param {Roo.GridDD} dd The drag drop object
57393 * @param {event} e The raw browser event
57395 "startdrag" : true,
57398 * Fires when a drag operation is complete
57399 * @param {Grid} this
57400 * @param {Roo.GridDD} dd The drag drop object
57401 * @param {event} e The raw browser event
57406 * Fires when dragged row(s) are dropped on a valid DD target
57407 * @param {Grid} this
57408 * @param {Roo.GridDD} dd The drag drop object
57409 * @param {String} targetId The target drag drop object
57410 * @param {event} e The raw browser event
57415 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
57416 * @param {Grid} this
57417 * @param {Roo.GridDD} dd The drag drop object
57418 * @param {String} targetId The target drag drop object
57419 * @param {event} e The raw browser event
57424 * Fires when the dragged row(s) first cross another DD target while being dragged
57425 * @param {Grid} this
57426 * @param {Roo.GridDD} dd The drag drop object
57427 * @param {String} targetId The target drag drop object
57428 * @param {event} e The raw browser event
57430 "dragenter" : true,
57433 * Fires when the dragged row(s) leave another DD target while being dragged
57434 * @param {Grid} this
57435 * @param {Roo.GridDD} dd The drag drop object
57436 * @param {String} targetId The target drag drop object
57437 * @param {event} e The raw browser event
57442 * Fires when a row is rendered, so you can change add a style to it.
57443 * @param {GridView} gridview The grid view
57444 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
57450 * Fires when the grid is rendered
57451 * @param {Grid} grid
57456 * Fires when a date is selected
57457 * @param {DatePicker} this
57458 * @param {Date} date The selected date
57462 * @event monthchange
57463 * Fires when the displayed month changes
57464 * @param {DatePicker} this
57465 * @param {Date} date The selected month
57467 'monthchange': true,
57469 * @event evententer
57470 * Fires when mouse over an event
57471 * @param {Calendar} this
57472 * @param {event} Event
57474 'evententer': true,
57476 * @event eventleave
57477 * Fires when the mouse leaves an
57478 * @param {Calendar} this
57481 'eventleave': true,
57483 * @event eventclick
57484 * Fires when the mouse click an
57485 * @param {Calendar} this
57488 'eventclick': true,
57490 * @event eventrender
57491 * Fires before each cell is rendered, so you can modify the contents, like cls / title / qtip
57492 * @param {Calendar} this
57493 * @param {data} data to be modified
57495 'eventrender': true
57499 Roo.grid.Grid.superclass.constructor.call(this);
57500 this.on('render', function() {
57501 this.view.el.addClass('x-grid-cal');
57503 (function() { this.setDate(new Date()); }).defer(100,this); //default today..
57507 if (!Roo.grid.Calendar.style) {
57508 Roo.grid.Calendar.style = Roo.util.CSS.createStyleSheet({
57511 '.x-grid-cal .x-grid-col' : {
57512 height: 'auto !important',
57513 'vertical-align': 'top'
57515 '.x-grid-cal .fc-event-hori' : {
57526 Roo.extend(Roo.grid.Calendar, Roo.grid.Grid, {
57528 * @cfg {Store} eventStore The store that loads events.
57533 activeDate : false,
57536 monitorWindowResize : false,
57539 resizeColumns : function() {
57540 var col = (this.view.el.getWidth() / 7) - 3;
57541 // loop through cols, and setWidth
57542 for(var i =0 ; i < 7 ; i++){
57543 this.cm.setColumnWidth(i, col);
57546 setDate :function(date) {
57548 Roo.log('setDate?');
57550 this.resizeColumns();
57551 var vd = this.activeDate;
57552 this.activeDate = date;
57553 // if(vd && this.el){
57554 // var t = date.getTime();
57555 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
57556 // Roo.log('using add remove');
57558 // this.fireEvent('monthchange', this, date);
57560 // this.cells.removeClass("fc-state-highlight");
57561 // this.cells.each(function(c){
57562 // if(c.dateValue == t){
57563 // c.addClass("fc-state-highlight");
57564 // setTimeout(function(){
57565 // try{c.dom.firstChild.focus();}catch(e){}
57575 var days = date.getDaysInMonth();
57577 var firstOfMonth = date.getFirstDateOfMonth();
57578 var startingPos = firstOfMonth.getDay()-this.startDay;
57580 if(startingPos < this.startDay){
57584 var pm = date.add(Date.MONTH, -1);
57585 var prevStart = pm.getDaysInMonth()-startingPos;
57589 this.cells = this.view.el.select('.x-grid-row .x-grid-col',true);
57591 this.textNodes = this.view.el.query('.x-grid-row .x-grid-col .x-grid-cell-text');
57592 //this.cells.addClassOnOver('fc-state-hover');
57594 var cells = this.cells.elements;
57595 var textEls = this.textNodes;
57597 //Roo.each(cells, function(cell){
57598 // cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
57601 days += startingPos;
57603 // convert everything to numbers so it's fast
57604 var day = 86400000;
57605 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
57608 //Roo.log(prevStart);
57610 var today = new Date().clearTime().getTime();
57611 var sel = date.clearTime().getTime();
57612 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
57613 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
57614 var ddMatch = this.disabledDatesRE;
57615 var ddText = this.disabledDatesText;
57616 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
57617 var ddaysText = this.disabledDaysText;
57618 var format = this.format;
57620 var setCellClass = function(cal, cell){
57622 //Roo.log('set Cell Class');
57624 var t = d.getTime();
57629 cell.dateValue = t;
57631 cell.className += " fc-today";
57632 cell.className += " fc-state-highlight";
57633 cell.title = cal.todayText;
57636 // disable highlight in other month..
57637 cell.className += " fc-state-highlight";
57642 //cell.className = " fc-state-disabled";
57643 cell.title = cal.minText;
57647 //cell.className = " fc-state-disabled";
57648 cell.title = cal.maxText;
57652 if(ddays.indexOf(d.getDay()) != -1){
57653 // cell.title = ddaysText;
57654 // cell.className = " fc-state-disabled";
57657 if(ddMatch && format){
57658 var fvalue = d.dateFormat(format);
57659 if(ddMatch.test(fvalue)){
57660 cell.title = ddText.replace("%0", fvalue);
57661 cell.className = " fc-state-disabled";
57665 if (!cell.initialClassName) {
57666 cell.initialClassName = cell.dom.className;
57669 cell.dom.className = cell.initialClassName + ' ' + cell.className;
57674 for(; i < startingPos; i++) {
57675 cells[i].dayName = (++prevStart);
57676 Roo.log(textEls[i]);
57677 d.setDate(d.getDate()+1);
57679 //cells[i].className = "fc-past fc-other-month";
57680 setCellClass(this, cells[i]);
57685 for(; i < days; i++){
57686 intDay = i - startingPos + 1;
57687 cells[i].dayName = (intDay);
57688 d.setDate(d.getDate()+1);
57690 cells[i].className = ''; // "x-date-active";
57691 setCellClass(this, cells[i]);
57695 for(; i < 42; i++) {
57696 //textEls[i].innerHTML = (++extraDays);
57698 d.setDate(d.getDate()+1);
57699 cells[i].dayName = (++extraDays);
57700 cells[i].className = "fc-future fc-other-month";
57701 setCellClass(this, cells[i]);
57704 //this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
57706 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
57708 // this will cause all the cells to mis
57711 for (var r = 0;r < 6;r++) {
57712 for (var c =0;c < 7;c++) {
57713 this.ds.getAt(r).set('weekday' + c ,cells[i++].dayName );
57717 this.cells = this.view.el.select('.x-grid-row .x-grid-col',true);
57718 for(i=0;i<cells.length;i++) {
57720 this.cells.elements[i].dayName = cells[i].dayName ;
57721 this.cells.elements[i].className = cells[i].className;
57722 this.cells.elements[i].initialClassName = cells[i].initialClassName ;
57723 this.cells.elements[i].title = cells[i].title ;
57724 this.cells.elements[i].dateValue = cells[i].dateValue ;
57730 //this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
57731 //this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
57733 ////if(totalRows != 6){
57734 //this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
57735 // this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
57738 this.fireEvent('monthchange', this, date);
57743 * Returns the grid's SelectionModel.
57744 * @return {SelectionModel}
57746 getSelectionModel : function(){
57747 if(!this.selModel){
57748 this.selModel = new Roo.grid.CellSelectionModel();
57750 return this.selModel;
57754 this.eventStore.load()
57760 findCell : function(dt) {
57761 dt = dt.clearTime().getTime();
57763 this.cells.each(function(c){
57764 //Roo.log("check " +c.dateValue + '?=' + dt);
57765 if(c.dateValue == dt){
57775 findCells : function(rec) {
57776 var s = rec.data.start_dt.clone().clearTime().getTime();
57778 var e= rec.data.end_dt.clone().clearTime().getTime();
57781 this.cells.each(function(c){
57782 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
57784 if(c.dateValue > e){
57787 if(c.dateValue < s){
57796 findBestRow: function(cells)
57800 for (var i =0 ; i < cells.length;i++) {
57801 ret = Math.max(cells[i].rows || 0,ret);
57808 addItem : function(rec)
57810 // look for vertical location slot in
57811 var cells = this.findCells(rec);
57813 rec.row = this.findBestRow(cells);
57815 // work out the location.
57819 for(var i =0; i < cells.length; i++) {
57827 if (crow.start.getY() == cells[i].getY()) {
57829 crow.end = cells[i];
57845 for (var i = 0; i < cells.length;i++) {
57846 cells[i].rows = Math.max(cells[i].rows || 0 , rec.row + 1 );
57853 clearEvents: function() {
57855 if (!this.eventStore.getCount()) {
57858 // reset number of rows in cells.
57859 Roo.each(this.cells.elements, function(c){
57863 this.eventStore.each(function(e) {
57864 this.clearEvent(e);
57869 clearEvent : function(ev)
57872 Roo.each(ev.els, function(el) {
57873 el.un('mouseenter' ,this.onEventEnter, this);
57874 el.un('mouseleave' ,this.onEventLeave, this);
57882 renderEvent : function(ev,ctr) {
57884 ctr = this.view.el.select('.fc-event-container',true).first();
57888 this.clearEvent(ev);
57894 var cells = ev.cells;
57895 var rows = ev.rows;
57896 this.fireEvent('eventrender', this, ev);
57898 for(var i =0; i < rows.length; i++) {
57902 cls += ' fc-event-start';
57904 if ((i+1) == rows.length) {
57905 cls += ' fc-event-end';
57908 //Roo.log(ev.data);
57909 // how many rows should it span..
57910 var cg = this.eventTmpl.append(ctr,Roo.apply({
57913 }, ev.data) , true);
57916 cg.on('mouseenter' ,this.onEventEnter, this, ev);
57917 cg.on('mouseleave' ,this.onEventLeave, this, ev);
57918 cg.on('click', this.onEventClick, this, ev);
57922 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
57923 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
57926 cg.setXY([sbox.x +2, sbox.y +(ev.row * 20)]);
57927 cg.setWidth(ebox.right - sbox.x -2);
57931 renderEvents: function()
57933 // first make sure there is enough space..
57935 if (!this.eventTmpl) {
57936 this.eventTmpl = new Roo.Template(
57937 '<div class="roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable {fccls} {cls}" style="position: absolute" unselectable="on">' +
57938 '<div class="fc-event-inner">' +
57939 '<span class="fc-event-time">{time}</span>' +
57940 '<span class="fc-event-title" qtip="{qtip}">{title}</span>' +
57942 '<div class="ui-resizable-heandle ui-resizable-e"> </div>' +
57950 this.cells.each(function(c) {
57951 //Roo.log(c.select('.fc-day-content div',true).first());
57952 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, (c.rows || 1) * 20));
57955 var ctr = this.view.el.select('.fc-event-container',true).first();
57958 this.eventStore.each(function(ev){
57960 this.renderEvent(ev);
57964 this.view.layout();
57968 onEventEnter: function (e, el,event,d) {
57969 this.fireEvent('evententer', this, el, event);
57972 onEventLeave: function (e, el,event,d) {
57973 this.fireEvent('eventleave', this, el, event);
57976 onEventClick: function (e, el,event,d) {
57977 this.fireEvent('eventclick', this, el, event);
57980 onMonthChange: function () {
57984 onLoad: function () {
57986 //Roo.log('calendar onload');
57988 if(this.eventStore.getCount() > 0){
57992 this.eventStore.each(function(d){
57997 if (typeof(add.end_dt) == 'undefined') {
57998 Roo.log("Missing End time in calendar data: ");
58002 if (typeof(add.start_dt) == 'undefined') {
58003 Roo.log("Missing Start time in calendar data: ");
58007 add.start_dt = typeof(add.start_dt) == 'string' ? Date.parseDate(add.start_dt,'Y-m-d H:i:s') : add.start_dt,
58008 add.end_dt = typeof(add.end_dt) == 'string' ? Date.parseDate(add.end_dt,'Y-m-d H:i:s') : add.end_dt,
58009 add.id = add.id || d.id;
58010 add.title = add.title || '??';
58018 this.renderEvents();
58028 render : function ()
58032 if (!this.view.el.hasClass('course-timesheet')) {
58033 this.view.el.addClass('course-timesheet');
58035 if (this.tsStyle) {
58040 Roo.log(_this.grid.view.el.getWidth());
58043 this.tsStyle = Roo.util.CSS.createStyleSheet({
58044 '.course-timesheet .x-grid-row' : {
58047 '.x-grid-row td' : {
58048 'vertical-align' : 0
58050 '.course-edit-link' : {
58052 'text-overflow' : 'ellipsis',
58053 'overflow' : 'hidden',
58054 'white-space' : 'nowrap',
58055 'cursor' : 'pointer'
58060 '.de-act-sup-link' : {
58061 'color' : 'purple',
58062 'text-decoration' : 'line-through'
58066 'text-decoration' : 'line-through'
58068 '.course-timesheet .course-highlight' : {
58069 'border-top-style': 'dashed !important',
58070 'border-bottom-bottom': 'dashed !important'
58072 '.course-timesheet .course-item' : {
58073 'font-family' : 'tahoma, arial, helvetica',
58074 'font-size' : '11px',
58075 'overflow' : 'hidden',
58076 'padding-left' : '10px',
58077 'padding-right' : '10px',
58078 'padding-top' : '10px'
58086 monitorWindowResize : false,
58087 cellrenderer : function(v,x,r)
58092 xtype: 'CellSelectionModel',
58099 beforeload : function (_self, options)
58101 options.params = options.params || {};
58102 options.params._month = _this.monthField.getValue();
58103 options.params.limit = 9999;
58104 options.params['sort'] = 'when_dt';
58105 options.params['dir'] = 'ASC';
58106 this.proxy.loadResponse = this.loadResponse;
58108 //this.addColumns();
58110 load : function (_self, records, options)
58112 _this.grid.view.el.select('.course-edit-link', true).on('click', function() {
58113 // if you click on the translation.. you can edit it...
58114 var el = Roo.get(this);
58115 var id = el.dom.getAttribute('data-id');
58116 var d = el.dom.getAttribute('data-date');
58117 var t = el.dom.getAttribute('data-time');
58118 //var id = this.child('span').dom.textContent;
58121 Pman.Dialog.CourseCalendar.show({
58125 productitem_active : id ? 1 : 0
58127 _this.grid.ds.load({});
58132 _this.panel.fireEvent('resize', [ '', '' ]);
58135 loadResponse : function(o, success, response){
58136 // this is overridden on before load..
58138 Roo.log("our code?");
58139 //Roo.log(success);
58140 //Roo.log(response)
58141 delete this.activeRequest;
58143 this.fireEvent("loadexception", this, o, response);
58144 o.request.callback.call(o.request.scope, null, o.request.arg, false);
58149 result = o.reader.read(response);
58151 Roo.log("load exception?");
58152 this.fireEvent("loadexception", this, o, response, e);
58153 o.request.callback.call(o.request.scope, null, o.request.arg, false);
58156 Roo.log("ready...");
58157 // loop through result.records;
58158 // and set this.tdate[date] = [] << array of records..
58160 Roo.each(result.records, function(r){
58162 if(typeof(_this.tdata[r.data.when_dt.format('j')]) == 'undefined'){
58163 _this.tdata[r.data.when_dt.format('j')] = [];
58165 _this.tdata[r.data.when_dt.format('j')].push(r.data);
58168 //Roo.log(_this.tdata);
58170 result.records = [];
58171 result.totalRecords = 6;
58173 // let's generate some duumy records for the rows.
58174 //var st = _this.dateField.getValue();
58176 // work out monday..
58177 //st = st.add(Date.DAY, -1 * st.format('w'));
58179 var date = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
58181 var firstOfMonth = date.getFirstDayOfMonth();
58182 var days = date.getDaysInMonth();
58184 var firstAdded = false;
58185 for (var i = 0; i < result.totalRecords ; i++) {
58186 //var d= st.add(Date.DAY, i);
58189 for(var w = 0 ; w < 7 ; w++){
58190 if(!firstAdded && firstOfMonth != w){
58197 var dd = (d > 0 && d < 10) ? "0"+d : d;
58198 row['weekday'+w] = String.format(
58199 '<span style="font-size: 16px;"><b>{0}</b></span>'+
58200 '<span class="course-edit-link" style="color:blue;" data-id="0" data-date="{1}"> Add New</span>',
58202 date.format('Y-m-')+dd
58205 if(typeof(_this.tdata[d]) != 'undefined'){
58206 Roo.each(_this.tdata[d], function(r){
58210 var desc = (r.productitem_id_descrip) ? r.productitem_id_descrip : '';
58211 if(r.parent_id*1>0){
58212 is_sub = (r.productitem_id_visible*1 < 1) ? 'de-act-sup-link' :'sub-link';
58215 if(r.productitem_id_visible*1 < 1 && r.parent_id*1 < 1){
58216 deactive = 'de-act-link';
58219 row['weekday'+w] += String.format(
58220 '<br /><span class="course-edit-link {3} {4}" qtip="{5}" data-id="{0}">{2} - {1}</span>',
58222 r.product_id_name, //1
58223 r.when_dt.format('h:ia'), //2
58233 // only do this if something added..
58235 result.records.push(_this.grid.dataSource.reader.newRow(row));
58239 // push it twice. (second one with an hour..
58243 this.fireEvent("load", this, o, o.request.arg);
58244 o.request.callback.call(o.request.scope, result, o.request.arg, true);
58246 sortInfo : {field: 'when_dt', direction : 'ASC' },
58248 xtype: 'HttpProxy',
58251 url : baseURL + '/Roo/Shop_course.php'
58254 xtype: 'JsonReader',
58271 'name': 'parent_id',
58275 'name': 'product_id',
58279 'name': 'productitem_id',
58297 click : function (_self, e)
58299 var sd = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
58300 sd.setMonth(sd.getMonth()-1);
58301 _this.monthField.setValue(sd.format('Y-m-d'));
58302 _this.grid.ds.load({});
58308 xtype: 'Separator',
58312 xtype: 'MonthField',
58315 render : function (_self)
58317 _this.monthField = _self;
58318 // _this.monthField.set today
58320 select : function (combo, date)
58322 _this.grid.ds.load({});
58325 value : (function() { return new Date(); })()
58328 xtype: 'Separator',
58334 text : "Blue: in-active, green: in-active sup-event, red: de-active, purple: de-active sup-event"
58344 click : function (_self, e)
58346 var sd = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
58347 sd.setMonth(sd.getMonth()+1);
58348 _this.monthField.setValue(sd.format('Y-m-d'));
58349 _this.grid.ds.load({});
58362 * Ext JS Library 1.1.1
58363 * Copyright(c) 2006-2007, Ext JS, LLC.
58365 * Originally Released Under LGPL - original licence link has changed is not relivant.
58368 * <script type="text/javascript">
58372 * @class Roo.LoadMask
58373 * A simple utility class for generically masking elements while loading data. If the element being masked has
58374 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
58375 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
58376 * element's UpdateManager load indicator and will be destroyed after the initial load.
58378 * Create a new LoadMask
58379 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
58380 * @param {Object} config The config object
58382 Roo.LoadMask = function(el, config){
58383 this.el = Roo.get(el);
58384 Roo.apply(this, config);
58386 this.store.on('beforeload', this.onBeforeLoad, this);
58387 this.store.on('load', this.onLoad, this);
58388 this.store.on('loadexception', this.onLoadException, this);
58389 this.removeMask = false;
58391 var um = this.el.getUpdateManager();
58392 um.showLoadIndicator = false; // disable the default indicator
58393 um.on('beforeupdate', this.onBeforeLoad, this);
58394 um.on('update', this.onLoad, this);
58395 um.on('failure', this.onLoad, this);
58396 this.removeMask = true;
58400 Roo.LoadMask.prototype = {
58402 * @cfg {Boolean} removeMask
58403 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
58404 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
58407 * @cfg {String} msg
58408 * The text to display in a centered loading message box (defaults to 'Loading...')
58410 msg : 'Loading...',
58412 * @cfg {String} msgCls
58413 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
58415 msgCls : 'x-mask-loading',
58418 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
58424 * Disables the mask to prevent it from being displayed
58426 disable : function(){
58427 this.disabled = true;
58431 * Enables the mask so that it can be displayed
58433 enable : function(){
58434 this.disabled = false;
58437 onLoadException : function()
58439 Roo.log(arguments);
58441 if (typeof(arguments[3]) != 'undefined') {
58442 Roo.MessageBox.alert("Error loading",arguments[3]);
58446 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
58447 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
58456 this.el.unmask(this.removeMask);
58459 onLoad : function()
58461 this.el.unmask(this.removeMask);
58465 onBeforeLoad : function(){
58466 if(!this.disabled){
58467 this.el.mask(this.msg, this.msgCls);
58472 destroy : function(){
58474 this.store.un('beforeload', this.onBeforeLoad, this);
58475 this.store.un('load', this.onLoad, this);
58476 this.store.un('loadexception', this.onLoadException, this);
58478 var um = this.el.getUpdateManager();
58479 um.un('beforeupdate', this.onBeforeLoad, this);
58480 um.un('update', this.onLoad, this);
58481 um.un('failure', this.onLoad, this);
58486 * Ext JS Library 1.1.1
58487 * Copyright(c) 2006-2007, Ext JS, LLC.
58489 * Originally Released Under LGPL - original licence link has changed is not relivant.
58492 * <script type="text/javascript">
58497 * @class Roo.XTemplate
58498 * @extends Roo.Template
58499 * Provides a template that can have nested templates for loops or conditionals. The syntax is:
58501 var t = new Roo.XTemplate(
58502 '<select name="{name}">',
58503 '<tpl for="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
58507 // then append, applying the master template values
58510 * Supported features:
58515 {a_variable} - output encoded.
58516 {a_variable.format:("Y-m-d")} - call a method on the variable
58517 {a_variable:raw} - unencoded output
58518 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
58519 {a_variable:this.method_on_template(...)} - call a method on the template object.
58524 <tpl for="a_variable or condition.."></tpl>
58525 <tpl if="a_variable or condition"></tpl>
58526 <tpl exec="some javascript"></tpl>
58527 <tpl name="named_template"></tpl> (experimental)
58529 <tpl for="."></tpl> - just iterate the property..
58530 <tpl for=".."></tpl> - iterates with the parent (probably the template)
58534 Roo.XTemplate = function()
58536 Roo.XTemplate.superclass.constructor.apply(this, arguments);
58543 Roo.extend(Roo.XTemplate, Roo.Template, {
58546 * The various sub templates
58551 * basic tag replacing syntax
58554 * // you can fake an object call by doing this
58558 re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
58561 * compile the template
58563 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
58566 compile: function()
58570 s = ['<tpl>', s, '</tpl>'].join('');
58572 var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
58573 nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
58574 ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
58575 execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
58576 namedRe = /^<tpl\b[^>]*?name="(\w+)"/, // named templates..
58581 while(true == !!(m = s.match(re))){
58582 var forMatch = m[0].match(nameRe),
58583 ifMatch = m[0].match(ifRe),
58584 execMatch = m[0].match(execRe),
58585 namedMatch = m[0].match(namedRe),
58590 name = forMatch && forMatch[1] ? forMatch[1] : '';
58593 // if - puts fn into test..
58594 exp = ifMatch && ifMatch[1] ? ifMatch[1] : null;
58596 fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
58601 // exec - calls a function... returns empty if true is returned.
58602 exp = execMatch && execMatch[1] ? execMatch[1] : null;
58604 exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
58612 case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
58613 case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
58614 default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
58617 var uid = namedMatch ? namedMatch[1] : id;
58621 id: namedMatch ? namedMatch[1] : id,
58628 s = s.replace(m[0], '');
58630 s = s.replace(m[0], '{xtpl'+ id + '}');
58635 for(var i = tpls.length-1; i >= 0; --i){
58636 this.compileTpl(tpls[i]);
58637 this.tpls[tpls[i].id] = tpls[i];
58639 this.master = tpls[tpls.length-1];
58643 * same as applyTemplate, except it's done to one of the subTemplates
58644 * when using named templates, you can do:
58646 * var str = pl.applySubTemplate('your-name', values);
58649 * @param {Number} id of the template
58650 * @param {Object} values to apply to template
58651 * @param {Object} parent (normaly the instance of this object)
58653 applySubTemplate : function(id, values, parent)
58657 var t = this.tpls[id];
58661 if(t.test && !t.test.call(this, values, parent)){
58665 Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");
58666 Roo.log(e.toString());
58672 if(t.exec && t.exec.call(this, values, parent)){
58676 Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");
58677 Roo.log(e.toString());
58682 var vs = t.target ? t.target.call(this, values, parent) : values;
58683 parent = t.target ? values : parent;
58684 if(t.target && vs instanceof Array){
58686 for(var i = 0, len = vs.length; i < len; i++){
58687 buf[buf.length] = t.compiled.call(this, vs[i], parent);
58689 return buf.join('');
58691 return t.compiled.call(this, vs, parent);
58693 Roo.log("Xtemplate.applySubTemplate : Exception thrown");
58694 Roo.log(e.toString());
58695 Roo.log(t.compiled);
58700 compileTpl : function(tpl)
58702 var fm = Roo.util.Format;
58703 var useF = this.disableFormats !== true;
58704 var sep = Roo.isGecko ? "+" : ",";
58705 var undef = function(str) {
58706 Roo.log("Property not found :" + str);
58710 var fn = function(m, name, format, args)
58712 //Roo.log(arguments);
58713 args = args ? args.replace(/\\'/g,"'") : args;
58714 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
58715 if (typeof(format) == 'undefined') {
58716 format= 'htmlEncode';
58718 if (format == 'raw' ) {
58722 if(name.substr(0, 4) == 'xtpl'){
58723 return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent)'+sep+"'";
58726 // build an array of options to determine if value is undefined..
58728 // basically get 'xxxx.yyyy' then do
58729 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
58730 // (function () { Roo.log("Property not found"); return ''; })() :
58735 Roo.each(name.split('.'), function(st) {
58736 lookfor += (lookfor.length ? '.': '') + st;
58737 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
58740 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
58743 if(format && useF){
58745 args = args ? ',' + args : "";
58747 if(format.substr(0, 5) != "this."){
58748 format = "fm." + format + '(';
58750 format = 'this.call("'+ format.substr(5) + '", ';
58754 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
58758 // called with xxyx.yuu:(test,test)
58760 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
58762 // raw.. - :raw modifier..
58763 return "'"+ sep + udef_st + name + ")"+sep+"'";
58767 // branched to use + in gecko and [].join() in others
58769 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
58770 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
58773 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
58774 body.push(tpl.body.replace(/(\r\n|\n)/g,
58775 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
58776 body.push("'].join('');};};");
58777 body = body.join('');
58780 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
58782 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
58788 applyTemplate : function(values){
58789 return this.master.compiled.call(this, values, {});
58790 //var s = this.subs;
58793 apply : function(){
58794 return this.applyTemplate.apply(this, arguments);
58799 Roo.XTemplate.from = function(el){
58800 el = Roo.getDom(el);
58801 return new Roo.XTemplate(el.value || el.innerHTML);