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">
14 * @class Roo.data.SortTypes
16 * Defines the default sorting (casting?) comparison functions used when sorting data.
18 Roo.data.SortTypes = {
20 * Default sort that does nothing
21 * @param {Mixed} s The value being converted
22 * @return {Mixed} The comparison value
29 * The regular expression used to strip tags
33 stripTagsRE : /<\/?[^>]+>/gi,
36 * Strips all HTML tags to sort on text only
37 * @param {Mixed} s The value being converted
38 * @return {String} The comparison value
41 return String(s).replace(this.stripTagsRE, "");
45 * Strips all HTML tags to sort on text only - Case insensitive
46 * @param {Mixed} s The value being converted
47 * @return {String} The comparison value
49 asUCText : function(s){
50 return String(s).toUpperCase().replace(this.stripTagsRE, "");
54 * Case insensitive string
55 * @param {Mixed} s The value being converted
56 * @return {String} The comparison value
58 asUCString : function(s) {
59 return String(s).toUpperCase();
64 * @param {Mixed} s The value being converted
65 * @return {Number} The comparison value
67 asDate : function(s) {
71 if(s instanceof Date){
74 return Date.parse(String(s));
79 * @param {Mixed} s The value being converted
80 * @return {Float} The comparison value
82 asFloat : function(s) {
83 var val = parseFloat(String(s).replace(/,/g, ""));
92 * @param {Mixed} s The value being converted
93 * @return {Number} The comparison value
96 var val = parseInt(String(s).replace(/,/g, ""));
104 * Ext JS Library 1.1.1
105 * Copyright(c) 2006-2007, Ext JS, LLC.
107 * Originally Released Under LGPL - original licence link has changed is not relivant.
110 * <script type="text/javascript">
114 * @class Roo.data.Record
115 * Instances of this class encapsulate both record <em>definition</em> information, and record
116 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
117 * to access Records cached in an {@link Roo.data.Store} object.<br>
119 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
120 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
123 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
125 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
126 * {@link #create}. The parameters are the same.
127 * @param {Array} data An associative Array of data values keyed by the field name.
128 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
129 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
130 * not specified an integer id is generated.
132 Roo.data.Record = function(data, id){
133 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
138 * Generate a constructor for a specific record layout.
139 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
140 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
141 * Each field definition object may contain the following properties: <ul>
142 * <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,
143 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
144 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
145 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
146 * is being used, then this is a string containing the javascript expression to reference the data relative to
147 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
148 * to the data item relative to the record element. If the mapping expression is the same as the field name,
149 * this may be omitted.</p></li>
150 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
151 * <ul><li>auto (Default, implies no conversion)</li>
156 * <li>date</li></ul></p></li>
157 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
158 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
159 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
160 * by the Reader into an object that will be stored in the Record. It is passed the
161 * following parameters:<ul>
162 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
164 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
166 * <br>usage:<br><pre><code>
167 var TopicRecord = Roo.data.Record.create(
168 {name: 'title', mapping: 'topic_title'},
169 {name: 'author', mapping: 'username'},
170 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
171 {name: 'lastPost', mapping: 'post_time', type: 'date'},
172 {name: 'lastPoster', mapping: 'user2'},
173 {name: 'excerpt', mapping: 'post_text'}
176 var myNewRecord = new TopicRecord({
177 title: 'Do my job please',
180 lastPost: new Date(),
181 lastPoster: 'Animal',
182 excerpt: 'No way dude!'
184 myStore.add(myNewRecord);
189 Roo.data.Record.create = function(o){
191 f.superclass.constructor.apply(this, arguments);
193 Roo.extend(f, Roo.data.Record);
195 p.fields = new Roo.util.MixedCollection(false, function(field){
198 for(var i = 0, len = o.length; i < len; i++){
199 p.fields.add(new Roo.data.Field(o[i]));
201 f.getField = function(name){
202 return p.fields.get(name);
207 Roo.data.Record.AUTO_ID = 1000;
208 Roo.data.Record.EDIT = 'edit';
209 Roo.data.Record.REJECT = 'reject';
210 Roo.data.Record.COMMIT = 'commit';
212 Roo.data.Record.prototype = {
214 * Readonly flag - true if this record has been modified.
223 join : function(store){
228 * Set the named field to the specified value.
229 * @param {String} name The name of the field to set.
230 * @param {Object} value The value to set the field to.
232 set : function(name, value){
233 if(this.data[name] == value){
240 if(typeof this.modified[name] == 'undefined'){
241 this.modified[name] = this.data[name];
243 this.data[name] = value;
244 if(!this.editing && this.store){
245 this.store.afterEdit(this);
250 * Get the value of the named field.
251 * @param {String} name The name of the field to get the value of.
252 * @return {Object} The value of the field.
254 get : function(name){
255 return this.data[name];
259 beginEdit : function(){
265 cancelEdit : function(){
266 this.editing = false;
267 delete this.modified;
271 endEdit : function(){
272 this.editing = false;
273 if(this.dirty && this.store){
274 this.store.afterEdit(this);
279 * Usually called by the {@link Roo.data.Store} which owns the Record.
280 * Rejects all changes made to the Record since either creation, or the last commit operation.
281 * Modified fields are reverted to their original values.
283 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
284 * of reject operations.
287 var m = this.modified;
289 if(typeof m[n] != "function"){
294 delete this.modified;
295 this.editing = false;
297 this.store.afterReject(this);
302 * Usually called by the {@link Roo.data.Store} which owns the Record.
303 * Commits all changes made to the Record since either creation, or the last commit operation.
305 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
306 * of commit operations.
310 delete this.modified;
311 this.editing = false;
313 this.store.afterCommit(this);
318 hasError : function(){
319 return this.error != null;
323 clearError : function(){
328 * Creates a copy of this record.
329 * @param {String} id (optional) A new record id if you don't want to use this record's id
332 copy : function(newId) {
333 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
337 * Ext JS Library 1.1.1
338 * Copyright(c) 2006-2007, Ext JS, LLC.
340 * Originally Released Under LGPL - original licence link has changed is not relivant.
343 * <script type="text/javascript">
349 * @class Roo.data.Store
350 * @extends Roo.util.Observable
351 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
352 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
354 * 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
355 * has no knowledge of the format of the data returned by the Proxy.<br>
357 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
358 * instances from the data object. These records are cached and made available through accessor functions.
360 * Creates a new Store.
361 * @param {Object} config A config object containing the objects needed for the Store to access data,
362 * and read the data into Records.
364 Roo.data.Store = function(config){
365 this.data = new Roo.util.MixedCollection(false);
366 this.data.getKey = function(o){
369 this.baseParams = {};
376 "multisort" : "_multisort"
379 if(config && config.data){
380 this.inlineData = config.data;
384 Roo.apply(this, config);
386 if(this.reader){ // reader passed
387 this.reader = Roo.factory(this.reader, Roo.data);
388 this.reader.xmodule = this.xmodule || false;
389 if(!this.recordType){
390 this.recordType = this.reader.recordType;
392 if(this.reader.onMetaChange){
393 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
398 this.fields = this.recordType.prototype.fields;
405 * Fires when the data cache has changed, and a widget which is using this Store
406 * as a Record cache should refresh its view.
407 * @param {Store} this
412 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
413 * @param {Store} this
414 * @param {Object} meta The JSON metadata
419 * Fires when Records have been added to the Store
420 * @param {Store} this
421 * @param {Roo.data.Record[]} records The array of Records added
422 * @param {Number} index The index at which the record(s) were added
427 * Fires when a Record has been removed from the Store
428 * @param {Store} this
429 * @param {Roo.data.Record} record The Record that was removed
430 * @param {Number} index The index at which the record was removed
435 * Fires when a Record has been updated
436 * @param {Store} this
437 * @param {Roo.data.Record} record The Record that was updated
438 * @param {String} operation The update operation being performed. Value may be one of:
441 Roo.data.Record.REJECT
442 Roo.data.Record.COMMIT
448 * Fires when the data cache has been cleared.
449 * @param {Store} this
454 * Fires before a request is made for a new data object. If the beforeload handler returns false
455 * the load action will be canceled.
456 * @param {Store} this
457 * @param {Object} options The loading options that were specified (see {@link #load} for details)
461 * @event beforeloadadd
462 * Fires after a new set of Records has been loaded.
463 * @param {Store} this
464 * @param {Roo.data.Record[]} records The Records that were loaded
465 * @param {Object} options The loading options that were specified (see {@link #load} for details)
467 beforeloadadd : true,
470 * Fires after a new set of Records has been loaded, before they are added to the store.
471 * @param {Store} this
472 * @param {Roo.data.Record[]} records The Records that were loaded
473 * @param {Object} options The loading options that were specified (see {@link #load} for details)
474 * @params {Object} return from reader
478 * @event loadexception
479 * Fires if an exception occurs in the Proxy during loading.
480 * Called with the signature of the Proxy's "loadexception" event.
481 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
484 * @param {Object} return from JsonData.reader() - success, totalRecords, records
485 * @param {Object} load options
486 * @param {Object} jsonData from your request (normally this contains the Exception)
492 this.proxy = Roo.factory(this.proxy, Roo.data);
493 this.proxy.xmodule = this.xmodule || false;
494 this.relayEvents(this.proxy, ["loadexception"]);
496 this.sortToggle = {};
497 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
499 Roo.data.Store.superclass.constructor.call(this);
502 this.loadData(this.inlineData);
503 delete this.inlineData;
507 Roo.extend(Roo.data.Store, Roo.util.Observable, {
509 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
510 * without a remote query - used by combo/forms at present.
514 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
517 * @cfg {Array} data Inline data to be loaded when the store is initialized.
520 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
521 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
524 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
525 * on any HTTP request
528 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
531 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
535 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
536 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
541 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
542 * loaded or when a record is removed. (defaults to false).
544 pruneModifiedRecords : false,
550 * Add Records to the Store and fires the add event.
551 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
553 add : function(records){
554 records = [].concat(records);
555 for(var i = 0, len = records.length; i < len; i++){
556 records[i].join(this);
558 var index = this.data.length;
559 this.data.addAll(records);
560 this.fireEvent("add", this, records, index);
564 * Remove a Record from the Store and fires the remove event.
565 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
567 remove : function(record){
568 var index = this.data.indexOf(record);
569 this.data.removeAt(index);
571 if(this.pruneModifiedRecords){
572 this.modified.remove(record);
574 this.fireEvent("remove", this, record, index);
578 * Remove all Records from the Store and fires the clear event.
580 removeAll : function(){
582 if(this.pruneModifiedRecords){
585 this.fireEvent("clear", this);
589 * Inserts Records to the Store at the given index and fires the add event.
590 * @param {Number} index The start index at which to insert the passed Records.
591 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
593 insert : function(index, records){
594 records = [].concat(records);
595 for(var i = 0, len = records.length; i < len; i++){
596 this.data.insert(index, records[i]);
597 records[i].join(this);
599 this.fireEvent("add", this, records, index);
603 * Get the index within the cache of the passed Record.
604 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
605 * @return {Number} The index of the passed Record. Returns -1 if not found.
607 indexOf : function(record){
608 return this.data.indexOf(record);
612 * Get the index within the cache of the Record with the passed id.
613 * @param {String} id The id of the Record to find.
614 * @return {Number} The index of the Record. Returns -1 if not found.
616 indexOfId : function(id){
617 return this.data.indexOfKey(id);
621 * Get the Record with the specified id.
622 * @param {String} id The id of the Record to find.
623 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
625 getById : function(id){
626 return this.data.key(id);
630 * Get the Record at the specified index.
631 * @param {Number} index The index of the Record to find.
632 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
634 getAt : function(index){
635 return this.data.itemAt(index);
639 * Returns a range of Records between specified indices.
640 * @param {Number} startIndex (optional) The starting index (defaults to 0)
641 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
642 * @return {Roo.data.Record[]} An array of Records
644 getRange : function(start, end){
645 return this.data.getRange(start, end);
649 storeOptions : function(o){
650 o = Roo.apply({}, o);
653 this.lastOptions = o;
657 * Loads the Record cache from the configured Proxy using the configured Reader.
659 * If using remote paging, then the first load call must specify the <em>start</em>
660 * and <em>limit</em> properties in the options.params property to establish the initial
661 * position within the dataset, and the number of Records to cache on each read from the Proxy.
663 * <strong>It is important to note that for remote data sources, loading is asynchronous,
664 * and this call will return before the new data has been loaded. Perform any post-processing
665 * in a callback function, or in a "load" event handler.</strong>
667 * @param {Object} options An object containing properties which control loading options:<ul>
668 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
669 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
670 * passed the following arguments:<ul>
671 * <li>r : Roo.data.Record[]</li>
672 * <li>options: Options object from the load call</li>
673 * <li>success: Boolean success indicator</li></ul></li>
674 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
675 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
678 load : function(options){
679 options = options || {};
680 if(this.fireEvent("beforeload", this, options) !== false){
681 this.storeOptions(options);
682 var p = Roo.apply(options.params || {}, this.baseParams);
683 // if meta was not loaded from remote source.. try requesting it.
684 if (!this.reader.metaFromRemote) {
687 if(this.sortInfo && this.remoteSort){
688 var pn = this.paramNames;
689 p[pn["sort"]] = this.sortInfo.field;
690 p[pn["dir"]] = this.sortInfo.direction;
692 if (this.multiSort) {
693 var pn = this.paramNames;
694 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
697 this.proxy.load(p, this.reader, this.loadRecords, this, options);
702 * Reloads the Record cache from the configured Proxy using the configured Reader and
703 * the options from the last load operation performed.
704 * @param {Object} options (optional) An object containing properties which may override the options
705 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
706 * the most recently used options are reused).
708 reload : function(options){
709 this.load(Roo.applyIf(options||{}, this.lastOptions));
713 // Called as a callback by the Reader during a load operation.
714 loadRecords : function(o, options, success){
715 if(!o || success === false){
716 if(success !== false){
717 this.fireEvent("load", this, [], options, o);
719 if(options.callback){
720 options.callback.call(options.scope || this, [], options, false);
724 // if data returned failure - throw an exception.
725 if (o.success === false) {
726 // show a message if no listener is registered.
727 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
728 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
730 // loadmask wil be hooked into this..
731 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
734 var r = o.records, t = o.totalRecords || r.length;
736 this.fireEvent("beforeloadadd", this, r, options, o);
738 if(!options || options.add !== true){
739 if(this.pruneModifiedRecords){
742 for(var i = 0, len = r.length; i < len; i++){
746 this.data = this.snapshot;
747 delete this.snapshot;
751 this.totalLength = t;
753 this.fireEvent("datachanged", this);
755 this.totalLength = Math.max(t, this.data.length+r.length);
759 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
761 var e = new Roo.data.Record({});
763 e.set(this.parent.displayField, this.parent.emptyTitle);
764 e.set(this.parent.valueField, '');
769 this.fireEvent("load", this, r, options, o);
770 if(options.callback){
771 options.callback.call(options.scope || this, r, options, true);
777 * Loads data from a passed data block. A Reader which understands the format of the data
778 * must have been configured in the constructor.
779 * @param {Object} data The data block from which to read the Records. The format of the data expected
780 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
781 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
783 loadData : function(o, append){
784 var r = this.reader.readRecords(o);
785 this.loadRecords(r, {add: append}, true);
789 * Gets the number of cached records.
791 * <em>If using paging, this may not be the total size of the dataset. If the data object
792 * used by the Reader contains the dataset size, then the getTotalCount() function returns
793 * the data set size</em>
795 getCount : function(){
796 return this.data.length || 0;
800 * Gets the total number of records in the dataset as returned by the server.
802 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
803 * the dataset size</em>
805 getTotalCount : function(){
806 return this.totalLength || 0;
810 * Returns the sort state of the Store as an object with two properties:
812 field {String} The name of the field by which the Records are sorted
813 direction {String} The sort order, "ASC" or "DESC"
816 getSortState : function(){
817 return this.sortInfo;
821 applySort : function(){
822 if(this.sortInfo && !this.remoteSort){
823 var s = this.sortInfo, f = s.field;
824 var st = this.fields.get(f).sortType;
825 var fn = function(r1, r2){
826 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
827 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
829 this.data.sort(s.direction, fn);
830 if(this.snapshot && this.snapshot != this.data){
831 this.snapshot.sort(s.direction, fn);
837 * Sets the default sort column and order to be used by the next load operation.
838 * @param {String} fieldName The name of the field to sort by.
839 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
841 setDefaultSort : function(field, dir){
842 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
847 * If remote sorting is used, the sort is performed on the server, and the cache is
848 * reloaded. If local sorting is used, the cache is sorted internally.
849 * @param {String} fieldName The name of the field to sort by.
850 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
852 sort : function(fieldName, dir){
853 var f = this.fields.get(fieldName);
855 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
857 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
858 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
863 this.sortToggle[f.name] = dir;
864 this.sortInfo = {field: f.name, direction: dir};
865 if(!this.remoteSort){
867 this.fireEvent("datachanged", this);
869 this.load(this.lastOptions);
874 * Calls the specified function for each of the Records in the cache.
875 * @param {Function} fn The function to call. The Record is passed as the first parameter.
876 * Returning <em>false</em> aborts and exits the iteration.
877 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
879 each : function(fn, scope){
880 this.data.each(fn, scope);
884 * Gets all records modified since the last commit. Modified records are persisted across load operations
885 * (e.g., during paging).
886 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
888 getModifiedRecords : function(){
889 return this.modified;
893 createFilterFn : function(property, value, anyMatch){
894 if(!value.exec){ // not a regex
895 value = String(value);
896 if(value.length == 0){
899 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
902 return value.test(r.data[property]);
907 * Sums the value of <i>property</i> for each record between start and end and returns the result.
908 * @param {String} property A field on your records
909 * @param {Number} start The record index to start at (defaults to 0)
910 * @param {Number} end The last record index to include (defaults to length - 1)
911 * @return {Number} The sum
913 sum : function(property, start, end){
914 var rs = this.data.items, v = 0;
916 end = (end || end === 0) ? end : rs.length-1;
918 for(var i = start; i <= end; i++){
919 v += (rs[i].data[property] || 0);
925 * Filter the records by a specified property.
926 * @param {String} field A field on your records
927 * @param {String/RegExp} value Either a string that the field
928 * should start with or a RegExp to test against the field
929 * @param {Boolean} anyMatch True to match any part not just the beginning
931 filter : function(property, value, anyMatch){
932 var fn = this.createFilterFn(property, value, anyMatch);
933 return fn ? this.filterBy(fn) : this.clearFilter();
937 * Filter by a function. The specified function will be called with each
938 * record in this data source. If the function returns true the record is included,
939 * otherwise it is filtered.
940 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
941 * @param {Object} scope (optional) The scope of the function (defaults to this)
943 filterBy : function(fn, scope){
944 this.snapshot = this.snapshot || this.data;
945 this.data = this.queryBy(fn, scope||this);
946 this.fireEvent("datachanged", this);
950 * Query the records by a specified property.
951 * @param {String} field A field on your records
952 * @param {String/RegExp} value Either a string that the field
953 * should start with or a RegExp to test against the field
954 * @param {Boolean} anyMatch True to match any part not just the beginning
955 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
957 query : function(property, value, anyMatch){
958 var fn = this.createFilterFn(property, value, anyMatch);
959 return fn ? this.queryBy(fn) : this.data.clone();
963 * Query by a function. The specified function will be called with each
964 * record in this data source. If the function returns true the record is included
966 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
967 * @param {Object} scope (optional) The scope of the function (defaults to this)
968 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
970 queryBy : function(fn, scope){
971 var data = this.snapshot || this.data;
972 return data.filterBy(fn, scope||this);
976 * Collects unique values for a particular dataIndex from this store.
977 * @param {String} dataIndex The property to collect
978 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
979 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
980 * @return {Array} An array of the unique values
982 collect : function(dataIndex, allowNull, bypassFilter){
983 var d = (bypassFilter === true && this.snapshot) ?
984 this.snapshot.items : this.data.items;
985 var v, sv, r = [], l = {};
986 for(var i = 0, len = d.length; i < len; i++){
987 v = d[i].data[dataIndex];
989 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
998 * Revert to a view of the Record cache with no filtering applied.
999 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
1001 clearFilter : function(suppressEvent){
1002 if(this.snapshot && this.snapshot != this.data){
1003 this.data = this.snapshot;
1004 delete this.snapshot;
1005 if(suppressEvent !== true){
1006 this.fireEvent("datachanged", this);
1012 afterEdit : function(record){
1013 if(this.modified.indexOf(record) == -1){
1014 this.modified.push(record);
1016 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
1020 afterReject : function(record){
1021 this.modified.remove(record);
1022 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
1026 afterCommit : function(record){
1027 this.modified.remove(record);
1028 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
1032 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
1033 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
1035 commitChanges : function(){
1036 var m = this.modified.slice(0);
1038 for(var i = 0, len = m.length; i < len; i++){
1044 * Cancel outstanding changes on all changed records.
1046 rejectChanges : function(){
1047 var m = this.modified.slice(0);
1049 for(var i = 0, len = m.length; i < len; i++){
1054 onMetaChange : function(meta, rtype, o){
1055 this.recordType = rtype;
1056 this.fields = rtype.prototype.fields;
1057 delete this.snapshot;
1058 this.sortInfo = meta.sortInfo || this.sortInfo;
1060 this.fireEvent('metachange', this, this.reader.meta);
1063 moveIndex : function(data, type)
1065 var index = this.indexOf(data);
1067 var newIndex = index + type;
1071 this.insert(newIndex, data);
1076 * Ext JS Library 1.1.1
1077 * Copyright(c) 2006-2007, Ext JS, LLC.
1079 * Originally Released Under LGPL - original licence link has changed is not relivant.
1082 * <script type="text/javascript">
1086 * @class Roo.data.SimpleStore
1087 * @extends Roo.data.Store
1088 * Small helper class to make creating Stores from Array data easier.
1089 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
1090 * @cfg {Array} fields An array of field definition objects, or field name strings.
1091 * @cfg {Object} an existing reader (eg. copied from another store)
1092 * @cfg {Array} data The multi-dimensional array of data
1094 * @param {Object} config
1096 Roo.data.SimpleStore = function(config)
1098 Roo.data.SimpleStore.superclass.constructor.call(this, {
1100 reader: typeof(config.reader) != 'undefined' ? config.reader : new Roo.data.ArrayReader({
1103 Roo.data.Record.create(config.fields)
1105 proxy : new Roo.data.MemoryProxy(config.data)
1109 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
1111 * Ext JS Library 1.1.1
1112 * Copyright(c) 2006-2007, Ext JS, LLC.
1114 * Originally Released Under LGPL - original licence link has changed is not relivant.
1117 * <script type="text/javascript">
1122 * @extends Roo.data.Store
1123 * @class Roo.data.JsonStore
1124 * Small helper class to make creating Stores for JSON data easier. <br/>
1126 var store = new Roo.data.JsonStore({
1127 url: 'get-images.php',
1129 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
1132 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
1133 * JsonReader and HttpProxy (unless inline data is provided).</b>
1134 * @cfg {Array} fields An array of field definition objects, or field name strings.
1136 * @param {Object} config
1138 Roo.data.JsonStore = function(c){
1139 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
1140 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
1141 reader: new Roo.data.JsonReader(c, c.fields)
1144 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
1146 * Ext JS Library 1.1.1
1147 * Copyright(c) 2006-2007, Ext JS, LLC.
1149 * Originally Released Under LGPL - original licence link has changed is not relivant.
1152 * <script type="text/javascript">
1156 Roo.data.Field = function(config){
1157 if(typeof config == "string"){
1158 config = {name: config};
1160 Roo.apply(this, config);
1166 var st = Roo.data.SortTypes;
1167 // named sortTypes are supported, here we look them up
1168 if(typeof this.sortType == "string"){
1169 this.sortType = st[this.sortType];
1172 // set default sortType for strings and dates
1176 this.sortType = st.asUCString;
1179 this.sortType = st.asDate;
1182 this.sortType = st.none;
1187 var stripRe = /[\$,%]/g;
1189 // prebuilt conversion function for this field, instead of
1190 // switching every time we're reading a value
1192 var cv, dateFormat = this.dateFormat;
1197 cv = function(v){ return v; };
1200 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
1204 return v !== undefined && v !== null && v !== '' ?
1205 parseInt(String(v).replace(stripRe, ""), 10) : '';
1210 return v !== undefined && v !== null && v !== '' ?
1211 parseFloat(String(v).replace(stripRe, ""), 10) : '';
1216 cv = function(v){ return v === true || v === "true" || v == 1; };
1223 if(v instanceof Date){
1227 if(dateFormat == "timestamp"){
1228 return new Date(v*1000);
1230 return Date.parseDate(v, dateFormat);
1232 var parsed = Date.parse(v);
1233 return parsed ? new Date(parsed) : null;
1242 Roo.data.Field.prototype = {
1250 * Ext JS Library 1.1.1
1251 * Copyright(c) 2006-2007, Ext JS, LLC.
1253 * Originally Released Under LGPL - original licence link has changed is not relivant.
1256 * <script type="text/javascript">
1259 // Base class for reading structured data from a data source. This class is intended to be
1260 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
1263 * @class Roo.data.DataReader
1264 * Base class for reading structured data from a data source. This class is intended to be
1265 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
1268 Roo.data.DataReader = function(meta, recordType){
1272 this.recordType = recordType instanceof Array ?
1273 Roo.data.Record.create(recordType) : recordType;
1276 Roo.data.DataReader.prototype = {
1279 readerType : 'Data',
1281 * Create an empty record
1282 * @param {Object} data (optional) - overlay some values
1283 * @return {Roo.data.Record} record created.
1285 newRow : function(d) {
1287 this.recordType.prototype.fields.each(function(c) {
1289 case 'int' : da[c.name] = 0; break;
1290 case 'date' : da[c.name] = new Date(); break;
1291 case 'float' : da[c.name] = 0.0; break;
1292 case 'boolean' : da[c.name] = false; break;
1293 default : da[c.name] = ""; break;
1297 return new this.recordType(Roo.apply(da, d));
1303 * Ext JS Library 1.1.1
1304 * Copyright(c) 2006-2007, Ext JS, LLC.
1306 * Originally Released Under LGPL - original licence link has changed is not relivant.
1309 * <script type="text/javascript">
1313 * @class Roo.data.DataProxy
1314 * @extends Roo.data.Observable
1315 * This class is an abstract base class for implementations which provide retrieval of
1316 * unformatted data objects.<br>
1318 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
1319 * (of the appropriate type which knows how to parse the data object) to provide a block of
1320 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
1322 * Custom implementations must implement the load method as described in
1323 * {@link Roo.data.HttpProxy#load}.
1325 Roo.data.DataProxy = function(){
1329 * Fires before a network request is made to retrieve a data object.
1330 * @param {Object} This DataProxy object.
1331 * @param {Object} params The params parameter to the load function.
1336 * Fires before the load method's callback is called.
1337 * @param {Object} This DataProxy object.
1338 * @param {Object} o The data object.
1339 * @param {Object} arg The callback argument object passed to the load function.
1343 * @event loadexception
1344 * Fires if an Exception occurs during data retrieval.
1345 * @param {Object} This DataProxy object.
1346 * @param {Object} o The data object.
1347 * @param {Object} arg The callback argument object passed to the load function.
1348 * @param {Object} e The Exception.
1350 loadexception : true
1352 Roo.data.DataProxy.superclass.constructor.call(this);
1355 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
1358 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
1362 * Ext JS Library 1.1.1
1363 * Copyright(c) 2006-2007, Ext JS, LLC.
1365 * Originally Released Under LGPL - original licence link has changed is not relivant.
1368 * <script type="text/javascript">
1371 * @class Roo.data.MemoryProxy
1372 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
1373 * to the Reader when its load method is called.
1375 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
1377 Roo.data.MemoryProxy = function(data){
1381 Roo.data.MemoryProxy.superclass.constructor.call(this);
1385 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
1388 * Load data from the requested source (in this case an in-memory
1389 * data object passed to the constructor), read the data object into
1390 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
1391 * process that block using the passed callback.
1392 * @param {Object} params This parameter is not used by the MemoryProxy class.
1393 * @param {Roo.data.DataReader} reader The Reader object which converts the data
1394 * object into a block of Roo.data.Records.
1395 * @param {Function} callback The function into which to pass the block of Roo.data.records.
1396 * The function must be passed <ul>
1397 * <li>The Record block object</li>
1398 * <li>The "arg" argument from the load function</li>
1399 * <li>A boolean success indicator</li>
1401 * @param {Object} scope The scope in which to call the callback
1402 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
1404 load : function(params, reader, callback, scope, arg){
1405 params = params || {};
1408 result = reader.readRecords(params.data ? params.data :this.data);
1410 this.fireEvent("loadexception", this, arg, null, e);
1411 callback.call(scope, null, arg, false);
1414 callback.call(scope, result, arg, true);
1418 update : function(params, records){
1423 * Ext JS Library 1.1.1
1424 * Copyright(c) 2006-2007, Ext JS, LLC.
1426 * Originally Released Under LGPL - original licence link has changed is not relivant.
1429 * <script type="text/javascript">
1432 * @class Roo.data.HttpProxy
1433 * @extends Roo.data.DataProxy
1434 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
1435 * configured to reference a certain URL.<br><br>
1437 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
1438 * from which the running page was served.<br><br>
1440 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
1442 * Be aware that to enable the browser to parse an XML document, the server must set
1443 * the Content-Type header in the HTTP response to "text/xml".
1445 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
1446 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
1447 * will be used to make the request.
1449 Roo.data.HttpProxy = function(conn){
1450 Roo.data.HttpProxy.superclass.constructor.call(this);
1451 // is conn a conn config or a real conn?
1453 this.useAjax = !conn || !conn.events;
1457 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
1458 // thse are take from connection...
1461 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
1464 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
1465 * extra parameters to each request made by this object. (defaults to undefined)
1468 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
1469 * to each request made by this object. (defaults to undefined)
1472 * @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)
1475 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
1478 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
1484 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
1488 * Return the {@link Roo.data.Connection} object being used by this Proxy.
1489 * @return {Connection} The Connection object. This object may be used to subscribe to events on
1490 * a finer-grained basis than the DataProxy events.
1492 getConnection : function(){
1493 return this.useAjax ? Roo.Ajax : this.conn;
1497 * Load data from the configured {@link Roo.data.Connection}, read the data object into
1498 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
1499 * process that block using the passed callback.
1500 * @param {Object} params An object containing properties which are to be used as HTTP parameters
1501 * for the request to the remote server.
1502 * @param {Roo.data.DataReader} reader The Reader object which converts the data
1503 * object into a block of Roo.data.Records.
1504 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
1505 * The function must be passed <ul>
1506 * <li>The Record block object</li>
1507 * <li>The "arg" argument from the load function</li>
1508 * <li>A boolean success indicator</li>
1510 * @param {Object} scope The scope in which to call the callback
1511 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
1513 load : function(params, reader, callback, scope, arg){
1514 if(this.fireEvent("beforeload", this, params) !== false){
1516 params : params || {},
1518 callback : callback,
1523 callback : this.loadResponse,
1527 Roo.applyIf(o, this.conn);
1528 if(this.activeRequest){
1529 Roo.Ajax.abort(this.activeRequest);
1531 this.activeRequest = Roo.Ajax.request(o);
1533 this.conn.request(o);
1536 callback.call(scope||this, null, arg, false);
1541 loadResponse : function(o, success, response){
1542 delete this.activeRequest;
1544 this.fireEvent("loadexception", this, o, response);
1545 o.request.callback.call(o.request.scope, null, o.request.arg, false);
1550 result = o.reader.read(response);
1552 this.fireEvent("loadexception", this, o, response, e);
1553 o.request.callback.call(o.request.scope, null, o.request.arg, false);
1557 this.fireEvent("load", this, o, o.request.arg);
1558 o.request.callback.call(o.request.scope, result, o.request.arg, true);
1562 update : function(dataSet){
1567 updateResponse : function(dataSet){
1572 * Ext JS Library 1.1.1
1573 * Copyright(c) 2006-2007, Ext JS, LLC.
1575 * Originally Released Under LGPL - original licence link has changed is not relivant.
1578 * <script type="text/javascript">
1582 * @class Roo.data.ScriptTagProxy
1583 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
1584 * other than the originating domain of the running page.<br><br>
1586 * <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
1587 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
1589 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
1590 * source code that is used as the source inside a <script> tag.<br><br>
1592 * In order for the browser to process the returned data, the server must wrap the data object
1593 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
1594 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
1595 * depending on whether the callback name was passed:
1598 boolean scriptTag = false;
1599 String cb = request.getParameter("callback");
1602 response.setContentType("text/javascript");
1604 response.setContentType("application/x-json");
1606 Writer out = response.getWriter();
1608 out.write(cb + "(");
1610 out.print(dataBlock.toJsonString());
1617 * @param {Object} config A configuration object.
1619 Roo.data.ScriptTagProxy = function(config){
1620 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
1621 Roo.apply(this, config);
1622 this.head = document.getElementsByTagName("head")[0];
1625 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
1627 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
1629 * @cfg {String} url The URL from which to request the data object.
1632 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
1636 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
1637 * the server the name of the callback function set up by the load call to process the returned data object.
1638 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
1639 * javascript output which calls this named function passing the data object as its only parameter.
1641 callbackParam : "callback",
1643 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
1644 * name to the request.
1649 * Load data from the configured URL, read the data object into
1650 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
1651 * process that block using the passed callback.
1652 * @param {Object} params An object containing properties which are to be used as HTTP parameters
1653 * for the request to the remote server.
1654 * @param {Roo.data.DataReader} reader The Reader object which converts the data
1655 * object into a block of Roo.data.Records.
1656 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
1657 * The function must be passed <ul>
1658 * <li>The Record block object</li>
1659 * <li>The "arg" argument from the load function</li>
1660 * <li>A boolean success indicator</li>
1662 * @param {Object} scope The scope in which to call the callback
1663 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
1665 load : function(params, reader, callback, scope, arg){
1666 if(this.fireEvent("beforeload", this, params) !== false){
1668 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
1671 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
1673 url += "&_dc=" + (new Date().getTime());
1675 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
1678 cb : "stcCallback"+transId,
1679 scriptId : "stcScript"+transId,
1683 callback : callback,
1689 window[trans.cb] = function(o){
1690 conn.handleResponse(o, trans);
1693 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
1695 if(this.autoAbort !== false){
1699 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
1701 var script = document.createElement("script");
1702 script.setAttribute("src", url);
1703 script.setAttribute("type", "text/javascript");
1704 script.setAttribute("id", trans.scriptId);
1705 this.head.appendChild(script);
1709 callback.call(scope||this, null, arg, false);
1714 isLoading : function(){
1715 return this.trans ? true : false;
1719 * Abort the current server request.
1722 if(this.isLoading()){
1723 this.destroyTrans(this.trans);
1728 destroyTrans : function(trans, isLoaded){
1729 this.head.removeChild(document.getElementById(trans.scriptId));
1730 clearTimeout(trans.timeoutId);
1732 window[trans.cb] = undefined;
1734 delete window[trans.cb];
1737 // if hasn't been loaded, wait for load to remove it to prevent script error
1738 window[trans.cb] = function(){
1739 window[trans.cb] = undefined;
1741 delete window[trans.cb];
1748 handleResponse : function(o, trans){
1750 this.destroyTrans(trans, true);
1753 result = trans.reader.readRecords(o);
1755 this.fireEvent("loadexception", this, o, trans.arg, e);
1756 trans.callback.call(trans.scope||window, null, trans.arg, false);
1759 this.fireEvent("load", this, o, trans.arg);
1760 trans.callback.call(trans.scope||window, result, trans.arg, true);
1764 handleFailure : function(trans){
1766 this.destroyTrans(trans, false);
1767 this.fireEvent("loadexception", this, null, trans.arg);
1768 trans.callback.call(trans.scope||window, null, trans.arg, false);
1772 * Ext JS Library 1.1.1
1773 * Copyright(c) 2006-2007, Ext JS, LLC.
1775 * Originally Released Under LGPL - original licence link has changed is not relivant.
1778 * <script type="text/javascript">
1782 * @class Roo.data.JsonReader
1783 * @extends Roo.data.DataReader
1784 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
1785 * based on mappings in a provided Roo.data.Record constructor.
1787 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
1788 * in the reply previously.
1793 var RecordDef = Roo.data.Record.create([
1794 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
1795 {name: 'occupation'} // This field will use "occupation" as the mapping.
1797 var myReader = new Roo.data.JsonReader({
1798 totalProperty: "results", // The property which contains the total dataset size (optional)
1799 root: "rows", // The property which contains an Array of row objects
1800 id: "id" // The property within each row object that provides an ID for the record (optional)
1804 * This would consume a JSON file like this:
1806 { 'results': 2, 'rows': [
1807 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
1808 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
1811 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
1812 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
1813 * paged from the remote server.
1814 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
1815 * @cfg {String} root name of the property which contains the Array of row objects.
1816 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
1817 * @cfg {Array} fields Array of field definition objects
1819 * Create a new JsonReader
1820 * @param {Object} meta Metadata configuration options
1821 * @param {Object} recordType Either an Array of field definition objects,
1822 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
1824 Roo.data.JsonReader = function(meta, recordType){
1827 // set some defaults:
1829 totalProperty: 'total',
1830 successProperty : 'success',
1835 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
1837 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
1839 readerType : 'Json',
1842 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
1843 * Used by Store query builder to append _requestMeta to params.
1846 metaFromRemote : false,
1848 * This method is only used by a DataProxy which has retrieved data from a remote server.
1849 * @param {Object} response The XHR object which contains the JSON data in its responseText.
1850 * @return {Object} data A data block which is used by an Roo.data.Store object as
1851 * a cache of Roo.data.Records.
1853 read : function(response){
1854 var json = response.responseText;
1856 var o = /* eval:var:o */ eval("("+json+")");
1858 throw {message: "JsonReader.read: Json object not found"};
1864 this.metaFromRemote = true;
1865 this.meta = o.metaData;
1866 this.recordType = Roo.data.Record.create(o.metaData.fields);
1867 this.onMetaChange(this.meta, this.recordType, o);
1869 return this.readRecords(o);
1872 // private function a store will implement
1873 onMetaChange : function(meta, recordType, o){
1880 simpleAccess: function(obj, subsc) {
1887 getJsonAccessor: function(){
1889 return function(expr) {
1891 return(re.test(expr))
1892 ? new Function("obj", "return obj." + expr)
1902 * Create a data block containing Roo.data.Records from an XML document.
1903 * @param {Object} o An object which contains an Array of row objects in the property specified
1904 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
1905 * which contains the total size of the dataset.
1906 * @return {Object} data A data block which is used by an Roo.data.Store object as
1907 * a cache of Roo.data.Records.
1909 readRecords : function(o){
1911 * After any data loads, the raw JSON data is available for further custom processing.
1915 var s = this.meta, Record = this.recordType,
1916 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
1918 // Generate extraction functions for the totalProperty, the root, the id, and for each field
1920 if(s.totalProperty) {
1921 this.getTotal = this.getJsonAccessor(s.totalProperty);
1923 if(s.successProperty) {
1924 this.getSuccess = this.getJsonAccessor(s.successProperty);
1926 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
1928 var g = this.getJsonAccessor(s.id);
1929 this.getId = function(rec) {
1931 return (r === undefined || r === "") ? null : r;
1934 this.getId = function(){return null;};
1937 for(var jj = 0; jj < fl; jj++){
1939 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
1940 this.ef[jj] = this.getJsonAccessor(map);
1944 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
1945 if(s.totalProperty){
1946 var vt = parseInt(this.getTotal(o), 10);
1951 if(s.successProperty){
1952 var vs = this.getSuccess(o);
1953 if(vs === false || vs === 'false'){
1958 for(var i = 0; i < c; i++){
1961 var id = this.getId(n);
1962 for(var j = 0; j < fl; j++){
1964 var v = this.ef[j](n);
1966 Roo.log('missing convert for ' + f.name);
1970 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
1972 var record = new Record(values, id);
1974 records[i] = record;
1980 totalRecords : totalRecords
1985 * Ext JS Library 1.1.1
1986 * Copyright(c) 2006-2007, Ext JS, LLC.
1988 * Originally Released Under LGPL - original licence link has changed is not relivant.
1991 * <script type="text/javascript">
1995 * @class Roo.data.XmlReader
1996 * @extends Roo.data.DataReader
1997 * Data reader class to create an Array of {@link Roo.data.Record} objects from an XML document
1998 * based on mappings in a provided Roo.data.Record constructor.<br><br>
2000 * <em>Note that in order for the browser to parse a returned XML document, the Content-Type
2001 * header in the HTTP response must be set to "text/xml".</em>
2005 var RecordDef = Roo.data.Record.create([
2006 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
2007 {name: 'occupation'} // This field will use "occupation" as the mapping.
2009 var myReader = new Roo.data.XmlReader({
2010 totalRecords: "results", // The element which contains the total dataset size (optional)
2011 record: "row", // The repeated element which contains row information
2012 id: "id" // The element within the row that provides an ID for the record (optional)
2016 * This would consume an XML file like this:
2020 <results>2</results>
2023 <name>Bill</name>
2024 <occupation>Gardener</occupation>
2028 <name>Ben</name>
2029 <occupation>Horticulturalist</occupation>
2033 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
2034 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
2035 * paged from the remote server.
2036 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
2037 * @cfg {String} success The DomQuery path to the success attribute used by forms.
2038 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
2039 * a record identifier value.
2041 * Create a new XmlReader
2042 * @param {Object} meta Metadata configuration options
2043 * @param {Mixed} recordType The definition of the data record type to produce. This can be either a valid
2044 * Record subclass created with {@link Roo.data.Record#create}, or an array of objects with which to call
2045 * Roo.data.Record.create. See the {@link Roo.data.Record} class for more details.
2047 Roo.data.XmlReader = function(meta, recordType){
2049 Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields);
2051 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
2056 * This method is only used by a DataProxy which has retrieved data from a remote server.
2057 * @param {Object} response The XHR object which contains the parsed XML document. The response is expected
2058 * to contain a method called 'responseXML' that returns an XML document object.
2059 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
2060 * a cache of Roo.data.Records.
2062 read : function(response){
2063 var doc = response.responseXML;
2065 throw {message: "XmlReader.read: XML Document not available"};
2067 return this.readRecords(doc);
2071 * Create a data block containing Roo.data.Records from an XML document.
2072 * @param {Object} doc A parsed XML document.
2073 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
2074 * a cache of Roo.data.Records.
2076 readRecords : function(doc){
2078 * After any data loads/reads, the raw XML Document is available for further custom processing.
2082 var root = doc.documentElement || doc;
2083 var q = Roo.DomQuery;
2084 var recordType = this.recordType, fields = recordType.prototype.fields;
2085 var sid = this.meta.id;
2086 var totalRecords = 0, success = true;
2087 if(this.meta.totalRecords){
2088 totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
2091 if(this.meta.success){
2092 var sv = q.selectValue(this.meta.success, root, true);
2093 success = sv !== false && sv !== 'false';
2096 var ns = q.select(this.meta.record, root);
2097 for(var i = 0, len = ns.length; i < len; i++) {
2100 var id = sid ? q.selectValue(sid, n) : undefined;
2101 for(var j = 0, jlen = fields.length; j < jlen; j++){
2102 var f = fields.items[j];
2103 var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
2107 var record = new recordType(values, id);
2109 records[records.length] = record;
2115 totalRecords : totalRecords || records.length
2120 * Ext JS Library 1.1.1
2121 * Copyright(c) 2006-2007, Ext JS, LLC.
2123 * Originally Released Under LGPL - original licence link has changed is not relivant.
2126 * <script type="text/javascript">
2130 * @class Roo.data.ArrayReader
2131 * @extends Roo.data.DataReader
2132 * Data reader class to create an Array of Roo.data.Record objects from an Array.
2133 * Each element of that Array represents a row of data fields. The
2134 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
2135 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
2139 var RecordDef = Roo.data.Record.create([
2140 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
2141 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
2143 var myReader = new Roo.data.ArrayReader({
2144 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
2148 * This would consume an Array like this:
2150 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
2154 * Create a new JsonReader
2155 * @param {Object} meta Metadata configuration options.
2156 * @param {Object|Array} recordType Either an Array of field definition objects
2158 * @cfg {Array} fields Array of field definition objects
2159 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
2160 * as specified to {@link Roo.data.Record#create},
2161 * or an {@link Roo.data.Record} object
2164 * created using {@link Roo.data.Record#create}.
2166 Roo.data.ArrayReader = function(meta, recordType)
2168 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType||meta.fields);
2171 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
2174 * Create a data block containing Roo.data.Records from an XML document.
2175 * @param {Object} o An Array of row objects which represents the dataset.
2176 * @return {Object} A data block which is used by an {@link Roo.data.Store} object as
2177 * a cache of Roo.data.Records.
2179 readRecords : function(o)
2181 var sid = this.meta ? this.meta.id : null;
2182 var recordType = this.recordType, fields = recordType.prototype.fields;
2185 for(var i = 0; i < root.length; i++){
2188 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
2189 for(var j = 0, jlen = fields.length; j < jlen; j++){
2190 var f = fields.items[j];
2191 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
2192 var v = n[k] !== undefined ? n[k] : f.defaultValue;
2196 var record = new recordType(values, id);
2198 records[records.length] = record;
2202 totalRecords : records.length
2206 * using 'cn' the nested child reader read the child array into it's child stores.
2209 loadDataFromChildren: function(rec)
2211 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
2212 return this.loadData(rec.data.cn);
2219 * Ext JS Library 1.1.1
2220 * Copyright(c) 2006-2007, Ext JS, LLC.
2222 * Originally Released Under LGPL - original licence link has changed is not relivant.
2225 * <script type="text/javascript">
2230 * @class Roo.data.Tree
2231 * @extends Roo.util.Observable
2232 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
2233 * in the tree have most standard DOM functionality.
2235 * @param {Node} root (optional) The root node
2237 Roo.data.Tree = function(root){
2240 * The root node for this tree
2245 this.setRootNode(root);
2250 * Fires when a new child node is appended to a node in this tree.
2251 * @param {Tree} tree The owner tree
2252 * @param {Node} parent The parent node
2253 * @param {Node} node The newly appended node
2254 * @param {Number} index The index of the newly appended node
2259 * Fires when a child node is removed from a node in this tree.
2260 * @param {Tree} tree The owner tree
2261 * @param {Node} parent The parent node
2262 * @param {Node} node The child node removed
2267 * Fires when a node is moved to a new location in the tree
2268 * @param {Tree} tree The owner tree
2269 * @param {Node} node The node moved
2270 * @param {Node} oldParent The old parent of this node
2271 * @param {Node} newParent The new parent of this node
2272 * @param {Number} index The index it was moved to
2277 * Fires when a new child node is inserted in a node in this tree.
2278 * @param {Tree} tree The owner tree
2279 * @param {Node} parent The parent node
2280 * @param {Node} node The child node inserted
2281 * @param {Node} refNode The child node the node was inserted before
2285 * @event beforeappend
2286 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
2287 * @param {Tree} tree The owner tree
2288 * @param {Node} parent The parent node
2289 * @param {Node} node The child node to be appended
2291 "beforeappend" : true,
2293 * @event beforeremove
2294 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
2295 * @param {Tree} tree The owner tree
2296 * @param {Node} parent The parent node
2297 * @param {Node} node The child node to be removed
2299 "beforeremove" : true,
2302 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
2303 * @param {Tree} tree The owner tree
2304 * @param {Node} node The node being moved
2305 * @param {Node} oldParent The parent of the node
2306 * @param {Node} newParent The new parent the node is moving to
2307 * @param {Number} index The index it is being moved to
2309 "beforemove" : true,
2311 * @event beforeinsert
2312 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
2313 * @param {Tree} tree The owner tree
2314 * @param {Node} parent The parent node
2315 * @param {Node} node The child node to be inserted
2316 * @param {Node} refNode The child node the node is being inserted before
2318 "beforeinsert" : true
2321 Roo.data.Tree.superclass.constructor.call(this);
2324 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
2327 proxyNodeEvent : function(){
2328 return this.fireEvent.apply(this, arguments);
2332 * Returns the root node for this tree.
2335 getRootNode : function(){
2340 * Sets the root node for this tree.
2341 * @param {Node} node
2344 setRootNode : function(node){
2346 node.ownerTree = this;
2348 this.registerNode(node);
2353 * Gets a node in this tree by its id.
2354 * @param {String} id
2357 getNodeById : function(id){
2358 return this.nodeHash[id];
2361 registerNode : function(node){
2362 this.nodeHash[node.id] = node;
2365 unregisterNode : function(node){
2366 delete this.nodeHash[node.id];
2369 toString : function(){
2370 return "[Tree"+(this.id?" "+this.id:"")+"]";
2375 * @class Roo.data.Node
2376 * @extends Roo.util.Observable
2377 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
2378 * @cfg {String} id The id for this node. If one is not specified, one is generated.
2380 * @param {Object} attributes The attributes/config for the node
2382 Roo.data.Node = function(attributes){
2384 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
2387 this.attributes = attributes || {};
2388 this.leaf = this.attributes.leaf;
2390 * The node id. @type String
2392 this.id = this.attributes.id;
2394 this.id = Roo.id(null, "ynode-");
2395 this.attributes.id = this.id;
2400 * All child nodes of this node. @type Array
2402 this.childNodes = [];
2403 if(!this.childNodes.indexOf){ // indexOf is a must
2404 this.childNodes.indexOf = function(o){
2405 for(var i = 0, len = this.length; i < len; i++){
2414 * The parent node for this node. @type Node
2416 this.parentNode = null;
2418 * The first direct child node of this node, or null if this node has no child nodes. @type Node
2420 this.firstChild = null;
2422 * The last direct child node of this node, or null if this node has no child nodes. @type Node
2424 this.lastChild = null;
2426 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
2428 this.previousSibling = null;
2430 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
2432 this.nextSibling = null;
2437 * Fires when a new child node is appended
2438 * @param {Tree} tree The owner tree
2439 * @param {Node} this This node
2440 * @param {Node} node The newly appended node
2441 * @param {Number} index The index of the newly appended node
2446 * Fires when a child node is removed
2447 * @param {Tree} tree The owner tree
2448 * @param {Node} this This node
2449 * @param {Node} node The removed node
2454 * Fires when this node is moved to a new location in the tree
2455 * @param {Tree} tree The owner tree
2456 * @param {Node} this This node
2457 * @param {Node} oldParent The old parent of this node
2458 * @param {Node} newParent The new parent of this node
2459 * @param {Number} index The index it was moved to
2464 * Fires when a new child node is inserted.
2465 * @param {Tree} tree The owner tree
2466 * @param {Node} this This node
2467 * @param {Node} node The child node inserted
2468 * @param {Node} refNode The child node the node was inserted before
2472 * @event beforeappend
2473 * Fires before a new child is appended, return false to cancel the append.
2474 * @param {Tree} tree The owner tree
2475 * @param {Node} this This node
2476 * @param {Node} node The child node to be appended
2478 "beforeappend" : true,
2480 * @event beforeremove
2481 * Fires before a child is removed, return false to cancel the remove.
2482 * @param {Tree} tree The owner tree
2483 * @param {Node} this This node
2484 * @param {Node} node The child node to be removed
2486 "beforeremove" : true,
2489 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
2490 * @param {Tree} tree The owner tree
2491 * @param {Node} this This node
2492 * @param {Node} oldParent The parent of this node
2493 * @param {Node} newParent The new parent this node is moving to
2494 * @param {Number} index The index it is being moved to
2496 "beforemove" : true,
2498 * @event beforeinsert
2499 * Fires before a new child is inserted, return false to cancel the insert.
2500 * @param {Tree} tree The owner tree
2501 * @param {Node} this This node
2502 * @param {Node} node The child node to be inserted
2503 * @param {Node} refNode The child node the node is being inserted before
2505 "beforeinsert" : true
2507 this.listeners = this.attributes.listeners;
2508 Roo.data.Node.superclass.constructor.call(this);
2511 Roo.extend(Roo.data.Node, Roo.util.Observable, {
2512 fireEvent : function(evtName){
2513 // first do standard event for this node
2514 if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
2517 // then bubble it up to the tree if the event wasn't cancelled
2518 var ot = this.getOwnerTree();
2520 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
2528 * Returns true if this node is a leaf
2531 isLeaf : function(){
2532 return this.leaf === true;
2536 setFirstChild : function(node){
2537 this.firstChild = node;
2541 setLastChild : function(node){
2542 this.lastChild = node;
2547 * Returns true if this node is the last child of its parent
2550 isLast : function(){
2551 return (!this.parentNode ? true : this.parentNode.lastChild == this);
2555 * Returns true if this node is the first child of its parent
2558 isFirst : function(){
2559 return (!this.parentNode ? true : this.parentNode.firstChild == this);
2562 hasChildNodes : function(){
2563 return !this.isLeaf() && this.childNodes.length > 0;
2567 * Insert node(s) as the last child node of this node.
2568 * @param {Node/Array} node The node or Array of nodes to append
2569 * @return {Node} The appended node if single append, or null if an array was passed
2571 appendChild : function(node){
2573 if(node instanceof Array){
2575 }else if(arguments.length > 1){
2579 // if passed an array or multiple args do them one by one
2581 for(var i = 0, len = multi.length; i < len; i++) {
2582 this.appendChild(multi[i]);
2585 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
2588 var index = this.childNodes.length;
2589 var oldParent = node.parentNode;
2590 // it's a move, make sure we move it cleanly
2592 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
2595 oldParent.removeChild(node);
2598 index = this.childNodes.length;
2600 this.setFirstChild(node);
2602 this.childNodes.push(node);
2603 node.parentNode = this;
2604 var ps = this.childNodes[index-1];
2606 node.previousSibling = ps;
2607 ps.nextSibling = node;
2609 node.previousSibling = null;
2611 node.nextSibling = null;
2612 this.setLastChild(node);
2613 node.setOwnerTree(this.getOwnerTree());
2614 this.fireEvent("append", this.ownerTree, this, node, index);
2615 if(this.ownerTree) {
2616 this.ownerTree.fireEvent("appendnode", this, node, index);
2619 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
2626 * Removes a child node from this node.
2627 * @param {Node} node The node to remove
2628 * @return {Node} The removed node
2630 removeChild : function(node){
2631 var index = this.childNodes.indexOf(node);
2635 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
2639 // remove it from childNodes collection
2640 this.childNodes.splice(index, 1);
2643 if(node.previousSibling){
2644 node.previousSibling.nextSibling = node.nextSibling;
2646 if(node.nextSibling){
2647 node.nextSibling.previousSibling = node.previousSibling;
2650 // update child refs
2651 if(this.firstChild == node){
2652 this.setFirstChild(node.nextSibling);
2654 if(this.lastChild == node){
2655 this.setLastChild(node.previousSibling);
2658 node.setOwnerTree(null);
2659 // clear any references from the node
2660 node.parentNode = null;
2661 node.previousSibling = null;
2662 node.nextSibling = null;
2663 this.fireEvent("remove", this.ownerTree, this, node);
2668 * Inserts the first node before the second node in this nodes childNodes collection.
2669 * @param {Node} node The node to insert
2670 * @param {Node} refNode The node to insert before (if null the node is appended)
2671 * @return {Node} The inserted node
2673 insertBefore : function(node, refNode){
2674 if(!refNode){ // like standard Dom, refNode can be null for append
2675 return this.appendChild(node);
2678 if(node == refNode){
2682 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
2685 var index = this.childNodes.indexOf(refNode);
2686 var oldParent = node.parentNode;
2687 var refIndex = index;
2689 // when moving internally, indexes will change after remove
2690 if(oldParent == this && this.childNodes.indexOf(node) < index){
2694 // it's a move, make sure we move it cleanly
2696 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
2699 oldParent.removeChild(node);
2702 this.setFirstChild(node);
2704 this.childNodes.splice(refIndex, 0, node);
2705 node.parentNode = this;
2706 var ps = this.childNodes[refIndex-1];
2708 node.previousSibling = ps;
2709 ps.nextSibling = node;
2711 node.previousSibling = null;
2713 node.nextSibling = refNode;
2714 refNode.previousSibling = node;
2715 node.setOwnerTree(this.getOwnerTree());
2716 this.fireEvent("insert", this.ownerTree, this, node, refNode);
2718 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
2724 * Returns the child node at the specified index.
2725 * @param {Number} index
2728 item : function(index){
2729 return this.childNodes[index];
2733 * Replaces one child node in this node with another.
2734 * @param {Node} newChild The replacement node
2735 * @param {Node} oldChild The node to replace
2736 * @return {Node} The replaced node
2738 replaceChild : function(newChild, oldChild){
2739 this.insertBefore(newChild, oldChild);
2740 this.removeChild(oldChild);
2745 * Returns the index of a child node
2746 * @param {Node} node
2747 * @return {Number} The index of the node or -1 if it was not found
2749 indexOf : function(child){
2750 return this.childNodes.indexOf(child);
2754 * Returns the tree this node is in.
2757 getOwnerTree : function(){
2758 // if it doesn't have one, look for one
2759 if(!this.ownerTree){
2763 this.ownerTree = p.ownerTree;
2769 return this.ownerTree;
2773 * Returns depth of this node (the root node has a depth of 0)
2776 getDepth : function(){
2779 while(p.parentNode){
2787 setOwnerTree : function(tree){
2788 // if it's move, we need to update everyone
2789 if(tree != this.ownerTree){
2791 this.ownerTree.unregisterNode(this);
2793 this.ownerTree = tree;
2794 var cs = this.childNodes;
2795 for(var i = 0, len = cs.length; i < len; i++) {
2796 cs[i].setOwnerTree(tree);
2799 tree.registerNode(this);
2805 * Returns the path for this node. The path can be used to expand or select this node programmatically.
2806 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
2807 * @return {String} The path
2809 getPath : function(attr){
2810 attr = attr || "id";
2811 var p = this.parentNode;
2812 var b = [this.attributes[attr]];
2814 b.unshift(p.attributes[attr]);
2817 var sep = this.getOwnerTree().pathSeparator;
2818 return sep + b.join(sep);
2822 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
2823 * function call will be the scope provided or the current node. The arguments to the function
2824 * will be the args provided or the current node. If the function returns false at any point,
2825 * the bubble is stopped.
2826 * @param {Function} fn The function to call
2827 * @param {Object} scope (optional) The scope of the function (defaults to current node)
2828 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
2830 bubble : function(fn, scope, args){
2833 if(fn.call(scope || p, args || p) === false){
2841 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
2842 * function call will be the scope provided or the current node. The arguments to the function
2843 * will be the args provided or the current node. If the function returns false at any point,
2844 * the cascade is stopped on that branch.
2845 * @param {Function} fn The function to call
2846 * @param {Object} scope (optional) The scope of the function (defaults to current node)
2847 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
2849 cascade : function(fn, scope, args){
2850 if(fn.call(scope || this, args || this) !== false){
2851 var cs = this.childNodes;
2852 for(var i = 0, len = cs.length; i < len; i++) {
2853 cs[i].cascade(fn, scope, args);
2859 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
2860 * function call will be the scope provided or the current node. The arguments to the function
2861 * will be the args provided or the current node. If the function returns false at any point,
2862 * the iteration stops.
2863 * @param {Function} fn The function to call
2864 * @param {Object} scope (optional) The scope of the function (defaults to current node)
2865 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
2867 eachChild : function(fn, scope, args){
2868 var cs = this.childNodes;
2869 for(var i = 0, len = cs.length; i < len; i++) {
2870 if(fn.call(scope || this, args || cs[i]) === false){
2877 * Finds the first child that has the attribute with the specified value.
2878 * @param {String} attribute The attribute name
2879 * @param {Mixed} value The value to search for
2880 * @return {Node} The found child or null if none was found
2882 findChild : function(attribute, value){
2883 var cs = this.childNodes;
2884 for(var i = 0, len = cs.length; i < len; i++) {
2885 if(cs[i].attributes[attribute] == value){
2893 * Finds the first child by a custom function. The child matches if the function passed
2895 * @param {Function} fn
2896 * @param {Object} scope (optional)
2897 * @return {Node} The found child or null if none was found
2899 findChildBy : function(fn, scope){
2900 var cs = this.childNodes;
2901 for(var i = 0, len = cs.length; i < len; i++) {
2902 if(fn.call(scope||cs[i], cs[i]) === true){
2910 * Sorts this nodes children using the supplied sort function
2911 * @param {Function} fn
2912 * @param {Object} scope (optional)
2914 sort : function(fn, scope){
2915 var cs = this.childNodes;
2916 var len = cs.length;
2918 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
2920 for(var i = 0; i < len; i++){
2922 n.previousSibling = cs[i-1];
2923 n.nextSibling = cs[i+1];
2925 this.setFirstChild(n);
2928 this.setLastChild(n);
2935 * Returns true if this node is an ancestor (at any point) of the passed node.
2936 * @param {Node} node
2939 contains : function(node){
2940 return node.isAncestor(this);
2944 * Returns true if the passed node is an ancestor (at any point) of this node.
2945 * @param {Node} node
2948 isAncestor : function(node){
2949 var p = this.parentNode;
2959 toString : function(){
2960 return "[Node"+(this.id?" "+this.id:"")+"]";
2964 * Ext JS Library 1.1.1
2965 * Copyright(c) 2006-2007, Ext JS, LLC.
2967 * Originally Released Under LGPL - original licence link has changed is not relivant.
2970 * <script type="text/javascript">
2975 * @extends Roo.Element
2976 * An extended {@link Roo.Element} object that supports a shadow and shim, constrain to viewport and
2977 * automatic maintaining of shadow/shim positions.
2978 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
2979 * @cfg {String/Boolean} shadow True to create a shadow element with default class "x-layer-shadow", or
2980 * you can pass a string with a CSS class name. False turns off the shadow.
2981 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: "div", cls: "x-layer"}).
2982 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
2983 * @cfg {String} cls CSS class to add to the element
2984 * @cfg {Number} zindex Starting z-index (defaults to 11000)
2985 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 3)
2987 * @param {Object} config An object with config options.
2988 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
2991 Roo.Layer = function(config, existingEl){
2992 config = config || {};
2993 var dh = Roo.DomHelper;
2994 var cp = config.parentEl, pel = cp ? Roo.getDom(cp) : document.body;
2996 this.dom = Roo.getDom(existingEl);
2999 var o = config.dh || {tag: "div", cls: "x-layer"};
3000 this.dom = dh.append(pel, o);
3003 this.addClass(config.cls);
3005 this.constrain = config.constrain !== false;
3006 this.visibilityMode = Roo.Element.VISIBILITY;
3008 this.id = this.dom.id = config.id;
3010 this.id = Roo.id(this.dom);
3012 this.zindex = config.zindex || this.getZIndex();
3013 this.position("absolute", this.zindex);
3015 this.shadowOffset = config.shadowOffset || 4;
3016 this.shadow = new Roo.Shadow({
3017 offset : this.shadowOffset,
3018 mode : config.shadow
3021 this.shadowOffset = 0;
3023 this.useShim = config.shim !== false && Roo.useShims;
3024 this.useDisplay = config.useDisplay;
3028 var supr = Roo.Element.prototype;
3030 // shims are shared among layer to keep from having 100 iframes
3033 Roo.extend(Roo.Layer, Roo.Element, {
3035 getZIndex : function(){
3036 return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
3039 getShim : function(){
3046 var shim = shims.shift();
3048 shim = this.createShim();
3049 shim.enableDisplayMode('block');
3050 shim.dom.style.display = 'none';
3051 shim.dom.style.visibility = 'visible';
3053 var pn = this.dom.parentNode;
3054 if(shim.dom.parentNode != pn){
3055 pn.insertBefore(shim.dom, this.dom);
3057 shim.setStyle('z-index', this.getZIndex()-2);
3062 hideShim : function(){
3064 this.shim.setDisplayed(false);
3065 shims.push(this.shim);
3070 disableShadow : function(){
3072 this.shadowDisabled = true;
3074 this.lastShadowOffset = this.shadowOffset;
3075 this.shadowOffset = 0;
3079 enableShadow : function(show){
3081 this.shadowDisabled = false;
3082 this.shadowOffset = this.lastShadowOffset;
3083 delete this.lastShadowOffset;
3091 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
3092 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
3093 sync : function(doShow){
3094 var sw = this.shadow;
3095 if(!this.updating && this.isVisible() && (sw || this.useShim)){
3096 var sh = this.getShim();
3098 var w = this.getWidth(),
3099 h = this.getHeight();
3101 var l = this.getLeft(true),
3102 t = this.getTop(true);
3104 if(sw && !this.shadowDisabled){
3105 if(doShow && !sw.isVisible()){
3108 sw.realign(l, t, w, h);
3114 // fit the shim behind the shadow, so it is shimmed too
3115 var a = sw.adjusts, s = sh.dom.style;
3116 s.left = (Math.min(l, l+a.l))+"px";
3117 s.top = (Math.min(t, t+a.t))+"px";
3118 s.width = (w+a.w)+"px";
3119 s.height = (h+a.h)+"px";
3126 sh.setLeftTop(l, t);
3133 destroy : function(){
3138 this.removeAllListeners();
3139 var pn = this.dom.parentNode;
3141 pn.removeChild(this.dom);
3143 Roo.Element.uncache(this.id);
3146 remove : function(){
3151 beginUpdate : function(){
3152 this.updating = true;
3156 endUpdate : function(){
3157 this.updating = false;
3162 hideUnders : function(negOffset){
3170 constrainXY : function(){
3172 var vw = Roo.lib.Dom.getViewWidth(),
3173 vh = Roo.lib.Dom.getViewHeight();
3174 var s = Roo.get(document).getScroll();
3176 var xy = this.getXY();
3177 var x = xy[0], y = xy[1];
3178 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
3179 // only move it if it needs it
3181 // first validate right/bottom
3182 if((x + w) > vw+s.left){
3183 x = vw - w - this.shadowOffset;
3186 if((y + h) > vh+s.top){
3187 y = vh - h - this.shadowOffset;
3190 // then make sure top/left isn't negative
3201 var ay = this.avoidY;
3202 if(y <= ay && (y+h) >= ay){
3208 supr.setXY.call(this, xy);
3214 isVisible : function(){
3215 return this.visible;
3219 showAction : function(){
3220 this.visible = true; // track visibility to prevent getStyle calls
3221 if(this.useDisplay === true){
3222 this.setDisplayed("");
3223 }else if(this.lastXY){
3224 supr.setXY.call(this, this.lastXY);
3225 }else if(this.lastLT){
3226 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
3231 hideAction : function(){
3232 this.visible = false;
3233 if(this.useDisplay === true){
3234 this.setDisplayed(false);
3236 this.setLeftTop(-10000,-10000);
3240 // overridden Element method
3241 setVisible : function(v, a, d, c, e){
3246 var cb = function(){
3251 }.createDelegate(this);
3252 supr.setVisible.call(this, true, true, d, cb, e);
3255 this.hideUnders(true);
3264 }.createDelegate(this);
3266 supr.setVisible.call(this, v, a, d, cb, e);
3275 storeXY : function(xy){
3280 storeLeftTop : function(left, top){
3282 this.lastLT = [left, top];
3286 beforeFx : function(){
3287 this.beforeAction();
3288 return Roo.Layer.superclass.beforeFx.apply(this, arguments);
3292 afterFx : function(){
3293 Roo.Layer.superclass.afterFx.apply(this, arguments);
3294 this.sync(this.isVisible());
3298 beforeAction : function(){
3299 if(!this.updating && this.shadow){
3304 // overridden Element method
3305 setLeft : function(left){
3306 this.storeLeftTop(left, this.getTop(true));
3307 supr.setLeft.apply(this, arguments);
3311 setTop : function(top){
3312 this.storeLeftTop(this.getLeft(true), top);
3313 supr.setTop.apply(this, arguments);
3317 setLeftTop : function(left, top){
3318 this.storeLeftTop(left, top);
3319 supr.setLeftTop.apply(this, arguments);
3323 setXY : function(xy, a, d, c, e){
3325 this.beforeAction();
3327 var cb = this.createCB(c);
3328 supr.setXY.call(this, xy, a, d, cb, e);
3335 createCB : function(c){
3346 // overridden Element method
3347 setX : function(x, a, d, c, e){
3348 this.setXY([x, this.getY()], a, d, c, e);
3351 // overridden Element method
3352 setY : function(y, a, d, c, e){
3353 this.setXY([this.getX(), y], a, d, c, e);
3356 // overridden Element method
3357 setSize : function(w, h, a, d, c, e){
3358 this.beforeAction();
3359 var cb = this.createCB(c);
3360 supr.setSize.call(this, w, h, a, d, cb, e);
3366 // overridden Element method
3367 setWidth : function(w, a, d, c, e){
3368 this.beforeAction();
3369 var cb = this.createCB(c);
3370 supr.setWidth.call(this, w, a, d, cb, e);
3376 // overridden Element method
3377 setHeight : function(h, a, d, c, e){
3378 this.beforeAction();
3379 var cb = this.createCB(c);
3380 supr.setHeight.call(this, h, a, d, cb, e);
3386 // overridden Element method
3387 setBounds : function(x, y, w, h, a, d, c, e){
3388 this.beforeAction();
3389 var cb = this.createCB(c);
3391 this.storeXY([x, y]);
3392 supr.setXY.call(this, [x, y]);
3393 supr.setSize.call(this, w, h, a, d, cb, e);
3396 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
3402 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
3403 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
3404 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
3405 * @param {Number} zindex The new z-index to set
3406 * @return {this} The Layer
3408 setZIndex : function(zindex){
3409 this.zindex = zindex;
3410 this.setStyle("z-index", zindex + 2);
3412 this.shadow.setZIndex(zindex + 1);
3415 this.shim.setStyle("z-index", zindex);
3421 * Ext JS Library 1.1.1
3422 * Copyright(c) 2006-2007, Ext JS, LLC.
3424 * Originally Released Under LGPL - original licence link has changed is not relivant.
3427 * <script type="text/javascript">
3433 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
3434 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
3435 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
3437 * Create a new Shadow
3438 * @param {Object} config The config object
3440 Roo.Shadow = function(config){
3441 Roo.apply(this, config);
3442 if(typeof this.mode != "string"){
3443 this.mode = this.defaultMode;
3445 var o = this.offset, a = {h: 0};
3446 var rad = Math.floor(this.offset/2);
3447 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
3453 a.l -= this.offset + rad;
3454 a.t -= this.offset + rad;
3465 a.l -= (this.offset - rad);
3466 a.t -= this.offset + rad;
3468 a.w -= (this.offset - rad)*2;
3479 a.l -= (this.offset - rad);
3480 a.t -= (this.offset - rad);
3482 a.w -= (this.offset + rad + 1);
3483 a.h -= (this.offset + rad);
3492 Roo.Shadow.prototype = {
3494 * @cfg {String} mode
3495 * The shadow display mode. Supports the following options:<br />
3496 * sides: Shadow displays on both sides and bottom only<br />
3497 * frame: Shadow displays equally on all four sides<br />
3498 * drop: Traditional bottom-right drop shadow (default)
3501 * @cfg {String} offset
3502 * The number of pixels to offset the shadow from the element (defaults to 4)
3507 defaultMode: "drop",
3510 * Displays the shadow under the target element
3511 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
3513 show : function(target){
3514 target = Roo.get(target);
3516 this.el = Roo.Shadow.Pool.pull();
3517 if(this.el.dom.nextSibling != target.dom){
3518 this.el.insertBefore(target);
3521 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
3523 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
3526 target.getLeft(true),
3527 target.getTop(true),
3531 this.el.dom.style.display = "block";
3535 * Returns true if the shadow is visible, else false
3537 isVisible : function(){
3538 return this.el ? true : false;
3542 * Direct alignment when values are already available. Show must be called at least once before
3543 * calling this method to ensure it is initialized.
3544 * @param {Number} left The target element left position
3545 * @param {Number} top The target element top position
3546 * @param {Number} width The target element width
3547 * @param {Number} height The target element height
3549 realign : function(l, t, w, h){
3553 var a = this.adjusts, d = this.el.dom, s = d.style;
3555 s.left = (l+a.l)+"px";
3556 s.top = (t+a.t)+"px";
3557 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
3559 if(s.width != sws || s.height != shs){
3563 var cn = d.childNodes;
3564 var sww = Math.max(0, (sw-12))+"px";
3565 cn[0].childNodes[1].style.width = sww;
3566 cn[1].childNodes[1].style.width = sww;
3567 cn[2].childNodes[1].style.width = sww;
3568 cn[1].style.height = Math.max(0, (sh-12))+"px";
3578 this.el.dom.style.display = "none";
3579 Roo.Shadow.Pool.push(this.el);
3585 * Adjust the z-index of this shadow
3586 * @param {Number} zindex The new z-index
3588 setZIndex : function(z){
3591 this.el.setStyle("z-index", z);
3596 // Private utility class that manages the internal Shadow cache
3597 Roo.Shadow.Pool = function(){
3599 var markup = Roo.isIE ?
3600 '<div class="x-ie-shadow"></div>' :
3601 '<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>';
3606 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
3607 sh.autoBoxAdjust = false;
3612 push : function(sh){
3618 * Ext JS Library 1.1.1
3619 * Copyright(c) 2006-2007, Ext JS, LLC.
3621 * Originally Released Under LGPL - original licence link has changed is not relivant.
3624 * <script type="text/javascript">
3629 * @class Roo.SplitBar
3630 * @extends Roo.util.Observable
3631 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
3635 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
3636 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
3637 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
3638 split.minSize = 100;
3639 split.maxSize = 600;
3640 split.animate = true;
3641 split.on('moved', splitterMoved);
3644 * Create a new SplitBar
3645 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
3646 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
3647 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
3648 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
3649 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
3650 position of the SplitBar).
3652 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
3655 this.el = Roo.get(dragElement, true);
3656 this.el.dom.unselectable = "on";
3658 this.resizingEl = Roo.get(resizingElement, true);
3662 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
3663 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
3666 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
3669 * The minimum size of the resizing element. (Defaults to 0)
3675 * The maximum size of the resizing element. (Defaults to 2000)
3678 this.maxSize = 2000;
3681 * Whether to animate the transition to the new size
3684 this.animate = false;
3687 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
3690 this.useShim = false;
3697 this.proxy = Roo.SplitBar.createProxy(this.orientation);
3699 this.proxy = Roo.get(existingProxy).dom;
3702 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
3705 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
3708 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
3711 this.dragSpecs = {};
3714 * @private The adapter to use to positon and resize elements
3716 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
3717 this.adapter.init(this);
3719 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3721 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
3722 this.el.addClass("x-splitbar-h");
3725 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
3726 this.el.addClass("x-splitbar-v");
3732 * Fires when the splitter is moved (alias for {@link #event-moved})
3733 * @param {Roo.SplitBar} this
3734 * @param {Number} newSize the new width or height
3739 * Fires when the splitter is moved
3740 * @param {Roo.SplitBar} this
3741 * @param {Number} newSize the new width or height
3745 * @event beforeresize
3746 * Fires before the splitter is dragged
3747 * @param {Roo.SplitBar} this
3749 "beforeresize" : true,
3751 "beforeapply" : true
3754 Roo.util.Observable.call(this);
3757 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
3758 onStartProxyDrag : function(x, y){
3759 this.fireEvent("beforeresize", this);
3761 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
3763 o.enableDisplayMode("block");
3764 // all splitbars share the same overlay
3765 Roo.SplitBar.prototype.overlay = o;
3767 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
3768 this.overlay.show();
3769 Roo.get(this.proxy).setDisplayed("block");
3770 var size = this.adapter.getElementSize(this);
3771 this.activeMinSize = this.getMinimumSize();;
3772 this.activeMaxSize = this.getMaximumSize();;
3773 var c1 = size - this.activeMinSize;
3774 var c2 = Math.max(this.activeMaxSize - size, 0);
3775 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3776 this.dd.resetConstraints();
3777 this.dd.setXConstraint(
3778 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
3779 this.placement == Roo.SplitBar.LEFT ? c2 : c1
3781 this.dd.setYConstraint(0, 0);
3783 this.dd.resetConstraints();
3784 this.dd.setXConstraint(0, 0);
3785 this.dd.setYConstraint(
3786 this.placement == Roo.SplitBar.TOP ? c1 : c2,
3787 this.placement == Roo.SplitBar.TOP ? c2 : c1
3790 this.dragSpecs.startSize = size;
3791 this.dragSpecs.startPoint = [x, y];
3792 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
3796 * @private Called after the drag operation by the DDProxy
3798 onEndProxyDrag : function(e){
3799 Roo.get(this.proxy).setDisplayed(false);
3800 var endPoint = Roo.lib.Event.getXY(e);
3802 this.overlay.hide();
3805 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3806 newSize = this.dragSpecs.startSize +
3807 (this.placement == Roo.SplitBar.LEFT ?
3808 endPoint[0] - this.dragSpecs.startPoint[0] :
3809 this.dragSpecs.startPoint[0] - endPoint[0]
3812 newSize = this.dragSpecs.startSize +
3813 (this.placement == Roo.SplitBar.TOP ?
3814 endPoint[1] - this.dragSpecs.startPoint[1] :
3815 this.dragSpecs.startPoint[1] - endPoint[1]
3818 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
3819 if(newSize != this.dragSpecs.startSize){
3820 if(this.fireEvent('beforeapply', this, newSize) !== false){
3821 this.adapter.setElementSize(this, newSize);
3822 this.fireEvent("moved", this, newSize);
3823 this.fireEvent("resize", this, newSize);
3829 * Get the adapter this SplitBar uses
3830 * @return The adapter object
3832 getAdapter : function(){
3833 return this.adapter;
3837 * Set the adapter this SplitBar uses
3838 * @param {Object} adapter A SplitBar adapter object
3840 setAdapter : function(adapter){
3841 this.adapter = adapter;
3842 this.adapter.init(this);
3846 * Gets the minimum size for the resizing element
3847 * @return {Number} The minimum size
3849 getMinimumSize : function(){
3850 return this.minSize;
3854 * Sets the minimum size for the resizing element
3855 * @param {Number} minSize The minimum size
3857 setMinimumSize : function(minSize){
3858 this.minSize = minSize;
3862 * Gets the maximum size for the resizing element
3863 * @return {Number} The maximum size
3865 getMaximumSize : function(){
3866 return this.maxSize;
3870 * Sets the maximum size for the resizing element
3871 * @param {Number} maxSize The maximum size
3873 setMaximumSize : function(maxSize){
3874 this.maxSize = maxSize;
3878 * Sets the initialize size for the resizing element
3879 * @param {Number} size The initial size
3881 setCurrentSize : function(size){
3882 var oldAnimate = this.animate;
3883 this.animate = false;
3884 this.adapter.setElementSize(this, size);
3885 this.animate = oldAnimate;
3889 * Destroy this splitbar.
3890 * @param {Boolean} removeEl True to remove the element
3892 destroy : function(removeEl){
3897 this.proxy.parentNode.removeChild(this.proxy);
3905 * @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.
3907 Roo.SplitBar.createProxy = function(dir){
3908 var proxy = new Roo.Element(document.createElement("div"));
3909 proxy.unselectable();
3910 var cls = 'x-splitbar-proxy';
3911 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
3912 document.body.appendChild(proxy.dom);
3917 * @class Roo.SplitBar.BasicLayoutAdapter
3918 * Default Adapter. It assumes the splitter and resizing element are not positioned
3919 * elements and only gets/sets the width of the element. Generally used for table based layouts.
3921 Roo.SplitBar.BasicLayoutAdapter = function(){
3924 Roo.SplitBar.BasicLayoutAdapter.prototype = {
3925 // do nothing for now
3930 * Called before drag operations to get the current size of the resizing element.
3931 * @param {Roo.SplitBar} s The SplitBar using this adapter
3933 getElementSize : function(s){
3934 if(s.orientation == Roo.SplitBar.HORIZONTAL){
3935 return s.resizingEl.getWidth();
3937 return s.resizingEl.getHeight();
3942 * Called after drag operations to set the size of the resizing element.
3943 * @param {Roo.SplitBar} s The SplitBar using this adapter
3944 * @param {Number} newSize The new size to set
3945 * @param {Function} onComplete A function to be invoked when resizing is complete
3947 setElementSize : function(s, newSize, onComplete){
3948 if(s.orientation == Roo.SplitBar.HORIZONTAL){
3950 s.resizingEl.setWidth(newSize);
3952 onComplete(s, newSize);
3955 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
3960 s.resizingEl.setHeight(newSize);
3962 onComplete(s, newSize);
3965 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
3972 *@class Roo.SplitBar.AbsoluteLayoutAdapter
3973 * @extends Roo.SplitBar.BasicLayoutAdapter
3974 * Adapter that moves the splitter element to align with the resized sizing element.
3975 * Used with an absolute positioned SplitBar.
3976 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
3977 * document.body, make sure you assign an id to the body element.
3979 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
3980 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
3981 this.container = Roo.get(container);
3984 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
3989 getElementSize : function(s){
3990 return this.basic.getElementSize(s);
3993 setElementSize : function(s, newSize, onComplete){
3994 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
3997 moveSplitter : function(s){
3998 var yes = Roo.SplitBar;
3999 switch(s.placement){
4001 s.el.setX(s.resizingEl.getRight());
4004 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
4007 s.el.setY(s.resizingEl.getBottom());
4010 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
4017 * Orientation constant - Create a vertical SplitBar
4021 Roo.SplitBar.VERTICAL = 1;
4024 * Orientation constant - Create a horizontal SplitBar
4028 Roo.SplitBar.HORIZONTAL = 2;
4031 * Placement constant - The resizing element is to the left of the splitter element
4035 Roo.SplitBar.LEFT = 1;
4038 * Placement constant - The resizing element is to the right of the splitter element
4042 Roo.SplitBar.RIGHT = 2;
4045 * Placement constant - The resizing element is positioned above the splitter element
4049 Roo.SplitBar.TOP = 3;
4052 * Placement constant - The resizing element is positioned under splitter element
4056 Roo.SplitBar.BOTTOM = 4;
4059 * Ext JS Library 1.1.1
4060 * Copyright(c) 2006-2007, Ext JS, LLC.
4062 * Originally Released Under LGPL - original licence link has changed is not relivant.
4065 * <script type="text/javascript">
4070 * @extends Roo.util.Observable
4071 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
4072 * This class also supports single and multi selection modes. <br>
4073 * Create a data model bound view:
4075 var store = new Roo.data.Store(...);
4077 var view = new Roo.View({
4079 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
4082 selectedClass: "ydataview-selected",
4086 // listen for node click?
4087 view.on("click", function(vw, index, node, e){
4088 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
4092 dataModel.load("foobar.xml");
4094 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
4096 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
4097 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
4099 * Note: old style constructor is still suported (container, template, config)
4103 * @param {Object} config The config object
4106 Roo.View = function(config, depreciated_tpl, depreciated_config){
4108 this.parent = false;
4110 if (typeof(depreciated_tpl) == 'undefined') {
4111 // new way.. - universal constructor.
4112 Roo.apply(this, config);
4113 this.el = Roo.get(this.el);
4116 this.el = Roo.get(config);
4117 this.tpl = depreciated_tpl;
4118 Roo.apply(this, depreciated_config);
4120 this.wrapEl = this.el.wrap().wrap();
4121 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
4124 if(typeof(this.tpl) == "string"){
4125 this.tpl = new Roo.Template(this.tpl);
4127 // support xtype ctors..
4128 this.tpl = new Roo.factory(this.tpl, Roo);
4137 * @event beforeclick
4138 * Fires before a click is processed. Returns false to cancel the default action.
4139 * @param {Roo.View} this
4140 * @param {Number} index The index of the target node
4141 * @param {HTMLElement} node The target node
4142 * @param {Roo.EventObject} e The raw event object
4144 "beforeclick" : true,
4147 * Fires when a template node is clicked.
4148 * @param {Roo.View} this
4149 * @param {Number} index The index of the target node
4150 * @param {HTMLElement} node The target node
4151 * @param {Roo.EventObject} e The raw event object
4156 * Fires when a template node is double clicked.
4157 * @param {Roo.View} this
4158 * @param {Number} index The index of the target node
4159 * @param {HTMLElement} node The target node
4160 * @param {Roo.EventObject} e The raw event object
4164 * @event contextmenu
4165 * Fires when a template node is right clicked.
4166 * @param {Roo.View} this
4167 * @param {Number} index The index of the target node
4168 * @param {HTMLElement} node The target node
4169 * @param {Roo.EventObject} e The raw event object
4171 "contextmenu" : true,
4173 * @event selectionchange
4174 * Fires when the selected nodes change.
4175 * @param {Roo.View} this
4176 * @param {Array} selections Array of the selected nodes
4178 "selectionchange" : true,
4181 * @event beforeselect
4182 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
4183 * @param {Roo.View} this
4184 * @param {HTMLElement} node The node to be selected
4185 * @param {Array} selections Array of currently selected nodes
4187 "beforeselect" : true,
4189 * @event preparedata
4190 * Fires on every row to render, to allow you to change the data.
4191 * @param {Roo.View} this
4192 * @param {Object} data to be rendered (change this)
4194 "preparedata" : true
4202 "click": this.onClick,
4203 "dblclick": this.onDblClick,
4204 "contextmenu": this.onContextMenu,
4208 this.selections = [];
4210 this.cmp = new Roo.CompositeElementLite([]);
4212 this.store = Roo.factory(this.store, Roo.data);
4213 this.setStore(this.store, true);
4216 if ( this.footer && this.footer.xtype) {
4218 var fctr = this.wrapEl.appendChild(document.createElement("div"));
4220 this.footer.dataSource = this.store;
4221 this.footer.container = fctr;
4222 this.footer = Roo.factory(this.footer, Roo);
4223 fctr.insertFirst(this.el);
4225 // this is a bit insane - as the paging toolbar seems to detach the el..
4226 // dom.parentNode.parentNode.parentNode
4227 // they get detached?
4231 Roo.View.superclass.constructor.call(this);
4236 Roo.extend(Roo.View, Roo.util.Observable, {
4239 * @cfg {Roo.data.Store} store Data store to load data from.
4244 * @cfg {String|Roo.Element} el The container element.
4249 * @cfg {String|Roo.Template} tpl The template used by this View
4253 * @cfg {String} dataName the named area of the template to use as the data area
4254 * Works with domtemplates roo-name="name"
4258 * @cfg {String} selectedClass The css class to add to selected nodes
4260 selectedClass : "x-view-selected",
4262 * @cfg {String} emptyText The empty text to show when nothing is loaded.
4267 * @cfg {String} text to display on mask (default Loading)
4271 * @cfg {Boolean} multiSelect Allow multiple selection
4273 multiSelect : false,
4275 * @cfg {Boolean} singleSelect Allow single selection
4277 singleSelect: false,
4280 * @cfg {Boolean} toggleSelect - selecting
4282 toggleSelect : false,
4285 * @cfg {Boolean} tickable - selecting
4290 * Returns the element this view is bound to.
4291 * @return {Roo.Element}
4300 * Refreshes the view. - called by datachanged on the store. - do not call directly.
4302 refresh : function(){
4303 //Roo.log('refresh');
4306 // if we are using something like 'domtemplate', then
4307 // the what gets used is:
4308 // t.applySubtemplate(NAME, data, wrapping data..)
4309 // the outer template then get' applied with
4310 // the store 'extra data'
4311 // and the body get's added to the
4312 // roo-name="data" node?
4313 // <span class='roo-tpl-{name}'></span> ?????
4317 this.clearSelections();
4320 var records = this.store.getRange();
4321 if(records.length < 1) {
4323 // is this valid?? = should it render a template??
4325 this.el.update(this.emptyText);
4329 if (this.dataName) {
4330 this.el.update(t.apply(this.store.meta)); //????
4331 el = this.el.child('.roo-tpl-' + this.dataName);
4334 for(var i = 0, len = records.length; i < len; i++){
4335 var data = this.prepareData(records[i].data, i, records[i]);
4336 this.fireEvent("preparedata", this, data, i, records[i]);
4338 var d = Roo.apply({}, data);
4341 Roo.apply(d, {'roo-id' : Roo.id()});
4345 Roo.each(this.parent.item, function(item){
4346 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
4349 Roo.apply(d, {'roo-data-checked' : 'checked'});
4353 html[html.length] = Roo.util.Format.trim(
4355 t.applySubtemplate(this.dataName, d, this.store.meta) :
4362 el.update(html.join(""));
4363 this.nodes = el.dom.childNodes;
4364 this.updateIndexes(0);
4369 * Function to override to reformat the data that is sent to
4370 * the template for each node.
4371 * DEPRICATED - use the preparedata event handler.
4372 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
4373 * a JSON object for an UpdateManager bound view).
4375 prepareData : function(data, index, record)
4377 this.fireEvent("preparedata", this, data, index, record);
4381 onUpdate : function(ds, record){
4382 // Roo.log('on update');
4383 this.clearSelections();
4384 var index = this.store.indexOf(record);
4385 var n = this.nodes[index];
4386 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
4387 n.parentNode.removeChild(n);
4388 this.updateIndexes(index, index);
4394 onAdd : function(ds, records, index)
4396 //Roo.log(['on Add', ds, records, index] );
4397 this.clearSelections();
4398 if(this.nodes.length == 0){
4402 var n = this.nodes[index];
4403 for(var i = 0, len = records.length; i < len; i++){
4404 var d = this.prepareData(records[i].data, i, records[i]);
4406 this.tpl.insertBefore(n, d);
4409 this.tpl.append(this.el, d);
4412 this.updateIndexes(index);
4415 onRemove : function(ds, record, index){
4416 // Roo.log('onRemove');
4417 this.clearSelections();
4418 var el = this.dataName ?
4419 this.el.child('.roo-tpl-' + this.dataName) :
4422 el.dom.removeChild(this.nodes[index]);
4423 this.updateIndexes(index);
4427 * Refresh an individual node.
4428 * @param {Number} index
4430 refreshNode : function(index){
4431 this.onUpdate(this.store, this.store.getAt(index));
4434 updateIndexes : function(startIndex, endIndex){
4435 var ns = this.nodes;
4436 startIndex = startIndex || 0;
4437 endIndex = endIndex || ns.length - 1;
4438 for(var i = startIndex; i <= endIndex; i++){
4439 ns[i].nodeIndex = i;
4444 * Changes the data store this view uses and refresh the view.
4445 * @param {Store} store
4447 setStore : function(store, initial){
4448 if(!initial && this.store){
4449 this.store.un("datachanged", this.refresh);
4450 this.store.un("add", this.onAdd);
4451 this.store.un("remove", this.onRemove);
4452 this.store.un("update", this.onUpdate);
4453 this.store.un("clear", this.refresh);
4454 this.store.un("beforeload", this.onBeforeLoad);
4455 this.store.un("load", this.onLoad);
4456 this.store.un("loadexception", this.onLoad);
4460 store.on("datachanged", this.refresh, this);
4461 store.on("add", this.onAdd, this);
4462 store.on("remove", this.onRemove, this);
4463 store.on("update", this.onUpdate, this);
4464 store.on("clear", this.refresh, this);
4465 store.on("beforeload", this.onBeforeLoad, this);
4466 store.on("load", this.onLoad, this);
4467 store.on("loadexception", this.onLoad, this);
4475 * onbeforeLoad - masks the loading area.
4478 onBeforeLoad : function(store,opts)
4480 //Roo.log('onBeforeLoad');
4484 this.el.mask(this.mask ? this.mask : "Loading" );
4486 onLoad : function ()
4493 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
4494 * @param {HTMLElement} node
4495 * @return {HTMLElement} The template node
4497 findItemFromChild : function(node){
4498 var el = this.dataName ?
4499 this.el.child('.roo-tpl-' + this.dataName,true) :
4502 if(!node || node.parentNode == el){
4505 var p = node.parentNode;
4506 while(p && p != el){
4507 if(p.parentNode == el){
4516 onClick : function(e){
4517 var item = this.findItemFromChild(e.getTarget());
4519 var index = this.indexOf(item);
4520 if(this.onItemClick(item, index, e) !== false){
4521 this.fireEvent("click", this, index, item, e);
4524 this.clearSelections();
4529 onContextMenu : function(e){
4530 var item = this.findItemFromChild(e.getTarget());
4532 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
4537 onDblClick : function(e){
4538 var item = this.findItemFromChild(e.getTarget());
4540 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
4544 onItemClick : function(item, index, e)
4546 if(this.fireEvent("beforeclick", this, index, item, e) === false){
4549 if (this.toggleSelect) {
4550 var m = this.isSelected(item) ? 'unselect' : 'select';
4553 _t[m](item, true, false);
4556 if(this.multiSelect || this.singleSelect){
4557 if(this.multiSelect && e.shiftKey && this.lastSelection){
4558 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
4560 this.select(item, this.multiSelect && e.ctrlKey);
4561 this.lastSelection = item;
4573 * Get the number of selected nodes.
4576 getSelectionCount : function(){
4577 return this.selections.length;
4581 * Get the currently selected nodes.
4582 * @return {Array} An array of HTMLElements
4584 getSelectedNodes : function(){
4585 return this.selections;
4589 * Get the indexes of the selected nodes.
4592 getSelectedIndexes : function(){
4593 var indexes = [], s = this.selections;
4594 for(var i = 0, len = s.length; i < len; i++){
4595 indexes.push(s[i].nodeIndex);
4601 * Clear all selections
4602 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
4604 clearSelections : function(suppressEvent){
4605 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
4606 this.cmp.elements = this.selections;
4607 this.cmp.removeClass(this.selectedClass);
4608 this.selections = [];
4610 this.fireEvent("selectionchange", this, this.selections);
4616 * Returns true if the passed node is selected
4617 * @param {HTMLElement/Number} node The node or node index
4620 isSelected : function(node){
4621 var s = this.selections;
4625 node = this.getNode(node);
4626 return s.indexOf(node) !== -1;
4631 * @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
4632 * @param {Boolean} keepExisting (optional) true to keep existing selections
4633 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
4635 select : function(nodeInfo, keepExisting, suppressEvent){
4636 if(nodeInfo instanceof Array){
4638 this.clearSelections(true);
4640 for(var i = 0, len = nodeInfo.length; i < len; i++){
4641 this.select(nodeInfo[i], true, true);
4645 var node = this.getNode(nodeInfo);
4646 if(!node || this.isSelected(node)){
4647 return; // already selected.
4650 this.clearSelections(true);
4653 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
4654 Roo.fly(node).addClass(this.selectedClass);
4655 this.selections.push(node);
4657 this.fireEvent("selectionchange", this, this.selections);
4665 * @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
4666 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
4667 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
4669 unselect : function(nodeInfo, keepExisting, suppressEvent)
4671 if(nodeInfo instanceof Array){
4672 Roo.each(this.selections, function(s) {
4673 this.unselect(s, nodeInfo);
4677 var node = this.getNode(nodeInfo);
4678 if(!node || !this.isSelected(node)){
4679 //Roo.log("not selected");
4680 return; // not selected.
4684 Roo.each(this.selections, function(s) {
4686 Roo.fly(node).removeClass(this.selectedClass);
4693 this.selections= ns;
4694 this.fireEvent("selectionchange", this, this.selections);
4698 * Gets a template node.
4699 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
4700 * @return {HTMLElement} The node or null if it wasn't found
4702 getNode : function(nodeInfo){
4703 if(typeof nodeInfo == "string"){
4704 return document.getElementById(nodeInfo);
4705 }else if(typeof nodeInfo == "number"){
4706 return this.nodes[nodeInfo];
4712 * Gets a range template nodes.
4713 * @param {Number} startIndex
4714 * @param {Number} endIndex
4715 * @return {Array} An array of nodes
4717 getNodes : function(start, end){
4718 var ns = this.nodes;
4720 end = typeof end == "undefined" ? ns.length - 1 : end;
4723 for(var i = start; i <= end; i++){
4727 for(var i = start; i >= end; i--){
4735 * Finds the index of the passed node
4736 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
4737 * @return {Number} The index of the node or -1
4739 indexOf : function(node){
4740 node = this.getNode(node);
4741 if(typeof node.nodeIndex == "number"){
4742 return node.nodeIndex;
4744 var ns = this.nodes;
4745 for(var i = 0, len = ns.length; i < len; i++){
4755 * Ext JS Library 1.1.1
4756 * Copyright(c) 2006-2007, Ext JS, LLC.
4758 * Originally Released Under LGPL - original licence link has changed is not relivant.
4761 * <script type="text/javascript">
4765 * @class Roo.JsonView
4767 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
4769 var view = new Roo.JsonView({
4770 container: "my-element",
4771 tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
4776 // listen for node click?
4777 view.on("click", function(vw, index, node, e){
4778 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
4781 // direct load of JSON data
4782 view.load("foobar.php");
4784 // Example from my blog list
4785 var tpl = new Roo.Template(
4786 '<div class="entry">' +
4787 '<a class="entry-title" href="{link}">{title}</a>' +
4788 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
4789 "</div><hr />"
4792 var moreView = new Roo.JsonView({
4793 container : "entry-list",
4797 moreView.on("beforerender", this.sortEntries, this);
4799 url: "/blog/get-posts.php",
4800 params: "allposts=true",
4801 text: "Loading Blog Entries..."
4805 * Note: old code is supported with arguments : (container, template, config)
4809 * Create a new JsonView
4811 * @param {Object} config The config object
4814 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
4817 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
4819 var um = this.el.getUpdateManager();
4820 um.setRenderer(this);
4821 um.on("update", this.onLoad, this);
4822 um.on("failure", this.onLoadException, this);
4825 * @event beforerender
4826 * Fires before rendering of the downloaded JSON data.
4827 * @param {Roo.JsonView} this
4828 * @param {Object} data The JSON data loaded
4832 * Fires when data is loaded.
4833 * @param {Roo.JsonView} this
4834 * @param {Object} data The JSON data loaded
4835 * @param {Object} response The raw Connect response object
4838 * @event loadexception
4839 * Fires when loading fails.
4840 * @param {Roo.JsonView} this
4841 * @param {Object} response The raw Connect response object
4844 'beforerender' : true,
4846 'loadexception' : true
4849 Roo.extend(Roo.JsonView, Roo.View, {
4851 * @type {String} The root property in the loaded JSON object that contains the data
4856 * Refreshes the view.
4858 refresh : function(){
4859 this.clearSelections();
4862 var o = this.jsonData;
4863 if(o && o.length > 0){
4864 for(var i = 0, len = o.length; i < len; i++){
4865 var data = this.prepareData(o[i], i, o);
4866 html[html.length] = this.tpl.apply(data);
4869 html.push(this.emptyText);
4871 this.el.update(html.join(""));
4872 this.nodes = this.el.dom.childNodes;
4873 this.updateIndexes(0);
4877 * 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.
4878 * @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:
4881 url: "your-url.php",
4882 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
4883 callback: yourFunction,
4884 scope: yourObject, //(optional scope)
4892 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
4893 * 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.
4894 * @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}
4895 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
4896 * @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.
4899 var um = this.el.getUpdateManager();
4900 um.update.apply(um, arguments);
4903 // note - render is a standard framework call...
4904 // using it for the response is really flaky... - it's called by UpdateManager normally, except when called by the XComponent/addXtype.
4905 render : function(el, response){
4907 this.clearSelections();
4911 if (response != '') {
4912 o = Roo.util.JSON.decode(response.responseText);
4915 o = o[this.jsonRoot];
4921 * The current JSON data or null
4924 this.beforeRender();
4929 * Get the number of records in the current JSON dataset
4932 getCount : function(){
4933 return this.jsonData ? this.jsonData.length : 0;
4937 * Returns the JSON object for the specified node(s)
4938 * @param {HTMLElement/Array} node The node or an array of nodes
4939 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
4940 * you get the JSON object for the node
4942 getNodeData : function(node){
4943 if(node instanceof Array){
4945 for(var i = 0, len = node.length; i < len; i++){
4946 data.push(this.getNodeData(node[i]));
4950 return this.jsonData[this.indexOf(node)] || null;
4953 beforeRender : function(){
4954 this.snapshot = this.jsonData;
4956 this.sort.apply(this, this.sortInfo);
4958 this.fireEvent("beforerender", this, this.jsonData);
4961 onLoad : function(el, o){
4962 this.fireEvent("load", this, this.jsonData, o);
4965 onLoadException : function(el, o){
4966 this.fireEvent("loadexception", this, o);
4970 * Filter the data by a specific property.
4971 * @param {String} property A property on your JSON objects
4972 * @param {String/RegExp} value Either string that the property values
4973 * should start with, or a RegExp to test against the property
4975 filter : function(property, value){
4978 var ss = this.snapshot;
4979 if(typeof value == "string"){
4980 var vlen = value.length;
4985 value = value.toLowerCase();
4986 for(var i = 0, len = ss.length; i < len; i++){
4988 if(o[property].substr(0, vlen).toLowerCase() == value){
4992 } else if(value.exec){ // regex?
4993 for(var i = 0, len = ss.length; i < len; i++){
4995 if(value.test(o[property])){
5002 this.jsonData = data;
5008 * Filter by a function. The passed function will be called with each
5009 * object in the current dataset. If the function returns true the value is kept,
5010 * otherwise it is filtered.
5011 * @param {Function} fn
5012 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
5014 filterBy : function(fn, scope){
5017 var ss = this.snapshot;
5018 for(var i = 0, len = ss.length; i < len; i++){
5020 if(fn.call(scope || this, o)){
5024 this.jsonData = data;
5030 * Clears the current filter.
5032 clearFilter : function(){
5033 if(this.snapshot && this.jsonData != this.snapshot){
5034 this.jsonData = this.snapshot;
5041 * Sorts the data for this view and refreshes it.
5042 * @param {String} property A property on your JSON objects to sort on
5043 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
5044 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
5046 sort : function(property, dir, sortType){
5047 this.sortInfo = Array.prototype.slice.call(arguments, 0);
5050 var dsc = dir && dir.toLowerCase() == "desc";
5051 var f = function(o1, o2){
5052 var v1 = sortType ? sortType(o1[p]) : o1[p];
5053 var v2 = sortType ? sortType(o2[p]) : o2[p];
5056 return dsc ? +1 : -1;
5058 return dsc ? -1 : +1;
5063 this.jsonData.sort(f);
5065 if(this.jsonData != this.snapshot){
5066 this.snapshot.sort(f);
5072 * Ext JS Library 1.1.1
5073 * Copyright(c) 2006-2007, Ext JS, LLC.
5075 * Originally Released Under LGPL - original licence link has changed is not relivant.
5078 * <script type="text/javascript">
5083 * @class Roo.ColorPalette
5084 * @extends Roo.Component
5085 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
5086 * Here's an example of typical usage:
5088 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
5089 cp.render('my-div');
5091 cp.on('select', function(palette, selColor){
5092 // do something with selColor
5096 * Create a new ColorPalette
5097 * @param {Object} config The config object
5099 Roo.ColorPalette = function(config){
5100 Roo.ColorPalette.superclass.constructor.call(this, config);
5104 * Fires when a color is selected
5105 * @param {ColorPalette} this
5106 * @param {String} color The 6-digit color hex code (without the # symbol)
5112 this.on("select", this.handler, this.scope, true);
5115 Roo.extend(Roo.ColorPalette, Roo.Component, {
5117 * @cfg {String} itemCls
5118 * The CSS class to apply to the containing element (defaults to "x-color-palette")
5120 itemCls : "x-color-palette",
5122 * @cfg {String} value
5123 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
5124 * the hex codes are case-sensitive.
5129 ctype: "Roo.ColorPalette",
5132 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
5134 allowReselect : false,
5137 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
5138 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
5139 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
5140 * of colors with the width setting until the box is symmetrical.</p>
5141 * <p>You can override individual colors if needed:</p>
5143 var cp = new Roo.ColorPalette();
5144 cp.colors[0] = "FF0000"; // change the first box to red
5147 Or you can provide a custom array of your own for complete control:
5149 var cp = new Roo.ColorPalette();
5150 cp.colors = ["000000", "993300", "333300"];
5155 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
5156 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
5157 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
5158 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
5159 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
5163 onRender : function(container, position){
5164 var t = new Roo.MasterTemplate(
5165 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
5167 var c = this.colors;
5168 for(var i = 0, len = c.length; i < len; i++){
5171 var el = document.createElement("div");
5172 el.className = this.itemCls;
5174 container.dom.insertBefore(el, position);
5175 this.el = Roo.get(el);
5176 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
5177 if(this.clickEvent != 'click'){
5178 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
5183 afterRender : function(){
5184 Roo.ColorPalette.superclass.afterRender.call(this);
5193 handleClick : function(e, t){
5196 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
5197 this.select(c.toUpperCase());
5202 * Selects the specified color in the palette (fires the select event)
5203 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
5205 select : function(color){
5206 color = color.replace("#", "");
5207 if(color != this.value || this.allowReselect){
5210 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
5212 el.child("a.color-"+color).addClass("x-color-palette-sel");
5214 this.fireEvent("select", this, color);
5219 * Ext JS Library 1.1.1
5220 * Copyright(c) 2006-2007, Ext JS, LLC.
5222 * Originally Released Under LGPL - original licence link has changed is not relivant.
5225 * <script type="text/javascript">
5229 * @class Roo.DatePicker
5230 * @extends Roo.Component
5231 * Simple date picker class.
5233 * Create a new DatePicker
5234 * @param {Object} config The config object
5236 Roo.DatePicker = function(config){
5237 Roo.DatePicker.superclass.constructor.call(this, config);
5239 this.value = config && config.value ?
5240 config.value.clearTime() : new Date().clearTime();
5245 * Fires when a date is selected
5246 * @param {DatePicker} this
5247 * @param {Date} date The selected date
5251 * @event monthchange
5252 * Fires when the displayed month changes
5253 * @param {DatePicker} this
5254 * @param {Date} date The selected month
5260 this.on("select", this.handler, this.scope || this);
5262 // build the disabledDatesRE
5263 if(!this.disabledDatesRE && this.disabledDates){
5264 var dd = this.disabledDates;
5266 for(var i = 0; i < dd.length; i++){
5268 if(i != dd.length-1) {
5272 this.disabledDatesRE = new RegExp(re + ")");
5276 Roo.extend(Roo.DatePicker, Roo.Component, {
5278 * @cfg {String} todayText
5279 * The text to display on the button that selects the current date (defaults to "Today")
5281 todayText : "Today",
5283 * @cfg {String} okText
5284 * The text to display on the ok button
5286 okText : " OK ", //   to give the user extra clicking room
5288 * @cfg {String} cancelText
5289 * The text to display on the cancel button
5291 cancelText : "Cancel",
5293 * @cfg {String} todayTip
5294 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
5296 todayTip : "{0} (Spacebar)",
5298 * @cfg {Date} minDate
5299 * Minimum allowable date (JavaScript date object, defaults to null)
5303 * @cfg {Date} maxDate
5304 * Maximum allowable date (JavaScript date object, defaults to null)
5308 * @cfg {String} minText
5309 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
5311 minText : "This date is before the minimum date",
5313 * @cfg {String} maxText
5314 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
5316 maxText : "This date is after the maximum date",
5318 * @cfg {String} format
5319 * The default date format string which can be overriden for localization support. The format must be
5320 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
5324 * @cfg {Array} disabledDays
5325 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
5327 disabledDays : null,
5329 * @cfg {String} disabledDaysText
5330 * The tooltip to display when the date falls on a disabled day (defaults to "")
5332 disabledDaysText : "",
5334 * @cfg {RegExp} disabledDatesRE
5335 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
5337 disabledDatesRE : null,
5339 * @cfg {String} disabledDatesText
5340 * The tooltip text to display when the date falls on a disabled date (defaults to "")
5342 disabledDatesText : "",
5344 * @cfg {Boolean} constrainToViewport
5345 * True to constrain the date picker to the viewport (defaults to true)
5347 constrainToViewport : true,
5349 * @cfg {Array} monthNames
5350 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
5352 monthNames : Date.monthNames,
5354 * @cfg {Array} dayNames
5355 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
5357 dayNames : Date.dayNames,
5359 * @cfg {String} nextText
5360 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
5362 nextText: 'Next Month (Control+Right)',
5364 * @cfg {String} prevText
5365 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
5367 prevText: 'Previous Month (Control+Left)',
5369 * @cfg {String} monthYearText
5370 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
5372 monthYearText: 'Choose a month (Control+Up/Down to move years)',
5374 * @cfg {Number} startDay
5375 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
5379 * @cfg {Bool} showClear
5380 * Show a clear button (usefull for date form elements that can be blank.)
5386 * Sets the value of the date field
5387 * @param {Date} value The date to set
5389 setValue : function(value){
5390 var old = this.value;
5392 if (typeof(value) == 'string') {
5394 value = Date.parseDate(value, this.format);
5400 this.value = value.clearTime(true);
5402 this.update(this.value);
5407 * Gets the current selected value of the date field
5408 * @return {Date} The selected date
5410 getValue : function(){
5417 this.update(this.activeDate);
5422 onRender : function(container, position){
5425 '<table cellspacing="0">',
5426 '<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>',
5427 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
5428 var dn = this.dayNames;
5429 for(var i = 0; i < 7; i++){
5430 var d = this.startDay+i;
5434 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
5436 m[m.length] = "</tr></thead><tbody><tr>";
5437 for(var i = 0; i < 42; i++) {
5438 if(i % 7 == 0 && i != 0){
5439 m[m.length] = "</tr><tr>";
5441 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
5443 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
5444 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
5446 var el = document.createElement("div");
5447 el.className = "x-date-picker";
5448 el.innerHTML = m.join("");
5450 container.dom.insertBefore(el, position);
5452 this.el = Roo.get(el);
5453 this.eventEl = Roo.get(el.firstChild);
5455 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
5456 handler: this.showPrevMonth,
5458 preventDefault:true,
5462 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
5463 handler: this.showNextMonth,
5465 preventDefault:true,
5469 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
5471 this.monthPicker = this.el.down('div.x-date-mp');
5472 this.monthPicker.enableDisplayMode('block');
5474 var kn = new Roo.KeyNav(this.eventEl, {
5475 "left" : function(e){
5477 this.showPrevMonth() :
5478 this.update(this.activeDate.add("d", -1));
5481 "right" : function(e){
5483 this.showNextMonth() :
5484 this.update(this.activeDate.add("d", 1));
5489 this.showNextYear() :
5490 this.update(this.activeDate.add("d", -7));
5493 "down" : function(e){
5495 this.showPrevYear() :
5496 this.update(this.activeDate.add("d", 7));
5499 "pageUp" : function(e){
5500 this.showNextMonth();
5503 "pageDown" : function(e){
5504 this.showPrevMonth();
5507 "enter" : function(e){
5508 e.stopPropagation();
5515 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
5517 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
5519 this.el.unselectable();
5521 this.cells = this.el.select("table.x-date-inner tbody td");
5522 this.textNodes = this.el.query("table.x-date-inner tbody span");
5524 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
5526 tooltip: this.monthYearText
5529 this.mbtn.on('click', this.showMonthPicker, this);
5530 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
5533 var today = (new Date()).dateFormat(this.format);
5535 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
5536 if (this.showClear) {
5537 baseTb.add( new Roo.Toolbar.Fill());
5540 text: String.format(this.todayText, today),
5541 tooltip: String.format(this.todayTip, today),
5542 handler: this.selectToday,
5546 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
5549 if (this.showClear) {
5551 baseTb.add( new Roo.Toolbar.Fill());
5554 cls: 'x-btn-icon x-btn-clear',
5555 handler: function() {
5557 this.fireEvent("select", this, '');
5567 this.update(this.value);
5570 createMonthPicker : function(){
5571 if(!this.monthPicker.dom.firstChild){
5572 var buf = ['<table border="0" cellspacing="0">'];
5573 for(var i = 0; i < 6; i++){
5575 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
5576 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
5578 '<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>' :
5579 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
5583 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
5585 '</button><button type="button" class="x-date-mp-cancel">',
5587 '</button></td></tr>',
5590 this.monthPicker.update(buf.join(''));
5591 this.monthPicker.on('click', this.onMonthClick, this);
5592 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
5594 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
5595 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
5597 this.mpMonths.each(function(m, a, i){
5600 m.dom.xmonth = 5 + Math.round(i * .5);
5602 m.dom.xmonth = Math.round((i-1) * .5);
5608 showMonthPicker : function(){
5609 this.createMonthPicker();
5610 var size = this.el.getSize();
5611 this.monthPicker.setSize(size);
5612 this.monthPicker.child('table').setSize(size);
5614 this.mpSelMonth = (this.activeDate || this.value).getMonth();
5615 this.updateMPMonth(this.mpSelMonth);
5616 this.mpSelYear = (this.activeDate || this.value).getFullYear();
5617 this.updateMPYear(this.mpSelYear);
5619 this.monthPicker.slideIn('t', {duration:.2});
5622 updateMPYear : function(y){
5624 var ys = this.mpYears.elements;
5625 for(var i = 1; i <= 10; i++){
5626 var td = ys[i-1], y2;
5628 y2 = y + Math.round(i * .5);
5629 td.firstChild.innerHTML = y2;
5632 y2 = y - (5-Math.round(i * .5));
5633 td.firstChild.innerHTML = y2;
5636 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
5640 updateMPMonth : function(sm){
5641 this.mpMonths.each(function(m, a, i){
5642 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
5646 selectMPMonth: function(m){
5650 onMonthClick : function(e, t){
5652 var el = new Roo.Element(t), pn;
5653 if(el.is('button.x-date-mp-cancel')){
5654 this.hideMonthPicker();
5656 else if(el.is('button.x-date-mp-ok')){
5657 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
5658 this.hideMonthPicker();
5660 else if(pn = el.up('td.x-date-mp-month', 2)){
5661 this.mpMonths.removeClass('x-date-mp-sel');
5662 pn.addClass('x-date-mp-sel');
5663 this.mpSelMonth = pn.dom.xmonth;
5665 else if(pn = el.up('td.x-date-mp-year', 2)){
5666 this.mpYears.removeClass('x-date-mp-sel');
5667 pn.addClass('x-date-mp-sel');
5668 this.mpSelYear = pn.dom.xyear;
5670 else if(el.is('a.x-date-mp-prev')){
5671 this.updateMPYear(this.mpyear-10);
5673 else if(el.is('a.x-date-mp-next')){
5674 this.updateMPYear(this.mpyear+10);
5678 onMonthDblClick : function(e, t){
5680 var el = new Roo.Element(t), pn;
5681 if(pn = el.up('td.x-date-mp-month', 2)){
5682 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
5683 this.hideMonthPicker();
5685 else if(pn = el.up('td.x-date-mp-year', 2)){
5686 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
5687 this.hideMonthPicker();
5691 hideMonthPicker : function(disableAnim){
5692 if(this.monthPicker){
5693 if(disableAnim === true){
5694 this.monthPicker.hide();
5696 this.monthPicker.slideOut('t', {duration:.2});
5702 showPrevMonth : function(e){
5703 this.update(this.activeDate.add("mo", -1));
5707 showNextMonth : function(e){
5708 this.update(this.activeDate.add("mo", 1));
5712 showPrevYear : function(){
5713 this.update(this.activeDate.add("y", -1));
5717 showNextYear : function(){
5718 this.update(this.activeDate.add("y", 1));
5722 handleMouseWheel : function(e){
5723 var delta = e.getWheelDelta();
5725 this.showPrevMonth();
5727 } else if(delta < 0){
5728 this.showNextMonth();
5734 handleDateClick : function(e, t){
5736 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
5737 this.setValue(new Date(t.dateValue));
5738 this.fireEvent("select", this, this.value);
5743 selectToday : function(){
5744 this.setValue(new Date().clearTime());
5745 this.fireEvent("select", this, this.value);
5749 update : function(date)
5751 var vd = this.activeDate;
5752 this.activeDate = date;
5754 var t = date.getTime();
5755 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
5756 this.cells.removeClass("x-date-selected");
5757 this.cells.each(function(c){
5758 if(c.dom.firstChild.dateValue == t){
5759 c.addClass("x-date-selected");
5760 setTimeout(function(){
5761 try{c.dom.firstChild.focus();}catch(e){}
5770 var days = date.getDaysInMonth();
5771 var firstOfMonth = date.getFirstDateOfMonth();
5772 var startingPos = firstOfMonth.getDay()-this.startDay;
5774 if(startingPos <= this.startDay){
5778 var pm = date.add("mo", -1);
5779 var prevStart = pm.getDaysInMonth()-startingPos;
5781 var cells = this.cells.elements;
5782 var textEls = this.textNodes;
5783 days += startingPos;
5785 // convert everything to numbers so it's fast
5787 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
5788 var today = new Date().clearTime().getTime();
5789 var sel = date.clearTime().getTime();
5790 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
5791 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
5792 var ddMatch = this.disabledDatesRE;
5793 var ddText = this.disabledDatesText;
5794 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
5795 var ddaysText = this.disabledDaysText;
5796 var format = this.format;
5798 var setCellClass = function(cal, cell){
5800 var t = d.getTime();
5801 cell.firstChild.dateValue = t;
5803 cell.className += " x-date-today";
5804 cell.title = cal.todayText;
5807 cell.className += " x-date-selected";
5808 setTimeout(function(){
5809 try{cell.firstChild.focus();}catch(e){}
5814 cell.className = " x-date-disabled";
5815 cell.title = cal.minText;
5819 cell.className = " x-date-disabled";
5820 cell.title = cal.maxText;
5824 if(ddays.indexOf(d.getDay()) != -1){
5825 cell.title = ddaysText;
5826 cell.className = " x-date-disabled";
5829 if(ddMatch && format){
5830 var fvalue = d.dateFormat(format);
5831 if(ddMatch.test(fvalue)){
5832 cell.title = ddText.replace("%0", fvalue);
5833 cell.className = " x-date-disabled";
5839 for(; i < startingPos; i++) {
5840 textEls[i].innerHTML = (++prevStart);
5841 d.setDate(d.getDate()+1);
5842 cells[i].className = "x-date-prevday";
5843 setCellClass(this, cells[i]);
5845 for(; i < days; i++){
5846 intDay = i - startingPos + 1;
5847 textEls[i].innerHTML = (intDay);
5848 d.setDate(d.getDate()+1);
5849 cells[i].className = "x-date-active";
5850 setCellClass(this, cells[i]);
5853 for(; i < 42; i++) {
5854 textEls[i].innerHTML = (++extraDays);
5855 d.setDate(d.getDate()+1);
5856 cells[i].className = "x-date-nextday";
5857 setCellClass(this, cells[i]);
5860 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
5861 this.fireEvent('monthchange', this, date);
5863 if(!this.internalRender){
5864 var main = this.el.dom.firstChild;
5865 var w = main.offsetWidth;
5866 this.el.setWidth(w + this.el.getBorderWidth("lr"));
5867 Roo.fly(main).setWidth(w);
5868 this.internalRender = true;
5869 // opera does not respect the auto grow header center column
5870 // then, after it gets a width opera refuses to recalculate
5871 // without a second pass
5872 if(Roo.isOpera && !this.secondPass){
5873 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
5874 this.secondPass = true;
5875 this.update.defer(10, this, [date]);
5883 * Ext JS Library 1.1.1
5884 * Copyright(c) 2006-2007, Ext JS, LLC.
5886 * Originally Released Under LGPL - original licence link has changed is not relivant.
5889 * <script type="text/javascript">
5892 * @class Roo.TabPanel
5893 * @extends Roo.util.Observable
5894 * A lightweight tab container.
5898 // basic tabs 1, built from existing content
5899 var tabs = new Roo.TabPanel("tabs1");
5900 tabs.addTab("script", "View Script");
5901 tabs.addTab("markup", "View Markup");
5902 tabs.activate("script");
5904 // more advanced tabs, built from javascript
5905 var jtabs = new Roo.TabPanel("jtabs");
5906 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
5908 // set up the UpdateManager
5909 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
5910 var updater = tab2.getUpdateManager();
5911 updater.setDefaultUrl("ajax1.htm");
5912 tab2.on('activate', updater.refresh, updater, true);
5914 // Use setUrl for Ajax loading
5915 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
5916 tab3.setUrl("ajax2.htm", null, true);
5919 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
5922 jtabs.activate("jtabs-1");
5925 * Create a new TabPanel.
5926 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
5927 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
5929 Roo.TabPanel = function(container, config){
5931 * The container element for this TabPanel.
5934 this.el = Roo.get(container, true);
5936 if(typeof config == "boolean"){
5937 this.tabPosition = config ? "bottom" : "top";
5939 Roo.apply(this, config);
5942 if(this.tabPosition == "bottom"){
5943 this.bodyEl = Roo.get(this.createBody(this.el.dom));
5944 this.el.addClass("x-tabs-bottom");
5946 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
5947 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
5948 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
5950 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
5952 if(this.tabPosition != "bottom"){
5953 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
5956 this.bodyEl = Roo.get(this.createBody(this.el.dom));
5957 this.el.addClass("x-tabs-top");
5961 this.bodyEl.setStyle("position", "relative");
5964 this.activateDelegate = this.activate.createDelegate(this);
5969 * Fires when the active tab changes
5970 * @param {Roo.TabPanel} this
5971 * @param {Roo.TabPanelItem} activePanel The new active tab
5975 * @event beforetabchange
5976 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
5977 * @param {Roo.TabPanel} this
5978 * @param {Object} e Set cancel to true on this object to cancel the tab change
5979 * @param {Roo.TabPanelItem} tab The tab being changed to
5981 "beforetabchange" : true
5984 Roo.EventManager.onWindowResize(this.onResize, this);
5985 this.cpad = this.el.getPadding("lr");
5986 this.hiddenCount = 0;
5989 // toolbar on the tabbar support...
5991 var tcfg = this.toolbar;
5992 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
5993 this.toolbar = new Roo.Toolbar(tcfg);
5995 var tbl = tcfg.container.child('table', true);
5996 tbl.setAttribute('width', '100%');
6003 Roo.TabPanel.superclass.constructor.call(this);
6006 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
6008 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
6010 tabPosition : "top",
6012 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
6014 currentTabWidth : 0,
6016 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
6020 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
6024 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
6026 preferredTabWidth : 175,
6028 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
6032 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
6034 monitorResize : true,
6036 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
6041 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
6042 * @param {String} id The id of the div to use <b>or create</b>
6043 * @param {String} text The text for the tab
6044 * @param {String} content (optional) Content to put in the TabPanelItem body
6045 * @param {Boolean} closable (optional) True to create a close icon on the tab
6046 * @return {Roo.TabPanelItem} The created TabPanelItem
6048 addTab : function(id, text, content, closable){
6049 var item = new Roo.TabPanelItem(this, id, text, closable);
6050 this.addTabItem(item);
6052 item.setContent(content);
6058 * Returns the {@link Roo.TabPanelItem} with the specified id/index
6059 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
6060 * @return {Roo.TabPanelItem}
6062 getTab : function(id){
6063 return this.items[id];
6067 * Hides the {@link Roo.TabPanelItem} with the specified id/index
6068 * @param {String/Number} id The id or index of the TabPanelItem to hide.
6070 hideTab : function(id){
6071 var t = this.items[id];
6075 this.autoSizeTabs();
6080 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
6081 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
6083 unhideTab : function(id){
6084 var t = this.items[id];
6088 this.autoSizeTabs();
6093 * Adds an existing {@link Roo.TabPanelItem}.
6094 * @param {Roo.TabPanelItem} item The TabPanelItem to add
6096 addTabItem : function(item){
6097 this.items[item.id] = item;
6098 this.items.push(item);
6099 if(this.resizeTabs){
6100 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
6101 this.autoSizeTabs();
6108 * Removes a {@link Roo.TabPanelItem}.
6109 * @param {String/Number} id The id or index of the TabPanelItem to remove.
6111 removeTab : function(id){
6112 var items = this.items;
6113 var tab = items[id];
6114 if(!tab) { return; }
6115 var index = items.indexOf(tab);
6116 if(this.active == tab && items.length > 1){
6117 var newTab = this.getNextAvailable(index);
6122 this.stripEl.dom.removeChild(tab.pnode.dom);
6123 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
6124 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
6126 items.splice(index, 1);
6127 delete this.items[tab.id];
6128 tab.fireEvent("close", tab);
6129 tab.purgeListeners();
6130 this.autoSizeTabs();
6133 getNextAvailable : function(start){
6134 var items = this.items;
6136 // look for a next tab that will slide over to
6137 // replace the one being removed
6138 while(index < items.length){
6139 var item = items[++index];
6140 if(item && !item.isHidden()){
6144 // if one isn't found select the previous tab (on the left)
6147 var item = items[--index];
6148 if(item && !item.isHidden()){
6156 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
6157 * @param {String/Number} id The id or index of the TabPanelItem to disable.
6159 disableTab : function(id){
6160 var tab = this.items[id];
6161 if(tab && this.active != tab){
6167 * Enables a {@link Roo.TabPanelItem} that is disabled.
6168 * @param {String/Number} id The id or index of the TabPanelItem to enable.
6170 enableTab : function(id){
6171 var tab = this.items[id];
6176 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
6177 * @param {String/Number} id The id or index of the TabPanelItem to activate.
6178 * @return {Roo.TabPanelItem} The TabPanelItem.
6180 activate : function(id){
6181 var tab = this.items[id];
6185 if(tab == this.active || tab.disabled){
6189 this.fireEvent("beforetabchange", this, e, tab);
6190 if(e.cancel !== true && !tab.disabled){
6194 this.active = this.items[id];
6196 this.fireEvent("tabchange", this, this.active);
6202 * Gets the active {@link Roo.TabPanelItem}.
6203 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
6205 getActiveTab : function(){
6210 * Updates the tab body element to fit the height of the container element
6211 * for overflow scrolling
6212 * @param {Number} targetHeight (optional) Override the starting height from the elements height
6214 syncHeight : function(targetHeight){
6215 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
6216 var bm = this.bodyEl.getMargins();
6217 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
6218 this.bodyEl.setHeight(newHeight);
6222 onResize : function(){
6223 if(this.monitorResize){
6224 this.autoSizeTabs();
6229 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
6231 beginUpdate : function(){
6232 this.updating = true;
6236 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
6238 endUpdate : function(){
6239 this.updating = false;
6240 this.autoSizeTabs();
6244 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
6246 autoSizeTabs : function(){
6247 var count = this.items.length;
6248 var vcount = count - this.hiddenCount;
6249 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
6252 var w = Math.max(this.el.getWidth() - this.cpad, 10);
6253 var availWidth = Math.floor(w / vcount);
6254 var b = this.stripBody;
6255 if(b.getWidth() > w){
6256 var tabs = this.items;
6257 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
6258 if(availWidth < this.minTabWidth){
6259 /*if(!this.sleft){ // incomplete scrolling code
6260 this.createScrollButtons();
6263 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
6266 if(this.currentTabWidth < this.preferredTabWidth){
6267 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
6273 * Returns the number of tabs in this TabPanel.
6276 getCount : function(){
6277 return this.items.length;
6281 * Resizes all the tabs to the passed width
6282 * @param {Number} The new width
6284 setTabWidth : function(width){
6285 this.currentTabWidth = width;
6286 for(var i = 0, len = this.items.length; i < len; i++) {
6287 if(!this.items[i].isHidden()) {
6288 this.items[i].setWidth(width);
6294 * Destroys this TabPanel
6295 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
6297 destroy : function(removeEl){
6298 Roo.EventManager.removeResizeListener(this.onResize, this);
6299 for(var i = 0, len = this.items.length; i < len; i++){
6300 this.items[i].purgeListeners();
6302 if(removeEl === true){
6310 * @class Roo.TabPanelItem
6311 * @extends Roo.util.Observable
6312 * Represents an individual item (tab plus body) in a TabPanel.
6313 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
6314 * @param {String} id The id of this TabPanelItem
6315 * @param {String} text The text for the tab of this TabPanelItem
6316 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
6318 Roo.TabPanelItem = function(tabPanel, id, text, closable){
6320 * The {@link Roo.TabPanel} this TabPanelItem belongs to
6321 * @type Roo.TabPanel
6323 this.tabPanel = tabPanel;
6325 * The id for this TabPanelItem
6330 this.disabled = false;
6334 this.loaded = false;
6335 this.closable = closable;
6338 * The body element for this TabPanelItem.
6341 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
6342 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
6343 this.bodyEl.setStyle("display", "block");
6344 this.bodyEl.setStyle("zoom", "1");
6347 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
6349 this.el = Roo.get(els.el, true);
6350 this.inner = Roo.get(els.inner, true);
6351 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
6352 this.pnode = Roo.get(els.el.parentNode, true);
6353 this.el.on("mousedown", this.onTabMouseDown, this);
6354 this.el.on("click", this.onTabClick, this);
6357 var c = Roo.get(els.close, true);
6358 c.dom.title = this.closeText;
6359 c.addClassOnOver("close-over");
6360 c.on("click", this.closeClick, this);
6366 * Fires when this tab becomes the active tab.
6367 * @param {Roo.TabPanel} tabPanel The parent TabPanel
6368 * @param {Roo.TabPanelItem} this
6372 * @event beforeclose
6373 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
6374 * @param {Roo.TabPanelItem} this
6375 * @param {Object} e Set cancel to true on this object to cancel the close.
6377 "beforeclose": true,
6380 * Fires when this tab is closed.
6381 * @param {Roo.TabPanelItem} this
6386 * Fires when this tab is no longer the active tab.
6387 * @param {Roo.TabPanel} tabPanel The parent TabPanel
6388 * @param {Roo.TabPanelItem} this
6392 this.hidden = false;
6394 Roo.TabPanelItem.superclass.constructor.call(this);
6397 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
6398 purgeListeners : function(){
6399 Roo.util.Observable.prototype.purgeListeners.call(this);
6400 this.el.removeAllListeners();
6403 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
6406 this.pnode.addClass("on");
6409 this.tabPanel.stripWrap.repaint();
6411 this.fireEvent("activate", this.tabPanel, this);
6415 * Returns true if this tab is the active tab.
6418 isActive : function(){
6419 return this.tabPanel.getActiveTab() == this;
6423 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
6426 this.pnode.removeClass("on");
6428 this.fireEvent("deactivate", this.tabPanel, this);
6431 hideAction : function(){
6433 this.bodyEl.setStyle("position", "absolute");
6434 this.bodyEl.setLeft("-20000px");
6435 this.bodyEl.setTop("-20000px");
6438 showAction : function(){
6439 this.bodyEl.setStyle("position", "relative");
6440 this.bodyEl.setTop("");
6441 this.bodyEl.setLeft("");
6446 * Set the tooltip for the tab.
6447 * @param {String} tooltip The tab's tooltip
6449 setTooltip : function(text){
6450 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
6451 this.textEl.dom.qtip = text;
6452 this.textEl.dom.removeAttribute('title');
6454 this.textEl.dom.title = text;
6458 onTabClick : function(e){
6460 this.tabPanel.activate(this.id);
6463 onTabMouseDown : function(e){
6465 this.tabPanel.activate(this.id);
6468 getWidth : function(){
6469 return this.inner.getWidth();
6472 setWidth : function(width){
6473 var iwidth = width - this.pnode.getPadding("lr");
6474 this.inner.setWidth(iwidth);
6475 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
6476 this.pnode.setWidth(width);
6480 * Show or hide the tab
6481 * @param {Boolean} hidden True to hide or false to show.
6483 setHidden : function(hidden){
6484 this.hidden = hidden;
6485 this.pnode.setStyle("display", hidden ? "none" : "");
6489 * Returns true if this tab is "hidden"
6492 isHidden : function(){
6497 * Returns the text for this tab
6500 getText : function(){
6504 autoSize : function(){
6505 //this.el.beginMeasure();
6506 this.textEl.setWidth(1);
6508 * #2804 [new] Tabs in Roojs
6509 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
6511 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
6512 //this.el.endMeasure();
6516 * Sets the text for the tab (Note: this also sets the tooltip text)
6517 * @param {String} text The tab's text and tooltip
6519 setText : function(text){
6521 this.textEl.update(text);
6522 this.setTooltip(text);
6523 if(!this.tabPanel.resizeTabs){
6528 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
6530 activate : function(){
6531 this.tabPanel.activate(this.id);
6535 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
6537 disable : function(){
6538 if(this.tabPanel.active != this){
6539 this.disabled = true;
6540 this.pnode.addClass("disabled");
6545 * Enables this TabPanelItem if it was previously disabled.
6547 enable : function(){
6548 this.disabled = false;
6549 this.pnode.removeClass("disabled");
6553 * Sets the content for this TabPanelItem.
6554 * @param {String} content The content
6555 * @param {Boolean} loadScripts true to look for and load scripts
6557 setContent : function(content, loadScripts){
6558 this.bodyEl.update(content, loadScripts);
6562 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
6563 * @return {Roo.UpdateManager} The UpdateManager
6565 getUpdateManager : function(){
6566 return this.bodyEl.getUpdateManager();
6570 * Set a URL to be used to load the content for this TabPanelItem.
6571 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
6572 * @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)
6573 * @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)
6574 * @return {Roo.UpdateManager} The UpdateManager
6576 setUrl : function(url, params, loadOnce){
6577 if(this.refreshDelegate){
6578 this.un('activate', this.refreshDelegate);
6580 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
6581 this.on("activate", this.refreshDelegate);
6582 return this.bodyEl.getUpdateManager();
6586 _handleRefresh : function(url, params, loadOnce){
6587 if(!loadOnce || !this.loaded){
6588 var updater = this.bodyEl.getUpdateManager();
6589 updater.update(url, params, this._setLoaded.createDelegate(this));
6594 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
6595 * Will fail silently if the setUrl method has not been called.
6596 * This does not activate the panel, just updates its content.
6598 refresh : function(){
6599 if(this.refreshDelegate){
6600 this.loaded = false;
6601 this.refreshDelegate();
6606 _setLoaded : function(){
6611 closeClick : function(e){
6614 this.fireEvent("beforeclose", this, o);
6615 if(o.cancel !== true){
6616 this.tabPanel.removeTab(this.id);
6620 * The text displayed in the tooltip for the close icon.
6623 closeText : "Close this tab"
6627 Roo.TabPanel.prototype.createStrip = function(container){
6628 var strip = document.createElement("div");
6629 strip.className = "x-tabs-wrap";
6630 container.appendChild(strip);
6634 Roo.TabPanel.prototype.createStripList = function(strip){
6635 // div wrapper for retard IE
6636 // returns the "tr" element.
6637 strip.innerHTML = '<div class="x-tabs-strip-wrap">'+
6638 '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
6639 '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
6640 return strip.firstChild.firstChild.firstChild.firstChild;
6643 Roo.TabPanel.prototype.createBody = function(container){
6644 var body = document.createElement("div");
6645 Roo.id(body, "tab-body");
6646 Roo.fly(body).addClass("x-tabs-body");
6647 container.appendChild(body);
6651 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
6652 var body = Roo.getDom(id);
6654 body = document.createElement("div");
6657 Roo.fly(body).addClass("x-tabs-item-body");
6658 bodyEl.insertBefore(body, bodyEl.firstChild);
6662 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
6663 var td = document.createElement("td");
6664 stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
6665 //stripEl.appendChild(td);
6667 td.className = "x-tabs-closable";
6669 this.closeTpl = new Roo.Template(
6670 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
6671 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
6672 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
6675 var el = this.closeTpl.overwrite(td, {"text": text});
6676 var close = el.getElementsByTagName("div")[0];
6677 var inner = el.getElementsByTagName("em")[0];
6678 return {"el": el, "close": close, "inner": inner};
6681 this.tabTpl = new Roo.Template(
6682 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
6683 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
6686 var el = this.tabTpl.overwrite(td, {"text": text});
6687 var inner = el.getElementsByTagName("em")[0];
6688 return {"el": el, "inner": inner};
6692 * Ext JS Library 1.1.1
6693 * Copyright(c) 2006-2007, Ext JS, LLC.
6695 * Originally Released Under LGPL - original licence link has changed is not relivant.
6698 * <script type="text/javascript">
6703 * @extends Roo.util.Observable
6704 * Simple Button class
6705 * @cfg {String} text The button text
6706 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
6707 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
6708 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
6709 * @cfg {Object} scope The scope of the handler
6710 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
6711 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
6712 * @cfg {Boolean} hidden True to start hidden (defaults to false)
6713 * @cfg {Boolean} disabled True to start disabled (defaults to false)
6714 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
6715 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
6716 applies if enableToggle = true)
6717 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
6718 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
6719 an {@link Roo.util.ClickRepeater} config object (defaults to false).
6721 * Create a new button
6722 * @param {Object} config The config object
6724 Roo.Button = function(renderTo, config)
6728 renderTo = config.renderTo || false;
6731 Roo.apply(this, config);
6735 * Fires when this button is clicked
6736 * @param {Button} this
6737 * @param {EventObject} e The click event
6742 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
6743 * @param {Button} this
6744 * @param {Boolean} pressed
6749 * Fires when the mouse hovers over the button
6750 * @param {Button} this
6751 * @param {Event} e The event object
6756 * Fires when the mouse exits the button
6757 * @param {Button} this
6758 * @param {Event} e The event object
6763 * Fires when the button is rendered
6764 * @param {Button} this
6769 this.menu = Roo.menu.MenuMgr.get(this.menu);
6771 // register listeners first!! - so render can be captured..
6772 Roo.util.Observable.call(this);
6774 this.render(renderTo);
6780 Roo.extend(Roo.Button, Roo.util.Observable, {
6786 * Read-only. True if this button is hidden
6791 * Read-only. True if this button is disabled
6796 * Read-only. True if this button is pressed (only if enableToggle = true)
6802 * @cfg {Number} tabIndex
6803 * The DOM tabIndex for this button (defaults to undefined)
6805 tabIndex : undefined,
6808 * @cfg {Boolean} enableToggle
6809 * True to enable pressed/not pressed toggling (defaults to false)
6811 enableToggle: false,
6814 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
6818 * @cfg {String} menuAlign
6819 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
6821 menuAlign : "tl-bl?",
6824 * @cfg {String} iconCls
6825 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
6827 iconCls : undefined,
6829 * @cfg {String} type
6830 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
6835 menuClassTarget: 'tr',
6838 * @cfg {String} clickEvent
6839 * The type of event to map to the button's event handler (defaults to 'click')
6841 clickEvent : 'click',
6844 * @cfg {Boolean} handleMouseEvents
6845 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
6847 handleMouseEvents : true,
6850 * @cfg {String} tooltipType
6851 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
6853 tooltipType : 'qtip',
6857 * A CSS class to apply to the button's main element.
6861 * @cfg {Roo.Template} template (Optional)
6862 * An {@link Roo.Template} with which to create the Button's main element. This Template must
6863 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
6864 * require code modifications if required elements (e.g. a button) aren't present.
6868 render : function(renderTo){
6870 if(this.hideParent){
6871 this.parentEl = Roo.get(renderTo);
6875 if(!Roo.Button.buttonTemplate){
6876 // hideous table template
6877 Roo.Button.buttonTemplate = new Roo.Template(
6878 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
6879 '<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>',
6880 "</tr></tbody></table>");
6882 this.template = Roo.Button.buttonTemplate;
6884 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
6885 var btnEl = btn.child("button:first");
6886 btnEl.on('focus', this.onFocus, this);
6887 btnEl.on('blur', this.onBlur, this);
6889 btn.addClass(this.cls);
6892 btnEl.setStyle('background-image', 'url(' +this.icon +')');
6895 btnEl.addClass(this.iconCls);
6897 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
6900 if(this.tabIndex !== undefined){
6901 btnEl.dom.tabIndex = this.tabIndex;
6904 if(typeof this.tooltip == 'object'){
6905 Roo.QuickTips.tips(Roo.apply({
6909 btnEl.dom[this.tooltipType] = this.tooltip;
6913 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
6917 this.el.dom.id = this.el.id = this.id;
6920 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
6921 this.menu.on("show", this.onMenuShow, this);
6922 this.menu.on("hide", this.onMenuHide, this);
6924 btn.addClass("x-btn");
6925 if(Roo.isIE && !Roo.isIE7){
6926 this.autoWidth.defer(1, this);
6930 if(this.handleMouseEvents){
6931 btn.on("mouseover", this.onMouseOver, this);
6932 btn.on("mouseout", this.onMouseOut, this);
6933 btn.on("mousedown", this.onMouseDown, this);
6935 btn.on(this.clickEvent, this.onClick, this);
6936 //btn.on("mouseup", this.onMouseUp, this);
6943 Roo.ButtonToggleMgr.register(this);
6945 this.el.addClass("x-btn-pressed");
6948 var repeater = new Roo.util.ClickRepeater(btn,
6949 typeof this.repeat == "object" ? this.repeat : {}
6951 repeater.on("click", this.onClick, this);
6954 this.fireEvent('render', this);
6958 * Returns the button's underlying element
6959 * @return {Roo.Element} The element
6966 * Destroys this Button and removes any listeners.
6968 destroy : function(){
6969 Roo.ButtonToggleMgr.unregister(this);
6970 this.el.removeAllListeners();
6971 this.purgeListeners();
6976 autoWidth : function(){
6978 this.el.setWidth("auto");
6979 if(Roo.isIE7 && Roo.isStrict){
6980 var ib = this.el.child('button');
6981 if(ib && ib.getWidth() > 20){
6983 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
6988 this.el.beginMeasure();
6990 if(this.el.getWidth() < this.minWidth){
6991 this.el.setWidth(this.minWidth);
6994 this.el.endMeasure();
7001 * Assigns this button's click handler
7002 * @param {Function} handler The function to call when the button is clicked
7003 * @param {Object} scope (optional) Scope for the function passed in
7005 setHandler : function(handler, scope){
7006 this.handler = handler;
7011 * Sets this button's text
7012 * @param {String} text The button text
7014 setText : function(text){
7017 this.el.child("td.x-btn-center button.x-btn-text").update(text);
7023 * Gets the text for this button
7024 * @return {String} The button text
7026 getText : function(){
7034 this.hidden = false;
7036 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
7046 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
7051 * Convenience function for boolean show/hide
7052 * @param {Boolean} visible True to show, false to hide
7054 setVisible: function(visible){
7063 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
7064 * @param {Boolean} state (optional) Force a particular state
7066 toggle : function(state){
7067 state = state === undefined ? !this.pressed : state;
7068 if(state != this.pressed){
7070 this.el.addClass("x-btn-pressed");
7071 this.pressed = true;
7072 this.fireEvent("toggle", this, true);
7074 this.el.removeClass("x-btn-pressed");
7075 this.pressed = false;
7076 this.fireEvent("toggle", this, false);
7078 if(this.toggleHandler){
7079 this.toggleHandler.call(this.scope || this, this, state);
7088 this.el.child('button:first').focus();
7092 * Disable this button
7094 disable : function(){
7096 this.el.addClass("x-btn-disabled");
7098 this.disabled = true;
7102 * Enable this button
7104 enable : function(){
7106 this.el.removeClass("x-btn-disabled");
7108 this.disabled = false;
7112 * Convenience function for boolean enable/disable
7113 * @param {Boolean} enabled True to enable, false to disable
7115 setDisabled : function(v){
7116 this[v !== true ? "enable" : "disable"]();
7120 onClick : function(e)
7129 if(this.enableToggle){
7132 if(this.menu && !this.menu.isVisible()){
7133 this.menu.show(this.el, this.menuAlign);
7135 this.fireEvent("click", this, e);
7137 this.el.removeClass("x-btn-over");
7138 this.handler.call(this.scope || this, this, e);
7143 onMouseOver : function(e){
7145 this.el.addClass("x-btn-over");
7146 this.fireEvent('mouseover', this, e);
7150 onMouseOut : function(e){
7151 if(!e.within(this.el, true)){
7152 this.el.removeClass("x-btn-over");
7153 this.fireEvent('mouseout', this, e);
7157 onFocus : function(e){
7159 this.el.addClass("x-btn-focus");
7163 onBlur : function(e){
7164 this.el.removeClass("x-btn-focus");
7167 onMouseDown : function(e){
7168 if(!this.disabled && e.button == 0){
7169 this.el.addClass("x-btn-click");
7170 Roo.get(document).on('mouseup', this.onMouseUp, this);
7174 onMouseUp : function(e){
7176 this.el.removeClass("x-btn-click");
7177 Roo.get(document).un('mouseup', this.onMouseUp, this);
7181 onMenuShow : function(e){
7182 this.el.addClass("x-btn-menu-active");
7185 onMenuHide : function(e){
7186 this.el.removeClass("x-btn-menu-active");
7190 // Private utility class used by Button
7191 Roo.ButtonToggleMgr = function(){
7194 function toggleGroup(btn, state){
7196 var g = groups[btn.toggleGroup];
7197 for(var i = 0, l = g.length; i < l; i++){
7206 register : function(btn){
7207 if(!btn.toggleGroup){
7210 var g = groups[btn.toggleGroup];
7212 g = groups[btn.toggleGroup] = [];
7215 btn.on("toggle", toggleGroup);
7218 unregister : function(btn){
7219 if(!btn.toggleGroup){
7222 var g = groups[btn.toggleGroup];
7225 btn.un("toggle", toggleGroup);
7231 * Ext JS Library 1.1.1
7232 * Copyright(c) 2006-2007, Ext JS, LLC.
7234 * Originally Released Under LGPL - original licence link has changed is not relivant.
7237 * <script type="text/javascript">
7241 * @class Roo.SplitButton
7242 * @extends Roo.Button
7243 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
7244 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
7245 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
7246 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
7247 * @cfg {String} arrowTooltip The title attribute of the arrow
7249 * Create a new menu button
7250 * @param {String/HTMLElement/Element} renderTo The element to append the button to
7251 * @param {Object} config The config object
7253 Roo.SplitButton = function(renderTo, config){
7254 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
7257 * Fires when this button's arrow is clicked
7258 * @param {SplitButton} this
7259 * @param {EventObject} e The click event
7261 this.addEvents({"arrowclick":true});
7264 Roo.extend(Roo.SplitButton, Roo.Button, {
7265 render : function(renderTo){
7266 // this is one sweet looking template!
7267 var tpl = new Roo.Template(
7268 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
7269 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
7270 '<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>',
7271 "</tbody></table></td><td>",
7272 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
7273 '<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>',
7274 "</tbody></table></td></tr></table>"
7276 var btn = tpl.append(renderTo, [this.text, this.type], true);
7277 var btnEl = btn.child("button");
7279 btn.addClass(this.cls);
7282 btnEl.setStyle('background-image', 'url(' +this.icon +')');
7285 btnEl.addClass(this.iconCls);
7287 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
7291 if(this.handleMouseEvents){
7292 btn.on("mouseover", this.onMouseOver, this);
7293 btn.on("mouseout", this.onMouseOut, this);
7294 btn.on("mousedown", this.onMouseDown, this);
7295 btn.on("mouseup", this.onMouseUp, this);
7297 btn.on(this.clickEvent, this.onClick, this);
7299 if(typeof this.tooltip == 'object'){
7300 Roo.QuickTips.tips(Roo.apply({
7304 btnEl.dom[this.tooltipType] = this.tooltip;
7307 if(this.arrowTooltip){
7308 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
7317 this.el.addClass("x-btn-pressed");
7319 if(Roo.isIE && !Roo.isIE7){
7320 this.autoWidth.defer(1, this);
7325 this.menu.on("show", this.onMenuShow, this);
7326 this.menu.on("hide", this.onMenuHide, this);
7328 this.fireEvent('render', this);
7332 autoWidth : function(){
7334 var tbl = this.el.child("table:first");
7335 var tbl2 = this.el.child("table:last");
7336 this.el.setWidth("auto");
7337 tbl.setWidth("auto");
7338 if(Roo.isIE7 && Roo.isStrict){
7339 var ib = this.el.child('button:first');
7340 if(ib && ib.getWidth() > 20){
7342 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
7347 this.el.beginMeasure();
7349 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
7350 tbl.setWidth(this.minWidth-tbl2.getWidth());
7353 this.el.endMeasure();
7356 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
7360 * Sets this button's click handler
7361 * @param {Function} handler The function to call when the button is clicked
7362 * @param {Object} scope (optional) Scope for the function passed above
7364 setHandler : function(handler, scope){
7365 this.handler = handler;
7370 * Sets this button's arrow click handler
7371 * @param {Function} handler The function to call when the arrow is clicked
7372 * @param {Object} scope (optional) Scope for the function passed above
7374 setArrowHandler : function(handler, scope){
7375 this.arrowHandler = handler;
7384 this.el.child("button:first").focus();
7389 onClick : function(e){
7392 if(e.getTarget(".x-btn-menu-arrow-wrap")){
7393 if(this.menu && !this.menu.isVisible()){
7394 this.menu.show(this.el, this.menuAlign);
7396 this.fireEvent("arrowclick", this, e);
7397 if(this.arrowHandler){
7398 this.arrowHandler.call(this.scope || this, this, e);
7401 this.fireEvent("click", this, e);
7403 this.handler.call(this.scope || this, this, e);
7409 onMouseDown : function(e){
7411 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
7415 onMouseUp : function(e){
7416 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
7422 Roo.MenuButton = Roo.SplitButton;/*
7424 * Ext JS Library 1.1.1
7425 * Copyright(c) 2006-2007, Ext JS, LLC.
7427 * Originally Released Under LGPL - original licence link has changed is not relivant.
7430 * <script type="text/javascript">
7434 * @class Roo.Toolbar
7435 * Basic Toolbar class.
7437 * Creates a new Toolbar
7438 * @param {Object} container The config object
7440 Roo.Toolbar = function(container, buttons, config)
7442 /// old consturctor format still supported..
7443 if(container instanceof Array){ // omit the container for later rendering
7444 buttons = container;
7448 if (typeof(container) == 'object' && container.xtype) {
7450 container = config.container;
7451 buttons = config.buttons || []; // not really - use items!!
7454 if (config && config.items) {
7455 xitems = config.items;
7456 delete config.items;
7458 Roo.apply(this, config);
7459 this.buttons = buttons;
7462 this.render(container);
7464 this.xitems = xitems;
7465 Roo.each(xitems, function(b) {
7471 Roo.Toolbar.prototype = {
7473 * @cfg {Array} items
7474 * array of button configs or elements to add (will be converted to a MixedCollection)
7478 * @cfg {String/HTMLElement/Element} container
7479 * The id or element that will contain the toolbar
7482 render : function(ct){
7483 this.el = Roo.get(ct);
7485 this.el.addClass(this.cls);
7487 // using a table allows for vertical alignment
7488 // 100% width is needed by Safari...
7489 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
7490 this.tr = this.el.child("tr", true);
7492 this.items = new Roo.util.MixedCollection(false, function(o){
7493 return o.id || ("item" + (++autoId));
7496 this.add.apply(this, this.buttons);
7497 delete this.buttons;
7502 * Adds element(s) to the toolbar -- this function takes a variable number of
7503 * arguments of mixed type and adds them to the toolbar.
7504 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
7506 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
7507 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
7508 * <li>Field: Any form field (equivalent to {@link #addField})</li>
7509 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
7510 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
7511 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
7512 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
7513 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
7514 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
7516 * @param {Mixed} arg2
7517 * @param {Mixed} etc.
7520 var a = arguments, l = a.length;
7521 for(var i = 0; i < l; i++){
7526 _add : function(el) {
7529 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
7532 if (el.applyTo){ // some kind of form field
7533 return this.addField(el);
7535 if (el.render){ // some kind of Toolbar.Item
7536 return this.addItem(el);
7538 if (typeof el == "string"){ // string
7539 if(el == "separator" || el == "-"){
7540 return this.addSeparator();
7543 return this.addSpacer();
7546 return this.addFill();
7548 return this.addText(el);
7551 if(el.tagName){ // element
7552 return this.addElement(el);
7554 if(typeof el == "object"){ // must be button config?
7555 return this.addButton(el);
7563 * Add an Xtype element
7564 * @param {Object} xtype Xtype Object
7565 * @return {Object} created Object
7567 addxtype : function(e){
7572 * Returns the Element for this toolbar.
7573 * @return {Roo.Element}
7581 * @return {Roo.Toolbar.Item} The separator item
7583 addSeparator : function(){
7584 return this.addItem(new Roo.Toolbar.Separator());
7588 * Adds a spacer element
7589 * @return {Roo.Toolbar.Spacer} The spacer item
7591 addSpacer : function(){
7592 return this.addItem(new Roo.Toolbar.Spacer());
7596 * Adds a fill element that forces subsequent additions to the right side of the toolbar
7597 * @return {Roo.Toolbar.Fill} The fill item
7599 addFill : function(){
7600 return this.addItem(new Roo.Toolbar.Fill());
7604 * Adds any standard HTML element to the toolbar
7605 * @param {String/HTMLElement/Element} el The element or id of the element to add
7606 * @return {Roo.Toolbar.Item} The element's item
7608 addElement : function(el){
7609 return this.addItem(new Roo.Toolbar.Item(el));
7612 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
7613 * @type Roo.util.MixedCollection
7618 * Adds any Toolbar.Item or subclass
7619 * @param {Roo.Toolbar.Item} item
7620 * @return {Roo.Toolbar.Item} The item
7622 addItem : function(item){
7623 var td = this.nextBlock();
7625 this.items.add(item);
7630 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
7631 * @param {Object/Array} config A button config or array of configs
7632 * @return {Roo.Toolbar.Button/Array}
7634 addButton : function(config){
7635 if(config instanceof Array){
7637 for(var i = 0, len = config.length; i < len; i++) {
7638 buttons.push(this.addButton(config[i]));
7643 if(!(config instanceof Roo.Toolbar.Button)){
7645 new Roo.Toolbar.SplitButton(config) :
7646 new Roo.Toolbar.Button(config);
7648 var td = this.nextBlock();
7655 * Adds text to the toolbar
7656 * @param {String} text The text to add
7657 * @return {Roo.Toolbar.Item} The element's item
7659 addText : function(text){
7660 return this.addItem(new Roo.Toolbar.TextItem(text));
7664 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
7665 * @param {Number} index The index where the item is to be inserted
7666 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
7667 * @return {Roo.Toolbar.Button/Item}
7669 insertButton : function(index, item){
7670 if(item instanceof Array){
7672 for(var i = 0, len = item.length; i < len; i++) {
7673 buttons.push(this.insertButton(index + i, item[i]));
7677 if (!(item instanceof Roo.Toolbar.Button)){
7678 item = new Roo.Toolbar.Button(item);
7680 var td = document.createElement("td");
7681 this.tr.insertBefore(td, this.tr.childNodes[index]);
7683 this.items.insert(index, item);
7688 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
7689 * @param {Object} config
7690 * @return {Roo.Toolbar.Item} The element's item
7692 addDom : function(config, returnEl){
7693 var td = this.nextBlock();
7694 Roo.DomHelper.overwrite(td, config);
7695 var ti = new Roo.Toolbar.Item(td.firstChild);
7702 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
7703 * @type Roo.util.MixedCollection
7708 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc).
7709 * Note: the field should not have been rendered yet. For a field that has already been
7710 * rendered, use {@link #addElement}.
7711 * @param {Roo.form.Field} field
7712 * @return {Roo.ToolbarItem}
7716 addField : function(field) {
7719 this.fields = new Roo.util.MixedCollection(false, function(o){
7720 return o.id || ("item" + (++autoId));
7725 var td = this.nextBlock();
7727 var ti = new Roo.Toolbar.Item(td.firstChild);
7730 this.fields.add(field);
7741 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
7742 this.el.child('div').hide();
7750 this.el.child('div').show();
7754 nextBlock : function(){
7755 var td = document.createElement("td");
7756 this.tr.appendChild(td);
7761 destroy : function(){
7762 if(this.items){ // rendered?
7763 Roo.destroy.apply(Roo, this.items.items);
7765 if(this.fields){ // rendered?
7766 Roo.destroy.apply(Roo, this.fields.items);
7768 Roo.Element.uncache(this.el, this.tr);
7773 * @class Roo.Toolbar.Item
7774 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
7776 * Creates a new Item
7777 * @param {HTMLElement} el
7779 Roo.Toolbar.Item = function(el){
7781 if (typeof (el.xtype) != 'undefined') {
7786 this.el = Roo.getDom(el);
7787 this.id = Roo.id(this.el);
7788 this.hidden = false;
7793 * Fires when the button is rendered
7794 * @param {Button} this
7798 Roo.Toolbar.Item.superclass.constructor.call(this,cfg);
7800 Roo.extend(Roo.Toolbar.Item, Roo.util.Observable, {
7801 //Roo.Toolbar.Item.prototype = {
7804 * Get this item's HTML Element
7805 * @return {HTMLElement}
7812 render : function(td){
7815 td.appendChild(this.el);
7817 this.fireEvent('render', this);
7821 * Removes and destroys this item.
7823 destroy : function(){
7824 this.td.parentNode.removeChild(this.td);
7831 this.hidden = false;
7832 this.td.style.display = "";
7840 this.td.style.display = "none";
7844 * Convenience function for boolean show/hide.
7845 * @param {Boolean} visible true to show/false to hide
7847 setVisible: function(visible){
7856 * Try to focus this item.
7859 Roo.fly(this.el).focus();
7863 * Disables this item.
7865 disable : function(){
7866 Roo.fly(this.td).addClass("x-item-disabled");
7867 this.disabled = true;
7868 this.el.disabled = true;
7872 * Enables this item.
7874 enable : function(){
7875 Roo.fly(this.td).removeClass("x-item-disabled");
7876 this.disabled = false;
7877 this.el.disabled = false;
7883 * @class Roo.Toolbar.Separator
7884 * @extends Roo.Toolbar.Item
7885 * A simple toolbar separator class
7887 * Creates a new Separator
7889 Roo.Toolbar.Separator = function(cfg){
7891 var s = document.createElement("span");
7892 s.className = "ytb-sep";
7897 Roo.Toolbar.Separator.superclass.constructor.call(this, cfg || s);
7899 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
7901 disable:Roo.emptyFn,
7906 * @class Roo.Toolbar.Spacer
7907 * @extends Roo.Toolbar.Item
7908 * A simple element that adds extra horizontal space to a toolbar.
7910 * Creates a new Spacer
7912 Roo.Toolbar.Spacer = function(cfg){
7913 var s = document.createElement("div");
7914 s.className = "ytb-spacer";
7918 Roo.Toolbar.Spacer.superclass.constructor.call(this, cfg || s);
7920 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
7922 disable:Roo.emptyFn,
7927 * @class Roo.Toolbar.Fill
7928 * @extends Roo.Toolbar.Spacer
7929 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
7931 * Creates a new Spacer
7933 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
7935 render : function(td){
7936 td.style.width = '100%';
7937 Roo.Toolbar.Fill.superclass.render.call(this, td);
7942 * @class Roo.Toolbar.TextItem
7943 * @extends Roo.Toolbar.Item
7944 * A simple class that renders text directly into a toolbar.
7946 * Creates a new TextItem
7947 * @param {String} text
7949 Roo.Toolbar.TextItem = function(cfg){
7950 var text = cfg || "";
7951 if (typeof(cfg) == 'object') {
7952 text = cfg.text || "";
7956 var s = document.createElement("span");
7957 s.className = "ytb-text";
7963 Roo.Toolbar.TextItem.superclass.constructor.call(this, cfg || s);
7965 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
7969 disable:Roo.emptyFn,
7974 * @class Roo.Toolbar.Button
7975 * @extends Roo.Button
7976 * A button that renders into a toolbar.
7978 * Creates a new Button
7979 * @param {Object} config A standard {@link Roo.Button} config object
7981 Roo.Toolbar.Button = function(config){
7982 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
7984 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
7985 render : function(td){
7987 Roo.Toolbar.Button.superclass.render.call(this, td);
7991 * Removes and destroys this button
7993 destroy : function(){
7994 Roo.Toolbar.Button.superclass.destroy.call(this);
7995 this.td.parentNode.removeChild(this.td);
8002 this.hidden = false;
8003 this.td.style.display = "";
8011 this.td.style.display = "none";
8015 * Disables this item
8017 disable : function(){
8018 Roo.fly(this.td).addClass("x-item-disabled");
8019 this.disabled = true;
8025 enable : function(){
8026 Roo.fly(this.td).removeClass("x-item-disabled");
8027 this.disabled = false;
8031 Roo.ToolbarButton = Roo.Toolbar.Button;
8034 * @class Roo.Toolbar.SplitButton
8035 * @extends Roo.SplitButton
8036 * A menu button that renders into a toolbar.
8038 * Creates a new SplitButton
8039 * @param {Object} config A standard {@link Roo.SplitButton} config object
8041 Roo.Toolbar.SplitButton = function(config){
8042 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
8044 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
8045 render : function(td){
8047 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
8051 * Removes and destroys this button
8053 destroy : function(){
8054 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
8055 this.td.parentNode.removeChild(this.td);
8062 this.hidden = false;
8063 this.td.style.display = "";
8071 this.td.style.display = "none";
8076 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
8078 * Ext JS Library 1.1.1
8079 * Copyright(c) 2006-2007, Ext JS, LLC.
8081 * Originally Released Under LGPL - original licence link has changed is not relivant.
8084 * <script type="text/javascript">
8088 * @class Roo.PagingToolbar
8089 * @extends Roo.Toolbar
8090 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
8092 * Create a new PagingToolbar
8093 * @param {Object} config The config object
8095 Roo.PagingToolbar = function(el, ds, config)
8097 // old args format still supported... - xtype is prefered..
8098 if (typeof(el) == 'object' && el.xtype) {
8099 // created from xtype...
8102 el = config.container;
8106 items = config.items;
8110 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
8113 this.renderButtons(this.el);
8116 // supprot items array.
8118 Roo.each(items, function(e) {
8119 this.add(Roo.factory(e));
8124 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
8126 * @cfg {Roo.data.Store} dataSource
8127 * The underlying data store providing the paged data
8130 * @cfg {String/HTMLElement/Element} container
8131 * container The id or element that will contain the toolbar
8134 * @cfg {Boolean} displayInfo
8135 * True to display the displayMsg (defaults to false)
8138 * @cfg {Number} pageSize
8139 * The number of records to display per page (defaults to 20)
8143 * @cfg {String} displayMsg
8144 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
8146 displayMsg : 'Displaying {0} - {1} of {2}',
8148 * @cfg {String} emptyMsg
8149 * The message to display when no records are found (defaults to "No data to display")
8151 emptyMsg : 'No data to display',
8153 * Customizable piece of the default paging text (defaults to "Page")
8156 beforePageText : "Page",
8158 * Customizable piece of the default paging text (defaults to "of %0")
8161 afterPageText : "of {0}",
8163 * Customizable piece of the default paging text (defaults to "First Page")
8166 firstText : "First Page",
8168 * Customizable piece of the default paging text (defaults to "Previous Page")
8171 prevText : "Previous Page",
8173 * Customizable piece of the default paging text (defaults to "Next Page")
8176 nextText : "Next Page",
8178 * Customizable piece of the default paging text (defaults to "Last Page")
8181 lastText : "Last Page",
8183 * Customizable piece of the default paging text (defaults to "Refresh")
8186 refreshText : "Refresh",
8189 renderButtons : function(el){
8190 Roo.PagingToolbar.superclass.render.call(this, el);
8191 this.first = this.addButton({
8192 tooltip: this.firstText,
8193 cls: "x-btn-icon x-grid-page-first",
8195 handler: this.onClick.createDelegate(this, ["first"])
8197 this.prev = this.addButton({
8198 tooltip: this.prevText,
8199 cls: "x-btn-icon x-grid-page-prev",
8201 handler: this.onClick.createDelegate(this, ["prev"])
8203 //this.addSeparator();
8204 this.add(this.beforePageText);
8205 this.field = Roo.get(this.addDom({
8210 cls: "x-grid-page-number"
8212 this.field.on("keydown", this.onPagingKeydown, this);
8213 this.field.on("focus", function(){this.dom.select();});
8214 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
8215 this.field.setHeight(18);
8216 //this.addSeparator();
8217 this.next = this.addButton({
8218 tooltip: this.nextText,
8219 cls: "x-btn-icon x-grid-page-next",
8221 handler: this.onClick.createDelegate(this, ["next"])
8223 this.last = this.addButton({
8224 tooltip: this.lastText,
8225 cls: "x-btn-icon x-grid-page-last",
8227 handler: this.onClick.createDelegate(this, ["last"])
8229 //this.addSeparator();
8230 this.loading = this.addButton({
8231 tooltip: this.refreshText,
8232 cls: "x-btn-icon x-grid-loading",
8233 handler: this.onClick.createDelegate(this, ["refresh"])
8236 if(this.displayInfo){
8237 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
8242 updateInfo : function(){
8244 var count = this.ds.getCount();
8245 var msg = count == 0 ?
8249 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
8251 this.displayEl.update(msg);
8256 onLoad : function(ds, r, o){
8257 this.cursor = o.params ? o.params.start : 0;
8258 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
8260 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
8261 this.field.dom.value = ap;
8262 this.first.setDisabled(ap == 1);
8263 this.prev.setDisabled(ap == 1);
8264 this.next.setDisabled(ap == ps);
8265 this.last.setDisabled(ap == ps);
8266 this.loading.enable();
8271 getPageData : function(){
8272 var total = this.ds.getTotalCount();
8275 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
8276 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
8281 onLoadError : function(){
8282 this.loading.enable();
8286 onPagingKeydown : function(e){
8288 var d = this.getPageData();
8290 var v = this.field.dom.value, pageNum;
8291 if(!v || isNaN(pageNum = parseInt(v, 10))){
8292 this.field.dom.value = d.activePage;
8295 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
8296 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
8299 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))
8301 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
8302 this.field.dom.value = pageNum;
8303 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
8306 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
8308 var v = this.field.dom.value, pageNum;
8309 var increment = (e.shiftKey) ? 10 : 1;
8310 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
8313 if(!v || isNaN(pageNum = parseInt(v, 10))) {
8314 this.field.dom.value = d.activePage;
8317 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
8319 this.field.dom.value = parseInt(v, 10) + increment;
8320 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
8321 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
8328 beforeLoad : function(){
8330 this.loading.disable();
8335 onClick : function(which){
8339 ds.load({params:{start: 0, limit: this.pageSize}});
8342 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
8345 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
8348 var total = ds.getTotalCount();
8349 var extra = total % this.pageSize;
8350 var lastStart = extra ? (total - extra) : total-this.pageSize;
8351 ds.load({params:{start: lastStart, limit: this.pageSize}});
8354 ds.load({params:{start: this.cursor, limit: this.pageSize}});
8360 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
8361 * @param {Roo.data.Store} store The data store to unbind
8363 unbind : function(ds){
8364 ds.un("beforeload", this.beforeLoad, this);
8365 ds.un("load", this.onLoad, this);
8366 ds.un("loadexception", this.onLoadError, this);
8367 ds.un("remove", this.updateInfo, this);
8368 ds.un("add", this.updateInfo, this);
8369 this.ds = undefined;
8373 * Binds the paging toolbar to the specified {@link Roo.data.Store}
8374 * @param {Roo.data.Store} store The data store to bind
8376 bind : function(ds){
8377 ds.on("beforeload", this.beforeLoad, this);
8378 ds.on("load", this.onLoad, this);
8379 ds.on("loadexception", this.onLoadError, this);
8380 ds.on("remove", this.updateInfo, this);
8381 ds.on("add", this.updateInfo, this);
8386 * Ext JS Library 1.1.1
8387 * Copyright(c) 2006-2007, Ext JS, LLC.
8389 * Originally Released Under LGPL - original licence link has changed is not relivant.
8392 * <script type="text/javascript">
8396 * @class Roo.Resizable
8397 * @extends Roo.util.Observable
8398 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
8399 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
8400 * 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
8401 * the element will be wrapped for you automatically.</p>
8402 * <p>Here is the list of valid resize handles:</p>
8405 ------ -------------------
8414 'hd' horizontal drag
8417 * <p>Here's an example showing the creation of a typical Resizable:</p>
8419 var resizer = new Roo.Resizable("element-id", {
8427 resizer.on("resize", myHandler);
8429 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
8430 * resizer.east.setDisplayed(false);</p>
8431 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
8432 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
8433 * resize operation's new size (defaults to [0, 0])
8434 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
8435 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
8436 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
8437 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
8438 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
8439 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
8440 * @cfg {Number} width The width of the element in pixels (defaults to null)
8441 * @cfg {Number} height The height of the element in pixels (defaults to null)
8442 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
8443 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
8444 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
8445 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
8446 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
8447 * in favor of the handles config option (defaults to false)
8448 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
8449 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
8450 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
8451 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
8452 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
8453 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
8454 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
8455 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
8456 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
8457 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
8458 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
8460 * Create a new resizable component
8461 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
8462 * @param {Object} config configuration options
8464 Roo.Resizable = function(el, config)
8466 this.el = Roo.get(el);
8468 if(config && config.wrap){
8469 config.resizeChild = this.el;
8470 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
8471 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
8472 this.el.setStyle("overflow", "hidden");
8473 this.el.setPositioning(config.resizeChild.getPositioning());
8474 config.resizeChild.clearPositioning();
8475 if(!config.width || !config.height){
8476 var csize = config.resizeChild.getSize();
8477 this.el.setSize(csize.width, csize.height);
8479 if(config.pinned && !config.adjustments){
8480 config.adjustments = "auto";
8484 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
8485 this.proxy.unselectable();
8486 this.proxy.enableDisplayMode('block');
8488 Roo.apply(this, config);
8491 this.disableTrackOver = true;
8492 this.el.addClass("x-resizable-pinned");
8494 // if the element isn't positioned, make it relative
8495 var position = this.el.getStyle("position");
8496 if(position != "absolute" && position != "fixed"){
8497 this.el.setStyle("position", "relative");
8499 if(!this.handles){ // no handles passed, must be legacy style
8500 this.handles = 's,e,se';
8501 if(this.multiDirectional){
8502 this.handles += ',n,w';
8505 if(this.handles == "all"){
8506 this.handles = "n s e w ne nw se sw";
8508 var hs = this.handles.split(/\s*?[,;]\s*?| /);
8509 var ps = Roo.Resizable.positions;
8510 for(var i = 0, len = hs.length; i < len; i++){
8511 if(hs[i] && ps[hs[i]]){
8512 var pos = ps[hs[i]];
8513 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
8517 this.corner = this.southeast;
8519 // updateBox = the box can move..
8520 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1 || this.handles.indexOf("hd") != -1) {
8521 this.updateBox = true;
8524 this.activeHandle = null;
8526 if(this.resizeChild){
8527 if(typeof this.resizeChild == "boolean"){
8528 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
8530 this.resizeChild = Roo.get(this.resizeChild, true);
8534 if(this.adjustments == "auto"){
8535 var rc = this.resizeChild;
8536 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
8537 if(rc && (hw || hn)){
8538 rc.position("relative");
8539 rc.setLeft(hw ? hw.el.getWidth() : 0);
8540 rc.setTop(hn ? hn.el.getHeight() : 0);
8542 this.adjustments = [
8543 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
8544 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
8549 this.dd = this.dynamic ?
8550 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
8551 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
8557 * @event beforeresize
8558 * Fired before resize is allowed. Set enabled to false to cancel resize.
8559 * @param {Roo.Resizable} this
8560 * @param {Roo.EventObject} e The mousedown event
8562 "beforeresize" : true,
8566 * @param {Roo.Resizable} this
8567 * @param {Number} x The new x position
8568 * @param {Number} y The new y position
8569 * @param {Number} w The new w width
8570 * @param {Number} h The new h hight
8571 * @param {Roo.EventObject} e The mouseup event
8576 * Fired after a resize.
8577 * @param {Roo.Resizable} this
8578 * @param {Number} width The new width
8579 * @param {Number} height The new height
8580 * @param {Roo.EventObject} e The mouseup event
8585 if(this.width !== null && this.height !== null){
8586 this.resizeTo(this.width, this.height);
8588 this.updateChildSize();
8591 this.el.dom.style.zoom = 1;
8593 Roo.Resizable.superclass.constructor.call(this);
8596 Roo.extend(Roo.Resizable, Roo.util.Observable, {
8597 resizeChild : false,
8598 adjustments : [0, 0],
8608 multiDirectional : false,
8609 disableTrackOver : false,
8610 easing : 'easeOutStrong',
8612 heightIncrement : 0,
8616 preserveRatio : false,
8623 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
8625 constrainTo: undefined,
8627 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
8629 resizeRegion: undefined,
8633 * Perform a manual resize
8634 * @param {Number} width
8635 * @param {Number} height
8637 resizeTo : function(width, height){
8638 this.el.setSize(width, height);
8639 this.updateChildSize();
8640 this.fireEvent("resize", this, width, height, null);
8644 startSizing : function(e, handle){
8645 this.fireEvent("beforeresize", this, e);
8646 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
8649 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
8650 this.overlay.unselectable();
8651 this.overlay.enableDisplayMode("block");
8652 this.overlay.on("mousemove", this.onMouseMove, this);
8653 this.overlay.on("mouseup", this.onMouseUp, this);
8655 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
8657 this.resizing = true;
8658 this.startBox = this.el.getBox();
8659 this.startPoint = e.getXY();
8660 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
8661 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
8663 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
8664 this.overlay.show();
8666 if(this.constrainTo) {
8667 var ct = Roo.get(this.constrainTo);
8668 this.resizeRegion = ct.getRegion().adjust(
8669 ct.getFrameWidth('t'),
8670 ct.getFrameWidth('l'),
8671 -ct.getFrameWidth('b'),
8672 -ct.getFrameWidth('r')
8676 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
8678 this.proxy.setBox(this.startBox);
8680 this.proxy.setStyle('visibility', 'visible');
8686 onMouseDown : function(handle, e){
8689 this.activeHandle = handle;
8690 this.startSizing(e, handle);
8695 onMouseUp : function(e){
8696 var size = this.resizeElement();
8697 this.resizing = false;
8699 this.overlay.hide();
8701 this.fireEvent("resize", this, size.width, size.height, e);
8705 updateChildSize : function(){
8707 if(this.resizeChild){
8709 var child = this.resizeChild;
8710 var adj = this.adjustments;
8711 if(el.dom.offsetWidth){
8712 var b = el.getSize(true);
8713 child.setSize(b.width+adj[0], b.height+adj[1]);
8715 // Second call here for IE
8716 // The first call enables instant resizing and
8717 // the second call corrects scroll bars if they
8720 setTimeout(function(){
8721 if(el.dom.offsetWidth){
8722 var b = el.getSize(true);
8723 child.setSize(b.width+adj[0], b.height+adj[1]);
8731 snap : function(value, inc, min){
8732 if(!inc || !value) {
8735 var newValue = value;
8736 var m = value % inc;
8739 newValue = value + (inc-m);
8741 newValue = value - m;
8744 return Math.max(min, newValue);
8748 resizeElement : function(){
8749 var box = this.proxy.getBox();
8751 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
8753 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
8755 this.updateChildSize();
8763 constrain : function(v, diff, m, mx){
8766 }else if(v - diff > mx){
8773 onMouseMove : function(e){
8776 try{// try catch so if something goes wrong the user doesn't get hung
8778 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
8782 //var curXY = this.startPoint;
8783 var curSize = this.curSize || this.startBox;
8784 var x = this.startBox.x, y = this.startBox.y;
8786 var w = curSize.width, h = curSize.height;
8788 var mw = this.minWidth, mh = this.minHeight;
8789 var mxw = this.maxWidth, mxh = this.maxHeight;
8790 var wi = this.widthIncrement;
8791 var hi = this.heightIncrement;
8793 var eventXY = e.getXY();
8794 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
8795 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
8797 var pos = this.activeHandle.position;
8802 w = Math.min(Math.max(mw, w), mxw);
8807 h = Math.min(Math.max(mh, h), mxh);
8812 w = Math.min(Math.max(mw, w), mxw);
8813 h = Math.min(Math.max(mh, h), mxh);
8816 diffY = this.constrain(h, diffY, mh, mxh);
8823 var adiffX = Math.abs(diffX);
8824 var sub = (adiffX % wi); // how much
8825 if (sub > (wi/2)) { // far enough to snap
8826 diffX = (diffX > 0) ? diffX-sub + wi : diffX+sub - wi;
8828 // remove difference..
8829 diffX = (diffX > 0) ? diffX-sub : diffX+sub;
8833 x = Math.max(this.minX, x);
8836 diffX = this.constrain(w, diffX, mw, mxw);
8842 w = Math.min(Math.max(mw, w), mxw);
8843 diffY = this.constrain(h, diffY, mh, mxh);
8848 diffX = this.constrain(w, diffX, mw, mxw);
8849 diffY = this.constrain(h, diffY, mh, mxh);
8856 diffX = this.constrain(w, diffX, mw, mxw);
8858 h = Math.min(Math.max(mh, h), mxh);
8864 var sw = this.snap(w, wi, mw);
8865 var sh = this.snap(h, hi, mh);
8866 if(sw != w || sh != h){
8889 if(this.preserveRatio){
8894 h = Math.min(Math.max(mh, h), mxh);
8899 w = Math.min(Math.max(mw, w), mxw);
8904 w = Math.min(Math.max(mw, w), mxw);
8910 w = Math.min(Math.max(mw, w), mxw);
8916 h = Math.min(Math.max(mh, h), mxh);
8924 h = Math.min(Math.max(mh, h), mxh);
8934 h = Math.min(Math.max(mh, h), mxh);
8942 if (pos == 'hdrag') {
8945 this.proxy.setBounds(x, y, w, h);
8947 this.resizeElement();
8951 this.fireEvent("resizing", this, x, y, w, h, e);
8955 handleOver : function(){
8957 this.el.addClass("x-resizable-over");
8962 handleOut : function(){
8964 this.el.removeClass("x-resizable-over");
8969 * Returns the element this component is bound to.
8970 * @return {Roo.Element}
8977 * Returns the resizeChild element (or null).
8978 * @return {Roo.Element}
8980 getResizeChild : function(){
8981 return this.resizeChild;
8983 groupHandler : function()
8988 * Destroys this resizable. If the element was wrapped and
8989 * removeEl is not true then the element remains.
8990 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
8992 destroy : function(removeEl){
8993 this.proxy.remove();
8995 this.overlay.removeAllListeners();
8996 this.overlay.remove();
8998 var ps = Roo.Resizable.positions;
9000 if(typeof ps[k] != "function" && this[ps[k]]){
9001 var h = this[ps[k]];
9002 h.el.removeAllListeners();
9014 // hash to map config positions to true positions
9015 Roo.Resizable.positions = {
9016 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast",
9021 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
9023 // only initialize the template if resizable is used
9024 var tpl = Roo.DomHelper.createTemplate(
9025 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
9028 Roo.Resizable.Handle.prototype.tpl = tpl;
9030 this.position = pos;
9032 // show north drag fro topdra
9033 var handlepos = pos == 'hdrag' ? 'north' : pos;
9035 this.el = this.tpl.append(rz.el.dom, [handlepos], true);
9036 if (pos == 'hdrag') {
9037 this.el.setStyle('cursor', 'pointer');
9039 this.el.unselectable();
9041 this.el.setOpacity(0);
9043 this.el.on("mousedown", this.onMouseDown, this);
9044 if(!disableTrackOver){
9045 this.el.on("mouseover", this.onMouseOver, this);
9046 this.el.on("mouseout", this.onMouseOut, this);
9051 Roo.Resizable.Handle.prototype = {
9052 afterResize : function(rz){
9057 onMouseDown : function(e){
9058 this.rz.onMouseDown(this, e);
9061 onMouseOver : function(e){
9062 this.rz.handleOver(this, e);
9065 onMouseOut : function(e){
9066 this.rz.handleOut(this, e);
9070 * Ext JS Library 1.1.1
9071 * Copyright(c) 2006-2007, Ext JS, LLC.
9073 * Originally Released Under LGPL - original licence link has changed is not relivant.
9076 * <script type="text/javascript">
9081 * @extends Roo.Component
9082 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
9084 * Create a new Editor
9085 * @param {Roo.form.Field} field The Field object (or descendant)
9086 * @param {Object} config The config object
9088 Roo.Editor = function(field, config){
9089 Roo.Editor.superclass.constructor.call(this, config);
9093 * @event beforestartedit
9094 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
9095 * false from the handler of this event.
9096 * @param {Editor} this
9097 * @param {Roo.Element} boundEl The underlying element bound to this editor
9098 * @param {Mixed} value The field value being set
9100 "beforestartedit" : true,
9103 * Fires when this editor is displayed
9104 * @param {Roo.Element} boundEl The underlying element bound to this editor
9105 * @param {Mixed} value The starting field value
9109 * @event beforecomplete
9110 * Fires after a change has been made to the field, but before the change is reflected in the underlying
9111 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
9112 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
9113 * event will not fire since no edit actually occurred.
9114 * @param {Editor} this
9115 * @param {Mixed} value The current field value
9116 * @param {Mixed} startValue The original field value
9118 "beforecomplete" : true,
9121 * Fires after editing is complete and any changed value has been written to the underlying field.
9122 * @param {Editor} this
9123 * @param {Mixed} value The current field value
9124 * @param {Mixed} startValue The original field value
9129 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
9130 * {@link Roo.EventObject#getKey} to determine which key was pressed.
9131 * @param {Roo.form.Field} this
9132 * @param {Roo.EventObject} e The event object
9138 Roo.extend(Roo.Editor, Roo.Component, {
9140 * @cfg {Boolean/String} autosize
9141 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
9142 * or "height" to adopt the height only (defaults to false)
9145 * @cfg {Boolean} revertInvalid
9146 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
9147 * validation fails (defaults to true)
9150 * @cfg {Boolean} ignoreNoChange
9151 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
9152 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
9153 * will never be ignored.
9156 * @cfg {Boolean} hideEl
9157 * False to keep the bound element visible while the editor is displayed (defaults to true)
9160 * @cfg {Mixed} value
9161 * The data value of the underlying field (defaults to "")
9165 * @cfg {String} alignment
9166 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
9170 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
9171 * for bottom-right shadow (defaults to "frame")
9175 * @cfg {Boolean} constrain True to constrain the editor to the viewport
9179 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
9181 completeOnEnter : false,
9183 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
9185 cancelOnEsc : false,
9187 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
9192 onRender : function(ct, position){
9193 this.el = new Roo.Layer({
9194 shadow: this.shadow,
9200 constrain: this.constrain
9202 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
9203 if(this.field.msgTarget != 'title'){
9204 this.field.msgTarget = 'qtip';
9206 this.field.render(this.el);
9208 this.field.el.dom.setAttribute('autocomplete', 'off');
9210 this.field.on("specialkey", this.onSpecialKey, this);
9211 if(this.swallowKeys){
9212 this.field.el.swallowEvent(['keydown','keypress']);
9215 this.field.on("blur", this.onBlur, this);
9216 if(this.field.grow){
9217 this.field.on("autosize", this.el.sync, this.el, {delay:1});
9221 onSpecialKey : function(field, e)
9223 //Roo.log('editor onSpecialKey');
9224 if(this.completeOnEnter && e.getKey() == e.ENTER){
9226 this.completeEdit();
9229 // do not fire special key otherwise it might hide close the editor...
9230 if(e.getKey() == e.ENTER){
9233 if(this.cancelOnEsc && e.getKey() == e.ESC){
9237 this.fireEvent('specialkey', field, e);
9242 * Starts the editing process and shows the editor.
9243 * @param {String/HTMLElement/Element} el The element to edit
9244 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
9245 * to the innerHTML of el.
9247 startEdit : function(el, value){
9249 this.completeEdit();
9251 this.boundEl = Roo.get(el);
9252 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
9254 this.render(this.parentEl || document.body);
9256 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
9259 this.startValue = v;
9260 this.field.setValue(v);
9262 var sz = this.boundEl.getSize();
9263 switch(this.autoSize){
9265 this.setSize(sz.width, "");
9268 this.setSize("", sz.height);
9271 this.setSize(sz.width, sz.height);
9274 this.el.alignTo(this.boundEl, this.alignment);
9275 this.editing = true;
9277 Roo.QuickTips.disable();
9283 * Sets the height and width of this editor.
9284 * @param {Number} width The new width
9285 * @param {Number} height The new height
9287 setSize : function(w, h){
9288 this.field.setSize(w, h);
9295 * Realigns the editor to the bound field based on the current alignment config value.
9297 realign : function(){
9298 this.el.alignTo(this.boundEl, this.alignment);
9302 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
9303 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
9305 completeEdit : function(remainVisible){
9309 var v = this.getValue();
9310 if(this.revertInvalid !== false && !this.field.isValid()){
9311 v = this.startValue;
9312 this.cancelEdit(true);
9314 if(String(v) === String(this.startValue) && this.ignoreNoChange){
9315 this.editing = false;
9319 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
9320 this.editing = false;
9321 if(this.updateEl && this.boundEl){
9322 this.boundEl.update(v);
9324 if(remainVisible !== true){
9327 this.fireEvent("complete", this, v, this.startValue);
9332 onShow : function(){
9334 if(this.hideEl !== false){
9335 this.boundEl.hide();
9338 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
9339 this.fixIEFocus = true;
9340 this.deferredFocus.defer(50, this);
9344 this.fireEvent("startedit", this.boundEl, this.startValue);
9347 deferredFocus : function(){
9354 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
9355 * reverted to the original starting value.
9356 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
9357 * cancel (defaults to false)
9359 cancelEdit : function(remainVisible){
9361 this.setValue(this.startValue);
9362 if(remainVisible !== true){
9369 onBlur : function(){
9370 if(this.allowBlur !== true && this.editing){
9371 this.completeEdit();
9376 onHide : function(){
9378 this.completeEdit();
9382 if(this.field.collapse){
9383 this.field.collapse();
9386 if(this.hideEl !== false){
9387 this.boundEl.show();
9390 Roo.QuickTips.enable();
9395 * Sets the data value of the editor
9396 * @param {Mixed} value Any valid value supported by the underlying field
9398 setValue : function(v){
9399 this.field.setValue(v);
9403 * Gets the data value of the editor
9404 * @return {Mixed} The data value
9406 getValue : function(){
9407 return this.field.getValue();
9411 * Ext JS Library 1.1.1
9412 * Copyright(c) 2006-2007, Ext JS, LLC.
9414 * Originally Released Under LGPL - original licence link has changed is not relivant.
9417 * <script type="text/javascript">
9421 * @class Roo.BasicDialog
9422 * @extends Roo.util.Observable
9423 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
9425 var dlg = new Roo.BasicDialog("my-dlg", {
9434 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
9435 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
9436 dlg.addButton('Cancel', dlg.hide, dlg);
9439 <b>A Dialog should always be a direct child of the body element.</b>
9440 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
9441 * @cfg {String} title Default text to display in the title bar (defaults to null)
9442 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
9443 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
9444 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
9445 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
9446 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
9447 * (defaults to null with no animation)
9448 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
9449 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
9450 * property for valid values (defaults to 'all')
9451 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
9452 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
9453 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
9454 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
9455 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
9456 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
9457 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
9458 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
9459 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
9460 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
9461 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
9462 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
9463 * draggable = true (defaults to false)
9464 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
9465 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
9466 * shadow (defaults to false)
9467 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
9468 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
9469 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
9470 * @cfg {Array} buttons Array of buttons
9471 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
9473 * Create a new BasicDialog.
9474 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
9475 * @param {Object} config Configuration options
9477 Roo.BasicDialog = function(el, config){
9478 this.el = Roo.get(el);
9479 var dh = Roo.DomHelper;
9480 if(!this.el && config && config.autoCreate){
9481 if(typeof config.autoCreate == "object"){
9482 if(!config.autoCreate.id){
9483 config.autoCreate.id = el;
9485 this.el = dh.append(document.body,
9486 config.autoCreate, true);
9488 this.el = dh.append(document.body,
9489 {tag: "div", id: el, style:'visibility:hidden;'}, true);
9493 el.setDisplayed(true);
9494 el.hide = this.hideAction;
9496 el.addClass("x-dlg");
9498 Roo.apply(this, config);
9500 this.proxy = el.createProxy("x-dlg-proxy");
9501 this.proxy.hide = this.hideAction;
9502 this.proxy.setOpacity(.5);
9506 el.setWidth(config.width);
9509 el.setHeight(config.height);
9511 this.size = el.getSize();
9512 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
9513 this.xy = [config.x,config.y];
9515 this.xy = el.getCenterXY(true);
9517 /** The header element @type Roo.Element */
9518 this.header = el.child("> .x-dlg-hd");
9519 /** The body element @type Roo.Element */
9520 this.body = el.child("> .x-dlg-bd");
9521 /** The footer element @type Roo.Element */
9522 this.footer = el.child("> .x-dlg-ft");
9525 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
9528 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
9531 this.header.unselectable();
9533 this.header.update(this.title);
9535 // this element allows the dialog to be focused for keyboard event
9536 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
9537 this.focusEl.swallowEvent("click", true);
9539 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
9541 // wrap the body and footer for special rendering
9542 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
9544 this.bwrap.dom.appendChild(this.footer.dom);
9547 this.bg = this.el.createChild({
9548 tag: "div", cls:"x-dlg-bg",
9549 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
9551 this.centerBg = this.bg.child("div.x-dlg-bg-center");
9554 if(this.autoScroll !== false && !this.autoTabs){
9555 this.body.setStyle("overflow", "auto");
9558 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
9560 if(this.closable !== false){
9561 this.el.addClass("x-dlg-closable");
9562 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
9563 this.close.on("click", this.closeClick, this);
9564 this.close.addClassOnOver("x-dlg-close-over");
9566 if(this.collapsible !== false){
9567 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
9568 this.collapseBtn.on("click", this.collapseClick, this);
9569 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
9570 this.header.on("dblclick", this.collapseClick, this);
9572 if(this.resizable !== false){
9573 this.el.addClass("x-dlg-resizable");
9574 this.resizer = new Roo.Resizable(el, {
9575 minWidth: this.minWidth || 80,
9576 minHeight:this.minHeight || 80,
9577 handles: this.resizeHandles || "all",
9580 this.resizer.on("beforeresize", this.beforeResize, this);
9581 this.resizer.on("resize", this.onResize, this);
9583 if(this.draggable !== false){
9584 el.addClass("x-dlg-draggable");
9585 if (!this.proxyDrag) {
9586 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
9589 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
9591 dd.setHandleElId(this.header.id);
9592 dd.endDrag = this.endMove.createDelegate(this);
9593 dd.startDrag = this.startMove.createDelegate(this);
9594 dd.onDrag = this.onDrag.createDelegate(this);
9599 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
9600 this.mask.enableDisplayMode("block");
9602 this.el.addClass("x-dlg-modal");
9605 this.shadow = new Roo.Shadow({
9606 mode : typeof this.shadow == "string" ? this.shadow : "sides",
9607 offset : this.shadowOffset
9610 this.shadowOffset = 0;
9612 if(Roo.useShims && this.shim !== false){
9613 this.shim = this.el.createShim();
9614 this.shim.hide = this.hideAction;
9623 var bts= this.buttons;
9625 Roo.each(bts, function(b) {
9634 * Fires when a key is pressed
9635 * @param {Roo.BasicDialog} this
9636 * @param {Roo.EventObject} e
9641 * Fires when this dialog is moved by the user.
9642 * @param {Roo.BasicDialog} this
9643 * @param {Number} x The new page X
9644 * @param {Number} y The new page Y
9649 * Fires when this dialog is resized by the user.
9650 * @param {Roo.BasicDialog} this
9651 * @param {Number} width The new width
9652 * @param {Number} height The new height
9657 * Fires before this dialog is hidden.
9658 * @param {Roo.BasicDialog} this
9660 "beforehide" : true,
9663 * Fires when this dialog is hidden.
9664 * @param {Roo.BasicDialog} this
9669 * Fires before this dialog is shown.
9670 * @param {Roo.BasicDialog} this
9672 "beforeshow" : true,
9675 * Fires when this dialog is shown.
9676 * @param {Roo.BasicDialog} this
9680 el.on("keydown", this.onKeyDown, this);
9681 el.on("mousedown", this.toFront, this);
9682 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
9684 Roo.DialogManager.register(this);
9685 Roo.BasicDialog.superclass.constructor.call(this);
9688 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
9689 shadowOffset: Roo.isIE ? 6 : 5,
9693 defaultButton: null,
9694 buttonAlign: "right",
9699 * Sets the dialog title text
9700 * @param {String} text The title text to display
9701 * @return {Roo.BasicDialog} this
9703 setTitle : function(text){
9704 this.header.update(text);
9709 closeClick : function(){
9714 collapseClick : function(){
9715 this[this.collapsed ? "expand" : "collapse"]();
9719 * Collapses the dialog to its minimized state (only the title bar is visible).
9720 * Equivalent to the user clicking the collapse dialog button.
9722 collapse : function(){
9723 if(!this.collapsed){
9724 this.collapsed = true;
9725 this.el.addClass("x-dlg-collapsed");
9726 this.restoreHeight = this.el.getHeight();
9727 this.resizeTo(this.el.getWidth(), this.header.getHeight());
9732 * Expands a collapsed dialog back to its normal state. Equivalent to the user
9733 * clicking the expand dialog button.
9735 expand : function(){
9737 this.collapsed = false;
9738 this.el.removeClass("x-dlg-collapsed");
9739 this.resizeTo(this.el.getWidth(), this.restoreHeight);
9744 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
9745 * @return {Roo.TabPanel} The tabs component
9747 initTabs : function(){
9748 var tabs = this.getTabs();
9749 while(tabs.getTab(0)){
9752 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
9754 tabs.addTab(Roo.id(dom), dom.title);
9762 beforeResize : function(){
9763 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
9767 onResize : function(){
9769 this.syncBodyHeight();
9770 this.adjustAssets();
9772 this.fireEvent("resize", this, this.size.width, this.size.height);
9776 onKeyDown : function(e){
9777 if(this.isVisible()){
9778 this.fireEvent("keydown", this, e);
9783 * Resizes the dialog.
9784 * @param {Number} width
9785 * @param {Number} height
9786 * @return {Roo.BasicDialog} this
9788 resizeTo : function(width, height){
9789 this.el.setSize(width, height);
9790 this.size = {width: width, height: height};
9791 this.syncBodyHeight();
9792 if(this.fixedcenter){
9795 if(this.isVisible()){
9797 this.adjustAssets();
9799 this.fireEvent("resize", this, width, height);
9805 * Resizes the dialog to fit the specified content size.
9806 * @param {Number} width
9807 * @param {Number} height
9808 * @return {Roo.BasicDialog} this
9810 setContentSize : function(w, h){
9811 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
9812 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
9813 //if(!this.el.isBorderBox()){
9814 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
9815 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
9818 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
9819 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
9821 this.resizeTo(w, h);
9826 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
9827 * executed in response to a particular key being pressed while the dialog is active.
9828 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
9829 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9830 * @param {Function} fn The function to call
9831 * @param {Object} scope (optional) The scope of the function
9832 * @return {Roo.BasicDialog} this
9834 addKeyListener : function(key, fn, scope){
9835 var keyCode, shift, ctrl, alt;
9836 if(typeof key == "object" && !(key instanceof Array)){
9837 keyCode = key["key"];
9838 shift = key["shift"];
9844 var handler = function(dlg, e){
9845 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
9847 if(keyCode instanceof Array){
9848 for(var i = 0, len = keyCode.length; i < len; i++){
9849 if(keyCode[i] == k){
9850 fn.call(scope || window, dlg, k, e);
9856 fn.call(scope || window, dlg, k, e);
9861 this.on("keydown", handler);
9866 * Returns the TabPanel component (creates it if it doesn't exist).
9867 * Note: If you wish to simply check for the existence of tabs without creating them,
9868 * check for a null 'tabs' property.
9869 * @return {Roo.TabPanel} The tabs component
9871 getTabs : function(){
9873 this.el.addClass("x-dlg-auto-tabs");
9874 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
9875 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
9881 * Adds a button to the footer section of the dialog.
9882 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
9883 * object or a valid Roo.DomHelper element config
9884 * @param {Function} handler The function called when the button is clicked
9885 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
9886 * @return {Roo.Button} The new button
9888 addButton : function(config, handler, scope){
9889 var dh = Roo.DomHelper;
9891 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
9893 if(!this.btnContainer){
9894 var tb = this.footer.createChild({
9896 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
9897 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
9899 this.btnContainer = tb.firstChild.firstChild.firstChild;
9904 minWidth: this.minButtonWidth,
9907 if(typeof config == "string"){
9908 bconfig.text = config;
9911 bconfig.dhconfig = config;
9913 Roo.apply(bconfig, config);
9917 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
9918 bconfig.position = Math.max(0, bconfig.position);
9919 fc = this.btnContainer.childNodes[bconfig.position];
9922 var btn = new Roo.Button(
9924 this.btnContainer.insertBefore(document.createElement("td"),fc)
9925 : this.btnContainer.appendChild(document.createElement("td")),
9926 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
9929 this.syncBodyHeight();
9932 * Array of all the buttons that have been added to this dialog via addButton
9937 this.buttons.push(btn);
9942 * Sets the default button to be focused when the dialog is displayed.
9943 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
9944 * @return {Roo.BasicDialog} this
9946 setDefaultButton : function(btn){
9947 this.defaultButton = btn;
9952 getHeaderFooterHeight : function(safe){
9955 height += this.header.getHeight();
9958 var fm = this.footer.getMargins();
9959 height += (this.footer.getHeight()+fm.top+fm.bottom);
9961 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
9962 height += this.centerBg.getPadding("tb");
9967 syncBodyHeight : function()
9969 var bd = this.body, // the text
9970 cb = this.centerBg, // wrapper around bottom.. but does not seem to be used..
9972 var height = this.size.height - this.getHeaderFooterHeight(false);
9973 bd.setHeight(height-bd.getMargins("tb"));
9974 var hh = this.header.getHeight();
9975 var h = this.size.height-hh;
9978 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
9979 bw.setHeight(h-cb.getPadding("tb"));
9981 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
9982 bd.setWidth(bw.getWidth(true));
9984 this.tabs.syncHeight();
9986 this.tabs.el.repaint();
9992 * Restores the previous state of the dialog if Roo.state is configured.
9993 * @return {Roo.BasicDialog} this
9995 restoreState : function(){
9996 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
9997 if(box && box.width){
9998 this.xy = [box.x, box.y];
9999 this.resizeTo(box.width, box.height);
10005 beforeShow : function(){
10007 if(this.fixedcenter){
10008 this.xy = this.el.getCenterXY(true);
10011 Roo.get(document.body).addClass("x-body-masked");
10012 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
10015 this.constrainXY();
10019 animShow : function(){
10020 var b = Roo.get(this.animateTarget).getBox();
10021 this.proxy.setSize(b.width, b.height);
10022 this.proxy.setLocation(b.x, b.y);
10024 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
10025 true, .35, this.showEl.createDelegate(this));
10029 * Shows the dialog.
10030 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
10031 * @return {Roo.BasicDialog} this
10033 show : function(animateTarget){
10034 if (this.fireEvent("beforeshow", this) === false){
10037 if(this.syncHeightBeforeShow){
10038 this.syncBodyHeight();
10039 }else if(this.firstShow){
10040 this.firstShow = false;
10041 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
10043 this.animateTarget = animateTarget || this.animateTarget;
10044 if(!this.el.isVisible()){
10046 if(this.animateTarget && Roo.get(this.animateTarget)){
10056 showEl : function(){
10058 this.el.setXY(this.xy);
10060 this.adjustAssets(true);
10063 // IE peekaboo bug - fix found by Dave Fenwick
10067 this.fireEvent("show", this);
10071 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
10072 * dialog itself will receive focus.
10074 focus : function(){
10075 if(this.defaultButton){
10076 this.defaultButton.focus();
10078 this.focusEl.focus();
10083 constrainXY : function(){
10084 if(this.constraintoviewport !== false){
10085 if(!this.viewSize){
10086 if(this.container){
10087 var s = this.container.getSize();
10088 this.viewSize = [s.width, s.height];
10090 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
10093 var s = Roo.get(this.container||document).getScroll();
10095 var x = this.xy[0], y = this.xy[1];
10096 var w = this.size.width, h = this.size.height;
10097 var vw = this.viewSize[0], vh = this.viewSize[1];
10098 // only move it if it needs it
10100 // first validate right/bottom
10101 if(x + w > vw+s.left){
10105 if(y + h > vh+s.top){
10109 // then make sure top/left isn't negative
10121 if(this.isVisible()){
10122 this.el.setLocation(x, y);
10123 this.adjustAssets();
10130 onDrag : function(){
10131 if(!this.proxyDrag){
10132 this.xy = this.el.getXY();
10133 this.adjustAssets();
10138 adjustAssets : function(doShow){
10139 var x = this.xy[0], y = this.xy[1];
10140 var w = this.size.width, h = this.size.height;
10141 if(doShow === true){
10143 this.shadow.show(this.el);
10149 if(this.shadow && this.shadow.isVisible()){
10150 this.shadow.show(this.el);
10152 if(this.shim && this.shim.isVisible()){
10153 this.shim.setBounds(x, y, w, h);
10158 adjustViewport : function(w, h){
10160 w = Roo.lib.Dom.getViewWidth();
10161 h = Roo.lib.Dom.getViewHeight();
10164 this.viewSize = [w, h];
10165 if(this.modal && this.mask.isVisible()){
10166 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
10167 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
10169 if(this.isVisible()){
10170 this.constrainXY();
10175 * Destroys this dialog and all its supporting elements (including any tabs, shim,
10176 * shadow, proxy, mask, etc.) Also removes all event listeners.
10177 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
10179 destroy : function(removeEl){
10180 if(this.isVisible()){
10181 this.animateTarget = null;
10184 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
10186 this.tabs.destroy(removeEl);
10199 for(var i = 0, len = this.buttons.length; i < len; i++){
10200 this.buttons[i].destroy();
10203 this.el.removeAllListeners();
10204 if(removeEl === true){
10205 this.el.update("");
10208 Roo.DialogManager.unregister(this);
10212 startMove : function(){
10213 if(this.proxyDrag){
10216 if(this.constraintoviewport !== false){
10217 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
10222 endMove : function(){
10223 if(!this.proxyDrag){
10224 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
10226 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
10229 this.refreshSize();
10230 this.adjustAssets();
10232 this.fireEvent("move", this, this.xy[0], this.xy[1]);
10236 * Brings this dialog to the front of any other visible dialogs
10237 * @return {Roo.BasicDialog} this
10239 toFront : function(){
10240 Roo.DialogManager.bringToFront(this);
10245 * Sends this dialog to the back (under) of any other visible dialogs
10246 * @return {Roo.BasicDialog} this
10248 toBack : function(){
10249 Roo.DialogManager.sendToBack(this);
10254 * Centers this dialog in the viewport
10255 * @return {Roo.BasicDialog} this
10257 center : function(){
10258 var xy = this.el.getCenterXY(true);
10259 this.moveTo(xy[0], xy[1]);
10264 * Moves the dialog's top-left corner to the specified point
10265 * @param {Number} x
10266 * @param {Number} y
10267 * @return {Roo.BasicDialog} this
10269 moveTo : function(x, y){
10271 if(this.isVisible()){
10272 this.el.setXY(this.xy);
10273 this.adjustAssets();
10279 * Aligns the dialog to the specified element
10280 * @param {String/HTMLElement/Roo.Element} element The element to align to.
10281 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
10282 * @param {Array} offsets (optional) Offset the positioning by [x, y]
10283 * @return {Roo.BasicDialog} this
10285 alignTo : function(element, position, offsets){
10286 this.xy = this.el.getAlignToXY(element, position, offsets);
10287 if(this.isVisible()){
10288 this.el.setXY(this.xy);
10289 this.adjustAssets();
10295 * Anchors an element to another element and realigns it when the window is resized.
10296 * @param {String/HTMLElement/Roo.Element} element The element to align to.
10297 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
10298 * @param {Array} offsets (optional) Offset the positioning by [x, y]
10299 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
10300 * is a number, it is used as the buffer delay (defaults to 50ms).
10301 * @return {Roo.BasicDialog} this
10303 anchorTo : function(el, alignment, offsets, monitorScroll){
10304 var action = function(){
10305 this.alignTo(el, alignment, offsets);
10307 Roo.EventManager.onWindowResize(action, this);
10308 var tm = typeof monitorScroll;
10309 if(tm != 'undefined'){
10310 Roo.EventManager.on(window, 'scroll', action, this,
10311 {buffer: tm == 'number' ? monitorScroll : 50});
10318 * Returns true if the dialog is visible
10319 * @return {Boolean}
10321 isVisible : function(){
10322 return this.el.isVisible();
10326 animHide : function(callback){
10327 var b = Roo.get(this.animateTarget).getBox();
10329 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
10331 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
10332 this.hideEl.createDelegate(this, [callback]));
10336 * Hides the dialog.
10337 * @param {Function} callback (optional) Function to call when the dialog is hidden
10338 * @return {Roo.BasicDialog} this
10340 hide : function(callback){
10341 if (this.fireEvent("beforehide", this) === false){
10345 this.shadow.hide();
10350 // sometimes animateTarget seems to get set.. causing problems...
10351 // this just double checks..
10352 if(this.animateTarget && Roo.get(this.animateTarget)) {
10353 this.animHide(callback);
10356 this.hideEl(callback);
10362 hideEl : function(callback){
10366 Roo.get(document.body).removeClass("x-body-masked");
10368 this.fireEvent("hide", this);
10369 if(typeof callback == "function"){
10375 hideAction : function(){
10376 this.setLeft("-10000px");
10377 this.setTop("-10000px");
10378 this.setStyle("visibility", "hidden");
10382 refreshSize : function(){
10383 this.size = this.el.getSize();
10384 this.xy = this.el.getXY();
10385 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
10389 // z-index is managed by the DialogManager and may be overwritten at any time
10390 setZIndex : function(index){
10392 this.mask.setStyle("z-index", index);
10395 this.shim.setStyle("z-index", ++index);
10398 this.shadow.setZIndex(++index);
10400 this.el.setStyle("z-index", ++index);
10402 this.proxy.setStyle("z-index", ++index);
10405 this.resizer.proxy.setStyle("z-index", ++index);
10408 this.lastZIndex = index;
10412 * Returns the element for this dialog
10413 * @return {Roo.Element} The underlying dialog Element
10415 getEl : function(){
10421 * @class Roo.DialogManager
10422 * Provides global access to BasicDialogs that have been created and
10423 * support for z-indexing (layering) multiple open dialogs.
10425 Roo.DialogManager = function(){
10427 var accessList = [];
10431 var sortDialogs = function(d1, d2){
10432 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
10436 var orderDialogs = function(){
10437 accessList.sort(sortDialogs);
10438 var seed = Roo.DialogManager.zseed;
10439 for(var i = 0, len = accessList.length; i < len; i++){
10440 var dlg = accessList[i];
10442 dlg.setZIndex(seed + (i*10));
10449 * The starting z-index for BasicDialogs (defaults to 9000)
10450 * @type Number The z-index value
10455 register : function(dlg){
10456 list[dlg.id] = dlg;
10457 accessList.push(dlg);
10461 unregister : function(dlg){
10462 delete list[dlg.id];
10465 if(!accessList.indexOf){
10466 for( i = 0, len = accessList.length; i < len; i++){
10467 if(accessList[i] == dlg){
10468 accessList.splice(i, 1);
10473 i = accessList.indexOf(dlg);
10475 accessList.splice(i, 1);
10481 * Gets a registered dialog by id
10482 * @param {String/Object} id The id of the dialog or a dialog
10483 * @return {Roo.BasicDialog} this
10485 get : function(id){
10486 return typeof id == "object" ? id : list[id];
10490 * Brings the specified dialog to the front
10491 * @param {String/Object} dlg The id of the dialog or a dialog
10492 * @return {Roo.BasicDialog} this
10494 bringToFront : function(dlg){
10495 dlg = this.get(dlg);
10498 dlg._lastAccess = new Date().getTime();
10505 * Sends the specified dialog to the back
10506 * @param {String/Object} dlg The id of the dialog or a dialog
10507 * @return {Roo.BasicDialog} this
10509 sendToBack : function(dlg){
10510 dlg = this.get(dlg);
10511 dlg._lastAccess = -(new Date().getTime());
10517 * Hides all dialogs
10519 hideAll : function(){
10520 for(var id in list){
10521 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
10530 * @class Roo.LayoutDialog
10531 * @extends Roo.BasicDialog
10532 * Dialog which provides adjustments for working with a layout in a Dialog.
10533 * Add your necessary layout config options to the dialog's config.<br>
10534 * Example usage (including a nested layout):
10537 dialog = new Roo.LayoutDialog("download-dlg", {
10546 // layout config merges with the dialog config
10548 tabPosition: "top",
10549 alwaysShowTabs: true
10552 dialog.addKeyListener(27, dialog.hide, dialog);
10553 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
10554 dialog.addButton("Build It!", this.getDownload, this);
10556 // we can even add nested layouts
10557 var innerLayout = new Roo.BorderLayout("dl-inner", {
10567 innerLayout.beginUpdate();
10568 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
10569 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
10570 innerLayout.endUpdate(true);
10572 var layout = dialog.getLayout();
10573 layout.beginUpdate();
10574 layout.add("center", new Roo.ContentPanel("standard-panel",
10575 {title: "Download the Source", fitToFrame:true}));
10576 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
10577 {title: "Build your own roo.js"}));
10578 layout.getRegion("center").showPanel(sp);
10579 layout.endUpdate();
10583 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
10584 * @param {Object} config configuration options
10586 Roo.LayoutDialog = function(el, cfg){
10589 if (typeof(cfg) == 'undefined') {
10590 config = Roo.apply({}, el);
10591 // not sure why we use documentElement here.. - it should always be body.
10592 // IE7 borks horribly if we use documentElement.
10593 // webkit also does not like documentElement - it creates a body element...
10594 el = Roo.get( document.body || document.documentElement ).createChild();
10595 //config.autoCreate = true;
10599 config.autoTabs = false;
10600 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
10601 this.body.setStyle({overflow:"hidden", position:"relative"});
10602 this.layout = new Roo.BorderLayout(this.body.dom, config);
10603 this.layout.monitorWindowResize = false;
10604 this.el.addClass("x-dlg-auto-layout");
10605 // fix case when center region overwrites center function
10606 this.center = Roo.BasicDialog.prototype.center;
10607 this.on("show", this.layout.layout, this.layout, true);
10608 if (config.items) {
10609 var xitems = config.items;
10610 delete config.items;
10611 Roo.each(xitems, this.addxtype, this);
10616 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
10618 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
10621 endUpdate : function(){
10622 this.layout.endUpdate();
10626 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
10629 beginUpdate : function(){
10630 this.layout.beginUpdate();
10634 * Get the BorderLayout for this dialog
10635 * @return {Roo.BorderLayout}
10637 getLayout : function(){
10638 return this.layout;
10641 showEl : function(){
10642 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
10644 this.layout.layout();
10649 // Use the syncHeightBeforeShow config option to control this automatically
10650 syncBodyHeight : function(){
10651 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
10652 if(this.layout){this.layout.layout();}
10656 * Add an xtype element (actually adds to the layout.)
10657 * @return {Object} xdata xtype object data.
10660 addxtype : function(c) {
10661 return this.layout.addxtype(c);
10665 * Ext JS Library 1.1.1
10666 * Copyright(c) 2006-2007, Ext JS, LLC.
10668 * Originally Released Under LGPL - original licence link has changed is not relivant.
10671 * <script type="text/javascript">
10675 * @class Roo.MessageBox
10676 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
10680 Roo.Msg.alert('Status', 'Changes saved successfully.');
10682 // Prompt for user data:
10683 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
10685 // process text value...
10689 // Show a dialog using config options:
10691 title:'Save Changes?',
10692 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
10693 buttons: Roo.Msg.YESNOCANCEL,
10700 Roo.MessageBox = function(){
10701 var dlg, opt, mask, waitTimer;
10702 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
10703 var buttons, activeTextEl, bwidth;
10706 var handleButton = function(button){
10708 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
10712 var handleHide = function(){
10713 if(opt && opt.cls){
10714 dlg.el.removeClass(opt.cls);
10717 Roo.TaskMgr.stop(waitTimer);
10723 var updateButtons = function(b){
10726 buttons["ok"].hide();
10727 buttons["cancel"].hide();
10728 buttons["yes"].hide();
10729 buttons["no"].hide();
10730 dlg.footer.dom.style.display = 'none';
10733 dlg.footer.dom.style.display = '';
10734 for(var k in buttons){
10735 if(typeof buttons[k] != "function"){
10738 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
10739 width += buttons[k].el.getWidth()+15;
10749 var handleEsc = function(d, k, e){
10750 if(opt && opt.closable !== false){
10760 * Returns a reference to the underlying {@link Roo.BasicDialog} element
10761 * @return {Roo.BasicDialog} The BasicDialog element
10763 getDialog : function(){
10765 dlg = new Roo.BasicDialog("x-msg-box", {
10770 constraintoviewport:false,
10772 collapsible : false,
10775 width:400, height:100,
10776 buttonAlign:"center",
10777 closeClick : function(){
10778 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
10779 handleButton("no");
10781 handleButton("cancel");
10785 dlg.on("hide", handleHide);
10787 dlg.addKeyListener(27, handleEsc);
10789 var bt = this.buttonText;
10790 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
10791 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
10792 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
10793 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
10794 bodyEl = dlg.body.createChild({
10796 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>'
10798 msgEl = bodyEl.dom.firstChild;
10799 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
10800 textboxEl.enableDisplayMode();
10801 textboxEl.addKeyListener([10,13], function(){
10802 if(dlg.isVisible() && opt && opt.buttons){
10803 if(opt.buttons.ok){
10804 handleButton("ok");
10805 }else if(opt.buttons.yes){
10806 handleButton("yes");
10810 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
10811 textareaEl.enableDisplayMode();
10812 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
10813 progressEl.enableDisplayMode();
10814 var pf = progressEl.dom.firstChild;
10816 pp = Roo.get(pf.firstChild);
10817 pp.setHeight(pf.offsetHeight);
10825 * Updates the message box body text
10826 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
10827 * the XHTML-compliant non-breaking space character '&#160;')
10828 * @return {Roo.MessageBox} This message box
10830 updateText : function(text){
10831 if(!dlg.isVisible() && !opt.width){
10832 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
10834 msgEl.innerHTML = text || ' ';
10836 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
10837 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
10839 Math.min(opt.width || cw , this.maxWidth),
10840 Math.max(opt.minWidth || this.minWidth, bwidth)
10843 activeTextEl.setWidth(w);
10845 if(dlg.isVisible()){
10846 dlg.fixedcenter = false;
10848 // to big, make it scroll. = But as usual stupid IE does not support
10851 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
10852 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
10853 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
10855 bodyEl.dom.style.height = '';
10856 bodyEl.dom.style.overflowY = '';
10859 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
10861 bodyEl.dom.style.overflowX = '';
10864 dlg.setContentSize(w, bodyEl.getHeight());
10865 if(dlg.isVisible()){
10866 dlg.fixedcenter = true;
10872 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
10873 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
10874 * @param {Number} value Any number between 0 and 1 (e.g., .5)
10875 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
10876 * @return {Roo.MessageBox} This message box
10878 updateProgress : function(value, text){
10880 this.updateText(text);
10882 if (pp) { // weird bug on my firefox - for some reason this is not defined
10883 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
10889 * Returns true if the message box is currently displayed
10890 * @return {Boolean} True if the message box is visible, else false
10892 isVisible : function(){
10893 return dlg && dlg.isVisible();
10897 * Hides the message box if it is displayed
10900 if(this.isVisible()){
10906 * Displays a new message box, or reinitializes an existing message box, based on the config options
10907 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
10908 * The following config object properties are supported:
10910 Property Type Description
10911 ---------- --------------- ------------------------------------------------------------------------------------
10912 animEl String/Element An id or Element from which the message box should animate as it opens and
10913 closes (defaults to undefined)
10914 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
10915 cancel:'Bar'}), or false to not show any buttons (defaults to false)
10916 closable Boolean False to hide the top-right close button (defaults to true). Note that
10917 progress and wait dialogs will ignore this property and always hide the
10918 close button as they can only be closed programmatically.
10919 cls String A custom CSS class to apply to the message box element
10920 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
10921 displayed (defaults to 75)
10922 fn Function A callback function to execute after closing the dialog. The arguments to the
10923 function will be btn (the name of the button that was clicked, if applicable,
10924 e.g. "ok"), and text (the value of the active text field, if applicable).
10925 Progress and wait dialogs will ignore this option since they do not respond to
10926 user actions and can only be closed programmatically, so any required function
10927 should be called by the same code after it closes the dialog.
10928 icon String A CSS class that provides a background image to be used as an icon for
10929 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
10930 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
10931 minWidth Number The minimum width in pixels of the message box (defaults to 100)
10932 modal Boolean False to allow user interaction with the page while the message box is
10933 displayed (defaults to true)
10934 msg String A string that will replace the existing message box body text (defaults
10935 to the XHTML-compliant non-breaking space character ' ')
10936 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
10937 progress Boolean True to display a progress bar (defaults to false)
10938 progressText String The text to display inside the progress bar if progress = true (defaults to '')
10939 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
10940 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
10941 title String The title text
10942 value String The string value to set into the active textbox element if displayed
10943 wait Boolean True to display a progress bar (defaults to false)
10944 width Number The width of the dialog in pixels
10951 msg: 'Please enter your address:',
10953 buttons: Roo.MessageBox.OKCANCEL,
10956 animEl: 'addAddressBtn'
10959 * @param {Object} config Configuration options
10960 * @return {Roo.MessageBox} This message box
10962 show : function(options)
10965 // this causes nightmares if you show one dialog after another
10966 // especially on callbacks..
10968 if(this.isVisible()){
10971 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
10972 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
10973 Roo.log("New Dialog Message:" + options.msg )
10974 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
10975 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
10978 var d = this.getDialog();
10980 d.setTitle(opt.title || " ");
10981 d.close.setDisplayed(opt.closable !== false);
10982 activeTextEl = textboxEl;
10983 opt.prompt = opt.prompt || (opt.multiline ? true : false);
10988 textareaEl.setHeight(typeof opt.multiline == "number" ?
10989 opt.multiline : this.defaultTextHeight);
10990 activeTextEl = textareaEl;
10999 progressEl.setDisplayed(opt.progress === true);
11000 this.updateProgress(0);
11001 activeTextEl.dom.value = opt.value || "";
11003 dlg.setDefaultButton(activeTextEl);
11005 var bs = opt.buttons;
11008 db = buttons["ok"];
11009 }else if(bs && bs.yes){
11010 db = buttons["yes"];
11012 dlg.setDefaultButton(db);
11014 bwidth = updateButtons(opt.buttons);
11015 this.updateText(opt.msg);
11017 d.el.addClass(opt.cls);
11019 d.proxyDrag = opt.proxyDrag === true;
11020 d.modal = opt.modal !== false;
11021 d.mask = opt.modal !== false ? mask : false;
11022 if(!d.isVisible()){
11023 // force it to the end of the z-index stack so it gets a cursor in FF
11024 document.body.appendChild(dlg.el.dom);
11025 d.animateTarget = null;
11026 d.show(options.animEl);
11032 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
11033 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
11034 * and closing the message box when the process is complete.
11035 * @param {String} title The title bar text
11036 * @param {String} msg The message box body text
11037 * @return {Roo.MessageBox} This message box
11039 progress : function(title, msg){
11046 minWidth: this.minProgressWidth,
11053 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
11054 * If a callback function is passed it will be called after the user clicks the button, and the
11055 * id of the button that was clicked will be passed as the only parameter to the callback
11056 * (could also be the top-right close button).
11057 * @param {String} title The title bar text
11058 * @param {String} msg The message box body text
11059 * @param {Function} fn (optional) The callback function invoked after the message box is closed
11060 * @param {Object} scope (optional) The scope of the callback function
11061 * @return {Roo.MessageBox} This message box
11063 alert : function(title, msg, fn, scope){
11076 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
11077 * interaction while waiting for a long-running process to complete that does not have defined intervals.
11078 * You are responsible for closing the message box when the process is complete.
11079 * @param {String} msg The message box body text
11080 * @param {String} title (optional) The title bar text
11081 * @return {Roo.MessageBox} This message box
11083 wait : function(msg, title){
11094 waitTimer = Roo.TaskMgr.start({
11096 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
11104 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
11105 * If a callback function is passed it will be called after the user clicks either button, and the id of the
11106 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
11107 * @param {String} title The title bar text
11108 * @param {String} msg The message box body text
11109 * @param {Function} fn (optional) The callback function invoked after the message box is closed
11110 * @param {Object} scope (optional) The scope of the callback function
11111 * @return {Roo.MessageBox} This message box
11113 confirm : function(title, msg, fn, scope){
11117 buttons: this.YESNO,
11126 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
11127 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
11128 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
11129 * (could also be the top-right close button) and the text that was entered will be passed as the two
11130 * parameters to the callback.
11131 * @param {String} title The title bar text
11132 * @param {String} msg The message box body text
11133 * @param {Function} fn (optional) The callback function invoked after the message box is closed
11134 * @param {Object} scope (optional) The scope of the callback function
11135 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
11136 * property, or the height in pixels to create the textbox (defaults to false / single-line)
11137 * @return {Roo.MessageBox} This message box
11139 prompt : function(title, msg, fn, scope, multiline){
11143 buttons: this.OKCANCEL,
11148 multiline: multiline,
11155 * Button config that displays a single OK button
11160 * Button config that displays Yes and No buttons
11163 YESNO : {yes:true, no:true},
11165 * Button config that displays OK and Cancel buttons
11168 OKCANCEL : {ok:true, cancel:true},
11170 * Button config that displays Yes, No and Cancel buttons
11173 YESNOCANCEL : {yes:true, no:true, cancel:true},
11176 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
11179 defaultTextHeight : 75,
11181 * The maximum width in pixels of the message box (defaults to 600)
11186 * The minimum width in pixels of the message box (defaults to 100)
11191 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
11192 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
11195 minProgressWidth : 250,
11197 * An object containing the default button text strings that can be overriden for localized language support.
11198 * Supported properties are: ok, cancel, yes and no.
11199 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
11212 * Shorthand for {@link Roo.MessageBox}
11214 Roo.Msg = Roo.MessageBox;/*
11216 * Ext JS Library 1.1.1
11217 * Copyright(c) 2006-2007, Ext JS, LLC.
11219 * Originally Released Under LGPL - original licence link has changed is not relivant.
11222 * <script type="text/javascript">
11225 * @class Roo.QuickTips
11226 * Provides attractive and customizable tooltips for any element.
11229 Roo.QuickTips = function(){
11230 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
11231 var ce, bd, xy, dd;
11232 var visible = false, disabled = true, inited = false;
11233 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
11235 var onOver = function(e){
11239 var t = e.getTarget();
11240 if(!t || t.nodeType !== 1 || t == document || t == document.body){
11243 if(ce && t == ce.el){
11244 clearTimeout(hideProc);
11247 if(t && tagEls[t.id]){
11248 tagEls[t.id].el = t;
11249 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
11252 var ttp, et = Roo.fly(t);
11253 var ns = cfg.namespace;
11254 if(tm.interceptTitles && t.title){
11257 t.removeAttribute("title");
11258 e.preventDefault();
11260 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute) || et.getAttributeNS(cfg.alt_namespace, cfg.attribute) ;
11263 showProc = show.defer(tm.showDelay, tm, [{
11265 text: ttp.replace(/\\n/g,'<br/>'),
11266 width: et.getAttributeNS(ns, cfg.width),
11267 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
11268 title: et.getAttributeNS(ns, cfg.title),
11269 cls: et.getAttributeNS(ns, cfg.cls)
11274 var onOut = function(e){
11275 clearTimeout(showProc);
11276 var t = e.getTarget();
11277 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
11278 hideProc = setTimeout(hide, tm.hideDelay);
11282 var onMove = function(e){
11288 if(tm.trackMouse && ce){
11293 var onDown = function(e){
11294 clearTimeout(showProc);
11295 clearTimeout(hideProc);
11297 if(tm.hideOnClick){
11300 tm.enable.defer(100, tm);
11305 var getPad = function(){
11306 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
11309 var show = function(o){
11313 clearTimeout(dismissProc);
11315 if(removeCls){ // in case manually hidden
11316 el.removeClass(removeCls);
11320 el.addClass(ce.cls);
11321 removeCls = ce.cls;
11324 tipTitle.update(ce.title);
11327 tipTitle.update('');
11330 el.dom.style.width = tm.maxWidth+'px';
11331 //tipBody.dom.style.width = '';
11332 tipBodyText.update(o.text);
11333 var p = getPad(), w = ce.width;
11335 var td = tipBodyText.dom;
11336 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
11337 if(aw > tm.maxWidth){
11339 }else if(aw < tm.minWidth){
11345 //tipBody.setWidth(w);
11346 el.setWidth(parseInt(w, 10) + p);
11347 if(ce.autoHide === false){
11348 close.setDisplayed(true);
11353 close.setDisplayed(false);
11359 el.avoidY = xy[1]-18;
11364 el.setStyle("visibility", "visible");
11365 el.fadeIn({callback: afterShow});
11371 var afterShow = function(){
11375 if(tm.autoDismiss && ce.autoHide !== false){
11376 dismissProc = setTimeout(hide, tm.autoDismissDelay);
11381 var hide = function(noanim){
11382 clearTimeout(dismissProc);
11383 clearTimeout(hideProc);
11385 if(el.isVisible()){
11387 if(noanim !== true && tm.animate){
11388 el.fadeOut({callback: afterHide});
11395 var afterHide = function(){
11398 el.removeClass(removeCls);
11405 * @cfg {Number} minWidth
11406 * The minimum width of the quick tip (defaults to 40)
11410 * @cfg {Number} maxWidth
11411 * The maximum width of the quick tip (defaults to 300)
11415 * @cfg {Boolean} interceptTitles
11416 * True to automatically use the element's DOM title value if available (defaults to false)
11418 interceptTitles : false,
11420 * @cfg {Boolean} trackMouse
11421 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
11423 trackMouse : false,
11425 * @cfg {Boolean} hideOnClick
11426 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
11428 hideOnClick : true,
11430 * @cfg {Number} showDelay
11431 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
11435 * @cfg {Number} hideDelay
11436 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
11440 * @cfg {Boolean} autoHide
11441 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
11442 * Used in conjunction with hideDelay.
11447 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
11448 * (defaults to true). Used in conjunction with autoDismissDelay.
11450 autoDismiss : true,
11453 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
11455 autoDismissDelay : 5000,
11457 * @cfg {Boolean} animate
11458 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
11463 * @cfg {String} title
11464 * Title text to display (defaults to ''). This can be any valid HTML markup.
11468 * @cfg {String} text
11469 * Body text to display (defaults to ''). This can be any valid HTML markup.
11473 * @cfg {String} cls
11474 * A CSS class to apply to the base quick tip element (defaults to '').
11478 * @cfg {Number} width
11479 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
11480 * minWidth or maxWidth.
11485 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
11486 * or display QuickTips in a page.
11489 tm = Roo.QuickTips;
11490 cfg = tm.tagConfig;
11492 if(!Roo.isReady){ // allow calling of init() before onReady
11493 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
11496 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
11497 el.fxDefaults = {stopFx: true};
11498 // maximum custom styling
11499 //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>');
11500 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>');
11501 tipTitle = el.child('h3');
11502 tipTitle.enableDisplayMode("block");
11503 tipBody = el.child('div.x-tip-bd');
11504 tipBodyText = el.child('div.x-tip-bd-inner');
11505 //bdLeft = el.child('div.x-tip-bd-left');
11506 //bdRight = el.child('div.x-tip-bd-right');
11507 close = el.child('div.x-tip-close');
11508 close.enableDisplayMode("block");
11509 close.on("click", hide);
11510 var d = Roo.get(document);
11511 d.on("mousedown", onDown);
11512 d.on("mouseover", onOver);
11513 d.on("mouseout", onOut);
11514 d.on("mousemove", onMove);
11515 esc = d.addKeyListener(27, hide);
11518 dd = el.initDD("default", null, {
11519 onDrag : function(){
11523 dd.setHandleElId(tipTitle.id);
11532 * Configures a new quick tip instance and assigns it to a target element. The following config options
11535 Property Type Description
11536 ---------- --------------------- ------------------------------------------------------------------------
11537 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
11539 * @param {Object} config The config object
11541 register : function(config){
11542 var cs = config instanceof Array ? config : arguments;
11543 for(var i = 0, len = cs.length; i < len; i++) {
11545 var target = c.target;
11547 if(target instanceof Array){
11548 for(var j = 0, jlen = target.length; j < jlen; j++){
11549 tagEls[target[j]] = c;
11552 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
11559 * Removes this quick tip from its element and destroys it.
11560 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
11562 unregister : function(el){
11563 delete tagEls[Roo.id(el)];
11567 * Enable this quick tip.
11569 enable : function(){
11570 if(inited && disabled){
11572 if(locks.length < 1){
11579 * Disable this quick tip.
11581 disable : function(){
11583 clearTimeout(showProc);
11584 clearTimeout(hideProc);
11585 clearTimeout(dismissProc);
11593 * Returns true if the quick tip is enabled, else false.
11595 isEnabled : function(){
11601 namespace : "roo", // was ext?? this may break..
11602 alt_namespace : "ext",
11603 attribute : "qtip",
11613 // backwards compat
11614 Roo.QuickTips.tips = Roo.QuickTips.register;/*
11616 * Ext JS Library 1.1.1
11617 * Copyright(c) 2006-2007, Ext JS, LLC.
11619 * Originally Released Under LGPL - original licence link has changed is not relivant.
11622 * <script type="text/javascript">
11627 * @class Roo.tree.TreePanel
11628 * @extends Roo.data.Tree
11630 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
11631 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
11632 * @cfg {Boolean} enableDD true to enable drag and drop
11633 * @cfg {Boolean} enableDrag true to enable just drag
11634 * @cfg {Boolean} enableDrop true to enable just drop
11635 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
11636 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
11637 * @cfg {String} ddGroup The DD group this TreePanel belongs to
11638 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
11639 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
11640 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
11641 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
11642 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
11643 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
11644 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
11645 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
11646 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
11647 * @cfg {Object|Roo.tree.TreeEditor} editor The TreeEditor or xtype data to display when clicked.
11648 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
11649 * @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>
11650 * @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>
11653 * @param {String/HTMLElement/Element} el The container element
11654 * @param {Object} config
11656 Roo.tree.TreePanel = function(el, config){
11658 var loader = false;
11660 root = config.root;
11661 delete config.root;
11663 if (config.loader) {
11664 loader = config.loader;
11665 delete config.loader;
11668 Roo.apply(this, config);
11669 Roo.tree.TreePanel.superclass.constructor.call(this);
11670 this.el = Roo.get(el);
11671 this.el.addClass('x-tree');
11672 //console.log(root);
11674 this.setRootNode( Roo.factory(root, Roo.tree));
11677 this.loader = Roo.factory(loader, Roo.tree);
11680 * Read-only. The id of the container element becomes this TreePanel's id.
11682 this.id = this.el.id;
11685 * @event beforeload
11686 * Fires before a node is loaded, return false to cancel
11687 * @param {Node} node The node being loaded
11689 "beforeload" : true,
11692 * Fires when a node is loaded
11693 * @param {Node} node The node that was loaded
11697 * @event textchange
11698 * Fires when the text for a node is changed
11699 * @param {Node} node The node
11700 * @param {String} text The new text
11701 * @param {String} oldText The old text
11703 "textchange" : true,
11705 * @event beforeexpand
11706 * Fires before a node is expanded, return false to cancel.
11707 * @param {Node} node The node
11708 * @param {Boolean} deep
11709 * @param {Boolean} anim
11711 "beforeexpand" : true,
11713 * @event beforecollapse
11714 * Fires before a node is collapsed, return false to cancel.
11715 * @param {Node} node The node
11716 * @param {Boolean} deep
11717 * @param {Boolean} anim
11719 "beforecollapse" : true,
11722 * Fires when a node is expanded
11723 * @param {Node} node The node
11727 * @event disabledchange
11728 * Fires when the disabled status of a node changes
11729 * @param {Node} node The node
11730 * @param {Boolean} disabled
11732 "disabledchange" : true,
11735 * Fires when a node is collapsed
11736 * @param {Node} node The node
11740 * @event beforeclick
11741 * Fires before click processing on a node. Return false to cancel the default action.
11742 * @param {Node} node The node
11743 * @param {Roo.EventObject} e The event object
11745 "beforeclick":true,
11747 * @event checkchange
11748 * Fires when a node with a checkbox's checked property changes
11749 * @param {Node} this This node
11750 * @param {Boolean} checked
11752 "checkchange":true,
11755 * Fires when a node is clicked
11756 * @param {Node} node The node
11757 * @param {Roo.EventObject} e The event object
11762 * Fires when a node is double clicked
11763 * @param {Node} node The node
11764 * @param {Roo.EventObject} e The event object
11768 * @event contextmenu
11769 * Fires when a node is right clicked
11770 * @param {Node} node The node
11771 * @param {Roo.EventObject} e The event object
11773 "contextmenu":true,
11775 * @event beforechildrenrendered
11776 * Fires right before the child nodes for a node are rendered
11777 * @param {Node} node The node
11779 "beforechildrenrendered":true,
11782 * Fires when a node starts being dragged
11783 * @param {Roo.tree.TreePanel} this
11784 * @param {Roo.tree.TreeNode} node
11785 * @param {event} e The raw browser event
11787 "startdrag" : true,
11790 * Fires when a drag operation is complete
11791 * @param {Roo.tree.TreePanel} this
11792 * @param {Roo.tree.TreeNode} node
11793 * @param {event} e The raw browser event
11798 * Fires when a dragged node is dropped on a valid DD target
11799 * @param {Roo.tree.TreePanel} this
11800 * @param {Roo.tree.TreeNode} node
11801 * @param {DD} dd The dd it was dropped on
11802 * @param {event} e The raw browser event
11806 * @event beforenodedrop
11807 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
11808 * passed to handlers has the following properties:<br />
11809 * <ul style="padding:5px;padding-left:16px;">
11810 * <li>tree - The TreePanel</li>
11811 * <li>target - The node being targeted for the drop</li>
11812 * <li>data - The drag data from the drag source</li>
11813 * <li>point - The point of the drop - append, above or below</li>
11814 * <li>source - The drag source</li>
11815 * <li>rawEvent - Raw mouse event</li>
11816 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
11817 * to be inserted by setting them on this object.</li>
11818 * <li>cancel - Set this to true to cancel the drop.</li>
11820 * @param {Object} dropEvent
11822 "beforenodedrop" : true,
11825 * Fires after a DD object is dropped on a node in this tree. The dropEvent
11826 * passed to handlers has the following properties:<br />
11827 * <ul style="padding:5px;padding-left:16px;">
11828 * <li>tree - The TreePanel</li>
11829 * <li>target - The node being targeted for the drop</li>
11830 * <li>data - The drag data from the drag source</li>
11831 * <li>point - The point of the drop - append, above or below</li>
11832 * <li>source - The drag source</li>
11833 * <li>rawEvent - Raw mouse event</li>
11834 * <li>dropNode - Dropped node(s).</li>
11836 * @param {Object} dropEvent
11840 * @event nodedragover
11841 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
11842 * passed to handlers has the following properties:<br />
11843 * <ul style="padding:5px;padding-left:16px;">
11844 * <li>tree - The TreePanel</li>
11845 * <li>target - The node being targeted for the drop</li>
11846 * <li>data - The drag data from the drag source</li>
11847 * <li>point - The point of the drop - append, above or below</li>
11848 * <li>source - The drag source</li>
11849 * <li>rawEvent - Raw mouse event</li>
11850 * <li>dropNode - Drop node(s) provided by the source.</li>
11851 * <li>cancel - Set this to true to signal drop not allowed.</li>
11853 * @param {Object} dragOverEvent
11855 "nodedragover" : true,
11857 * @event appendnode
11858 * Fires when append node to the tree
11859 * @param {Roo.tree.TreePanel} this
11860 * @param {Roo.tree.TreeNode} node
11861 * @param {Number} index The index of the newly appended node
11863 "appendnode" : true
11866 if(this.singleExpand){
11867 this.on("beforeexpand", this.restrictExpand, this);
11870 this.editor.tree = this;
11871 this.editor = Roo.factory(this.editor, Roo.tree);
11874 if (this.selModel) {
11875 this.selModel = Roo.factory(this.selModel, Roo.tree);
11879 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
11880 rootVisible : true,
11881 animate: Roo.enableFx,
11884 hlDrop : Roo.enableFx,
11888 rendererTip: false,
11890 restrictExpand : function(node){
11891 var p = node.parentNode;
11893 if(p.expandedChild && p.expandedChild.parentNode == p){
11894 p.expandedChild.collapse();
11896 p.expandedChild = node;
11900 // private override
11901 setRootNode : function(node){
11902 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
11903 if(!this.rootVisible){
11904 node.ui = new Roo.tree.RootTreeNodeUI(node);
11910 * Returns the container element for this TreePanel
11912 getEl : function(){
11917 * Returns the default TreeLoader for this TreePanel
11919 getLoader : function(){
11920 return this.loader;
11926 expandAll : function(){
11927 this.root.expand(true);
11931 * Collapse all nodes
11933 collapseAll : function(){
11934 this.root.collapse(true);
11938 * Returns the selection model used by this TreePanel
11940 getSelectionModel : function(){
11941 if(!this.selModel){
11942 this.selModel = new Roo.tree.DefaultSelectionModel();
11944 return this.selModel;
11948 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
11949 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
11950 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
11953 getChecked : function(a, startNode){
11954 startNode = startNode || this.root;
11956 var f = function(){
11957 if(this.attributes.checked){
11958 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
11961 startNode.cascade(f);
11966 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
11967 * @param {String} path
11968 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
11969 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
11970 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
11972 expandPath : function(path, attr, callback){
11973 attr = attr || "id";
11974 var keys = path.split(this.pathSeparator);
11975 var curNode = this.root;
11976 if(curNode.attributes[attr] != keys[1]){ // invalid root
11978 callback(false, null);
11983 var f = function(){
11984 if(++index == keys.length){
11986 callback(true, curNode);
11990 var c = curNode.findChild(attr, keys[index]);
11993 callback(false, curNode);
11998 c.expand(false, false, f);
12000 curNode.expand(false, false, f);
12004 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
12005 * @param {String} path
12006 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
12007 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
12008 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
12010 selectPath : function(path, attr, callback){
12011 attr = attr || "id";
12012 var keys = path.split(this.pathSeparator);
12013 var v = keys.pop();
12014 if(keys.length > 0){
12015 var f = function(success, node){
12016 if(success && node){
12017 var n = node.findChild(attr, v);
12023 }else if(callback){
12024 callback(false, n);
12028 callback(false, n);
12032 this.expandPath(keys.join(this.pathSeparator), attr, f);
12034 this.root.select();
12036 callback(true, this.root);
12041 getTreeEl : function(){
12046 * Trigger rendering of this TreePanel
12048 render : function(){
12049 if (this.innerCt) {
12050 return this; // stop it rendering more than once!!
12053 this.innerCt = this.el.createChild({tag:"ul",
12054 cls:"x-tree-root-ct " +
12055 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
12057 if(this.containerScroll){
12058 Roo.dd.ScrollManager.register(this.el);
12060 if((this.enableDD || this.enableDrop) && !this.dropZone){
12062 * The dropZone used by this tree if drop is enabled
12063 * @type Roo.tree.TreeDropZone
12065 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
12066 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
12069 if((this.enableDD || this.enableDrag) && !this.dragZone){
12071 * The dragZone used by this tree if drag is enabled
12072 * @type Roo.tree.TreeDragZone
12074 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
12075 ddGroup: this.ddGroup || "TreeDD",
12076 scroll: this.ddScroll
12079 this.getSelectionModel().init(this);
12081 Roo.log("ROOT not set in tree");
12084 this.root.render();
12085 if(!this.rootVisible){
12086 this.root.renderChildren();
12092 * Ext JS Library 1.1.1
12093 * Copyright(c) 2006-2007, Ext JS, LLC.
12095 * Originally Released Under LGPL - original licence link has changed is not relivant.
12098 * <script type="text/javascript">
12103 * @class Roo.tree.DefaultSelectionModel
12104 * @extends Roo.util.Observable
12105 * The default single selection for a TreePanel.
12106 * @param {Object} cfg Configuration
12108 Roo.tree.DefaultSelectionModel = function(cfg){
12109 this.selNode = null;
12115 * @event selectionchange
12116 * Fires when the selected node changes
12117 * @param {DefaultSelectionModel} this
12118 * @param {TreeNode} node the new selection
12120 "selectionchange" : true,
12123 * @event beforeselect
12124 * Fires before the selected node changes, return false to cancel the change
12125 * @param {DefaultSelectionModel} this
12126 * @param {TreeNode} node the new selection
12127 * @param {TreeNode} node the old selection
12129 "beforeselect" : true
12132 Roo.tree.DefaultSelectionModel.superclass.constructor.call(this,cfg);
12135 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
12136 init : function(tree){
12138 tree.getTreeEl().on("keydown", this.onKeyDown, this);
12139 tree.on("click", this.onNodeClick, this);
12142 onNodeClick : function(node, e){
12143 if (e.ctrlKey && this.selNode == node) {
12144 this.unselect(node);
12152 * @param {TreeNode} node The node to select
12153 * @return {TreeNode} The selected node
12155 select : function(node){
12156 var last = this.selNode;
12157 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
12159 last.ui.onSelectedChange(false);
12161 this.selNode = node;
12162 node.ui.onSelectedChange(true);
12163 this.fireEvent("selectionchange", this, node, last);
12170 * @param {TreeNode} node The node to unselect
12172 unselect : function(node){
12173 if(this.selNode == node){
12174 this.clearSelections();
12179 * Clear all selections
12181 clearSelections : function(){
12182 var n = this.selNode;
12184 n.ui.onSelectedChange(false);
12185 this.selNode = null;
12186 this.fireEvent("selectionchange", this, null);
12192 * Get the selected node
12193 * @return {TreeNode} The selected node
12195 getSelectedNode : function(){
12196 return this.selNode;
12200 * Returns true if the node is selected
12201 * @param {TreeNode} node The node to check
12202 * @return {Boolean}
12204 isSelected : function(node){
12205 return this.selNode == node;
12209 * Selects the node above the selected node in the tree, intelligently walking the nodes
12210 * @return TreeNode The new selection
12212 selectPrevious : function(){
12213 var s = this.selNode || this.lastSelNode;
12217 var ps = s.previousSibling;
12219 if(!ps.isExpanded() || ps.childNodes.length < 1){
12220 return this.select(ps);
12222 var lc = ps.lastChild;
12223 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
12226 return this.select(lc);
12228 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
12229 return this.select(s.parentNode);
12235 * Selects the node above the selected node in the tree, intelligently walking the nodes
12236 * @return TreeNode The new selection
12238 selectNext : function(){
12239 var s = this.selNode || this.lastSelNode;
12243 if(s.firstChild && s.isExpanded()){
12244 return this.select(s.firstChild);
12245 }else if(s.nextSibling){
12246 return this.select(s.nextSibling);
12247 }else if(s.parentNode){
12249 s.parentNode.bubble(function(){
12250 if(this.nextSibling){
12251 newS = this.getOwnerTree().selModel.select(this.nextSibling);
12260 onKeyDown : function(e){
12261 var s = this.selNode || this.lastSelNode;
12262 // undesirable, but required
12267 var k = e.getKey();
12275 this.selectPrevious();
12278 e.preventDefault();
12279 if(s.hasChildNodes()){
12280 if(!s.isExpanded()){
12282 }else if(s.firstChild){
12283 this.select(s.firstChild, e);
12288 e.preventDefault();
12289 if(s.hasChildNodes() && s.isExpanded()){
12291 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
12292 this.select(s.parentNode, e);
12300 * @class Roo.tree.MultiSelectionModel
12301 * @extends Roo.util.Observable
12302 * Multi selection for a TreePanel.
12303 * @param {Object} cfg Configuration
12305 Roo.tree.MultiSelectionModel = function(){
12306 this.selNodes = [];
12310 * @event selectionchange
12311 * Fires when the selected nodes change
12312 * @param {MultiSelectionModel} this
12313 * @param {Array} nodes Array of the selected nodes
12315 "selectionchange" : true
12317 Roo.tree.MultiSelectionModel.superclass.constructor.call(this,cfg);
12321 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
12322 init : function(tree){
12324 tree.getTreeEl().on("keydown", this.onKeyDown, this);
12325 tree.on("click", this.onNodeClick, this);
12328 onNodeClick : function(node, e){
12329 this.select(node, e, e.ctrlKey);
12334 * @param {TreeNode} node The node to select
12335 * @param {EventObject} e (optional) An event associated with the selection
12336 * @param {Boolean} keepExisting True to retain existing selections
12337 * @return {TreeNode} The selected node
12339 select : function(node, e, keepExisting){
12340 if(keepExisting !== true){
12341 this.clearSelections(true);
12343 if(this.isSelected(node)){
12344 this.lastSelNode = node;
12347 this.selNodes.push(node);
12348 this.selMap[node.id] = node;
12349 this.lastSelNode = node;
12350 node.ui.onSelectedChange(true);
12351 this.fireEvent("selectionchange", this, this.selNodes);
12357 * @param {TreeNode} node The node to unselect
12359 unselect : function(node){
12360 if(this.selMap[node.id]){
12361 node.ui.onSelectedChange(false);
12362 var sn = this.selNodes;
12365 index = sn.indexOf(node);
12367 for(var i = 0, len = sn.length; i < len; i++){
12375 this.selNodes.splice(index, 1);
12377 delete this.selMap[node.id];
12378 this.fireEvent("selectionchange", this, this.selNodes);
12383 * Clear all selections
12385 clearSelections : function(suppressEvent){
12386 var sn = this.selNodes;
12388 for(var i = 0, len = sn.length; i < len; i++){
12389 sn[i].ui.onSelectedChange(false);
12391 this.selNodes = [];
12393 if(suppressEvent !== true){
12394 this.fireEvent("selectionchange", this, this.selNodes);
12400 * Returns true if the node is selected
12401 * @param {TreeNode} node The node to check
12402 * @return {Boolean}
12404 isSelected : function(node){
12405 return this.selMap[node.id] ? true : false;
12409 * Returns an array of the selected nodes
12412 getSelectedNodes : function(){
12413 return this.selNodes;
12416 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
12418 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
12420 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
12423 * Ext JS Library 1.1.1
12424 * Copyright(c) 2006-2007, Ext JS, LLC.
12426 * Originally Released Under LGPL - original licence link has changed is not relivant.
12429 * <script type="text/javascript">
12433 * @class Roo.tree.TreeNode
12434 * @extends Roo.data.Node
12435 * @cfg {String} text The text for this node
12436 * @cfg {Boolean} expanded true to start the node expanded
12437 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
12438 * @cfg {Boolean} allowDrop false if this node cannot be drop on
12439 * @cfg {Boolean} disabled true to start the node disabled
12440 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
12441 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
12442 * @cfg {String} cls A css class to be added to the node
12443 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
12444 * @cfg {String} href URL of the link used for the node (defaults to #)
12445 * @cfg {String} hrefTarget target frame for the link
12446 * @cfg {String} qtip An Ext QuickTip for the node
12447 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
12448 * @cfg {Boolean} singleClickExpand True for single click expand on this node
12449 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
12450 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
12451 * (defaults to undefined with no checkbox rendered)
12453 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
12455 Roo.tree.TreeNode = function(attributes){
12456 attributes = attributes || {};
12457 if(typeof attributes == "string"){
12458 attributes = {text: attributes};
12460 this.childrenRendered = false;
12461 this.rendered = false;
12462 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
12463 this.expanded = attributes.expanded === true;
12464 this.isTarget = attributes.isTarget !== false;
12465 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
12466 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
12469 * Read-only. The text for this node. To change it use setText().
12472 this.text = attributes.text;
12474 * True if this node is disabled.
12477 this.disabled = attributes.disabled === true;
12481 * @event textchange
12482 * Fires when the text for this node is changed
12483 * @param {Node} this This node
12484 * @param {String} text The new text
12485 * @param {String} oldText The old text
12487 "textchange" : true,
12489 * @event beforeexpand
12490 * Fires before this node is expanded, return false to cancel.
12491 * @param {Node} this This node
12492 * @param {Boolean} deep
12493 * @param {Boolean} anim
12495 "beforeexpand" : true,
12497 * @event beforecollapse
12498 * Fires before this node is collapsed, return false to cancel.
12499 * @param {Node} this This node
12500 * @param {Boolean} deep
12501 * @param {Boolean} anim
12503 "beforecollapse" : true,
12506 * Fires when this node is expanded
12507 * @param {Node} this This node
12511 * @event disabledchange
12512 * Fires when the disabled status of this node changes
12513 * @param {Node} this This node
12514 * @param {Boolean} disabled
12516 "disabledchange" : true,
12519 * Fires when this node is collapsed
12520 * @param {Node} this This node
12524 * @event beforeclick
12525 * Fires before click processing. Return false to cancel the default action.
12526 * @param {Node} this This node
12527 * @param {Roo.EventObject} e The event object
12529 "beforeclick":true,
12531 * @event checkchange
12532 * Fires when a node with a checkbox's checked property changes
12533 * @param {Node} this This node
12534 * @param {Boolean} checked
12536 "checkchange":true,
12539 * Fires when this node is clicked
12540 * @param {Node} this This node
12541 * @param {Roo.EventObject} e The event object
12546 * Fires when this node is double clicked
12547 * @param {Node} this This node
12548 * @param {Roo.EventObject} e The event object
12552 * @event contextmenu
12553 * Fires when this node is right clicked
12554 * @param {Node} this This node
12555 * @param {Roo.EventObject} e The event object
12557 "contextmenu":true,
12559 * @event beforechildrenrendered
12560 * Fires right before the child nodes for this node are rendered
12561 * @param {Node} this This node
12563 "beforechildrenrendered":true
12566 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
12569 * Read-only. The UI for this node
12572 this.ui = new uiClass(this);
12574 // finally support items[]
12575 if (typeof(this.attributes.items) == 'undefined' || !this.attributes.items) {
12580 Roo.each(this.attributes.items, function(c) {
12581 this.appendChild(Roo.factory(c,Roo.Tree));
12583 delete this.attributes.items;
12588 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
12589 preventHScroll: true,
12591 * Returns true if this node is expanded
12592 * @return {Boolean}
12594 isExpanded : function(){
12595 return this.expanded;
12599 * Returns the UI object for this node
12600 * @return {TreeNodeUI}
12602 getUI : function(){
12606 // private override
12607 setFirstChild : function(node){
12608 var of = this.firstChild;
12609 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
12610 if(this.childrenRendered && of && node != of){
12611 of.renderIndent(true, true);
12614 this.renderIndent(true, true);
12618 // private override
12619 setLastChild : function(node){
12620 var ol = this.lastChild;
12621 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
12622 if(this.childrenRendered && ol && node != ol){
12623 ol.renderIndent(true, true);
12626 this.renderIndent(true, true);
12630 // these methods are overridden to provide lazy rendering support
12631 // private override
12632 appendChild : function()
12634 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
12635 if(node && this.childrenRendered){
12638 this.ui.updateExpandIcon();
12642 // private override
12643 removeChild : function(node){
12644 this.ownerTree.getSelectionModel().unselect(node);
12645 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
12646 // if it's been rendered remove dom node
12647 if(this.childrenRendered){
12650 if(this.childNodes.length < 1){
12651 this.collapse(false, false);
12653 this.ui.updateExpandIcon();
12655 if(!this.firstChild) {
12656 this.childrenRendered = false;
12661 // private override
12662 insertBefore : function(node, refNode){
12663 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
12664 if(newNode && refNode && this.childrenRendered){
12667 this.ui.updateExpandIcon();
12672 * Sets the text for this node
12673 * @param {String} text
12675 setText : function(text){
12676 var oldText = this.text;
12678 this.attributes.text = text;
12679 if(this.rendered){ // event without subscribing
12680 this.ui.onTextChange(this, text, oldText);
12682 this.fireEvent("textchange", this, text, oldText);
12686 * Triggers selection of this node
12688 select : function(){
12689 this.getOwnerTree().getSelectionModel().select(this);
12693 * Triggers deselection of this node
12695 unselect : function(){
12696 this.getOwnerTree().getSelectionModel().unselect(this);
12700 * Returns true if this node is selected
12701 * @return {Boolean}
12703 isSelected : function(){
12704 return this.getOwnerTree().getSelectionModel().isSelected(this);
12708 * Expand this node.
12709 * @param {Boolean} deep (optional) True to expand all children as well
12710 * @param {Boolean} anim (optional) false to cancel the default animation
12711 * @param {Function} callback (optional) A callback to be called when
12712 * expanding this node completes (does not wait for deep expand to complete).
12713 * Called with 1 parameter, this node.
12715 expand : function(deep, anim, callback){
12716 if(!this.expanded){
12717 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
12720 if(!this.childrenRendered){
12721 this.renderChildren();
12723 this.expanded = true;
12725 if(!this.isHiddenRoot() && (this.getOwnerTree() && this.getOwnerTree().animate && anim !== false) || anim){
12726 this.ui.animExpand(function(){
12727 this.fireEvent("expand", this);
12728 if(typeof callback == "function"){
12732 this.expandChildNodes(true);
12734 }.createDelegate(this));
12738 this.fireEvent("expand", this);
12739 if(typeof callback == "function"){
12744 if(typeof callback == "function"){
12749 this.expandChildNodes(true);
12753 isHiddenRoot : function(){
12754 return this.isRoot && !this.getOwnerTree().rootVisible;
12758 * Collapse this node.
12759 * @param {Boolean} deep (optional) True to collapse all children as well
12760 * @param {Boolean} anim (optional) false to cancel the default animation
12762 collapse : function(deep, anim){
12763 if(this.expanded && !this.isHiddenRoot()){
12764 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
12767 this.expanded = false;
12768 if((this.getOwnerTree().animate && anim !== false) || anim){
12769 this.ui.animCollapse(function(){
12770 this.fireEvent("collapse", this);
12772 this.collapseChildNodes(true);
12774 }.createDelegate(this));
12777 this.ui.collapse();
12778 this.fireEvent("collapse", this);
12782 var cs = this.childNodes;
12783 for(var i = 0, len = cs.length; i < len; i++) {
12784 cs[i].collapse(true, false);
12790 delayedExpand : function(delay){
12791 if(!this.expandProcId){
12792 this.expandProcId = this.expand.defer(delay, this);
12797 cancelExpand : function(){
12798 if(this.expandProcId){
12799 clearTimeout(this.expandProcId);
12801 this.expandProcId = false;
12805 * Toggles expanded/collapsed state of the node
12807 toggle : function(){
12816 * Ensures all parent nodes are expanded
12818 ensureVisible : function(callback){
12819 var tree = this.getOwnerTree();
12820 tree.expandPath(this.parentNode.getPath(), false, function(){
12821 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
12822 Roo.callback(callback);
12823 }.createDelegate(this));
12827 * Expand all child nodes
12828 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
12830 expandChildNodes : function(deep){
12831 var cs = this.childNodes;
12832 for(var i = 0, len = cs.length; i < len; i++) {
12833 cs[i].expand(deep);
12838 * Collapse all child nodes
12839 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
12841 collapseChildNodes : function(deep){
12842 var cs = this.childNodes;
12843 for(var i = 0, len = cs.length; i < len; i++) {
12844 cs[i].collapse(deep);
12849 * Disables this node
12851 disable : function(){
12852 this.disabled = true;
12854 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
12855 this.ui.onDisableChange(this, true);
12857 this.fireEvent("disabledchange", this, true);
12861 * Enables this node
12863 enable : function(){
12864 this.disabled = false;
12865 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
12866 this.ui.onDisableChange(this, false);
12868 this.fireEvent("disabledchange", this, false);
12872 renderChildren : function(suppressEvent){
12873 if(suppressEvent !== false){
12874 this.fireEvent("beforechildrenrendered", this);
12876 var cs = this.childNodes;
12877 for(var i = 0, len = cs.length; i < len; i++){
12878 cs[i].render(true);
12880 this.childrenRendered = true;
12884 sort : function(fn, scope){
12885 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
12886 if(this.childrenRendered){
12887 var cs = this.childNodes;
12888 for(var i = 0, len = cs.length; i < len; i++){
12889 cs[i].render(true);
12895 render : function(bulkRender){
12896 this.ui.render(bulkRender);
12897 if(!this.rendered){
12898 this.rendered = true;
12900 this.expanded = false;
12901 this.expand(false, false);
12907 renderIndent : function(deep, refresh){
12909 this.ui.childIndent = null;
12911 this.ui.renderIndent();
12912 if(deep === true && this.childrenRendered){
12913 var cs = this.childNodes;
12914 for(var i = 0, len = cs.length; i < len; i++){
12915 cs[i].renderIndent(true, refresh);
12921 * Ext JS Library 1.1.1
12922 * Copyright(c) 2006-2007, Ext JS, LLC.
12924 * Originally Released Under LGPL - original licence link has changed is not relivant.
12927 * <script type="text/javascript">
12931 * @class Roo.tree.AsyncTreeNode
12932 * @extends Roo.tree.TreeNode
12933 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
12935 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
12937 Roo.tree.AsyncTreeNode = function(config){
12938 this.loaded = false;
12939 this.loading = false;
12940 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
12942 * @event beforeload
12943 * Fires before this node is loaded, return false to cancel
12944 * @param {Node} this This node
12946 this.addEvents({'beforeload':true, 'load': true});
12949 * Fires when this node is loaded
12950 * @param {Node} this This node
12953 * The loader used by this node (defaults to using the tree's defined loader)
12958 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
12959 expand : function(deep, anim, callback){
12960 if(this.loading){ // if an async load is already running, waiting til it's done
12962 var f = function(){
12963 if(!this.loading){ // done loading
12964 clearInterval(timer);
12965 this.expand(deep, anim, callback);
12967 }.createDelegate(this);
12968 timer = setInterval(f, 200);
12972 if(this.fireEvent("beforeload", this) === false){
12975 this.loading = true;
12976 this.ui.beforeLoad(this);
12977 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
12979 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
12983 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
12987 * Returns true if this node is currently loading
12988 * @return {Boolean}
12990 isLoading : function(){
12991 return this.loading;
12994 loadComplete : function(deep, anim, callback){
12995 this.loading = false;
12996 this.loaded = true;
12997 this.ui.afterLoad(this);
12998 this.fireEvent("load", this);
12999 this.expand(deep, anim, callback);
13003 * Returns true if this node has been loaded
13004 * @return {Boolean}
13006 isLoaded : function(){
13007 return this.loaded;
13010 hasChildNodes : function(){
13011 if(!this.isLeaf() && !this.loaded){
13014 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
13019 * Trigger a reload for this node
13020 * @param {Function} callback
13022 reload : function(callback){
13023 this.collapse(false, false);
13024 while(this.firstChild){
13025 this.removeChild(this.firstChild);
13027 this.childrenRendered = false;
13028 this.loaded = false;
13029 if(this.isHiddenRoot()){
13030 this.expanded = false;
13032 this.expand(false, false, callback);
13036 * Ext JS Library 1.1.1
13037 * Copyright(c) 2006-2007, Ext JS, LLC.
13039 * Originally Released Under LGPL - original licence link has changed is not relivant.
13042 * <script type="text/javascript">
13046 * @class Roo.tree.TreeNodeUI
13048 * @param {Object} node The node to render
13049 * The TreeNode UI implementation is separate from the
13050 * tree implementation. Unless you are customizing the tree UI,
13051 * you should never have to use this directly.
13053 Roo.tree.TreeNodeUI = function(node){
13055 this.rendered = false;
13056 this.animating = false;
13057 this.emptyIcon = Roo.BLANK_IMAGE_URL;
13060 Roo.tree.TreeNodeUI.prototype = {
13061 removeChild : function(node){
13063 this.ctNode.removeChild(node.ui.getEl());
13067 beforeLoad : function(){
13068 this.addClass("x-tree-node-loading");
13071 afterLoad : function(){
13072 this.removeClass("x-tree-node-loading");
13075 onTextChange : function(node, text, oldText){
13077 this.textNode.innerHTML = text;
13081 onDisableChange : function(node, state){
13082 this.disabled = state;
13084 this.addClass("x-tree-node-disabled");
13086 this.removeClass("x-tree-node-disabled");
13090 onSelectedChange : function(state){
13093 this.addClass("x-tree-selected");
13096 this.removeClass("x-tree-selected");
13100 onMove : function(tree, node, oldParent, newParent, index, refNode){
13101 this.childIndent = null;
13103 var targetNode = newParent.ui.getContainer();
13104 if(!targetNode){//target not rendered
13105 this.holder = document.createElement("div");
13106 this.holder.appendChild(this.wrap);
13109 var insertBefore = refNode ? refNode.ui.getEl() : null;
13111 targetNode.insertBefore(this.wrap, insertBefore);
13113 targetNode.appendChild(this.wrap);
13115 this.node.renderIndent(true);
13119 addClass : function(cls){
13121 Roo.fly(this.elNode).addClass(cls);
13125 removeClass : function(cls){
13127 Roo.fly(this.elNode).removeClass(cls);
13131 remove : function(){
13133 this.holder = document.createElement("div");
13134 this.holder.appendChild(this.wrap);
13138 fireEvent : function(){
13139 return this.node.fireEvent.apply(this.node, arguments);
13142 initEvents : function(){
13143 this.node.on("move", this.onMove, this);
13144 var E = Roo.EventManager;
13145 var a = this.anchor;
13147 var el = Roo.fly(a, '_treeui');
13149 if(Roo.isOpera){ // opera render bug ignores the CSS
13150 el.setStyle("text-decoration", "none");
13153 el.on("click", this.onClick, this);
13154 el.on("dblclick", this.onDblClick, this);
13157 Roo.EventManager.on(this.checkbox,
13158 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
13161 el.on("contextmenu", this.onContextMenu, this);
13163 var icon = Roo.fly(this.iconNode);
13164 icon.on("click", this.onClick, this);
13165 icon.on("dblclick", this.onDblClick, this);
13166 icon.on("contextmenu", this.onContextMenu, this);
13167 E.on(this.ecNode, "click", this.ecClick, this, true);
13169 if(this.node.disabled){
13170 this.addClass("x-tree-node-disabled");
13172 if(this.node.hidden){
13173 this.addClass("x-tree-node-disabled");
13175 var ot = this.node.getOwnerTree();
13176 var dd = ot ? (ot.enableDD || ot.enableDrag || ot.enableDrop) : false;
13177 if(dd && (!this.node.isRoot || ot.rootVisible)){
13178 Roo.dd.Registry.register(this.elNode, {
13180 handles: this.getDDHandles(),
13186 getDDHandles : function(){
13187 return [this.iconNode, this.textNode];
13192 this.wrap.style.display = "none";
13198 this.wrap.style.display = "";
13202 onContextMenu : function(e){
13203 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
13204 e.preventDefault();
13206 this.fireEvent("contextmenu", this.node, e);
13210 onClick : function(e){
13215 if(this.fireEvent("beforeclick", this.node, e) !== false){
13216 if(!this.disabled && this.node.attributes.href){
13217 this.fireEvent("click", this.node, e);
13220 e.preventDefault();
13225 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
13226 this.node.toggle();
13229 this.fireEvent("click", this.node, e);
13235 onDblClick : function(e){
13236 e.preventDefault();
13241 this.toggleCheck();
13243 if(!this.animating && this.node.hasChildNodes()){
13244 this.node.toggle();
13246 this.fireEvent("dblclick", this.node, e);
13249 onCheckChange : function(){
13250 var checked = this.checkbox.checked;
13251 this.node.attributes.checked = checked;
13252 this.fireEvent('checkchange', this.node, checked);
13255 ecClick : function(e){
13256 if(!this.animating && this.node.hasChildNodes()){
13257 this.node.toggle();
13261 startDrop : function(){
13262 this.dropping = true;
13265 // delayed drop so the click event doesn't get fired on a drop
13266 endDrop : function(){
13267 setTimeout(function(){
13268 this.dropping = false;
13269 }.createDelegate(this), 50);
13272 expand : function(){
13273 this.updateExpandIcon();
13274 this.ctNode.style.display = "";
13277 focus : function(){
13278 if(!this.node.preventHScroll){
13279 try{this.anchor.focus();
13281 }else if(!Roo.isIE){
13283 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
13284 var l = noscroll.scrollLeft;
13285 this.anchor.focus();
13286 noscroll.scrollLeft = l;
13291 toggleCheck : function(value){
13292 var cb = this.checkbox;
13294 cb.checked = (value === undefined ? !cb.checked : value);
13300 this.anchor.blur();
13304 animExpand : function(callback){
13305 var ct = Roo.get(this.ctNode);
13307 if(!this.node.hasChildNodes()){
13308 this.updateExpandIcon();
13309 this.ctNode.style.display = "";
13310 Roo.callback(callback);
13313 this.animating = true;
13314 this.updateExpandIcon();
13317 callback : function(){
13318 this.animating = false;
13319 Roo.callback(callback);
13322 duration: this.node.ownerTree.duration || .25
13326 highlight : function(){
13327 var tree = this.node.getOwnerTree();
13328 Roo.fly(this.wrap).highlight(
13329 tree.hlColor || "C3DAF9",
13330 {endColor: tree.hlBaseColor}
13334 collapse : function(){
13335 this.updateExpandIcon();
13336 this.ctNode.style.display = "none";
13339 animCollapse : function(callback){
13340 var ct = Roo.get(this.ctNode);
13341 ct.enableDisplayMode('block');
13344 this.animating = true;
13345 this.updateExpandIcon();
13348 callback : function(){
13349 this.animating = false;
13350 Roo.callback(callback);
13353 duration: this.node.ownerTree.duration || .25
13357 getContainer : function(){
13358 return this.ctNode;
13361 getEl : function(){
13365 appendDDGhost : function(ghostNode){
13366 ghostNode.appendChild(this.elNode.cloneNode(true));
13369 getDDRepairXY : function(){
13370 return Roo.lib.Dom.getXY(this.iconNode);
13373 onRender : function(){
13377 render : function(bulkRender){
13378 var n = this.node, a = n.attributes;
13379 var targetNode = n.parentNode ?
13380 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
13382 if(!this.rendered){
13383 this.rendered = true;
13385 this.renderElements(n, a, targetNode, bulkRender);
13388 if(this.textNode.setAttributeNS){
13389 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
13391 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
13394 this.textNode.setAttribute("ext:qtip", a.qtip);
13396 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
13399 }else if(a.qtipCfg){
13400 a.qtipCfg.target = Roo.id(this.textNode);
13401 Roo.QuickTips.register(a.qtipCfg);
13404 if(!this.node.expanded){
13405 this.updateExpandIcon();
13408 if(bulkRender === true) {
13409 targetNode.appendChild(this.wrap);
13414 renderElements : function(n, a, targetNode, bulkRender)
13416 // add some indent caching, this helps performance when rendering a large tree
13417 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
13418 var t = n.getOwnerTree();
13419 var txt = t && t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
13420 if (typeof(n.attributes.html) != 'undefined') {
13421 txt = n.attributes.html;
13423 var tip = t && t.rendererTip ? t.rendererTip(n.attributes) : txt;
13424 var cb = typeof a.checked == 'boolean';
13425 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
13426 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
13427 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
13428 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
13429 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
13430 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
13431 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
13432 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
13433 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
13434 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
13437 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
13438 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
13439 n.nextSibling.ui.getEl(), buf.join(""));
13441 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
13444 this.elNode = this.wrap.childNodes[0];
13445 this.ctNode = this.wrap.childNodes[1];
13446 var cs = this.elNode.childNodes;
13447 this.indentNode = cs[0];
13448 this.ecNode = cs[1];
13449 this.iconNode = cs[2];
13452 this.checkbox = cs[3];
13455 this.anchor = cs[index];
13456 this.textNode = cs[index].firstChild;
13459 getAnchor : function(){
13460 return this.anchor;
13463 getTextEl : function(){
13464 return this.textNode;
13467 getIconEl : function(){
13468 return this.iconNode;
13471 isChecked : function(){
13472 return this.checkbox ? this.checkbox.checked : false;
13475 updateExpandIcon : function(){
13477 var n = this.node, c1, c2;
13478 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
13479 var hasChild = n.hasChildNodes();
13483 c1 = "x-tree-node-collapsed";
13484 c2 = "x-tree-node-expanded";
13487 c1 = "x-tree-node-expanded";
13488 c2 = "x-tree-node-collapsed";
13491 this.removeClass("x-tree-node-leaf");
13492 this.wasLeaf = false;
13494 if(this.c1 != c1 || this.c2 != c2){
13495 Roo.fly(this.elNode).replaceClass(c1, c2);
13496 this.c1 = c1; this.c2 = c2;
13499 // this changes non-leafs into leafs if they have no children.
13500 // it's not very rational behaviour..
13502 if(!this.wasLeaf && this.node.leaf){
13503 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
13506 this.wasLeaf = true;
13509 var ecc = "x-tree-ec-icon "+cls;
13510 if(this.ecc != ecc){
13511 this.ecNode.className = ecc;
13517 getChildIndent : function(){
13518 if(!this.childIndent){
13522 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
13524 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
13526 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
13531 this.childIndent = buf.join("");
13533 return this.childIndent;
13536 renderIndent : function(){
13539 var p = this.node.parentNode;
13541 indent = p.ui.getChildIndent();
13543 if(this.indentMarkup != indent){ // don't rerender if not required
13544 this.indentNode.innerHTML = indent;
13545 this.indentMarkup = indent;
13547 this.updateExpandIcon();
13552 Roo.tree.RootTreeNodeUI = function(){
13553 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
13555 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
13556 render : function(){
13557 if(!this.rendered){
13558 var targetNode = this.node.ownerTree.innerCt.dom;
13559 this.node.expanded = true;
13560 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
13561 this.wrap = this.ctNode = targetNode.firstChild;
13564 collapse : function(){
13566 expand : function(){
13570 * Ext JS Library 1.1.1
13571 * Copyright(c) 2006-2007, Ext JS, LLC.
13573 * Originally Released Under LGPL - original licence link has changed is not relivant.
13576 * <script type="text/javascript">
13579 * @class Roo.tree.TreeLoader
13580 * @extends Roo.util.Observable
13581 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
13582 * nodes from a specified URL. The response must be a javascript Array definition
13583 * who's elements are node definition objects. eg:
13588 { 'id': 1, 'text': 'A folder Node', 'leaf': false },
13589 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }
13596 * The old style respose with just an array is still supported, but not recommended.
13599 * A server request is sent, and child nodes are loaded only when a node is expanded.
13600 * The loading node's id is passed to the server under the parameter name "node" to
13601 * enable the server to produce the correct child nodes.
13603 * To pass extra parameters, an event handler may be attached to the "beforeload"
13604 * event, and the parameters specified in the TreeLoader's baseParams property:
13606 myTreeLoader.on("beforeload", function(treeLoader, node) {
13607 this.baseParams.category = node.attributes.category;
13612 * This would pass an HTTP parameter called "category" to the server containing
13613 * the value of the Node's "category" attribute.
13615 * Creates a new Treeloader.
13616 * @param {Object} config A config object containing config properties.
13618 Roo.tree.TreeLoader = function(config){
13619 this.baseParams = {};
13620 this.requestMethod = "POST";
13621 Roo.apply(this, config);
13626 * @event beforeload
13627 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
13628 * @param {Object} This TreeLoader object.
13629 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13630 * @param {Object} callback The callback function specified in the {@link #load} call.
13635 * Fires when the node has been successfuly loaded.
13636 * @param {Object} This TreeLoader object.
13637 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13638 * @param {Object} response The response object containing the data from the server.
13642 * @event loadexception
13643 * Fires if the network request failed.
13644 * @param {Object} This TreeLoader object.
13645 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13646 * @param {Object} response The response object containing the data from the server.
13648 loadexception : true,
13651 * Fires before a node is created, enabling you to return custom Node types
13652 * @param {Object} This TreeLoader object.
13653 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
13658 Roo.tree.TreeLoader.superclass.constructor.call(this);
13661 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
13663 * @cfg {String} dataUrl The URL from which to request a Json string which
13664 * specifies an array of node definition object representing the child nodes
13668 * @cfg {String} requestMethod either GET or POST
13669 * defaults to POST (due to BC)
13673 * @cfg {Object} baseParams (optional) An object containing properties which
13674 * specify HTTP parameters to be passed to each request for child nodes.
13677 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
13678 * created by this loader. If the attributes sent by the server have an attribute in this object,
13679 * they take priority.
13682 * @cfg {Object} uiProviders (optional) An object containing properties which
13684 * DEPRECATED - use 'create' event handler to modify attributes - which affect creation.
13685 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
13686 * <i>uiProvider</i> attribute of a returned child node is a string rather
13687 * than a reference to a TreeNodeUI implementation, this that string value
13688 * is used as a property name in the uiProviders object. You can define the provider named
13689 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
13694 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
13695 * child nodes before loading.
13697 clearOnLoad : true,
13700 * @cfg {String} root (optional) Default to false. Use this to read data from an object
13701 * property on loading, rather than expecting an array. (eg. more compatible to a standard
13702 * Grid query { data : [ .....] }
13707 * @cfg {String} queryParam (optional)
13708 * Name of the query as it will be passed on the querystring (defaults to 'node')
13709 * eg. the request will be ?node=[id]
13716 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
13717 * This is called automatically when a node is expanded, but may be used to reload
13718 * a node (or append new children if the {@link #clearOnLoad} option is false.)
13719 * @param {Roo.tree.TreeNode} node
13720 * @param {Function} callback
13722 load : function(node, callback){
13723 if(this.clearOnLoad){
13724 while(node.firstChild){
13725 node.removeChild(node.firstChild);
13728 if(node.attributes.children){ // preloaded json children
13729 var cs = node.attributes.children;
13730 for(var i = 0, len = cs.length; i < len; i++){
13731 node.appendChild(this.createNode(cs[i]));
13733 if(typeof callback == "function"){
13736 }else if(this.dataUrl){
13737 this.requestData(node, callback);
13741 getParams: function(node){
13742 var buf = [], bp = this.baseParams;
13743 for(var key in bp){
13744 if(typeof bp[key] != "function"){
13745 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
13748 var n = this.queryParam === false ? 'node' : this.queryParam;
13749 buf.push(n + "=", encodeURIComponent(node.id));
13750 return buf.join("");
13753 requestData : function(node, callback){
13754 if(this.fireEvent("beforeload", this, node, callback) !== false){
13755 this.transId = Roo.Ajax.request({
13756 method:this.requestMethod,
13757 url: this.dataUrl||this.url,
13758 success: this.handleResponse,
13759 failure: this.handleFailure,
13761 argument: {callback: callback, node: node},
13762 params: this.getParams(node)
13765 // if the load is cancelled, make sure we notify
13766 // the node that we are done
13767 if(typeof callback == "function"){
13773 isLoading : function(){
13774 return this.transId ? true : false;
13777 abort : function(){
13778 if(this.isLoading()){
13779 Roo.Ajax.abort(this.transId);
13784 createNode : function(attr)
13786 // apply baseAttrs, nice idea Corey!
13787 if(this.baseAttrs){
13788 Roo.applyIf(attr, this.baseAttrs);
13790 if(this.applyLoader !== false){
13791 attr.loader = this;
13793 // uiProvider = depreciated..
13795 if(typeof(attr.uiProvider) == 'string'){
13796 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
13797 /** eval:var:attr */ eval(attr.uiProvider);
13799 if(typeof(this.uiProviders['default']) != 'undefined') {
13800 attr.uiProvider = this.uiProviders['default'];
13803 this.fireEvent('create', this, attr);
13805 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
13807 new Roo.tree.TreeNode(attr) :
13808 new Roo.tree.AsyncTreeNode(attr));
13811 processResponse : function(response, node, callback)
13813 var json = response.responseText;
13816 var o = Roo.decode(json);
13818 if (this.root === false && typeof(o.success) != undefined) {
13819 this.root = 'data'; // the default behaviour for list like data..
13822 if (this.root !== false && !o.success) {
13823 // it's a failure condition.
13824 var a = response.argument;
13825 this.fireEvent("loadexception", this, a.node, response);
13826 Roo.log("Load failed - should have a handler really");
13832 if (this.root !== false) {
13836 for(var i = 0, len = o.length; i < len; i++){
13837 var n = this.createNode(o[i]);
13839 node.appendChild(n);
13842 if(typeof callback == "function"){
13843 callback(this, node);
13846 this.handleFailure(response);
13850 handleResponse : function(response){
13851 this.transId = false;
13852 var a = response.argument;
13853 this.processResponse(response, a.node, a.callback);
13854 this.fireEvent("load", this, a.node, response);
13857 handleFailure : function(response)
13859 // should handle failure better..
13860 this.transId = false;
13861 var a = response.argument;
13862 this.fireEvent("loadexception", this, a.node, response);
13863 if(typeof a.callback == "function"){
13864 a.callback(this, a.node);
13869 * Ext JS Library 1.1.1
13870 * Copyright(c) 2006-2007, Ext JS, LLC.
13872 * Originally Released Under LGPL - original licence link has changed is not relivant.
13875 * <script type="text/javascript">
13879 * @class Roo.tree.TreeFilter
13880 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
13881 * @param {TreePanel} tree
13882 * @param {Object} config (optional)
13884 Roo.tree.TreeFilter = function(tree, config){
13886 this.filtered = {};
13887 Roo.apply(this, config);
13890 Roo.tree.TreeFilter.prototype = {
13897 * Filter the data by a specific attribute.
13898 * @param {String/RegExp} value Either string that the attribute value
13899 * should start with or a RegExp to test against the attribute
13900 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
13901 * @param {TreeNode} startNode (optional) The node to start the filter at.
13903 filter : function(value, attr, startNode){
13904 attr = attr || "text";
13906 if(typeof value == "string"){
13907 var vlen = value.length;
13908 // auto clear empty filter
13909 if(vlen == 0 && this.clearBlank){
13913 value = value.toLowerCase();
13915 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
13917 }else if(value.exec){ // regex?
13919 return value.test(n.attributes[attr]);
13922 throw 'Illegal filter type, must be string or regex';
13924 this.filterBy(f, null, startNode);
13928 * Filter by a function. The passed function will be called with each
13929 * node in the tree (or from the startNode). If the function returns true, the node is kept
13930 * otherwise it is filtered. If a node is filtered, its children are also filtered.
13931 * @param {Function} fn The filter function
13932 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
13934 filterBy : function(fn, scope, startNode){
13935 startNode = startNode || this.tree.root;
13936 if(this.autoClear){
13939 var af = this.filtered, rv = this.reverse;
13940 var f = function(n){
13941 if(n == startNode){
13947 var m = fn.call(scope || n, n);
13955 startNode.cascade(f);
13958 if(typeof id != "function"){
13960 if(n && n.parentNode){
13961 n.parentNode.removeChild(n);
13969 * Clears the current filter. Note: with the "remove" option
13970 * set a filter cannot be cleared.
13972 clear : function(){
13974 var af = this.filtered;
13976 if(typeof id != "function"){
13983 this.filtered = {};
13988 * Ext JS Library 1.1.1
13989 * Copyright(c) 2006-2007, Ext JS, LLC.
13991 * Originally Released Under LGPL - original licence link has changed is not relivant.
13994 * <script type="text/javascript">
13999 * @class Roo.tree.TreeSorter
14000 * Provides sorting of nodes in a TreePanel
14002 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
14003 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
14004 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
14005 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
14006 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
14007 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
14009 * @param {TreePanel} tree
14010 * @param {Object} config
14012 Roo.tree.TreeSorter = function(tree, config){
14013 Roo.apply(this, config);
14014 tree.on("beforechildrenrendered", this.doSort, this);
14015 tree.on("append", this.updateSort, this);
14016 tree.on("insert", this.updateSort, this);
14018 var dsc = this.dir && this.dir.toLowerCase() == "desc";
14019 var p = this.property || "text";
14020 var sortType = this.sortType;
14021 var fs = this.folderSort;
14022 var cs = this.caseSensitive === true;
14023 var leafAttr = this.leafAttr || 'leaf';
14025 this.sortFn = function(n1, n2){
14027 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
14030 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
14034 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
14035 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
14037 return dsc ? +1 : -1;
14039 return dsc ? -1 : +1;
14046 Roo.tree.TreeSorter.prototype = {
14047 doSort : function(node){
14048 node.sort(this.sortFn);
14051 compareNodes : function(n1, n2){
14052 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
14055 updateSort : function(tree, node){
14056 if(node.childrenRendered){
14057 this.doSort.defer(1, this, [node]);
14062 * Ext JS Library 1.1.1
14063 * Copyright(c) 2006-2007, Ext JS, LLC.
14065 * Originally Released Under LGPL - original licence link has changed is not relivant.
14068 * <script type="text/javascript">
14071 if(Roo.dd.DropZone){
14073 Roo.tree.TreeDropZone = function(tree, config){
14074 this.allowParentInsert = false;
14075 this.allowContainerDrop = false;
14076 this.appendOnly = false;
14077 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
14079 this.lastInsertClass = "x-tree-no-status";
14080 this.dragOverData = {};
14083 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
14084 ddGroup : "TreeDD",
14087 expandDelay : 1000,
14089 expandNode : function(node){
14090 if(node.hasChildNodes() && !node.isExpanded()){
14091 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
14095 queueExpand : function(node){
14096 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
14099 cancelExpand : function(){
14100 if(this.expandProcId){
14101 clearTimeout(this.expandProcId);
14102 this.expandProcId = false;
14106 isValidDropPoint : function(n, pt, dd, e, data){
14107 if(!n || !data){ return false; }
14108 var targetNode = n.node;
14109 var dropNode = data.node;
14110 // default drop rules
14111 if(!(targetNode && targetNode.isTarget && pt)){
14114 if(pt == "append" && targetNode.allowChildren === false){
14117 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
14120 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
14123 // reuse the object
14124 var overEvent = this.dragOverData;
14125 overEvent.tree = this.tree;
14126 overEvent.target = targetNode;
14127 overEvent.data = data;
14128 overEvent.point = pt;
14129 overEvent.source = dd;
14130 overEvent.rawEvent = e;
14131 overEvent.dropNode = dropNode;
14132 overEvent.cancel = false;
14133 var result = this.tree.fireEvent("nodedragover", overEvent);
14134 return overEvent.cancel === false && result !== false;
14137 getDropPoint : function(e, n, dd)
14141 return tn.allowChildren !== false ? "append" : false; // always append for root
14143 var dragEl = n.ddel;
14144 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
14145 var y = Roo.lib.Event.getPageY(e);
14146 //var noAppend = tn.allowChildren === false || tn.isLeaf();
14148 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
14149 var noAppend = tn.allowChildren === false;
14150 if(this.appendOnly || tn.parentNode.allowChildren === false){
14151 return noAppend ? false : "append";
14153 var noBelow = false;
14154 if(!this.allowParentInsert){
14155 noBelow = tn.hasChildNodes() && tn.isExpanded();
14157 var q = (b - t) / (noAppend ? 2 : 3);
14158 if(y >= t && y < (t + q)){
14160 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
14167 onNodeEnter : function(n, dd, e, data)
14169 this.cancelExpand();
14172 onNodeOver : function(n, dd, e, data)
14175 var pt = this.getDropPoint(e, n, dd);
14178 // auto node expand check
14179 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
14180 this.queueExpand(node);
14181 }else if(pt != "append"){
14182 this.cancelExpand();
14185 // set the insert point style on the target node
14186 var returnCls = this.dropNotAllowed;
14187 if(this.isValidDropPoint(n, pt, dd, e, data)){
14192 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
14193 cls = "x-tree-drag-insert-above";
14194 }else if(pt == "below"){
14195 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
14196 cls = "x-tree-drag-insert-below";
14198 returnCls = "x-tree-drop-ok-append";
14199 cls = "x-tree-drag-append";
14201 if(this.lastInsertClass != cls){
14202 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
14203 this.lastInsertClass = cls;
14210 onNodeOut : function(n, dd, e, data){
14212 this.cancelExpand();
14213 this.removeDropIndicators(n);
14216 onNodeDrop : function(n, dd, e, data){
14217 var point = this.getDropPoint(e, n, dd);
14218 var targetNode = n.node;
14219 targetNode.ui.startDrop();
14220 if(!this.isValidDropPoint(n, point, dd, e, data)){
14221 targetNode.ui.endDrop();
14224 // first try to find the drop node
14225 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
14228 target: targetNode,
14233 dropNode: dropNode,
14236 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
14237 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
14238 targetNode.ui.endDrop();
14241 // allow target changing
14242 targetNode = dropEvent.target;
14243 if(point == "append" && !targetNode.isExpanded()){
14244 targetNode.expand(false, null, function(){
14245 this.completeDrop(dropEvent);
14246 }.createDelegate(this));
14248 this.completeDrop(dropEvent);
14253 completeDrop : function(de){
14254 var ns = de.dropNode, p = de.point, t = de.target;
14255 if(!(ns instanceof Array)){
14259 for(var i = 0, len = ns.length; i < len; i++){
14262 t.parentNode.insertBefore(n, t);
14263 }else if(p == "below"){
14264 t.parentNode.insertBefore(n, t.nextSibling);
14270 if(this.tree.hlDrop){
14274 this.tree.fireEvent("nodedrop", de);
14277 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
14278 if(this.tree.hlDrop){
14279 dropNode.ui.focus();
14280 dropNode.ui.highlight();
14282 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
14285 getTree : function(){
14289 removeDropIndicators : function(n){
14292 Roo.fly(el).removeClass([
14293 "x-tree-drag-insert-above",
14294 "x-tree-drag-insert-below",
14295 "x-tree-drag-append"]);
14296 this.lastInsertClass = "_noclass";
14300 beforeDragDrop : function(target, e, id){
14301 this.cancelExpand();
14305 afterRepair : function(data){
14306 if(data && Roo.enableFx){
14307 data.node.ui.highlight();
14317 * Ext JS Library 1.1.1
14318 * Copyright(c) 2006-2007, Ext JS, LLC.
14320 * Originally Released Under LGPL - original licence link has changed is not relivant.
14323 * <script type="text/javascript">
14327 if(Roo.dd.DragZone){
14328 Roo.tree.TreeDragZone = function(tree, config){
14329 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
14333 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
14334 ddGroup : "TreeDD",
14336 onBeforeDrag : function(data, e){
14338 return n && n.draggable && !n.disabled;
14342 onInitDrag : function(e){
14343 var data = this.dragData;
14344 this.tree.getSelectionModel().select(data.node);
14345 this.proxy.update("");
14346 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
14347 this.tree.fireEvent("startdrag", this.tree, data.node, e);
14350 getRepairXY : function(e, data){
14351 return data.node.ui.getDDRepairXY();
14354 onEndDrag : function(data, e){
14355 this.tree.fireEvent("enddrag", this.tree, data.node, e);
14360 onValidDrop : function(dd, e, id){
14361 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
14365 beforeInvalidDrop : function(e, id){
14366 // this scrolls the original position back into view
14367 var sm = this.tree.getSelectionModel();
14368 sm.clearSelections();
14369 sm.select(this.dragData.node);
14374 * Ext JS Library 1.1.1
14375 * Copyright(c) 2006-2007, Ext JS, LLC.
14377 * Originally Released Under LGPL - original licence link has changed is not relivant.
14380 * <script type="text/javascript">
14383 * @class Roo.tree.TreeEditor
14384 * @extends Roo.Editor
14385 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
14386 * as the editor field.
14388 * @param {Object} config (used to be the tree panel.)
14389 * @param {Object} oldconfig DEPRECIATED Either a prebuilt {@link Roo.form.Field} instance or a Field config object
14391 * @cfg {Roo.tree.TreePanel} tree The tree to bind to.
14392 * @cfg {Roo.form.TextField|Object} field The field configuration
14396 Roo.tree.TreeEditor = function(config, oldconfig) { // was -- (tree, config){
14399 if (oldconfig) { // old style..
14400 field = oldconfig.events ? oldconfig : new Roo.form.TextField(oldconfig);
14403 tree = config.tree;
14404 config.field = config.field || {};
14405 config.field.xtype = 'TextField';
14406 field = Roo.factory(config.field, Roo.form);
14408 config = config || {};
14413 * @event beforenodeedit
14414 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
14415 * false from the handler of this event.
14416 * @param {Editor} this
14417 * @param {Roo.tree.Node} node
14419 "beforenodeedit" : true
14423 Roo.tree.TreeEditor.superclass.constructor.call(this, field, config);
14427 tree.on('beforeclick', this.beforeNodeClick, this);
14428 tree.getTreeEl().on('mousedown', this.hide, this);
14429 this.on('complete', this.updateNode, this);
14430 this.on('beforestartedit', this.fitToTree, this);
14431 this.on('startedit', this.bindScroll, this, {delay:10});
14432 this.on('specialkey', this.onSpecialKey, this);
14435 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
14437 * @cfg {String} alignment
14438 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
14444 * @cfg {Boolean} hideEl
14445 * True to hide the bound element while the editor is displayed (defaults to false)
14449 * @cfg {String} cls
14450 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
14452 cls: "x-small-editor x-tree-editor",
14454 * @cfg {Boolean} shim
14455 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
14461 * @cfg {Number} maxWidth
14462 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
14463 * the containing tree element's size, it will be automatically limited for you to the container width, taking
14464 * scroll and client offsets into account prior to each edit.
14471 fitToTree : function(ed, el){
14472 var td = this.tree.getTreeEl().dom, nd = el.dom;
14473 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
14474 td.scrollLeft = nd.offsetLeft;
14478 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
14479 this.setSize(w, '');
14481 return this.fireEvent('beforenodeedit', this, this.editNode);
14486 triggerEdit : function(node){
14487 this.completeEdit();
14488 this.editNode = node;
14489 this.startEdit(node.ui.textNode, node.text);
14493 bindScroll : function(){
14494 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
14498 beforeNodeClick : function(node, e){
14499 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
14500 this.lastClick = new Date();
14501 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
14503 this.triggerEdit(node);
14510 updateNode : function(ed, value){
14511 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
14512 this.editNode.setText(value);
14516 onHide : function(){
14517 Roo.tree.TreeEditor.superclass.onHide.call(this);
14519 this.editNode.ui.focus();
14524 onSpecialKey : function(field, e){
14525 var k = e.getKey();
14529 }else if(k == e.ENTER && !e.hasModifier()){
14531 this.completeEdit();
14534 });//<Script type="text/javascript">
14537 * Ext JS Library 1.1.1
14538 * Copyright(c) 2006-2007, Ext JS, LLC.
14540 * Originally Released Under LGPL - original licence link has changed is not relivant.
14543 * <script type="text/javascript">
14547 * Not documented??? - probably should be...
14550 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
14551 //focus: Roo.emptyFn, // prevent odd scrolling behavior
14553 renderElements : function(n, a, targetNode, bulkRender){
14554 //consel.log("renderElements?");
14555 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
14557 var t = n.getOwnerTree();
14558 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
14560 var cols = t.columns;
14561 var bw = t.borderWidth;
14563 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
14564 var cb = typeof a.checked == "boolean";
14565 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
14566 var colcls = 'x-t-' + tid + '-c0';
14568 '<li class="x-tree-node">',
14571 '<div class="x-tree-node-el ', a.cls,'">',
14573 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
14576 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
14577 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
14578 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
14579 (a.icon ? ' x-tree-node-inline-icon' : ''),
14580 (a.iconCls ? ' '+a.iconCls : ''),
14581 '" unselectable="on" />',
14582 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
14583 (a.checked ? 'checked="checked" />' : ' />')) : ''),
14585 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
14586 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
14587 '<span unselectable="on" qtip="' + tx + '">',
14591 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
14592 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>'
14594 for(var i = 1, len = cols.length; i < len; i++){
14596 colcls = 'x-t-' + tid + '-c' +i;
14597 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
14598 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
14599 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
14605 '<div class="x-clear"></div></div>',
14606 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
14609 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
14610 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
14611 n.nextSibling.ui.getEl(), buf.join(""));
14613 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
14615 var el = this.wrap.firstChild;
14617 this.elNode = el.firstChild;
14618 this.ranchor = el.childNodes[1];
14619 this.ctNode = this.wrap.childNodes[1];
14620 var cs = el.firstChild.childNodes;
14621 this.indentNode = cs[0];
14622 this.ecNode = cs[1];
14623 this.iconNode = cs[2];
14626 this.checkbox = cs[3];
14629 this.anchor = cs[index];
14631 this.textNode = cs[index].firstChild;
14633 //el.on("click", this.onClick, this);
14634 //el.on("dblclick", this.onDblClick, this);
14637 // console.log(this);
14639 initEvents : function(){
14640 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
14643 var a = this.ranchor;
14645 var el = Roo.get(a);
14647 if(Roo.isOpera){ // opera render bug ignores the CSS
14648 el.setStyle("text-decoration", "none");
14651 el.on("click", this.onClick, this);
14652 el.on("dblclick", this.onDblClick, this);
14653 el.on("contextmenu", this.onContextMenu, this);
14657 /*onSelectedChange : function(state){
14660 this.addClass("x-tree-selected");
14663 this.removeClass("x-tree-selected");
14666 addClass : function(cls){
14668 Roo.fly(this.elRow).addClass(cls);
14674 removeClass : function(cls){
14676 Roo.fly(this.elRow).removeClass(cls);
14682 });//<Script type="text/javascript">
14686 * Ext JS Library 1.1.1
14687 * Copyright(c) 2006-2007, Ext JS, LLC.
14689 * Originally Released Under LGPL - original licence link has changed is not relivant.
14692 * <script type="text/javascript">
14697 * @class Roo.tree.ColumnTree
14698 * @extends Roo.data.TreePanel
14699 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
14700 * @cfg {int} borderWidth compined right/left border allowance
14702 * @param {String/HTMLElement/Element} el The container element
14703 * @param {Object} config
14705 Roo.tree.ColumnTree = function(el, config)
14707 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
14711 * Fire this event on a container when it resizes
14712 * @param {int} w Width
14713 * @param {int} h Height
14717 this.on('resize', this.onResize, this);
14720 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
14724 borderWidth: Roo.isBorderBox ? 0 : 2,
14727 render : function(){
14728 // add the header.....
14730 Roo.tree.ColumnTree.superclass.render.apply(this);
14732 this.el.addClass('x-column-tree');
14734 this.headers = this.el.createChild(
14735 {cls:'x-tree-headers'},this.innerCt.dom);
14737 var cols = this.columns, c;
14738 var totalWidth = 0;
14740 var len = cols.length;
14741 for(var i = 0; i < len; i++){
14743 totalWidth += c.width;
14744 this.headEls.push(this.headers.createChild({
14745 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
14747 cls:'x-tree-hd-text',
14750 style:'width:'+(c.width-this.borderWidth)+'px;'
14753 this.headers.createChild({cls:'x-clear'});
14754 // prevent floats from wrapping when clipped
14755 this.headers.setWidth(totalWidth);
14756 //this.innerCt.setWidth(totalWidth);
14757 this.innerCt.setStyle({ overflow: 'auto' });
14758 this.onResize(this.width, this.height);
14762 onResize : function(w,h)
14767 this.innerCt.setWidth(this.width);
14768 this.innerCt.setHeight(this.height-20);
14771 var cols = this.columns, c;
14772 var totalWidth = 0;
14774 var len = cols.length;
14775 for(var i = 0; i < len; i++){
14777 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
14778 // it's the expander..
14779 expEl = this.headEls[i];
14782 totalWidth += c.width;
14786 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
14788 this.headers.setWidth(w-20);
14797 * Ext JS Library 1.1.1
14798 * Copyright(c) 2006-2007, Ext JS, LLC.
14800 * Originally Released Under LGPL - original licence link has changed is not relivant.
14803 * <script type="text/javascript">
14807 * @class Roo.menu.Menu
14808 * @extends Roo.util.Observable
14809 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
14810 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
14812 * Creates a new Menu
14813 * @param {Object} config Configuration options
14815 Roo.menu.Menu = function(config){
14817 Roo.menu.Menu.superclass.constructor.call(this, config);
14819 this.id = this.id || Roo.id();
14822 * @event beforeshow
14823 * Fires before this menu is displayed
14824 * @param {Roo.menu.Menu} this
14828 * @event beforehide
14829 * Fires before this menu is hidden
14830 * @param {Roo.menu.Menu} this
14835 * Fires after this menu is displayed
14836 * @param {Roo.menu.Menu} this
14841 * Fires after this menu is hidden
14842 * @param {Roo.menu.Menu} this
14847 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
14848 * @param {Roo.menu.Menu} this
14849 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14850 * @param {Roo.EventObject} e
14855 * Fires when the mouse is hovering over this menu
14856 * @param {Roo.menu.Menu} this
14857 * @param {Roo.EventObject} e
14858 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14863 * Fires when the mouse exits this menu
14864 * @param {Roo.menu.Menu} this
14865 * @param {Roo.EventObject} e
14866 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14871 * Fires when a menu item contained in this menu is clicked
14872 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
14873 * @param {Roo.EventObject} e
14877 if (this.registerMenu) {
14878 Roo.menu.MenuMgr.register(this);
14881 var mis = this.items;
14882 this.items = new Roo.util.MixedCollection();
14884 this.add.apply(this, mis);
14888 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
14890 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
14894 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
14895 * for bottom-right shadow (defaults to "sides")
14899 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
14900 * this menu (defaults to "tl-tr?")
14902 subMenuAlign : "tl-tr?",
14904 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
14905 * relative to its element of origin (defaults to "tl-bl?")
14907 defaultAlign : "tl-bl?",
14909 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
14911 allowOtherMenus : false,
14913 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
14915 registerMenu : true,
14920 render : function(){
14924 var el = this.el = new Roo.Layer({
14926 shadow:this.shadow,
14928 parentEl: this.parentEl || document.body,
14932 this.keyNav = new Roo.menu.MenuNav(this);
14935 el.addClass("x-menu-plain");
14938 el.addClass(this.cls);
14940 // generic focus element
14941 this.focusEl = el.createChild({
14942 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
14944 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
14945 //disabling touch- as it's causing issues ..
14946 //ul.on(Roo.isTouch ? 'touchstart' : 'click' , this.onClick, this);
14947 ul.on('click' , this.onClick, this);
14950 ul.on("mouseover", this.onMouseOver, this);
14951 ul.on("mouseout", this.onMouseOut, this);
14952 this.items.each(function(item){
14957 var li = document.createElement("li");
14958 li.className = "x-menu-list-item";
14959 ul.dom.appendChild(li);
14960 item.render(li, this);
14967 autoWidth : function(){
14968 var el = this.el, ul = this.ul;
14972 var w = this.width;
14975 }else if(Roo.isIE){
14976 el.setWidth(this.minWidth);
14977 var t = el.dom.offsetWidth; // force recalc
14978 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
14983 delayAutoWidth : function(){
14986 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
14988 this.awTask.delay(20);
14993 findTargetItem : function(e){
14994 var t = e.getTarget(".x-menu-list-item", this.ul, true);
14995 if(t && t.menuItemId){
14996 return this.items.get(t.menuItemId);
15001 onClick : function(e){
15002 Roo.log("menu.onClick");
15003 var t = this.findTargetItem(e);
15008 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
15009 if(t == this.activeItem && t.shouldDeactivate(e)){
15010 this.activeItem.deactivate();
15011 delete this.activeItem;
15015 this.setActiveItem(t, true);
15023 this.fireEvent("click", this, t, e);
15027 setActiveItem : function(item, autoExpand){
15028 if(item != this.activeItem){
15029 if(this.activeItem){
15030 this.activeItem.deactivate();
15032 this.activeItem = item;
15033 item.activate(autoExpand);
15034 }else if(autoExpand){
15040 tryActivate : function(start, step){
15041 var items = this.items;
15042 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
15043 var item = items.get(i);
15044 if(!item.disabled && item.canActivate){
15045 this.setActiveItem(item, false);
15053 onMouseOver : function(e){
15055 if(t = this.findTargetItem(e)){
15056 if(t.canActivate && !t.disabled){
15057 this.setActiveItem(t, true);
15060 this.fireEvent("mouseover", this, e, t);
15064 onMouseOut : function(e){
15066 if(t = this.findTargetItem(e)){
15067 if(t == this.activeItem && t.shouldDeactivate(e)){
15068 this.activeItem.deactivate();
15069 delete this.activeItem;
15072 this.fireEvent("mouseout", this, e, t);
15076 * Read-only. Returns true if the menu is currently displayed, else false.
15079 isVisible : function(){
15080 return this.el && !this.hidden;
15084 * Displays this menu relative to another element
15085 * @param {String/HTMLElement/Roo.Element} element The element to align to
15086 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
15087 * the element (defaults to this.defaultAlign)
15088 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
15090 show : function(el, pos, parentMenu){
15091 this.parentMenu = parentMenu;
15095 this.fireEvent("beforeshow", this);
15096 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
15100 * Displays this menu at a specific xy position
15101 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
15102 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
15104 showAt : function(xy, parentMenu, /* private: */_e){
15105 this.parentMenu = parentMenu;
15110 this.fireEvent("beforeshow", this);
15111 xy = this.el.adjustForConstraints(xy);
15115 this.hidden = false;
15117 this.fireEvent("show", this);
15120 focus : function(){
15122 this.doFocus.defer(50, this);
15126 doFocus : function(){
15128 this.focusEl.focus();
15133 * Hides this menu and optionally all parent menus
15134 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
15136 hide : function(deep){
15137 if(this.el && this.isVisible()){
15138 this.fireEvent("beforehide", this);
15139 if(this.activeItem){
15140 this.activeItem.deactivate();
15141 this.activeItem = null;
15144 this.hidden = true;
15145 this.fireEvent("hide", this);
15147 if(deep === true && this.parentMenu){
15148 this.parentMenu.hide(true);
15153 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
15154 * Any of the following are valid:
15156 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
15157 * <li>An HTMLElement object which will be converted to a menu item</li>
15158 * <li>A menu item config object that will be created as a new menu item</li>
15159 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
15160 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
15165 var menu = new Roo.menu.Menu();
15167 // Create a menu item to add by reference
15168 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
15170 // Add a bunch of items at once using different methods.
15171 // Only the last item added will be returned.
15172 var item = menu.add(
15173 menuItem, // add existing item by ref
15174 'Dynamic Item', // new TextItem
15175 '-', // new separator
15176 { text: 'Config Item' } // new item by config
15179 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
15180 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
15183 var a = arguments, l = a.length, item;
15184 for(var i = 0; i < l; i++){
15186 if ((typeof(el) == "object") && el.xtype && el.xns) {
15187 el = Roo.factory(el, Roo.menu);
15190 if(el.render){ // some kind of Item
15191 item = this.addItem(el);
15192 }else if(typeof el == "string"){ // string
15193 if(el == "separator" || el == "-"){
15194 item = this.addSeparator();
15196 item = this.addText(el);
15198 }else if(el.tagName || el.el){ // element
15199 item = this.addElement(el);
15200 }else if(typeof el == "object"){ // must be menu item config?
15201 item = this.addMenuItem(el);
15208 * Returns this menu's underlying {@link Roo.Element} object
15209 * @return {Roo.Element} The element
15211 getEl : function(){
15219 * Adds a separator bar to the menu
15220 * @return {Roo.menu.Item} The menu item that was added
15222 addSeparator : function(){
15223 return this.addItem(new Roo.menu.Separator());
15227 * Adds an {@link Roo.Element} object to the menu
15228 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
15229 * @return {Roo.menu.Item} The menu item that was added
15231 addElement : function(el){
15232 return this.addItem(new Roo.menu.BaseItem(el));
15236 * Adds an existing object based on {@link Roo.menu.Item} to the menu
15237 * @param {Roo.menu.Item} item The menu item to add
15238 * @return {Roo.menu.Item} The menu item that was added
15240 addItem : function(item){
15241 this.items.add(item);
15243 var li = document.createElement("li");
15244 li.className = "x-menu-list-item";
15245 this.ul.dom.appendChild(li);
15246 item.render(li, this);
15247 this.delayAutoWidth();
15253 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
15254 * @param {Object} config A MenuItem config object
15255 * @return {Roo.menu.Item} The menu item that was added
15257 addMenuItem : function(config){
15258 if(!(config instanceof Roo.menu.Item)){
15259 if(typeof config.checked == "boolean"){ // must be check menu item config?
15260 config = new Roo.menu.CheckItem(config);
15262 config = new Roo.menu.Item(config);
15265 return this.addItem(config);
15269 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
15270 * @param {String} text The text to display in the menu item
15271 * @return {Roo.menu.Item} The menu item that was added
15273 addText : function(text){
15274 return this.addItem(new Roo.menu.TextItem({ text : text }));
15278 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
15279 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
15280 * @param {Roo.menu.Item} item The menu item to add
15281 * @return {Roo.menu.Item} The menu item that was added
15283 insert : function(index, item){
15284 this.items.insert(index, item);
15286 var li = document.createElement("li");
15287 li.className = "x-menu-list-item";
15288 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
15289 item.render(li, this);
15290 this.delayAutoWidth();
15296 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
15297 * @param {Roo.menu.Item} item The menu item to remove
15299 remove : function(item){
15300 this.items.removeKey(item.id);
15305 * Removes and destroys all items in the menu
15307 removeAll : function(){
15309 while(f = this.items.first()){
15315 // MenuNav is a private utility class used internally by the Menu
15316 Roo.menu.MenuNav = function(menu){
15317 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
15318 this.scope = this.menu = menu;
15321 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
15322 doRelay : function(e, h){
15323 var k = e.getKey();
15324 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
15325 this.menu.tryActivate(0, 1);
15328 return h.call(this.scope || this, e, this.menu);
15331 up : function(e, m){
15332 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
15333 m.tryActivate(m.items.length-1, -1);
15337 down : function(e, m){
15338 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
15339 m.tryActivate(0, 1);
15343 right : function(e, m){
15345 m.activeItem.expandMenu(true);
15349 left : function(e, m){
15351 if(m.parentMenu && m.parentMenu.activeItem){
15352 m.parentMenu.activeItem.activate();
15356 enter : function(e, m){
15358 e.stopPropagation();
15359 m.activeItem.onClick(e);
15360 m.fireEvent("click", this, m.activeItem);
15366 * Ext JS Library 1.1.1
15367 * Copyright(c) 2006-2007, Ext JS, LLC.
15369 * Originally Released Under LGPL - original licence link has changed is not relivant.
15372 * <script type="text/javascript">
15376 * @class Roo.menu.MenuMgr
15377 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
15380 Roo.menu.MenuMgr = function(){
15381 var menus, active, groups = {}, attached = false, lastShow = new Date();
15383 // private - called when first menu is created
15386 active = new Roo.util.MixedCollection();
15387 Roo.get(document).addKeyListener(27, function(){
15388 if(active.length > 0){
15395 function hideAll(){
15396 if(active && active.length > 0){
15397 var c = active.clone();
15398 c.each(function(m){
15405 function onHide(m){
15407 if(active.length < 1){
15408 Roo.get(document).un("mousedown", onMouseDown);
15414 function onShow(m){
15415 var last = active.last();
15416 lastShow = new Date();
15419 Roo.get(document).on("mousedown", onMouseDown);
15423 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
15424 m.parentMenu.activeChild = m;
15425 }else if(last && last.isVisible()){
15426 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
15431 function onBeforeHide(m){
15433 m.activeChild.hide();
15435 if(m.autoHideTimer){
15436 clearTimeout(m.autoHideTimer);
15437 delete m.autoHideTimer;
15442 function onBeforeShow(m){
15443 var pm = m.parentMenu;
15444 if(!pm && !m.allowOtherMenus){
15446 }else if(pm && pm.activeChild && active != m){
15447 pm.activeChild.hide();
15452 function onMouseDown(e){
15453 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
15459 function onBeforeCheck(mi, state){
15461 var g = groups[mi.group];
15462 for(var i = 0, l = g.length; i < l; i++){
15464 g[i].setChecked(false);
15473 * Hides all menus that are currently visible
15475 hideAll : function(){
15480 register : function(menu){
15484 menus[menu.id] = menu;
15485 menu.on("beforehide", onBeforeHide);
15486 menu.on("hide", onHide);
15487 menu.on("beforeshow", onBeforeShow);
15488 menu.on("show", onShow);
15489 var g = menu.group;
15490 if(g && menu.events["checkchange"]){
15494 groups[g].push(menu);
15495 menu.on("checkchange", onCheck);
15500 * Returns a {@link Roo.menu.Menu} object
15501 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
15502 * be used to generate and return a new Menu instance.
15504 get : function(menu){
15505 if(typeof menu == "string"){ // menu id
15506 return menus[menu];
15507 }else if(menu.events){ // menu instance
15509 }else if(typeof menu.length == 'number'){ // array of menu items?
15510 return new Roo.menu.Menu({items:menu});
15511 }else{ // otherwise, must be a config
15512 return new Roo.menu.Menu(menu);
15517 unregister : function(menu){
15518 delete menus[menu.id];
15519 menu.un("beforehide", onBeforeHide);
15520 menu.un("hide", onHide);
15521 menu.un("beforeshow", onBeforeShow);
15522 menu.un("show", onShow);
15523 var g = menu.group;
15524 if(g && menu.events["checkchange"]){
15525 groups[g].remove(menu);
15526 menu.un("checkchange", onCheck);
15531 registerCheckable : function(menuItem){
15532 var g = menuItem.group;
15537 groups[g].push(menuItem);
15538 menuItem.on("beforecheckchange", onBeforeCheck);
15543 unregisterCheckable : function(menuItem){
15544 var g = menuItem.group;
15546 groups[g].remove(menuItem);
15547 menuItem.un("beforecheckchange", onBeforeCheck);
15553 * Ext JS Library 1.1.1
15554 * Copyright(c) 2006-2007, Ext JS, LLC.
15556 * Originally Released Under LGPL - original licence link has changed is not relivant.
15559 * <script type="text/javascript">
15564 * @class Roo.menu.BaseItem
15565 * @extends Roo.Component
15566 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
15567 * management and base configuration options shared by all menu components.
15569 * Creates a new BaseItem
15570 * @param {Object} config Configuration options
15572 Roo.menu.BaseItem = function(config){
15573 Roo.menu.BaseItem.superclass.constructor.call(this, config);
15578 * Fires when this item is clicked
15579 * @param {Roo.menu.BaseItem} this
15580 * @param {Roo.EventObject} e
15585 * Fires when this item is activated
15586 * @param {Roo.menu.BaseItem} this
15590 * @event deactivate
15591 * Fires when this item is deactivated
15592 * @param {Roo.menu.BaseItem} this
15598 this.on("click", this.handler, this.scope, true);
15602 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
15604 * @cfg {Function} handler
15605 * A function that will handle the click event of this menu item (defaults to undefined)
15608 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
15610 canActivate : false,
15613 * @cfg {Boolean} hidden True to prevent creation of this menu item (defaults to false)
15618 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
15620 activeClass : "x-menu-item-active",
15622 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
15624 hideOnClick : true,
15626 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
15631 ctype: "Roo.menu.BaseItem",
15634 actionMode : "container",
15637 render : function(container, parentMenu){
15638 this.parentMenu = parentMenu;
15639 Roo.menu.BaseItem.superclass.render.call(this, container);
15640 this.container.menuItemId = this.id;
15644 onRender : function(container, position){
15645 this.el = Roo.get(this.el);
15646 container.dom.appendChild(this.el.dom);
15650 onClick : function(e){
15651 if(!this.disabled && this.fireEvent("click", this, e) !== false
15652 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
15653 this.handleClick(e);
15660 activate : function(){
15664 var li = this.container;
15665 li.addClass(this.activeClass);
15666 this.region = li.getRegion().adjust(2, 2, -2, -2);
15667 this.fireEvent("activate", this);
15672 deactivate : function(){
15673 this.container.removeClass(this.activeClass);
15674 this.fireEvent("deactivate", this);
15678 shouldDeactivate : function(e){
15679 return !this.region || !this.region.contains(e.getPoint());
15683 handleClick : function(e){
15684 if(this.hideOnClick){
15685 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
15690 expandMenu : function(autoActivate){
15695 hideMenu : function(){
15700 * Ext JS Library 1.1.1
15701 * Copyright(c) 2006-2007, Ext JS, LLC.
15703 * Originally Released Under LGPL - original licence link has changed is not relivant.
15706 * <script type="text/javascript">
15710 * @class Roo.menu.Adapter
15711 * @extends Roo.menu.BaseItem
15712 * 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.
15713 * It provides basic rendering, activation management and enable/disable logic required to work in menus.
15715 * Creates a new Adapter
15716 * @param {Object} config Configuration options
15718 Roo.menu.Adapter = function(component, config){
15719 Roo.menu.Adapter.superclass.constructor.call(this, config);
15720 this.component = component;
15722 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
15724 canActivate : true,
15727 onRender : function(container, position){
15728 this.component.render(container);
15729 this.el = this.component.getEl();
15733 activate : function(){
15737 this.component.focus();
15738 this.fireEvent("activate", this);
15743 deactivate : function(){
15744 this.fireEvent("deactivate", this);
15748 disable : function(){
15749 this.component.disable();
15750 Roo.menu.Adapter.superclass.disable.call(this);
15754 enable : function(){
15755 this.component.enable();
15756 Roo.menu.Adapter.superclass.enable.call(this);
15760 * Ext JS Library 1.1.1
15761 * Copyright(c) 2006-2007, Ext JS, LLC.
15763 * Originally Released Under LGPL - original licence link has changed is not relivant.
15766 * <script type="text/javascript">
15770 * @class Roo.menu.TextItem
15771 * @extends Roo.menu.BaseItem
15772 * Adds a static text string to a menu, usually used as either a heading or group separator.
15773 * Note: old style constructor with text is still supported.
15776 * Creates a new TextItem
15777 * @param {Object} cfg Configuration
15779 Roo.menu.TextItem = function(cfg){
15780 if (typeof(cfg) == 'string') {
15783 Roo.apply(this,cfg);
15786 Roo.menu.TextItem.superclass.constructor.call(this);
15789 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
15791 * @cfg {Boolean} text Text to show on item.
15796 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
15798 hideOnClick : false,
15800 * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
15802 itemCls : "x-menu-text",
15805 onRender : function(){
15806 var s = document.createElement("span");
15807 s.className = this.itemCls;
15808 s.innerHTML = this.text;
15810 Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
15814 * Ext JS Library 1.1.1
15815 * Copyright(c) 2006-2007, Ext JS, LLC.
15817 * Originally Released Under LGPL - original licence link has changed is not relivant.
15820 * <script type="text/javascript">
15824 * @class Roo.menu.Separator
15825 * @extends Roo.menu.BaseItem
15826 * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
15827 * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
15829 * @param {Object} config Configuration options
15831 Roo.menu.Separator = function(config){
15832 Roo.menu.Separator.superclass.constructor.call(this, config);
15835 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
15837 * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
15839 itemCls : "x-menu-sep",
15841 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
15843 hideOnClick : false,
15846 onRender : function(li){
15847 var s = document.createElement("span");
15848 s.className = this.itemCls;
15849 s.innerHTML = " ";
15851 li.addClass("x-menu-sep-li");
15852 Roo.menu.Separator.superclass.onRender.apply(this, arguments);
15856 * Ext JS Library 1.1.1
15857 * Copyright(c) 2006-2007, Ext JS, LLC.
15859 * Originally Released Under LGPL - original licence link has changed is not relivant.
15862 * <script type="text/javascript">
15865 * @class Roo.menu.Item
15866 * @extends Roo.menu.BaseItem
15867 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
15868 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
15869 * activation and click handling.
15871 * Creates a new Item
15872 * @param {Object} config Configuration options
15874 Roo.menu.Item = function(config){
15875 Roo.menu.Item.superclass.constructor.call(this, config);
15877 this.menu = Roo.menu.MenuMgr.get(this.menu);
15880 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
15883 * @cfg {String} text
15884 * The text to show on the menu item.
15888 * @cfg {String} HTML to render in menu
15889 * The text to show on the menu item (HTML version).
15893 * @cfg {String} icon
15894 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
15898 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
15900 itemCls : "x-menu-item",
15902 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
15904 canActivate : true,
15906 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
15909 // doc'd in BaseItem
15913 ctype: "Roo.menu.Item",
15916 onRender : function(container, position){
15917 var el = document.createElement("a");
15918 el.hideFocus = true;
15919 el.unselectable = "on";
15920 el.href = this.href || "#";
15921 if(this.hrefTarget){
15922 el.target = this.hrefTarget;
15924 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
15926 var html = this.html.length ? this.html : String.format('{0}',this.text);
15928 el.innerHTML = String.format(
15929 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
15930 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
15932 Roo.menu.Item.superclass.onRender.call(this, container, position);
15936 * Sets the text to display in this menu item
15937 * @param {String} text The text to display
15938 * @param {Boolean} isHTML true to indicate text is pure html.
15940 setText : function(text, isHTML){
15948 var html = this.html.length ? this.html : String.format('{0}',this.text);
15950 this.el.update(String.format(
15951 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
15952 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
15953 this.parentMenu.autoWidth();
15958 handleClick : function(e){
15959 if(!this.href){ // if no link defined, stop the event automatically
15962 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
15966 activate : function(autoExpand){
15967 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
15977 shouldDeactivate : function(e){
15978 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
15979 if(this.menu && this.menu.isVisible()){
15980 return !this.menu.getEl().getRegion().contains(e.getPoint());
15988 deactivate : function(){
15989 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
15994 expandMenu : function(autoActivate){
15995 if(!this.disabled && this.menu){
15996 clearTimeout(this.hideTimer);
15997 delete this.hideTimer;
15998 if(!this.menu.isVisible() && !this.showTimer){
15999 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
16000 }else if (this.menu.isVisible() && autoActivate){
16001 this.menu.tryActivate(0, 1);
16007 deferExpand : function(autoActivate){
16008 delete this.showTimer;
16009 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
16011 this.menu.tryActivate(0, 1);
16016 hideMenu : function(){
16017 clearTimeout(this.showTimer);
16018 delete this.showTimer;
16019 if(!this.hideTimer && this.menu && this.menu.isVisible()){
16020 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
16025 deferHide : function(){
16026 delete this.hideTimer;
16031 * Ext JS Library 1.1.1
16032 * Copyright(c) 2006-2007, Ext JS, LLC.
16034 * Originally Released Under LGPL - original licence link has changed is not relivant.
16037 * <script type="text/javascript">
16041 * @class Roo.menu.CheckItem
16042 * @extends Roo.menu.Item
16043 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
16045 * Creates a new CheckItem
16046 * @param {Object} config Configuration options
16048 Roo.menu.CheckItem = function(config){
16049 Roo.menu.CheckItem.superclass.constructor.call(this, config);
16052 * @event beforecheckchange
16053 * Fires before the checked value is set, providing an opportunity to cancel if needed
16054 * @param {Roo.menu.CheckItem} this
16055 * @param {Boolean} checked The new checked value that will be set
16057 "beforecheckchange" : true,
16059 * @event checkchange
16060 * Fires after the checked value has been set
16061 * @param {Roo.menu.CheckItem} this
16062 * @param {Boolean} checked The checked value that was set
16064 "checkchange" : true
16066 if(this.checkHandler){
16067 this.on('checkchange', this.checkHandler, this.scope);
16070 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
16072 * @cfg {String} group
16073 * All check items with the same group name will automatically be grouped into a single-select
16074 * radio button group (defaults to '')
16077 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
16079 itemCls : "x-menu-item x-menu-check-item",
16081 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
16083 groupClass : "x-menu-group-item",
16086 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
16087 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
16088 * initialized with checked = true will be rendered as checked.
16093 ctype: "Roo.menu.CheckItem",
16096 onRender : function(c){
16097 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
16099 this.el.addClass(this.groupClass);
16101 Roo.menu.MenuMgr.registerCheckable(this);
16103 this.checked = false;
16104 this.setChecked(true, true);
16109 destroy : function(){
16111 Roo.menu.MenuMgr.unregisterCheckable(this);
16113 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
16117 * Set the checked state of this item
16118 * @param {Boolean} checked The new checked value
16119 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
16121 setChecked : function(state, suppressEvent){
16122 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
16123 if(this.container){
16124 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
16126 this.checked = state;
16127 if(suppressEvent !== true){
16128 this.fireEvent("checkchange", this, state);
16134 handleClick : function(e){
16135 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
16136 this.setChecked(!this.checked);
16138 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
16142 * Ext JS Library 1.1.1
16143 * Copyright(c) 2006-2007, Ext JS, LLC.
16145 * Originally Released Under LGPL - original licence link has changed is not relivant.
16148 * <script type="text/javascript">
16152 * @class Roo.menu.DateItem
16153 * @extends Roo.menu.Adapter
16154 * A menu item that wraps the {@link Roo.DatPicker} component.
16156 * Creates a new DateItem
16157 * @param {Object} config Configuration options
16159 Roo.menu.DateItem = function(config){
16160 Roo.menu.DateItem.superclass.constructor.call(this, new Roo.DatePicker(config), config);
16161 /** The Roo.DatePicker object @type Roo.DatePicker */
16162 this.picker = this.component;
16163 this.addEvents({select: true});
16165 this.picker.on("render", function(picker){
16166 picker.getEl().swallowEvent("click");
16167 picker.container.addClass("x-menu-date-item");
16170 this.picker.on("select", this.onSelect, this);
16173 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
16175 onSelect : function(picker, date){
16176 this.fireEvent("select", this, date, picker);
16177 Roo.menu.DateItem.superclass.handleClick.call(this);
16181 * Ext JS Library 1.1.1
16182 * Copyright(c) 2006-2007, Ext JS, LLC.
16184 * Originally Released Under LGPL - original licence link has changed is not relivant.
16187 * <script type="text/javascript">
16191 * @class Roo.menu.ColorItem
16192 * @extends Roo.menu.Adapter
16193 * A menu item that wraps the {@link Roo.ColorPalette} component.
16195 * Creates a new ColorItem
16196 * @param {Object} config Configuration options
16198 Roo.menu.ColorItem = function(config){
16199 Roo.menu.ColorItem.superclass.constructor.call(this, new Roo.ColorPalette(config), config);
16200 /** The Roo.ColorPalette object @type Roo.ColorPalette */
16201 this.palette = this.component;
16202 this.relayEvents(this.palette, ["select"]);
16203 if(this.selectHandler){
16204 this.on('select', this.selectHandler, this.scope);
16207 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);/*
16209 * Ext JS Library 1.1.1
16210 * Copyright(c) 2006-2007, Ext JS, LLC.
16212 * Originally Released Under LGPL - original licence link has changed is not relivant.
16215 * <script type="text/javascript">
16220 * @class Roo.menu.DateMenu
16221 * @extends Roo.menu.Menu
16222 * A menu containing a {@link Roo.menu.DateItem} component (which provides a date picker).
16224 * Creates a new DateMenu
16225 * @param {Object} config Configuration options
16227 Roo.menu.DateMenu = function(config){
16228 Roo.menu.DateMenu.superclass.constructor.call(this, config);
16230 var di = new Roo.menu.DateItem(config);
16233 * The {@link Roo.DatePicker} instance for this DateMenu
16236 this.picker = di.picker;
16239 * @param {DatePicker} picker
16240 * @param {Date} date
16242 this.relayEvents(di, ["select"]);
16243 this.on('beforeshow', function(){
16245 this.picker.hideMonthPicker(false);
16249 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
16253 * Ext JS Library 1.1.1
16254 * Copyright(c) 2006-2007, Ext JS, LLC.
16256 * Originally Released Under LGPL - original licence link has changed is not relivant.
16259 * <script type="text/javascript">
16264 * @class Roo.menu.ColorMenu
16265 * @extends Roo.menu.Menu
16266 * A menu containing a {@link Roo.menu.ColorItem} component (which provides a basic color picker).
16268 * Creates a new ColorMenu
16269 * @param {Object} config Configuration options
16271 Roo.menu.ColorMenu = function(config){
16272 Roo.menu.ColorMenu.superclass.constructor.call(this, config);
16274 var ci = new Roo.menu.ColorItem(config);
16277 * The {@link Roo.ColorPalette} instance for this ColorMenu
16278 * @type ColorPalette
16280 this.palette = ci.palette;
16283 * @param {ColorPalette} palette
16284 * @param {String} color
16286 this.relayEvents(ci, ["select"]);
16288 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);/*
16290 * Ext JS Library 1.1.1
16291 * Copyright(c) 2006-2007, Ext JS, LLC.
16293 * Originally Released Under LGPL - original licence link has changed is not relivant.
16296 * <script type="text/javascript">
16300 * @class Roo.form.TextItem
16301 * @extends Roo.BoxComponent
16302 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
16304 * Creates a new TextItem
16305 * @param {Object} config Configuration options
16307 Roo.form.TextItem = function(config){
16308 Roo.form.TextItem.superclass.constructor.call(this, config);
16311 Roo.extend(Roo.form.TextItem, Roo.BoxComponent, {
16314 * @cfg {String} tag the tag for this item (default div)
16318 * @cfg {String} html the content for this item
16322 getAutoCreate : function()
16335 onRender : function(ct, position)
16337 Roo.form.TextItem.superclass.onRender.call(this, ct, position);
16340 var cfg = this.getAutoCreate();
16342 cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
16344 if (!cfg.name.length) {
16347 this.el = ct.createChild(cfg, position);
16353 * Ext JS Library 1.1.1
16354 * Copyright(c) 2006-2007, Ext JS, LLC.
16356 * Originally Released Under LGPL - original licence link has changed is not relivant.
16359 * <script type="text/javascript">
16363 * @class Roo.form.Field
16364 * @extends Roo.BoxComponent
16365 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
16367 * Creates a new Field
16368 * @param {Object} config Configuration options
16370 Roo.form.Field = function(config){
16371 Roo.form.Field.superclass.constructor.call(this, config);
16374 Roo.extend(Roo.form.Field, Roo.BoxComponent, {
16376 * @cfg {String} fieldLabel Label to use when rendering a form.
16379 * @cfg {String} qtip Mouse over tip
16383 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
16385 invalidClass : "x-form-invalid",
16387 * @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")
16389 invalidText : "The value in this field is invalid",
16391 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
16393 focusClass : "x-form-focus",
16395 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
16396 automatic validation (defaults to "keyup").
16398 validationEvent : "keyup",
16400 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
16402 validateOnBlur : true,
16404 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
16406 validationDelay : 250,
16408 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
16409 * {tag: "input", type: "text", size: "20", autocomplete: "off"})
16411 defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "new-password"},
16413 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field")
16415 fieldClass : "x-form-field",
16417 * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'):
16420 ----------- ----------------------------------------------------------------------
16421 qtip Display a quick tip when the user hovers over the field
16422 title Display a default browser title attribute popup
16423 under Add a block div beneath the field containing the error text
16424 side Add an error icon to the right of the field with a popup on hover
16425 [element id] Add the error text directly to the innerHTML of the specified element
16428 msgTarget : 'qtip',
16430 * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal').
16435 * @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.
16440 * @cfg {Boolean} disabled True to disable the field (defaults to false).
16445 * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password (defaults to "text").
16447 inputType : undefined,
16450 * @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).
16452 tabIndex : undefined,
16455 isFormField : true,
16460 * @property {Roo.Element} fieldEl
16461 * Element Containing the rendered Field (with label etc.)
16464 * @cfg {Mixed} value A value to initialize this field with.
16469 * @cfg {String} name The field's HTML name attribute.
16472 * @cfg {String} cls A CSS class to apply to the field's underlying element.
16475 loadedValue : false,
16479 initComponent : function(){
16480 Roo.form.Field.superclass.initComponent.call(this);
16484 * Fires when this field receives input focus.
16485 * @param {Roo.form.Field} this
16490 * Fires when this field loses input focus.
16491 * @param {Roo.form.Field} this
16495 * @event specialkey
16496 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
16497 * {@link Roo.EventObject#getKey} to determine which key was pressed.
16498 * @param {Roo.form.Field} this
16499 * @param {Roo.EventObject} e The event object
16504 * Fires just before the field blurs if the field value has changed.
16505 * @param {Roo.form.Field} this
16506 * @param {Mixed} newValue The new value
16507 * @param {Mixed} oldValue The original value
16512 * Fires after the field has been marked as invalid.
16513 * @param {Roo.form.Field} this
16514 * @param {String} msg The validation message
16519 * Fires after the field has been validated with no errors.
16520 * @param {Roo.form.Field} this
16525 * Fires after the key up
16526 * @param {Roo.form.Field} this
16527 * @param {Roo.EventObject} e The event Object
16534 * Returns the name attribute of the field if available
16535 * @return {String} name The field name
16537 getName: function(){
16538 return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
16542 onRender : function(ct, position){
16543 Roo.form.Field.superclass.onRender.call(this, ct, position);
16545 var cfg = this.getAutoCreate();
16547 cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
16549 if (!cfg.name.length) {
16552 if(this.inputType){
16553 cfg.type = this.inputType;
16555 this.el = ct.createChild(cfg, position);
16557 var type = this.el.dom.type;
16559 if(type == 'password'){
16562 this.el.addClass('x-form-'+type);
16565 this.el.dom.readOnly = true;
16567 if(this.tabIndex !== undefined){
16568 this.el.dom.setAttribute('tabIndex', this.tabIndex);
16571 this.el.addClass([this.fieldClass, this.cls]);
16576 * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b>
16577 * @param {String/HTMLElement/Element} el The id of the node, a DOM node or an existing Element
16578 * @return {Roo.form.Field} this
16580 applyTo : function(target){
16581 this.allowDomMove = false;
16582 this.el = Roo.get(target);
16583 this.render(this.el.dom.parentNode);
16588 initValue : function(){
16589 if(this.value !== undefined){
16590 this.setValue(this.value);
16591 }else if(this.el.dom.value.length > 0){
16592 this.setValue(this.el.dom.value);
16597 * Returns true if this field has been changed since it was originally loaded and is not disabled.
16598 * DEPRICATED - it never worked well - use hasChanged/resetHasChanged.
16600 isDirty : function() {
16601 if(this.disabled) {
16604 return String(this.getValue()) !== String(this.originalValue);
16608 * stores the current value in loadedValue
16610 resetHasChanged : function()
16612 this.loadedValue = String(this.getValue());
16615 * checks the current value against the 'loaded' value.
16616 * Note - will return false if 'resetHasChanged' has not been called first.
16618 hasChanged : function()
16620 if(this.disabled || this.readOnly) {
16623 return this.loadedValue !== false && String(this.getValue()) !== this.loadedValue;
16629 afterRender : function(){
16630 Roo.form.Field.superclass.afterRender.call(this);
16635 fireKey : function(e){
16636 //Roo.log('field ' + e.getKey());
16637 if(e.isNavKeyPress()){
16638 this.fireEvent("specialkey", this, e);
16643 * Resets the current field value to the originally loaded value and clears any validation messages
16645 reset : function(){
16646 this.setValue(this.resetValue);
16647 this.originalValue = this.getValue();
16648 this.clearInvalid();
16652 initEvents : function(){
16653 // safari killled keypress - so keydown is now used..
16654 this.el.on("keydown" , this.fireKey, this);
16655 this.el.on("focus", this.onFocus, this);
16656 this.el.on("blur", this.onBlur, this);
16657 this.el.relayEvent('keyup', this);
16659 // reference to original value for reset
16660 this.originalValue = this.getValue();
16661 this.resetValue = this.getValue();
16665 onFocus : function(){
16666 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
16667 this.el.addClass(this.focusClass);
16669 if(!this.hasFocus){
16670 this.hasFocus = true;
16671 this.startValue = this.getValue();
16672 this.fireEvent("focus", this);
16676 beforeBlur : Roo.emptyFn,
16679 onBlur : function(){
16681 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
16682 this.el.removeClass(this.focusClass);
16684 this.hasFocus = false;
16685 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
16688 var v = this.getValue();
16689 if(String(v) !== String(this.startValue)){
16690 this.fireEvent('change', this, v, this.startValue);
16692 this.fireEvent("blur", this);
16696 * Returns whether or not the field value is currently valid
16697 * @param {Boolean} preventMark True to disable marking the field invalid
16698 * @return {Boolean} True if the value is valid, else false
16700 isValid : function(preventMark){
16704 var restore = this.preventMark;
16705 this.preventMark = preventMark === true;
16706 var v = this.validateValue(this.processValue(this.getRawValue()));
16707 this.preventMark = restore;
16712 * Validates the field value
16713 * @return {Boolean} True if the value is valid, else false
16715 validate : function(){
16716 if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
16717 this.clearInvalid();
16723 processValue : function(value){
16728 // Subclasses should provide the validation implementation by overriding this
16729 validateValue : function(value){
16734 * Mark this field as invalid
16735 * @param {String} msg The validation message
16737 markInvalid : function(msg){
16738 if(!this.rendered || this.preventMark){ // not rendered
16742 var obj = (typeof(this.combo) != 'undefined') ? this.combo : this; // fix the combox array!!
16744 obj.el.addClass(this.invalidClass);
16745 msg = msg || this.invalidText;
16746 switch(this.msgTarget){
16748 obj.el.dom.qtip = msg;
16749 obj.el.dom.qclass = 'x-form-invalid-tip';
16750 if(Roo.QuickTips){ // fix for floating editors interacting with DND
16751 Roo.QuickTips.enable();
16755 this.el.dom.title = msg;
16759 var elp = this.el.findParent('.x-form-element', 5, true);
16760 this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
16761 this.errorEl.setWidth(elp.getWidth(true)-20);
16763 this.errorEl.update(msg);
16764 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
16767 if(!this.errorIcon){
16768 var elp = this.el.findParent('.x-form-element', 5, true);
16769 this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
16771 this.alignErrorIcon();
16772 this.errorIcon.dom.qtip = msg;
16773 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
16774 this.errorIcon.show();
16775 this.on('resize', this.alignErrorIcon, this);
16778 var t = Roo.getDom(this.msgTarget);
16780 t.style.display = this.msgDisplay;
16783 this.fireEvent('invalid', this, msg);
16787 alignErrorIcon : function(){
16788 this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
16792 * Clear any invalid styles/messages for this field
16794 clearInvalid : function(){
16795 if(!this.rendered || this.preventMark){ // not rendered
16798 var obj = (typeof(this.combo) != 'undefined') ? this.combo : this; // fix the combox array!!
16800 obj.el.removeClass(this.invalidClass);
16801 switch(this.msgTarget){
16803 obj.el.dom.qtip = '';
16806 this.el.dom.title = '';
16810 Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
16814 if(this.errorIcon){
16815 this.errorIcon.dom.qtip = '';
16816 this.errorIcon.hide();
16817 this.un('resize', this.alignErrorIcon, this);
16821 var t = Roo.getDom(this.msgTarget);
16823 t.style.display = 'none';
16826 this.fireEvent('valid', this);
16830 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
16831 * @return {Mixed} value The field value
16833 getRawValue : function(){
16834 var v = this.el.getValue();
16840 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
16841 * @return {Mixed} value The field value
16843 getValue : function(){
16844 var v = this.el.getValue();
16850 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
16851 * @param {Mixed} value The value to set
16853 setRawValue : function(v){
16854 return this.el.dom.value = (v === null || v === undefined ? '' : v);
16858 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
16859 * @param {Mixed} value The value to set
16861 setValue : function(v){
16864 this.el.dom.value = (v === null || v === undefined ? '' : v);
16869 adjustSize : function(w, h){
16870 var s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
16871 s.width = this.adjustWidth(this.el.dom.tagName, s.width);
16875 adjustWidth : function(tag, w){
16876 tag = tag.toLowerCase();
16877 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
16878 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
16879 if(tag == 'input'){
16882 if(tag == 'textarea'){
16885 }else if(Roo.isOpera){
16886 if(tag == 'input'){
16889 if(tag == 'textarea'){
16899 // anything other than normal should be considered experimental
16900 Roo.form.Field.msgFx = {
16902 show: function(msgEl, f){
16903 msgEl.setDisplayed('block');
16906 hide : function(msgEl, f){
16907 msgEl.setDisplayed(false).update('');
16912 show: function(msgEl, f){
16913 msgEl.slideIn('t', {stopFx:true});
16916 hide : function(msgEl, f){
16917 msgEl.slideOut('t', {stopFx:true,useDisplay:true});
16922 show: function(msgEl, f){
16923 msgEl.fixDisplay();
16924 msgEl.alignTo(f.el, 'tl-tr');
16925 msgEl.slideIn('l', {stopFx:true});
16928 hide : function(msgEl, f){
16929 msgEl.slideOut('l', {stopFx:true,useDisplay:true});
16934 * Ext JS Library 1.1.1
16935 * Copyright(c) 2006-2007, Ext JS, LLC.
16937 * Originally Released Under LGPL - original licence link has changed is not relivant.
16940 * <script type="text/javascript">
16945 * @class Roo.form.TextField
16946 * @extends Roo.form.Field
16947 * Basic text field. Can be used as a direct replacement for traditional text inputs, or as the base
16948 * class for more sophisticated input controls (like {@link Roo.form.TextArea} and {@link Roo.form.ComboBox}).
16950 * Creates a new TextField
16951 * @param {Object} config Configuration options
16953 Roo.form.TextField = function(config){
16954 Roo.form.TextField.superclass.constructor.call(this, config);
16958 * Fires when the autosize function is triggered. The field may or may not have actually changed size
16959 * according to the default logic, but this event provides a hook for the developer to apply additional
16960 * logic at runtime to resize the field if needed.
16961 * @param {Roo.form.Field} this This text field
16962 * @param {Number} width The new field width
16968 Roo.extend(Roo.form.TextField, Roo.form.Field, {
16970 * @cfg {Boolean} grow True if this field should automatically grow and shrink to its content
16974 * @cfg {Number} growMin The minimum width to allow when grow = true (defaults to 30)
16978 * @cfg {Number} growMax The maximum width to allow when grow = true (defaults to 800)
16982 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
16986 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
16990 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
16992 disableKeyFilter : false,
16994 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
16998 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
17002 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
17004 maxLength : Number.MAX_VALUE,
17006 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
17008 minLengthText : "The minimum length for this field is {0}",
17010 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
17012 maxLengthText : "The maximum length for this field is {0}",
17014 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
17016 selectOnFocus : false,
17018 * @cfg {Boolean} allowLeadingSpace True to prevent the stripping of leading white space
17020 allowLeadingSpace : false,
17022 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
17024 blankText : "This field is required",
17026 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
17027 * If available, this function will be called only after the basic validators all return true, and will be passed the
17028 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
17032 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
17033 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
17034 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
17038 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
17042 * @cfg {String} emptyText The default text to display in an empty field - placeholder... (defaults to null).
17048 initEvents : function()
17050 if (this.emptyText) {
17051 this.el.attr('placeholder', this.emptyText);
17054 Roo.form.TextField.superclass.initEvents.call(this);
17055 if(this.validationEvent == 'keyup'){
17056 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
17057 this.el.on('keyup', this.filterValidation, this);
17059 else if(this.validationEvent !== false){
17060 this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
17063 if(this.selectOnFocus){
17064 this.on("focus", this.preFocus, this);
17066 if (!this.allowLeadingSpace) {
17067 this.on('blur', this.cleanLeadingSpace, this);
17070 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
17071 this.el.on("keypress", this.filterKeys, this);
17074 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
17075 this.el.on("click", this.autoSize, this);
17077 if(this.el.is('input[type=password]') && Roo.isSafari){
17078 this.el.on('keydown', this.SafariOnKeyDown, this);
17082 processValue : function(value){
17083 if(this.stripCharsRe){
17084 var newValue = value.replace(this.stripCharsRe, '');
17085 if(newValue !== value){
17086 this.setRawValue(newValue);
17093 filterValidation : function(e){
17094 if(!e.isNavKeyPress()){
17095 this.validationTask.delay(this.validationDelay);
17100 onKeyUp : function(e){
17101 if(!e.isNavKeyPress()){
17105 // private - clean the leading white space
17106 cleanLeadingSpace : function(e)
17108 if ( this.inputType == 'file') {
17112 this.setValue((this.getValue() + '').replace(/^\s+/,''));
17115 * Resets the current field value to the originally-loaded value and clears any validation messages.
17118 reset : function(){
17119 Roo.form.TextField.superclass.reset.call(this);
17123 preFocus : function(){
17125 if(this.selectOnFocus){
17126 this.el.dom.select();
17132 filterKeys : function(e){
17133 var k = e.getKey();
17134 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
17137 var c = e.getCharCode(), cc = String.fromCharCode(c);
17138 if(Roo.isIE && (e.isSpecialKey() || !cc)){
17141 if(!this.maskRe.test(cc)){
17146 setValue : function(v){
17148 Roo.form.TextField.superclass.setValue.apply(this, arguments);
17154 * Validates a value according to the field's validation rules and marks the field as invalid
17155 * if the validation fails
17156 * @param {Mixed} value The value to validate
17157 * @return {Boolean} True if the value is valid, else false
17159 validateValue : function(value){
17160 if(value.length < 1) { // if it's blank
17161 if(this.allowBlank){
17162 this.clearInvalid();
17165 this.markInvalid(this.blankText);
17169 if(value.length < this.minLength){
17170 this.markInvalid(String.format(this.minLengthText, this.minLength));
17173 if(value.length > this.maxLength){
17174 this.markInvalid(String.format(this.maxLengthText, this.maxLength));
17178 var vt = Roo.form.VTypes;
17179 if(!vt[this.vtype](value, this)){
17180 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
17184 if(typeof this.validator == "function"){
17185 var msg = this.validator(value);
17187 this.markInvalid(msg);
17191 if(this.regex && !this.regex.test(value)){
17192 this.markInvalid(this.regexText);
17199 * Selects text in this field
17200 * @param {Number} start (optional) The index where the selection should start (defaults to 0)
17201 * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
17203 selectText : function(start, end){
17204 var v = this.getRawValue();
17206 start = start === undefined ? 0 : start;
17207 end = end === undefined ? v.length : end;
17208 var d = this.el.dom;
17209 if(d.setSelectionRange){
17210 d.setSelectionRange(start, end);
17211 }else if(d.createTextRange){
17212 var range = d.createTextRange();
17213 range.moveStart("character", start);
17214 range.moveEnd("character", v.length-end);
17221 * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
17222 * This only takes effect if grow = true, and fires the autosize event.
17224 autoSize : function(){
17225 if(!this.grow || !this.rendered){
17229 this.metrics = Roo.util.TextMetrics.createInstance(this.el);
17232 var v = el.dom.value;
17233 var d = document.createElement('div');
17234 d.appendChild(document.createTextNode(v));
17238 var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
17239 this.el.setWidth(w);
17240 this.fireEvent("autosize", this, w);
17244 SafariOnKeyDown : function(event)
17246 // this is a workaround for a password hang bug on chrome/ webkit.
17248 var isSelectAll = false;
17250 if(this.el.dom.selectionEnd > 0){
17251 isSelectAll = (this.el.dom.selectionEnd - this.el.dom.selectionStart - this.getValue().length == 0) ? true : false;
17253 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
17254 event.preventDefault();
17259 if(isSelectAll && event.getCharCode() > 31){ // backspace and delete key
17261 event.preventDefault();
17262 // this is very hacky as keydown always get's upper case.
17264 var cc = String.fromCharCode(event.getCharCode());
17267 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
17275 * Ext JS Library 1.1.1
17276 * Copyright(c) 2006-2007, Ext JS, LLC.
17278 * Originally Released Under LGPL - original licence link has changed is not relivant.
17281 * <script type="text/javascript">
17285 * @class Roo.form.Hidden
17286 * @extends Roo.form.TextField
17287 * Simple Hidden element used on forms
17289 * usage: form.add(new Roo.form.HiddenField({ 'name' : 'test1' }));
17292 * Creates a new Hidden form element.
17293 * @param {Object} config Configuration options
17298 // easy hidden field...
17299 Roo.form.Hidden = function(config){
17300 Roo.form.Hidden.superclass.constructor.call(this, config);
17303 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
17305 inputType: 'hidden',
17308 labelSeparator: '',
17310 itemCls : 'x-form-item-display-none'
17318 * Ext JS Library 1.1.1
17319 * Copyright(c) 2006-2007, Ext JS, LLC.
17321 * Originally Released Under LGPL - original licence link has changed is not relivant.
17324 * <script type="text/javascript">
17328 * @class Roo.form.TriggerField
17329 * @extends Roo.form.TextField
17330 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
17331 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
17332 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
17333 * for which you can provide a custom implementation. For example:
17335 var trigger = new Roo.form.TriggerField();
17336 trigger.onTriggerClick = myTriggerFn;
17337 trigger.applyTo('my-field');
17340 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
17341 * {@link Roo.form.DateField} and {@link Roo.form.ComboBox} are perfect examples of this.
17342 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
17343 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
17345 * Create a new TriggerField.
17346 * @param {Object} config Configuration options (valid {@Roo.form.TextField} config options will also be applied
17347 * to the base TextField)
17349 Roo.form.TriggerField = function(config){
17350 this.mimicing = false;
17351 Roo.form.TriggerField.superclass.constructor.call(this, config);
17354 Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
17356 * @cfg {String} triggerClass A CSS class to apply to the trigger
17359 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
17360 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
17362 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "new-password"},
17364 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
17368 /** @cfg {Boolean} grow @hide */
17369 /** @cfg {Number} growMin @hide */
17370 /** @cfg {Number} growMax @hide */
17376 autoSize: Roo.emptyFn,
17380 deferHeight : true,
17383 actionMode : 'wrap',
17385 onResize : function(w, h){
17386 Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
17387 if(typeof w == 'number'){
17388 var x = w - this.trigger.getWidth();
17389 this.el.setWidth(this.adjustWidth('input', x));
17390 this.trigger.setStyle('left', x+'px');
17395 adjustSize : Roo.BoxComponent.prototype.adjustSize,
17398 getResizeEl : function(){
17403 getPositionEl : function(){
17408 alignErrorIcon : function(){
17409 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
17413 onRender : function(ct, position){
17414 Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
17415 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
17416 this.trigger = this.wrap.createChild(this.triggerConfig ||
17417 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
17418 if(this.hideTrigger){
17419 this.trigger.setDisplayed(false);
17421 this.initTrigger();
17423 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
17428 initTrigger : function(){
17429 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
17430 this.trigger.addClassOnOver('x-form-trigger-over');
17431 this.trigger.addClassOnClick('x-form-trigger-click');
17435 onDestroy : function(){
17437 this.trigger.removeAllListeners();
17438 this.trigger.remove();
17441 this.wrap.remove();
17443 Roo.form.TriggerField.superclass.onDestroy.call(this);
17447 onFocus : function(){
17448 Roo.form.TriggerField.superclass.onFocus.call(this);
17449 if(!this.mimicing){
17450 this.wrap.addClass('x-trigger-wrap-focus');
17451 this.mimicing = true;
17452 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
17453 if(this.monitorTab){
17454 this.el.on("keydown", this.checkTab, this);
17460 checkTab : function(e){
17461 if(e.getKey() == e.TAB){
17462 this.triggerBlur();
17467 onBlur : function(){
17472 mimicBlur : function(e, t){
17473 if(!this.wrap.contains(t) && this.validateBlur()){
17474 this.triggerBlur();
17479 triggerBlur : function(){
17480 this.mimicing = false;
17481 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
17482 if(this.monitorTab){
17483 this.el.un("keydown", this.checkTab, this);
17485 this.wrap.removeClass('x-trigger-wrap-focus');
17486 Roo.form.TriggerField.superclass.onBlur.call(this);
17490 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
17491 validateBlur : function(e, t){
17496 onDisable : function(){
17497 Roo.form.TriggerField.superclass.onDisable.call(this);
17499 this.wrap.addClass('x-item-disabled');
17504 onEnable : function(){
17505 Roo.form.TriggerField.superclass.onEnable.call(this);
17507 this.wrap.removeClass('x-item-disabled');
17512 onShow : function(){
17513 var ae = this.getActionEl();
17516 ae.dom.style.display = '';
17517 ae.dom.style.visibility = 'visible';
17523 onHide : function(){
17524 var ae = this.getActionEl();
17525 ae.dom.style.display = 'none';
17529 * The function that should handle the trigger's click event. This method does nothing by default until overridden
17530 * by an implementing function.
17532 * @param {EventObject} e
17534 onTriggerClick : Roo.emptyFn
17537 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
17538 // to be extended by an implementing class. For an example of implementing this class, see the custom
17539 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
17540 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
17541 initComponent : function(){
17542 Roo.form.TwinTriggerField.superclass.initComponent.call(this);
17544 this.triggerConfig = {
17545 tag:'span', cls:'x-form-twin-triggers', cn:[
17546 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
17547 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
17551 getTrigger : function(index){
17552 return this.triggers[index];
17555 initTrigger : function(){
17556 var ts = this.trigger.select('.x-form-trigger', true);
17557 this.wrap.setStyle('overflow', 'hidden');
17558 var triggerField = this;
17559 ts.each(function(t, all, index){
17560 t.hide = function(){
17561 var w = triggerField.wrap.getWidth();
17562 this.dom.style.display = 'none';
17563 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
17565 t.show = function(){
17566 var w = triggerField.wrap.getWidth();
17567 this.dom.style.display = '';
17568 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
17570 var triggerIndex = 'Trigger'+(index+1);
17572 if(this['hide'+triggerIndex]){
17573 t.dom.style.display = 'none';
17575 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
17576 t.addClassOnOver('x-form-trigger-over');
17577 t.addClassOnClick('x-form-trigger-click');
17579 this.triggers = ts.elements;
17582 onTrigger1Click : Roo.emptyFn,
17583 onTrigger2Click : Roo.emptyFn
17586 * Ext JS Library 1.1.1
17587 * Copyright(c) 2006-2007, Ext JS, LLC.
17589 * Originally Released Under LGPL - original licence link has changed is not relivant.
17592 * <script type="text/javascript">
17596 * @class Roo.form.TextArea
17597 * @extends Roo.form.TextField
17598 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
17599 * support for auto-sizing.
17601 * Creates a new TextArea
17602 * @param {Object} config Configuration options
17604 Roo.form.TextArea = function(config){
17605 Roo.form.TextArea.superclass.constructor.call(this, config);
17606 // these are provided exchanges for backwards compat
17607 // minHeight/maxHeight were replaced by growMin/growMax to be
17608 // compatible with TextField growing config values
17609 if(this.minHeight !== undefined){
17610 this.growMin = this.minHeight;
17612 if(this.maxHeight !== undefined){
17613 this.growMax = this.maxHeight;
17617 Roo.extend(Roo.form.TextArea, Roo.form.TextField, {
17619 * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
17623 * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
17627 * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
17628 * in the field (equivalent to setting overflow: hidden, defaults to false)
17630 preventScrollbars: false,
17632 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
17633 * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"})
17637 onRender : function(ct, position){
17639 this.defaultAutoCreate = {
17641 style:"width:300px;height:60px;",
17642 autocomplete: "new-password"
17645 Roo.form.TextArea.superclass.onRender.call(this, ct, position);
17647 this.textSizeEl = Roo.DomHelper.append(document.body, {
17648 tag: "pre", cls: "x-form-grow-sizer"
17650 if(this.preventScrollbars){
17651 this.el.setStyle("overflow", "hidden");
17653 this.el.setHeight(this.growMin);
17657 onDestroy : function(){
17658 if(this.textSizeEl){
17659 this.textSizeEl.parentNode.removeChild(this.textSizeEl);
17661 Roo.form.TextArea.superclass.onDestroy.call(this);
17665 onKeyUp : function(e){
17666 if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
17672 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
17673 * This only takes effect if grow = true, and fires the autosize event if the height changes.
17675 autoSize : function(){
17676 if(!this.grow || !this.textSizeEl){
17680 var v = el.dom.value;
17681 var ts = this.textSizeEl;
17684 ts.appendChild(document.createTextNode(v));
17687 Roo.fly(ts).setWidth(this.el.getWidth());
17689 v = "  ";
17692 v = v.replace(/\n/g, '<p> </p>');
17694 v += " \n ";
17697 var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
17698 if(h != this.lastHeight){
17699 this.lastHeight = h;
17700 this.el.setHeight(h);
17701 this.fireEvent("autosize", this, h);
17706 * Ext JS Library 1.1.1
17707 * Copyright(c) 2006-2007, Ext JS, LLC.
17709 * Originally Released Under LGPL - original licence link has changed is not relivant.
17712 * <script type="text/javascript">
17717 * @class Roo.form.NumberField
17718 * @extends Roo.form.TextField
17719 * Numeric text field that provides automatic keystroke filtering and numeric validation.
17721 * Creates a new NumberField
17722 * @param {Object} config Configuration options
17724 Roo.form.NumberField = function(config){
17725 Roo.form.NumberField.superclass.constructor.call(this, config);
17728 Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
17730 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
17732 fieldClass: "x-form-field x-form-num-field",
17734 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
17736 allowDecimals : true,
17738 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
17740 decimalSeparator : ".",
17742 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
17744 decimalPrecision : 2,
17746 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
17748 allowNegative : true,
17750 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
17752 minValue : Number.NEGATIVE_INFINITY,
17754 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
17756 maxValue : Number.MAX_VALUE,
17758 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
17760 minText : "The minimum value for this field is {0}",
17762 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
17764 maxText : "The maximum value for this field is {0}",
17766 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
17767 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
17769 nanText : "{0} is not a valid number",
17772 initEvents : function(){
17773 Roo.form.NumberField.superclass.initEvents.call(this);
17774 var allowed = "0123456789";
17775 if(this.allowDecimals){
17776 allowed += this.decimalSeparator;
17778 if(this.allowNegative){
17781 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
17782 var keyPress = function(e){
17783 var k = e.getKey();
17784 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
17787 var c = e.getCharCode();
17788 if(allowed.indexOf(String.fromCharCode(c)) === -1){
17792 this.el.on("keypress", keyPress, this);
17796 validateValue : function(value){
17797 if(!Roo.form.NumberField.superclass.validateValue.call(this, value)){
17800 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
17803 var num = this.parseValue(value);
17805 this.markInvalid(String.format(this.nanText, value));
17808 if(num < this.minValue){
17809 this.markInvalid(String.format(this.minText, this.minValue));
17812 if(num > this.maxValue){
17813 this.markInvalid(String.format(this.maxText, this.maxValue));
17819 getValue : function(){
17820 return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
17824 parseValue : function(value){
17825 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
17826 return isNaN(value) ? '' : value;
17830 fixPrecision : function(value){
17831 var nan = isNaN(value);
17832 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
17833 return nan ? '' : value;
17835 return parseFloat(value).toFixed(this.decimalPrecision);
17838 setValue : function(v){
17839 v = this.fixPrecision(v);
17840 Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
17844 decimalPrecisionFcn : function(v){
17845 return Math.floor(v);
17848 beforeBlur : function(){
17849 var v = this.parseValue(this.getRawValue());
17856 * Ext JS Library 1.1.1
17857 * Copyright(c) 2006-2007, Ext JS, LLC.
17859 * Originally Released Under LGPL - original licence link has changed is not relivant.
17862 * <script type="text/javascript">
17866 * @class Roo.form.DateField
17867 * @extends Roo.form.TriggerField
17868 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
17870 * Create a new DateField
17871 * @param {Object} config
17873 Roo.form.DateField = function(config)
17875 Roo.form.DateField.superclass.constructor.call(this, config);
17881 * Fires when a date is selected
17882 * @param {Roo.form.DateField} combo This combo box
17883 * @param {Date} date The date selected
17890 if(typeof this.minValue == "string") {
17891 this.minValue = this.parseDate(this.minValue);
17893 if(typeof this.maxValue == "string") {
17894 this.maxValue = this.parseDate(this.maxValue);
17896 this.ddMatch = null;
17897 if(this.disabledDates){
17898 var dd = this.disabledDates;
17900 for(var i = 0; i < dd.length; i++){
17902 if(i != dd.length-1) {
17906 this.ddMatch = new RegExp(re + ")");
17910 Roo.extend(Roo.form.DateField, Roo.form.TriggerField, {
17912 * @cfg {String} format
17913 * The default date format string which can be overriden for localization support. The format must be
17914 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
17918 * @cfg {String} altFormats
17919 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
17920 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
17922 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
17924 * @cfg {Array} disabledDays
17925 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
17927 disabledDays : null,
17929 * @cfg {String} disabledDaysText
17930 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
17932 disabledDaysText : "Disabled",
17934 * @cfg {Array} disabledDates
17935 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
17936 * expression so they are very powerful. Some examples:
17938 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
17939 * <li>["03/08", "09/16"] would disable those days for every year</li>
17940 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
17941 * <li>["03/../2006"] would disable every day in March 2006</li>
17942 * <li>["^03"] would disable every day in every March</li>
17944 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
17945 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
17947 disabledDates : null,
17949 * @cfg {String} disabledDatesText
17950 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
17952 disabledDatesText : "Disabled",
17954 * @cfg {Date/String} minValue
17955 * The minimum allowed date. Can be either a Javascript date object or a string date in a
17956 * valid format (defaults to null).
17960 * @cfg {Date/String} maxValue
17961 * The maximum allowed date. Can be either a Javascript date object or a string date in a
17962 * valid format (defaults to null).
17966 * @cfg {String} minText
17967 * The error text to display when the date in the cell is before minValue (defaults to
17968 * 'The date in this field must be after {minValue}').
17970 minText : "The date in this field must be equal to or after {0}",
17972 * @cfg {String} maxText
17973 * The error text to display when the date in the cell is after maxValue (defaults to
17974 * 'The date in this field must be before {maxValue}').
17976 maxText : "The date in this field must be equal to or before {0}",
17978 * @cfg {String} invalidText
17979 * The error text to display when the date in the field is invalid (defaults to
17980 * '{value} is not a valid date - it must be in the format {format}').
17982 invalidText : "{0} is not a valid date - it must be in the format {1}",
17984 * @cfg {String} triggerClass
17985 * An additional CSS class used to style the trigger button. The trigger will always get the
17986 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
17987 * which displays a calendar icon).
17989 triggerClass : 'x-form-date-trigger',
17993 * @cfg {Boolean} useIso
17994 * if enabled, then the date field will use a hidden field to store the
17995 * real value as iso formated date. default (false)
17999 * @cfg {String/Object} autoCreate
18000 * A DomHelper element spec, or true for a default element spec (defaults to
18001 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
18004 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
18007 hiddenField: false,
18009 onRender : function(ct, position)
18011 Roo.form.DateField.superclass.onRender.call(this, ct, position);
18013 //this.el.dom.removeAttribute('name');
18014 Roo.log("Changing name?");
18015 this.el.dom.setAttribute('name', this.name + '____hidden___' );
18016 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
18018 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
18019 // prevent input submission
18020 this.hiddenName = this.name;
18027 validateValue : function(value)
18029 value = this.formatDate(value);
18030 if(!Roo.form.DateField.superclass.validateValue.call(this, value)){
18031 Roo.log('super failed');
18034 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
18037 var svalue = value;
18038 value = this.parseDate(value);
18040 Roo.log('parse date failed' + svalue);
18041 this.markInvalid(String.format(this.invalidText, svalue, this.format));
18044 var time = value.getTime();
18045 if(this.minValue && time < this.minValue.getTime()){
18046 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
18049 if(this.maxValue && time > this.maxValue.getTime()){
18050 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
18053 if(this.disabledDays){
18054 var day = value.getDay();
18055 for(var i = 0; i < this.disabledDays.length; i++) {
18056 if(day === this.disabledDays[i]){
18057 this.markInvalid(this.disabledDaysText);
18062 var fvalue = this.formatDate(value);
18063 if(this.ddMatch && this.ddMatch.test(fvalue)){
18064 this.markInvalid(String.format(this.disabledDatesText, fvalue));
18071 // Provides logic to override the default TriggerField.validateBlur which just returns true
18072 validateBlur : function(){
18073 return !this.menu || !this.menu.isVisible();
18076 getName: function()
18078 // returns hidden if it's set..
18079 if (!this.rendered) {return ''};
18080 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
18085 * Returns the current date value of the date field.
18086 * @return {Date} The date value
18088 getValue : function(){
18090 return this.hiddenField ?
18091 this.hiddenField.value :
18092 this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
18096 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
18097 * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}
18098 * (the default format used is "m/d/y").
18101 //All of these calls set the same date value (May 4, 2006)
18103 //Pass a date object:
18104 var dt = new Date('5/4/06');
18105 dateField.setValue(dt);
18107 //Pass a date string (default format):
18108 dateField.setValue('5/4/06');
18110 //Pass a date string (custom format):
18111 dateField.format = 'Y-m-d';
18112 dateField.setValue('2006-5-4');
18114 * @param {String/Date} date The date or valid date string
18116 setValue : function(date){
18117 if (this.hiddenField) {
18118 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
18120 Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
18121 // make sure the value field is always stored as a date..
18122 this.value = this.parseDate(date);
18128 parseDate : function(value){
18129 if(!value || value instanceof Date){
18132 var v = Date.parseDate(value, this.format);
18133 if (!v && this.useIso) {
18134 v = Date.parseDate(value, 'Y-m-d');
18136 if(!v && this.altFormats){
18137 if(!this.altFormatsArray){
18138 this.altFormatsArray = this.altFormats.split("|");
18140 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18141 v = Date.parseDate(value, this.altFormatsArray[i]);
18148 formatDate : function(date, fmt){
18149 return (!date || !(date instanceof Date)) ?
18150 date : date.dateFormat(fmt || this.format);
18155 select: function(m, d){
18158 this.fireEvent('select', this, d);
18160 show : function(){ // retain focus styling
18164 this.focus.defer(10, this);
18165 var ml = this.menuListeners;
18166 this.menu.un("select", ml.select, this);
18167 this.menu.un("show", ml.show, this);
18168 this.menu.un("hide", ml.hide, this);
18173 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
18174 onTriggerClick : function(){
18178 if(this.menu == null){
18179 this.menu = new Roo.menu.DateMenu();
18181 Roo.apply(this.menu.picker, {
18182 showClear: this.allowBlank,
18183 minDate : this.minValue,
18184 maxDate : this.maxValue,
18185 disabledDatesRE : this.ddMatch,
18186 disabledDatesText : this.disabledDatesText,
18187 disabledDays : this.disabledDays,
18188 disabledDaysText : this.disabledDaysText,
18189 format : this.useIso ? 'Y-m-d' : this.format,
18190 minText : String.format(this.minText, this.formatDate(this.minValue)),
18191 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
18193 this.menu.on(Roo.apply({}, this.menuListeners, {
18196 this.menu.picker.setValue(this.getValue() || new Date());
18197 this.menu.show(this.el, "tl-bl?");
18200 beforeBlur : function(){
18201 var v = this.parseDate(this.getRawValue());
18211 isDirty : function() {
18212 if(this.disabled) {
18216 if(typeof(this.startValue) === 'undefined'){
18220 return String(this.getValue()) !== String(this.startValue);
18224 cleanLeadingSpace : function(e)
18231 * Ext JS Library 1.1.1
18232 * Copyright(c) 2006-2007, Ext JS, LLC.
18234 * Originally Released Under LGPL - original licence link has changed is not relivant.
18237 * <script type="text/javascript">
18241 * @class Roo.form.MonthField
18242 * @extends Roo.form.TriggerField
18243 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
18245 * Create a new MonthField
18246 * @param {Object} config
18248 Roo.form.MonthField = function(config){
18250 Roo.form.MonthField.superclass.constructor.call(this, config);
18256 * Fires when a date is selected
18257 * @param {Roo.form.MonthFieeld} combo This combo box
18258 * @param {Date} date The date selected
18265 if(typeof this.minValue == "string") {
18266 this.minValue = this.parseDate(this.minValue);
18268 if(typeof this.maxValue == "string") {
18269 this.maxValue = this.parseDate(this.maxValue);
18271 this.ddMatch = null;
18272 if(this.disabledDates){
18273 var dd = this.disabledDates;
18275 for(var i = 0; i < dd.length; i++){
18277 if(i != dd.length-1) {
18281 this.ddMatch = new RegExp(re + ")");
18285 Roo.extend(Roo.form.MonthField, Roo.form.TriggerField, {
18287 * @cfg {String} format
18288 * The default date format string which can be overriden for localization support. The format must be
18289 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18293 * @cfg {String} altFormats
18294 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18295 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18297 altFormats : "M Y|m/Y|m-y|m-Y|my|mY",
18299 * @cfg {Array} disabledDays
18300 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
18302 disabledDays : [0,1,2,3,4,5,6],
18304 * @cfg {String} disabledDaysText
18305 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
18307 disabledDaysText : "Disabled",
18309 * @cfg {Array} disabledDates
18310 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
18311 * expression so they are very powerful. Some examples:
18313 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
18314 * <li>["03/08", "09/16"] would disable those days for every year</li>
18315 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
18316 * <li>["03/../2006"] would disable every day in March 2006</li>
18317 * <li>["^03"] would disable every day in every March</li>
18319 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
18320 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
18322 disabledDates : null,
18324 * @cfg {String} disabledDatesText
18325 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
18327 disabledDatesText : "Disabled",
18329 * @cfg {Date/String} minValue
18330 * The minimum allowed date. Can be either a Javascript date object or a string date in a
18331 * valid format (defaults to null).
18335 * @cfg {Date/String} maxValue
18336 * The maximum allowed date. Can be either a Javascript date object or a string date in a
18337 * valid format (defaults to null).
18341 * @cfg {String} minText
18342 * The error text to display when the date in the cell is before minValue (defaults to
18343 * 'The date in this field must be after {minValue}').
18345 minText : "The date in this field must be equal to or after {0}",
18347 * @cfg {String} maxTextf
18348 * The error text to display when the date in the cell is after maxValue (defaults to
18349 * 'The date in this field must be before {maxValue}').
18351 maxText : "The date in this field must be equal to or before {0}",
18353 * @cfg {String} invalidText
18354 * The error text to display when the date in the field is invalid (defaults to
18355 * '{value} is not a valid date - it must be in the format {format}').
18357 invalidText : "{0} is not a valid date - it must be in the format {1}",
18359 * @cfg {String} triggerClass
18360 * An additional CSS class used to style the trigger button. The trigger will always get the
18361 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
18362 * which displays a calendar icon).
18364 triggerClass : 'x-form-date-trigger',
18368 * @cfg {Boolean} useIso
18369 * if enabled, then the date field will use a hidden field to store the
18370 * real value as iso formated date. default (true)
18374 * @cfg {String/Object} autoCreate
18375 * A DomHelper element spec, or true for a default element spec (defaults to
18376 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
18379 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "new-password"},
18382 hiddenField: false,
18384 hideMonthPicker : false,
18386 onRender : function(ct, position)
18388 Roo.form.MonthField.superclass.onRender.call(this, ct, position);
18390 this.el.dom.removeAttribute('name');
18391 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
18393 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
18394 // prevent input submission
18395 this.hiddenName = this.name;
18402 validateValue : function(value)
18404 value = this.formatDate(value);
18405 if(!Roo.form.MonthField.superclass.validateValue.call(this, value)){
18408 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
18411 var svalue = value;
18412 value = this.parseDate(value);
18414 this.markInvalid(String.format(this.invalidText, svalue, this.format));
18417 var time = value.getTime();
18418 if(this.minValue && time < this.minValue.getTime()){
18419 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
18422 if(this.maxValue && time > this.maxValue.getTime()){
18423 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
18426 /*if(this.disabledDays){
18427 var day = value.getDay();
18428 for(var i = 0; i < this.disabledDays.length; i++) {
18429 if(day === this.disabledDays[i]){
18430 this.markInvalid(this.disabledDaysText);
18436 var fvalue = this.formatDate(value);
18437 /*if(this.ddMatch && this.ddMatch.test(fvalue)){
18438 this.markInvalid(String.format(this.disabledDatesText, fvalue));
18446 // Provides logic to override the default TriggerField.validateBlur which just returns true
18447 validateBlur : function(){
18448 return !this.menu || !this.menu.isVisible();
18452 * Returns the current date value of the date field.
18453 * @return {Date} The date value
18455 getValue : function(){
18459 return this.hiddenField ?
18460 this.hiddenField.value :
18461 this.parseDate(Roo.form.MonthField.superclass.getValue.call(this)) || "";
18465 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
18466 * date, using MonthField.format as the date format, according to the same rules as {@link Date#parseDate}
18467 * (the default format used is "m/d/y").
18470 //All of these calls set the same date value (May 4, 2006)
18472 //Pass a date object:
18473 var dt = new Date('5/4/06');
18474 monthField.setValue(dt);
18476 //Pass a date string (default format):
18477 monthField.setValue('5/4/06');
18479 //Pass a date string (custom format):
18480 monthField.format = 'Y-m-d';
18481 monthField.setValue('2006-5-4');
18483 * @param {String/Date} date The date or valid date string
18485 setValue : function(date){
18486 Roo.log('month setValue' + date);
18487 // can only be first of month..
18489 var val = this.parseDate(date);
18491 if (this.hiddenField) {
18492 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
18494 Roo.form.MonthField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
18495 this.value = this.parseDate(date);
18499 parseDate : function(value){
18500 if(!value || value instanceof Date){
18501 value = value ? Date.parseDate(value.format('Y-m') + '-01', 'Y-m-d') : null;
18504 var v = Date.parseDate(value, this.format);
18505 if (!v && this.useIso) {
18506 v = Date.parseDate(value, 'Y-m-d');
18510 v = Date.parseDate(v.format('Y-m') +'-01', 'Y-m-d');
18514 if(!v && this.altFormats){
18515 if(!this.altFormatsArray){
18516 this.altFormatsArray = this.altFormats.split("|");
18518 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18519 v = Date.parseDate(value, this.altFormatsArray[i]);
18526 formatDate : function(date, fmt){
18527 return (!date || !(date instanceof Date)) ?
18528 date : date.dateFormat(fmt || this.format);
18533 select: function(m, d){
18535 this.fireEvent('select', this, d);
18537 show : function(){ // retain focus styling
18541 this.focus.defer(10, this);
18542 var ml = this.menuListeners;
18543 this.menu.un("select", ml.select, this);
18544 this.menu.un("show", ml.show, this);
18545 this.menu.un("hide", ml.hide, this);
18549 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
18550 onTriggerClick : function(){
18554 if(this.menu == null){
18555 this.menu = new Roo.menu.DateMenu();
18559 Roo.apply(this.menu.picker, {
18561 showClear: this.allowBlank,
18562 minDate : this.minValue,
18563 maxDate : this.maxValue,
18564 disabledDatesRE : this.ddMatch,
18565 disabledDatesText : this.disabledDatesText,
18567 format : this.useIso ? 'Y-m-d' : this.format,
18568 minText : String.format(this.minText, this.formatDate(this.minValue)),
18569 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
18572 this.menu.on(Roo.apply({}, this.menuListeners, {
18580 // hide month picker get's called when we called by 'before hide';
18582 var ignorehide = true;
18583 p.hideMonthPicker = function(disableAnim){
18587 if(this.monthPicker){
18588 Roo.log("hideMonthPicker called");
18589 if(disableAnim === true){
18590 this.monthPicker.hide();
18592 this.monthPicker.slideOut('t', {duration:.2});
18593 p.setValue(new Date(m.picker.mpSelYear, m.picker.mpSelMonth, 1));
18594 p.fireEvent("select", this, this.value);
18600 Roo.log('picker set value');
18601 Roo.log(this.getValue());
18602 p.setValue(this.getValue() ? this.parseDate(this.getValue()) : new Date());
18603 m.show(this.el, 'tl-bl?');
18604 ignorehide = false;
18605 // this will trigger hideMonthPicker..
18608 // hidden the day picker
18609 Roo.select('.x-date-picker table', true).first().dom.style.visibility = "hidden";
18615 p.showMonthPicker.defer(100, p);
18621 beforeBlur : function(){
18622 var v = this.parseDate(this.getRawValue());
18628 /** @cfg {Boolean} grow @hide */
18629 /** @cfg {Number} growMin @hide */
18630 /** @cfg {Number} growMax @hide */
18637 * Ext JS Library 1.1.1
18638 * Copyright(c) 2006-2007, Ext JS, LLC.
18640 * Originally Released Under LGPL - original licence link has changed is not relivant.
18643 * <script type="text/javascript">
18648 * @class Roo.form.ComboBox
18649 * @extends Roo.form.TriggerField
18650 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
18652 * Create a new ComboBox.
18653 * @param {Object} config Configuration options
18655 Roo.form.ComboBox = function(config){
18656 Roo.form.ComboBox.superclass.constructor.call(this, config);
18660 * Fires when the dropdown list is expanded
18661 * @param {Roo.form.ComboBox} combo This combo box
18666 * Fires when the dropdown list is collapsed
18667 * @param {Roo.form.ComboBox} combo This combo box
18671 * @event beforeselect
18672 * Fires before a list item is selected. Return false to cancel the selection.
18673 * @param {Roo.form.ComboBox} combo This combo box
18674 * @param {Roo.data.Record} record The data record returned from the underlying store
18675 * @param {Number} index The index of the selected item in the dropdown list
18677 'beforeselect' : true,
18680 * Fires when a list item is selected
18681 * @param {Roo.form.ComboBox} combo This combo box
18682 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
18683 * @param {Number} index The index of the selected item in the dropdown list
18687 * @event beforequery
18688 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
18689 * The event object passed has these properties:
18690 * @param {Roo.form.ComboBox} combo This combo box
18691 * @param {String} query The query
18692 * @param {Boolean} forceAll true to force "all" query
18693 * @param {Boolean} cancel true to cancel the query
18694 * @param {Object} e The query event object
18696 'beforequery': true,
18699 * Fires when the 'add' icon is pressed (add a listener to enable add button)
18700 * @param {Roo.form.ComboBox} combo This combo box
18705 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
18706 * @param {Roo.form.ComboBox} combo This combo box
18707 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
18713 if(this.transform){
18714 this.allowDomMove = false;
18715 var s = Roo.getDom(this.transform);
18716 if(!this.hiddenName){
18717 this.hiddenName = s.name;
18720 this.mode = 'local';
18721 var d = [], opts = s.options;
18722 for(var i = 0, len = opts.length;i < len; i++){
18724 var value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
18726 this.value = value;
18728 d.push([value, o.text]);
18730 this.store = new Roo.data.SimpleStore({
18732 fields: ['value', 'text'],
18735 this.valueField = 'value';
18736 this.displayField = 'text';
18738 s.name = Roo.id(); // wipe out the name in case somewhere else they have a reference
18739 if(!this.lazyRender){
18740 this.target = true;
18741 this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
18742 s.parentNode.removeChild(s); // remove it
18743 this.render(this.el.parentNode);
18745 s.parentNode.removeChild(s); // remove it
18750 this.store = Roo.factory(this.store, Roo.data);
18753 this.selectedIndex = -1;
18754 if(this.mode == 'local'){
18755 if(config.queryDelay === undefined){
18756 this.queryDelay = 10;
18758 if(config.minChars === undefined){
18764 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
18766 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
18769 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
18770 * rendering into an Roo.Editor, defaults to false)
18773 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
18774 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
18777 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
18780 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
18781 * the dropdown list (defaults to undefined, with no header element)
18785 * @cfg {String/Roo.Template} tpl The template to use to render the output
18789 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
18791 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
18793 listWidth: undefined,
18795 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
18796 * mode = 'remote' or 'text' if mode = 'local')
18798 displayField: undefined,
18800 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
18801 * mode = 'remote' or 'value' if mode = 'local').
18802 * Note: use of a valueField requires the user make a selection
18803 * in order for a value to be mapped.
18805 valueField: undefined,
18809 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
18810 * field's data value (defaults to the underlying DOM element's name)
18812 hiddenName: undefined,
18814 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
18818 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
18820 selectedClass: 'x-combo-selected',
18822 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
18823 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
18824 * which displays a downward arrow icon).
18826 triggerClass : 'x-form-arrow-trigger',
18828 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
18832 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
18833 * anchor positions (defaults to 'tl-bl')
18835 listAlign: 'tl-bl?',
18837 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
18841 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
18842 * query specified by the allQuery config option (defaults to 'query')
18844 triggerAction: 'query',
18846 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
18847 * (defaults to 4, does not apply if editable = false)
18851 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
18852 * delay (typeAheadDelay) if it matches a known value (defaults to false)
18856 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
18857 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
18861 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
18862 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
18866 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
18867 * when editable = true (defaults to false)
18869 selectOnFocus:false,
18871 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
18873 queryParam: 'query',
18875 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
18876 * when mode = 'remote' (defaults to 'Loading...')
18878 loadingText: 'Loading...',
18880 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
18884 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
18888 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
18889 * traditional select (defaults to true)
18893 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
18897 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
18901 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
18902 * listWidth has a higher value)
18906 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
18907 * allow the user to set arbitrary text into the field (defaults to false)
18909 forceSelection:false,
18911 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
18912 * if typeAhead = true (defaults to 250)
18914 typeAheadDelay : 250,
18916 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
18917 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
18919 valueNotFoundText : undefined,
18921 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
18923 blockFocus : false,
18926 * @cfg {Boolean} disableClear Disable showing of clear button.
18928 disableClear : false,
18930 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
18932 alwaysQuery : false,
18938 // element that contains real text value.. (when hidden is used..)
18941 onRender : function(ct, position)
18943 Roo.form.ComboBox.superclass.onRender.call(this, ct, position);
18945 if(this.hiddenName){
18946 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
18948 this.hiddenField.value =
18949 this.hiddenValue !== undefined ? this.hiddenValue :
18950 this.value !== undefined ? this.value : '';
18952 // prevent input submission
18953 this.el.dom.removeAttribute('name');
18959 this.el.dom.setAttribute('autocomplete', 'off');
18962 var cls = 'x-combo-list';
18964 this.list = new Roo.Layer({
18965 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
18968 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
18969 this.list.setWidth(lw);
18970 this.list.swallowEvent('mousewheel');
18971 this.assetHeight = 0;
18974 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
18975 this.assetHeight += this.header.getHeight();
18978 this.innerList = this.list.createChild({cls:cls+'-inner'});
18979 this.innerList.on('mouseover', this.onViewOver, this);
18980 this.innerList.on('mousemove', this.onViewMove, this);
18981 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
18983 if(this.allowBlank && !this.pageSize && !this.disableClear){
18984 this.footer = this.list.createChild({cls:cls+'-ft'});
18985 this.pageTb = new Roo.Toolbar(this.footer);
18989 this.footer = this.list.createChild({cls:cls+'-ft'});
18990 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
18991 {pageSize: this.pageSize});
18995 if (this.pageTb && this.allowBlank && !this.disableClear) {
18997 this.pageTb.add(new Roo.Toolbar.Fill(), {
18998 cls: 'x-btn-icon x-btn-clear',
19000 handler: function()
19003 _this.clearValue();
19004 _this.onSelect(false, -1);
19009 this.assetHeight += this.footer.getHeight();
19014 this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
19017 this.view = new Roo.View(this.innerList, this.tpl, {
19020 selectedClass: this.selectedClass
19023 this.view.on('click', this.onViewClick, this);
19025 this.store.on('beforeload', this.onBeforeLoad, this);
19026 this.store.on('load', this.onLoad, this);
19027 this.store.on('loadexception', this.onLoadException, this);
19029 if(this.resizable){
19030 this.resizer = new Roo.Resizable(this.list, {
19031 pinned:true, handles:'se'
19033 this.resizer.on('resize', function(r, w, h){
19034 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
19035 this.listWidth = w;
19036 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
19037 this.restrictHeight();
19039 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
19041 if(!this.editable){
19042 this.editable = true;
19043 this.setEditable(false);
19047 if (typeof(this.events.add.listeners) != 'undefined') {
19049 this.addicon = this.wrap.createChild(
19050 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
19052 this.addicon.on('click', function(e) {
19053 this.fireEvent('add', this);
19056 if (typeof(this.events.edit.listeners) != 'undefined') {
19058 this.editicon = this.wrap.createChild(
19059 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
19060 if (this.addicon) {
19061 this.editicon.setStyle('margin-left', '40px');
19063 this.editicon.on('click', function(e) {
19065 // we fire even if inothing is selected..
19066 this.fireEvent('edit', this, this.lastData );
19076 initEvents : function(){
19077 Roo.form.ComboBox.superclass.initEvents.call(this);
19079 this.keyNav = new Roo.KeyNav(this.el, {
19080 "up" : function(e){
19081 this.inKeyMode = true;
19085 "down" : function(e){
19086 if(!this.isExpanded()){
19087 this.onTriggerClick();
19089 this.inKeyMode = true;
19094 "enter" : function(e){
19095 this.onViewClick();
19099 "esc" : function(e){
19103 "tab" : function(e){
19104 this.onViewClick(false);
19105 this.fireEvent("specialkey", this, e);
19111 doRelay : function(foo, bar, hname){
19112 if(hname == 'down' || this.scope.isExpanded()){
19113 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
19120 this.queryDelay = Math.max(this.queryDelay || 10,
19121 this.mode == 'local' ? 10 : 250);
19122 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
19123 if(this.typeAhead){
19124 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
19126 if(this.editable !== false){
19127 this.el.on("keyup", this.onKeyUp, this);
19129 if(this.forceSelection){
19130 this.on('blur', this.doForce, this);
19134 onDestroy : function(){
19136 this.view.setStore(null);
19137 this.view.el.removeAllListeners();
19138 this.view.el.remove();
19139 this.view.purgeListeners();
19142 this.list.destroy();
19145 this.store.un('beforeload', this.onBeforeLoad, this);
19146 this.store.un('load', this.onLoad, this);
19147 this.store.un('loadexception', this.onLoadException, this);
19149 Roo.form.ComboBox.superclass.onDestroy.call(this);
19153 fireKey : function(e){
19154 if(e.isNavKeyPress() && !this.list.isVisible()){
19155 this.fireEvent("specialkey", this, e);
19160 onResize: function(w, h){
19161 Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
19163 if(typeof w != 'number'){
19164 // we do not handle it!?!?
19167 var tw = this.trigger.getWidth();
19168 tw += this.addicon ? this.addicon.getWidth() : 0;
19169 tw += this.editicon ? this.editicon.getWidth() : 0;
19171 this.el.setWidth( this.adjustWidth('input', x));
19173 this.trigger.setStyle('left', x+'px');
19175 if(this.list && this.listWidth === undefined){
19176 var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
19177 this.list.setWidth(lw);
19178 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
19186 * Allow or prevent the user from directly editing the field text. If false is passed,
19187 * the user will only be able to select from the items defined in the dropdown list. This method
19188 * is the runtime equivalent of setting the 'editable' config option at config time.
19189 * @param {Boolean} value True to allow the user to directly edit the field text
19191 setEditable : function(value){
19192 if(value == this.editable){
19195 this.editable = value;
19197 this.el.dom.setAttribute('readOnly', true);
19198 this.el.on('mousedown', this.onTriggerClick, this);
19199 this.el.addClass('x-combo-noedit');
19201 this.el.dom.setAttribute('readOnly', false);
19202 this.el.un('mousedown', this.onTriggerClick, this);
19203 this.el.removeClass('x-combo-noedit');
19208 onBeforeLoad : function(){
19209 if(!this.hasFocus){
19212 this.innerList.update(this.loadingText ?
19213 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
19214 this.restrictHeight();
19215 this.selectedIndex = -1;
19219 onLoad : function(){
19220 if(!this.hasFocus){
19223 if(this.store.getCount() > 0){
19225 this.restrictHeight();
19226 if(this.lastQuery == this.allQuery){
19228 this.el.dom.select();
19230 if(!this.selectByValue(this.value, true)){
19231 this.select(0, true);
19235 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
19236 this.taTask.delay(this.typeAheadDelay);
19240 this.onEmptyResults();
19245 onLoadException : function()
19248 Roo.log(this.store.reader.jsonData);
19249 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
19250 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
19256 onTypeAhead : function(){
19257 if(this.store.getCount() > 0){
19258 var r = this.store.getAt(0);
19259 var newValue = r.data[this.displayField];
19260 var len = newValue.length;
19261 var selStart = this.getRawValue().length;
19262 if(selStart != len){
19263 this.setRawValue(newValue);
19264 this.selectText(selStart, newValue.length);
19270 onSelect : function(record, index){
19271 if(this.fireEvent('beforeselect', this, record, index) !== false){
19272 this.setFromData(index > -1 ? record.data : false);
19274 this.fireEvent('select', this, record, index);
19279 * Returns the currently selected field value or empty string if no value is set.
19280 * @return {String} value The selected value
19282 getValue : function(){
19283 if(this.valueField){
19284 return typeof this.value != 'undefined' ? this.value : '';
19286 return Roo.form.ComboBox.superclass.getValue.call(this);
19290 * Clears any text/value currently set in the field
19292 clearValue : function(){
19293 if(this.hiddenField){
19294 this.hiddenField.value = '';
19297 this.setRawValue('');
19298 this.lastSelectionText = '';
19303 * Sets the specified value into the field. If the value finds a match, the corresponding record text
19304 * will be displayed in the field. If the value does not match the data value of an existing item,
19305 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
19306 * Otherwise the field will be blank (although the value will still be set).
19307 * @param {String} value The value to match
19309 setValue : function(v){
19311 if(this.valueField){
19312 var r = this.findRecord(this.valueField, v);
19314 text = r.data[this.displayField];
19315 }else if(this.valueNotFoundText !== undefined){
19316 text = this.valueNotFoundText;
19319 this.lastSelectionText = text;
19320 if(this.hiddenField){
19321 this.hiddenField.value = v;
19323 Roo.form.ComboBox.superclass.setValue.call(this, text);
19327 * @property {Object} the last set data for the element
19332 * Sets the value of the field based on a object which is related to the record format for the store.
19333 * @param {Object} value the value to set as. or false on reset?
19335 setFromData : function(o){
19336 var dv = ''; // display value
19337 var vv = ''; // value value..
19339 if (this.displayField) {
19340 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
19342 // this is an error condition!!!
19343 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
19346 if(this.valueField){
19347 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
19349 if(this.hiddenField){
19350 this.hiddenField.value = vv;
19352 this.lastSelectionText = dv;
19353 Roo.form.ComboBox.superclass.setValue.call(this, dv);
19357 // no hidden field.. - we store the value in 'value', but still display
19358 // display field!!!!
19359 this.lastSelectionText = dv;
19360 Roo.form.ComboBox.superclass.setValue.call(this, dv);
19366 reset : function(){
19367 // overridden so that last data is reset..
19368 this.setValue(this.resetValue);
19369 this.originalValue = this.getValue();
19370 this.clearInvalid();
19371 this.lastData = false;
19373 this.view.clearSelections();
19377 findRecord : function(prop, value){
19379 if(this.store.getCount() > 0){
19380 this.store.each(function(r){
19381 if(r.data[prop] == value){
19391 getName: function()
19393 // returns hidden if it's set..
19394 if (!this.rendered) {return ''};
19395 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
19399 onViewMove : function(e, t){
19400 this.inKeyMode = false;
19404 onViewOver : function(e, t){
19405 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
19408 var item = this.view.findItemFromChild(t);
19410 var index = this.view.indexOf(item);
19411 this.select(index, false);
19416 onViewClick : function(doFocus)
19418 var index = this.view.getSelectedIndexes()[0];
19419 var r = this.store.getAt(index);
19421 this.onSelect(r, index);
19423 if(doFocus !== false && !this.blockFocus){
19429 restrictHeight : function(){
19430 this.innerList.dom.style.height = '';
19431 var inner = this.innerList.dom;
19432 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
19433 this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
19434 this.list.beginUpdate();
19435 this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
19436 this.list.alignTo(this.el, this.listAlign);
19437 this.list.endUpdate();
19441 onEmptyResults : function(){
19446 * Returns true if the dropdown list is expanded, else false.
19448 isExpanded : function(){
19449 return this.list.isVisible();
19453 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
19454 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
19455 * @param {String} value The data value of the item to select
19456 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
19457 * selected item if it is not currently in view (defaults to true)
19458 * @return {Boolean} True if the value matched an item in the list, else false
19460 selectByValue : function(v, scrollIntoView){
19461 if(v !== undefined && v !== null){
19462 var r = this.findRecord(this.valueField || this.displayField, v);
19464 this.select(this.store.indexOf(r), scrollIntoView);
19472 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
19473 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
19474 * @param {Number} index The zero-based index of the list item to select
19475 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
19476 * selected item if it is not currently in view (defaults to true)
19478 select : function(index, scrollIntoView){
19479 this.selectedIndex = index;
19480 this.view.select(index);
19481 if(scrollIntoView !== false){
19482 var el = this.view.getNode(index);
19484 this.innerList.scrollChildIntoView(el, false);
19490 selectNext : function(){
19491 var ct = this.store.getCount();
19493 if(this.selectedIndex == -1){
19495 }else if(this.selectedIndex < ct-1){
19496 this.select(this.selectedIndex+1);
19502 selectPrev : function(){
19503 var ct = this.store.getCount();
19505 if(this.selectedIndex == -1){
19507 }else if(this.selectedIndex != 0){
19508 this.select(this.selectedIndex-1);
19514 onKeyUp : function(e){
19515 if(this.editable !== false && !e.isSpecialKey()){
19516 this.lastKey = e.getKey();
19517 this.dqTask.delay(this.queryDelay);
19522 validateBlur : function(){
19523 return !this.list || !this.list.isVisible();
19527 initQuery : function(){
19528 this.doQuery(this.getRawValue());
19532 doForce : function(){
19533 if(this.el.dom.value.length > 0){
19534 this.el.dom.value =
19535 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
19541 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
19542 * query allowing the query action to be canceled if needed.
19543 * @param {String} query The SQL query to execute
19544 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
19545 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
19546 * saved in the current store (defaults to false)
19548 doQuery : function(q, forceAll){
19549 if(q === undefined || q === null){
19554 forceAll: forceAll,
19558 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
19562 forceAll = qe.forceAll;
19563 if(forceAll === true || (q.length >= this.minChars)){
19564 if(this.lastQuery != q || this.alwaysQuery){
19565 this.lastQuery = q;
19566 if(this.mode == 'local'){
19567 this.selectedIndex = -1;
19569 this.store.clearFilter();
19571 this.store.filter(this.displayField, q);
19575 this.store.baseParams[this.queryParam] = q;
19577 params: this.getParams(q)
19582 this.selectedIndex = -1;
19589 getParams : function(q){
19591 //p[this.queryParam] = q;
19594 p.limit = this.pageSize;
19600 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
19602 collapse : function(){
19603 if(!this.isExpanded()){
19607 Roo.get(document).un('mousedown', this.collapseIf, this);
19608 Roo.get(document).un('mousewheel', this.collapseIf, this);
19609 if (!this.editable) {
19610 Roo.get(document).un('keydown', this.listKeyPress, this);
19612 this.fireEvent('collapse', this);
19616 collapseIf : function(e){
19617 if(!e.within(this.wrap) && !e.within(this.list)){
19623 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
19625 expand : function(){
19626 if(this.isExpanded() || !this.hasFocus){
19629 this.list.alignTo(this.el, this.listAlign);
19631 Roo.get(document).on('mousedown', this.collapseIf, this);
19632 Roo.get(document).on('mousewheel', this.collapseIf, this);
19633 if (!this.editable) {
19634 Roo.get(document).on('keydown', this.listKeyPress, this);
19637 this.fireEvent('expand', this);
19641 // Implements the default empty TriggerField.onTriggerClick function
19642 onTriggerClick : function(){
19646 if(this.isExpanded()){
19648 if (!this.blockFocus) {
19653 this.hasFocus = true;
19654 if(this.triggerAction == 'all') {
19655 this.doQuery(this.allQuery, true);
19657 this.doQuery(this.getRawValue());
19659 if (!this.blockFocus) {
19664 listKeyPress : function(e)
19666 //Roo.log('listkeypress');
19667 // scroll to first matching element based on key pres..
19668 if (e.isSpecialKey()) {
19671 var k = String.fromCharCode(e.getKey()).toUpperCase();
19674 var csel = this.view.getSelectedNodes();
19675 var cselitem = false;
19677 var ix = this.view.indexOf(csel[0]);
19678 cselitem = this.store.getAt(ix);
19679 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
19685 this.store.each(function(v) {
19687 // start at existing selection.
19688 if (cselitem.id == v.id) {
19694 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
19695 match = this.store.indexOf(v);
19700 if (match === false) {
19701 return true; // no more action?
19704 this.view.select(match);
19705 var sn = Roo.get(this.view.getSelectedNodes()[0]);
19706 sn.scrollIntoView(sn.dom.parentNode, false);
19710 * @cfg {Boolean} grow
19714 * @cfg {Number} growMin
19718 * @cfg {Number} growMax
19726 * Copyright(c) 2010-2012, Roo J Solutions Limited
19733 * @class Roo.form.ComboBoxArray
19734 * @extends Roo.form.TextField
19735 * A facebook style adder... for lists of email / people / countries etc...
19736 * pick multiple items from a combo box, and shows each one.
19738 * Fred [x] Brian [x] [Pick another |v]
19741 * For this to work: it needs various extra information
19742 * - normal combo problay has
19744 * + displayField, valueField
19746 * For our purpose...
19749 * If we change from 'extends' to wrapping...
19756 * Create a new ComboBoxArray.
19757 * @param {Object} config Configuration options
19761 Roo.form.ComboBoxArray = function(config)
19765 * @event beforeremove
19766 * Fires before remove the value from the list
19767 * @param {Roo.form.ComboBoxArray} _self This combo box array
19768 * @param {Roo.form.ComboBoxArray.Item} item removed item
19770 'beforeremove' : true,
19773 * Fires when remove the value from the list
19774 * @param {Roo.form.ComboBoxArray} _self This combo box array
19775 * @param {Roo.form.ComboBoxArray.Item} item removed item
19782 Roo.form.ComboBoxArray.superclass.constructor.call(this, config);
19784 this.items = new Roo.util.MixedCollection(false);
19786 // construct the child combo...
19796 Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField,
19799 * @cfg {Roo.form.Combo} combo The combo box that is wrapped
19804 // behavies liek a hiddne field
19805 inputType: 'hidden',
19807 * @cfg {Number} width The width of the box that displays the selected element
19814 * @cfg {String} name The name of the visable items on this form (eg. titles not ids)
19818 * @cfg {String} hiddenName The hidden name of the field, often contains an comma seperated list of names
19820 hiddenName : false,
19823 // private the array of items that are displayed..
19825 // private - the hidden field el.
19827 // private - the filed el..
19830 //validateValue : function() { return true; }, // all values are ok!
19831 //onAddClick: function() { },
19833 onRender : function(ct, position)
19836 // create the standard hidden element
19837 //Roo.form.ComboBoxArray.superclass.onRender.call(this, ct, position);
19840 // give fake names to child combo;
19841 this.combo.hiddenName = this.hiddenName ? (this.hiddenName+'-subcombo') : this.hiddenName;
19842 this.combo.name = this.name ? (this.name+'-subcombo') : this.name;
19844 this.combo = Roo.factory(this.combo, Roo.form);
19845 this.combo.onRender(ct, position);
19846 if (typeof(this.combo.width) != 'undefined') {
19847 this.combo.onResize(this.combo.width,0);
19850 this.combo.initEvents();
19852 // assigned so form know we need to do this..
19853 this.store = this.combo.store;
19854 this.valueField = this.combo.valueField;
19855 this.displayField = this.combo.displayField ;
19858 this.combo.wrap.addClass('x-cbarray-grp');
19860 var cbwrap = this.combo.wrap.createChild(
19861 {tag: 'div', cls: 'x-cbarray-cb'},
19866 this.hiddenEl = this.combo.wrap.createChild({
19867 tag: 'input', type:'hidden' , name: this.hiddenName, value : ''
19869 this.el = this.combo.wrap.createChild({
19870 tag: 'input', type:'hidden' , name: this.name, value : ''
19872 // this.el.dom.removeAttribute("name");
19875 this.outerWrap = this.combo.wrap;
19876 this.wrap = cbwrap;
19878 this.outerWrap.setWidth(this.width);
19879 this.outerWrap.dom.removeChild(this.el.dom);
19881 this.wrap.dom.appendChild(this.el.dom);
19882 this.outerWrap.dom.removeChild(this.combo.trigger.dom);
19883 this.combo.wrap.dom.appendChild(this.combo.trigger.dom);
19885 this.combo.trigger.setStyle('position','relative');
19886 this.combo.trigger.setStyle('left', '0px');
19887 this.combo.trigger.setStyle('top', '2px');
19889 this.combo.el.setStyle('vertical-align', 'text-bottom');
19891 //this.trigger.setStyle('vertical-align', 'top');
19893 // this should use the code from combo really... on('add' ....)
19897 this.adder = this.outerWrap.createChild(
19898 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-adder', style: 'margin-left:2px'});
19900 this.adder.on('click', function(e) {
19901 _t.fireEvent('adderclick', this, e);
19905 //this.adder.on('click', this.onAddClick, _t);
19908 this.combo.on('select', function(cb, rec, ix) {
19909 this.addItem(rec.data);
19912 cb.el.dom.value = '';
19913 //cb.lastData = rec.data;
19922 getName: function()
19924 // returns hidden if it's set..
19925 if (!this.rendered) {return ''};
19926 return this.hiddenName ? this.hiddenName : this.name;
19931 onResize: function(w, h){
19934 // not sure if this is needed..
19935 //this.combo.onResize(w,h);
19937 if(typeof w != 'number'){
19938 // we do not handle it!?!?
19941 var tw = this.combo.trigger.getWidth();
19942 tw += this.addicon ? this.addicon.getWidth() : 0;
19943 tw += this.editicon ? this.editicon.getWidth() : 0;
19945 this.combo.el.setWidth( this.combo.adjustWidth('input', x));
19947 this.combo.trigger.setStyle('left', '0px');
19949 if(this.list && this.listWidth === undefined){
19950 var lw = Math.max(x + this.combo.trigger.getWidth(), this.combo.minListWidth);
19951 this.list.setWidth(lw);
19952 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
19959 addItem: function(rec)
19961 var valueField = this.combo.valueField;
19962 var displayField = this.combo.displayField;
19964 if (this.items.indexOfKey(rec[valueField]) > -1) {
19965 //console.log("GOT " + rec.data.id);
19969 var x = new Roo.form.ComboBoxArray.Item({
19970 //id : rec[this.idField],
19972 displayField : displayField ,
19973 tipField : displayField ,
19977 this.items.add(rec[valueField],x);
19978 // add it before the element..
19979 this.updateHiddenEl();
19980 x.render(this.outerWrap, this.wrap.dom);
19981 // add the image handler..
19984 updateHiddenEl : function()
19987 if (!this.hiddenEl) {
19991 var idField = this.combo.valueField;
19993 this.items.each(function(f) {
19994 ar.push(f.data[idField]);
19996 this.hiddenEl.dom.value = ar.join(',');
20002 this.items.clear();
20004 Roo.each(this.outerWrap.select('.x-cbarray-item', true).elements, function(el){
20008 this.el.dom.value = '';
20009 if (this.hiddenEl) {
20010 this.hiddenEl.dom.value = '';
20014 getValue: function()
20016 return this.hiddenEl ? this.hiddenEl.dom.value : '';
20018 setValue: function(v) // not a valid action - must use addItems..
20023 if (this.store.isLocal && (typeof(v) == 'string')) {
20024 // then we can use the store to find the values..
20025 // comma seperated at present.. this needs to allow JSON based encoding..
20026 this.hiddenEl.value = v;
20028 Roo.each(v.split(','), function(k) {
20029 Roo.log("CHECK " + this.valueField + ',' + k);
20030 var li = this.store.query(this.valueField, k);
20035 add[this.valueField] = k;
20036 add[this.displayField] = li.item(0).data[this.displayField];
20042 if (typeof(v) == 'object' ) {
20043 // then let's assume it's an array of objects..
20044 Roo.each(v, function(l) {
20052 setFromData: function(v)
20054 // this recieves an object, if setValues is called.
20056 this.el.dom.value = v[this.displayField];
20057 this.hiddenEl.dom.value = v[this.valueField];
20058 if (typeof(v[this.valueField]) != 'string' || !v[this.valueField].length) {
20061 var kv = v[this.valueField];
20062 var dv = v[this.displayField];
20063 kv = typeof(kv) != 'string' ? '' : kv;
20064 dv = typeof(dv) != 'string' ? '' : dv;
20067 var keys = kv.split(',');
20068 var display = dv.split(',');
20069 for (var i = 0 ; i < keys.length; i++) {
20072 add[this.valueField] = keys[i];
20073 add[this.displayField] = display[i];
20081 * Validates the combox array value
20082 * @return {Boolean} True if the value is valid, else false
20084 validate : function(){
20085 if(this.disabled || this.validateValue(this.processValue(this.getValue()))){
20086 this.clearInvalid();
20092 validateValue : function(value){
20093 return Roo.form.ComboBoxArray.superclass.validateValue.call(this, this.getValue());
20101 isDirty : function() {
20102 if(this.disabled) {
20107 var d = Roo.decode(String(this.originalValue));
20109 return String(this.getValue()) !== String(this.originalValue);
20112 var originalValue = [];
20114 for (var i = 0; i < d.length; i++){
20115 originalValue.push(d[i][this.valueField]);
20118 return String(this.getValue()) !== String(originalValue.join(','));
20127 * @class Roo.form.ComboBoxArray.Item
20128 * @extends Roo.BoxComponent
20129 * A selected item in the list
20130 * Fred [x] Brian [x] [Pick another |v]
20133 * Create a new item.
20134 * @param {Object} config Configuration options
20137 Roo.form.ComboBoxArray.Item = function(config) {
20138 config.id = Roo.id();
20139 Roo.form.ComboBoxArray.Item.superclass.constructor.call(this, config);
20142 Roo.extend(Roo.form.ComboBoxArray.Item, Roo.BoxComponent, {
20145 displayField : false,
20149 defaultAutoCreate : {
20151 cls: 'x-cbarray-item',
20158 src : Roo.BLANK_IMAGE_URL ,
20166 onRender : function(ct, position)
20168 Roo.form.Field.superclass.onRender.call(this, ct, position);
20171 var cfg = this.getAutoCreate();
20172 this.el = ct.createChild(cfg, position);
20175 this.el.child('img').dom.setAttribute('src', Roo.BLANK_IMAGE_URL);
20177 this.el.child('div').dom.innerHTML = this.cb.renderer ?
20178 this.cb.renderer(this.data) :
20179 String.format('{0}',this.data[this.displayField]);
20182 this.el.child('div').dom.setAttribute('qtip',
20183 String.format('{0}',this.data[this.tipField])
20186 this.el.child('img').on('click', this.remove, this);
20190 remove : function()
20192 if(this.cb.disabled){
20196 if(false !== this.cb.fireEvent('beforeremove', this.cb, this)){
20197 this.cb.items.remove(this);
20198 this.el.child('img').un('click', this.remove, this);
20200 this.cb.updateHiddenEl();
20202 this.cb.fireEvent('remove', this.cb, this);
20207 * RooJS Library 1.1.1
20208 * Copyright(c) 2008-2011 Alan Knowles
20215 * @class Roo.form.ComboNested
20216 * @extends Roo.form.ComboBox
20217 * A combobox for that allows selection of nested items in a list,
20232 * Create a new ComboNested
20233 * @param {Object} config Configuration options
20235 Roo.form.ComboNested = function(config){
20236 Roo.form.ComboCheck.superclass.constructor.call(this, config);
20237 // should verify some data...
20239 // hiddenName = required..
20240 // displayField = required
20241 // valudField == required
20242 var req= [ 'hiddenName', 'displayField', 'valueField' ];
20244 Roo.each(req, function(e) {
20245 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
20246 throw "Roo.form.ComboNested : missing value for: " + e;
20253 Roo.extend(Roo.form.ComboNested, Roo.form.ComboBox, {
20256 * @config {Number} max Number of columns to show
20261 list : null, // the outermost div..
20262 innerLists : null, // the
20266 onRender : function(ct, position)
20268 Roo.form.ComboBox.superclass.onRender.call(this, ct, position); // skip parent call - got to above..
20270 if(this.hiddenName){
20271 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
20273 this.hiddenField.value =
20274 this.hiddenValue !== undefined ? this.hiddenValue :
20275 this.value !== undefined ? this.value : '';
20277 // prevent input submission
20278 this.el.dom.removeAttribute('name');
20284 this.el.dom.setAttribute('autocomplete', 'off');
20287 var cls = 'x-combo-list';
20289 this.list = new Roo.Layer({
20290 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
20293 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
20294 this.list.setWidth(lw);
20295 this.list.swallowEvent('mousewheel');
20296 this.assetHeight = 0;
20299 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
20300 this.assetHeight += this.header.getHeight();
20302 this.innerLists = [];
20305 for (var i =0 ; i < this.maxColumns; i++) {
20306 this.onRenderList( cls, i);
20309 // always needs footer, as we are going to have an 'OK' button.
20310 this.footer = this.list.createChild({cls:cls+'-ft'});
20311 this.pageTb = new Roo.Toolbar(this.footer);
20316 handler: function()
20322 if ( this.allowBlank && !this.disableClear) {
20324 this.pageTb.add(new Roo.Toolbar.Fill(), {
20325 cls: 'x-btn-icon x-btn-clear',
20327 handler: function()
20330 _this.clearValue();
20331 _this.onSelect(false, -1);
20336 this.assetHeight += this.footer.getHeight();
20340 onRenderList : function ( cls, i)
20343 var lw = Math.floor(
20344 ((this.listWidth * this.maxColumns || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / this.maxColumns
20347 this.list.setWidth(lw); // default to '1'
20349 var il = this.innerLists[i] = this.list.createChild({cls:cls+'-inner'});
20350 //il.on('mouseover', this.onViewOver, this, { list: i });
20351 //il.on('mousemove', this.onViewMove, this, { list: i });
20353 il.setStyle({ 'overflow-x' : 'hidden'});
20356 this.tpl = new Roo.Template({
20357 html : '<div class="'+cls+'-item '+cls+'-item-{cn:this.isEmpty}">{' + this.displayField + '}</div>',
20358 isEmpty: function (value, allValues) {
20360 var dl = typeof(value.data) != 'undefined' ? value.data.length : value.length; ///json is a nested response..
20361 return dl ? 'has-children' : 'no-children'
20366 var store = this.store;
20368 store = new Roo.data.SimpleStore({
20369 //fields : this.store.reader.meta.fields,
20370 reader : this.store.reader,
20374 this.stores[i] = store;
20378 var view = this.views[i] = new Roo.View(
20384 selectedClass: this.selectedClass
20387 view.getEl().setWidth(lw);
20388 view.getEl().setStyle({
20389 position: i < 1 ? 'relative' : 'absolute',
20391 left: (i * lw ) + 'px',
20392 display : i > 0 ? 'none' : 'block'
20394 view.on('selectionchange', this.onSelectChange, this, {list : i });
20395 view.on('dblclick', this.onDoubleClick, this, {list : i });
20396 //view.on('click', this.onViewClick, this, { list : i });
20398 store.on('beforeload', this.onBeforeLoad, this);
20399 store.on('load', this.onLoad, this, { list : i});
20400 store.on('loadexception', this.onLoadException, this);
20402 // hide the other vies..
20407 onResize : function() {},
20409 restrictHeight : function()
20412 Roo.each(this.innerLists, function(il,i) {
20413 var el = this.views[i].getEl();
20414 el.dom.style.height = '';
20415 var inner = el.dom;
20416 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
20417 // only adjust heights on other ones..
20420 el.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
20421 il.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
20422 mh = Math.max(el.getHeight(), mh);
20428 this.list.beginUpdate();
20429 this.list.setHeight(mh+this.list.getFrameWidth('tb')+this.assetHeight);
20430 this.list.alignTo(this.el, this.listAlign);
20431 this.list.endUpdate();
20436 // -- store handlers..
20438 onBeforeLoad : function()
20440 if(!this.hasFocus){
20443 this.innerLists[0].update(this.loadingText ?
20444 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
20445 this.restrictHeight();
20446 this.selectedIndex = -1;
20449 onLoad : function(a,b,c,d)
20452 if(!this.hasFocus){
20456 if(this.store.getCount() > 0) {
20458 this.restrictHeight();
20460 this.onEmptyResults();
20463 this.stores[1].loadData([]);
20464 this.stores[2].loadData([]);
20473 onLoadException : function()
20476 Roo.log(this.store.reader.jsonData);
20477 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
20478 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
20486 onSelectChange : function (view, sels, opts )
20488 var ix = view.getSelectedIndexes();
20491 if (opts.list > this.maxColumns - 2) {
20493 this.setFromData(ix.length ? view.store.getAt(ix[0]).data : {});
20498 this.setFromData({});
20499 var str = this.stores[opts.list+1];
20504 var rec = view.store.getAt(ix[0]);
20505 this.setFromData(rec.data);
20507 var lw = Math.floor(
20508 ((this.listWidth * this.maxColumns || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / this.maxColumns
20510 var data = typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
20511 var dl = typeof(data.data) != 'undefined' ? data.total : data.length; ///json is a nested response..
20512 this.stores[opts.list+1].loadData( data );
20513 this.views[opts.list+1].getEl().setHeight( this.innerLists[0].getHeight());
20514 this.views[opts.list+1].getEl().setStyle({ display : dl ? 'block' : 'none' });
20515 this.innerLists[opts.list+1].setHeight( this.innerLists[0].getHeight());
20516 this.list.setWidth(lw * (opts.list + (dl ? 2 : 1)));
20518 onDoubleClick : function()
20520 this.collapse(); //??
20525 findRecord : function (prop,value)
20527 return this.findRecordInStore(this.store, prop,value);
20531 findRecordInStore : function(store, prop, value)
20533 var cstore = new Roo.data.SimpleStore({
20534 //fields : this.store.reader.meta.fields, // we need array reader.. for
20535 reader : this.store.reader,
20539 var record = false;
20540 if(store.getCount() > 0){
20541 store.each(function(r){
20542 if(r.data[prop] == value){
20546 if (r.data.cn && r.data.cn.length) {
20547 cstore.loadData( r.data.cn);
20548 var cret = _this.findRecordInStore(cstore, prop, value);
20549 if (cret !== false) {
20566 * Ext JS Library 1.1.1
20567 * Copyright(c) 2006-2007, Ext JS, LLC.
20569 * Originally Released Under LGPL - original licence link has changed is not relivant.
20572 * <script type="text/javascript">
20575 * @class Roo.form.Checkbox
20576 * @extends Roo.form.Field
20577 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
20579 * Creates a new Checkbox
20580 * @param {Object} config Configuration options
20582 Roo.form.Checkbox = function(config){
20583 Roo.form.Checkbox.superclass.constructor.call(this, config);
20587 * Fires when the checkbox is checked or unchecked.
20588 * @param {Roo.form.Checkbox} this This checkbox
20589 * @param {Boolean} checked The new checked value
20595 Roo.extend(Roo.form.Checkbox, Roo.form.Field, {
20597 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
20599 focusClass : undefined,
20601 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
20603 fieldClass: "x-form-field",
20605 * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
20609 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
20610 * {tag: "input", type: "checkbox", autocomplete: "off"})
20612 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
20614 * @cfg {String} boxLabel The text that appears beside the checkbox
20618 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
20622 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20624 valueOff: '0', // value when not checked..
20626 actionMode : 'viewEl',
20629 itemCls : 'x-menu-check-item x-form-item',
20630 groupClass : 'x-menu-group-item',
20631 inputType : 'hidden',
20634 inSetChecked: false, // check that we are not calling self...
20636 inputElement: false, // real input element?
20637 basedOn: false, // ????
20639 isFormField: true, // not sure where this is needed!!!!
20641 onResize : function(){
20642 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
20643 if(!this.boxLabel){
20644 this.el.alignTo(this.wrap, 'c-c');
20648 initEvents : function(){
20649 Roo.form.Checkbox.superclass.initEvents.call(this);
20650 this.el.on("click", this.onClick, this);
20651 this.el.on("change", this.onClick, this);
20655 getResizeEl : function(){
20659 getPositionEl : function(){
20664 onRender : function(ct, position){
20665 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
20667 if(this.inputValue !== undefined){
20668 this.el.dom.value = this.inputValue;
20671 //this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
20672 this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
20673 var viewEl = this.wrap.createChild({
20674 tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
20675 this.viewEl = viewEl;
20676 this.wrap.on('click', this.onClick, this);
20678 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
20679 this.el.on('propertychange', this.setFromHidden, this); //ie
20684 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
20685 // viewEl.on('click', this.onClick, this);
20687 //if(this.checked){
20688 this.setChecked(this.checked);
20690 //this.checked = this.el.dom;
20696 initValue : Roo.emptyFn,
20699 * Returns the checked state of the checkbox.
20700 * @return {Boolean} True if checked, else false
20702 getValue : function(){
20704 return String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
20706 return this.valueOff;
20711 onClick : function(){
20712 if (this.disabled) {
20715 this.setChecked(!this.checked);
20717 //if(this.el.dom.checked != this.checked){
20718 // this.setValue(this.el.dom.checked);
20723 * Sets the checked state of the checkbox.
20724 * On is always based on a string comparison between inputValue and the param.
20725 * @param {Boolean/String} value - the value to set
20726 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
20728 setValue : function(v,suppressEvent){
20731 //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
20732 //if(this.el && this.el.dom){
20733 // this.el.dom.checked = this.checked;
20734 // this.el.dom.defaultChecked = this.checked;
20736 this.setChecked(String(v) === String(this.inputValue), suppressEvent);
20737 //this.fireEvent("check", this, this.checked);
20740 setChecked : function(state,suppressEvent)
20742 if (this.inSetChecked) {
20743 this.checked = state;
20749 this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked');
20751 this.checked = state;
20752 if(suppressEvent !== true){
20753 this.fireEvent('check', this, state);
20755 this.inSetChecked = true;
20756 this.el.dom.value = state ? this.inputValue : this.valueOff;
20757 this.inSetChecked = false;
20760 // handle setting of hidden value by some other method!!?!?
20761 setFromHidden: function()
20766 //console.log("SET FROM HIDDEN");
20767 //alert('setFrom hidden');
20768 this.setValue(this.el.dom.value);
20771 onDestroy : function()
20774 Roo.get(this.viewEl).remove();
20777 Roo.form.Checkbox.superclass.onDestroy.call(this);
20780 setBoxLabel : function(str)
20782 this.wrap.select('.x-form-cb-label', true).first().dom.innerHTML = str;
20787 * Ext JS Library 1.1.1
20788 * Copyright(c) 2006-2007, Ext JS, LLC.
20790 * Originally Released Under LGPL - original licence link has changed is not relivant.
20793 * <script type="text/javascript">
20797 * @class Roo.form.Radio
20798 * @extends Roo.form.Checkbox
20799 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
20800 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
20802 * Creates a new Radio
20803 * @param {Object} config Configuration options
20805 Roo.form.Radio = function(){
20806 Roo.form.Radio.superclass.constructor.apply(this, arguments);
20808 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
20809 inputType: 'radio',
20812 * If this radio is part of a group, it will return the selected value
20815 getGroupValue : function(){
20816 return this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
20820 onRender : function(ct, position){
20821 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
20823 if(this.inputValue !== undefined){
20824 this.el.dom.value = this.inputValue;
20827 this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
20828 //this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
20829 //var viewEl = this.wrap.createChild({
20830 // tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
20831 //this.viewEl = viewEl;
20832 //this.wrap.on('click', this.onClick, this);
20834 //this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
20835 //this.el.on('propertychange', this.setFromHidden, this); //ie
20840 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
20841 // viewEl.on('click', this.onClick, this);
20844 this.el.dom.checked = 'checked' ;
20850 });//<script type="text/javascript">
20853 * Based Ext JS Library 1.1.1
20854 * Copyright(c) 2006-2007, Ext JS, LLC.
20860 * @class Roo.HtmlEditorCore
20861 * @extends Roo.Component
20862 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
20864 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
20867 Roo.HtmlEditorCore = function(config){
20870 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
20875 * @event initialize
20876 * Fires when the editor is fully initialized (including the iframe)
20877 * @param {Roo.HtmlEditorCore} this
20882 * Fires when the editor is first receives the focus. Any insertion must wait
20883 * until after this event.
20884 * @param {Roo.HtmlEditorCore} this
20888 * @event beforesync
20889 * Fires before the textarea is updated with content from the editor iframe. Return false
20890 * to cancel the sync.
20891 * @param {Roo.HtmlEditorCore} this
20892 * @param {String} html
20896 * @event beforepush
20897 * Fires before the iframe editor is updated with content from the textarea. Return false
20898 * to cancel the push.
20899 * @param {Roo.HtmlEditorCore} this
20900 * @param {String} html
20905 * Fires when the textarea is updated with content from the editor iframe.
20906 * @param {Roo.HtmlEditorCore} this
20907 * @param {String} html
20912 * Fires when the iframe editor is updated with content from the textarea.
20913 * @param {Roo.HtmlEditorCore} this
20914 * @param {String} html
20919 * @event editorevent
20920 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
20921 * @param {Roo.HtmlEditorCore} this
20927 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
20929 // defaults : white / black...
20930 this.applyBlacklists();
20937 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
20941 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
20947 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
20952 * @cfg {Number} height (in pixels)
20956 * @cfg {Number} width (in pixels)
20961 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
20964 stylesheets: false,
20969 // private properties
20970 validationEvent : false,
20972 initialized : false,
20974 sourceEditMode : false,
20975 onFocus : Roo.emptyFn,
20977 hideMode:'offsets',
20981 // blacklist + whitelisted elements..
20988 * Protected method that will not generally be called directly. It
20989 * is called when the editor initializes the iframe with HTML contents. Override this method if you
20990 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
20992 getDocMarkup : function(){
20996 // inherit styels from page...??
20997 if (this.stylesheets === false) {
20999 Roo.get(document.head).select('style').each(function(node) {
21000 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21003 Roo.get(document.head).select('link').each(function(node) {
21004 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21007 } else if (!this.stylesheets.length) {
21009 st = '<style type="text/css">' +
21010 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21013 st = '<style type="text/css">' +
21018 st += '<style type="text/css">' +
21019 'IMG { cursor: pointer } ' +
21022 var cls = 'roo-htmleditor-body';
21024 if(this.bodyCls.length){
21025 cls += ' ' + this.bodyCls;
21028 return '<html><head>' + st +
21029 //<style type="text/css">' +
21030 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21032 ' </head><body class="' + cls + '"></body></html>';
21036 onRender : function(ct, position)
21039 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21040 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21043 this.el.dom.style.border = '0 none';
21044 this.el.dom.setAttribute('tabIndex', -1);
21045 this.el.addClass('x-hidden hide');
21049 if(Roo.isIE){ // fix IE 1px bogus margin
21050 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21054 this.frameId = Roo.id();
21058 var iframe = this.owner.wrap.createChild({
21060 cls: 'form-control', // bootstrap..
21062 name: this.frameId,
21063 frameBorder : 'no',
21064 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21069 this.iframe = iframe.dom;
21071 this.assignDocWin();
21073 this.doc.designMode = 'on';
21076 this.doc.write(this.getDocMarkup());
21080 var task = { // must defer to wait for browser to be ready
21082 //console.log("run task?" + this.doc.readyState);
21083 this.assignDocWin();
21084 if(this.doc.body || this.doc.readyState == 'complete'){
21086 this.doc.designMode="on";
21090 Roo.TaskMgr.stop(task);
21091 this.initEditor.defer(10, this);
21098 Roo.TaskMgr.start(task);
21103 onResize : function(w, h)
21105 Roo.log('resize: ' +w + ',' + h );
21106 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21110 if(typeof w == 'number'){
21112 this.iframe.style.width = w + 'px';
21114 if(typeof h == 'number'){
21116 this.iframe.style.height = h + 'px';
21118 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21125 * Toggles the editor between standard and source edit mode.
21126 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21128 toggleSourceEdit : function(sourceEditMode){
21130 this.sourceEditMode = sourceEditMode === true;
21132 if(this.sourceEditMode){
21134 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21137 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21138 //this.iframe.className = '';
21141 //this.setSize(this.owner.wrap.getSize());
21142 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21149 * Protected method that will not generally be called directly. If you need/want
21150 * custom HTML cleanup, this is the method you should override.
21151 * @param {String} html The HTML to be cleaned
21152 * return {String} The cleaned HTML
21154 cleanHtml : function(html){
21155 html = String(html);
21156 if(html.length > 5){
21157 if(Roo.isSafari){ // strip safari nonsense
21158 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21161 if(html == ' '){
21168 * HTML Editor -> Textarea
21169 * Protected method that will not generally be called directly. Syncs the contents
21170 * of the editor iframe with the textarea.
21172 syncValue : function(){
21173 if(this.initialized){
21174 var bd = (this.doc.body || this.doc.documentElement);
21175 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21176 var html = bd.innerHTML;
21178 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21179 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
21181 html = '<div style="'+m[0]+'">' + html + '</div>';
21184 html = this.cleanHtml(html);
21185 // fix up the special chars.. normaly like back quotes in word...
21186 // however we do not want to do this with chinese..
21187 html = html.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g, function(match) {
21189 var cc = match.charCodeAt();
21191 // Get the character value, handling surrogate pairs
21192 if (match.length == 2) {
21193 // It's a surrogate pair, calculate the Unicode code point
21194 var high = match.charCodeAt(0) - 0xD800;
21195 var low = match.charCodeAt(1) - 0xDC00;
21196 cc = (high * 0x400) + low + 0x10000;
21198 (cc >= 0x4E00 && cc < 0xA000 ) ||
21199 (cc >= 0x3400 && cc < 0x4E00 ) ||
21200 (cc >= 0xf900 && cc < 0xfb00 )
21205 // No, use a numeric entity. Here we brazenly (and possibly mistakenly)
21206 return "&#" + cc + ";";
21213 if(this.owner.fireEvent('beforesync', this, html) !== false){
21214 this.el.dom.value = html;
21215 this.owner.fireEvent('sync', this, html);
21221 * Protected method that will not generally be called directly. Pushes the value of the textarea
21222 * into the iframe editor.
21224 pushValue : function(){
21225 if(this.initialized){
21226 var v = this.el.dom.value.trim();
21228 // if(v.length < 1){
21232 if(this.owner.fireEvent('beforepush', this, v) !== false){
21233 var d = (this.doc.body || this.doc.documentElement);
21235 this.cleanUpPaste();
21236 this.el.dom.value = d.innerHTML;
21237 this.owner.fireEvent('push', this, v);
21243 deferFocus : function(){
21244 this.focus.defer(10, this);
21248 focus : function(){
21249 if(this.win && !this.sourceEditMode){
21256 assignDocWin: function()
21258 var iframe = this.iframe;
21261 this.doc = iframe.contentWindow.document;
21262 this.win = iframe.contentWindow;
21264 // if (!Roo.get(this.frameId)) {
21267 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21268 // this.win = Roo.get(this.frameId).dom.contentWindow;
21270 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
21274 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21275 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
21280 initEditor : function(){
21281 //console.log("INIT EDITOR");
21282 this.assignDocWin();
21286 this.doc.designMode="on";
21288 this.doc.write(this.getDocMarkup());
21291 var dbody = (this.doc.body || this.doc.documentElement);
21292 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
21293 // this copies styles from the containing element into thsi one..
21294 // not sure why we need all of this..
21295 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
21297 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
21298 //ss['background-attachment'] = 'fixed'; // w3c
21299 dbody.bgProperties = 'fixed'; // ie
21300 //Roo.DomHelper.applyStyles(dbody, ss);
21301 Roo.EventManager.on(this.doc, {
21302 //'mousedown': this.onEditorEvent,
21303 'mouseup': this.onEditorEvent,
21304 'dblclick': this.onEditorEvent,
21305 'click': this.onEditorEvent,
21306 'keyup': this.onEditorEvent,
21311 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
21313 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
21314 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
21316 this.initialized = true;
21318 this.owner.fireEvent('initialize', this);
21323 onDestroy : function(){
21329 //for (var i =0; i < this.toolbars.length;i++) {
21330 // // fixme - ask toolbars for heights?
21331 // this.toolbars[i].onDestroy();
21334 //this.wrap.dom.innerHTML = '';
21335 //this.wrap.remove();
21340 onFirstFocus : function(){
21342 this.assignDocWin();
21345 this.activated = true;
21348 if(Roo.isGecko){ // prevent silly gecko errors
21350 var s = this.win.getSelection();
21351 if(!s.focusNode || s.focusNode.nodeType != 3){
21352 var r = s.getRangeAt(0);
21353 r.selectNodeContents((this.doc.body || this.doc.documentElement));
21358 this.execCmd('useCSS', true);
21359 this.execCmd('styleWithCSS', false);
21362 this.owner.fireEvent('activate', this);
21366 adjustFont: function(btn){
21367 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
21368 //if(Roo.isSafari){ // safari
21371 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
21372 if(Roo.isSafari){ // safari
21373 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
21374 v = (v < 10) ? 10 : v;
21375 v = (v > 48) ? 48 : v;
21376 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
21381 v = Math.max(1, v+adjust);
21383 this.execCmd('FontSize', v );
21386 onEditorEvent : function(e)
21388 this.owner.fireEvent('editorevent', this, e);
21389 // this.updateToolbar();
21390 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
21393 insertTag : function(tg)
21395 // could be a bit smarter... -> wrap the current selected tRoo..
21396 if (tg.toLowerCase() == 'span' ||
21397 tg.toLowerCase() == 'code' ||
21398 tg.toLowerCase() == 'sup' ||
21399 tg.toLowerCase() == 'sub'
21402 range = this.createRange(this.getSelection());
21403 var wrappingNode = this.doc.createElement(tg.toLowerCase());
21404 wrappingNode.appendChild(range.extractContents());
21405 range.insertNode(wrappingNode);
21412 this.execCmd("formatblock", tg);
21416 insertText : function(txt)
21420 var range = this.createRange();
21421 range.deleteContents();
21422 //alert(Sender.getAttribute('label'));
21424 range.insertNode(this.doc.createTextNode(txt));
21430 * Executes a Midas editor command on the editor document and performs necessary focus and
21431 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
21432 * @param {String} cmd The Midas command
21433 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21435 relayCmd : function(cmd, value){
21437 this.execCmd(cmd, value);
21438 this.owner.fireEvent('editorevent', this);
21439 //this.updateToolbar();
21440 this.owner.deferFocus();
21444 * Executes a Midas editor command directly on the editor document.
21445 * For visual commands, you should use {@link #relayCmd} instead.
21446 * <b>This should only be called after the editor is initialized.</b>
21447 * @param {String} cmd The Midas command
21448 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21450 execCmd : function(cmd, value){
21451 this.doc.execCommand(cmd, false, value === undefined ? null : value);
21458 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
21460 * @param {String} text | dom node..
21462 insertAtCursor : function(text)
21465 if(!this.activated){
21471 var r = this.doc.selection.createRange();
21482 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
21486 // from jquery ui (MIT licenced)
21488 var win = this.win;
21490 if (win.getSelection && win.getSelection().getRangeAt) {
21491 range = win.getSelection().getRangeAt(0);
21492 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
21493 range.insertNode(node);
21494 } else if (win.document.selection && win.document.selection.createRange) {
21495 // no firefox support
21496 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21497 win.document.selection.createRange().pasteHTML(txt);
21499 // no firefox support
21500 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21501 this.execCmd('InsertHTML', txt);
21510 mozKeyPress : function(e){
21512 var c = e.getCharCode(), cmd;
21515 c = String.fromCharCode(c).toLowerCase();
21529 this.cleanUpPaste.defer(100, this);
21537 e.preventDefault();
21545 fixKeys : function(){ // load time branching for fastest keydown performance
21547 return function(e){
21548 var k = e.getKey(), r;
21551 r = this.doc.selection.createRange();
21554 r.pasteHTML('    ');
21561 r = this.doc.selection.createRange();
21563 var target = r.parentElement();
21564 if(!target || target.tagName.toLowerCase() != 'li'){
21566 r.pasteHTML('<br />');
21572 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21573 this.cleanUpPaste.defer(100, this);
21579 }else if(Roo.isOpera){
21580 return function(e){
21581 var k = e.getKey();
21585 this.execCmd('InsertHTML','    ');
21588 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21589 this.cleanUpPaste.defer(100, this);
21594 }else if(Roo.isSafari){
21595 return function(e){
21596 var k = e.getKey();
21600 this.execCmd('InsertText','\t');
21604 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21605 this.cleanUpPaste.defer(100, this);
21613 getAllAncestors: function()
21615 var p = this.getSelectedNode();
21618 a.push(p); // push blank onto stack..
21619 p = this.getParentElement();
21623 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
21627 a.push(this.doc.body);
21631 lastSelNode : false,
21634 getSelection : function()
21636 this.assignDocWin();
21637 return Roo.isIE ? this.doc.selection : this.win.getSelection();
21640 getSelectedNode: function()
21642 // this may only work on Gecko!!!
21644 // should we cache this!!!!
21649 var range = this.createRange(this.getSelection()).cloneRange();
21652 var parent = range.parentElement();
21654 var testRange = range.duplicate();
21655 testRange.moveToElementText(parent);
21656 if (testRange.inRange(range)) {
21659 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
21662 parent = parent.parentElement;
21667 // is ancestor a text element.
21668 var ac = range.commonAncestorContainer;
21669 if (ac.nodeType == 3) {
21670 ac = ac.parentNode;
21673 var ar = ac.childNodes;
21676 var other_nodes = [];
21677 var has_other_nodes = false;
21678 for (var i=0;i<ar.length;i++) {
21679 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
21682 // fullly contained node.
21684 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
21689 // probably selected..
21690 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
21691 other_nodes.push(ar[i]);
21695 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
21700 has_other_nodes = true;
21702 if (!nodes.length && other_nodes.length) {
21703 nodes= other_nodes;
21705 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
21711 createRange: function(sel)
21713 // this has strange effects when using with
21714 // top toolbar - not sure if it's a great idea.
21715 //this.editor.contentWindow.focus();
21716 if (typeof sel != "undefined") {
21718 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
21720 return this.doc.createRange();
21723 return this.doc.createRange();
21726 getParentElement: function()
21729 this.assignDocWin();
21730 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
21732 var range = this.createRange(sel);
21735 var p = range.commonAncestorContainer;
21736 while (p.nodeType == 3) { // text node
21747 * Range intersection.. the hard stuff...
21751 * [ -- selected range --- ]
21755 * if end is before start or hits it. fail.
21756 * if start is after end or hits it fail.
21758 * if either hits (but other is outside. - then it's not
21764 // @see http://www.thismuchiknow.co.uk/?p=64.
21765 rangeIntersectsNode : function(range, node)
21767 var nodeRange = node.ownerDocument.createRange();
21769 nodeRange.selectNode(node);
21771 nodeRange.selectNodeContents(node);
21774 var rangeStartRange = range.cloneRange();
21775 rangeStartRange.collapse(true);
21777 var rangeEndRange = range.cloneRange();
21778 rangeEndRange.collapse(false);
21780 var nodeStartRange = nodeRange.cloneRange();
21781 nodeStartRange.collapse(true);
21783 var nodeEndRange = nodeRange.cloneRange();
21784 nodeEndRange.collapse(false);
21786 return rangeStartRange.compareBoundaryPoints(
21787 Range.START_TO_START, nodeEndRange) == -1 &&
21788 rangeEndRange.compareBoundaryPoints(
21789 Range.START_TO_START, nodeStartRange) == 1;
21793 rangeCompareNode : function(range, node)
21795 var nodeRange = node.ownerDocument.createRange();
21797 nodeRange.selectNode(node);
21799 nodeRange.selectNodeContents(node);
21803 range.collapse(true);
21805 nodeRange.collapse(true);
21807 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
21808 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
21810 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
21812 var nodeIsBefore = ss == 1;
21813 var nodeIsAfter = ee == -1;
21815 if (nodeIsBefore && nodeIsAfter) {
21818 if (!nodeIsBefore && nodeIsAfter) {
21819 return 1; //right trailed.
21822 if (nodeIsBefore && !nodeIsAfter) {
21823 return 2; // left trailed.
21829 // private? - in a new class?
21830 cleanUpPaste : function()
21832 // cleans up the whole document..
21833 Roo.log('cleanuppaste');
21835 this.cleanUpChildren(this.doc.body);
21836 var clean = this.cleanWordChars(this.doc.body.innerHTML);
21837 if (clean != this.doc.body.innerHTML) {
21838 this.doc.body.innerHTML = clean;
21843 cleanWordChars : function(input) {// change the chars to hex code
21844 var he = Roo.HtmlEditorCore;
21846 var output = input;
21847 Roo.each(he.swapCodes, function(sw) {
21848 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
21850 output = output.replace(swapper, sw[1]);
21857 cleanUpChildren : function (n)
21859 if (!n.childNodes.length) {
21862 for (var i = n.childNodes.length-1; i > -1 ; i--) {
21863 this.cleanUpChild(n.childNodes[i]);
21870 cleanUpChild : function (node)
21873 //console.log(node);
21874 if (node.nodeName == "#text") {
21875 // clean up silly Windows -- stuff?
21878 if (node.nodeName == "#comment") {
21879 node.parentNode.removeChild(node);
21880 // clean up silly Windows -- stuff?
21883 var lcname = node.tagName.toLowerCase();
21884 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
21885 // whitelist of tags..
21887 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
21889 node.parentNode.removeChild(node);
21894 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
21896 // spans with no attributes - just remove them..
21897 if ((!node.attributes || !node.attributes.length) && lcname == 'span') {
21898 remove_keep_children = true;
21901 // remove <a name=....> as rendering on yahoo mailer is borked with this.
21902 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
21904 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
21905 // remove_keep_children = true;
21908 if (remove_keep_children) {
21909 this.cleanUpChildren(node);
21910 // inserts everything just before this node...
21911 while (node.childNodes.length) {
21912 var cn = node.childNodes[0];
21913 node.removeChild(cn);
21914 node.parentNode.insertBefore(cn, node);
21916 node.parentNode.removeChild(node);
21920 if (!node.attributes || !node.attributes.length) {
21925 this.cleanUpChildren(node);
21929 function cleanAttr(n,v)
21932 if (v.match(/^\./) || v.match(/^\//)) {
21935 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) {
21938 if (v.match(/^#/)) {
21941 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
21942 node.removeAttribute(n);
21946 var cwhite = this.cwhite;
21947 var cblack = this.cblack;
21949 function cleanStyle(n,v)
21951 if (v.match(/expression/)) { //XSS?? should we even bother..
21952 node.removeAttribute(n);
21956 var parts = v.split(/;/);
21959 Roo.each(parts, function(p) {
21960 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
21964 var l = p.split(':').shift().replace(/\s+/g,'');
21965 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
21967 if ( cwhite.length && cblack.indexOf(l) > -1) {
21968 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
21969 //node.removeAttribute(n);
21973 // only allow 'c whitelisted system attributes'
21974 if ( cwhite.length && cwhite.indexOf(l) < 0) {
21975 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
21976 //node.removeAttribute(n);
21986 if (clean.length) {
21987 node.setAttribute(n, clean.join(';'));
21989 node.removeAttribute(n);
21995 for (var i = node.attributes.length-1; i > -1 ; i--) {
21996 var a = node.attributes[i];
21999 if (a.name.toLowerCase().substr(0,2)=='on') {
22000 node.removeAttribute(a.name);
22003 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22004 node.removeAttribute(a.name);
22007 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22008 cleanAttr(a.name,a.value); // fixme..
22011 if (a.name == 'style') {
22012 cleanStyle(a.name,a.value);
22015 /// clean up MS crap..
22016 // tecnically this should be a list of valid class'es..
22019 if (a.name == 'class') {
22020 if (a.value.match(/^Mso/)) {
22021 node.removeAttribute('class');
22024 if (a.value.match(/^body$/)) {
22025 node.removeAttribute('class');
22036 this.cleanUpChildren(node);
22042 * Clean up MS wordisms...
22044 cleanWord : function(node)
22047 this.cleanWord(this.doc.body);
22052 node.nodeName == 'SPAN' &&
22053 !node.hasAttributes() &&
22054 node.childNodes.length == 1 &&
22055 node.firstChild.nodeName == "#text"
22057 var textNode = node.firstChild;
22058 node.removeChild(textNode);
22059 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
22060 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" "), node);
22062 node.parentNode.insertBefore(textNode, node);
22063 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
22064 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" ") , node);
22066 node.parentNode.removeChild(node);
22069 if (node.nodeName == "#text") {
22070 // clean up silly Windows -- stuff?
22073 if (node.nodeName == "#comment") {
22074 node.parentNode.removeChild(node);
22075 // clean up silly Windows -- stuff?
22079 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22080 node.parentNode.removeChild(node);
22083 //Roo.log(node.tagName);
22084 // remove - but keep children..
22085 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)) {
22086 //Roo.log('-- removed');
22087 while (node.childNodes.length) {
22088 var cn = node.childNodes[0];
22089 node.removeChild(cn);
22090 node.parentNode.insertBefore(cn, node);
22091 // move node to parent - and clean it..
22092 this.cleanWord(cn);
22094 node.parentNode.removeChild(node);
22095 /// no need to iterate chidlren = it's got none..
22096 //this.iterateChildren(node, this.cleanWord);
22100 if (node.className.length) {
22102 var cn = node.className.split(/\W+/);
22104 Roo.each(cn, function(cls) {
22105 if (cls.match(/Mso[a-zA-Z]+/)) {
22110 node.className = cna.length ? cna.join(' ') : '';
22112 node.removeAttribute("class");
22116 if (node.hasAttribute("lang")) {
22117 node.removeAttribute("lang");
22120 if (node.hasAttribute("style")) {
22122 var styles = node.getAttribute("style").split(";");
22124 Roo.each(styles, function(s) {
22125 if (!s.match(/:/)) {
22128 var kv = s.split(":");
22129 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22132 // what ever is left... we allow.
22135 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22136 if (!nstyle.length) {
22137 node.removeAttribute('style');
22140 this.iterateChildren(node, this.cleanWord);
22146 * iterateChildren of a Node, calling fn each time, using this as the scole..
22147 * @param {DomNode} node node to iterate children of.
22148 * @param {Function} fn method of this class to call on each item.
22150 iterateChildren : function(node, fn)
22152 if (!node.childNodes.length) {
22155 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22156 fn.call(this, node.childNodes[i])
22162 * cleanTableWidths.
22164 * Quite often pasting from word etc.. results in tables with column and widths.
22165 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22168 cleanTableWidths : function(node)
22173 this.cleanTableWidths(this.doc.body);
22178 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22181 Roo.log(node.tagName);
22182 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22183 this.iterateChildren(node, this.cleanTableWidths);
22186 if (node.hasAttribute('width')) {
22187 node.removeAttribute('width');
22191 if (node.hasAttribute("style")) {
22194 var styles = node.getAttribute("style").split(";");
22196 Roo.each(styles, function(s) {
22197 if (!s.match(/:/)) {
22200 var kv = s.split(":");
22201 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22204 // what ever is left... we allow.
22207 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22208 if (!nstyle.length) {
22209 node.removeAttribute('style');
22213 this.iterateChildren(node, this.cleanTableWidths);
22221 domToHTML : function(currentElement, depth, nopadtext) {
22223 depth = depth || 0;
22224 nopadtext = nopadtext || false;
22226 if (!currentElement) {
22227 return this.domToHTML(this.doc.body);
22230 //Roo.log(currentElement);
22232 var allText = false;
22233 var nodeName = currentElement.nodeName;
22234 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
22236 if (nodeName == '#text') {
22238 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
22243 if (nodeName != 'BODY') {
22246 // Prints the node tagName, such as <A>, <IMG>, etc
22249 for(i = 0; i < currentElement.attributes.length;i++) {
22251 var aname = currentElement.attributes.item(i).name;
22252 if (!currentElement.attributes.item(i).value.length) {
22255 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
22258 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
22267 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
22270 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
22275 // Traverse the tree
22277 var currentElementChild = currentElement.childNodes.item(i);
22278 var allText = true;
22279 var innerHTML = '';
22281 while (currentElementChild) {
22282 // Formatting code (indent the tree so it looks nice on the screen)
22283 var nopad = nopadtext;
22284 if (lastnode == 'SPAN') {
22288 if (currentElementChild.nodeName == '#text') {
22289 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
22290 toadd = nopadtext ? toadd : toadd.trim();
22291 if (!nopad && toadd.length > 80) {
22292 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
22294 innerHTML += toadd;
22297 currentElementChild = currentElement.childNodes.item(i);
22303 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
22305 // Recursively traverse the tree structure of the child node
22306 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
22307 lastnode = currentElementChild.nodeName;
22309 currentElementChild=currentElement.childNodes.item(i);
22315 // The remaining code is mostly for formatting the tree
22316 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
22321 ret+= "</"+tagName+">";
22327 applyBlacklists : function()
22329 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
22330 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
22334 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
22335 if (b.indexOf(tag) > -1) {
22338 this.white.push(tag);
22342 Roo.each(w, function(tag) {
22343 if (b.indexOf(tag) > -1) {
22346 if (this.white.indexOf(tag) > -1) {
22349 this.white.push(tag);
22354 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
22355 if (w.indexOf(tag) > -1) {
22358 this.black.push(tag);
22362 Roo.each(b, function(tag) {
22363 if (w.indexOf(tag) > -1) {
22366 if (this.black.indexOf(tag) > -1) {
22369 this.black.push(tag);
22374 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
22375 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
22379 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
22380 if (b.indexOf(tag) > -1) {
22383 this.cwhite.push(tag);
22387 Roo.each(w, function(tag) {
22388 if (b.indexOf(tag) > -1) {
22391 if (this.cwhite.indexOf(tag) > -1) {
22394 this.cwhite.push(tag);
22399 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
22400 if (w.indexOf(tag) > -1) {
22403 this.cblack.push(tag);
22407 Roo.each(b, function(tag) {
22408 if (w.indexOf(tag) > -1) {
22411 if (this.cblack.indexOf(tag) > -1) {
22414 this.cblack.push(tag);
22419 setStylesheets : function(stylesheets)
22421 if(typeof(stylesheets) == 'string'){
22422 Roo.get(this.iframe.contentDocument.head).createChild({
22424 rel : 'stylesheet',
22433 Roo.each(stylesheets, function(s) {
22438 Roo.get(_this.iframe.contentDocument.head).createChild({
22440 rel : 'stylesheet',
22449 removeStylesheets : function()
22453 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
22458 setStyle : function(style)
22460 Roo.get(this.iframe.contentDocument.head).createChild({
22469 // hide stuff that is not compatible
22483 * @event specialkey
22487 * @cfg {String} fieldClass @hide
22490 * @cfg {String} focusClass @hide
22493 * @cfg {String} autoCreate @hide
22496 * @cfg {String} inputType @hide
22499 * @cfg {String} invalidClass @hide
22502 * @cfg {String} invalidText @hide
22505 * @cfg {String} msgFx @hide
22508 * @cfg {String} validateOnBlur @hide
22512 Roo.HtmlEditorCore.white = [
22513 'area', 'br', 'img', 'input', 'hr', 'wbr',
22515 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
22516 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
22517 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
22518 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
22519 'table', 'ul', 'xmp',
22521 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
22524 'dir', 'menu', 'ol', 'ul', 'dl',
22530 Roo.HtmlEditorCore.black = [
22531 // 'embed', 'object', // enable - backend responsiblity to clean thiese
22533 'base', 'basefont', 'bgsound', 'blink', 'body',
22534 'frame', 'frameset', 'head', 'html', 'ilayer',
22535 'iframe', 'layer', 'link', 'meta', 'object',
22536 'script', 'style' ,'title', 'xml' // clean later..
22538 Roo.HtmlEditorCore.clean = [
22539 'script', 'style', 'title', 'xml'
22541 Roo.HtmlEditorCore.remove = [
22546 Roo.HtmlEditorCore.ablack = [
22550 Roo.HtmlEditorCore.aclean = [
22551 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
22555 Roo.HtmlEditorCore.pwhite= [
22556 'http', 'https', 'mailto'
22559 // white listed style attributes.
22560 Roo.HtmlEditorCore.cwhite= [
22561 // 'text-align', /// default is to allow most things..
22567 // black listed style attributes.
22568 Roo.HtmlEditorCore.cblack= [
22569 // 'font-size' -- this can be set by the project
22573 Roo.HtmlEditorCore.swapCodes =[
22584 //<script type="text/javascript">
22587 * Ext JS Library 1.1.1
22588 * Copyright(c) 2006-2007, Ext JS, LLC.
22594 Roo.form.HtmlEditor = function(config){
22598 Roo.form.HtmlEditor.superclass.constructor.call(this, config);
22600 if (!this.toolbars) {
22601 this.toolbars = [];
22603 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
22609 * @class Roo.form.HtmlEditor
22610 * @extends Roo.form.Field
22611 * Provides a lightweight HTML Editor component.
22613 * This has been tested on Fireforx / Chrome.. IE may not be so great..
22615 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
22616 * supported by this editor.</b><br/><br/>
22617 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
22618 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
22620 Roo.extend(Roo.form.HtmlEditor, Roo.form.Field, {
22622 * @cfg {Boolean} clearUp
22626 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
22631 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
22636 * @cfg {Number} height (in pixels)
22640 * @cfg {Number} width (in pixels)
22645 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
22648 stylesheets: false,
22652 * @cfg {Array} blacklist of css styles style attributes (blacklist overrides whitelist)
22657 * @cfg {Array} whitelist of css styles style attributes (blacklist overrides whitelist)
22663 * @cfg {Array} blacklist of html tags - in addition to standard blacklist.
22668 * @cfg {Array} whitelist of html tags - in addition to statndard whitelist
22676 // private properties
22677 validationEvent : false,
22679 initialized : false,
22682 onFocus : Roo.emptyFn,
22684 hideMode:'offsets',
22686 actionMode : 'container', // defaults to hiding it...
22688 defaultAutoCreate : { // modified by initCompnoent..
22690 style:"width:500px;height:300px;",
22691 autocomplete: "new-password"
22695 initComponent : function(){
22698 * @event initialize
22699 * Fires when the editor is fully initialized (including the iframe)
22700 * @param {HtmlEditor} this
22705 * Fires when the editor is first receives the focus. Any insertion must wait
22706 * until after this event.
22707 * @param {HtmlEditor} this
22711 * @event beforesync
22712 * Fires before the textarea is updated with content from the editor iframe. Return false
22713 * to cancel the sync.
22714 * @param {HtmlEditor} this
22715 * @param {String} html
22719 * @event beforepush
22720 * Fires before the iframe editor is updated with content from the textarea. Return false
22721 * to cancel the push.
22722 * @param {HtmlEditor} this
22723 * @param {String} html
22728 * Fires when the textarea is updated with content from the editor iframe.
22729 * @param {HtmlEditor} this
22730 * @param {String} html
22735 * Fires when the iframe editor is updated with content from the textarea.
22736 * @param {HtmlEditor} this
22737 * @param {String} html
22741 * @event editmodechange
22742 * Fires when the editor switches edit modes
22743 * @param {HtmlEditor} this
22744 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
22746 editmodechange: true,
22748 * @event editorevent
22749 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
22750 * @param {HtmlEditor} this
22754 * @event firstfocus
22755 * Fires when on first focus - needed by toolbars..
22756 * @param {HtmlEditor} this
22761 * Auto save the htmlEditor value as a file into Events
22762 * @param {HtmlEditor} this
22766 * @event savedpreview
22767 * preview the saved version of htmlEditor
22768 * @param {HtmlEditor} this
22770 savedpreview: true,
22773 * @event stylesheetsclick
22774 * Fires when press the Sytlesheets button
22775 * @param {Roo.HtmlEditorCore} this
22777 stylesheetsclick: true
22779 this.defaultAutoCreate = {
22781 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
22782 autocomplete: "new-password"
22787 * Protected method that will not generally be called directly. It
22788 * is called when the editor creates its toolbar. Override this method if you need to
22789 * add custom toolbar buttons.
22790 * @param {HtmlEditor} editor
22792 createToolbar : function(editor){
22793 Roo.log("create toolbars");
22794 if (!editor.toolbars || !editor.toolbars.length) {
22795 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
22798 for (var i =0 ; i < editor.toolbars.length;i++) {
22799 editor.toolbars[i] = Roo.factory(
22800 typeof(editor.toolbars[i]) == 'string' ?
22801 { xtype: editor.toolbars[i]} : editor.toolbars[i],
22802 Roo.form.HtmlEditor);
22803 editor.toolbars[i].init(editor);
22811 onRender : function(ct, position)
22814 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
22816 this.wrap = this.el.wrap({
22817 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
22820 this.editorcore.onRender(ct, position);
22822 if (this.resizable) {
22823 this.resizeEl = new Roo.Resizable(this.wrap, {
22827 minHeight : this.height,
22828 height: this.height,
22829 handles : this.resizable,
22832 resize : function(r, w, h) {
22833 _t.onResize(w,h); // -something
22839 this.createToolbar(this);
22843 this.setSize(this.wrap.getSize());
22845 if (this.resizeEl) {
22846 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
22847 // should trigger onReize..
22850 this.keyNav = new Roo.KeyNav(this.el, {
22852 "tab" : function(e){
22853 e.preventDefault();
22855 var value = this.getValue();
22857 var start = this.el.dom.selectionStart;
22858 var end = this.el.dom.selectionEnd;
22862 this.setValue(value.substring(0, start) + "\t" + value.substring(end));
22863 this.el.dom.setSelectionRange(end + 1, end + 1);
22867 var f = value.substring(0, start).split("\t");
22869 if(f.pop().length != 0){
22873 this.setValue(f.join("\t") + value.substring(end));
22874 this.el.dom.setSelectionRange(start - 1, start - 1);
22878 "home" : function(e){
22879 e.preventDefault();
22881 var curr = this.el.dom.selectionStart;
22882 var lines = this.getValue().split("\n");
22889 this.el.dom.setSelectionRange(0, 0);
22895 for (var i = 0; i < lines.length;i++) {
22896 pos += lines[i].length;
22906 pos -= lines[i].length;
22912 this.el.dom.setSelectionRange(pos, pos);
22916 this.el.dom.selectionStart = pos;
22917 this.el.dom.selectionEnd = curr;
22920 "end" : function(e){
22921 e.preventDefault();
22923 var curr = this.el.dom.selectionStart;
22924 var lines = this.getValue().split("\n");
22931 this.el.dom.setSelectionRange(this.getValue().length, this.getValue().length);
22937 for (var i = 0; i < lines.length;i++) {
22939 pos += lines[i].length;
22953 this.el.dom.setSelectionRange(pos, pos);
22957 this.el.dom.selectionStart = curr;
22958 this.el.dom.selectionEnd = pos;
22963 doRelay : function(foo, bar, hname){
22964 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
22970 // if(this.autosave && this.w){
22971 // this.autoSaveFn = setInterval(this.autosave, 1000);
22976 onResize : function(w, h)
22978 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
22983 if(typeof w == 'number'){
22984 var aw = w - this.wrap.getFrameWidth('lr');
22985 this.el.setWidth(this.adjustWidth('textarea', aw));
22988 if(typeof h == 'number'){
22990 for (var i =0; i < this.toolbars.length;i++) {
22991 // fixme - ask toolbars for heights?
22992 tbh += this.toolbars[i].tb.el.getHeight();
22993 if (this.toolbars[i].footer) {
22994 tbh += this.toolbars[i].footer.el.getHeight();
23001 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23002 ah -= 5; // knock a few pixes off for look..
23004 this.el.setHeight(this.adjustWidth('textarea', ah));
23008 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23009 this.editorcore.onResize(ew,eh);
23014 * Toggles the editor between standard and source edit mode.
23015 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23017 toggleSourceEdit : function(sourceEditMode)
23019 this.editorcore.toggleSourceEdit(sourceEditMode);
23021 if(this.editorcore.sourceEditMode){
23022 Roo.log('editor - showing textarea');
23025 // Roo.log(this.syncValue());
23026 this.editorcore.syncValue();
23027 this.el.removeClass('x-hidden');
23028 this.el.dom.removeAttribute('tabIndex');
23031 for (var i = 0; i < this.toolbars.length; i++) {
23032 if(this.toolbars[i] instanceof Roo.form.HtmlEditor.ToolbarContext){
23033 this.toolbars[i].tb.hide();
23034 this.toolbars[i].footer.hide();
23039 Roo.log('editor - hiding textarea');
23041 // Roo.log(this.pushValue());
23042 this.editorcore.pushValue();
23044 this.el.addClass('x-hidden');
23045 this.el.dom.setAttribute('tabIndex', -1);
23047 for (var i = 0; i < this.toolbars.length; i++) {
23048 if(this.toolbars[i] instanceof Roo.form.HtmlEditor.ToolbarContext){
23049 this.toolbars[i].tb.show();
23050 this.toolbars[i].footer.show();
23054 //this.deferFocus();
23057 this.setSize(this.wrap.getSize());
23058 this.onResize(this.wrap.getSize().width, this.wrap.getSize().height);
23060 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23063 // private (for BoxComponent)
23064 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23066 // private (for BoxComponent)
23067 getResizeEl : function(){
23071 // private (for BoxComponent)
23072 getPositionEl : function(){
23077 initEvents : function(){
23078 this.originalValue = this.getValue();
23082 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23085 markInvalid : Roo.emptyFn,
23087 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23090 clearInvalid : Roo.emptyFn,
23092 setValue : function(v){
23093 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
23094 this.editorcore.pushValue();
23099 deferFocus : function(){
23100 this.focus.defer(10, this);
23104 focus : function(){
23105 this.editorcore.focus();
23111 onDestroy : function(){
23117 for (var i =0; i < this.toolbars.length;i++) {
23118 // fixme - ask toolbars for heights?
23119 this.toolbars[i].onDestroy();
23122 this.wrap.dom.innerHTML = '';
23123 this.wrap.remove();
23128 onFirstFocus : function(){
23129 //Roo.log("onFirstFocus");
23130 this.editorcore.onFirstFocus();
23131 for (var i =0; i < this.toolbars.length;i++) {
23132 this.toolbars[i].onFirstFocus();
23138 syncValue : function()
23140 this.editorcore.syncValue();
23143 pushValue : function()
23145 this.editorcore.pushValue();
23148 setStylesheets : function(stylesheets)
23150 this.editorcore.setStylesheets(stylesheets);
23153 removeStylesheets : function()
23155 this.editorcore.removeStylesheets();
23159 // hide stuff that is not compatible
23173 * @event specialkey
23177 * @cfg {String} fieldClass @hide
23180 * @cfg {String} focusClass @hide
23183 * @cfg {String} autoCreate @hide
23186 * @cfg {String} inputType @hide
23189 * @cfg {String} invalidClass @hide
23192 * @cfg {String} invalidText @hide
23195 * @cfg {String} msgFx @hide
23198 * @cfg {String} validateOnBlur @hide
23202 // <script type="text/javascript">
23205 * Ext JS Library 1.1.1
23206 * Copyright(c) 2006-2007, Ext JS, LLC.
23212 * @class Roo.form.HtmlEditorToolbar1
23217 new Roo.form.HtmlEditor({
23220 new Roo.form.HtmlEditorToolbar1({
23221 disable : { fonts: 1 , format: 1, ..., ... , ...],
23227 * @cfg {Object} disable List of elements to disable..
23228 * @cfg {Array} btns List of additional buttons.
23232 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23235 Roo.form.HtmlEditor.ToolbarStandard = function(config)
23238 Roo.apply(this, config);
23240 // default disabled, based on 'good practice'..
23241 this.disable = this.disable || {};
23242 Roo.applyIf(this.disable, {
23245 specialElements : true
23249 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23250 // dont call parent... till later.
23253 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
23260 editorcore : false,
23262 * @cfg {Object} disable List of toolbar elements to disable
23269 * @cfg {String} createLinkText The default text for the create link prompt
23271 createLinkText : 'Please enter the URL for the link:',
23273 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
23275 defaultLinkValue : 'http:/'+'/',
23279 * @cfg {Array} fontFamilies An array of available font families
23297 // "á" , ?? a acute?
23302 "°" // , // degrees
23304 // "é" , // e ecute
23305 // "ú" , // u ecute?
23308 specialElements : [
23310 text: "Insert Table",
23313 ihtml : '<table><tr><td>Cell</td></tr></table>'
23317 text: "Insert Image",
23320 ihtml : '<img src="about:blank"/>'
23329 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
23330 "input:submit", "input:button", "select", "textarea", "label" ],
23333 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
23335 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"],
23344 * @cfg {String} defaultFont default font to use.
23346 defaultFont: 'tahoma',
23348 fontSelect : false,
23351 formatCombo : false,
23353 init : function(editor)
23355 this.editor = editor;
23356 this.editorcore = editor.editorcore ? editor.editorcore : editor;
23357 var editorcore = this.editorcore;
23361 var fid = editorcore.frameId;
23363 function btn(id, toggle, handler){
23364 var xid = fid + '-'+ id ;
23368 cls : 'x-btn-icon x-edit-'+id,
23369 enableToggle:toggle !== false,
23370 scope: _t, // was editor...
23371 handler:handler||_t.relayBtnCmd,
23372 clickEvent:'mousedown',
23373 tooltip: etb.buttonTips[id] || undefined, ///tips ???
23380 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
23382 // stop form submits
23383 tb.el.on('click', function(e){
23384 e.preventDefault(); // what does this do?
23387 if(!this.disable.font) { // && !Roo.isSafari){
23388 /* why no safari for fonts
23389 editor.fontSelect = tb.el.createChild({
23392 cls:'x-font-select',
23393 html: this.createFontOptions()
23396 editor.fontSelect.on('change', function(){
23397 var font = editor.fontSelect.dom.value;
23398 editor.relayCmd('fontname', font);
23399 editor.deferFocus();
23403 editor.fontSelect.dom,
23409 if(!this.disable.formats){
23410 this.formatCombo = new Roo.form.ComboBox({
23411 store: new Roo.data.SimpleStore({
23414 data : this.formats // from states.js
23418 //autoCreate : {tag: "div", size: "20"},
23419 displayField:'tag',
23423 triggerAction: 'all',
23424 emptyText:'Add tag',
23425 selectOnFocus:true,
23428 'select': function(c, r, i) {
23429 editorcore.insertTag(r.get('tag'));
23435 tb.addField(this.formatCombo);
23439 if(!this.disable.format){
23444 btn('strikethrough')
23447 if(!this.disable.fontSize){
23452 btn('increasefontsize', false, editorcore.adjustFont),
23453 btn('decreasefontsize', false, editorcore.adjustFont)
23458 if(!this.disable.colors){
23461 id:editorcore.frameId +'-forecolor',
23462 cls:'x-btn-icon x-edit-forecolor',
23463 clickEvent:'mousedown',
23464 tooltip: this.buttonTips['forecolor'] || undefined,
23466 menu : new Roo.menu.ColorMenu({
23467 allowReselect: true,
23468 focus: Roo.emptyFn,
23471 selectHandler: function(cp, color){
23472 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
23473 editor.deferFocus();
23476 clickEvent:'mousedown'
23479 id:editorcore.frameId +'backcolor',
23480 cls:'x-btn-icon x-edit-backcolor',
23481 clickEvent:'mousedown',
23482 tooltip: this.buttonTips['backcolor'] || undefined,
23484 menu : new Roo.menu.ColorMenu({
23485 focus: Roo.emptyFn,
23488 allowReselect: true,
23489 selectHandler: function(cp, color){
23491 editorcore.execCmd('useCSS', false);
23492 editorcore.execCmd('hilitecolor', color);
23493 editorcore.execCmd('useCSS', true);
23494 editor.deferFocus();
23496 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
23497 Roo.isSafari || Roo.isIE ? '#'+color : color);
23498 editor.deferFocus();
23502 clickEvent:'mousedown'
23507 // now add all the items...
23510 if(!this.disable.alignments){
23513 btn('justifyleft'),
23514 btn('justifycenter'),
23515 btn('justifyright')
23519 //if(!Roo.isSafari){
23520 if(!this.disable.links){
23523 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
23527 if(!this.disable.lists){
23530 btn('insertorderedlist'),
23531 btn('insertunorderedlist')
23534 if(!this.disable.sourceEdit){
23537 btn('sourceedit', true, function(btn){
23538 this.toggleSourceEdit(btn.pressed);
23545 // special menu.. - needs to be tidied up..
23546 if (!this.disable.special) {
23549 cls: 'x-edit-none',
23555 for (var i =0; i < this.specialChars.length; i++) {
23556 smenu.menu.items.push({
23558 html: this.specialChars[i],
23559 handler: function(a,b) {
23560 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
23561 //editor.insertAtCursor(a.html);
23575 if (!this.disable.cleanStyles) {
23577 cls: 'x-btn-icon x-btn-clear',
23583 for (var i =0; i < this.cleanStyles.length; i++) {
23584 cmenu.menu.items.push({
23585 actiontype : this.cleanStyles[i],
23586 html: 'Remove ' + this.cleanStyles[i],
23587 handler: function(a,b) {
23590 var c = Roo.get(editorcore.doc.body);
23591 c.select('[style]').each(function(s) {
23592 s.dom.style.removeProperty(a.actiontype);
23594 editorcore.syncValue();
23599 cmenu.menu.items.push({
23600 actiontype : 'tablewidths',
23601 html: 'Remove Table Widths',
23602 handler: function(a,b) {
23603 editorcore.cleanTableWidths();
23604 editorcore.syncValue();
23608 cmenu.menu.items.push({
23609 actiontype : 'word',
23610 html: 'Remove MS Word Formating',
23611 handler: function(a,b) {
23612 editorcore.cleanWord();
23613 editorcore.syncValue();
23618 cmenu.menu.items.push({
23619 actiontype : 'all',
23620 html: 'Remove All Styles',
23621 handler: function(a,b) {
23623 var c = Roo.get(editorcore.doc.body);
23624 c.select('[style]').each(function(s) {
23625 s.dom.removeAttribute('style');
23627 editorcore.syncValue();
23632 cmenu.menu.items.push({
23633 actiontype : 'all',
23634 html: 'Remove All CSS Classes',
23635 handler: function(a,b) {
23637 var c = Roo.get(editorcore.doc.body);
23638 c.select('[class]').each(function(s) {
23639 s.dom.removeAttribute('class');
23641 editorcore.cleanWord();
23642 editorcore.syncValue();
23647 cmenu.menu.items.push({
23648 actiontype : 'tidy',
23649 html: 'Tidy HTML Source',
23650 handler: function(a,b) {
23651 editorcore.doc.body.innerHTML = editorcore.domToHTML();
23652 editorcore.syncValue();
23661 if (!this.disable.specialElements) {
23664 cls: 'x-edit-none',
23669 for (var i =0; i < this.specialElements.length; i++) {
23670 semenu.menu.items.push(
23672 handler: function(a,b) {
23673 editor.insertAtCursor(this.ihtml);
23675 }, this.specialElements[i])
23687 for(var i =0; i< this.btns.length;i++) {
23688 var b = Roo.factory(this.btns[i],Roo.form);
23689 b.cls = 'x-edit-none';
23691 if(typeof(this.btns[i].cls) != 'undefined' && this.btns[i].cls.indexOf('x-init-enable') !== -1){
23692 b.cls += ' x-init-enable';
23695 b.scope = editorcore;
23703 // disable everything...
23705 this.tb.items.each(function(item){
23708 item.id != editorcore.frameId+ '-sourceedit' &&
23709 (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)
23715 this.rendered = true;
23717 // the all the btns;
23718 editor.on('editorevent', this.updateToolbar, this);
23719 // other toolbars need to implement this..
23720 //editor.on('editmodechange', this.updateToolbar, this);
23724 relayBtnCmd : function(btn) {
23725 this.editorcore.relayCmd(btn.cmd);
23727 // private used internally
23728 createLink : function(){
23729 Roo.log("create link?");
23730 var url = prompt(this.createLinkText, this.defaultLinkValue);
23731 if(url && url != 'http:/'+'/'){
23732 this.editorcore.relayCmd('createlink', url);
23738 * Protected method that will not generally be called directly. It triggers
23739 * a toolbar update by reading the markup state of the current selection in the editor.
23741 updateToolbar: function(){
23743 if(!this.editorcore.activated){
23744 this.editor.onFirstFocus();
23748 var btns = this.tb.items.map,
23749 doc = this.editorcore.doc,
23750 frameId = this.editorcore.frameId;
23752 if(!this.disable.font && !Roo.isSafari){
23754 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
23755 if(name != this.fontSelect.dom.value){
23756 this.fontSelect.dom.value = name;
23760 if(!this.disable.format){
23761 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
23762 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
23763 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
23764 btns[frameId + '-strikethrough'].toggle(doc.queryCommandState('strikethrough'));
23766 if(!this.disable.alignments){
23767 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
23768 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
23769 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
23771 if(!Roo.isSafari && !this.disable.lists){
23772 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
23773 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
23776 var ans = this.editorcore.getAllAncestors();
23777 if (this.formatCombo) {
23780 var store = this.formatCombo.store;
23781 this.formatCombo.setValue("");
23782 for (var i =0; i < ans.length;i++) {
23783 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23785 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23793 // hides menus... - so this cant be on a menu...
23794 Roo.menu.MenuMgr.hideAll();
23796 //this.editorsyncValue();
23800 createFontOptions : function(){
23801 var buf = [], fs = this.fontFamilies, ff, lc;
23805 for(var i = 0, len = fs.length; i< len; i++){
23807 lc = ff.toLowerCase();
23809 '<option value="',lc,'" style="font-family:',ff,';"',
23810 (this.defaultFont == lc ? ' selected="true">' : '>'),
23815 return buf.join('');
23818 toggleSourceEdit : function(sourceEditMode){
23820 Roo.log("toolbar toogle");
23821 if(sourceEditMode === undefined){
23822 sourceEditMode = !this.sourceEditMode;
23824 this.sourceEditMode = sourceEditMode === true;
23825 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
23826 // just toggle the button?
23827 if(btn.pressed !== this.sourceEditMode){
23828 btn.toggle(this.sourceEditMode);
23832 if(sourceEditMode){
23833 Roo.log("disabling buttons");
23834 this.tb.items.each(function(item){
23835 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
23841 Roo.log("enabling buttons");
23842 if(this.editorcore.initialized){
23843 this.tb.items.each(function(item){
23849 Roo.log("calling toggole on editor");
23850 // tell the editor that it's been pressed..
23851 this.editor.toggleSourceEdit(sourceEditMode);
23855 * Object collection of toolbar tooltips for the buttons in the editor. The key
23856 * is the command id associated with that button and the value is a valid QuickTips object.
23861 title: 'Bold (Ctrl+B)',
23862 text: 'Make the selected text bold.',
23863 cls: 'x-html-editor-tip'
23866 title: 'Italic (Ctrl+I)',
23867 text: 'Make the selected text italic.',
23868 cls: 'x-html-editor-tip'
23876 title: 'Bold (Ctrl+B)',
23877 text: 'Make the selected text bold.',
23878 cls: 'x-html-editor-tip'
23881 title: 'Italic (Ctrl+I)',
23882 text: 'Make the selected text italic.',
23883 cls: 'x-html-editor-tip'
23886 title: 'Underline (Ctrl+U)',
23887 text: 'Underline the selected text.',
23888 cls: 'x-html-editor-tip'
23891 title: 'Strikethrough',
23892 text: 'Strikethrough the selected text.',
23893 cls: 'x-html-editor-tip'
23895 increasefontsize : {
23896 title: 'Grow Text',
23897 text: 'Increase the font size.',
23898 cls: 'x-html-editor-tip'
23900 decreasefontsize : {
23901 title: 'Shrink Text',
23902 text: 'Decrease the font size.',
23903 cls: 'x-html-editor-tip'
23906 title: 'Text Highlight Color',
23907 text: 'Change the background color of the selected text.',
23908 cls: 'x-html-editor-tip'
23911 title: 'Font Color',
23912 text: 'Change the color of the selected text.',
23913 cls: 'x-html-editor-tip'
23916 title: 'Align Text Left',
23917 text: 'Align text to the left.',
23918 cls: 'x-html-editor-tip'
23921 title: 'Center Text',
23922 text: 'Center text in the editor.',
23923 cls: 'x-html-editor-tip'
23926 title: 'Align Text Right',
23927 text: 'Align text to the right.',
23928 cls: 'x-html-editor-tip'
23930 insertunorderedlist : {
23931 title: 'Bullet List',
23932 text: 'Start a bulleted list.',
23933 cls: 'x-html-editor-tip'
23935 insertorderedlist : {
23936 title: 'Numbered List',
23937 text: 'Start a numbered list.',
23938 cls: 'x-html-editor-tip'
23941 title: 'Hyperlink',
23942 text: 'Make the selected text a hyperlink.',
23943 cls: 'x-html-editor-tip'
23946 title: 'Source Edit',
23947 text: 'Switch to source editing mode.',
23948 cls: 'x-html-editor-tip'
23952 onDestroy : function(){
23955 this.tb.items.each(function(item){
23957 item.menu.removeAll();
23959 item.menu.el.destroy();
23967 onFirstFocus: function() {
23968 this.tb.items.each(function(item){
23977 // <script type="text/javascript">
23980 * Ext JS Library 1.1.1
23981 * Copyright(c) 2006-2007, Ext JS, LLC.
23988 * @class Roo.form.HtmlEditor.ToolbarContext
23993 new Roo.form.HtmlEditor({
23996 { xtype: 'ToolbarStandard', styles : {} }
23997 { xtype: 'ToolbarContext', disable : {} }
24003 * @config : {Object} disable List of elements to disable.. (not done yet.)
24004 * @config : {Object} styles Map of styles available.
24008 Roo.form.HtmlEditor.ToolbarContext = function(config)
24011 Roo.apply(this, config);
24012 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
24013 // dont call parent... till later.
24014 this.styles = this.styles || {};
24019 Roo.form.HtmlEditor.ToolbarContext.types = {
24031 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
24097 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
24102 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
24112 style : 'fontFamily',
24113 displayField: 'display',
24114 optname : 'font-family',
24163 // should we really allow this??
24164 // should this just be
24175 style : 'fontFamily',
24176 displayField: 'display',
24177 optname : 'font-family',
24184 style : 'fontFamily',
24185 displayField: 'display',
24186 optname : 'font-family',
24193 style : 'fontFamily',
24194 displayField: 'display',
24195 optname : 'font-family',
24206 // this should be configurable.. - you can either set it up using stores, or modify options somehwere..
24207 Roo.form.HtmlEditor.ToolbarContext.stores = false;
24209 Roo.form.HtmlEditor.ToolbarContext.options = {
24211 [ 'Helvetica,Arial,sans-serif', 'Helvetica'],
24212 [ 'Courier New', 'Courier New'],
24213 [ 'Tahoma', 'Tahoma'],
24214 [ 'Times New Roman,serif', 'Times'],
24215 [ 'Verdana','Verdana' ]
24219 // fixme - these need to be configurable..
24222 //Roo.form.HtmlEditor.ToolbarContext.types
24225 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
24232 editorcore : false,
24234 * @cfg {Object} disable List of toolbar elements to disable
24239 * @cfg {Object} styles List of styles
24240 * eg. { '*' : [ 'headline' ] , 'TD' : [ 'underline', 'double-underline' ] }
24242 * These must be defined in the page, so they get rendered correctly..
24253 init : function(editor)
24255 this.editor = editor;
24256 this.editorcore = editor.editorcore ? editor.editorcore : editor;
24257 var editorcore = this.editorcore;
24259 var fid = editorcore.frameId;
24261 function btn(id, toggle, handler){
24262 var xid = fid + '-'+ id ;
24266 cls : 'x-btn-icon x-edit-'+id,
24267 enableToggle:toggle !== false,
24268 scope: editorcore, // was editor...
24269 handler:handler||editorcore.relayBtnCmd,
24270 clickEvent:'mousedown',
24271 tooltip: etb.buttonTips[id] || undefined, ///tips ???
24275 // create a new element.
24276 var wdiv = editor.wrap.createChild({
24278 }, editor.wrap.dom.firstChild.nextSibling, true);
24280 // can we do this more than once??
24282 // stop form submits
24285 // disable everything...
24286 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
24287 this.toolbars = {};
24289 for (var i in ty) {
24291 this.toolbars[i] = this.buildToolbar(ty[i],i);
24293 this.tb = this.toolbars.BODY;
24295 this.buildFooter();
24296 this.footer.show();
24297 editor.on('hide', function( ) { this.footer.hide() }, this);
24298 editor.on('show', function( ) { this.footer.show() }, this);
24301 this.rendered = true;
24303 // the all the btns;
24304 editor.on('editorevent', this.updateToolbar, this);
24305 // other toolbars need to implement this..
24306 //editor.on('editmodechange', this.updateToolbar, this);
24312 * Protected method that will not generally be called directly. It triggers
24313 * a toolbar update by reading the markup state of the current selection in the editor.
24315 * Note you can force an update by calling on('editorevent', scope, false)
24317 updateToolbar: function(editor,ev,sel){
24320 // capture mouse up - this is handy for selecting images..
24321 // perhaps should go somewhere else...
24322 if(!this.editorcore.activated){
24323 this.editor.onFirstFocus();
24329 // http://developer.yahoo.com/yui/docs/simple-editor.js.html
24330 // selectNode - might want to handle IE?
24332 (ev.type == 'mouseup' || ev.type == 'click' ) &&
24333 ev.target && ev.target.tagName == 'IMG') {
24334 // they have click on an image...
24335 // let's see if we can change the selection...
24338 var nodeRange = sel.ownerDocument.createRange();
24340 nodeRange.selectNode(sel);
24342 nodeRange.selectNodeContents(sel);
24344 //nodeRange.collapse(true);
24345 var s = this.editorcore.win.getSelection();
24346 s.removeAllRanges();
24347 s.addRange(nodeRange);
24351 var updateFooter = sel ? false : true;
24354 var ans = this.editorcore.getAllAncestors();
24357 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
24360 sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editorcore.doc.body;
24361 sel = sel ? sel : this.editorcore.doc.body;
24362 sel = sel.tagName.length ? sel : this.editorcore.doc.body;
24365 // pick a menu that exists..
24366 var tn = sel.tagName.toUpperCase();
24367 //sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
24369 tn = sel.tagName.toUpperCase();
24371 var lastSel = this.tb.selectedNode;
24373 this.tb.selectedNode = sel;
24375 // if current menu does not match..
24377 if ((this.tb.name != tn) || (lastSel != this.tb.selectedNode) || ev === false) {
24380 ///console.log("show: " + tn);
24381 this.tb = typeof(ty[tn]) != 'undefined' ? this.toolbars[tn] : this.toolbars['*'];
24384 this.tb.items.first().el.innerHTML = tn + ': ';
24387 // update attributes
24388 if (this.tb.fields) {
24389 this.tb.fields.each(function(e) {
24391 e.setValue(sel.style[e.stylename]);
24394 e.setValue(sel.getAttribute(e.attrname));
24398 var hasStyles = false;
24399 for(var i in this.styles) {
24406 var st = this.tb.fields.item(0);
24408 st.store.removeAll();
24411 var cn = sel.className.split(/\s+/);
24414 if (this.styles['*']) {
24416 Roo.each(this.styles['*'], function(v) {
24417 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
24420 if (this.styles[tn]) {
24421 Roo.each(this.styles[tn], function(v) {
24422 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
24426 st.store.loadData(avs);
24430 // flag our selected Node.
24431 this.tb.selectedNode = sel;
24434 Roo.menu.MenuMgr.hideAll();
24438 if (!updateFooter) {
24439 //this.footDisp.dom.innerHTML = '';
24442 // update the footer
24446 this.footerEls = ans.reverse();
24447 Roo.each(this.footerEls, function(a,i) {
24448 if (!a) { return; }
24449 html += html.length ? ' > ' : '';
24451 html += '<span class="x-ed-loc-' + i + '">' + a.tagName + '</span>';
24456 var sz = this.footDisp.up('td').getSize();
24457 this.footDisp.dom.style.width = (sz.width -10) + 'px';
24458 this.footDisp.dom.style.marginLeft = '5px';
24460 this.footDisp.dom.style.overflow = 'hidden';
24462 this.footDisp.dom.innerHTML = html;
24464 //this.editorsyncValue();
24471 onDestroy : function(){
24474 this.tb.items.each(function(item){
24476 item.menu.removeAll();
24478 item.menu.el.destroy();
24486 onFirstFocus: function() {
24487 // need to do this for all the toolbars..
24488 this.tb.items.each(function(item){
24492 buildToolbar: function(tlist, nm)
24494 var editor = this.editor;
24495 var editorcore = this.editorcore;
24496 // create a new element.
24497 var wdiv = editor.wrap.createChild({
24499 }, editor.wrap.dom.firstChild.nextSibling, true);
24502 var tb = new Roo.Toolbar(wdiv);
24505 tb.add(nm+ ": ");
24508 for(var i in this.styles) {
24513 if (styles && styles.length) {
24515 // this needs a multi-select checkbox...
24516 tb.addField( new Roo.form.ComboBox({
24517 store: new Roo.data.SimpleStore({
24519 fields: ['val', 'selected'],
24522 name : '-roo-edit-className',
24523 attrname : 'className',
24524 displayField: 'val',
24528 triggerAction: 'all',
24529 emptyText:'Select Style',
24530 selectOnFocus:true,
24533 'select': function(c, r, i) {
24534 // initial support only for on class per el..
24535 tb.selectedNode.className = r ? r.get('val') : '';
24536 editorcore.syncValue();
24543 var tbc = Roo.form.HtmlEditor.ToolbarContext;
24544 var tbops = tbc.options;
24546 for (var i in tlist) {
24548 var item = tlist[i];
24549 tb.add(item.title + ": ");
24552 //optname == used so you can configure the options available..
24553 var opts = item.opts ? item.opts : false;
24554 if (item.optname) {
24555 opts = tbops[item.optname];
24560 // opts == pulldown..
24561 tb.addField( new Roo.form.ComboBox({
24562 store: typeof(tbc.stores[i]) != 'undefined' ? Roo.factory(tbc.stores[i],Roo.data) : new Roo.data.SimpleStore({
24564 fields: ['val', 'display'],
24567 name : '-roo-edit-' + i,
24569 stylename : item.style ? item.style : false,
24570 displayField: item.displayField ? item.displayField : 'val',
24571 valueField : 'val',
24573 mode: typeof(tbc.stores[i]) != 'undefined' ? 'remote' : 'local',
24575 triggerAction: 'all',
24576 emptyText:'Select',
24577 selectOnFocus:true,
24578 width: item.width ? item.width : 130,
24580 'select': function(c, r, i) {
24582 tb.selectedNode.style[c.stylename] = r.get('val');
24585 tb.selectedNode.setAttribute(c.attrname, r.get('val'));
24594 tb.addField( new Roo.form.TextField({
24597 //allowBlank:false,
24602 tb.addField( new Roo.form.TextField({
24603 name: '-roo-edit-' + i,
24610 'change' : function(f, nv, ov) {
24611 tb.selectedNode.setAttribute(f.attrname, nv);
24612 editorcore.syncValue();
24625 text: 'Stylesheets',
24628 click : function ()
24630 _this.editor.fireEvent('stylesheetsclick', _this.editor);
24638 text: 'Remove Tag',
24641 click : function ()
24644 // undo does not work.
24646 var sn = tb.selectedNode;
24648 var pn = sn.parentNode;
24650 var stn = sn.childNodes[0];
24651 var en = sn.childNodes[sn.childNodes.length - 1 ];
24652 while (sn.childNodes.length) {
24653 var node = sn.childNodes[0];
24654 sn.removeChild(node);
24656 pn.insertBefore(node, sn);
24659 pn.removeChild(sn);
24660 var range = editorcore.createRange();
24662 range.setStart(stn,0);
24663 range.setEnd(en,0); //????
24664 //range.selectNode(sel);
24667 var selection = editorcore.getSelection();
24668 selection.removeAllRanges();
24669 selection.addRange(range);
24673 //_this.updateToolbar(null, null, pn);
24674 _this.updateToolbar(null, null, null);
24675 _this.footDisp.dom.innerHTML = '';
24685 tb.el.on('click', function(e){
24686 e.preventDefault(); // what does this do?
24688 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
24691 // dont need to disable them... as they will get hidden
24696 buildFooter : function()
24699 var fel = this.editor.wrap.createChild();
24700 this.footer = new Roo.Toolbar(fel);
24701 // toolbar has scrolly on left / right?
24702 var footDisp= new Roo.Toolbar.Fill();
24708 handler : function() {
24709 _t.footDisp.scrollTo('left',0,true)
24713 this.footer.add( footDisp );
24718 handler : function() {
24720 _t.footDisp.select('span').last().scrollIntoView(_t.footDisp,true);
24724 var fel = Roo.get(footDisp.el);
24725 fel.addClass('x-editor-context');
24726 this.footDispWrap = fel;
24727 this.footDispWrap.overflow = 'hidden';
24729 this.footDisp = fel.createChild();
24730 this.footDispWrap.on('click', this.onContextClick, this)
24734 onContextClick : function (ev,dom)
24736 ev.preventDefault();
24737 var cn = dom.className;
24739 if (!cn.match(/x-ed-loc-/)) {
24742 var n = cn.split('-').pop();
24743 var ans = this.footerEls;
24747 var range = this.editorcore.createRange();
24749 range.selectNodeContents(sel);
24750 //range.selectNode(sel);
24753 var selection = this.editorcore.getSelection();
24754 selection.removeAllRanges();
24755 selection.addRange(range);
24759 this.updateToolbar(null, null, sel);
24776 * Ext JS Library 1.1.1
24777 * Copyright(c) 2006-2007, Ext JS, LLC.
24779 * Originally Released Under LGPL - original licence link has changed is not relivant.
24782 * <script type="text/javascript">
24786 * @class Roo.form.BasicForm
24787 * @extends Roo.util.Observable
24788 * Supplies the functionality to do "actions" on forms and initialize Roo.form.Field types on existing markup.
24790 * @param {String/HTMLElement/Roo.Element} el The form element or its id
24791 * @param {Object} config Configuration options
24793 Roo.form.BasicForm = function(el, config){
24794 this.allItems = [];
24795 this.childForms = [];
24796 Roo.apply(this, config);
24798 * The Roo.form.Field items in this form.
24799 * @type MixedCollection
24803 this.items = new Roo.util.MixedCollection(false, function(o){
24804 return o.id || (o.id = Roo.id());
24808 * @event beforeaction
24809 * Fires before any action is performed. Return false to cancel the action.
24810 * @param {Form} this
24811 * @param {Action} action The action to be performed
24813 beforeaction: true,
24815 * @event actionfailed
24816 * Fires when an action fails.
24817 * @param {Form} this
24818 * @param {Action} action The action that failed
24820 actionfailed : true,
24822 * @event actioncomplete
24823 * Fires when an action is completed.
24824 * @param {Form} this
24825 * @param {Action} action The action that completed
24827 actioncomplete : true
24832 Roo.form.BasicForm.superclass.constructor.call(this);
24834 Roo.form.BasicForm.popover.apply();
24837 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
24839 * @cfg {String} method
24840 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
24843 * @cfg {DataReader} reader
24844 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when executing "load" actions.
24845 * This is optional as there is built-in support for processing JSON.
24848 * @cfg {DataReader} errorReader
24849 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
24850 * This is completely optional as there is built-in support for processing JSON.
24853 * @cfg {String} url
24854 * The URL to use for form actions if one isn't supplied in the action options.
24857 * @cfg {Boolean} fileUpload
24858 * Set to true if this form is a file upload.
24862 * @cfg {Object} baseParams
24863 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
24868 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
24873 activeAction : null,
24876 * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded
24877 * or setValues() data instead of when the form was first created.
24879 trackResetOnLoad : false,
24883 * childForms - used for multi-tab forms
24886 childForms : false,
24889 * allItems - full list of fields.
24895 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
24896 * element by passing it or its id or mask the form itself by passing in true.
24899 waitMsgTarget : false,
24904 disableMask : false,
24907 * @cfg {Boolean} errorMask (true|false) default false
24912 * @cfg {Number} maskOffset Default 100
24917 initEl : function(el){
24918 this.el = Roo.get(el);
24919 this.id = this.el.id || Roo.id();
24920 this.el.on('submit', this.onSubmit, this);
24921 this.el.addClass('x-form');
24925 onSubmit : function(e){
24930 * Returns true if client-side validation on the form is successful.
24933 isValid : function(){
24935 var target = false;
24936 this.items.each(function(f){
24943 if(!target && f.el.isVisible(true)){
24948 if(this.errorMask && !valid){
24949 Roo.form.BasicForm.popover.mask(this, target);
24956 * DEPRICATED Returns true if any fields in this form have changed since their original load.
24959 isDirty : function(){
24961 this.items.each(function(f){
24971 * Returns true if any fields in this form have changed since their original load. (New version)
24975 hasChanged : function()
24978 this.items.each(function(f){
24979 if(f.hasChanged()){
24988 * Resets all hasChanged to 'false' -
24989 * The old 'isDirty' used 'original value..' however this breaks reset() and a few other things.
24990 * So hasChanged storage is only to be used for this purpose
24993 resetHasChanged : function()
24995 this.items.each(function(f){
24996 f.resetHasChanged();
25003 * Performs a predefined action (submit or load) or custom actions you define on this form.
25004 * @param {String} actionName The name of the action type
25005 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
25006 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
25007 * accept other config options):
25009 Property Type Description
25010 ---------------- --------------- ----------------------------------------------------------------------------------
25011 url String The url for the action (defaults to the form's url)
25012 method String The form method to use (defaults to the form's method, or POST if not defined)
25013 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
25014 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
25015 validate the form on the client (defaults to false)
25017 * @return {BasicForm} this
25019 doAction : function(action, options){
25020 if(typeof action == 'string'){
25021 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
25023 if(this.fireEvent('beforeaction', this, action) !== false){
25024 this.beforeAction(action);
25025 action.run.defer(100, action);
25031 * Shortcut to do a submit action.
25032 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
25033 * @return {BasicForm} this
25035 submit : function(options){
25036 this.doAction('submit', options);
25041 * Shortcut to do a load action.
25042 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
25043 * @return {BasicForm} this
25045 load : function(options){
25046 this.doAction('load', options);
25051 * Persists the values in this form into the passed Roo.data.Record object in a beginEdit/endEdit block.
25052 * @param {Record} record The record to edit
25053 * @return {BasicForm} this
25055 updateRecord : function(record){
25056 record.beginEdit();
25057 var fs = record.fields;
25058 fs.each(function(f){
25059 var field = this.findField(f.name);
25061 record.set(f.name, field.getValue());
25069 * Loads an Roo.data.Record into this form.
25070 * @param {Record} record The record to load
25071 * @return {BasicForm} this
25073 loadRecord : function(record){
25074 this.setValues(record.data);
25079 beforeAction : function(action){
25080 var o = action.options;
25082 if(!this.disableMask) {
25083 if(this.waitMsgTarget === true){
25084 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
25085 }else if(this.waitMsgTarget){
25086 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
25087 this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
25089 Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
25097 afterAction : function(action, success){
25098 this.activeAction = null;
25099 var o = action.options;
25101 if(!this.disableMask) {
25102 if(this.waitMsgTarget === true){
25104 }else if(this.waitMsgTarget){
25105 this.waitMsgTarget.unmask();
25107 Roo.MessageBox.updateProgress(1);
25108 Roo.MessageBox.hide();
25116 Roo.callback(o.success, o.scope, [this, action]);
25117 this.fireEvent('actioncomplete', this, action);
25121 // failure condition..
25122 // we have a scenario where updates need confirming.
25123 // eg. if a locking scenario exists..
25124 // we look for { errors : { needs_confirm : true }} in the response.
25126 (typeof(action.result) != 'undefined') &&
25127 (typeof(action.result.errors) != 'undefined') &&
25128 (typeof(action.result.errors.needs_confirm) != 'undefined')
25131 Roo.MessageBox.confirm(
25132 "Change requires confirmation",
25133 action.result.errorMsg,
25138 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
25148 Roo.callback(o.failure, o.scope, [this, action]);
25149 // show an error message if no failed handler is set..
25150 if (!this.hasListener('actionfailed')) {
25151 Roo.MessageBox.alert("Error",
25152 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
25153 action.result.errorMsg :
25154 "Saving Failed, please check your entries or try again"
25158 this.fireEvent('actionfailed', this, action);
25164 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
25165 * @param {String} id The value to search for
25168 findField : function(id){
25169 var field = this.items.get(id);
25171 this.items.each(function(f){
25172 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
25178 return field || null;
25182 * Add a secondary form to this one,
25183 * Used to provide tabbed forms. One form is primary, with hidden values
25184 * which mirror the elements from the other forms.
25186 * @param {Roo.form.Form} form to add.
25189 addForm : function(form)
25192 if (this.childForms.indexOf(form) > -1) {
25196 this.childForms.push(form);
25198 Roo.each(form.allItems, function (fe) {
25200 n = typeof(fe.getName) == 'undefined' ? fe.name : fe.getName();
25201 if (this.findField(n)) { // already added..
25204 var add = new Roo.form.Hidden({
25207 add.render(this.el);
25214 * Mark fields in this form invalid in bulk.
25215 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
25216 * @return {BasicForm} this
25218 markInvalid : function(errors){
25219 if(errors instanceof Array){
25220 for(var i = 0, len = errors.length; i < len; i++){
25221 var fieldError = errors[i];
25222 var f = this.findField(fieldError.id);
25224 f.markInvalid(fieldError.msg);
25230 if(typeof errors[id] != 'function' && (field = this.findField(id))){
25231 field.markInvalid(errors[id]);
25235 Roo.each(this.childForms || [], function (f) {
25236 f.markInvalid(errors);
25243 * Set values for fields in this form in bulk.
25244 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
25245 * @return {BasicForm} this
25247 setValues : function(values){
25248 if(values instanceof Array){ // array of objects
25249 for(var i = 0, len = values.length; i < len; i++){
25251 var f = this.findField(v.id);
25253 f.setValue(v.value);
25254 if(this.trackResetOnLoad){
25255 f.originalValue = f.getValue();
25259 }else{ // object hash
25262 if(typeof values[id] != 'function' && (field = this.findField(id))){
25264 if (field.setFromData &&
25265 field.valueField &&
25266 field.displayField &&
25267 // combos' with local stores can
25268 // be queried via setValue()
25269 // to set their value..
25270 (field.store && !field.store.isLocal)
25274 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
25275 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
25276 field.setFromData(sd);
25279 field.setValue(values[id]);
25283 if(this.trackResetOnLoad){
25284 field.originalValue = field.getValue();
25289 this.resetHasChanged();
25292 Roo.each(this.childForms || [], function (f) {
25293 f.setValues(values);
25294 f.resetHasChanged();
25301 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
25302 * they are returned as an array.
25303 * @param {Boolean} asString
25306 getValues : function(asString){
25307 if (this.childForms) {
25308 // copy values from the child forms
25309 Roo.each(this.childForms, function (f) {
25310 this.setValues(f.getValues());
25315 if (typeof(FormData) != 'undefined' && asString !== true) {
25316 var fd = (new FormData(this.el.dom)).entries();
25318 var ent = fd.next();
25319 while (!ent.done) {
25320 ret[ent.value[0]] = ent.value[1]; // not sure how this will handle duplicates..
25327 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
25328 if(asString === true){
25331 return Roo.urlDecode(fs);
25335 * Returns the fields in this form as an object with key/value pairs.
25336 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
25339 getFieldValues : function(with_hidden)
25341 if (this.childForms) {
25342 // copy values from the child forms
25343 // should this call getFieldValues - probably not as we do not currently copy
25344 // hidden fields when we generate..
25345 Roo.each(this.childForms, function (f) {
25346 this.setValues(f.getValues());
25351 this.items.each(function(f){
25352 if (!f.getName()) {
25355 var v = f.getValue();
25356 if (f.inputType =='radio') {
25357 if (typeof(ret[f.getName()]) == 'undefined') {
25358 ret[f.getName()] = ''; // empty..
25361 if (!f.el.dom.checked) {
25365 v = f.el.dom.value;
25369 // not sure if this supported any more..
25370 if ((typeof(v) == 'object') && f.getRawValue) {
25371 v = f.getRawValue() ; // dates..
25373 // combo boxes where name != hiddenName...
25374 if (f.name != f.getName()) {
25375 ret[f.name] = f.getRawValue();
25377 ret[f.getName()] = v;
25384 * Clears all invalid messages in this form.
25385 * @return {BasicForm} this
25387 clearInvalid : function(){
25388 this.items.each(function(f){
25392 Roo.each(this.childForms || [], function (f) {
25401 * Resets this form.
25402 * @return {BasicForm} this
25404 reset : function(){
25405 this.items.each(function(f){
25409 Roo.each(this.childForms || [], function (f) {
25412 this.resetHasChanged();
25418 * Add Roo.form components to this form.
25419 * @param {Field} field1
25420 * @param {Field} field2 (optional)
25421 * @param {Field} etc (optional)
25422 * @return {BasicForm} this
25425 this.items.addAll(Array.prototype.slice.call(arguments, 0));
25431 * Removes a field from the items collection (does NOT remove its markup).
25432 * @param {Field} field
25433 * @return {BasicForm} this
25435 remove : function(field){
25436 this.items.remove(field);
25441 * Looks at the fields in this form, checks them for an id attribute,
25442 * and calls applyTo on the existing dom element with that id.
25443 * @return {BasicForm} this
25445 render : function(){
25446 this.items.each(function(f){
25447 if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
25455 * Calls {@link Ext#apply} for all fields in this form with the passed object.
25456 * @param {Object} values
25457 * @return {BasicForm} this
25459 applyToFields : function(o){
25460 this.items.each(function(f){
25467 * Calls {@link Ext#applyIf} for all field in this form with the passed object.
25468 * @param {Object} values
25469 * @return {BasicForm} this
25471 applyIfToFields : function(o){
25472 this.items.each(function(f){
25480 Roo.BasicForm = Roo.form.BasicForm;
25482 Roo.apply(Roo.form.BasicForm, {
25496 intervalID : false,
25502 if(this.isApplied){
25507 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
25508 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
25509 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
25510 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
25513 this.maskEl.top.enableDisplayMode("block");
25514 this.maskEl.left.enableDisplayMode("block");
25515 this.maskEl.bottom.enableDisplayMode("block");
25516 this.maskEl.right.enableDisplayMode("block");
25518 Roo.get(document.body).on('click', function(){
25522 Roo.get(document.body).on('touchstart', function(){
25526 this.isApplied = true
25529 mask : function(form, target)
25533 this.target = target;
25535 if(!this.form.errorMask || !target.el){
25539 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.x-layout-active-content', 100, true) || Roo.get(document.body);
25541 var ot = this.target.el.calcOffsetsTo(scrollable);
25543 var scrollTo = ot[1] - this.form.maskOffset;
25545 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
25547 scrollable.scrollTo('top', scrollTo);
25549 var el = this.target.wrap || this.target.el;
25551 var box = el.getBox();
25553 this.maskEl.top.setStyle('position', 'absolute');
25554 this.maskEl.top.setStyle('z-index', 10000);
25555 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
25556 this.maskEl.top.setLeft(0);
25557 this.maskEl.top.setTop(0);
25558 this.maskEl.top.show();
25560 this.maskEl.left.setStyle('position', 'absolute');
25561 this.maskEl.left.setStyle('z-index', 10000);
25562 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
25563 this.maskEl.left.setLeft(0);
25564 this.maskEl.left.setTop(box.y - this.padding);
25565 this.maskEl.left.show();
25567 this.maskEl.bottom.setStyle('position', 'absolute');
25568 this.maskEl.bottom.setStyle('z-index', 10000);
25569 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
25570 this.maskEl.bottom.setLeft(0);
25571 this.maskEl.bottom.setTop(box.bottom + this.padding);
25572 this.maskEl.bottom.show();
25574 this.maskEl.right.setStyle('position', 'absolute');
25575 this.maskEl.right.setStyle('z-index', 10000);
25576 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
25577 this.maskEl.right.setLeft(box.right + this.padding);
25578 this.maskEl.right.setTop(box.y - this.padding);
25579 this.maskEl.right.show();
25581 this.intervalID = window.setInterval(function() {
25582 Roo.form.BasicForm.popover.unmask();
25585 window.onwheel = function(){ return false;};
25587 (function(){ this.isMasked = true; }).defer(500, this);
25591 unmask : function()
25593 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
25597 this.maskEl.top.setStyle('position', 'absolute');
25598 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
25599 this.maskEl.top.hide();
25601 this.maskEl.left.setStyle('position', 'absolute');
25602 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
25603 this.maskEl.left.hide();
25605 this.maskEl.bottom.setStyle('position', 'absolute');
25606 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
25607 this.maskEl.bottom.hide();
25609 this.maskEl.right.setStyle('position', 'absolute');
25610 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
25611 this.maskEl.right.hide();
25613 window.onwheel = function(){ return true;};
25615 if(this.intervalID){
25616 window.clearInterval(this.intervalID);
25617 this.intervalID = false;
25620 this.isMasked = false;
25628 * Ext JS Library 1.1.1
25629 * Copyright(c) 2006-2007, Ext JS, LLC.
25631 * Originally Released Under LGPL - original licence link has changed is not relivant.
25634 * <script type="text/javascript">
25638 * @class Roo.form.Form
25639 * @extends Roo.form.BasicForm
25640 * Adds the ability to dynamically render forms with JavaScript to {@link Roo.form.BasicForm}.
25642 * @param {Object} config Configuration options
25644 Roo.form.Form = function(config){
25646 if (config.items) {
25647 xitems = config.items;
25648 delete config.items;
25652 Roo.form.Form.superclass.constructor.call(this, null, config);
25653 this.url = this.url || this.action;
25655 this.root = new Roo.form.Layout(Roo.applyIf({
25659 this.active = this.root;
25661 * Array of all the buttons that have been added to this form via {@link addButton}
25665 this.allItems = [];
25668 * @event clientvalidation
25669 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
25670 * @param {Form} this
25671 * @param {Boolean} valid true if the form has passed client-side validation
25673 clientvalidation: true,
25676 * Fires when the form is rendered
25677 * @param {Roo.form.Form} form
25682 if (this.progressUrl) {
25683 // push a hidden field onto the list of fields..
25687 name : 'UPLOAD_IDENTIFIER'
25692 Roo.each(xitems, this.addxtype, this);
25696 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
25698 * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
25701 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
25704 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
25706 buttonAlign:'center',
25709 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
25714 * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
25715 * This property cascades to child containers if not set.
25720 * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
25721 * fires a looping event with that state. This is required to bind buttons to the valid
25722 * state using the config value formBind:true on the button.
25724 monitorValid : false,
25727 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
25732 * @cfg {String} progressUrl - Url to return progress data
25735 progressUrl : false,
25737 * @cfg {boolean|FormData} formData - true to use new 'FormData' post, or set to a new FormData({dom form}) Object, if
25738 * sending a formdata with extra parameters - eg uploaded elements.
25744 * Opens a new {@link Roo.form.Column} container in the layout stack. If fields are passed after the config, the
25745 * fields are added and the column is closed. If no fields are passed the column remains open
25746 * until end() is called.
25747 * @param {Object} config The config to pass to the column
25748 * @param {Field} field1 (optional)
25749 * @param {Field} field2 (optional)
25750 * @param {Field} etc (optional)
25751 * @return Column The column container object
25753 column : function(c){
25754 var col = new Roo.form.Column(c);
25756 if(arguments.length > 1){ // duplicate code required because of Opera
25757 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25764 * Opens a new {@link Roo.form.FieldSet} container in the layout stack. If fields are passed after the config, the
25765 * fields are added and the fieldset is closed. If no fields are passed the fieldset remains open
25766 * until end() is called.
25767 * @param {Object} config The config to pass to the fieldset
25768 * @param {Field} field1 (optional)
25769 * @param {Field} field2 (optional)
25770 * @param {Field} etc (optional)
25771 * @return FieldSet The fieldset container object
25773 fieldset : function(c){
25774 var fs = new Roo.form.FieldSet(c);
25776 if(arguments.length > 1){ // duplicate code required because of Opera
25777 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25784 * Opens a new {@link Roo.form.Layout} container in the layout stack. If fields are passed after the config, the
25785 * fields are added and the container is closed. If no fields are passed the container remains open
25786 * until end() is called.
25787 * @param {Object} config The config to pass to the Layout
25788 * @param {Field} field1 (optional)
25789 * @param {Field} field2 (optional)
25790 * @param {Field} etc (optional)
25791 * @return Layout The container object
25793 container : function(c){
25794 var l = new Roo.form.Layout(c);
25796 if(arguments.length > 1){ // duplicate code required because of Opera
25797 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25804 * Opens the passed container in the layout stack. The container can be any {@link Roo.form.Layout} or subclass.
25805 * @param {Object} container A Roo.form.Layout or subclass of Layout
25806 * @return {Form} this
25808 start : function(c){
25809 // cascade label info
25810 Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
25811 this.active.stack.push(c);
25812 c.ownerCt = this.active;
25818 * Closes the current open container
25819 * @return {Form} this
25822 if(this.active == this.root){
25825 this.active = this.active.ownerCt;
25830 * Add Roo.form components to the current open container (e.g. column, fieldset, etc.). Fields added via this method
25831 * can also be passed with an additional property of fieldLabel, which if supplied, will provide the text to display
25832 * as the label of the field.
25833 * @param {Field} field1
25834 * @param {Field} field2 (optional)
25835 * @param {Field} etc. (optional)
25836 * @return {Form} this
25839 this.active.stack.push.apply(this.active.stack, arguments);
25840 this.allItems.push.apply(this.allItems,arguments);
25842 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
25843 if(a[i].isFormField){
25848 Roo.form.Form.superclass.add.apply(this, r);
25858 * Find any element that has been added to a form, using it's ID or name
25859 * This can include framesets, columns etc. along with regular fields..
25860 * @param {String} id - id or name to find.
25862 * @return {Element} e - or false if nothing found.
25864 findbyId : function(id)
25870 Roo.each(this.allItems, function(f){
25871 if (f.id == id || f.name == id ){
25882 * Render this form into the passed container. This should only be called once!
25883 * @param {String/HTMLElement/Element} container The element this component should be rendered into
25884 * @return {Form} this
25886 render : function(ct)
25892 var o = this.autoCreate || {
25894 method : this.method || 'POST',
25895 id : this.id || Roo.id()
25897 this.initEl(ct.createChild(o));
25899 this.root.render(this.el);
25903 this.items.each(function(f){
25904 f.render('x-form-el-'+f.id);
25907 if(this.buttons.length > 0){
25908 // tables are required to maintain order and for correct IE layout
25909 var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
25910 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
25911 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
25913 var tr = tb.getElementsByTagName('tr')[0];
25914 for(var i = 0, len = this.buttons.length; i < len; i++) {
25915 var b = this.buttons[i];
25916 var td = document.createElement('td');
25917 td.className = 'x-form-btn-td';
25918 b.render(tr.appendChild(td));
25921 if(this.monitorValid){ // initialize after render
25922 this.startMonitoring();
25924 this.fireEvent('rendered', this);
25929 * Adds a button to the footer of the form - this <b>must</b> be called before the form is rendered.
25930 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
25931 * object or a valid Roo.DomHelper element config
25932 * @param {Function} handler The function called when the button is clicked
25933 * @param {Object} scope (optional) The scope of the handler function
25934 * @return {Roo.Button}
25936 addButton : function(config, handler, scope){
25940 minWidth: this.minButtonWidth,
25943 if(typeof config == "string"){
25946 Roo.apply(bc, config);
25948 var btn = new Roo.Button(null, bc);
25949 this.buttons.push(btn);
25954 * Adds a series of form elements (using the xtype property as the factory method.
25955 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column, (and 'end' to close a block)
25956 * @param {Object} config
25959 addxtype : function()
25961 var ar = Array.prototype.slice.call(arguments, 0);
25963 for(var i = 0; i < ar.length; i++) {
25965 continue; // skip -- if this happends something invalid got sent, we
25966 // should ignore it, as basically that interface element will not show up
25967 // and that should be pretty obvious!!
25970 if (Roo.form[ar[i].xtype]) {
25972 var fe = Roo.factory(ar[i], Roo.form);
25978 fe.store.form = this;
25983 this.allItems.push(fe);
25984 if (fe.items && fe.addxtype) {
25985 fe.addxtype.apply(fe, fe.items);
25995 // console.log('adding ' + ar[i].xtype);
25997 if (ar[i].xtype == 'Button') {
25998 //console.log('adding button');
25999 //console.log(ar[i]);
26000 this.addButton(ar[i]);
26001 this.allItems.push(fe);
26005 if (ar[i].xtype == 'end') { // so we can add fieldsets... / layout etc.
26006 alert('end is not supported on xtype any more, use items');
26008 // //console.log('adding end');
26016 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
26017 * option "monitorValid"
26019 startMonitoring : function(){
26022 Roo.TaskMgr.start({
26023 run : this.bindHandler,
26024 interval : this.monitorPoll || 200,
26031 * Stops monitoring of the valid state of this form
26033 stopMonitoring : function(){
26034 this.bound = false;
26038 bindHandler : function(){
26040 return false; // stops binding
26043 this.items.each(function(f){
26044 if(!f.isValid(true)){
26049 for(var i = 0, len = this.buttons.length; i < len; i++){
26050 var btn = this.buttons[i];
26051 if(btn.formBind === true && btn.disabled === valid){
26052 btn.setDisabled(!valid);
26055 this.fireEvent('clientvalidation', this, valid);
26069 Roo.Form = Roo.form.Form;
26072 * Ext JS Library 1.1.1
26073 * Copyright(c) 2006-2007, Ext JS, LLC.
26075 * Originally Released Under LGPL - original licence link has changed is not relivant.
26078 * <script type="text/javascript">
26081 // as we use this in bootstrap.
26082 Roo.namespace('Roo.form');
26084 * @class Roo.form.Action
26085 * Internal Class used to handle form actions
26087 * @param {Roo.form.BasicForm} el The form element or its id
26088 * @param {Object} config Configuration options
26093 // define the action interface
26094 Roo.form.Action = function(form, options){
26096 this.options = options || {};
26099 * Client Validation Failed
26102 Roo.form.Action.CLIENT_INVALID = 'client';
26104 * Server Validation Failed
26107 Roo.form.Action.SERVER_INVALID = 'server';
26109 * Connect to Server Failed
26112 Roo.form.Action.CONNECT_FAILURE = 'connect';
26114 * Reading Data from Server Failed
26117 Roo.form.Action.LOAD_FAILURE = 'load';
26119 Roo.form.Action.prototype = {
26121 failureType : undefined,
26122 response : undefined,
26123 result : undefined,
26125 // interface method
26126 run : function(options){
26130 // interface method
26131 success : function(response){
26135 // interface method
26136 handleResponse : function(response){
26140 // default connection failure
26141 failure : function(response){
26143 this.response = response;
26144 this.failureType = Roo.form.Action.CONNECT_FAILURE;
26145 this.form.afterAction(this, false);
26148 processResponse : function(response){
26149 this.response = response;
26150 if(!response.responseText){
26153 this.result = this.handleResponse(response);
26154 return this.result;
26157 // utility functions used internally
26158 getUrl : function(appendParams){
26159 var url = this.options.url || this.form.url || this.form.el.dom.action;
26161 var p = this.getParams();
26163 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
26169 getMethod : function(){
26170 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
26173 getParams : function(){
26174 var bp = this.form.baseParams;
26175 var p = this.options.params;
26177 if(typeof p == "object"){
26178 p = Roo.urlEncode(Roo.applyIf(p, bp));
26179 }else if(typeof p == 'string' && bp){
26180 p += '&' + Roo.urlEncode(bp);
26183 p = Roo.urlEncode(bp);
26188 createCallback : function(){
26190 success: this.success,
26191 failure: this.failure,
26193 timeout: (this.form.timeout*1000),
26194 upload: this.form.fileUpload ? this.success : undefined
26199 Roo.form.Action.Submit = function(form, options){
26200 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
26203 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
26206 haveProgress : false,
26207 uploadComplete : false,
26209 // uploadProgress indicator.
26210 uploadProgress : function()
26212 if (!this.form.progressUrl) {
26216 if (!this.haveProgress) {
26217 Roo.MessageBox.progress("Uploading", "Uploading");
26219 if (this.uploadComplete) {
26220 Roo.MessageBox.hide();
26224 this.haveProgress = true;
26226 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
26228 var c = new Roo.data.Connection();
26230 url : this.form.progressUrl,
26235 success : function(req){
26236 //console.log(data);
26240 rdata = Roo.decode(req.responseText)
26242 Roo.log("Invalid data from server..");
26246 if (!rdata || !rdata.success) {
26248 Roo.MessageBox.alert(Roo.encode(rdata));
26251 var data = rdata.data;
26253 if (this.uploadComplete) {
26254 Roo.MessageBox.hide();
26259 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
26260 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
26263 this.uploadProgress.defer(2000,this);
26266 failure: function(data) {
26267 Roo.log('progress url failed ');
26278 // run get Values on the form, so it syncs any secondary forms.
26279 this.form.getValues();
26281 var o = this.options;
26282 var method = this.getMethod();
26283 var isPost = method == 'POST';
26284 if(o.clientValidation === false || this.form.isValid()){
26286 if (this.form.progressUrl) {
26287 this.form.findField('UPLOAD_IDENTIFIER').setValue(
26288 (new Date() * 1) + '' + Math.random());
26293 Roo.Ajax.request(Roo.apply(this.createCallback(), {
26294 form:this.form.el.dom,
26295 url:this.getUrl(!isPost),
26297 params:isPost ? this.getParams() : null,
26298 isUpload: this.form.fileUpload,
26299 formData : this.form.formData
26302 this.uploadProgress();
26304 }else if (o.clientValidation !== false){ // client validation failed
26305 this.failureType = Roo.form.Action.CLIENT_INVALID;
26306 this.form.afterAction(this, false);
26310 success : function(response)
26312 this.uploadComplete= true;
26313 if (this.haveProgress) {
26314 Roo.MessageBox.hide();
26318 var result = this.processResponse(response);
26319 if(result === true || result.success){
26320 this.form.afterAction(this, true);
26324 this.form.markInvalid(result.errors);
26325 this.failureType = Roo.form.Action.SERVER_INVALID;
26327 this.form.afterAction(this, false);
26329 failure : function(response)
26331 this.uploadComplete= true;
26332 if (this.haveProgress) {
26333 Roo.MessageBox.hide();
26336 this.response = response;
26337 this.failureType = Roo.form.Action.CONNECT_FAILURE;
26338 this.form.afterAction(this, false);
26341 handleResponse : function(response){
26342 if(this.form.errorReader){
26343 var rs = this.form.errorReader.read(response);
26346 for(var i = 0, len = rs.records.length; i < len; i++) {
26347 var r = rs.records[i];
26348 errors[i] = r.data;
26351 if(errors.length < 1){
26355 success : rs.success,
26361 ret = Roo.decode(response.responseText);
26365 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
26375 Roo.form.Action.Load = function(form, options){
26376 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
26377 this.reader = this.form.reader;
26380 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
26385 Roo.Ajax.request(Roo.apply(
26386 this.createCallback(), {
26387 method:this.getMethod(),
26388 url:this.getUrl(false),
26389 params:this.getParams()
26393 success : function(response){
26395 var result = this.processResponse(response);
26396 if(result === true || !result.success || !result.data){
26397 this.failureType = Roo.form.Action.LOAD_FAILURE;
26398 this.form.afterAction(this, false);
26401 this.form.clearInvalid();
26402 this.form.setValues(result.data);
26403 this.form.afterAction(this, true);
26406 handleResponse : function(response){
26407 if(this.form.reader){
26408 var rs = this.form.reader.read(response);
26409 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
26411 success : rs.success,
26415 return Roo.decode(response.responseText);
26419 Roo.form.Action.ACTION_TYPES = {
26420 'load' : Roo.form.Action.Load,
26421 'submit' : Roo.form.Action.Submit
26424 * Ext JS Library 1.1.1
26425 * Copyright(c) 2006-2007, Ext JS, LLC.
26427 * Originally Released Under LGPL - original licence link has changed is not relivant.
26430 * <script type="text/javascript">
26434 * @class Roo.form.Layout
26435 * @extends Roo.Component
26436 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
26438 * @param {Object} config Configuration options
26440 Roo.form.Layout = function(config){
26442 if (config.items) {
26443 xitems = config.items;
26444 delete config.items;
26446 Roo.form.Layout.superclass.constructor.call(this, config);
26448 Roo.each(xitems, this.addxtype, this);
26452 Roo.extend(Roo.form.Layout, Roo.Component, {
26454 * @cfg {String/Object} autoCreate
26455 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
26458 * @cfg {String/Object/Function} style
26459 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
26460 * a function which returns such a specification.
26463 * @cfg {String} labelAlign
26464 * Valid values are "left," "top" and "right" (defaults to "left")
26467 * @cfg {Number} labelWidth
26468 * Fixed width in pixels of all field labels (defaults to undefined)
26471 * @cfg {Boolean} clear
26472 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
26476 * @cfg {String} labelSeparator
26477 * The separator to use after field labels (defaults to ':')
26479 labelSeparator : ':',
26481 * @cfg {Boolean} hideLabels
26482 * True to suppress the display of field labels in this layout (defaults to false)
26484 hideLabels : false,
26487 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
26492 onRender : function(ct, position){
26493 if(this.el){ // from markup
26494 this.el = Roo.get(this.el);
26495 }else { // generate
26496 var cfg = this.getAutoCreate();
26497 this.el = ct.createChild(cfg, position);
26500 this.el.applyStyles(this.style);
26502 if(this.labelAlign){
26503 this.el.addClass('x-form-label-'+this.labelAlign);
26505 if(this.hideLabels){
26506 this.labelStyle = "display:none";
26507 this.elementStyle = "padding-left:0;";
26509 if(typeof this.labelWidth == 'number'){
26510 this.labelStyle = "width:"+this.labelWidth+"px;";
26511 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
26513 if(this.labelAlign == 'top'){
26514 this.labelStyle = "width:auto;";
26515 this.elementStyle = "padding-left:0;";
26518 var stack = this.stack;
26519 var slen = stack.length;
26521 if(!this.fieldTpl){
26522 var t = new Roo.Template(
26523 '<div class="x-form-item {5}">',
26524 '<label for="{0}" style="{2}">{1}{4}</label>',
26525 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
26527 '</div><div class="x-form-clear-left"></div>'
26529 t.disableFormats = true;
26531 Roo.form.Layout.prototype.fieldTpl = t;
26533 for(var i = 0; i < slen; i++) {
26534 if(stack[i].isFormField){
26535 this.renderField(stack[i]);
26537 this.renderComponent(stack[i]);
26542 this.el.createChild({cls:'x-form-clear'});
26547 renderField : function(f){
26548 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
26551 f.labelStyle||this.labelStyle||'', //2
26552 this.elementStyle||'', //3
26553 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
26554 f.itemCls||this.itemCls||'' //5
26555 ], true).getPrevSibling());
26559 renderComponent : function(c){
26560 c.render(c.isLayout ? this.el : this.el.createChild());
26563 * Adds a object form elements (using the xtype property as the factory method.)
26564 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
26565 * @param {Object} config
26567 addxtype : function(o)
26569 // create the lement.
26570 o.form = this.form;
26571 var fe = Roo.factory(o, Roo.form);
26572 this.form.allItems.push(fe);
26573 this.stack.push(fe);
26575 if (fe.isFormField) {
26576 this.form.items.add(fe);
26584 * @class Roo.form.Column
26585 * @extends Roo.form.Layout
26586 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
26588 * @param {Object} config Configuration options
26590 Roo.form.Column = function(config){
26591 Roo.form.Column.superclass.constructor.call(this, config);
26594 Roo.extend(Roo.form.Column, Roo.form.Layout, {
26596 * @cfg {Number/String} width
26597 * The fixed width of the column in pixels or CSS value (defaults to "auto")
26600 * @cfg {String/Object} autoCreate
26601 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
26605 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
26608 onRender : function(ct, position){
26609 Roo.form.Column.superclass.onRender.call(this, ct, position);
26611 this.el.setWidth(this.width);
26618 * @class Roo.form.Row
26619 * @extends Roo.form.Layout
26620 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
26622 * @param {Object} config Configuration options
26626 Roo.form.Row = function(config){
26627 Roo.form.Row.superclass.constructor.call(this, config);
26630 Roo.extend(Roo.form.Row, Roo.form.Layout, {
26632 * @cfg {Number/String} width
26633 * The fixed width of the column in pixels or CSS value (defaults to "auto")
26636 * @cfg {Number/String} height
26637 * The fixed height of the column in pixels or CSS value (defaults to "auto")
26639 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
26643 onRender : function(ct, position){
26644 //console.log('row render');
26646 var t = new Roo.Template(
26647 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
26648 '<label for="{0}" style="{2}">{1}{4}</label>',
26649 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
26653 t.disableFormats = true;
26655 Roo.form.Layout.prototype.rowTpl = t;
26657 this.fieldTpl = this.rowTpl;
26659 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
26660 var labelWidth = 100;
26662 if ((this.labelAlign != 'top')) {
26663 if (typeof this.labelWidth == 'number') {
26664 labelWidth = this.labelWidth
26666 this.padWidth = 20 + labelWidth;
26670 Roo.form.Column.superclass.onRender.call(this, ct, position);
26672 this.el.setWidth(this.width);
26675 this.el.setHeight(this.height);
26680 renderField : function(f){
26681 f.fieldEl = this.fieldTpl.append(this.el, [
26682 f.id, f.fieldLabel,
26683 f.labelStyle||this.labelStyle||'',
26684 this.elementStyle||'',
26685 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
26686 f.itemCls||this.itemCls||'',
26687 f.width ? f.width + this.padWidth : 160 + this.padWidth
26694 * @class Roo.form.FieldSet
26695 * @extends Roo.form.Layout
26696 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
26698 * @param {Object} config Configuration options
26700 Roo.form.FieldSet = function(config){
26701 Roo.form.FieldSet.superclass.constructor.call(this, config);
26704 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
26706 * @cfg {String} legend
26707 * The text to display as the legend for the FieldSet (defaults to '')
26710 * @cfg {String/Object} autoCreate
26711 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
26715 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
26718 onRender : function(ct, position){
26719 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
26721 this.setLegend(this.legend);
26726 setLegend : function(text){
26728 this.el.child('legend').update(text);
26733 * Ext JS Library 1.1.1
26734 * Copyright(c) 2006-2007, Ext JS, LLC.
26736 * Originally Released Under LGPL - original licence link has changed is not relivant.
26739 * <script type="text/javascript">
26742 * @class Roo.form.VTypes
26743 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
26746 Roo.form.VTypes = function(){
26747 // closure these in so they are only created once.
26748 var alpha = /^[a-zA-Z_]+$/;
26749 var alphanum = /^[a-zA-Z0-9_]+$/;
26750 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
26751 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
26753 // All these messages and functions are configurable
26756 * The function used to validate email addresses
26757 * @param {String} value The email address
26759 'email' : function(v){
26760 return email.test(v);
26763 * The error text to display when the email validation function returns false
26766 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
26768 * The keystroke filter mask to be applied on email input
26771 'emailMask' : /[a-z0-9_\.\-@]/i,
26774 * The function used to validate URLs
26775 * @param {String} value The URL
26777 'url' : function(v){
26778 return url.test(v);
26781 * The error text to display when the url validation function returns false
26784 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
26787 * The function used to validate alpha values
26788 * @param {String} value The value
26790 'alpha' : function(v){
26791 return alpha.test(v);
26794 * The error text to display when the alpha validation function returns false
26797 'alphaText' : 'This field should only contain letters and _',
26799 * The keystroke filter mask to be applied on alpha input
26802 'alphaMask' : /[a-z_]/i,
26805 * The function used to validate alphanumeric values
26806 * @param {String} value The value
26808 'alphanum' : function(v){
26809 return alphanum.test(v);
26812 * The error text to display when the alphanumeric validation function returns false
26815 'alphanumText' : 'This field should only contain letters, numbers and _',
26817 * The keystroke filter mask to be applied on alphanumeric input
26820 'alphanumMask' : /[a-z0-9_]/i
26822 }();//<script type="text/javascript">
26825 * @class Roo.form.FCKeditor
26826 * @extends Roo.form.TextArea
26827 * Wrapper around the FCKEditor http://www.fckeditor.net
26829 * Creates a new FCKeditor
26830 * @param {Object} config Configuration options
26832 Roo.form.FCKeditor = function(config){
26833 Roo.form.FCKeditor.superclass.constructor.call(this, config);
26836 * @event editorinit
26837 * Fired when the editor is initialized - you can add extra handlers here..
26838 * @param {FCKeditor} this
26839 * @param {Object} the FCK object.
26846 Roo.form.FCKeditor.editors = { };
26847 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
26849 //defaultAutoCreate : {
26850 // tag : "textarea",style : "width:100px;height:60px;" ,autocomplete : "off"
26854 * @cfg {Object} fck options - see fck manual for details.
26859 * @cfg {Object} fck toolbar set (Basic or Default)
26861 toolbarSet : 'Basic',
26863 * @cfg {Object} fck BasePath
26865 basePath : '/fckeditor/',
26873 onRender : function(ct, position)
26876 this.defaultAutoCreate = {
26878 style:"width:300px;height:60px;",
26879 autocomplete: "new-password"
26882 Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
26885 this.textSizeEl = Roo.DomHelper.append(document.body, {tag: "pre", cls: "x-form-grow-sizer"});
26886 if(this.preventScrollbars){
26887 this.el.setStyle("overflow", "hidden");
26889 this.el.setHeight(this.growMin);
26892 //console.log('onrender' + this.getId() );
26893 Roo.form.FCKeditor.editors[this.getId()] = this;
26896 this.replaceTextarea() ;
26900 getEditor : function() {
26901 return this.fckEditor;
26904 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
26905 * @param {Mixed} value The value to set
26909 setValue : function(value)
26911 //console.log('setValue: ' + value);
26913 if(typeof(value) == 'undefined') { // not sure why this is happending...
26916 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
26918 //if(!this.el || !this.getEditor()) {
26919 // this.value = value;
26920 //this.setValue.defer(100,this,[value]);
26924 if(!this.getEditor()) {
26928 this.getEditor().SetData(value);
26935 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
26936 * @return {Mixed} value The field value
26938 getValue : function()
26941 if (this.frame && this.frame.dom.style.display == 'none') {
26942 return Roo.form.FCKeditor.superclass.getValue.call(this);
26945 if(!this.el || !this.getEditor()) {
26947 // this.getValue.defer(100,this);
26952 var value=this.getEditor().GetData();
26953 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
26954 return Roo.form.FCKeditor.superclass.getValue.call(this);
26960 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
26961 * @return {Mixed} value The field value
26963 getRawValue : function()
26965 if (this.frame && this.frame.dom.style.display == 'none') {
26966 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
26969 if(!this.el || !this.getEditor()) {
26970 //this.getRawValue.defer(100,this);
26977 var value=this.getEditor().GetData();
26978 Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
26979 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
26983 setSize : function(w,h) {
26987 //if (this.frame && this.frame.dom.style.display == 'none') {
26988 // Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
26991 //if(!this.el || !this.getEditor()) {
26992 // this.setSize.defer(100,this, [w,h]);
26998 Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
27000 this.frame.dom.setAttribute('width', w);
27001 this.frame.dom.setAttribute('height', h);
27002 this.frame.setSize(w,h);
27006 toggleSourceEdit : function(value) {
27010 this.el.dom.style.display = value ? '' : 'none';
27011 this.frame.dom.style.display = value ? 'none' : '';
27016 focus: function(tag)
27018 if (this.frame.dom.style.display == 'none') {
27019 return Roo.form.FCKeditor.superclass.focus.call(this);
27021 if(!this.el || !this.getEditor()) {
27022 this.focus.defer(100,this, [tag]);
27029 var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
27030 this.getEditor().Focus();
27032 if (!this.getEditor().Selection.GetSelection()) {
27033 this.focus.defer(100,this, [tag]);
27038 var r = this.getEditor().EditorDocument.createRange();
27039 r.setStart(tgs[0],0);
27040 r.setEnd(tgs[0],0);
27041 this.getEditor().Selection.GetSelection().removeAllRanges();
27042 this.getEditor().Selection.GetSelection().addRange(r);
27043 this.getEditor().Focus();
27050 replaceTextarea : function()
27052 if ( document.getElementById( this.getId() + '___Frame' ) ) {
27055 //if ( !this.checkBrowser || this._isCompatibleBrowser() )
27057 // We must check the elements firstly using the Id and then the name.
27058 var oTextarea = document.getElementById( this.getId() );
27060 var colElementsByName = document.getElementsByName( this.getId() ) ;
27062 oTextarea.style.display = 'none' ;
27064 if ( oTextarea.tabIndex ) {
27065 this.TabIndex = oTextarea.tabIndex ;
27068 this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
27069 this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
27070 this.frame = Roo.get(this.getId() + '___Frame')
27073 _getConfigHtml : function()
27077 for ( var o in this.fckconfig ) {
27078 sConfig += sConfig.length > 0 ? '&' : '';
27079 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
27082 return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
27086 _getIFrameHtml : function()
27088 var sFile = 'fckeditor.html' ;
27089 /* no idea what this is about..
27092 if ( (/fcksource=true/i).test( window.top.location.search ) )
27093 sFile = 'fckeditor.original.html' ;
27098 var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
27099 sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
27102 var html = '<iframe id="' + this.getId() +
27103 '___Frame" src="' + sLink +
27104 '" width="' + this.width +
27105 '" height="' + this.height + '"' +
27106 (this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
27107 ' frameborder="0" scrolling="no"></iframe>' ;
27112 _insertHtmlBefore : function( html, element )
27114 if ( element.insertAdjacentHTML ) {
27116 element.insertAdjacentHTML( 'beforeBegin', html ) ;
27118 var oRange = document.createRange() ;
27119 oRange.setStartBefore( element ) ;
27120 var oFragment = oRange.createContextualFragment( html );
27121 element.parentNode.insertBefore( oFragment, element ) ;
27134 //Roo.reg('fckeditor', Roo.form.FCKeditor);
27136 function FCKeditor_OnComplete(editorInstance){
27137 var f = Roo.form.FCKeditor.editors[editorInstance.Name];
27138 f.fckEditor = editorInstance;
27139 //console.log("loaded");
27140 f.fireEvent('editorinit', f, editorInstance);
27160 //<script type="text/javascript">
27162 * @class Roo.form.GridField
27163 * @extends Roo.form.Field
27164 * Embed a grid (or editable grid into a form)
27167 * This embeds a grid in a form, the value of the field should be the json encoded array of rows
27169 * xgrid.store = Roo.data.Store
27170 * xgrid.store.proxy = Roo.data.MemoryProxy (data = [] )
27171 * xgrid.store.reader = Roo.data.JsonReader
27175 * Creates a new GridField
27176 * @param {Object} config Configuration options
27178 Roo.form.GridField = function(config){
27179 Roo.form.GridField.superclass.constructor.call(this, config);
27183 Roo.extend(Roo.form.GridField, Roo.form.Field, {
27185 * @cfg {Number} width - used to restrict width of grid..
27189 * @cfg {Number} height - used to restrict height of grid..
27193 * @cfg {Object} xgrid (xtype'd description of grid) { xtype : 'Grid', dataSource: .... }
27199 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27200 * {tag: "input", type: "checkbox", autocomplete: "off"})
27202 // defaultAutoCreate : { tag: 'div' },
27203 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'new-password'},
27205 * @cfg {String} addTitle Text to include for adding a title.
27209 onResize : function(){
27210 Roo.form.Field.superclass.onResize.apply(this, arguments);
27213 initEvents : function(){
27214 // Roo.form.Checkbox.superclass.initEvents.call(this);
27215 // has no events...
27220 getResizeEl : function(){
27224 getPositionEl : function(){
27229 onRender : function(ct, position){
27231 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
27232 var style = this.style;
27235 Roo.form.GridField.superclass.onRender.call(this, ct, position);
27236 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
27237 this.viewEl = this.wrap.createChild({ tag: 'div' });
27239 this.viewEl.applyStyles(style);
27242 this.viewEl.setWidth(this.width);
27245 this.viewEl.setHeight(this.height);
27247 //if(this.inputValue !== undefined){
27248 //this.setValue(this.value);
27251 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
27254 this.grid.render();
27255 this.grid.getDataSource().on('remove', this.refreshValue, this);
27256 this.grid.getDataSource().on('update', this.refreshValue, this);
27257 this.grid.on('afteredit', this.refreshValue, this);
27263 * Sets the value of the item.
27264 * @param {String} either an object or a string..
27266 setValue : function(v){
27268 v = v || []; // empty set..
27269 // this does not seem smart - it really only affects memoryproxy grids..
27270 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
27271 var ds = this.grid.getDataSource();
27272 // assumes a json reader..
27274 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
27275 ds.loadData( data);
27277 // clear selection so it does not get stale.
27278 if (this.grid.sm) {
27279 this.grid.sm.clearSelections();
27282 Roo.form.GridField.superclass.setValue.call(this, v);
27283 this.refreshValue();
27284 // should load data in the grid really....
27288 refreshValue: function() {
27290 this.grid.getDataSource().each(function(r) {
27293 this.el.dom.value = Roo.encode(val);
27301 * Ext JS Library 1.1.1
27302 * Copyright(c) 2006-2007, Ext JS, LLC.
27304 * Originally Released Under LGPL - original licence link has changed is not relivant.
27307 * <script type="text/javascript">
27310 * @class Roo.form.DisplayField
27311 * @extends Roo.form.Field
27312 * A generic Field to display non-editable data.
27313 * @cfg {Boolean} closable (true|false) default false
27315 * Creates a new Display Field item.
27316 * @param {Object} config Configuration options
27318 Roo.form.DisplayField = function(config){
27319 Roo.form.DisplayField.superclass.constructor.call(this, config);
27324 * Fires after the click the close btn
27325 * @param {Roo.form.DisplayField} this
27331 Roo.extend(Roo.form.DisplayField, Roo.form.TextField, {
27332 inputType: 'hidden',
27338 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
27340 focusClass : undefined,
27342 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
27344 fieldClass: 'x-form-field',
27347 * @cfg {Function} valueRenderer The renderer for the field (so you can reformat output). should return raw HTML
27349 valueRenderer: undefined,
27353 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27354 * {tag: "input", type: "checkbox", autocomplete: "off"})
27357 // defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
27361 onResize : function(){
27362 Roo.form.DisplayField.superclass.onResize.apply(this, arguments);
27366 initEvents : function(){
27367 // Roo.form.Checkbox.superclass.initEvents.call(this);
27368 // has no events...
27371 this.closeEl.on('click', this.onClose, this);
27377 getResizeEl : function(){
27381 getPositionEl : function(){
27386 onRender : function(ct, position){
27388 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
27389 //if(this.inputValue !== undefined){
27390 this.wrap = this.el.wrap();
27392 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
27395 this.closeEl = this.wrap.createChild({ tag: 'div', cls: 'x-dlg-close'});
27398 if (this.bodyStyle) {
27399 this.viewEl.applyStyles(this.bodyStyle);
27401 //this.viewEl.setStyle('padding', '2px');
27403 this.setValue(this.value);
27408 initValue : Roo.emptyFn,
27413 onClick : function(){
27418 * Sets the checked state of the checkbox.
27419 * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
27421 setValue : function(v){
27423 var html = this.valueRenderer ? this.valueRenderer(v) : String.format('{0}', v);
27424 // this might be called before we have a dom element..
27425 if (!this.viewEl) {
27428 this.viewEl.dom.innerHTML = html;
27429 Roo.form.DisplayField.superclass.setValue.call(this, v);
27433 onClose : function(e)
27435 e.preventDefault();
27437 this.fireEvent('close', this);
27446 * @class Roo.form.DayPicker
27447 * @extends Roo.form.Field
27448 * A Day picker show [M] [T] [W] ....
27450 * Creates a new Day Picker
27451 * @param {Object} config Configuration options
27453 Roo.form.DayPicker= function(config){
27454 Roo.form.DayPicker.superclass.constructor.call(this, config);
27458 Roo.extend(Roo.form.DayPicker, Roo.form.Field, {
27460 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
27462 focusClass : undefined,
27464 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
27466 fieldClass: "x-form-field",
27469 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27470 * {tag: "input", type: "checkbox", autocomplete: "off"})
27472 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "new-password"},
27475 actionMode : 'viewEl',
27479 inputType : 'hidden',
27482 inputElement: false, // real input element?
27483 basedOn: false, // ????
27485 isFormField: true, // not sure where this is needed!!!!
27487 onResize : function(){
27488 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
27489 if(!this.boxLabel){
27490 this.el.alignTo(this.wrap, 'c-c');
27494 initEvents : function(){
27495 Roo.form.Checkbox.superclass.initEvents.call(this);
27496 this.el.on("click", this.onClick, this);
27497 this.el.on("change", this.onClick, this);
27501 getResizeEl : function(){
27505 getPositionEl : function(){
27511 onRender : function(ct, position){
27512 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
27514 this.wrap = this.el.wrap({cls: 'x-form-daypick-item '});
27516 var r1 = '<table><tr>';
27517 var r2 = '<tr class="x-form-daypick-icons">';
27518 for (var i=0; i < 7; i++) {
27519 r1+= '<td><div>' + Date.dayNames[i].substring(0,3) + '</div></td>';
27520 r2+= '<td><img class="x-menu-item-icon" src="' + Roo.BLANK_IMAGE_URL +'"></td>';
27523 var viewEl = this.wrap.createChild( r1 + '</tr>' + r2 + '</tr></table>');
27524 viewEl.select('img').on('click', this.onClick, this);
27525 this.viewEl = viewEl;
27528 // this will not work on Chrome!!!
27529 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
27530 this.el.on('propertychange', this.setFromHidden, this); //ie
27538 initValue : Roo.emptyFn,
27541 * Returns the checked state of the checkbox.
27542 * @return {Boolean} True if checked, else false
27544 getValue : function(){
27545 return this.el.dom.value;
27550 onClick : function(e){
27551 //this.setChecked(!this.checked);
27552 Roo.get(e.target).toggleClass('x-menu-item-checked');
27553 this.refreshValue();
27554 //if(this.el.dom.checked != this.checked){
27555 // this.setValue(this.el.dom.checked);
27560 refreshValue : function()
27563 this.viewEl.select('img',true).each(function(e,i,n) {
27564 val += e.is(".x-menu-item-checked") ? String(n) : '';
27566 this.setValue(val, true);
27570 * Sets the checked state of the checkbox.
27571 * On is always based on a string comparison between inputValue and the param.
27572 * @param {Boolean/String} value - the value to set
27573 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
27575 setValue : function(v,suppressEvent){
27576 if (!this.el.dom) {
27579 var old = this.el.dom.value ;
27580 this.el.dom.value = v;
27581 if (suppressEvent) {
27585 // update display..
27586 this.viewEl.select('img',true).each(function(e,i,n) {
27588 var on = e.is(".x-menu-item-checked");
27589 var newv = v.indexOf(String(n)) > -1;
27591 e.toggleClass('x-menu-item-checked');
27597 this.fireEvent('change', this, v, old);
27602 // handle setting of hidden value by some other method!!?!?
27603 setFromHidden: function()
27608 //console.log("SET FROM HIDDEN");
27609 //alert('setFrom hidden');
27610 this.setValue(this.el.dom.value);
27613 onDestroy : function()
27616 Roo.get(this.viewEl).remove();
27619 Roo.form.DayPicker.superclass.onDestroy.call(this);
27623 * RooJS Library 1.1.1
27624 * Copyright(c) 2008-2011 Alan Knowles
27631 * @class Roo.form.ComboCheck
27632 * @extends Roo.form.ComboBox
27633 * A combobox for multiple select items.
27635 * FIXME - could do with a reset button..
27638 * Create a new ComboCheck
27639 * @param {Object} config Configuration options
27641 Roo.form.ComboCheck = function(config){
27642 Roo.form.ComboCheck.superclass.constructor.call(this, config);
27643 // should verify some data...
27645 // hiddenName = required..
27646 // displayField = required
27647 // valudField == required
27648 var req= [ 'hiddenName', 'displayField', 'valueField' ];
27650 Roo.each(req, function(e) {
27651 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
27652 throw "Roo.form.ComboCheck : missing value for: " + e;
27659 Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
27664 selectedClass: 'x-menu-item-checked',
27667 onRender : function(ct, position){
27673 var cls = 'x-combo-list';
27676 this.tpl = new Roo.Template({
27677 html : '<div class="'+cls+'-item x-menu-check-item">' +
27678 '<img class="x-menu-item-icon" style="margin: 0px;" src="' + Roo.BLANK_IMAGE_URL + '">' +
27679 '<span>{' + this.displayField + '}</span>' +
27686 Roo.form.ComboCheck.superclass.onRender.call(this, ct, position);
27687 this.view.singleSelect = false;
27688 this.view.multiSelect = true;
27689 this.view.toggleSelect = true;
27690 this.pageTb.add(new Roo.Toolbar.Fill(), {
27693 handler: function()
27700 onViewOver : function(e, t){
27706 onViewClick : function(doFocus,index){
27710 select: function () {
27711 //Roo.log("SELECT CALLED");
27714 selectByValue : function(xv, scrollIntoView){
27715 var ar = this.getValueArray();
27718 Roo.each(ar, function(v) {
27719 if(v === undefined || v === null){
27722 var r = this.findRecord(this.valueField, v);
27724 sels.push(this.store.indexOf(r))
27728 this.view.select(sels);
27734 onSelect : function(record, index){
27735 // Roo.log("onselect Called");
27736 // this is only called by the clear button now..
27737 this.view.clearSelections();
27738 this.setValue('[]');
27739 if (this.value != this.valueBefore) {
27740 this.fireEvent('change', this, this.value, this.valueBefore);
27741 this.valueBefore = this.value;
27744 getValueArray : function()
27749 //Roo.log(this.value);
27750 if (typeof(this.value) == 'undefined') {
27753 var ar = Roo.decode(this.value);
27754 return ar instanceof Array ? ar : []; //?? valid?
27757 Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
27762 expand : function ()
27765 Roo.form.ComboCheck.superclass.expand.call(this);
27766 this.valueBefore = typeof(this.value) == 'undefined' ? '' : this.value;
27767 //this.valueBefore = typeof(this.valueBefore) == 'undefined' ? '' : this.valueBefore;
27772 collapse : function(){
27773 Roo.form.ComboCheck.superclass.collapse.call(this);
27774 var sl = this.view.getSelectedIndexes();
27775 var st = this.store;
27779 Roo.each(sl, function(i) {
27781 nv.push(r.get(this.valueField));
27783 this.setValue(Roo.encode(nv));
27784 if (this.value != this.valueBefore) {
27786 this.fireEvent('change', this, this.value, this.valueBefore);
27787 this.valueBefore = this.value;
27792 setValue : function(v){
27796 var vals = this.getValueArray();
27798 Roo.each(vals, function(k) {
27799 var r = this.findRecord(this.valueField, k);
27801 tv.push(r.data[this.displayField]);
27802 }else if(this.valueNotFoundText !== undefined){
27803 tv.push( this.valueNotFoundText );
27808 Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
27809 this.hiddenField.value = v;
27815 * Ext JS Library 1.1.1
27816 * Copyright(c) 2006-2007, Ext JS, LLC.
27818 * Originally Released Under LGPL - original licence link has changed is not relivant.
27821 * <script type="text/javascript">
27825 * @class Roo.form.Signature
27826 * @extends Roo.form.Field
27830 * @param {Object} config Configuration options
27833 Roo.form.Signature = function(config){
27834 Roo.form.Signature.superclass.constructor.call(this, config);
27836 this.addEvents({// not in used??
27839 * Fires when the 'confirm' icon is pressed (add a listener to enable add button)
27840 * @param {Roo.form.Signature} combo This combo box
27845 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
27846 * @param {Roo.form.ComboBox} combo This combo box
27847 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
27853 Roo.extend(Roo.form.Signature, Roo.form.Field, {
27855 * @cfg {Object} labels Label to use when rendering a form.
27859 * confirm : "Confirm"
27864 confirm : "Confirm"
27867 * @cfg {Number} width The signature panel width (defaults to 300)
27871 * @cfg {Number} height The signature panel height (defaults to 100)
27875 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to false)
27877 allowBlank : false,
27880 // {Object} signPanel The signature SVG panel element (defaults to {})
27882 // {Boolean} isMouseDown False to validate that the mouse down event (defaults to false)
27883 isMouseDown : false,
27884 // {Boolean} isConfirmed validate the signature is confirmed or not for submitting form (defaults to false)
27885 isConfirmed : false,
27886 // {String} signatureTmp SVG mapping string (defaults to empty string)
27890 defaultAutoCreate : { // modified by initCompnoent..
27896 onRender : function(ct, position){
27898 Roo.form.Signature.superclass.onRender.call(this, ct, position);
27900 this.wrap = this.el.wrap({
27901 cls:'x-form-signature-wrap', style : 'width: ' + this.width + 'px', cn:{cls:'x-form-signature'}
27904 this.createToolbar(this);
27905 this.signPanel = this.wrap.createChild({
27907 style: 'width: ' + this.width + 'px; height: ' + this.height + 'px; border: 0;'
27911 this.svgID = Roo.id();
27912 this.svgEl = this.signPanel.createChild({
27913 xmlns : 'http://www.w3.org/2000/svg',
27915 id : this.svgID + "-svg",
27917 height: this.height,
27918 viewBox: '0 0 '+this.width+' '+this.height,
27922 id: this.svgID + "-svg-r",
27924 height: this.height,
27929 id: this.svgID + "-svg-l",
27931 y1: (this.height*0.8), // start set the line in 80% of height
27932 x2: this.width, // end
27933 y2: (this.height*0.8), // end set the line in 80% of height
27935 'stroke-width': "1",
27936 'stroke-dasharray': "3",
27937 'shape-rendering': "crispEdges",
27938 'pointer-events': "none"
27942 id: this.svgID + "-svg-p",
27944 'stroke-width': "3",
27946 'pointer-events': 'none'
27951 this.svgBox = this.svgEl.dom.getScreenCTM();
27953 createSVG : function(){
27954 var svg = this.signPanel;
27955 var r = svg.select('#'+ this.svgID + '-svg-r', true).first().dom;
27958 r.addEventListener('mousedown', function(e) { return t.down(e); }, false);
27959 r.addEventListener('mousemove', function(e) { return t.move(e); }, false);
27960 r.addEventListener('mouseup', function(e) { return t.up(e); }, false);
27961 r.addEventListener('mouseout', function(e) { return t.up(e); }, false);
27962 r.addEventListener('touchstart', function(e) { return t.down(e); }, false);
27963 r.addEventListener('touchmove', function(e) { return t.move(e); }, false);
27964 r.addEventListener('touchend', function(e) { return t.up(e); }, false);
27967 isTouchEvent : function(e){
27968 return e.type.match(/^touch/);
27970 getCoords : function (e) {
27971 var pt = this.svgEl.dom.createSVGPoint();
27974 if (this.isTouchEvent(e)) {
27975 pt.x = e.targetTouches[0].clientX;
27976 pt.y = e.targetTouches[0].clientY;
27978 var a = this.svgEl.dom.getScreenCTM();
27979 var b = a.inverse();
27980 var mx = pt.matrixTransform(b);
27981 return mx.x + ',' + mx.y;
27983 //mouse event headler
27984 down : function (e) {
27985 this.signatureTmp += 'M' + this.getCoords(e) + ' ';
27986 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr('d', this.signatureTmp);
27988 this.isMouseDown = true;
27990 e.preventDefault();
27992 move : function (e) {
27993 if (this.isMouseDown) {
27994 this.signatureTmp += 'L' + this.getCoords(e) + ' ';
27995 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', this.signatureTmp);
27998 e.preventDefault();
28000 up : function (e) {
28001 this.isMouseDown = false;
28002 var sp = this.signatureTmp.split(' ');
28005 if(!sp[sp.length-2].match(/^L/)){
28009 this.signatureTmp = sp.join(" ");
28012 if(this.getValue() != this.signatureTmp){
28013 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
28014 this.isConfirmed = false;
28016 e.preventDefault();
28020 * Protected method that will not generally be called directly. It
28021 * is called when the editor creates its toolbar. Override this method if you need to
28022 * add custom toolbar buttons.
28023 * @param {HtmlEditor} editor
28025 createToolbar : function(editor){
28026 function btn(id, toggle, handler){
28027 var xid = fid + '-'+ id ;
28031 cls : 'x-btn-icon x-edit-'+id,
28032 enableToggle:toggle !== false,
28033 scope: editor, // was editor...
28034 handler:handler||editor.relayBtnCmd,
28035 clickEvent:'mousedown',
28036 tooltip: etb.buttonTips[id] || undefined, ///tips ???
28042 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
28046 cls : ' x-signature-btn x-signature-'+id,
28047 scope: editor, // was editor...
28048 handler: this.reset,
28049 clickEvent:'mousedown',
28050 text: this.labels.clear
28057 cls : ' x-signature-btn x-signature-'+id,
28058 scope: editor, // was editor...
28059 handler: this.confirmHandler,
28060 clickEvent:'mousedown',
28061 text: this.labels.confirm
28068 * when user is clicked confirm then show this image.....
28070 * @return {String} Image Data URI
28072 getImageDataURI : function(){
28073 var svg = this.svgEl.dom.parentNode.innerHTML;
28074 var src = 'data:image/svg+xml;base64,'+window.btoa(svg);
28079 * @return {Boolean} this.isConfirmed
28081 getConfirmed : function(){
28082 return this.isConfirmed;
28086 * @return {Number} this.width
28088 getWidth : function(){
28093 * @return {Number} this.height
28095 getHeight : function(){
28096 return this.height;
28099 getSignature : function(){
28100 return this.signatureTmp;
28103 reset : function(){
28104 this.signatureTmp = '';
28105 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
28106 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', '');
28107 this.isConfirmed = false;
28108 Roo.form.Signature.superclass.reset.call(this);
28110 setSignature : function(s){
28111 this.signatureTmp = s;
28112 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
28113 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', s);
28115 this.isConfirmed = false;
28116 Roo.form.Signature.superclass.reset.call(this);
28119 // Roo.log(this.signPanel.dom.contentWindow.up())
28122 setConfirmed : function(){
28126 // Roo.log(Roo.get(this.signPanel.dom.contentWindow.r).attr('fill', '#cfc'));
28129 confirmHandler : function(){
28130 if(!this.getSignature()){
28134 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#cfc');
28135 this.setValue(this.getSignature());
28136 this.isConfirmed = true;
28138 this.fireEvent('confirm', this);
28141 // Subclasses should provide the validation implementation by overriding this
28142 validateValue : function(value){
28143 if(this.allowBlank){
28147 if(this.isConfirmed){
28154 * Ext JS Library 1.1.1
28155 * Copyright(c) 2006-2007, Ext JS, LLC.
28157 * Originally Released Under LGPL - original licence link has changed is not relivant.
28160 * <script type="text/javascript">
28165 * @class Roo.form.ComboBox
28166 * @extends Roo.form.TriggerField
28167 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
28169 * Create a new ComboBox.
28170 * @param {Object} config Configuration options
28172 Roo.form.Select = function(config){
28173 Roo.form.Select.superclass.constructor.call(this, config);
28177 Roo.extend(Roo.form.Select , Roo.form.ComboBox, {
28179 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
28182 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
28183 * rendering into an Roo.Editor, defaults to false)
28186 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
28187 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
28190 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
28193 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
28194 * the dropdown list (defaults to undefined, with no header element)
28198 * @cfg {String/Roo.Template} tpl The template to use to render the output
28202 defaultAutoCreate : {tag: "select" },
28204 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
28206 listWidth: undefined,
28208 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
28209 * mode = 'remote' or 'text' if mode = 'local')
28211 displayField: undefined,
28213 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
28214 * mode = 'remote' or 'value' if mode = 'local').
28215 * Note: use of a valueField requires the user make a selection
28216 * in order for a value to be mapped.
28218 valueField: undefined,
28222 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
28223 * field's data value (defaults to the underlying DOM element's name)
28225 hiddenName: undefined,
28227 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
28231 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
28233 selectedClass: 'x-combo-selected',
28235 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
28236 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
28237 * which displays a downward arrow icon).
28239 triggerClass : 'x-form-arrow-trigger',
28241 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
28245 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
28246 * anchor positions (defaults to 'tl-bl')
28248 listAlign: 'tl-bl?',
28250 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
28254 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
28255 * query specified by the allQuery config option (defaults to 'query')
28257 triggerAction: 'query',
28259 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
28260 * (defaults to 4, does not apply if editable = false)
28264 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
28265 * delay (typeAheadDelay) if it matches a known value (defaults to false)
28269 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
28270 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
28274 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
28275 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
28279 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
28280 * when editable = true (defaults to false)
28282 selectOnFocus:false,
28284 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
28286 queryParam: 'query',
28288 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
28289 * when mode = 'remote' (defaults to 'Loading...')
28291 loadingText: 'Loading...',
28293 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
28297 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
28301 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
28302 * traditional select (defaults to true)
28306 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
28310 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
28314 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
28315 * listWidth has a higher value)
28319 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
28320 * allow the user to set arbitrary text into the field (defaults to false)
28322 forceSelection:false,
28324 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
28325 * if typeAhead = true (defaults to 250)
28327 typeAheadDelay : 250,
28329 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
28330 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
28332 valueNotFoundText : undefined,
28335 * @cfg {String} defaultValue The value displayed after loading the store.
28340 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
28342 blockFocus : false,
28345 * @cfg {Boolean} disableClear Disable showing of clear button.
28347 disableClear : false,
28349 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
28351 alwaysQuery : false,
28357 // element that contains real text value.. (when hidden is used..)
28360 onRender : function(ct, position){
28361 Roo.form.Field.prototype.onRender.call(this, ct, position);
28364 this.store.on('beforeload', this.onBeforeLoad, this);
28365 this.store.on('load', this.onLoad, this);
28366 this.store.on('loadexception', this.onLoadException, this);
28367 this.store.load({});
28375 initEvents : function(){
28376 //Roo.form.ComboBox.superclass.initEvents.call(this);
28380 onDestroy : function(){
28383 this.store.un('beforeload', this.onBeforeLoad, this);
28384 this.store.un('load', this.onLoad, this);
28385 this.store.un('loadexception', this.onLoadException, this);
28387 //Roo.form.ComboBox.superclass.onDestroy.call(this);
28391 fireKey : function(e){
28392 if(e.isNavKeyPress() && !this.list.isVisible()){
28393 this.fireEvent("specialkey", this, e);
28398 onResize: function(w, h){
28406 * Allow or prevent the user from directly editing the field text. If false is passed,
28407 * the user will only be able to select from the items defined in the dropdown list. This method
28408 * is the runtime equivalent of setting the 'editable' config option at config time.
28409 * @param {Boolean} value True to allow the user to directly edit the field text
28411 setEditable : function(value){
28416 onBeforeLoad : function(){
28418 Roo.log("Select before load");
28421 this.innerList.update(this.loadingText ?
28422 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
28423 //this.restrictHeight();
28424 this.selectedIndex = -1;
28428 onLoad : function(){
28431 var dom = this.el.dom;
28432 dom.innerHTML = '';
28433 var od = dom.ownerDocument;
28435 if (this.emptyText) {
28436 var op = od.createElement('option');
28437 op.setAttribute('value', '');
28438 op.innerHTML = String.format('{0}', this.emptyText);
28439 dom.appendChild(op);
28441 if(this.store.getCount() > 0){
28443 var vf = this.valueField;
28444 var df = this.displayField;
28445 this.store.data.each(function(r) {
28446 // which colmsn to use... testing - cdoe / title..
28447 var op = od.createElement('option');
28448 op.setAttribute('value', r.data[vf]);
28449 op.innerHTML = String.format('{0}', r.data[df]);
28450 dom.appendChild(op);
28452 if (typeof(this.defaultValue != 'undefined')) {
28453 this.setValue(this.defaultValue);
28458 //this.onEmptyResults();
28463 onLoadException : function()
28465 dom.innerHTML = '';
28467 Roo.log("Select on load exception");
28471 Roo.log(this.store.reader.jsonData);
28472 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
28473 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
28479 onTypeAhead : function(){
28484 onSelect : function(record, index){
28485 Roo.log('on select?');
28487 if(this.fireEvent('beforeselect', this, record, index) !== false){
28488 this.setFromData(index > -1 ? record.data : false);
28490 this.fireEvent('select', this, record, index);
28495 * Returns the currently selected field value or empty string if no value is set.
28496 * @return {String} value The selected value
28498 getValue : function(){
28499 var dom = this.el.dom;
28500 this.value = dom.options[dom.selectedIndex].value;
28506 * Clears any text/value currently set in the field
28508 clearValue : function(){
28510 this.el.dom.selectedIndex = this.emptyText ? 0 : -1;
28515 * Sets the specified value into the field. If the value finds a match, the corresponding record text
28516 * will be displayed in the field. If the value does not match the data value of an existing item,
28517 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
28518 * Otherwise the field will be blank (although the value will still be set).
28519 * @param {String} value The value to match
28521 setValue : function(v){
28522 var d = this.el.dom;
28523 for (var i =0; i < d.options.length;i++) {
28524 if (v == d.options[i].value) {
28525 d.selectedIndex = i;
28533 * @property {Object} the last set data for the element
28538 * Sets the value of the field based on a object which is related to the record format for the store.
28539 * @param {Object} value the value to set as. or false on reset?
28541 setFromData : function(o){
28542 Roo.log('setfrom data?');
28548 reset : function(){
28552 findRecord : function(prop, value){
28557 if(this.store.getCount() > 0){
28558 this.store.each(function(r){
28559 if(r.data[prop] == value){
28569 getName: function()
28571 // returns hidden if it's set..
28572 if (!this.rendered) {return ''};
28573 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
28581 onEmptyResults : function(){
28582 Roo.log('empty results');
28587 * Returns true if the dropdown list is expanded, else false.
28589 isExpanded : function(){
28594 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
28595 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
28596 * @param {String} value The data value of the item to select
28597 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
28598 * selected item if it is not currently in view (defaults to true)
28599 * @return {Boolean} True if the value matched an item in the list, else false
28601 selectByValue : function(v, scrollIntoView){
28602 Roo.log('select By Value');
28605 if(v !== undefined && v !== null){
28606 var r = this.findRecord(this.valueField || this.displayField, v);
28608 this.select(this.store.indexOf(r), scrollIntoView);
28616 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
28617 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
28618 * @param {Number} index The zero-based index of the list item to select
28619 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
28620 * selected item if it is not currently in view (defaults to true)
28622 select : function(index, scrollIntoView){
28623 Roo.log('select ');
28626 this.selectedIndex = index;
28627 this.view.select(index);
28628 if(scrollIntoView !== false){
28629 var el = this.view.getNode(index);
28631 this.innerList.scrollChildIntoView(el, false);
28639 validateBlur : function(){
28646 initQuery : function(){
28647 this.doQuery(this.getRawValue());
28651 doForce : function(){
28652 if(this.el.dom.value.length > 0){
28653 this.el.dom.value =
28654 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
28660 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
28661 * query allowing the query action to be canceled if needed.
28662 * @param {String} query The SQL query to execute
28663 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
28664 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
28665 * saved in the current store (defaults to false)
28667 doQuery : function(q, forceAll){
28669 Roo.log('doQuery?');
28670 if(q === undefined || q === null){
28675 forceAll: forceAll,
28679 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
28683 forceAll = qe.forceAll;
28684 if(forceAll === true || (q.length >= this.minChars)){
28685 if(this.lastQuery != q || this.alwaysQuery){
28686 this.lastQuery = q;
28687 if(this.mode == 'local'){
28688 this.selectedIndex = -1;
28690 this.store.clearFilter();
28692 this.store.filter(this.displayField, q);
28696 this.store.baseParams[this.queryParam] = q;
28698 params: this.getParams(q)
28703 this.selectedIndex = -1;
28710 getParams : function(q){
28712 //p[this.queryParam] = q;
28715 p.limit = this.pageSize;
28721 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
28723 collapse : function(){
28728 collapseIf : function(e){
28733 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
28735 expand : function(){
28743 * @cfg {Boolean} grow
28747 * @cfg {Number} growMin
28751 * @cfg {Number} growMax
28759 setWidth : function()
28763 getResizeEl : function(){
28766 });//<script type="text/javasscript">
28770 * @class Roo.DDView
28771 * A DnD enabled version of Roo.View.
28772 * @param {Element/String} container The Element in which to create the View.
28773 * @param {String} tpl The template string used to create the markup for each element of the View
28774 * @param {Object} config The configuration properties. These include all the config options of
28775 * {@link Roo.View} plus some specific to this class.<br>
28777 * Drag/drop is implemented by adding {@link Roo.data.Record}s to the target DDView. If copying is
28778 * not being performed, the original {@link Roo.data.Record} is removed from the source DDView.<br>
28780 * The following extra CSS rules are needed to provide insertion point highlighting:<pre><code>
28781 .x-view-drag-insert-above {
28782 border-top:1px dotted #3366cc;
28784 .x-view-drag-insert-below {
28785 border-bottom:1px dotted #3366cc;
28791 Roo.DDView = function(container, tpl, config) {
28792 Roo.DDView.superclass.constructor.apply(this, arguments);
28793 this.getEl().setStyle("outline", "0px none");
28794 this.getEl().unselectable();
28795 if (this.dragGroup) {
28796 this.setDraggable(this.dragGroup.split(","));
28798 if (this.dropGroup) {
28799 this.setDroppable(this.dropGroup.split(","));
28801 if (this.deletable) {
28802 this.setDeletable();
28804 this.isDirtyFlag = false;
28810 Roo.extend(Roo.DDView, Roo.View, {
28811 /** @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone. */
28812 /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
28813 /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
28814 /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
28818 reset: Roo.emptyFn,
28820 clearInvalid: Roo.form.Field.prototype.clearInvalid,
28822 validate: function() {
28826 destroy: function() {
28827 this.purgeListeners();
28828 this.getEl.removeAllListeners();
28829 this.getEl().remove();
28830 if (this.dragZone) {
28831 if (this.dragZone.destroy) {
28832 this.dragZone.destroy();
28835 if (this.dropZone) {
28836 if (this.dropZone.destroy) {
28837 this.dropZone.destroy();
28842 /** Allows this class to be an Roo.form.Field so it can be found using {@link Roo.form.BasicForm#findField}. */
28843 getName: function() {
28847 /** Loads the View from a JSON string representing the Records to put into the Store. */
28848 setValue: function(v) {
28850 throw "DDView.setValue(). DDView must be constructed with a valid Store";
28853 data[this.store.reader.meta.root] = v ? [].concat(v) : [];
28854 this.store.proxy = new Roo.data.MemoryProxy(data);
28858 /** @return {String} a parenthesised list of the ids of the Records in the View. */
28859 getValue: function() {
28861 this.store.each(function(rec) {
28862 result += rec.id + ',';
28864 return result.substr(0, result.length - 1) + ')';
28867 getIds: function() {
28868 var i = 0, result = new Array(this.store.getCount());
28869 this.store.each(function(rec) {
28870 result[i++] = rec.id;
28875 isDirty: function() {
28876 return this.isDirtyFlag;
28880 * Part of the Roo.dd.DropZone interface. If no target node is found, the
28881 * whole Element becomes the target, and this causes the drop gesture to append.
28883 getTargetFromEvent : function(e) {
28884 var target = e.getTarget();
28885 while ((target !== null) && (target.parentNode != this.el.dom)) {
28886 target = target.parentNode;
28889 target = this.el.dom.lastChild || this.el.dom;
28895 * Create the drag data which consists of an object which has the property "ddel" as
28896 * the drag proxy element.
28898 getDragData : function(e) {
28899 var target = this.findItemFromChild(e.getTarget());
28901 this.handleSelection(e);
28902 var selNodes = this.getSelectedNodes();
28905 copy: this.copy || (this.allowCopy && e.ctrlKey),
28909 var selectedIndices = this.getSelectedIndexes();
28910 for (var i = 0; i < selectedIndices.length; i++) {
28911 dragData.records.push(this.store.getAt(selectedIndices[i]));
28913 if (selNodes.length == 1) {
28914 dragData.ddel = target.cloneNode(true); // the div element
28916 var div = document.createElement('div'); // create the multi element drag "ghost"
28917 div.className = 'multi-proxy';
28918 for (var i = 0, len = selNodes.length; i < len; i++) {
28919 div.appendChild(selNodes[i].cloneNode(true));
28921 dragData.ddel = div;
28923 //console.log(dragData)
28924 //console.log(dragData.ddel.innerHTML)
28927 //console.log('nodragData')
28931 /** Specify to which ddGroup items in this DDView may be dragged. */
28932 setDraggable: function(ddGroup) {
28933 if (ddGroup instanceof Array) {
28934 Roo.each(ddGroup, this.setDraggable, this);
28937 if (this.dragZone) {
28938 this.dragZone.addToGroup(ddGroup);
28940 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
28941 containerScroll: true,
28945 // Draggability implies selection. DragZone's mousedown selects the element.
28946 if (!this.multiSelect) { this.singleSelect = true; }
28948 // Wire the DragZone's handlers up to methods in *this*
28949 this.dragZone.getDragData = this.getDragData.createDelegate(this);
28953 /** Specify from which ddGroup this DDView accepts drops. */
28954 setDroppable: function(ddGroup) {
28955 if (ddGroup instanceof Array) {
28956 Roo.each(ddGroup, this.setDroppable, this);
28959 if (this.dropZone) {
28960 this.dropZone.addToGroup(ddGroup);
28962 this.dropZone = new Roo.dd.DropZone(this.getEl(), {
28963 containerScroll: true,
28967 // Wire the DropZone's handlers up to methods in *this*
28968 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
28969 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
28970 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
28971 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
28972 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
28976 /** Decide whether to drop above or below a View node. */
28977 getDropPoint : function(e, n, dd){
28978 if (n == this.el.dom) { return "above"; }
28979 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
28980 var c = t + (b - t) / 2;
28981 var y = Roo.lib.Event.getPageY(e);
28989 onNodeEnter : function(n, dd, e, data){
28993 onNodeOver : function(n, dd, e, data){
28994 var pt = this.getDropPoint(e, n, dd);
28995 // set the insert point style on the target node
28996 var dragElClass = this.dropNotAllowed;
28999 if (pt == "above"){
29000 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
29001 targetElClass = "x-view-drag-insert-above";
29003 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
29004 targetElClass = "x-view-drag-insert-below";
29006 if (this.lastInsertClass != targetElClass){
29007 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
29008 this.lastInsertClass = targetElClass;
29011 return dragElClass;
29014 onNodeOut : function(n, dd, e, data){
29015 this.removeDropIndicators(n);
29018 onNodeDrop : function(n, dd, e, data){
29019 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
29022 var pt = this.getDropPoint(e, n, dd);
29023 var insertAt = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
29024 if (pt == "below") { insertAt++; }
29025 for (var i = 0; i < data.records.length; i++) {
29026 var r = data.records[i];
29027 var dup = this.store.getById(r.id);
29028 if (dup && (dd != this.dragZone)) {
29029 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
29032 this.store.insert(insertAt++, r.copy());
29034 data.source.isDirtyFlag = true;
29036 this.store.insert(insertAt++, r);
29038 this.isDirtyFlag = true;
29041 this.dragZone.cachedTarget = null;
29045 removeDropIndicators : function(n){
29047 Roo.fly(n).removeClass([
29048 "x-view-drag-insert-above",
29049 "x-view-drag-insert-below"]);
29050 this.lastInsertClass = "_noclass";
29055 * Utility method. Add a delete option to the DDView's context menu.
29056 * @param {String} imageUrl The URL of the "delete" icon image.
29058 setDeletable: function(imageUrl) {
29059 if (!this.singleSelect && !this.multiSelect) {
29060 this.singleSelect = true;
29062 var c = this.getContextMenu();
29063 this.contextMenu.on("itemclick", function(item) {
29066 this.remove(this.getSelectedIndexes());
29070 this.contextMenu.add({
29077 /** Return the context menu for this DDView. */
29078 getContextMenu: function() {
29079 if (!this.contextMenu) {
29080 // Create the View's context menu
29081 this.contextMenu = new Roo.menu.Menu({
29082 id: this.id + "-contextmenu"
29084 this.el.on("contextmenu", this.showContextMenu, this);
29086 return this.contextMenu;
29089 disableContextMenu: function() {
29090 if (this.contextMenu) {
29091 this.el.un("contextmenu", this.showContextMenu, this);
29095 showContextMenu: function(e, item) {
29096 item = this.findItemFromChild(e.getTarget());
29099 this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true);
29100 this.contextMenu.showAt(e.getXY());
29105 * Remove {@link Roo.data.Record}s at the specified indices.
29106 * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove.
29108 remove: function(selectedIndices) {
29109 selectedIndices = [].concat(selectedIndices);
29110 for (var i = 0; i < selectedIndices.length; i++) {
29111 var rec = this.store.getAt(selectedIndices[i]);
29112 this.store.remove(rec);
29117 * Double click fires the event, but also, if this is draggable, and there is only one other
29118 * related DropZone, it transfers the selected node.
29120 onDblClick : function(e){
29121 var item = this.findItemFromChild(e.getTarget());
29123 if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) {
29126 if (this.dragGroup) {
29127 var targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
29128 while (targets.indexOf(this.dropZone) > -1) {
29129 targets.remove(this.dropZone);
29131 if (targets.length == 1) {
29132 this.dragZone.cachedTarget = null;
29133 var el = Roo.get(targets[0].getEl());
29134 var box = el.getBox(true);
29135 targets[0].onNodeDrop(el.dom, {
29137 xy: [box.x, box.y + box.height - 1]
29138 }, null, this.getDragData(e));
29144 handleSelection: function(e) {
29145 this.dragZone.cachedTarget = null;
29146 var item = this.findItemFromChild(e.getTarget());
29148 this.clearSelections(true);
29151 if (item && (this.multiSelect || this.singleSelect)){
29152 if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
29153 this.select(this.getNodes(this.indexOf(this.lastSelection), item.nodeIndex), false);
29154 }else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
29155 this.unselect(item);
29157 this.select(item, this.multiSelect && e.ctrlKey);
29158 this.lastSelection = item;
29163 onItemClick : function(item, index, e){
29164 if(this.fireEvent("beforeclick", this, index, item, e) === false){
29170 unselect : function(nodeInfo, suppressEvent){
29171 var node = this.getNode(nodeInfo);
29172 if(node && this.isSelected(node)){
29173 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
29174 Roo.fly(node).removeClass(this.selectedClass);
29175 this.selections.remove(node);
29176 if(!suppressEvent){
29177 this.fireEvent("selectionchange", this, this.selections);
29185 * Ext JS Library 1.1.1
29186 * Copyright(c) 2006-2007, Ext JS, LLC.
29188 * Originally Released Under LGPL - original licence link has changed is not relivant.
29191 * <script type="text/javascript">
29195 * @class Roo.LayoutManager
29196 * @extends Roo.util.Observable
29197 * Base class for layout managers.
29199 Roo.LayoutManager = function(container, config){
29200 Roo.LayoutManager.superclass.constructor.call(this);
29201 this.el = Roo.get(container);
29202 // ie scrollbar fix
29203 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
29204 document.body.scroll = "no";
29205 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
29206 this.el.position('relative');
29208 this.id = this.el.id;
29209 this.el.addClass("x-layout-container");
29210 /** false to disable window resize monitoring @type Boolean */
29211 this.monitorWindowResize = true;
29216 * Fires when a layout is performed.
29217 * @param {Roo.LayoutManager} this
29221 * @event regionresized
29222 * Fires when the user resizes a region.
29223 * @param {Roo.LayoutRegion} region The resized region
29224 * @param {Number} newSize The new size (width for east/west, height for north/south)
29226 "regionresized" : true,
29228 * @event regioncollapsed
29229 * Fires when a region is collapsed.
29230 * @param {Roo.LayoutRegion} region The collapsed region
29232 "regioncollapsed" : true,
29234 * @event regionexpanded
29235 * Fires when a region is expanded.
29236 * @param {Roo.LayoutRegion} region The expanded region
29238 "regionexpanded" : true
29240 this.updating = false;
29241 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
29244 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
29246 * Returns true if this layout is currently being updated
29247 * @return {Boolean}
29249 isUpdating : function(){
29250 return this.updating;
29254 * Suspend the LayoutManager from doing auto-layouts while
29255 * making multiple add or remove calls
29257 beginUpdate : function(){
29258 this.updating = true;
29262 * Restore auto-layouts and optionally disable the manager from performing a layout
29263 * @param {Boolean} noLayout true to disable a layout update
29265 endUpdate : function(noLayout){
29266 this.updating = false;
29272 layout: function(){
29276 onRegionResized : function(region, newSize){
29277 this.fireEvent("regionresized", region, newSize);
29281 onRegionCollapsed : function(region){
29282 this.fireEvent("regioncollapsed", region);
29285 onRegionExpanded : function(region){
29286 this.fireEvent("regionexpanded", region);
29290 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
29291 * performs box-model adjustments.
29292 * @return {Object} The size as an object {width: (the width), height: (the height)}
29294 getViewSize : function(){
29296 if(this.el.dom != document.body){
29297 size = this.el.getSize();
29299 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
29301 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
29302 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
29307 * Returns the Element this layout is bound to.
29308 * @return {Roo.Element}
29310 getEl : function(){
29315 * Returns the specified region.
29316 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
29317 * @return {Roo.LayoutRegion}
29319 getRegion : function(target){
29320 return this.regions[target.toLowerCase()];
29323 onWindowResize : function(){
29324 if(this.monitorWindowResize){
29330 * Ext JS Library 1.1.1
29331 * Copyright(c) 2006-2007, Ext JS, LLC.
29333 * Originally Released Under LGPL - original licence link has changed is not relivant.
29336 * <script type="text/javascript">
29339 * @class Roo.BorderLayout
29340 * @extends Roo.LayoutManager
29341 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
29342 * please see: <br><br>
29343 * <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>
29344 * <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>
29347 var layout = new Roo.BorderLayout(document.body, {
29381 preferredTabWidth: 150
29386 var CP = Roo.ContentPanel;
29388 layout.beginUpdate();
29389 layout.add("north", new CP("north", "North"));
29390 layout.add("south", new CP("south", {title: "South", closable: true}));
29391 layout.add("west", new CP("west", {title: "West"}));
29392 layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
29393 layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
29394 layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
29395 layout.getRegion("center").showPanel("center1");
29396 layout.endUpdate();
29399 <b>The container the layout is rendered into can be either the body element or any other element.
29400 If it is not the body element, the container needs to either be an absolute positioned element,
29401 or you will need to add "position:relative" to the css of the container. You will also need to specify
29402 the container size if it is not the body element.</b>
29405 * Create a new BorderLayout
29406 * @param {String/HTMLElement/Element} container The container this layout is bound to
29407 * @param {Object} config Configuration options
29409 Roo.BorderLayout = function(container, config){
29410 config = config || {};
29411 Roo.BorderLayout.superclass.constructor.call(this, container, config);
29412 this.factory = config.factory || Roo.BorderLayout.RegionFactory;
29413 for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
29414 var target = this.factory.validRegions[i];
29415 if(config[target]){
29416 this.addRegion(target, config[target]);
29421 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
29423 * Creates and adds a new region if it doesn't already exist.
29424 * @param {String} target The target region key (north, south, east, west or center).
29425 * @param {Object} config The regions config object
29426 * @return {BorderLayoutRegion} The new region
29428 addRegion : function(target, config){
29429 if(!this.regions[target]){
29430 var r = this.factory.create(target, this, config);
29431 this.bindRegion(target, r);
29433 return this.regions[target];
29437 bindRegion : function(name, r){
29438 this.regions[name] = r;
29439 r.on("visibilitychange", this.layout, this);
29440 r.on("paneladded", this.layout, this);
29441 r.on("panelremoved", this.layout, this);
29442 r.on("invalidated", this.layout, this);
29443 r.on("resized", this.onRegionResized, this);
29444 r.on("collapsed", this.onRegionCollapsed, this);
29445 r.on("expanded", this.onRegionExpanded, this);
29449 * Performs a layout update.
29451 layout : function(){
29452 if(this.updating) {
29455 var size = this.getViewSize();
29456 var w = size.width;
29457 var h = size.height;
29462 //var x = 0, y = 0;
29464 var rs = this.regions;
29465 var north = rs["north"];
29466 var south = rs["south"];
29467 var west = rs["west"];
29468 var east = rs["east"];
29469 var center = rs["center"];
29470 //if(this.hideOnLayout){ // not supported anymore
29471 //c.el.setStyle("display", "none");
29473 if(north && north.isVisible()){
29474 var b = north.getBox();
29475 var m = north.getMargins();
29476 b.width = w - (m.left+m.right);
29479 centerY = b.height + b.y + m.bottom;
29480 centerH -= centerY;
29481 north.updateBox(this.safeBox(b));
29483 if(south && south.isVisible()){
29484 var b = south.getBox();
29485 var m = south.getMargins();
29486 b.width = w - (m.left+m.right);
29488 var totalHeight = (b.height + m.top + m.bottom);
29489 b.y = h - totalHeight + m.top;
29490 centerH -= totalHeight;
29491 south.updateBox(this.safeBox(b));
29493 if(west && west.isVisible()){
29494 var b = west.getBox();
29495 var m = west.getMargins();
29496 b.height = centerH - (m.top+m.bottom);
29498 b.y = centerY + m.top;
29499 var totalWidth = (b.width + m.left + m.right);
29500 centerX += totalWidth;
29501 centerW -= totalWidth;
29502 west.updateBox(this.safeBox(b));
29504 if(east && east.isVisible()){
29505 var b = east.getBox();
29506 var m = east.getMargins();
29507 b.height = centerH - (m.top+m.bottom);
29508 var totalWidth = (b.width + m.left + m.right);
29509 b.x = w - totalWidth + m.left;
29510 b.y = centerY + m.top;
29511 centerW -= totalWidth;
29512 east.updateBox(this.safeBox(b));
29515 var m = center.getMargins();
29517 x: centerX + m.left,
29518 y: centerY + m.top,
29519 width: centerW - (m.left+m.right),
29520 height: centerH - (m.top+m.bottom)
29522 //if(this.hideOnLayout){
29523 //center.el.setStyle("display", "block");
29525 center.updateBox(this.safeBox(centerBox));
29528 this.fireEvent("layout", this);
29532 safeBox : function(box){
29533 box.width = Math.max(0, box.width);
29534 box.height = Math.max(0, box.height);
29539 * Adds a ContentPanel (or subclass) to this layout.
29540 * @param {String} target The target region key (north, south, east, west or center).
29541 * @param {Roo.ContentPanel} panel The panel to add
29542 * @return {Roo.ContentPanel} The added panel
29544 add : function(target, panel){
29546 target = target.toLowerCase();
29547 return this.regions[target].add(panel);
29551 * Remove a ContentPanel (or subclass) to this layout.
29552 * @param {String} target The target region key (north, south, east, west or center).
29553 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
29554 * @return {Roo.ContentPanel} The removed panel
29556 remove : function(target, panel){
29557 target = target.toLowerCase();
29558 return this.regions[target].remove(panel);
29562 * Searches all regions for a panel with the specified id
29563 * @param {String} panelId
29564 * @return {Roo.ContentPanel} The panel or null if it wasn't found
29566 findPanel : function(panelId){
29567 var rs = this.regions;
29568 for(var target in rs){
29569 if(typeof rs[target] != "function"){
29570 var p = rs[target].getPanel(panelId);
29580 * Searches all regions for a panel with the specified id and activates (shows) it.
29581 * @param {String/ContentPanel} panelId The panels id or the panel itself
29582 * @return {Roo.ContentPanel} The shown panel or null
29584 showPanel : function(panelId) {
29585 var rs = this.regions;
29586 for(var target in rs){
29587 var r = rs[target];
29588 if(typeof r != "function"){
29589 if(r.hasPanel(panelId)){
29590 return r.showPanel(panelId);
29598 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
29599 * @param {Roo.state.Provider} provider (optional) An alternate state provider
29601 restoreState : function(provider){
29603 provider = Roo.state.Manager;
29605 var sm = new Roo.LayoutStateManager();
29606 sm.init(this, provider);
29610 * Adds a batch of multiple ContentPanels dynamically by passing a special regions config object. This config
29611 * object should contain properties for each region to add ContentPanels to, and each property's value should be
29612 * a valid ContentPanel config object. Example:
29614 // Create the main layout
29615 var layout = new Roo.BorderLayout('main-ct', {
29626 // Create and add multiple ContentPanels at once via configs
29629 id: 'source-files',
29631 title:'Ext Source Files',
29644 * @param {Object} regions An object containing ContentPanel configs by region name
29646 batchAdd : function(regions){
29647 this.beginUpdate();
29648 for(var rname in regions){
29649 var lr = this.regions[rname];
29651 this.addTypedPanels(lr, regions[rname]);
29658 addTypedPanels : function(lr, ps){
29659 if(typeof ps == 'string'){
29660 lr.add(new Roo.ContentPanel(ps));
29662 else if(ps instanceof Array){
29663 for(var i =0, len = ps.length; i < len; i++){
29664 this.addTypedPanels(lr, ps[i]);
29667 else if(!ps.events){ // raw config?
29669 delete ps.el; // prevent conflict
29670 lr.add(new Roo.ContentPanel(el || Roo.id(), ps));
29672 else { // panel object assumed!
29677 * Adds a xtype elements to the layout.
29681 xtype : 'ContentPanel',
29688 xtype : 'NestedLayoutPanel',
29694 items : [ ... list of content panels or nested layout panels.. ]
29698 * @param {Object} cfg Xtype definition of item to add.
29700 addxtype : function(cfg)
29702 // basically accepts a pannel...
29703 // can accept a layout region..!?!?
29704 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
29706 if (!cfg.xtype.match(/Panel$/)) {
29711 if (typeof(cfg.region) == 'undefined') {
29712 Roo.log("Failed to add Panel, region was not set");
29716 var region = cfg.region;
29722 xitems = cfg.items;
29729 case 'ContentPanel': // ContentPanel (el, cfg)
29730 case 'ScrollPanel': // ContentPanel (el, cfg)
29732 if(cfg.autoCreate) {
29733 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29735 var el = this.el.createChild();
29736 ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
29739 this.add(region, ret);
29743 case 'TreePanel': // our new panel!
29744 cfg.el = this.el.createChild();
29745 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29746 this.add(region, ret);
29749 case 'NestedLayoutPanel':
29750 // create a new Layout (which is a Border Layout...
29751 var el = this.el.createChild();
29752 var clayout = cfg.layout;
29754 clayout.items = clayout.items || [];
29755 // replace this exitems with the clayout ones..
29756 xitems = clayout.items;
29759 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
29760 cfg.background = false;
29762 var layout = new Roo.BorderLayout(el, clayout);
29764 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
29765 //console.log('adding nested layout panel ' + cfg.toSource());
29766 this.add(region, ret);
29767 nb = {}; /// find first...
29772 // needs grid and region
29774 //var el = this.getRegion(region).el.createChild();
29775 var el = this.el.createChild();
29776 // create the grid first...
29778 var grid = new Roo.grid[cfg.grid.xtype](el, cfg.grid);
29780 if (region == 'center' && this.active ) {
29781 cfg.background = false;
29783 ret = new Roo[cfg.xtype](grid, cfg); // new panel!!!!!
29785 this.add(region, ret);
29786 if (cfg.background) {
29787 ret.on('activate', function(gp) {
29788 if (!gp.grid.rendered) {
29803 if (typeof(Roo[cfg.xtype]) != 'undefined') {
29805 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29806 this.add(region, ret);
29809 alert("Can not add '" + cfg.xtype + "' to BorderLayout");
29813 // GridPanel (grid, cfg)
29816 this.beginUpdate();
29820 Roo.each(xitems, function(i) {
29821 region = nb && i.region ? i.region : false;
29823 var add = ret.addxtype(i);
29826 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
29827 if (!i.background) {
29828 abn[region] = nb[region] ;
29835 // make the last non-background panel active..
29836 //if (nb) { Roo.log(abn); }
29839 for(var r in abn) {
29840 region = this.getRegion(r);
29842 // tried using nb[r], but it does not work..
29844 region.showPanel(abn[r]);
29855 * Shortcut for creating a new BorderLayout object and adding one or more ContentPanels to it in a single step, handling
29856 * the beginUpdate and endUpdate calls internally. The key to this method is the <b>panels</b> property that can be
29857 * provided with each region config, which allows you to add ContentPanel configs in addition to the region configs
29858 * during creation. The following code is equivalent to the constructor-based example at the beginning of this class:
29861 var CP = Roo.ContentPanel;
29863 var layout = Roo.BorderLayout.create({
29867 panels: [new CP("north", "North")]
29876 panels: [new CP("west", {title: "West"})]
29885 panels: [new CP("autoTabs", {title: "Auto Tabs", closable: true})]
29894 panels: [new CP("south", {title: "South", closable: true})]
29901 preferredTabWidth: 150,
29903 new CP("center1", {title: "Close Me", closable: true}),
29904 new CP("center2", {title: "Center Panel", closable: false})
29909 layout.getRegion("center").showPanel("center1");
29914 Roo.BorderLayout.create = function(config, targetEl){
29915 var layout = new Roo.BorderLayout(targetEl || document.body, config);
29916 layout.beginUpdate();
29917 var regions = Roo.BorderLayout.RegionFactory.validRegions;
29918 for(var j = 0, jlen = regions.length; j < jlen; j++){
29919 var lr = regions[j];
29920 if(layout.regions[lr] && config[lr].panels){
29921 var r = layout.regions[lr];
29922 var ps = config[lr].panels;
29923 layout.addTypedPanels(r, ps);
29926 layout.endUpdate();
29931 Roo.BorderLayout.RegionFactory = {
29933 validRegions : ["north","south","east","west","center"],
29936 create : function(target, mgr, config){
29937 target = target.toLowerCase();
29938 if(config.lightweight || config.basic){
29939 return new Roo.BasicLayoutRegion(mgr, config, target);
29943 return new Roo.NorthLayoutRegion(mgr, config);
29945 return new Roo.SouthLayoutRegion(mgr, config);
29947 return new Roo.EastLayoutRegion(mgr, config);
29949 return new Roo.WestLayoutRegion(mgr, config);
29951 return new Roo.CenterLayoutRegion(mgr, config);
29953 throw 'Layout region "'+target+'" not supported.';
29957 * Ext JS Library 1.1.1
29958 * Copyright(c) 2006-2007, Ext JS, LLC.
29960 * Originally Released Under LGPL - original licence link has changed is not relivant.
29963 * <script type="text/javascript">
29967 * @class Roo.BasicLayoutRegion
29968 * @extends Roo.util.Observable
29969 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
29970 * and does not have a titlebar, tabs or any other features. All it does is size and position
29971 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
29973 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
29975 this.position = pos;
29978 * @scope Roo.BasicLayoutRegion
29982 * @event beforeremove
29983 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
29984 * @param {Roo.LayoutRegion} this
29985 * @param {Roo.ContentPanel} panel The panel
29986 * @param {Object} e The cancel event object
29988 "beforeremove" : true,
29990 * @event invalidated
29991 * Fires when the layout for this region is changed.
29992 * @param {Roo.LayoutRegion} this
29994 "invalidated" : true,
29996 * @event visibilitychange
29997 * Fires when this region is shown or hidden
29998 * @param {Roo.LayoutRegion} this
29999 * @param {Boolean} visibility true or false
30001 "visibilitychange" : true,
30003 * @event paneladded
30004 * Fires when a panel is added.
30005 * @param {Roo.LayoutRegion} this
30006 * @param {Roo.ContentPanel} panel The panel
30008 "paneladded" : true,
30010 * @event panelremoved
30011 * Fires when a panel is removed.
30012 * @param {Roo.LayoutRegion} this
30013 * @param {Roo.ContentPanel} panel The panel
30015 "panelremoved" : true,
30017 * @event beforecollapse
30018 * Fires when this region before collapse.
30019 * @param {Roo.LayoutRegion} this
30021 "beforecollapse" : true,
30024 * Fires when this region is collapsed.
30025 * @param {Roo.LayoutRegion} this
30027 "collapsed" : true,
30030 * Fires when this region is expanded.
30031 * @param {Roo.LayoutRegion} this
30036 * Fires when this region is slid into view.
30037 * @param {Roo.LayoutRegion} this
30039 "slideshow" : true,
30042 * Fires when this region slides out of view.
30043 * @param {Roo.LayoutRegion} this
30045 "slidehide" : true,
30047 * @event panelactivated
30048 * Fires when a panel is activated.
30049 * @param {Roo.LayoutRegion} this
30050 * @param {Roo.ContentPanel} panel The activated panel
30052 "panelactivated" : true,
30055 * Fires when the user resizes this region.
30056 * @param {Roo.LayoutRegion} this
30057 * @param {Number} newSize The new size (width for east/west, height for north/south)
30061 /** A collection of panels in this region. @type Roo.util.MixedCollection */
30062 this.panels = new Roo.util.MixedCollection();
30063 this.panels.getKey = this.getPanelId.createDelegate(this);
30065 this.activePanel = null;
30066 // ensure listeners are added...
30068 if (config.listeners || config.events) {
30069 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
30070 listeners : config.listeners || {},
30071 events : config.events || {}
30075 if(skipConfig !== true){
30076 this.applyConfig(config);
30080 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
30081 getPanelId : function(p){
30085 applyConfig : function(config){
30086 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
30087 this.config = config;
30092 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
30093 * the width, for horizontal (north, south) the height.
30094 * @param {Number} newSize The new width or height
30096 resizeTo : function(newSize){
30097 var el = this.el ? this.el :
30098 (this.activePanel ? this.activePanel.getEl() : null);
30100 switch(this.position){
30103 el.setWidth(newSize);
30104 this.fireEvent("resized", this, newSize);
30108 el.setHeight(newSize);
30109 this.fireEvent("resized", this, newSize);
30115 getBox : function(){
30116 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
30119 getMargins : function(){
30120 return this.margins;
30123 updateBox : function(box){
30125 var el = this.activePanel.getEl();
30126 el.dom.style.left = box.x + "px";
30127 el.dom.style.top = box.y + "px";
30128 this.activePanel.setSize(box.width, box.height);
30132 * Returns the container element for this region.
30133 * @return {Roo.Element}
30135 getEl : function(){
30136 return this.activePanel;
30140 * Returns true if this region is currently visible.
30141 * @return {Boolean}
30143 isVisible : function(){
30144 return this.activePanel ? true : false;
30147 setActivePanel : function(panel){
30148 panel = this.getPanel(panel);
30149 if(this.activePanel && this.activePanel != panel){
30150 this.activePanel.setActiveState(false);
30151 this.activePanel.getEl().setLeftTop(-10000,-10000);
30153 this.activePanel = panel;
30154 panel.setActiveState(true);
30156 panel.setSize(this.box.width, this.box.height);
30158 this.fireEvent("panelactivated", this, panel);
30159 this.fireEvent("invalidated");
30163 * Show the specified panel.
30164 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
30165 * @return {Roo.ContentPanel} The shown panel or null
30167 showPanel : function(panel){
30168 if(panel = this.getPanel(panel)){
30169 this.setActivePanel(panel);
30175 * Get the active panel for this region.
30176 * @return {Roo.ContentPanel} The active panel or null
30178 getActivePanel : function(){
30179 return this.activePanel;
30183 * Add the passed ContentPanel(s)
30184 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
30185 * @return {Roo.ContentPanel} The panel added (if only one was added)
30187 add : function(panel){
30188 if(arguments.length > 1){
30189 for(var i = 0, len = arguments.length; i < len; i++) {
30190 this.add(arguments[i]);
30194 if(this.hasPanel(panel)){
30195 this.showPanel(panel);
30198 var el = panel.getEl();
30199 if(el.dom.parentNode != this.mgr.el.dom){
30200 this.mgr.el.dom.appendChild(el.dom);
30202 if(panel.setRegion){
30203 panel.setRegion(this);
30205 this.panels.add(panel);
30206 el.setStyle("position", "absolute");
30207 if(!panel.background){
30208 this.setActivePanel(panel);
30209 if(this.config.initialSize && this.panels.getCount()==1){
30210 this.resizeTo(this.config.initialSize);
30213 this.fireEvent("paneladded", this, panel);
30218 * Returns true if the panel is in this region.
30219 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
30220 * @return {Boolean}
30222 hasPanel : function(panel){
30223 if(typeof panel == "object"){ // must be panel obj
30224 panel = panel.getId();
30226 return this.getPanel(panel) ? true : false;
30230 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
30231 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
30232 * @param {Boolean} preservePanel Overrides the config preservePanel option
30233 * @return {Roo.ContentPanel} The panel that was removed
30235 remove : function(panel, preservePanel){
30236 panel = this.getPanel(panel);
30241 this.fireEvent("beforeremove", this, panel, e);
30242 if(e.cancel === true){
30245 var panelId = panel.getId();
30246 this.panels.removeKey(panelId);
30251 * Returns the panel specified or null if it's not in this region.
30252 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
30253 * @return {Roo.ContentPanel}
30255 getPanel : function(id){
30256 if(typeof id == "object"){ // must be panel obj
30259 return this.panels.get(id);
30263 * Returns this regions position (north/south/east/west/center).
30266 getPosition: function(){
30267 return this.position;
30271 * Ext JS Library 1.1.1
30272 * Copyright(c) 2006-2007, Ext JS, LLC.
30274 * Originally Released Under LGPL - original licence link has changed is not relivant.
30277 * <script type="text/javascript">
30281 * @class Roo.LayoutRegion
30282 * @extends Roo.BasicLayoutRegion
30283 * This class represents a region in a layout manager.
30284 * @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
30285 * @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
30286 * @cfg {Boolean} floatable False to disable floating (defaults to true)
30287 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
30288 * @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})
30289 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
30290 * @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
30291 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
30292 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
30293 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
30294 * @cfg {String} title The title for the region (overrides panel titles)
30295 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
30296 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
30297 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
30298 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
30299 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
30300 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
30301 * the space available, similar to FireFox 1.5 tabs (defaults to false)
30302 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
30303 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
30304 * @cfg {Boolean} showPin True to show a pin button
30305 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
30306 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
30307 * @cfg {Boolean} disableTabTips True to disable tab tooltips
30308 * @cfg {Number} width For East/West panels
30309 * @cfg {Number} height For North/South panels
30310 * @cfg {Boolean} split To show the splitter
30311 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
30313 Roo.LayoutRegion = function(mgr, config, pos){
30314 Roo.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
30315 var dh = Roo.DomHelper;
30316 /** This region's container element
30317 * @type Roo.Element */
30318 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
30319 /** This region's title element
30320 * @type Roo.Element */
30322 this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
30323 {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
30324 {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
30326 this.titleEl.enableDisplayMode();
30327 /** This region's title text element
30328 * @type HTMLElement */
30329 this.titleTextEl = this.titleEl.dom.firstChild;
30330 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
30331 this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
30332 this.closeBtn.enableDisplayMode();
30333 this.closeBtn.on("click", this.closeClicked, this);
30334 this.closeBtn.hide();
30336 this.createBody(config);
30337 this.visible = true;
30338 this.collapsed = false;
30340 if(config.hideWhenEmpty){
30342 this.on("paneladded", this.validateVisibility, this);
30343 this.on("panelremoved", this.validateVisibility, this);
30345 this.applyConfig(config);
30348 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
30350 createBody : function(){
30351 /** This region's body element
30352 * @type Roo.Element */
30353 this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
30356 applyConfig : function(c){
30357 if(c.collapsible && this.position != "center" && !this.collapsedEl){
30358 var dh = Roo.DomHelper;
30359 if(c.titlebar !== false){
30360 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
30361 this.collapseBtn.on("click", this.collapse, this);
30362 this.collapseBtn.enableDisplayMode();
30364 if(c.showPin === true || this.showPin){
30365 this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
30366 this.stickBtn.enableDisplayMode();
30367 this.stickBtn.on("click", this.expand, this);
30368 this.stickBtn.hide();
30371 /** This region's collapsed element
30372 * @type Roo.Element */
30373 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
30374 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
30376 if(c.floatable !== false){
30377 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
30378 this.collapsedEl.on("click", this.collapseClick, this);
30381 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
30382 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
30383 id: "message", unselectable: "on", style:{"float":"left"}});
30384 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
30386 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
30387 this.expandBtn.on("click", this.expand, this);
30389 if(this.collapseBtn){
30390 this.collapseBtn.setVisible(c.collapsible == true);
30392 this.cmargins = c.cmargins || this.cmargins ||
30393 (this.position == "west" || this.position == "east" ?
30394 {top: 0, left: 2, right:2, bottom: 0} :
30395 {top: 2, left: 0, right:0, bottom: 2});
30396 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
30397 this.bottomTabs = c.tabPosition != "top";
30398 this.autoScroll = c.autoScroll || false;
30399 if(this.autoScroll){
30400 this.bodyEl.setStyle("overflow", "auto");
30402 this.bodyEl.setStyle("overflow", "hidden");
30404 //if(c.titlebar !== false){
30405 if((!c.titlebar && !c.title) || c.titlebar === false){
30406 this.titleEl.hide();
30408 this.titleEl.show();
30410 this.titleTextEl.innerHTML = c.title;
30414 this.duration = c.duration || .30;
30415 this.slideDuration = c.slideDuration || .45;
30418 this.collapse(true);
30425 * Returns true if this region is currently visible.
30426 * @return {Boolean}
30428 isVisible : function(){
30429 return this.visible;
30433 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
30434 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
30436 setCollapsedTitle : function(title){
30437 title = title || " ";
30438 if(this.collapsedTitleTextEl){
30439 this.collapsedTitleTextEl.innerHTML = title;
30443 getBox : function(){
30445 if(!this.collapsed){
30446 b = this.el.getBox(false, true);
30448 b = this.collapsedEl.getBox(false, true);
30453 getMargins : function(){
30454 return this.collapsed ? this.cmargins : this.margins;
30457 highlight : function(){
30458 this.el.addClass("x-layout-panel-dragover");
30461 unhighlight : function(){
30462 this.el.removeClass("x-layout-panel-dragover");
30465 updateBox : function(box){
30467 if(!this.collapsed){
30468 this.el.dom.style.left = box.x + "px";
30469 this.el.dom.style.top = box.y + "px";
30470 this.updateBody(box.width, box.height);
30472 this.collapsedEl.dom.style.left = box.x + "px";
30473 this.collapsedEl.dom.style.top = box.y + "px";
30474 this.collapsedEl.setSize(box.width, box.height);
30477 this.tabs.autoSizeTabs();
30481 updateBody : function(w, h){
30483 this.el.setWidth(w);
30484 w -= this.el.getBorderWidth("rl");
30485 if(this.config.adjustments){
30486 w += this.config.adjustments[0];
30490 this.el.setHeight(h);
30491 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
30492 h -= this.el.getBorderWidth("tb");
30493 if(this.config.adjustments){
30494 h += this.config.adjustments[1];
30496 this.bodyEl.setHeight(h);
30498 h = this.tabs.syncHeight(h);
30501 if(this.panelSize){
30502 w = w !== null ? w : this.panelSize.width;
30503 h = h !== null ? h : this.panelSize.height;
30505 if(this.activePanel){
30506 var el = this.activePanel.getEl();
30507 w = w !== null ? w : el.getWidth();
30508 h = h !== null ? h : el.getHeight();
30509 this.panelSize = {width: w, height: h};
30510 this.activePanel.setSize(w, h);
30512 if(Roo.isIE && this.tabs){
30513 this.tabs.el.repaint();
30518 * Returns the container element for this region.
30519 * @return {Roo.Element}
30521 getEl : function(){
30526 * Hides this region.
30529 if(!this.collapsed){
30530 this.el.dom.style.left = "-2000px";
30533 this.collapsedEl.dom.style.left = "-2000px";
30534 this.collapsedEl.hide();
30536 this.visible = false;
30537 this.fireEvent("visibilitychange", this, false);
30541 * Shows this region if it was previously hidden.
30544 if(!this.collapsed){
30547 this.collapsedEl.show();
30549 this.visible = true;
30550 this.fireEvent("visibilitychange", this, true);
30553 closeClicked : function(){
30554 if(this.activePanel){
30555 this.remove(this.activePanel);
30559 collapseClick : function(e){
30561 e.stopPropagation();
30564 e.stopPropagation();
30570 * Collapses this region.
30571 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
30573 collapse : function(skipAnim, skipCheck){
30574 if(this.collapsed) {
30578 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
30580 this.collapsed = true;
30582 this.split.el.hide();
30584 if(this.config.animate && skipAnim !== true){
30585 this.fireEvent("invalidated", this);
30586 this.animateCollapse();
30588 this.el.setLocation(-20000,-20000);
30590 this.collapsedEl.show();
30591 this.fireEvent("collapsed", this);
30592 this.fireEvent("invalidated", this);
30598 animateCollapse : function(){
30603 * Expands this region if it was previously collapsed.
30604 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
30605 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
30607 expand : function(e, skipAnim){
30609 e.stopPropagation();
30611 if(!this.collapsed || this.el.hasActiveFx()) {
30615 this.afterSlideIn();
30618 this.collapsed = false;
30619 if(this.config.animate && skipAnim !== true){
30620 this.animateExpand();
30624 this.split.el.show();
30626 this.collapsedEl.setLocation(-2000,-2000);
30627 this.collapsedEl.hide();
30628 this.fireEvent("invalidated", this);
30629 this.fireEvent("expanded", this);
30633 animateExpand : function(){
30637 initTabs : function()
30639 this.bodyEl.setStyle("overflow", "hidden");
30640 var ts = new Roo.TabPanel(
30643 tabPosition: this.bottomTabs ? 'bottom' : 'top',
30644 disableTooltips: this.config.disableTabTips,
30645 toolbar : this.config.toolbar
30648 if(this.config.hideTabs){
30649 ts.stripWrap.setDisplayed(false);
30652 ts.resizeTabs = this.config.resizeTabs === true;
30653 ts.minTabWidth = this.config.minTabWidth || 40;
30654 ts.maxTabWidth = this.config.maxTabWidth || 250;
30655 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
30656 ts.monitorResize = false;
30657 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
30658 ts.bodyEl.addClass('x-layout-tabs-body');
30659 this.panels.each(this.initPanelAsTab, this);
30662 initPanelAsTab : function(panel){
30663 var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
30664 this.config.closeOnTab && panel.isClosable());
30665 if(panel.tabTip !== undefined){
30666 ti.setTooltip(panel.tabTip);
30668 ti.on("activate", function(){
30669 this.setActivePanel(panel);
30671 if(this.config.closeOnTab){
30672 ti.on("beforeclose", function(t, e){
30674 this.remove(panel);
30680 updatePanelTitle : function(panel, title){
30681 if(this.activePanel == panel){
30682 this.updateTitle(title);
30685 var ti = this.tabs.getTab(panel.getEl().id);
30687 if(panel.tabTip !== undefined){
30688 ti.setTooltip(panel.tabTip);
30693 updateTitle : function(title){
30694 if(this.titleTextEl && !this.config.title){
30695 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
30699 setActivePanel : function(panel){
30700 panel = this.getPanel(panel);
30701 if(this.activePanel && this.activePanel != panel){
30702 this.activePanel.setActiveState(false);
30704 this.activePanel = panel;
30705 panel.setActiveState(true);
30706 if(this.panelSize){
30707 panel.setSize(this.panelSize.width, this.panelSize.height);
30710 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
30712 this.updateTitle(panel.getTitle());
30714 this.fireEvent("invalidated", this);
30716 this.fireEvent("panelactivated", this, panel);
30720 * Shows the specified panel.
30721 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
30722 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
30724 showPanel : function(panel)
30726 panel = this.getPanel(panel);
30729 var tab = this.tabs.getTab(panel.getEl().id);
30730 if(tab.isHidden()){
30731 this.tabs.unhideTab(tab.id);
30735 this.setActivePanel(panel);
30742 * Get the active panel for this region.
30743 * @return {Roo.ContentPanel} The active panel or null
30745 getActivePanel : function(){
30746 return this.activePanel;
30749 validateVisibility : function(){
30750 if(this.panels.getCount() < 1){
30751 this.updateTitle(" ");
30752 this.closeBtn.hide();
30755 if(!this.isVisible()){
30762 * Adds the passed ContentPanel(s) to this region.
30763 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
30764 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
30766 add : function(panel){
30767 if(arguments.length > 1){
30768 for(var i = 0, len = arguments.length; i < len; i++) {
30769 this.add(arguments[i]);
30773 if(this.hasPanel(panel)){
30774 this.showPanel(panel);
30777 panel.setRegion(this);
30778 this.panels.add(panel);
30779 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
30780 this.bodyEl.dom.appendChild(panel.getEl().dom);
30781 if(panel.background !== true){
30782 this.setActivePanel(panel);
30784 this.fireEvent("paneladded", this, panel);
30790 this.initPanelAsTab(panel);
30792 if(panel.background !== true){
30793 this.tabs.activate(panel.getEl().id);
30795 this.fireEvent("paneladded", this, panel);
30800 * Hides the tab for the specified panel.
30801 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30803 hidePanel : function(panel){
30804 if(this.tabs && (panel = this.getPanel(panel))){
30805 this.tabs.hideTab(panel.getEl().id);
30810 * Unhides the tab for a previously hidden panel.
30811 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30813 unhidePanel : function(panel){
30814 if(this.tabs && (panel = this.getPanel(panel))){
30815 this.tabs.unhideTab(panel.getEl().id);
30819 clearPanels : function(){
30820 while(this.panels.getCount() > 0){
30821 this.remove(this.panels.first());
30826 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
30827 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30828 * @param {Boolean} preservePanel Overrides the config preservePanel option
30829 * @return {Roo.ContentPanel} The panel that was removed
30831 remove : function(panel, preservePanel){
30832 panel = this.getPanel(panel);
30837 this.fireEvent("beforeremove", this, panel, e);
30838 if(e.cancel === true){
30841 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
30842 var panelId = panel.getId();
30843 this.panels.removeKey(panelId);
30845 document.body.appendChild(panel.getEl().dom);
30848 this.tabs.removeTab(panel.getEl().id);
30849 }else if (!preservePanel){
30850 this.bodyEl.dom.removeChild(panel.getEl().dom);
30852 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
30853 var p = this.panels.first();
30854 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
30855 tempEl.appendChild(p.getEl().dom);
30856 this.bodyEl.update("");
30857 this.bodyEl.dom.appendChild(p.getEl().dom);
30859 this.updateTitle(p.getTitle());
30861 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
30862 this.setActivePanel(p);
30864 panel.setRegion(null);
30865 if(this.activePanel == panel){
30866 this.activePanel = null;
30868 if(this.config.autoDestroy !== false && preservePanel !== true){
30869 try{panel.destroy();}catch(e){}
30871 this.fireEvent("panelremoved", this, panel);
30876 * Returns the TabPanel component used by this region
30877 * @return {Roo.TabPanel}
30879 getTabs : function(){
30883 createTool : function(parentEl, className){
30884 var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
30885 children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
30886 btn.addClassOnOver("x-layout-tools-button-over");
30891 * Ext JS Library 1.1.1
30892 * Copyright(c) 2006-2007, Ext JS, LLC.
30894 * Originally Released Under LGPL - original licence link has changed is not relivant.
30897 * <script type="text/javascript">
30903 * @class Roo.SplitLayoutRegion
30904 * @extends Roo.LayoutRegion
30905 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
30907 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
30908 this.cursor = cursor;
30909 Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
30912 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
30913 splitTip : "Drag to resize.",
30914 collapsibleSplitTip : "Drag to resize. Double click to hide.",
30915 useSplitTips : false,
30917 applyConfig : function(config){
30918 Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
30921 var splitEl = Roo.DomHelper.append(this.mgr.el.dom,
30922 {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: " "});
30923 /** The SplitBar for this region
30924 * @type Roo.SplitBar */
30925 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
30926 this.split.on("moved", this.onSplitMove, this);
30927 this.split.useShim = config.useShim === true;
30928 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
30929 if(this.useSplitTips){
30930 this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
30932 if(config.collapsible){
30933 this.split.el.on("dblclick", this.collapse, this);
30936 if(typeof config.minSize != "undefined"){
30937 this.split.minSize = config.minSize;
30939 if(typeof config.maxSize != "undefined"){
30940 this.split.maxSize = config.maxSize;
30942 if(config.hideWhenEmpty || config.hidden || config.collapsed){
30943 this.hideSplitter();
30948 getHMaxSize : function(){
30949 var cmax = this.config.maxSize || 10000;
30950 var center = this.mgr.getRegion("center");
30951 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
30954 getVMaxSize : function(){
30955 var cmax = this.config.maxSize || 10000;
30956 var center = this.mgr.getRegion("center");
30957 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
30960 onSplitMove : function(split, newSize){
30961 this.fireEvent("resized", this, newSize);
30965 * Returns the {@link Roo.SplitBar} for this region.
30966 * @return {Roo.SplitBar}
30968 getSplitBar : function(){
30973 this.hideSplitter();
30974 Roo.SplitLayoutRegion.superclass.hide.call(this);
30977 hideSplitter : function(){
30979 this.split.el.setLocation(-2000,-2000);
30980 this.split.el.hide();
30986 this.split.el.show();
30988 Roo.SplitLayoutRegion.superclass.show.call(this);
30991 beforeSlide: function(){
30992 if(Roo.isGecko){// firefox overflow auto bug workaround
30993 this.bodyEl.clip();
30995 this.tabs.bodyEl.clip();
30997 if(this.activePanel){
30998 this.activePanel.getEl().clip();
31000 if(this.activePanel.beforeSlide){
31001 this.activePanel.beforeSlide();
31007 afterSlide : function(){
31008 if(Roo.isGecko){// firefox overflow auto bug workaround
31009 this.bodyEl.unclip();
31011 this.tabs.bodyEl.unclip();
31013 if(this.activePanel){
31014 this.activePanel.getEl().unclip();
31015 if(this.activePanel.afterSlide){
31016 this.activePanel.afterSlide();
31022 initAutoHide : function(){
31023 if(this.autoHide !== false){
31024 if(!this.autoHideHd){
31025 var st = new Roo.util.DelayedTask(this.slideIn, this);
31026 this.autoHideHd = {
31027 "mouseout": function(e){
31028 if(!e.within(this.el, true)){
31032 "mouseover" : function(e){
31038 this.el.on(this.autoHideHd);
31042 clearAutoHide : function(){
31043 if(this.autoHide !== false){
31044 this.el.un("mouseout", this.autoHideHd.mouseout);
31045 this.el.un("mouseover", this.autoHideHd.mouseover);
31049 clearMonitor : function(){
31050 Roo.get(document).un("click", this.slideInIf, this);
31053 // these names are backwards but not changed for compat
31054 slideOut : function(){
31055 if(this.isSlid || this.el.hasActiveFx()){
31058 this.isSlid = true;
31059 if(this.collapseBtn){
31060 this.collapseBtn.hide();
31062 this.closeBtnState = this.closeBtn.getStyle('display');
31063 this.closeBtn.hide();
31065 this.stickBtn.show();
31068 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
31069 this.beforeSlide();
31070 this.el.setStyle("z-index", 10001);
31071 this.el.slideIn(this.getSlideAnchor(), {
31072 callback: function(){
31074 this.initAutoHide();
31075 Roo.get(document).on("click", this.slideInIf, this);
31076 this.fireEvent("slideshow", this);
31083 afterSlideIn : function(){
31084 this.clearAutoHide();
31085 this.isSlid = false;
31086 this.clearMonitor();
31087 this.el.setStyle("z-index", "");
31088 if(this.collapseBtn){
31089 this.collapseBtn.show();
31091 this.closeBtn.setStyle('display', this.closeBtnState);
31093 this.stickBtn.hide();
31095 this.fireEvent("slidehide", this);
31098 slideIn : function(cb){
31099 if(!this.isSlid || this.el.hasActiveFx()){
31103 this.isSlid = false;
31104 this.beforeSlide();
31105 this.el.slideOut(this.getSlideAnchor(), {
31106 callback: function(){
31107 this.el.setLeftTop(-10000, -10000);
31109 this.afterSlideIn();
31117 slideInIf : function(e){
31118 if(!e.within(this.el)){
31123 animateCollapse : function(){
31124 this.beforeSlide();
31125 this.el.setStyle("z-index", 20000);
31126 var anchor = this.getSlideAnchor();
31127 this.el.slideOut(anchor, {
31128 callback : function(){
31129 this.el.setStyle("z-index", "");
31130 this.collapsedEl.slideIn(anchor, {duration:.3});
31132 this.el.setLocation(-10000,-10000);
31134 this.fireEvent("collapsed", this);
31141 animateExpand : function(){
31142 this.beforeSlide();
31143 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
31144 this.el.setStyle("z-index", 20000);
31145 this.collapsedEl.hide({
31148 this.el.slideIn(this.getSlideAnchor(), {
31149 callback : function(){
31150 this.el.setStyle("z-index", "");
31153 this.split.el.show();
31155 this.fireEvent("invalidated", this);
31156 this.fireEvent("expanded", this);
31184 getAnchor : function(){
31185 return this.anchors[this.position];
31188 getCollapseAnchor : function(){
31189 return this.canchors[this.position];
31192 getSlideAnchor : function(){
31193 return this.sanchors[this.position];
31196 getAlignAdj : function(){
31197 var cm = this.cmargins;
31198 switch(this.position){
31214 getExpandAdj : function(){
31215 var c = this.collapsedEl, cm = this.cmargins;
31216 switch(this.position){
31218 return [-(cm.right+c.getWidth()+cm.left), 0];
31221 return [cm.right+c.getWidth()+cm.left, 0];
31224 return [0, -(cm.top+cm.bottom+c.getHeight())];
31227 return [0, cm.top+cm.bottom+c.getHeight()];
31233 * Ext JS Library 1.1.1
31234 * Copyright(c) 2006-2007, Ext JS, LLC.
31236 * Originally Released Under LGPL - original licence link has changed is not relivant.
31239 * <script type="text/javascript">
31242 * These classes are private internal classes
31244 Roo.CenterLayoutRegion = function(mgr, config){
31245 Roo.LayoutRegion.call(this, mgr, config, "center");
31246 this.visible = true;
31247 this.minWidth = config.minWidth || 20;
31248 this.minHeight = config.minHeight || 20;
31251 Roo.extend(Roo.CenterLayoutRegion, Roo.LayoutRegion, {
31253 // center panel can't be hidden
31257 // center panel can't be hidden
31260 getMinWidth: function(){
31261 return this.minWidth;
31264 getMinHeight: function(){
31265 return this.minHeight;
31270 Roo.NorthLayoutRegion = function(mgr, config){
31271 Roo.LayoutRegion.call(this, mgr, config, "north", "n-resize");
31273 this.split.placement = Roo.SplitBar.TOP;
31274 this.split.orientation = Roo.SplitBar.VERTICAL;
31275 this.split.el.addClass("x-layout-split-v");
31277 var size = config.initialSize || config.height;
31278 if(typeof size != "undefined"){
31279 this.el.setHeight(size);
31282 Roo.extend(Roo.NorthLayoutRegion, Roo.SplitLayoutRegion, {
31283 orientation: Roo.SplitBar.VERTICAL,
31284 getBox : function(){
31285 if(this.collapsed){
31286 return this.collapsedEl.getBox();
31288 var box = this.el.getBox();
31290 box.height += this.split.el.getHeight();
31295 updateBox : function(box){
31296 if(this.split && !this.collapsed){
31297 box.height -= this.split.el.getHeight();
31298 this.split.el.setLeft(box.x);
31299 this.split.el.setTop(box.y+box.height);
31300 this.split.el.setWidth(box.width);
31302 if(this.collapsed){
31303 this.updateBody(box.width, null);
31305 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31309 Roo.SouthLayoutRegion = function(mgr, config){
31310 Roo.SplitLayoutRegion.call(this, mgr, config, "south", "s-resize");
31312 this.split.placement = Roo.SplitBar.BOTTOM;
31313 this.split.orientation = Roo.SplitBar.VERTICAL;
31314 this.split.el.addClass("x-layout-split-v");
31316 var size = config.initialSize || config.height;
31317 if(typeof size != "undefined"){
31318 this.el.setHeight(size);
31321 Roo.extend(Roo.SouthLayoutRegion, Roo.SplitLayoutRegion, {
31322 orientation: Roo.SplitBar.VERTICAL,
31323 getBox : function(){
31324 if(this.collapsed){
31325 return this.collapsedEl.getBox();
31327 var box = this.el.getBox();
31329 var sh = this.split.el.getHeight();
31336 updateBox : function(box){
31337 if(this.split && !this.collapsed){
31338 var sh = this.split.el.getHeight();
31341 this.split.el.setLeft(box.x);
31342 this.split.el.setTop(box.y-sh);
31343 this.split.el.setWidth(box.width);
31345 if(this.collapsed){
31346 this.updateBody(box.width, null);
31348 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31352 Roo.EastLayoutRegion = function(mgr, config){
31353 Roo.SplitLayoutRegion.call(this, mgr, config, "east", "e-resize");
31355 this.split.placement = Roo.SplitBar.RIGHT;
31356 this.split.orientation = Roo.SplitBar.HORIZONTAL;
31357 this.split.el.addClass("x-layout-split-h");
31359 var size = config.initialSize || config.width;
31360 if(typeof size != "undefined"){
31361 this.el.setWidth(size);
31364 Roo.extend(Roo.EastLayoutRegion, Roo.SplitLayoutRegion, {
31365 orientation: Roo.SplitBar.HORIZONTAL,
31366 getBox : function(){
31367 if(this.collapsed){
31368 return this.collapsedEl.getBox();
31370 var box = this.el.getBox();
31372 var sw = this.split.el.getWidth();
31379 updateBox : function(box){
31380 if(this.split && !this.collapsed){
31381 var sw = this.split.el.getWidth();
31383 this.split.el.setLeft(box.x);
31384 this.split.el.setTop(box.y);
31385 this.split.el.setHeight(box.height);
31388 if(this.collapsed){
31389 this.updateBody(null, box.height);
31391 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31395 Roo.WestLayoutRegion = function(mgr, config){
31396 Roo.SplitLayoutRegion.call(this, mgr, config, "west", "w-resize");
31398 this.split.placement = Roo.SplitBar.LEFT;
31399 this.split.orientation = Roo.SplitBar.HORIZONTAL;
31400 this.split.el.addClass("x-layout-split-h");
31402 var size = config.initialSize || config.width;
31403 if(typeof size != "undefined"){
31404 this.el.setWidth(size);
31407 Roo.extend(Roo.WestLayoutRegion, Roo.SplitLayoutRegion, {
31408 orientation: Roo.SplitBar.HORIZONTAL,
31409 getBox : function(){
31410 if(this.collapsed){
31411 return this.collapsedEl.getBox();
31413 var box = this.el.getBox();
31415 box.width += this.split.el.getWidth();
31420 updateBox : function(box){
31421 if(this.split && !this.collapsed){
31422 var sw = this.split.el.getWidth();
31424 this.split.el.setLeft(box.x+box.width);
31425 this.split.el.setTop(box.y);
31426 this.split.el.setHeight(box.height);
31428 if(this.collapsed){
31429 this.updateBody(null, box.height);
31431 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31436 * Ext JS Library 1.1.1
31437 * Copyright(c) 2006-2007, Ext JS, LLC.
31439 * Originally Released Under LGPL - original licence link has changed is not relivant.
31442 * <script type="text/javascript">
31447 * Private internal class for reading and applying state
31449 Roo.LayoutStateManager = function(layout){
31450 // default empty state
31459 Roo.LayoutStateManager.prototype = {
31460 init : function(layout, provider){
31461 this.provider = provider;
31462 var state = provider.get(layout.id+"-layout-state");
31464 var wasUpdating = layout.isUpdating();
31466 layout.beginUpdate();
31468 for(var key in state){
31469 if(typeof state[key] != "function"){
31470 var rstate = state[key];
31471 var r = layout.getRegion(key);
31474 r.resizeTo(rstate.size);
31476 if(rstate.collapsed == true){
31479 r.expand(null, true);
31485 layout.endUpdate();
31487 this.state = state;
31489 this.layout = layout;
31490 layout.on("regionresized", this.onRegionResized, this);
31491 layout.on("regioncollapsed", this.onRegionCollapsed, this);
31492 layout.on("regionexpanded", this.onRegionExpanded, this);
31495 storeState : function(){
31496 this.provider.set(this.layout.id+"-layout-state", this.state);
31499 onRegionResized : function(region, newSize){
31500 this.state[region.getPosition()].size = newSize;
31504 onRegionCollapsed : function(region){
31505 this.state[region.getPosition()].collapsed = true;
31509 onRegionExpanded : function(region){
31510 this.state[region.getPosition()].collapsed = false;
31515 * Ext JS Library 1.1.1
31516 * Copyright(c) 2006-2007, Ext JS, LLC.
31518 * Originally Released Under LGPL - original licence link has changed is not relivant.
31521 * <script type="text/javascript">
31524 * @class Roo.ContentPanel
31525 * @extends Roo.util.Observable
31526 * A basic ContentPanel element.
31527 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
31528 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
31529 * @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
31530 * @cfg {Boolean} closable True if the panel can be closed/removed
31531 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
31532 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
31533 * @cfg {Toolbar} toolbar A toolbar for this panel
31534 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
31535 * @cfg {String} title The title for this panel
31536 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
31537 * @cfg {String} url Calls {@link #setUrl} with this value
31538 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
31539 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
31540 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
31541 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
31544 * Create a new ContentPanel.
31545 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
31546 * @param {String/Object} config A string to set only the title or a config object
31547 * @param {String} content (optional) Set the HTML content for this panel
31548 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
31550 Roo.ContentPanel = function(el, config, content){
31554 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
31558 if (config && config.parentLayout) {
31559 el = config.parentLayout.el.createChild();
31562 if(el.autoCreate){ // xtype is available if this is called from factory
31566 this.el = Roo.get(el);
31567 if(!this.el && config && config.autoCreate){
31568 if(typeof config.autoCreate == "object"){
31569 if(!config.autoCreate.id){
31570 config.autoCreate.id = config.id||el;
31572 this.el = Roo.DomHelper.append(document.body,
31573 config.autoCreate, true);
31575 this.el = Roo.DomHelper.append(document.body,
31576 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
31579 this.closable = false;
31580 this.loaded = false;
31581 this.active = false;
31582 if(typeof config == "string"){
31583 this.title = config;
31585 Roo.apply(this, config);
31588 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
31589 this.wrapEl = this.el.wrap();
31590 this.toolbar.container = this.el.insertSibling(false, 'before');
31591 this.toolbar = new Roo.Toolbar(this.toolbar);
31594 // xtype created footer. - not sure if will work as we normally have to render first..
31595 if (this.footer && !this.footer.el && this.footer.xtype) {
31596 if (!this.wrapEl) {
31597 this.wrapEl = this.el.wrap();
31600 this.footer.container = this.wrapEl.createChild();
31602 this.footer = Roo.factory(this.footer, Roo);
31607 this.resizeEl = Roo.get(this.resizeEl, true);
31609 this.resizeEl = this.el;
31611 // handle view.xtype
31619 * Fires when this panel is activated.
31620 * @param {Roo.ContentPanel} this
31624 * @event deactivate
31625 * Fires when this panel is activated.
31626 * @param {Roo.ContentPanel} this
31628 "deactivate" : true,
31632 * Fires when this panel is resized if fitToFrame is true.
31633 * @param {Roo.ContentPanel} this
31634 * @param {Number} width The width after any component adjustments
31635 * @param {Number} height The height after any component adjustments
31641 * Fires when this tab is created
31642 * @param {Roo.ContentPanel} this
31652 if(this.autoScroll){
31653 this.resizeEl.setStyle("overflow", "auto");
31655 // fix randome scrolling
31656 this.el.on('scroll', function() {
31657 Roo.log('fix random scolling');
31658 this.scrollTo('top',0);
31661 content = content || this.content;
31663 this.setContent(content);
31665 if(config && config.url){
31666 this.setUrl(this.url, this.params, this.loadOnce);
31671 Roo.ContentPanel.superclass.constructor.call(this);
31673 if (this.view && typeof(this.view.xtype) != 'undefined') {
31674 this.view.el = this.el.appendChild(document.createElement("div"));
31675 this.view = Roo.factory(this.view);
31676 this.view.render && this.view.render(false, '');
31680 this.fireEvent('render', this);
31683 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
31685 setRegion : function(region){
31686 this.region = region;
31688 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
31690 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
31695 * Returns the toolbar for this Panel if one was configured.
31696 * @return {Roo.Toolbar}
31698 getToolbar : function(){
31699 return this.toolbar;
31702 setActiveState : function(active){
31703 this.active = active;
31705 this.fireEvent("deactivate", this);
31707 this.fireEvent("activate", this);
31711 * Updates this panel's element
31712 * @param {String} content The new content
31713 * @param {Boolean} loadScripts (optional) true to look for and process scripts
31715 setContent : function(content, loadScripts){
31716 this.el.update(content, loadScripts);
31719 ignoreResize : function(w, h){
31720 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
31723 this.lastSize = {width: w, height: h};
31728 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
31729 * @return {Roo.UpdateManager} The UpdateManager
31731 getUpdateManager : function(){
31732 return this.el.getUpdateManager();
31735 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
31736 * @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:
31739 url: "your-url.php",
31740 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
31741 callback: yourFunction,
31742 scope: yourObject, //(optional scope)
31745 text: "Loading...",
31750 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
31751 * 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.
31752 * @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}
31753 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
31754 * @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.
31755 * @return {Roo.ContentPanel} this
31758 var um = this.el.getUpdateManager();
31759 um.update.apply(um, arguments);
31765 * 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.
31766 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
31767 * @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)
31768 * @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)
31769 * @return {Roo.UpdateManager} The UpdateManager
31771 setUrl : function(url, params, loadOnce){
31772 if(this.refreshDelegate){
31773 this.removeListener("activate", this.refreshDelegate);
31775 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
31776 this.on("activate", this.refreshDelegate);
31777 return this.el.getUpdateManager();
31780 _handleRefresh : function(url, params, loadOnce){
31781 if(!loadOnce || !this.loaded){
31782 var updater = this.el.getUpdateManager();
31783 updater.update(url, params, this._setLoaded.createDelegate(this));
31787 _setLoaded : function(){
31788 this.loaded = true;
31792 * Returns this panel's id
31795 getId : function(){
31800 * Returns this panel's element - used by regiosn to add.
31801 * @return {Roo.Element}
31803 getEl : function(){
31804 return this.wrapEl || this.el;
31807 adjustForComponents : function(width, height)
31809 //Roo.log('adjustForComponents ');
31810 if(this.resizeEl != this.el){
31811 width -= this.el.getFrameWidth('lr');
31812 height -= this.el.getFrameWidth('tb');
31815 var te = this.toolbar.getEl();
31816 height -= te.getHeight();
31817 te.setWidth(width);
31820 var te = this.footer.getEl();
31821 //Roo.log("footer:" + te.getHeight());
31823 height -= te.getHeight();
31824 te.setWidth(width);
31828 if(this.adjustments){
31829 width += this.adjustments[0];
31830 height += this.adjustments[1];
31832 return {"width": width, "height": height};
31835 setSize : function(width, height){
31836 if(this.fitToFrame && !this.ignoreResize(width, height)){
31837 if(this.fitContainer && this.resizeEl != this.el){
31838 this.el.setSize(width, height);
31840 var size = this.adjustForComponents(width, height);
31841 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
31842 this.fireEvent('resize', this, size.width, size.height);
31847 * Returns this panel's title
31850 getTitle : function(){
31855 * Set this panel's title
31856 * @param {String} title
31858 setTitle : function(title){
31859 this.title = title;
31861 this.region.updatePanelTitle(this, title);
31866 * Returns true is this panel was configured to be closable
31867 * @return {Boolean}
31869 isClosable : function(){
31870 return this.closable;
31873 beforeSlide : function(){
31875 this.resizeEl.clip();
31878 afterSlide : function(){
31880 this.resizeEl.unclip();
31884 * Force a content refresh from the URL specified in the {@link #setUrl} method.
31885 * Will fail silently if the {@link #setUrl} method has not been called.
31886 * This does not activate the panel, just updates its content.
31888 refresh : function(){
31889 if(this.refreshDelegate){
31890 this.loaded = false;
31891 this.refreshDelegate();
31896 * Destroys this panel
31898 destroy : function(){
31899 this.el.removeAllListeners();
31900 var tempEl = document.createElement("span");
31901 tempEl.appendChild(this.el.dom);
31902 tempEl.innerHTML = "";
31908 * form - if the content panel contains a form - this is a reference to it.
31909 * @type {Roo.form.Form}
31913 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
31914 * This contains a reference to it.
31920 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
31930 * @param {Object} cfg Xtype definition of item to add.
31933 addxtype : function(cfg) {
31935 if (cfg.xtype.match(/^Form$/)) {
31938 //if (this.footer) {
31939 // el = this.footer.container.insertSibling(false, 'before');
31941 el = this.el.createChild();
31944 this.form = new Roo.form.Form(cfg);
31947 if ( this.form.allItems.length) {
31948 this.form.render(el.dom);
31952 // should only have one of theses..
31953 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
31954 // views.. should not be just added - used named prop 'view''
31956 cfg.el = this.el.appendChild(document.createElement("div"));
31959 var ret = new Roo.factory(cfg);
31961 ret.render && ret.render(false, ''); // render blank..
31970 * @class Roo.GridPanel
31971 * @extends Roo.ContentPanel
31973 * Create a new GridPanel.
31974 * @param {Roo.grid.Grid} grid The grid for this panel
31975 * @param {String/Object} config A string to set only the panel's title, or a config object
31977 Roo.GridPanel = function(grid, config){
31980 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
31981 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
31983 this.wrapper.dom.appendChild(grid.getGridEl().dom);
31985 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
31988 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
31990 // xtype created footer. - not sure if will work as we normally have to render first..
31991 if (this.footer && !this.footer.el && this.footer.xtype) {
31993 this.footer.container = this.grid.getView().getFooterPanel(true);
31994 this.footer.dataSource = this.grid.dataSource;
31995 this.footer = Roo.factory(this.footer, Roo);
31999 grid.monitorWindowResize = false; // turn off autosizing
32000 grid.autoHeight = false;
32001 grid.autoWidth = false;
32003 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
32006 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
32007 getId : function(){
32008 return this.grid.id;
32012 * Returns the grid for this panel
32013 * @return {Roo.grid.Grid}
32015 getGrid : function(){
32019 setSize : function(width, height){
32020 if(!this.ignoreResize(width, height)){
32021 var grid = this.grid;
32022 var size = this.adjustForComponents(width, height);
32023 grid.getGridEl().setSize(size.width, size.height);
32028 beforeSlide : function(){
32029 this.grid.getView().scroller.clip();
32032 afterSlide : function(){
32033 this.grid.getView().scroller.unclip();
32036 destroy : function(){
32037 this.grid.destroy();
32039 Roo.GridPanel.superclass.destroy.call(this);
32045 * @class Roo.NestedLayoutPanel
32046 * @extends Roo.ContentPanel
32048 * Create a new NestedLayoutPanel.
32051 * @param {Roo.BorderLayout} layout The layout for this panel
32052 * @param {String/Object} config A string to set only the title or a config object
32054 Roo.NestedLayoutPanel = function(layout, config)
32056 // construct with only one argument..
32057 /* FIXME - implement nicer consturctors
32058 if (layout.layout) {
32060 layout = config.layout;
32061 delete config.layout;
32063 if (layout.xtype && !layout.getEl) {
32064 // then layout needs constructing..
32065 layout = Roo.factory(layout, Roo);
32070 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
32072 layout.monitorWindowResize = false; // turn off autosizing
32073 this.layout = layout;
32074 this.layout.getEl().addClass("x-layout-nested-layout");
32081 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
32083 setSize : function(width, height){
32084 if(!this.ignoreResize(width, height)){
32085 var size = this.adjustForComponents(width, height);
32086 var el = this.layout.getEl();
32087 el.setSize(size.width, size.height);
32088 var touch = el.dom.offsetWidth;
32089 this.layout.layout();
32090 // ie requires a double layout on the first pass
32091 if(Roo.isIE && !this.initialized){
32092 this.initialized = true;
32093 this.layout.layout();
32098 // activate all subpanels if not currently active..
32100 setActiveState : function(active){
32101 this.active = active;
32103 this.fireEvent("deactivate", this);
32107 this.fireEvent("activate", this);
32108 // not sure if this should happen before or after..
32109 if (!this.layout) {
32110 return; // should not happen..
32113 for (var r in this.layout.regions) {
32114 reg = this.layout.getRegion(r);
32115 if (reg.getActivePanel()) {
32116 //reg.showPanel(reg.getActivePanel()); // force it to activate..
32117 reg.setActivePanel(reg.getActivePanel());
32120 if (!reg.panels.length) {
32123 reg.showPanel(reg.getPanel(0));
32132 * Returns the nested BorderLayout for this panel
32133 * @return {Roo.BorderLayout}
32135 getLayout : function(){
32136 return this.layout;
32140 * Adds a xtype elements to the layout of the nested panel
32144 xtype : 'ContentPanel',
32151 xtype : 'NestedLayoutPanel',
32157 items : [ ... list of content panels or nested layout panels.. ]
32161 * @param {Object} cfg Xtype definition of item to add.
32163 addxtype : function(cfg) {
32164 return this.layout.addxtype(cfg);
32169 Roo.ScrollPanel = function(el, config, content){
32170 config = config || {};
32171 config.fitToFrame = true;
32172 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
32174 this.el.dom.style.overflow = "hidden";
32175 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
32176 this.el.removeClass("x-layout-inactive-content");
32177 this.el.on("mousewheel", this.onWheel, this);
32179 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
32180 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
32181 up.unselectable(); down.unselectable();
32182 up.on("click", this.scrollUp, this);
32183 down.on("click", this.scrollDown, this);
32184 up.addClassOnOver("x-scroller-btn-over");
32185 down.addClassOnOver("x-scroller-btn-over");
32186 up.addClassOnClick("x-scroller-btn-click");
32187 down.addClassOnClick("x-scroller-btn-click");
32188 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
32190 this.resizeEl = this.el;
32191 this.el = wrap; this.up = up; this.down = down;
32194 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
32196 wheelIncrement : 5,
32197 scrollUp : function(){
32198 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
32201 scrollDown : function(){
32202 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
32205 afterScroll : function(){
32206 var el = this.resizeEl;
32207 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
32208 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
32209 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
32212 setSize : function(){
32213 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
32214 this.afterScroll();
32217 onWheel : function(e){
32218 var d = e.getWheelDelta();
32219 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
32220 this.afterScroll();
32224 setContent : function(content, loadScripts){
32225 this.resizeEl.update(content, loadScripts);
32239 * @class Roo.TreePanel
32240 * @extends Roo.ContentPanel
32242 * Create a new TreePanel. - defaults to fit/scoll contents.
32243 * @param {String/Object} config A string to set only the panel's title, or a config object
32244 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
32246 Roo.TreePanel = function(config){
32247 var el = config.el;
32248 var tree = config.tree;
32249 delete config.tree;
32250 delete config.el; // hopefull!
32252 // wrapper for IE7 strict & safari scroll issue
32254 var treeEl = el.createChild();
32255 config.resizeEl = treeEl;
32259 Roo.TreePanel.superclass.constructor.call(this, el, config);
32262 this.tree = new Roo.tree.TreePanel(treeEl , tree);
32263 //console.log(tree);
32264 this.on('activate', function()
32266 if (this.tree.rendered) {
32269 //console.log('render tree');
32270 this.tree.render();
32272 // this should not be needed.. - it's actually the 'el' that resizes?
32273 // actuall it breaks the containerScroll - dragging nodes auto scroll at top
32275 //this.on('resize', function (cp, w, h) {
32276 // this.tree.innerCt.setWidth(w);
32277 // this.tree.innerCt.setHeight(h);
32278 // //this.tree.innerCt.setStyle('overflow-y', 'auto');
32285 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {
32302 * Ext JS Library 1.1.1
32303 * Copyright(c) 2006-2007, Ext JS, LLC.
32305 * Originally Released Under LGPL - original licence link has changed is not relivant.
32308 * <script type="text/javascript">
32313 * @class Roo.ReaderLayout
32314 * @extends Roo.BorderLayout
32315 * This is a pre-built layout that represents a classic, 5-pane application. It consists of a header, a primary
32316 * center region containing two nested regions (a top one for a list view and one for item preview below),
32317 * and regions on either side that can be used for navigation, application commands, informational displays, etc.
32318 * The setup and configuration work exactly the same as it does for a {@link Roo.BorderLayout} - this class simply
32319 * expedites the setup of the overall layout and regions for this common application style.
32322 var reader = new Roo.ReaderLayout();
32323 var CP = Roo.ContentPanel; // shortcut for adding
32325 reader.beginUpdate();
32326 reader.add("north", new CP("north", "North"));
32327 reader.add("west", new CP("west", {title: "West"}));
32328 reader.add("east", new CP("east", {title: "East"}));
32330 reader.regions.listView.add(new CP("listView", "List"));
32331 reader.regions.preview.add(new CP("preview", "Preview"));
32332 reader.endUpdate();
32335 * Create a new ReaderLayout
32336 * @param {Object} config Configuration options
32337 * @param {String/HTMLElement/Element} container (optional) The container this layout is bound to (defaults to
32338 * document.body if omitted)
32340 Roo.ReaderLayout = function(config, renderTo){
32341 var c = config || {size:{}};
32342 Roo.ReaderLayout.superclass.constructor.call(this, renderTo || document.body, {
32343 north: c.north !== false ? Roo.apply({
32347 }, c.north) : false,
32348 west: c.west !== false ? Roo.apply({
32356 margins:{left:5,right:0,bottom:5,top:5},
32357 cmargins:{left:5,right:5,bottom:5,top:5}
32358 }, c.west) : false,
32359 east: c.east !== false ? Roo.apply({
32367 margins:{left:0,right:5,bottom:5,top:5},
32368 cmargins:{left:5,right:5,bottom:5,top:5}
32369 }, c.east) : false,
32370 center: Roo.apply({
32371 tabPosition: 'top',
32375 margins:{left:c.west!==false ? 0 : 5,right:c.east!==false ? 0 : 5,bottom:5,top:2}
32379 this.el.addClass('x-reader');
32381 this.beginUpdate();
32383 var inner = new Roo.BorderLayout(Roo.get(document.body).createChild(), {
32384 south: c.preview !== false ? Roo.apply({
32391 cmargins:{top:5,left:0, right:0, bottom:0}
32392 }, c.preview) : false,
32393 center: Roo.apply({
32399 this.add('center', new Roo.NestedLayoutPanel(inner,
32400 Roo.apply({title: c.mainTitle || '',tabTip:''},c.innerPanelCfg)));
32404 this.regions.preview = inner.getRegion('south');
32405 this.regions.listView = inner.getRegion('center');
32408 Roo.extend(Roo.ReaderLayout, Roo.BorderLayout);/*
32410 * Ext JS Library 1.1.1
32411 * Copyright(c) 2006-2007, Ext JS, LLC.
32413 * Originally Released Under LGPL - original licence link has changed is not relivant.
32416 * <script type="text/javascript">
32420 * @class Roo.grid.Grid
32421 * @extends Roo.util.Observable
32422 * This class represents the primary interface of a component based grid control.
32423 * <br><br>Usage:<pre><code>
32424 var grid = new Roo.grid.Grid("my-container-id", {
32427 selModel: mySelectionModel,
32428 autoSizeColumns: true,
32429 monitorWindowResize: false,
32430 trackMouseOver: true
32435 * <b>Common Problems:</b><br/>
32436 * - Grid does not resize properly when going smaller: Setting overflow hidden on the container
32437 * element will correct this<br/>
32438 * - If you get el.style[camel]= NaNpx or -2px or something related, be certain you have given your container element
32439 * dimensions. The grid adapts to your container's size, if your container has no size defined then the results
32440 * are unpredictable.<br/>
32441 * - Do not render the grid into an element with display:none. Try using visibility:hidden. Otherwise there is no way for the
32442 * grid to calculate dimensions/offsets.<br/>
32444 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
32445 * The container MUST have some type of size defined for the grid to fill. The container will be
32446 * automatically set to position relative if it isn't already.
32447 * @param {Object} config A config object that sets properties on this grid.
32449 Roo.grid.Grid = function(container, config){
32450 // initialize the container
32451 this.container = Roo.get(container);
32452 this.container.update("");
32453 this.container.setStyle("overflow", "hidden");
32454 this.container.addClass('x-grid-container');
32456 this.id = this.container.id;
32458 Roo.apply(this, config);
32459 // check and correct shorthanded configs
32461 this.dataSource = this.ds;
32465 this.colModel = this.cm;
32469 this.selModel = this.sm;
32473 if (this.selModel) {
32474 this.selModel = Roo.factory(this.selModel, Roo.grid);
32475 this.sm = this.selModel;
32476 this.sm.xmodule = this.xmodule || false;
32478 if (typeof(this.colModel.config) == 'undefined') {
32479 this.colModel = new Roo.grid.ColumnModel(this.colModel);
32480 this.cm = this.colModel;
32481 this.cm.xmodule = this.xmodule || false;
32483 if (this.dataSource) {
32484 this.dataSource= Roo.factory(this.dataSource, Roo.data);
32485 this.ds = this.dataSource;
32486 this.ds.xmodule = this.xmodule || false;
32493 this.container.setWidth(this.width);
32497 this.container.setHeight(this.height);
32504 * The raw click event for the entire grid.
32505 * @param {Roo.EventObject} e
32510 * The raw dblclick event for the entire grid.
32511 * @param {Roo.EventObject} e
32515 * @event contextmenu
32516 * The raw contextmenu event for the entire grid.
32517 * @param {Roo.EventObject} e
32519 "contextmenu" : true,
32522 * The raw mousedown event for the entire grid.
32523 * @param {Roo.EventObject} e
32525 "mousedown" : true,
32528 * The raw mouseup event for the entire grid.
32529 * @param {Roo.EventObject} e
32534 * The raw mouseover event for the entire grid.
32535 * @param {Roo.EventObject} e
32537 "mouseover" : true,
32540 * The raw mouseout event for the entire grid.
32541 * @param {Roo.EventObject} e
32546 * The raw keypress event for the entire grid.
32547 * @param {Roo.EventObject} e
32552 * The raw keydown event for the entire grid.
32553 * @param {Roo.EventObject} e
32561 * Fires when a cell is clicked
32562 * @param {Grid} this
32563 * @param {Number} rowIndex
32564 * @param {Number} columnIndex
32565 * @param {Roo.EventObject} e
32567 "cellclick" : true,
32569 * @event celldblclick
32570 * Fires when a cell is double clicked
32571 * @param {Grid} this
32572 * @param {Number} rowIndex
32573 * @param {Number} columnIndex
32574 * @param {Roo.EventObject} e
32576 "celldblclick" : true,
32579 * Fires when a row is clicked
32580 * @param {Grid} this
32581 * @param {Number} rowIndex
32582 * @param {Roo.EventObject} e
32586 * @event rowdblclick
32587 * Fires when a row is double clicked
32588 * @param {Grid} this
32589 * @param {Number} rowIndex
32590 * @param {Roo.EventObject} e
32592 "rowdblclick" : true,
32594 * @event headerclick
32595 * Fires when a header is clicked
32596 * @param {Grid} this
32597 * @param {Number} columnIndex
32598 * @param {Roo.EventObject} e
32600 "headerclick" : true,
32602 * @event headerdblclick
32603 * Fires when a header cell is double clicked
32604 * @param {Grid} this
32605 * @param {Number} columnIndex
32606 * @param {Roo.EventObject} e
32608 "headerdblclick" : true,
32610 * @event rowcontextmenu
32611 * Fires when a row is right clicked
32612 * @param {Grid} this
32613 * @param {Number} rowIndex
32614 * @param {Roo.EventObject} e
32616 "rowcontextmenu" : true,
32618 * @event cellcontextmenu
32619 * Fires when a cell is right clicked
32620 * @param {Grid} this
32621 * @param {Number} rowIndex
32622 * @param {Number} cellIndex
32623 * @param {Roo.EventObject} e
32625 "cellcontextmenu" : true,
32627 * @event headercontextmenu
32628 * Fires when a header is right clicked
32629 * @param {Grid} this
32630 * @param {Number} columnIndex
32631 * @param {Roo.EventObject} e
32633 "headercontextmenu" : true,
32635 * @event bodyscroll
32636 * Fires when the body element is scrolled
32637 * @param {Number} scrollLeft
32638 * @param {Number} scrollTop
32640 "bodyscroll" : true,
32642 * @event columnresize
32643 * Fires when the user resizes a column
32644 * @param {Number} columnIndex
32645 * @param {Number} newSize
32647 "columnresize" : true,
32649 * @event columnmove
32650 * Fires when the user moves a column
32651 * @param {Number} oldIndex
32652 * @param {Number} newIndex
32654 "columnmove" : true,
32657 * Fires when row(s) start being dragged
32658 * @param {Grid} this
32659 * @param {Roo.GridDD} dd The drag drop object
32660 * @param {event} e The raw browser event
32662 "startdrag" : true,
32665 * Fires when a drag operation is complete
32666 * @param {Grid} this
32667 * @param {Roo.GridDD} dd The drag drop object
32668 * @param {event} e The raw browser event
32673 * Fires when dragged row(s) are dropped on a valid DD target
32674 * @param {Grid} this
32675 * @param {Roo.GridDD} dd The drag drop object
32676 * @param {String} targetId The target drag drop object
32677 * @param {event} e The raw browser event
32682 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
32683 * @param {Grid} this
32684 * @param {Roo.GridDD} dd The drag drop object
32685 * @param {String} targetId The target drag drop object
32686 * @param {event} e The raw browser event
32691 * Fires when the dragged row(s) first cross another DD target while being dragged
32692 * @param {Grid} this
32693 * @param {Roo.GridDD} dd The drag drop object
32694 * @param {String} targetId The target drag drop object
32695 * @param {event} e The raw browser event
32697 "dragenter" : true,
32700 * Fires when the dragged row(s) leave another DD target while being dragged
32701 * @param {Grid} this
32702 * @param {Roo.GridDD} dd The drag drop object
32703 * @param {String} targetId The target drag drop object
32704 * @param {event} e The raw browser event
32709 * Fires when a row is rendered, so you can change add a style to it.
32710 * @param {GridView} gridview The grid view
32711 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
32717 * Fires when the grid is rendered
32718 * @param {Grid} grid
32723 Roo.grid.Grid.superclass.constructor.call(this);
32725 Roo.extend(Roo.grid.Grid, Roo.util.Observable, {
32728 * @cfg {String} ddGroup - drag drop group.
32732 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Default is 25.
32734 minColumnWidth : 25,
32737 * @cfg {Boolean} autoSizeColumns True to automatically resize the columns to fit their content
32738 * <b>on initial render.</b> It is more efficient to explicitly size the columns
32739 * through the ColumnModel's {@link Roo.grid.ColumnModel#width} config option. Default is false.
32741 autoSizeColumns : false,
32744 * @cfg {Boolean} autoSizeHeaders True to measure headers with column data when auto sizing columns. Default is true.
32746 autoSizeHeaders : true,
32749 * @cfg {Boolean} monitorWindowResize True to autoSize the grid when the window resizes. Default is true.
32751 monitorWindowResize : true,
32754 * @cfg {Boolean} maxRowsToMeasure If autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of
32755 * rows measured to get a columns size. Default is 0 (all rows).
32757 maxRowsToMeasure : 0,
32760 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is true.
32762 trackMouseOver : true,
32765 * @cfg {Boolean} enableDrag True to enable drag of rows. Default is false. (double check if this is needed?)
32769 * @cfg {Boolean} enableDragDrop True to enable drag and drop of rows. Default is false.
32771 enableDragDrop : false,
32774 * @cfg {Boolean} enableColumnMove True to enable drag and drop reorder of columns. Default is true.
32776 enableColumnMove : true,
32779 * @cfg {Boolean} enableColumnHide True to enable hiding of columns with the header context menu. Default is true.
32781 enableColumnHide : true,
32784 * @cfg {Boolean} enableRowHeightSync True to manually sync row heights across locked and not locked rows. Default is false.
32786 enableRowHeightSync : false,
32789 * @cfg {Boolean} stripeRows True to stripe the rows. Default is true.
32794 * @cfg {Boolean} autoHeight True to fit the height of the grid container to the height of the data. Default is false.
32796 autoHeight : false,
32799 * @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.
32801 autoExpandColumn : false,
32804 * @cfg {Number} autoExpandMin The minimum width the autoExpandColumn can have (if enabled).
32807 autoExpandMin : 50,
32810 * @cfg {Number} autoExpandMax The maximum width the autoExpandColumn can have (if enabled). Default is 1000.
32812 autoExpandMax : 1000,
32815 * @cfg {Object} view The {@link Roo.grid.GridView} used by the grid. This can be set before a call to render().
32820 * @cfg {Object} loadMask An {@link Roo.LoadMask} config or true to mask the grid while loading. Default is false.
32824 * @cfg {Roo.dd.DropTarget} dropTarget An {@link Roo.dd.DropTarget} config
32834 * @cfg {Boolean} autoWidth True to set the grid's width to the default total width of the grid's columns instead
32835 * of a fixed width. Default is false.
32838 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if autoHeight is not on.
32841 * Called once after all setup has been completed and the grid is ready to be rendered.
32842 * @return {Roo.grid.Grid} this
32844 render : function()
32846 var c = this.container;
32847 // try to detect autoHeight/width mode
32848 if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
32849 this.autoHeight = true;
32851 var view = this.getView();
32854 c.on("click", this.onClick, this);
32855 c.on("dblclick", this.onDblClick, this);
32856 c.on("contextmenu", this.onContextMenu, this);
32857 c.on("keydown", this.onKeyDown, this);
32859 c.on("touchstart", this.onTouchStart, this);
32862 this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
32864 this.getSelectionModel().init(this);
32869 this.loadMask = new Roo.LoadMask(this.container,
32870 Roo.apply({store:this.dataSource}, this.loadMask));
32874 if (this.toolbar && this.toolbar.xtype) {
32875 this.toolbar.container = this.getView().getHeaderPanel(true);
32876 this.toolbar = new Roo.Toolbar(this.toolbar);
32878 if (this.footer && this.footer.xtype) {
32879 this.footer.dataSource = this.getDataSource();
32880 this.footer.container = this.getView().getFooterPanel(true);
32881 this.footer = Roo.factory(this.footer, Roo);
32883 if (this.dropTarget && this.dropTarget.xtype) {
32884 delete this.dropTarget.xtype;
32885 this.dropTarget = new Roo.dd.DropTarget(this.getView().mainBody, this.dropTarget);
32889 this.rendered = true;
32890 this.fireEvent('render', this);
32895 * Reconfigures the grid to use a different Store and Column Model.
32896 * The View will be bound to the new objects and refreshed.
32897 * @param {Roo.data.Store} dataSource The new {@link Roo.data.Store} object
32898 * @param {Roo.grid.ColumnModel} The new {@link Roo.grid.ColumnModel} object
32900 reconfigure : function(dataSource, colModel){
32902 this.loadMask.destroy();
32903 this.loadMask = new Roo.LoadMask(this.container,
32904 Roo.apply({store:dataSource}, this.loadMask));
32906 this.view.bind(dataSource, colModel);
32907 this.dataSource = dataSource;
32908 this.colModel = colModel;
32909 this.view.refresh(true);
32913 onKeyDown : function(e){
32914 this.fireEvent("keydown", e);
32918 * Destroy this grid.
32919 * @param {Boolean} removeEl True to remove the element
32921 destroy : function(removeEl, keepListeners){
32923 this.loadMask.destroy();
32925 var c = this.container;
32926 c.removeAllListeners();
32927 this.view.destroy();
32928 this.colModel.purgeListeners();
32929 if(!keepListeners){
32930 this.purgeListeners();
32933 if(removeEl === true){
32939 processEvent : function(name, e){
32940 // does this fire select???
32941 //Roo.log('grid:processEvent ' + name);
32943 if (name != 'touchstart' ) {
32944 this.fireEvent(name, e);
32947 var t = e.getTarget();
32949 var header = v.findHeaderIndex(t);
32950 if(header !== false){
32951 var ename = name == 'touchstart' ? 'click' : name;
32953 this.fireEvent("header" + ename, this, header, e);
32955 var row = v.findRowIndex(t);
32956 var cell = v.findCellIndex(t);
32957 if (name == 'touchstart') {
32958 // first touch is always a click.
32959 // hopefull this happens after selection is updated.?
32962 if (typeof(this.selModel.getSelectedCell) != 'undefined') {
32963 var cs = this.selModel.getSelectedCell();
32964 if (row == cs[0] && cell == cs[1]){
32968 if (typeof(this.selModel.getSelections) != 'undefined') {
32969 var cs = this.selModel.getSelections();
32970 var ds = this.dataSource;
32971 if (cs.length == 1 && ds.getAt(row) == cs[0]){
32982 this.fireEvent("row" + name, this, row, e);
32983 if(cell !== false){
32984 this.fireEvent("cell" + name, this, row, cell, e);
32991 onClick : function(e){
32992 this.processEvent("click", e);
32995 onTouchStart : function(e){
32996 this.processEvent("touchstart", e);
33000 onContextMenu : function(e, t){
33001 this.processEvent("contextmenu", e);
33005 onDblClick : function(e){
33006 this.processEvent("dblclick", e);
33010 walkCells : function(row, col, step, fn, scope){
33011 var cm = this.colModel, clen = cm.getColumnCount();
33012 var ds = this.dataSource, rlen = ds.getCount(), first = true;
33024 if(fn.call(scope || this, row, col, cm) === true){
33042 if(fn.call(scope || this, row, col, cm) === true){
33054 getSelections : function(){
33055 return this.selModel.getSelections();
33059 * Causes the grid to manually recalculate its dimensions. Generally this is done automatically,
33060 * but if manual update is required this method will initiate it.
33062 autoSize : function(){
33064 this.view.layout();
33065 if(this.view.adjustForScroll){
33066 this.view.adjustForScroll();
33072 * Returns the grid's underlying element.
33073 * @return {Element} The element
33075 getGridEl : function(){
33076 return this.container;
33079 // private for compatibility, overridden by editor grid
33080 stopEditing : function(){},
33083 * Returns the grid's SelectionModel.
33084 * @return {SelectionModel}
33086 getSelectionModel : function(){
33087 if(!this.selModel){
33088 this.selModel = new Roo.grid.RowSelectionModel();
33090 return this.selModel;
33094 * Returns the grid's DataSource.
33095 * @return {DataSource}
33097 getDataSource : function(){
33098 return this.dataSource;
33102 * Returns the grid's ColumnModel.
33103 * @return {ColumnModel}
33105 getColumnModel : function(){
33106 return this.colModel;
33110 * Returns the grid's GridView object.
33111 * @return {GridView}
33113 getView : function(){
33115 this.view = new Roo.grid.GridView(this.viewConfig);
33120 * Called to get grid's drag proxy text, by default returns this.ddText.
33123 getDragDropText : function(){
33124 var count = this.selModel.getCount();
33125 return String.format(this.ddText, count, count == 1 ? '' : 's');
33129 * Configures the text is the drag proxy (defaults to "%0 selected row(s)").
33130 * %0 is replaced with the number of selected rows.
33133 Roo.grid.Grid.prototype.ddText = "{0} selected row{1}";/*
33135 * Ext JS Library 1.1.1
33136 * Copyright(c) 2006-2007, Ext JS, LLC.
33138 * Originally Released Under LGPL - original licence link has changed is not relivant.
33141 * <script type="text/javascript">
33144 Roo.grid.AbstractGridView = function(){
33148 "beforerowremoved" : true,
33149 "beforerowsinserted" : true,
33150 "beforerefresh" : true,
33151 "rowremoved" : true,
33152 "rowsinserted" : true,
33153 "rowupdated" : true,
33156 Roo.grid.AbstractGridView.superclass.constructor.call(this);
33159 Roo.extend(Roo.grid.AbstractGridView, Roo.util.Observable, {
33160 rowClass : "x-grid-row",
33161 cellClass : "x-grid-cell",
33162 tdClass : "x-grid-td",
33163 hdClass : "x-grid-hd",
33164 splitClass : "x-grid-hd-split",
33166 init: function(grid){
33168 var cid = this.grid.getGridEl().id;
33169 this.colSelector = "#" + cid + " ." + this.cellClass + "-";
33170 this.tdSelector = "#" + cid + " ." + this.tdClass + "-";
33171 this.hdSelector = "#" + cid + " ." + this.hdClass + "-";
33172 this.splitSelector = "#" + cid + " ." + this.splitClass + "-";
33175 getColumnRenderers : function(){
33176 var renderers = [];
33177 var cm = this.grid.colModel;
33178 var colCount = cm.getColumnCount();
33179 for(var i = 0; i < colCount; i++){
33180 renderers[i] = cm.getRenderer(i);
33185 getColumnIds : function(){
33187 var cm = this.grid.colModel;
33188 var colCount = cm.getColumnCount();
33189 for(var i = 0; i < colCount; i++){
33190 ids[i] = cm.getColumnId(i);
33195 getDataIndexes : function(){
33196 if(!this.indexMap){
33197 this.indexMap = this.buildIndexMap();
33199 return this.indexMap.colToData;
33202 getColumnIndexByDataIndex : function(dataIndex){
33203 if(!this.indexMap){
33204 this.indexMap = this.buildIndexMap();
33206 return this.indexMap.dataToCol[dataIndex];
33210 * Set a css style for a column dynamically.
33211 * @param {Number} colIndex The index of the column
33212 * @param {String} name The css property name
33213 * @param {String} value The css value
33215 setCSSStyle : function(colIndex, name, value){
33216 var selector = "#" + this.grid.id + " .x-grid-col-" + colIndex;
33217 Roo.util.CSS.updateRule(selector, name, value);
33220 generateRules : function(cm){
33221 var ruleBuf = [], rulesId = this.grid.id + '-cssrules';
33222 Roo.util.CSS.removeStyleSheet(rulesId);
33223 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
33224 var cid = cm.getColumnId(i);
33225 ruleBuf.push(this.colSelector, cid, " {\n", cm.config[i].css, "}\n",
33226 this.tdSelector, cid, " {\n}\n",
33227 this.hdSelector, cid, " {\n}\n",
33228 this.splitSelector, cid, " {\n}\n");
33230 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
33234 * Ext JS Library 1.1.1
33235 * Copyright(c) 2006-2007, Ext JS, LLC.
33237 * Originally Released Under LGPL - original licence link has changed is not relivant.
33240 * <script type="text/javascript">
33244 // This is a support class used internally by the Grid components
33245 Roo.grid.HeaderDragZone = function(grid, hd, hd2){
33247 this.view = grid.getView();
33248 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
33249 Roo.grid.HeaderDragZone.superclass.constructor.call(this, hd);
33251 this.setHandleElId(Roo.id(hd));
33252 this.setOuterHandleElId(Roo.id(hd2));
33254 this.scroll = false;
33256 Roo.extend(Roo.grid.HeaderDragZone, Roo.dd.DragZone, {
33258 getDragData : function(e){
33259 var t = Roo.lib.Event.getTarget(e);
33260 var h = this.view.findHeaderCell(t);
33262 return {ddel: h.firstChild, header:h};
33267 onInitDrag : function(e){
33268 this.view.headersDisabled = true;
33269 var clone = this.dragData.ddel.cloneNode(true);
33270 clone.id = Roo.id();
33271 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
33272 this.proxy.update(clone);
33276 afterValidDrop : function(){
33278 setTimeout(function(){
33279 v.headersDisabled = false;
33283 afterInvalidDrop : function(){
33285 setTimeout(function(){
33286 v.headersDisabled = false;
33292 * Ext JS Library 1.1.1
33293 * Copyright(c) 2006-2007, Ext JS, LLC.
33295 * Originally Released Under LGPL - original licence link has changed is not relivant.
33298 * <script type="text/javascript">
33301 // This is a support class used internally by the Grid components
33302 Roo.grid.HeaderDropZone = function(grid, hd, hd2){
33304 this.view = grid.getView();
33305 // split the proxies so they don't interfere with mouse events
33306 this.proxyTop = Roo.DomHelper.append(document.body, {
33307 cls:"col-move-top", html:" "
33309 this.proxyBottom = Roo.DomHelper.append(document.body, {
33310 cls:"col-move-bottom", html:" "
33312 this.proxyTop.hide = this.proxyBottom.hide = function(){
33313 this.setLeftTop(-100,-100);
33314 this.setStyle("visibility", "hidden");
33316 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
33317 // temporarily disabled
33318 //Roo.dd.ScrollManager.register(this.view.scroller.dom);
33319 Roo.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
33321 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
33322 proxyOffsets : [-4, -9],
33323 fly: Roo.Element.fly,
33325 getTargetFromEvent : function(e){
33326 var t = Roo.lib.Event.getTarget(e);
33327 var cindex = this.view.findCellIndex(t);
33328 if(cindex !== false){
33329 return this.view.getHeaderCell(cindex);
33334 nextVisible : function(h){
33335 var v = this.view, cm = this.grid.colModel;
33338 if(!cm.isHidden(v.getCellIndex(h))){
33346 prevVisible : function(h){
33347 var v = this.view, cm = this.grid.colModel;
33350 if(!cm.isHidden(v.getCellIndex(h))){
33358 positionIndicator : function(h, n, e){
33359 var x = Roo.lib.Event.getPageX(e);
33360 var r = Roo.lib.Dom.getRegion(n.firstChild);
33361 var px, pt, py = r.top + this.proxyOffsets[1];
33362 if((r.right - x) <= (r.right-r.left)/2){
33363 px = r.right+this.view.borderWidth;
33369 var oldIndex = this.view.getCellIndex(h);
33370 var newIndex = this.view.getCellIndex(n);
33372 if(this.grid.colModel.isFixed(newIndex)){
33376 var locked = this.grid.colModel.isLocked(newIndex);
33381 if(oldIndex < newIndex){
33384 if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){
33387 px += this.proxyOffsets[0];
33388 this.proxyTop.setLeftTop(px, py);
33389 this.proxyTop.show();
33390 if(!this.bottomOffset){
33391 this.bottomOffset = this.view.mainHd.getHeight();
33393 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
33394 this.proxyBottom.show();
33398 onNodeEnter : function(n, dd, e, data){
33399 if(data.header != n){
33400 this.positionIndicator(data.header, n, e);
33404 onNodeOver : function(n, dd, e, data){
33405 var result = false;
33406 if(data.header != n){
33407 result = this.positionIndicator(data.header, n, e);
33410 this.proxyTop.hide();
33411 this.proxyBottom.hide();
33413 return result ? this.dropAllowed : this.dropNotAllowed;
33416 onNodeOut : function(n, dd, e, data){
33417 this.proxyTop.hide();
33418 this.proxyBottom.hide();
33421 onNodeDrop : function(n, dd, e, data){
33422 var h = data.header;
33424 var cm = this.grid.colModel;
33425 var x = Roo.lib.Event.getPageX(e);
33426 var r = Roo.lib.Dom.getRegion(n.firstChild);
33427 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
33428 var oldIndex = this.view.getCellIndex(h);
33429 var newIndex = this.view.getCellIndex(n);
33430 var locked = cm.isLocked(newIndex);
33434 if(oldIndex < newIndex){
33437 if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){
33440 cm.setLocked(oldIndex, locked, true);
33441 cm.moveColumn(oldIndex, newIndex);
33442 this.grid.fireEvent("columnmove", oldIndex, newIndex);
33450 * Ext JS Library 1.1.1
33451 * Copyright(c) 2006-2007, Ext JS, LLC.
33453 * Originally Released Under LGPL - original licence link has changed is not relivant.
33456 * <script type="text/javascript">
33460 * @class Roo.grid.GridView
33461 * @extends Roo.util.Observable
33464 * @param {Object} config
33466 Roo.grid.GridView = function(config){
33467 Roo.grid.GridView.superclass.constructor.call(this);
33470 Roo.apply(this, config);
33473 Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
33475 unselectable : 'unselectable="on"',
33476 unselectableCls : 'x-unselectable',
33479 rowClass : "x-grid-row",
33481 cellClass : "x-grid-col",
33483 tdClass : "x-grid-td",
33485 hdClass : "x-grid-hd",
33487 splitClass : "x-grid-split",
33489 sortClasses : ["sort-asc", "sort-desc"],
33491 enableMoveAnim : false,
33495 dh : Roo.DomHelper,
33497 fly : Roo.Element.fly,
33499 css : Roo.util.CSS,
33505 scrollIncrement : 22,
33507 cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
33509 findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
33511 bind : function(ds, cm){
33513 this.ds.un("load", this.onLoad, this);
33514 this.ds.un("datachanged", this.onDataChange, this);
33515 this.ds.un("add", this.onAdd, this);
33516 this.ds.un("remove", this.onRemove, this);
33517 this.ds.un("update", this.onUpdate, this);
33518 this.ds.un("clear", this.onClear, this);
33521 ds.on("load", this.onLoad, this);
33522 ds.on("datachanged", this.onDataChange, this);
33523 ds.on("add", this.onAdd, this);
33524 ds.on("remove", this.onRemove, this);
33525 ds.on("update", this.onUpdate, this);
33526 ds.on("clear", this.onClear, this);
33531 this.cm.un("widthchange", this.onColWidthChange, this);
33532 this.cm.un("headerchange", this.onHeaderChange, this);
33533 this.cm.un("hiddenchange", this.onHiddenChange, this);
33534 this.cm.un("columnmoved", this.onColumnMove, this);
33535 this.cm.un("columnlockchange", this.onColumnLock, this);
33538 this.generateRules(cm);
33539 cm.on("widthchange", this.onColWidthChange, this);
33540 cm.on("headerchange", this.onHeaderChange, this);
33541 cm.on("hiddenchange", this.onHiddenChange, this);
33542 cm.on("columnmoved", this.onColumnMove, this);
33543 cm.on("columnlockchange", this.onColumnLock, this);
33548 init: function(grid){
33549 Roo.grid.GridView.superclass.init.call(this, grid);
33551 this.bind(grid.dataSource, grid.colModel);
33553 grid.on("headerclick", this.handleHeaderClick, this);
33555 if(grid.trackMouseOver){
33556 grid.on("mouseover", this.onRowOver, this);
33557 grid.on("mouseout", this.onRowOut, this);
33559 grid.cancelTextSelection = function(){};
33560 this.gridId = grid.id;
33562 var tpls = this.templates || {};
33565 tpls.master = new Roo.Template(
33566 '<div class="x-grid" hidefocus="true">',
33567 '<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
33568 '<div class="x-grid-topbar"></div>',
33569 '<div class="x-grid-scroller"><div></div></div>',
33570 '<div class="x-grid-locked">',
33571 '<div class="x-grid-header">{lockedHeader}</div>',
33572 '<div class="x-grid-body">{lockedBody}</div>',
33574 '<div class="x-grid-viewport">',
33575 '<div class="x-grid-header">{header}</div>',
33576 '<div class="x-grid-body">{body}</div>',
33578 '<div class="x-grid-bottombar"></div>',
33580 '<div class="x-grid-resize-proxy"> </div>',
33583 tpls.master.disableformats = true;
33587 tpls.header = new Roo.Template(
33588 '<table border="0" cellspacing="0" cellpadding="0">',
33589 '<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
33592 tpls.header.disableformats = true;
33594 tpls.header.compile();
33597 tpls.hcell = new Roo.Template(
33598 '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
33599 '<div class="x-grid-hd-text ' + this.unselectableCls + '" ' + this.unselectable +'>{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
33602 tpls.hcell.disableFormats = true;
33604 tpls.hcell.compile();
33607 tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style} ' +
33608 this.unselectableCls + '" ' + this.unselectable +'> </div>');
33609 tpls.hsplit.disableFormats = true;
33611 tpls.hsplit.compile();
33614 tpls.body = new Roo.Template(
33615 '<table border="0" cellspacing="0" cellpadding="0">',
33616 "<tbody>{rows}</tbody>",
33619 tpls.body.disableFormats = true;
33621 tpls.body.compile();
33624 tpls.row = new Roo.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
33625 tpls.row.disableFormats = true;
33627 tpls.row.compile();
33630 tpls.cell = new Roo.Template(
33631 '<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
33632 '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text ' +
33633 this.unselectableCls + '" ' + this.unselectable +'" {attr}>{value}</div></div>',
33636 tpls.cell.disableFormats = true;
33638 tpls.cell.compile();
33640 this.templates = tpls;
33643 // remap these for backwards compat
33644 onColWidthChange : function(){
33645 this.updateColumns.apply(this, arguments);
33647 onHeaderChange : function(){
33648 this.updateHeaders.apply(this, arguments);
33650 onHiddenChange : function(){
33651 this.handleHiddenChange.apply(this, arguments);
33653 onColumnMove : function(){
33654 this.handleColumnMove.apply(this, arguments);
33656 onColumnLock : function(){
33657 this.handleLockChange.apply(this, arguments);
33660 onDataChange : function(){
33662 this.updateHeaderSortState();
33665 onClear : function(){
33669 onUpdate : function(ds, record){
33670 this.refreshRow(record);
33673 refreshRow : function(record){
33674 var ds = this.ds, index;
33675 if(typeof record == 'number'){
33677 record = ds.getAt(index);
33679 index = ds.indexOf(record);
33681 this.insertRows(ds, index, index, true);
33682 this.onRemove(ds, record, index+1, true);
33683 this.syncRowHeights(index, index);
33685 this.fireEvent("rowupdated", this, index, record);
33688 onAdd : function(ds, records, index){
33689 this.insertRows(ds, index, index + (records.length-1));
33692 onRemove : function(ds, record, index, isUpdate){
33693 if(isUpdate !== true){
33694 this.fireEvent("beforerowremoved", this, index, record);
33696 var bt = this.getBodyTable(), lt = this.getLockedTable();
33697 if(bt.rows[index]){
33698 bt.firstChild.removeChild(bt.rows[index]);
33700 if(lt.rows[index]){
33701 lt.firstChild.removeChild(lt.rows[index]);
33703 if(isUpdate !== true){
33704 this.stripeRows(index);
33705 this.syncRowHeights(index, index);
33707 this.fireEvent("rowremoved", this, index, record);
33711 onLoad : function(){
33712 this.scrollToTop();
33716 * Scrolls the grid to the top
33718 scrollToTop : function(){
33720 this.scroller.dom.scrollTop = 0;
33726 * Gets a panel in the header of the grid that can be used for toolbars etc.
33727 * After modifying the contents of this panel a call to grid.autoSize() may be
33728 * required to register any changes in size.
33729 * @param {Boolean} doShow By default the header is hidden. Pass true to show the panel
33730 * @return Roo.Element
33732 getHeaderPanel : function(doShow){
33734 this.headerPanel.show();
33736 return this.headerPanel;
33740 * Gets a panel in the footer of the grid that can be used for toolbars etc.
33741 * After modifying the contents of this panel a call to grid.autoSize() may be
33742 * required to register any changes in size.
33743 * @param {Boolean} doShow By default the footer is hidden. Pass true to show the panel
33744 * @return Roo.Element
33746 getFooterPanel : function(doShow){
33748 this.footerPanel.show();
33750 return this.footerPanel;
33753 initElements : function(){
33754 var E = Roo.Element;
33755 var el = this.grid.getGridEl().dom.firstChild;
33756 var cs = el.childNodes;
33758 this.el = new E(el);
33760 this.focusEl = new E(el.firstChild);
33761 this.focusEl.swallowEvent("click", true);
33763 this.headerPanel = new E(cs[1]);
33764 this.headerPanel.enableDisplayMode("block");
33766 this.scroller = new E(cs[2]);
33767 this.scrollSizer = new E(this.scroller.dom.firstChild);
33769 this.lockedWrap = new E(cs[3]);
33770 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
33771 this.lockedBody = new E(this.lockedWrap.dom.childNodes[1]);
33773 this.mainWrap = new E(cs[4]);
33774 this.mainHd = new E(this.mainWrap.dom.firstChild);
33775 this.mainBody = new E(this.mainWrap.dom.childNodes[1]);
33777 this.footerPanel = new E(cs[5]);
33778 this.footerPanel.enableDisplayMode("block");
33780 this.resizeProxy = new E(cs[6]);
33782 this.headerSelector = String.format(
33783 '#{0} td.x-grid-hd, #{1} td.x-grid-hd',
33784 this.lockedHd.id, this.mainHd.id
33787 this.splitterSelector = String.format(
33788 '#{0} div.x-grid-split, #{1} div.x-grid-split',
33789 this.idToCssName(this.lockedHd.id), this.idToCssName(this.mainHd.id)
33792 idToCssName : function(s)
33794 return s.replace(/[^a-z0-9]+/ig, '-');
33797 getHeaderCell : function(index){
33798 return Roo.DomQuery.select(this.headerSelector)[index];
33801 getHeaderCellMeasure : function(index){
33802 return this.getHeaderCell(index).firstChild;
33805 getHeaderCellText : function(index){
33806 return this.getHeaderCell(index).firstChild.firstChild;
33809 getLockedTable : function(){
33810 return this.lockedBody.dom.firstChild;
33813 getBodyTable : function(){
33814 return this.mainBody.dom.firstChild;
33817 getLockedRow : function(index){
33818 return this.getLockedTable().rows[index];
33821 getRow : function(index){
33822 return this.getBodyTable().rows[index];
33825 getRowComposite : function(index){
33827 this.rowEl = new Roo.CompositeElementLite();
33829 var els = [], lrow, mrow;
33830 if(lrow = this.getLockedRow(index)){
33833 if(mrow = this.getRow(index)){
33836 this.rowEl.elements = els;
33840 * Gets the 'td' of the cell
33842 * @param {Integer} rowIndex row to select
33843 * @param {Integer} colIndex column to select
33847 getCell : function(rowIndex, colIndex){
33848 var locked = this.cm.getLockedCount();
33850 if(colIndex < locked){
33851 source = this.lockedBody.dom.firstChild;
33853 source = this.mainBody.dom.firstChild;
33854 colIndex -= locked;
33856 return source.rows[rowIndex].childNodes[colIndex];
33859 getCellText : function(rowIndex, colIndex){
33860 return this.getCell(rowIndex, colIndex).firstChild.firstChild;
33863 getCellBox : function(cell){
33864 var b = this.fly(cell).getBox();
33865 if(Roo.isOpera){ // opera fails to report the Y
33866 b.y = cell.offsetTop + this.mainBody.getY();
33871 getCellIndex : function(cell){
33872 var id = String(cell.className).match(this.cellRE);
33874 return parseInt(id[1], 10);
33879 findHeaderIndex : function(n){
33880 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
33881 return r ? this.getCellIndex(r) : false;
33884 findHeaderCell : function(n){
33885 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
33886 return r ? r : false;
33889 findRowIndex : function(n){
33893 var r = Roo.fly(n).findParent("tr." + this.rowClass, 6);
33894 return r ? r.rowIndex : false;
33897 findCellIndex : function(node){
33898 var stop = this.el.dom;
33899 while(node && node != stop){
33900 if(this.findRE.test(node.className)){
33901 return this.getCellIndex(node);
33903 node = node.parentNode;
33908 getColumnId : function(index){
33909 return this.cm.getColumnId(index);
33912 getSplitters : function()
33914 if(this.splitterSelector){
33915 return Roo.DomQuery.select(this.splitterSelector);
33921 getSplitter : function(index){
33922 return this.getSplitters()[index];
33925 onRowOver : function(e, t){
33927 if((row = this.findRowIndex(t)) !== false){
33928 this.getRowComposite(row).addClass("x-grid-row-over");
33932 onRowOut : function(e, t){
33934 if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){
33935 this.getRowComposite(row).removeClass("x-grid-row-over");
33939 renderHeaders : function(){
33941 var ct = this.templates.hcell, ht = this.templates.header, st = this.templates.hsplit;
33942 var cb = [], lb = [], sb = [], lsb = [], p = {};
33943 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
33944 p.cellId = "x-grid-hd-0-" + i;
33945 p.splitId = "x-grid-csplit-0-" + i;
33946 p.id = cm.getColumnId(i);
33947 p.value = cm.getColumnHeader(i) || "";
33948 p.title = cm.getColumnTooltip(i) || (''+p.value).match(/\</) ? '' : p.value || "";
33949 p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
33950 if(!cm.isLocked(i)){
33951 cb[cb.length] = ct.apply(p);
33952 sb[sb.length] = st.apply(p);
33954 lb[lb.length] = ct.apply(p);
33955 lsb[lsb.length] = st.apply(p);
33958 return [ht.apply({cells: lb.join(""), splits:lsb.join("")}),
33959 ht.apply({cells: cb.join(""), splits:sb.join("")})];
33962 updateHeaders : function(){
33963 var html = this.renderHeaders();
33964 this.lockedHd.update(html[0]);
33965 this.mainHd.update(html[1]);
33969 * Focuses the specified row.
33970 * @param {Number} row The row index
33972 focusRow : function(row)
33974 //Roo.log('GridView.focusRow');
33975 var x = this.scroller.dom.scrollLeft;
33976 this.focusCell(row, 0, false);
33977 this.scroller.dom.scrollLeft = x;
33981 * Focuses the specified cell.
33982 * @param {Number} row The row index
33983 * @param {Number} col The column index
33984 * @param {Boolean} hscroll false to disable horizontal scrolling
33986 focusCell : function(row, col, hscroll)
33988 //Roo.log('GridView.focusCell');
33989 var el = this.ensureVisible(row, col, hscroll);
33990 this.focusEl.alignTo(el, "tl-tl");
33992 this.focusEl.focus();
33994 this.focusEl.focus.defer(1, this.focusEl);
33999 * Scrolls the specified cell into view
34000 * @param {Number} row The row index
34001 * @param {Number} col The column index
34002 * @param {Boolean} hscroll false to disable horizontal scrolling
34004 ensureVisible : function(row, col, hscroll)
34006 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
34007 //return null; //disable for testing.
34008 if(typeof row != "number"){
34009 row = row.rowIndex;
34011 if(row < 0 && row >= this.ds.getCount()){
34014 col = (col !== undefined ? col : 0);
34015 var cm = this.grid.colModel;
34016 while(cm.isHidden(col)){
34020 var el = this.getCell(row, col);
34024 var c = this.scroller.dom;
34026 var ctop = parseInt(el.offsetTop, 10);
34027 var cleft = parseInt(el.offsetLeft, 10);
34028 var cbot = ctop + el.offsetHeight;
34029 var cright = cleft + el.offsetWidth;
34031 var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
34032 var stop = parseInt(c.scrollTop, 10);
34033 var sleft = parseInt(c.scrollLeft, 10);
34034 var sbot = stop + ch;
34035 var sright = sleft + c.clientWidth;
34037 Roo.log('GridView.ensureVisible:' +
34039 ' c.clientHeight:' + c.clientHeight +
34040 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
34048 c.scrollTop = ctop;
34049 //Roo.log("set scrolltop to ctop DISABLE?");
34050 }else if(cbot > sbot){
34051 //Roo.log("set scrolltop to cbot-ch");
34052 c.scrollTop = cbot-ch;
34055 if(hscroll !== false){
34057 c.scrollLeft = cleft;
34058 }else if(cright > sright){
34059 c.scrollLeft = cright-c.clientWidth;
34066 updateColumns : function(){
34067 this.grid.stopEditing();
34068 var cm = this.grid.colModel, colIds = this.getColumnIds();
34069 //var totalWidth = cm.getTotalWidth();
34071 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
34072 //if(cm.isHidden(i)) continue;
34073 var w = cm.getColumnWidth(i);
34074 this.css.updateRule(this.colSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
34075 this.css.updateRule(this.hdSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
34077 this.updateSplitters();
34080 generateRules : function(cm){
34081 var ruleBuf = [], rulesId = this.idToCssName(this.grid.id)+ '-cssrules';
34082 Roo.util.CSS.removeStyleSheet(rulesId);
34083 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
34084 var cid = cm.getColumnId(i);
34086 if(cm.config[i].align){
34087 align = 'text-align:'+cm.config[i].align+';';
34090 if(cm.isHidden(i)){
34091 hidden = 'display:none;';
34093 var width = "width:" + (cm.getColumnWidth(i) - this.borderWidth) + "px;";
34095 this.colSelector, cid, " {\n", cm.config[i].css, align, width, "\n}\n",
34096 this.hdSelector, cid, " {\n", align, width, "}\n",
34097 this.tdSelector, cid, " {\n",hidden,"\n}\n",
34098 this.splitSelector, cid, " {\n", hidden , "\n}\n");
34100 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
34103 updateSplitters : function(){
34104 var cm = this.cm, s = this.getSplitters();
34105 if(s){ // splitters not created yet
34106 var pos = 0, locked = true;
34107 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
34108 if(cm.isHidden(i)) {
34111 var w = cm.getColumnWidth(i); // make sure it's a number
34112 if(!cm.isLocked(i) && locked){
34117 s[i].style.left = (pos-this.splitOffset) + "px";
34122 handleHiddenChange : function(colModel, colIndex, hidden){
34124 this.hideColumn(colIndex);
34126 this.unhideColumn(colIndex);
34130 hideColumn : function(colIndex){
34131 var cid = this.getColumnId(colIndex);
34132 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "none");
34133 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "none");
34135 this.updateHeaders();
34137 this.updateSplitters();
34141 unhideColumn : function(colIndex){
34142 var cid = this.getColumnId(colIndex);
34143 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "");
34144 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "");
34147 this.updateHeaders();
34149 this.updateSplitters();
34153 insertRows : function(dm, firstRow, lastRow, isUpdate){
34154 if(firstRow == 0 && lastRow == dm.getCount()-1){
34158 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
34160 var s = this.getScrollState();
34161 var markup = this.renderRows(firstRow, lastRow);
34162 this.bufferRows(markup[0], this.getLockedTable(), firstRow);
34163 this.bufferRows(markup[1], this.getBodyTable(), firstRow);
34164 this.restoreScroll(s);
34166 this.fireEvent("rowsinserted", this, firstRow, lastRow);
34167 this.syncRowHeights(firstRow, lastRow);
34168 this.stripeRows(firstRow);
34174 bufferRows : function(markup, target, index){
34175 var before = null, trows = target.rows, tbody = target.tBodies[0];
34176 if(index < trows.length){
34177 before = trows[index];
34179 var b = document.createElement("div");
34180 b.innerHTML = "<table><tbody>"+markup+"</tbody></table>";
34181 var rows = b.firstChild.rows;
34182 for(var i = 0, len = rows.length; i < len; i++){
34184 tbody.insertBefore(rows[0], before);
34186 tbody.appendChild(rows[0]);
34193 deleteRows : function(dm, firstRow, lastRow){
34194 if(dm.getRowCount()<1){
34195 this.fireEvent("beforerefresh", this);
34196 this.mainBody.update("");
34197 this.lockedBody.update("");
34198 this.fireEvent("refresh", this);
34200 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
34201 var bt = this.getBodyTable();
34202 var tbody = bt.firstChild;
34203 var rows = bt.rows;
34204 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
34205 tbody.removeChild(rows[firstRow]);
34207 this.stripeRows(firstRow);
34208 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
34212 updateRows : function(dataSource, firstRow, lastRow){
34213 var s = this.getScrollState();
34215 this.restoreScroll(s);
34218 handleSort : function(dataSource, sortColumnIndex, sortDir, noRefresh){
34222 this.updateHeaderSortState();
34225 getScrollState : function(){
34227 var sb = this.scroller.dom;
34228 return {left: sb.scrollLeft, top: sb.scrollTop};
34231 stripeRows : function(startRow){
34232 if(!this.grid.stripeRows || this.ds.getCount() < 1){
34235 startRow = startRow || 0;
34236 var rows = this.getBodyTable().rows;
34237 var lrows = this.getLockedTable().rows;
34238 var cls = ' x-grid-row-alt ';
34239 for(var i = startRow, len = rows.length; i < len; i++){
34240 var row = rows[i], lrow = lrows[i];
34241 var isAlt = ((i+1) % 2 == 0);
34242 var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
34243 if(isAlt == hasAlt){
34247 row.className += " x-grid-row-alt";
34249 row.className = row.className.replace("x-grid-row-alt", "");
34252 lrow.className = row.className;
34257 restoreScroll : function(state){
34258 //Roo.log('GridView.restoreScroll');
34259 var sb = this.scroller.dom;
34260 sb.scrollLeft = state.left;
34261 sb.scrollTop = state.top;
34265 syncScroll : function(){
34266 //Roo.log('GridView.syncScroll');
34267 var sb = this.scroller.dom;
34268 var sh = this.mainHd.dom;
34269 var bs = this.mainBody.dom;
34270 var lv = this.lockedBody.dom;
34271 sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
34272 lv.scrollTop = bs.scrollTop = sb.scrollTop;
34275 handleScroll : function(e){
34277 var sb = this.scroller.dom;
34278 this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
34282 handleWheel : function(e){
34283 var d = e.getWheelDelta();
34284 this.scroller.dom.scrollTop -= d*22;
34285 // set this here to prevent jumpy scrolling on large tables
34286 this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
34290 renderRows : function(startRow, endRow){
34291 // pull in all the crap needed to render rows
34292 var g = this.grid, cm = g.colModel, ds = g.dataSource, stripe = g.stripeRows;
34293 var colCount = cm.getColumnCount();
34295 if(ds.getCount() < 1){
34299 // build a map for all the columns
34301 for(var i = 0; i < colCount; i++){
34302 var name = cm.getDataIndex(i);
34304 name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
34305 renderer : cm.getRenderer(i),
34306 id : cm.getColumnId(i),
34307 locked : cm.isLocked(i),
34308 has_editor : cm.isCellEditable(i)
34312 startRow = startRow || 0;
34313 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
34315 // records to render
34316 var rs = ds.getRange(startRow, endRow);
34318 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
34321 // As much as I hate to duplicate code, this was branched because FireFox really hates
34322 // [].join("") on strings. The performance difference was substantial enough to
34323 // branch this function
34324 doRender : Roo.isGecko ?
34325 function(cs, rs, ds, startRow, colCount, stripe){
34326 var ts = this.templates, ct = ts.cell, rt = ts.row;
34328 var buf = "", lbuf = "", cb, lcb, c, p = {}, rp = {}, r, rowIndex;
34330 var hasListener = this.grid.hasListener('rowclass');
34332 for(var j = 0, len = rs.length; j < len; j++){
34333 r = rs[j]; cb = ""; lcb = ""; rowIndex = (j+startRow);
34334 for(var i = 0; i < colCount; i++){
34336 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
34338 p.css = p.attr = "";
34339 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
34340 if(p.value == undefined || p.value === "") {
34341 p.value = " ";
34344 p.css += ' x-grid-editable-cell';
34346 if(c.dirty && typeof r.modified[c.name] !== 'undefined'){
34347 p.css += ' x-grid-dirty-cell';
34349 var markup = ct.apply(p);
34357 if(stripe && ((rowIndex+1) % 2 == 0)){
34358 alt.push("x-grid-row-alt")
34361 alt.push( " x-grid-dirty-row");
34364 if(this.getRowClass){
34365 alt.push(this.getRowClass(r, rowIndex));
34371 rowIndex : rowIndex,
34374 this.grid.fireEvent('rowclass', this, rowcfg);
34375 alt.push(rowcfg.rowClass);
34377 rp.alt = alt.join(" ");
34378 lbuf+= rt.apply(rp);
34380 buf+= rt.apply(rp);
34382 return [lbuf, buf];
34384 function(cs, rs, ds, startRow, colCount, stripe){
34385 var ts = this.templates, ct = ts.cell, rt = ts.row;
34387 var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
34388 var hasListener = this.grid.hasListener('rowclass');
34391 for(var j = 0, len = rs.length; j < len; j++){
34392 r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
34393 for(var i = 0; i < colCount; i++){
34395 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
34397 p.css = p.attr = "";
34398 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
34399 if(p.value == undefined || p.value === "") {
34400 p.value = " ";
34404 p.css += ' x-grid-editable-cell';
34406 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
34407 p.css += ' x-grid-dirty-cell'
34410 var markup = ct.apply(p);
34412 cb[cb.length] = markup;
34414 lcb[lcb.length] = markup;
34418 if(stripe && ((rowIndex+1) % 2 == 0)){
34419 alt.push( "x-grid-row-alt");
34422 alt.push(" x-grid-dirty-row");
34425 if(this.getRowClass){
34426 alt.push( this.getRowClass(r, rowIndex));
34432 rowIndex : rowIndex,
34435 this.grid.fireEvent('rowclass', this, rowcfg);
34436 alt.push(rowcfg.rowClass);
34439 rp.alt = alt.join(" ");
34440 rp.cells = lcb.join("");
34441 lbuf[lbuf.length] = rt.apply(rp);
34442 rp.cells = cb.join("");
34443 buf[buf.length] = rt.apply(rp);
34445 return [lbuf.join(""), buf.join("")];
34448 renderBody : function(){
34449 var markup = this.renderRows();
34450 var bt = this.templates.body;
34451 return [bt.apply({rows: markup[0]}), bt.apply({rows: markup[1]})];
34455 * Refreshes the grid
34456 * @param {Boolean} headersToo
34458 refresh : function(headersToo){
34459 this.fireEvent("beforerefresh", this);
34460 this.grid.stopEditing();
34461 var result = this.renderBody();
34462 this.lockedBody.update(result[0]);
34463 this.mainBody.update(result[1]);
34464 if(headersToo === true){
34465 this.updateHeaders();
34466 this.updateColumns();
34467 this.updateSplitters();
34468 this.updateHeaderSortState();
34470 this.syncRowHeights();
34472 this.fireEvent("refresh", this);
34475 handleColumnMove : function(cm, oldIndex, newIndex){
34476 this.indexMap = null;
34477 var s = this.getScrollState();
34478 this.refresh(true);
34479 this.restoreScroll(s);
34480 this.afterMove(newIndex);
34483 afterMove : function(colIndex){
34484 if(this.enableMoveAnim && Roo.enableFx){
34485 this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
34487 // if multisort - fix sortOrder, and reload..
34488 if (this.grid.dataSource.multiSort) {
34489 // the we can call sort again..
34490 var dm = this.grid.dataSource;
34491 var cm = this.grid.colModel;
34493 for(var i = 0; i < cm.config.length; i++ ) {
34495 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined')) {
34496 continue; // dont' bother, it's not in sort list or being set.
34499 so.push(cm.config[i].dataIndex);
34502 dm.load(dm.lastOptions);
34509 updateCell : function(dm, rowIndex, dataIndex){
34510 var colIndex = this.getColumnIndexByDataIndex(dataIndex);
34511 if(typeof colIndex == "undefined"){ // not present in grid
34514 var cm = this.grid.colModel;
34515 var cell = this.getCell(rowIndex, colIndex);
34516 var cellText = this.getCellText(rowIndex, colIndex);
34519 cellId : "x-grid-cell-" + rowIndex + "-" + colIndex,
34520 id : cm.getColumnId(colIndex),
34521 css: colIndex == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
34523 var renderer = cm.getRenderer(colIndex);
34524 var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
34525 if(typeof val == "undefined" || val === "") {
34528 cellText.innerHTML = val;
34529 cell.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
34530 this.syncRowHeights(rowIndex, rowIndex);
34533 calcColumnWidth : function(colIndex, maxRowsToMeasure){
34535 if(this.grid.autoSizeHeaders){
34536 var h = this.getHeaderCellMeasure(colIndex);
34537 maxWidth = Math.max(maxWidth, h.scrollWidth);
34540 if(this.cm.isLocked(colIndex)){
34541 tb = this.getLockedTable();
34544 tb = this.getBodyTable();
34545 index = colIndex - this.cm.getLockedCount();
34548 var rows = tb.rows;
34549 var stopIndex = Math.min(maxRowsToMeasure || rows.length, rows.length);
34550 for(var i = 0; i < stopIndex; i++){
34551 var cell = rows[i].childNodes[index].firstChild;
34552 maxWidth = Math.max(maxWidth, cell.scrollWidth);
34555 return maxWidth + /*margin for error in IE*/ 5;
34558 * Autofit a column to its content.
34559 * @param {Number} colIndex
34560 * @param {Boolean} forceMinSize true to force the column to go smaller if possible
34562 autoSizeColumn : function(colIndex, forceMinSize, suppressEvent){
34563 if(this.cm.isHidden(colIndex)){
34564 return; // can't calc a hidden column
34567 var cid = this.cm.getColumnId(colIndex);
34568 this.css.updateRule(this.colSelector +this.idToCssName( cid), "width", this.grid.minColumnWidth + "px");
34569 if(this.grid.autoSizeHeaders){
34570 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", this.grid.minColumnWidth + "px");
34573 var newWidth = this.calcColumnWidth(colIndex);
34574 this.cm.setColumnWidth(colIndex,
34575 Math.max(this.grid.minColumnWidth, newWidth), suppressEvent);
34576 if(!suppressEvent){
34577 this.grid.fireEvent("columnresize", colIndex, newWidth);
34582 * Autofits all columns to their content and then expands to fit any extra space in the grid
34584 autoSizeColumns : function(){
34585 var cm = this.grid.colModel;
34586 var colCount = cm.getColumnCount();
34587 for(var i = 0; i < colCount; i++){
34588 this.autoSizeColumn(i, true, true);
34590 if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
34593 this.updateColumns();
34599 * Autofits all columns to the grid's width proportionate with their current size
34600 * @param {Boolean} reserveScrollSpace Reserve space for a scrollbar
34602 fitColumns : function(reserveScrollSpace){
34603 var cm = this.grid.colModel;
34604 var colCount = cm.getColumnCount();
34608 for (i = 0; i < colCount; i++){
34609 if(!cm.isHidden(i) && !cm.isFixed(i)){
34610 w = cm.getColumnWidth(i);
34616 var avail = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
34617 if(reserveScrollSpace){
34620 var frac = (avail - cm.getTotalWidth())/width;
34621 while (cols.length){
34624 cm.setColumnWidth(i, Math.floor(w + w*frac), true);
34626 this.updateColumns();
34630 onRowSelect : function(rowIndex){
34631 var row = this.getRowComposite(rowIndex);
34632 row.addClass("x-grid-row-selected");
34635 onRowDeselect : function(rowIndex){
34636 var row = this.getRowComposite(rowIndex);
34637 row.removeClass("x-grid-row-selected");
34640 onCellSelect : function(row, col){
34641 var cell = this.getCell(row, col);
34643 Roo.fly(cell).addClass("x-grid-cell-selected");
34647 onCellDeselect : function(row, col){
34648 var cell = this.getCell(row, col);
34650 Roo.fly(cell).removeClass("x-grid-cell-selected");
34654 updateHeaderSortState : function(){
34656 // sort state can be single { field: xxx, direction : yyy}
34657 // or { xxx=>ASC , yyy : DESC ..... }
34660 if (!this.ds.multiSort) {
34661 var state = this.ds.getSortState();
34665 mstate[state.field] = state.direction;
34666 // FIXME... - this is not used here.. but might be elsewhere..
34667 this.sortState = state;
34670 mstate = this.ds.sortToggle;
34672 //remove existing sort classes..
34674 var sc = this.sortClasses;
34675 var hds = this.el.select(this.headerSelector).removeClass(sc);
34677 for(var f in mstate) {
34679 var sortColumn = this.cm.findColumnIndex(f);
34681 if(sortColumn != -1){
34682 var sortDir = mstate[f];
34683 hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
34692 handleHeaderClick : function(g, index,e){
34694 Roo.log("header click");
34697 // touch events on header are handled by context
34698 this.handleHdCtx(g,index,e);
34703 if(this.headersDisabled){
34706 var dm = g.dataSource, cm = g.colModel;
34707 if(!cm.isSortable(index)){
34712 if (dm.multiSort) {
34713 // update the sortOrder
34715 for(var i = 0; i < cm.config.length; i++ ) {
34717 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined') && (index != i)) {
34718 continue; // dont' bother, it's not in sort list or being set.
34721 so.push(cm.config[i].dataIndex);
34727 dm.sort(cm.getDataIndex(index));
34731 destroy : function(){
34733 this.colMenu.removeAll();
34734 Roo.menu.MenuMgr.unregister(this.colMenu);
34735 this.colMenu.getEl().remove();
34736 delete this.colMenu;
34739 this.hmenu.removeAll();
34740 Roo.menu.MenuMgr.unregister(this.hmenu);
34741 this.hmenu.getEl().remove();
34744 if(this.grid.enableColumnMove){
34745 var dds = Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
34747 for(var dd in dds){
34748 if(!dds[dd].config.isTarget && dds[dd].dragElId){
34749 var elid = dds[dd].dragElId;
34751 Roo.get(elid).remove();
34752 } else if(dds[dd].config.isTarget){
34753 dds[dd].proxyTop.remove();
34754 dds[dd].proxyBottom.remove();
34757 if(Roo.dd.DDM.locationCache[dd]){
34758 delete Roo.dd.DDM.locationCache[dd];
34761 delete Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
34764 Roo.util.CSS.removeStyleSheet(this.idToCssName(this.grid.id) + '-cssrules');
34765 this.bind(null, null);
34766 Roo.EventManager.removeResizeListener(this.onWindowResize, this);
34769 handleLockChange : function(){
34770 this.refresh(true);
34773 onDenyColumnLock : function(){
34777 onDenyColumnHide : function(){
34781 handleHdMenuClick : function(item){
34782 var index = this.hdCtxIndex;
34783 var cm = this.cm, ds = this.ds;
34786 ds.sort(cm.getDataIndex(index), "ASC");
34789 ds.sort(cm.getDataIndex(index), "DESC");
34792 var lc = cm.getLockedCount();
34793 if(cm.getColumnCount(true) <= lc+1){
34794 this.onDenyColumnLock();
34798 cm.setLocked(index, true, true);
34799 cm.moveColumn(index, lc);
34800 this.grid.fireEvent("columnmove", index, lc);
34802 cm.setLocked(index, true);
34806 var lc = cm.getLockedCount();
34807 if((lc-1) != index){
34808 cm.setLocked(index, false, true);
34809 cm.moveColumn(index, lc-1);
34810 this.grid.fireEvent("columnmove", index, lc-1);
34812 cm.setLocked(index, false);
34815 case 'wider': // used to expand cols on touch..
34817 var cw = cm.getColumnWidth(index);
34818 cw += (item.id == 'wider' ? 1 : -1) * 50;
34819 cw = Math.max(0, cw);
34820 cw = Math.min(cw,4000);
34821 cm.setColumnWidth(index, cw);
34825 index = cm.getIndexById(item.id.substr(4));
34827 if(item.checked && cm.getColumnCount(true) <= 1){
34828 this.onDenyColumnHide();
34831 cm.setHidden(index, item.checked);
34837 beforeColMenuShow : function(){
34838 var cm = this.cm, colCount = cm.getColumnCount();
34839 this.colMenu.removeAll();
34840 for(var i = 0; i < colCount; i++){
34841 this.colMenu.add(new Roo.menu.CheckItem({
34842 id: "col-"+cm.getColumnId(i),
34843 text: cm.getColumnHeader(i),
34844 checked: !cm.isHidden(i),
34850 handleHdCtx : function(g, index, e){
34852 var hd = this.getHeaderCell(index);
34853 this.hdCtxIndex = index;
34854 var ms = this.hmenu.items, cm = this.cm;
34855 ms.get("asc").setDisabled(!cm.isSortable(index));
34856 ms.get("desc").setDisabled(!cm.isSortable(index));
34857 if(this.grid.enableColLock !== false){
34858 ms.get("lock").setDisabled(cm.isLocked(index));
34859 ms.get("unlock").setDisabled(!cm.isLocked(index));
34861 this.hmenu.show(hd, "tl-bl");
34864 handleHdOver : function(e){
34865 var hd = this.findHeaderCell(e.getTarget());
34866 if(hd && !this.headersDisabled){
34867 if(this.grid.colModel.isSortable(this.getCellIndex(hd))){
34868 this.fly(hd).addClass("x-grid-hd-over");
34873 handleHdOut : function(e){
34874 var hd = this.findHeaderCell(e.getTarget());
34876 this.fly(hd).removeClass("x-grid-hd-over");
34880 handleSplitDblClick : function(e, t){
34881 var i = this.getCellIndex(t);
34882 if(this.grid.enableColumnResize !== false && this.cm.isResizable(i) && !this.cm.isFixed(i)){
34883 this.autoSizeColumn(i, true);
34888 render : function(){
34891 var colCount = cm.getColumnCount();
34893 if(this.grid.monitorWindowResize === true){
34894 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34896 var header = this.renderHeaders();
34897 var body = this.templates.body.apply({rows:""});
34898 var html = this.templates.master.apply({
34901 lockedHeader: header[0],
34905 //this.updateColumns();
34907 this.grid.getGridEl().dom.innerHTML = html;
34909 this.initElements();
34911 // a kludge to fix the random scolling effect in webkit
34912 this.el.on("scroll", function() {
34913 this.el.dom.scrollTop=0; // hopefully not recursive..
34916 this.scroller.on("scroll", this.handleScroll, this);
34917 this.lockedBody.on("mousewheel", this.handleWheel, this);
34918 this.mainBody.on("mousewheel", this.handleWheel, this);
34920 this.mainHd.on("mouseover", this.handleHdOver, this);
34921 this.mainHd.on("mouseout", this.handleHdOut, this);
34922 this.mainHd.on("dblclick", this.handleSplitDblClick, this,
34923 {delegate: "."+this.splitClass});
34925 this.lockedHd.on("mouseover", this.handleHdOver, this);
34926 this.lockedHd.on("mouseout", this.handleHdOut, this);
34927 this.lockedHd.on("dblclick", this.handleSplitDblClick, this,
34928 {delegate: "."+this.splitClass});
34930 if(this.grid.enableColumnResize !== false && Roo.grid.SplitDragZone){
34931 new Roo.grid.SplitDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34934 this.updateSplitters();
34936 if(this.grid.enableColumnMove && Roo.grid.HeaderDragZone){
34937 new Roo.grid.HeaderDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34938 new Roo.grid.HeaderDropZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34941 if(this.grid.enableCtxMenu !== false && Roo.menu.Menu){
34942 this.hmenu = new Roo.menu.Menu({id: this.grid.id + "-hctx"});
34944 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
34945 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
34947 if(this.grid.enableColLock !== false){
34948 this.hmenu.add('-',
34949 {id:"lock", text: this.lockText, cls: "xg-hmenu-lock"},
34950 {id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
34954 this.hmenu.add('-',
34955 {id:"wider", text: this.columnsWiderText},
34956 {id:"narrow", text: this.columnsNarrowText }
34962 if(this.grid.enableColumnHide !== false){
34964 this.colMenu = new Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
34965 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
34966 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
34968 this.hmenu.add('-',
34969 {id:"columns", text: this.columnsText, menu: this.colMenu}
34972 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
34974 this.grid.on("headercontextmenu", this.handleHdCtx, this);
34977 if((this.grid.enableDragDrop || this.grid.enableDrag) && Roo.grid.GridDragZone){
34978 this.dd = new Roo.grid.GridDragZone(this.grid, {
34979 ddGroup : this.grid.ddGroup || 'GridDD'
34985 for(var i = 0; i < colCount; i++){
34986 if(cm.isHidden(i)){
34987 this.hideColumn(i);
34989 if(cm.config[i].align){
34990 this.css.updateRule(this.colSelector + i, "textAlign", cm.config[i].align);
34991 this.css.updateRule(this.hdSelector + i, "textAlign", cm.config[i].align);
34995 this.updateHeaderSortState();
34997 this.beforeInitialResize();
35000 // two part rendering gives faster view to the user
35001 this.renderPhase2.defer(1, this);
35004 renderPhase2 : function(){
35005 // render the rows now
35007 if(this.grid.autoSizeColumns){
35008 this.autoSizeColumns();
35012 beforeInitialResize : function(){
35016 onColumnSplitterMoved : function(i, w){
35017 this.userResized = true;
35018 var cm = this.grid.colModel;
35019 cm.setColumnWidth(i, w, true);
35020 var cid = cm.getColumnId(i);
35021 this.css.updateRule(this.colSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
35022 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
35023 this.updateSplitters();
35025 this.grid.fireEvent("columnresize", i, w);
35028 syncRowHeights : function(startIndex, endIndex){
35029 if(this.grid.enableRowHeightSync === true && this.cm.getLockedCount() > 0){
35030 startIndex = startIndex || 0;
35031 var mrows = this.getBodyTable().rows;
35032 var lrows = this.getLockedTable().rows;
35033 var len = mrows.length-1;
35034 endIndex = Math.min(endIndex || len, len);
35035 for(var i = startIndex; i <= endIndex; i++){
35036 var m = mrows[i], l = lrows[i];
35037 var h = Math.max(m.offsetHeight, l.offsetHeight);
35038 m.style.height = l.style.height = h + "px";
35043 layout : function(initialRender, is2ndPass){
35045 var auto = g.autoHeight;
35046 var scrollOffset = 16;
35047 var c = g.getGridEl(), cm = this.cm,
35048 expandCol = g.autoExpandColumn,
35050 //c.beginMeasure();
35052 if(!c.dom.offsetWidth){ // display:none?
35054 this.lockedWrap.show();
35055 this.mainWrap.show();
35060 var hasLock = this.cm.isLocked(0);
35062 var tbh = this.headerPanel.getHeight();
35063 var bbh = this.footerPanel.getHeight();
35066 var ch = this.getBodyTable().offsetHeight + tbh + bbh + this.mainHd.getHeight();
35067 var newHeight = ch + c.getBorderWidth("tb");
35069 newHeight = Math.min(g.maxHeight, newHeight);
35071 c.setHeight(newHeight);
35075 c.setWidth(cm.getTotalWidth()+c.getBorderWidth('lr'));
35078 var s = this.scroller;
35080 var csize = c.getSize(true);
35082 this.el.setSize(csize.width, csize.height);
35084 this.headerPanel.setWidth(csize.width);
35085 this.footerPanel.setWidth(csize.width);
35087 var hdHeight = this.mainHd.getHeight();
35088 var vw = csize.width;
35089 var vh = csize.height - (tbh + bbh);
35093 var bt = this.getBodyTable();
35095 if(cm.getLockedCount() == cm.config.length){
35096 bt = this.getLockedTable();
35099 var ltWidth = hasLock ?
35100 Math.max(this.getLockedTable().offsetWidth, this.lockedHd.dom.firstChild.offsetWidth) : 0;
35102 var scrollHeight = bt.offsetHeight;
35103 var scrollWidth = ltWidth + bt.offsetWidth;
35104 var vscroll = false, hscroll = false;
35106 this.scrollSizer.setSize(scrollWidth, scrollHeight+hdHeight);
35108 var lw = this.lockedWrap, mw = this.mainWrap;
35109 var lb = this.lockedBody, mb = this.mainBody;
35111 setTimeout(function(){
35112 var t = s.dom.offsetTop;
35113 var w = s.dom.clientWidth,
35114 h = s.dom.clientHeight;
35117 lw.setSize(ltWidth, h);
35119 mw.setLeftTop(ltWidth, t);
35120 mw.setSize(w-ltWidth, h);
35122 lb.setHeight(h-hdHeight);
35123 mb.setHeight(h-hdHeight);
35125 if(is2ndPass !== true && !gv.userResized && expandCol){
35126 // high speed resize without full column calculation
35128 var ci = cm.getIndexById(expandCol);
35130 ci = cm.findColumnIndex(expandCol);
35132 ci = Math.max(0, ci); // make sure it's got at least the first col.
35133 var expandId = cm.getColumnId(ci);
35134 var tw = cm.getTotalWidth(false);
35135 var currentWidth = cm.getColumnWidth(ci);
35136 var cw = Math.min(Math.max(((w-tw)+currentWidth-2)-/*scrollbar*/(w <= s.dom.offsetWidth ? 0 : 18), g.autoExpandMin), g.autoExpandMax);
35137 if(currentWidth != cw){
35138 cm.setColumnWidth(ci, cw, true);
35139 gv.css.updateRule(gv.colSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
35140 gv.css.updateRule(gv.hdSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
35141 gv.updateSplitters();
35142 gv.layout(false, true);
35154 onWindowResize : function(){
35155 if(!this.grid.monitorWindowResize || this.grid.autoHeight){
35161 appendFooter : function(parentEl){
35165 sortAscText : "Sort Ascending",
35166 sortDescText : "Sort Descending",
35167 lockText : "Lock Column",
35168 unlockText : "Unlock Column",
35169 columnsText : "Columns",
35171 columnsWiderText : "Wider",
35172 columnsNarrowText : "Thinner"
35176 Roo.grid.GridView.ColumnDragZone = function(grid, hd){
35177 Roo.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
35178 this.proxy.el.addClass('x-grid3-col-dd');
35181 Roo.extend(Roo.grid.GridView.ColumnDragZone, Roo.grid.HeaderDragZone, {
35182 handleMouseDown : function(e){
35186 callHandleMouseDown : function(e){
35187 Roo.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
35192 * Ext JS Library 1.1.1
35193 * Copyright(c) 2006-2007, Ext JS, LLC.
35195 * Originally Released Under LGPL - original licence link has changed is not relivant.
35198 * <script type="text/javascript">
35202 // This is a support class used internally by the Grid components
35203 Roo.grid.SplitDragZone = function(grid, hd, hd2){
35205 this.view = grid.getView();
35206 this.proxy = this.view.resizeProxy;
35207 Roo.grid.SplitDragZone.superclass.constructor.call(this, hd,
35208 "gridSplitters" + this.grid.getGridEl().id, {
35209 dragElId : Roo.id(this.proxy.dom), resizeFrame:false
35211 this.setHandleElId(Roo.id(hd));
35212 this.setOuterHandleElId(Roo.id(hd2));
35213 this.scroll = false;
35215 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
35216 fly: Roo.Element.fly,
35218 b4StartDrag : function(x, y){
35219 this.view.headersDisabled = true;
35220 this.proxy.setHeight(this.view.mainWrap.getHeight());
35221 var w = this.cm.getColumnWidth(this.cellIndex);
35222 var minw = Math.max(w-this.grid.minColumnWidth, 0);
35223 this.resetConstraints();
35224 this.setXConstraint(minw, 1000);
35225 this.setYConstraint(0, 0);
35226 this.minX = x - minw;
35227 this.maxX = x + 1000;
35229 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
35233 handleMouseDown : function(e){
35234 ev = Roo.EventObject.setEvent(e);
35235 var t = this.fly(ev.getTarget());
35236 if(t.hasClass("x-grid-split")){
35237 this.cellIndex = this.view.getCellIndex(t.dom);
35238 this.split = t.dom;
35239 this.cm = this.grid.colModel;
35240 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
35241 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
35246 endDrag : function(e){
35247 this.view.headersDisabled = false;
35248 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
35249 var diff = endX - this.startPos;
35250 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
35253 autoOffset : function(){
35254 this.setDelta(0,0);
35258 * Ext JS Library 1.1.1
35259 * Copyright(c) 2006-2007, Ext JS, LLC.
35261 * Originally Released Under LGPL - original licence link has changed is not relivant.
35264 * <script type="text/javascript">
35268 // This is a support class used internally by the Grid components
35269 Roo.grid.GridDragZone = function(grid, config){
35270 this.view = grid.getView();
35271 Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
35272 if(this.view.lockedBody){
35273 this.setHandleElId(Roo.id(this.view.mainBody.dom));
35274 this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
35276 this.scroll = false;
35278 this.ddel = document.createElement('div');
35279 this.ddel.className = 'x-grid-dd-wrap';
35282 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
35283 ddGroup : "GridDD",
35285 getDragData : function(e){
35286 var t = Roo.lib.Event.getTarget(e);
35287 var rowIndex = this.view.findRowIndex(t);
35288 var sm = this.grid.selModel;
35290 //Roo.log(rowIndex);
35292 if (sm.getSelectedCell) {
35293 // cell selection..
35294 if (!sm.getSelectedCell()) {
35297 if (rowIndex != sm.getSelectedCell()[0]) {
35303 if(rowIndex !== false){
35308 //Roo.log([ sm.getSelectedCell() ? sm.getSelectedCell()[0] : 'NO' , rowIndex ]);
35310 //if(!sm.isSelected(rowIndex) || e.hasModifier()){
35313 if (e.hasModifier()){
35314 sm.handleMouseDown(e, t); // non modifier buttons are handled by row select.
35317 Roo.log("getDragData");
35322 rowIndex: rowIndex,
35323 selections:sm.getSelections ? sm.getSelections() : (
35324 sm.getSelectedCell() ? [ this.grid.ds.getAt(sm.getSelectedCell()[0]) ] : []
35331 onInitDrag : function(e){
35332 var data = this.dragData;
35333 this.ddel.innerHTML = this.grid.getDragDropText();
35334 this.proxy.update(this.ddel);
35335 // fire start drag?
35338 afterRepair : function(){
35339 this.dragging = false;
35342 getRepairXY : function(e, data){
35346 onEndDrag : function(data, e){
35350 onValidDrop : function(dd, e, id){
35355 beforeInvalidDrop : function(e, id){
35360 * Ext JS Library 1.1.1
35361 * Copyright(c) 2006-2007, Ext JS, LLC.
35363 * Originally Released Under LGPL - original licence link has changed is not relivant.
35366 * <script type="text/javascript">
35371 * @class Roo.grid.ColumnModel
35372 * @extends Roo.util.Observable
35373 * This is the default implementation of a ColumnModel used by the Grid. It defines
35374 * the columns in the grid.
35377 var colModel = new Roo.grid.ColumnModel([
35378 {header: "Ticker", width: 60, sortable: true, locked: true},
35379 {header: "Company Name", width: 150, sortable: true},
35380 {header: "Market Cap.", width: 100, sortable: true},
35381 {header: "$ Sales", width: 100, sortable: true, renderer: money},
35382 {header: "Employees", width: 100, sortable: true, resizable: false}
35387 * The config options listed for this class are options which may appear in each
35388 * individual column definition.
35389 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
35391 * @param {Object} config An Array of column config objects. See this class's
35392 * config objects for details.
35394 Roo.grid.ColumnModel = function(config){
35396 * The config passed into the constructor
35398 this.config = config;
35401 // if no id, create one
35402 // if the column does not have a dataIndex mapping,
35403 // map it to the order it is in the config
35404 for(var i = 0, len = config.length; i < len; i++){
35406 if(typeof c.dataIndex == "undefined"){
35409 if(typeof c.renderer == "string"){
35410 c.renderer = Roo.util.Format[c.renderer];
35412 if(typeof c.id == "undefined"){
35415 if(c.editor && c.editor.xtype){
35416 c.editor = Roo.factory(c.editor, Roo.grid);
35418 if(c.editor && c.editor.isFormField){
35419 c.editor = new Roo.grid.GridEditor(c.editor);
35421 this.lookup[c.id] = c;
35425 * The width of columns which have no width specified (defaults to 100)
35428 this.defaultWidth = 100;
35431 * Default sortable of columns which have no sortable specified (defaults to false)
35434 this.defaultSortable = false;
35438 * @event widthchange
35439 * Fires when the width of a column changes.
35440 * @param {ColumnModel} this
35441 * @param {Number} columnIndex The column index
35442 * @param {Number} newWidth The new width
35444 "widthchange": true,
35446 * @event headerchange
35447 * Fires when the text of a header changes.
35448 * @param {ColumnModel} this
35449 * @param {Number} columnIndex The column index
35450 * @param {Number} newText The new header text
35452 "headerchange": true,
35454 * @event hiddenchange
35455 * Fires when a column is hidden or "unhidden".
35456 * @param {ColumnModel} this
35457 * @param {Number} columnIndex The column index
35458 * @param {Boolean} hidden true if hidden, false otherwise
35460 "hiddenchange": true,
35462 * @event columnmoved
35463 * Fires when a column is moved.
35464 * @param {ColumnModel} this
35465 * @param {Number} oldIndex
35466 * @param {Number} newIndex
35468 "columnmoved" : true,
35470 * @event columlockchange
35471 * Fires when a column's locked state is changed
35472 * @param {ColumnModel} this
35473 * @param {Number} colIndex
35474 * @param {Boolean} locked true if locked
35476 "columnlockchange" : true
35478 Roo.grid.ColumnModel.superclass.constructor.call(this);
35480 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
35482 * @cfg {String} header The header text to display in the Grid view.
35485 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
35486 * {@link Roo.data.Record} definition from which to draw the column's value. If not
35487 * specified, the column's index is used as an index into the Record's data Array.
35490 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
35491 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
35494 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
35495 * Defaults to the value of the {@link #defaultSortable} property.
35496 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
35499 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
35502 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
35505 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
35508 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
35511 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
35512 * given the cell's data value. See {@link #setRenderer}. If not specified, the
35513 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
35514 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
35517 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
35520 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
35523 * @cfg {String} valign (Optional) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined.
35526 * @cfg {String} cursor (Optional)
35529 * @cfg {String} tooltip (Optional)
35532 * @cfg {Number} xs (Optional)
35535 * @cfg {Number} sm (Optional)
35538 * @cfg {Number} md (Optional)
35541 * @cfg {Number} lg (Optional)
35544 * Returns the id of the column at the specified index.
35545 * @param {Number} index The column index
35546 * @return {String} the id
35548 getColumnId : function(index){
35549 return this.config[index].id;
35553 * Returns the column for a specified id.
35554 * @param {String} id The column id
35555 * @return {Object} the column
35557 getColumnById : function(id){
35558 return this.lookup[id];
35563 * Returns the column for a specified dataIndex.
35564 * @param {String} dataIndex The column dataIndex
35565 * @return {Object|Boolean} the column or false if not found
35567 getColumnByDataIndex: function(dataIndex){
35568 var index = this.findColumnIndex(dataIndex);
35569 return index > -1 ? this.config[index] : false;
35573 * Returns the index for a specified column id.
35574 * @param {String} id The column id
35575 * @return {Number} the index, or -1 if not found
35577 getIndexById : function(id){
35578 for(var i = 0, len = this.config.length; i < len; i++){
35579 if(this.config[i].id == id){
35587 * Returns the index for a specified column dataIndex.
35588 * @param {String} dataIndex The column dataIndex
35589 * @return {Number} the index, or -1 if not found
35592 findColumnIndex : function(dataIndex){
35593 for(var i = 0, len = this.config.length; i < len; i++){
35594 if(this.config[i].dataIndex == dataIndex){
35602 moveColumn : function(oldIndex, newIndex){
35603 var c = this.config[oldIndex];
35604 this.config.splice(oldIndex, 1);
35605 this.config.splice(newIndex, 0, c);
35606 this.dataMap = null;
35607 this.fireEvent("columnmoved", this, oldIndex, newIndex);
35610 isLocked : function(colIndex){
35611 return this.config[colIndex].locked === true;
35614 setLocked : function(colIndex, value, suppressEvent){
35615 if(this.isLocked(colIndex) == value){
35618 this.config[colIndex].locked = value;
35619 if(!suppressEvent){
35620 this.fireEvent("columnlockchange", this, colIndex, value);
35624 getTotalLockedWidth : function(){
35625 var totalWidth = 0;
35626 for(var i = 0; i < this.config.length; i++){
35627 if(this.isLocked(i) && !this.isHidden(i)){
35628 this.totalWidth += this.getColumnWidth(i);
35634 getLockedCount : function(){
35635 for(var i = 0, len = this.config.length; i < len; i++){
35636 if(!this.isLocked(i)){
35641 return this.config.length;
35645 * Returns the number of columns.
35648 getColumnCount : function(visibleOnly){
35649 if(visibleOnly === true){
35651 for(var i = 0, len = this.config.length; i < len; i++){
35652 if(!this.isHidden(i)){
35658 return this.config.length;
35662 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
35663 * @param {Function} fn
35664 * @param {Object} scope (optional)
35665 * @return {Array} result
35667 getColumnsBy : function(fn, scope){
35669 for(var i = 0, len = this.config.length; i < len; i++){
35670 var c = this.config[i];
35671 if(fn.call(scope||this, c, i) === true){
35679 * Returns true if the specified column is sortable.
35680 * @param {Number} col The column index
35681 * @return {Boolean}
35683 isSortable : function(col){
35684 if(typeof this.config[col].sortable == "undefined"){
35685 return this.defaultSortable;
35687 return this.config[col].sortable;
35691 * Returns the rendering (formatting) function defined for the column.
35692 * @param {Number} col The column index.
35693 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
35695 getRenderer : function(col){
35696 if(!this.config[col].renderer){
35697 return Roo.grid.ColumnModel.defaultRenderer;
35699 return this.config[col].renderer;
35703 * Sets the rendering (formatting) function for a column.
35704 * @param {Number} col The column index
35705 * @param {Function} fn The function to use to process the cell's raw data
35706 * to return HTML markup for the grid view. The render function is called with
35707 * the following parameters:<ul>
35708 * <li>Data value.</li>
35709 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
35710 * <li>css A CSS style string to apply to the table cell.</li>
35711 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
35712 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
35713 * <li>Row index</li>
35714 * <li>Column index</li>
35715 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
35717 setRenderer : function(col, fn){
35718 this.config[col].renderer = fn;
35722 * Returns the width for the specified column.
35723 * @param {Number} col The column index
35726 getColumnWidth : function(col){
35727 return this.config[col].width * 1 || this.defaultWidth;
35731 * Sets the width for a column.
35732 * @param {Number} col The column index
35733 * @param {Number} width The new width
35735 setColumnWidth : function(col, width, suppressEvent){
35736 this.config[col].width = width;
35737 this.totalWidth = null;
35738 if(!suppressEvent){
35739 this.fireEvent("widthchange", this, col, width);
35744 * Returns the total width of all columns.
35745 * @param {Boolean} includeHidden True to include hidden column widths
35748 getTotalWidth : function(includeHidden){
35749 if(!this.totalWidth){
35750 this.totalWidth = 0;
35751 for(var i = 0, len = this.config.length; i < len; i++){
35752 if(includeHidden || !this.isHidden(i)){
35753 this.totalWidth += this.getColumnWidth(i);
35757 return this.totalWidth;
35761 * Returns the header for the specified column.
35762 * @param {Number} col The column index
35765 getColumnHeader : function(col){
35766 return this.config[col].header;
35770 * Sets the header for a column.
35771 * @param {Number} col The column index
35772 * @param {String} header The new header
35774 setColumnHeader : function(col, header){
35775 this.config[col].header = header;
35776 this.fireEvent("headerchange", this, col, header);
35780 * Returns the tooltip for the specified column.
35781 * @param {Number} col The column index
35784 getColumnTooltip : function(col){
35785 return this.config[col].tooltip;
35788 * Sets the tooltip for a column.
35789 * @param {Number} col The column index
35790 * @param {String} tooltip The new tooltip
35792 setColumnTooltip : function(col, tooltip){
35793 this.config[col].tooltip = tooltip;
35797 * Returns the dataIndex for the specified column.
35798 * @param {Number} col The column index
35801 getDataIndex : function(col){
35802 return this.config[col].dataIndex;
35806 * Sets the dataIndex for a column.
35807 * @param {Number} col The column index
35808 * @param {Number} dataIndex The new dataIndex
35810 setDataIndex : function(col, dataIndex){
35811 this.config[col].dataIndex = dataIndex;
35817 * Returns true if the cell is editable.
35818 * @param {Number} colIndex The column index
35819 * @param {Number} rowIndex The row index - this is nto actually used..?
35820 * @return {Boolean}
35822 isCellEditable : function(colIndex, rowIndex){
35823 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
35827 * Returns the editor defined for the cell/column.
35828 * return false or null to disable editing.
35829 * @param {Number} colIndex The column index
35830 * @param {Number} rowIndex The row index
35833 getCellEditor : function(colIndex, rowIndex){
35834 return this.config[colIndex].editor;
35838 * Sets if a column is editable.
35839 * @param {Number} col The column index
35840 * @param {Boolean} editable True if the column is editable
35842 setEditable : function(col, editable){
35843 this.config[col].editable = editable;
35848 * Returns true if the column is hidden.
35849 * @param {Number} colIndex The column index
35850 * @return {Boolean}
35852 isHidden : function(colIndex){
35853 return this.config[colIndex].hidden;
35858 * Returns true if the column width cannot be changed
35860 isFixed : function(colIndex){
35861 return this.config[colIndex].fixed;
35865 * Returns true if the column can be resized
35866 * @return {Boolean}
35868 isResizable : function(colIndex){
35869 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
35872 * Sets if a column is hidden.
35873 * @param {Number} colIndex The column index
35874 * @param {Boolean} hidden True if the column is hidden
35876 setHidden : function(colIndex, hidden){
35877 this.config[colIndex].hidden = hidden;
35878 this.totalWidth = null;
35879 this.fireEvent("hiddenchange", this, colIndex, hidden);
35883 * Sets the editor for a column.
35884 * @param {Number} col The column index
35885 * @param {Object} editor The editor object
35887 setEditor : function(col, editor){
35888 this.config[col].editor = editor;
35892 Roo.grid.ColumnModel.defaultRenderer = function(value)
35894 if(typeof value == "object") {
35897 if(typeof value == "string" && value.length < 1){
35901 return String.format("{0}", value);
35904 // Alias for backwards compatibility
35905 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
35908 * Ext JS Library 1.1.1
35909 * Copyright(c) 2006-2007, Ext JS, LLC.
35911 * Originally Released Under LGPL - original licence link has changed is not relivant.
35914 * <script type="text/javascript">
35918 * @class Roo.grid.AbstractSelectionModel
35919 * @extends Roo.util.Observable
35920 * Abstract base class for grid SelectionModels. It provides the interface that should be
35921 * implemented by descendant classes. This class should not be directly instantiated.
35924 Roo.grid.AbstractSelectionModel = function(){
35925 this.locked = false;
35926 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
35929 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
35930 /** @ignore Called by the grid automatically. Do not call directly. */
35931 init : function(grid){
35937 * Locks the selections.
35940 this.locked = true;
35944 * Unlocks the selections.
35946 unlock : function(){
35947 this.locked = false;
35951 * Returns true if the selections are locked.
35952 * @return {Boolean}
35954 isLocked : function(){
35955 return this.locked;
35959 * Ext JS Library 1.1.1
35960 * Copyright(c) 2006-2007, Ext JS, LLC.
35962 * Originally Released Under LGPL - original licence link has changed is not relivant.
35965 * <script type="text/javascript">
35968 * @extends Roo.grid.AbstractSelectionModel
35969 * @class Roo.grid.RowSelectionModel
35970 * The default SelectionModel used by {@link Roo.grid.Grid}.
35971 * It supports multiple selections and keyboard selection/navigation.
35973 * @param {Object} config
35975 Roo.grid.RowSelectionModel = function(config){
35976 Roo.apply(this, config);
35977 this.selections = new Roo.util.MixedCollection(false, function(o){
35982 this.lastActive = false;
35986 * @event selectionchange
35987 * Fires when the selection changes
35988 * @param {SelectionModel} this
35990 "selectionchange" : true,
35992 * @event afterselectionchange
35993 * Fires after the selection changes (eg. by key press or clicking)
35994 * @param {SelectionModel} this
35996 "afterselectionchange" : true,
35998 * @event beforerowselect
35999 * Fires when a row is selected being selected, return false to cancel.
36000 * @param {SelectionModel} this
36001 * @param {Number} rowIndex The selected index
36002 * @param {Boolean} keepExisting False if other selections will be cleared
36004 "beforerowselect" : true,
36007 * Fires when a row is selected.
36008 * @param {SelectionModel} this
36009 * @param {Number} rowIndex The selected index
36010 * @param {Roo.data.Record} r The record
36012 "rowselect" : true,
36014 * @event rowdeselect
36015 * Fires when a row is deselected.
36016 * @param {SelectionModel} this
36017 * @param {Number} rowIndex The selected index
36019 "rowdeselect" : true
36021 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
36022 this.locked = false;
36025 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
36027 * @cfg {Boolean} singleSelect
36028 * True to allow selection of only one row at a time (defaults to false)
36030 singleSelect : false,
36033 initEvents : function(){
36035 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
36036 this.grid.on("mousedown", this.handleMouseDown, this);
36037 }else{ // allow click to work like normal
36038 this.grid.on("rowclick", this.handleDragableRowClick, this);
36041 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
36042 "up" : function(e){
36044 this.selectPrevious(e.shiftKey);
36045 }else if(this.last !== false && this.lastActive !== false){
36046 var last = this.last;
36047 this.selectRange(this.last, this.lastActive-1);
36048 this.grid.getView().focusRow(this.lastActive);
36049 if(last !== false){
36053 this.selectFirstRow();
36055 this.fireEvent("afterselectionchange", this);
36057 "down" : function(e){
36059 this.selectNext(e.shiftKey);
36060 }else if(this.last !== false && this.lastActive !== false){
36061 var last = this.last;
36062 this.selectRange(this.last, this.lastActive+1);
36063 this.grid.getView().focusRow(this.lastActive);
36064 if(last !== false){
36068 this.selectFirstRow();
36070 this.fireEvent("afterselectionchange", this);
36075 var view = this.grid.view;
36076 view.on("refresh", this.onRefresh, this);
36077 view.on("rowupdated", this.onRowUpdated, this);
36078 view.on("rowremoved", this.onRemove, this);
36082 onRefresh : function(){
36083 var ds = this.grid.dataSource, i, v = this.grid.view;
36084 var s = this.selections;
36085 s.each(function(r){
36086 if((i = ds.indexOfId(r.id)) != -1){
36088 s.add(ds.getAt(i)); // updating the selection relate data
36096 onRemove : function(v, index, r){
36097 this.selections.remove(r);
36101 onRowUpdated : function(v, index, r){
36102 if(this.isSelected(r)){
36103 v.onRowSelect(index);
36109 * @param {Array} records The records to select
36110 * @param {Boolean} keepExisting (optional) True to keep existing selections
36112 selectRecords : function(records, keepExisting){
36114 this.clearSelections();
36116 var ds = this.grid.dataSource;
36117 for(var i = 0, len = records.length; i < len; i++){
36118 this.selectRow(ds.indexOf(records[i]), true);
36123 * Gets the number of selected rows.
36126 getCount : function(){
36127 return this.selections.length;
36131 * Selects the first row in the grid.
36133 selectFirstRow : function(){
36138 * Select the last row.
36139 * @param {Boolean} keepExisting (optional) True to keep existing selections
36141 selectLastRow : function(keepExisting){
36142 this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
36146 * Selects the row immediately following the last selected row.
36147 * @param {Boolean} keepExisting (optional) True to keep existing selections
36149 selectNext : function(keepExisting){
36150 if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
36151 this.selectRow(this.last+1, keepExisting);
36152 this.grid.getView().focusRow(this.last);
36157 * Selects the row that precedes the last selected row.
36158 * @param {Boolean} keepExisting (optional) True to keep existing selections
36160 selectPrevious : function(keepExisting){
36162 this.selectRow(this.last-1, keepExisting);
36163 this.grid.getView().focusRow(this.last);
36168 * Returns the selected records
36169 * @return {Array} Array of selected records
36171 getSelections : function(){
36172 return [].concat(this.selections.items);
36176 * Returns the first selected record.
36179 getSelected : function(){
36180 return this.selections.itemAt(0);
36185 * Clears all selections.
36187 clearSelections : function(fast){
36192 var ds = this.grid.dataSource;
36193 var s = this.selections;
36194 s.each(function(r){
36195 this.deselectRow(ds.indexOfId(r.id));
36199 this.selections.clear();
36206 * Selects all rows.
36208 selectAll : function(){
36212 this.selections.clear();
36213 for(var i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
36214 this.selectRow(i, true);
36219 * Returns True if there is a selection.
36220 * @return {Boolean}
36222 hasSelection : function(){
36223 return this.selections.length > 0;
36227 * Returns True if the specified row is selected.
36228 * @param {Number/Record} record The record or index of the record to check
36229 * @return {Boolean}
36231 isSelected : function(index){
36232 var r = typeof index == "number" ? this.grid.dataSource.getAt(index) : index;
36233 return (r && this.selections.key(r.id) ? true : false);
36237 * Returns True if the specified record id is selected.
36238 * @param {String} id The id of record to check
36239 * @return {Boolean}
36241 isIdSelected : function(id){
36242 return (this.selections.key(id) ? true : false);
36246 handleMouseDown : function(e, t){
36247 var view = this.grid.getView(), rowIndex;
36248 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
36251 if(e.shiftKey && this.last !== false){
36252 var last = this.last;
36253 this.selectRange(last, rowIndex, e.ctrlKey);
36254 this.last = last; // reset the last
36255 view.focusRow(rowIndex);
36257 var isSelected = this.isSelected(rowIndex);
36258 if(e.button !== 0 && isSelected){
36259 view.focusRow(rowIndex);
36260 }else if(e.ctrlKey && isSelected){
36261 this.deselectRow(rowIndex);
36262 }else if(!isSelected){
36263 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
36264 view.focusRow(rowIndex);
36267 this.fireEvent("afterselectionchange", this);
36270 handleDragableRowClick : function(grid, rowIndex, e)
36272 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
36273 this.selectRow(rowIndex, false);
36274 grid.view.focusRow(rowIndex);
36275 this.fireEvent("afterselectionchange", this);
36280 * Selects multiple rows.
36281 * @param {Array} rows Array of the indexes of the row to select
36282 * @param {Boolean} keepExisting (optional) True to keep existing selections
36284 selectRows : function(rows, keepExisting){
36286 this.clearSelections();
36288 for(var i = 0, len = rows.length; i < len; i++){
36289 this.selectRow(rows[i], true);
36294 * Selects a range of rows. All rows in between startRow and endRow are also selected.
36295 * @param {Number} startRow The index of the first row in the range
36296 * @param {Number} endRow The index of the last row in the range
36297 * @param {Boolean} keepExisting (optional) True to retain existing selections
36299 selectRange : function(startRow, endRow, keepExisting){
36304 this.clearSelections();
36306 if(startRow <= endRow){
36307 for(var i = startRow; i <= endRow; i++){
36308 this.selectRow(i, true);
36311 for(var i = startRow; i >= endRow; i--){
36312 this.selectRow(i, true);
36318 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
36319 * @param {Number} startRow The index of the first row in the range
36320 * @param {Number} endRow The index of the last row in the range
36322 deselectRange : function(startRow, endRow, preventViewNotify){
36326 for(var i = startRow; i <= endRow; i++){
36327 this.deselectRow(i, preventViewNotify);
36333 * @param {Number} row The index of the row to select
36334 * @param {Boolean} keepExisting (optional) True to keep existing selections
36336 selectRow : function(index, keepExisting, preventViewNotify){
36337 if(this.locked || (index < 0 || index >= this.grid.dataSource.getCount())) {
36340 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
36341 if(!keepExisting || this.singleSelect){
36342 this.clearSelections();
36344 var r = this.grid.dataSource.getAt(index);
36345 this.selections.add(r);
36346 this.last = this.lastActive = index;
36347 if(!preventViewNotify){
36348 this.grid.getView().onRowSelect(index);
36350 this.fireEvent("rowselect", this, index, r);
36351 this.fireEvent("selectionchange", this);
36357 * @param {Number} row The index of the row to deselect
36359 deselectRow : function(index, preventViewNotify){
36363 if(this.last == index){
36366 if(this.lastActive == index){
36367 this.lastActive = false;
36369 var r = this.grid.dataSource.getAt(index);
36370 this.selections.remove(r);
36371 if(!preventViewNotify){
36372 this.grid.getView().onRowDeselect(index);
36374 this.fireEvent("rowdeselect", this, index);
36375 this.fireEvent("selectionchange", this);
36379 restoreLast : function(){
36381 this.last = this._last;
36386 acceptsNav : function(row, col, cm){
36387 return !cm.isHidden(col) && cm.isCellEditable(col, row);
36391 onEditorKey : function(field, e){
36392 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
36397 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
36399 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36401 }else if(k == e.ENTER && !e.ctrlKey){
36405 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
36407 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
36409 }else if(k == e.ESC){
36413 g.startEditing(newCell[0], newCell[1]);
36418 * Ext JS Library 1.1.1
36419 * Copyright(c) 2006-2007, Ext JS, LLC.
36421 * Originally Released Under LGPL - original licence link has changed is not relivant.
36424 * <script type="text/javascript">
36427 * @class Roo.grid.CellSelectionModel
36428 * @extends Roo.grid.AbstractSelectionModel
36429 * This class provides the basic implementation for cell selection in a grid.
36431 * @param {Object} config The object containing the configuration of this model.
36432 * @cfg {Boolean} enter_is_tab Enter behaves the same as tab. (eg. goes to next cell) default: false
36434 Roo.grid.CellSelectionModel = function(config){
36435 Roo.apply(this, config);
36437 this.selection = null;
36441 * @event beforerowselect
36442 * Fires before a cell is selected.
36443 * @param {SelectionModel} this
36444 * @param {Number} rowIndex The selected row index
36445 * @param {Number} colIndex The selected cell index
36447 "beforecellselect" : true,
36449 * @event cellselect
36450 * Fires when a cell is selected.
36451 * @param {SelectionModel} this
36452 * @param {Number} rowIndex The selected row index
36453 * @param {Number} colIndex The selected cell index
36455 "cellselect" : true,
36457 * @event selectionchange
36458 * Fires when the active selection changes.
36459 * @param {SelectionModel} this
36460 * @param {Object} selection null for no selection or an object (o) with two properties
36462 <li>o.record: the record object for the row the selection is in</li>
36463 <li>o.cell: An array of [rowIndex, columnIndex]</li>
36466 "selectionchange" : true,
36469 * Fires when the tab (or enter) was pressed on the last editable cell
36470 * You can use this to trigger add new row.
36471 * @param {SelectionModel} this
36475 * @event beforeeditnext
36476 * Fires before the next editable sell is made active
36477 * You can use this to skip to another cell or fire the tabend
36478 * if you set cell to false
36479 * @param {Object} eventdata object : { cell : [ row, col ] }
36481 "beforeeditnext" : true
36483 Roo.grid.CellSelectionModel.superclass.constructor.call(this);
36486 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel, {
36488 enter_is_tab: false,
36491 initEvents : function(){
36492 this.grid.on("mousedown", this.handleMouseDown, this);
36493 this.grid.getGridEl().on(Roo.isIE ? "keydown" : "keypress", this.handleKeyDown, this);
36494 var view = this.grid.view;
36495 view.on("refresh", this.onViewChange, this);
36496 view.on("rowupdated", this.onRowUpdated, this);
36497 view.on("beforerowremoved", this.clearSelections, this);
36498 view.on("beforerowsinserted", this.clearSelections, this);
36499 if(this.grid.isEditor){
36500 this.grid.on("beforeedit", this.beforeEdit, this);
36505 beforeEdit : function(e){
36506 this.select(e.row, e.column, false, true, e.record);
36510 onRowUpdated : function(v, index, r){
36511 if(this.selection && this.selection.record == r){
36512 v.onCellSelect(index, this.selection.cell[1]);
36517 onViewChange : function(){
36518 this.clearSelections(true);
36522 * Returns the currently selected cell,.
36523 * @return {Array} The selected cell (row, column) or null if none selected.
36525 getSelectedCell : function(){
36526 return this.selection ? this.selection.cell : null;
36530 * Clears all selections.
36531 * @param {Boolean} true to prevent the gridview from being notified about the change.
36533 clearSelections : function(preventNotify){
36534 var s = this.selection;
36536 if(preventNotify !== true){
36537 this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
36539 this.selection = null;
36540 this.fireEvent("selectionchange", this, null);
36545 * Returns true if there is a selection.
36546 * @return {Boolean}
36548 hasSelection : function(){
36549 return this.selection ? true : false;
36553 handleMouseDown : function(e, t){
36554 var v = this.grid.getView();
36555 if(this.isLocked()){
36558 var row = v.findRowIndex(t);
36559 var cell = v.findCellIndex(t);
36560 if(row !== false && cell !== false){
36561 this.select(row, cell);
36567 * @param {Number} rowIndex
36568 * @param {Number} collIndex
36570 select : function(rowIndex, colIndex, preventViewNotify, preventFocus, /*internal*/ r){
36571 if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
36572 this.clearSelections();
36573 r = r || this.grid.dataSource.getAt(rowIndex);
36576 cell : [rowIndex, colIndex]
36578 if(!preventViewNotify){
36579 var v = this.grid.getView();
36580 v.onCellSelect(rowIndex, colIndex);
36581 if(preventFocus !== true){
36582 v.focusCell(rowIndex, colIndex);
36585 this.fireEvent("cellselect", this, rowIndex, colIndex);
36586 this.fireEvent("selectionchange", this, this.selection);
36591 isSelectable : function(rowIndex, colIndex, cm){
36592 return !cm.isHidden(colIndex);
36596 handleKeyDown : function(e){
36597 //Roo.log('Cell Sel Model handleKeyDown');
36598 if(!e.isNavKeyPress()){
36601 var g = this.grid, s = this.selection;
36604 var cell = g.walkCells(0, 0, 1, this.isSelectable, this);
36606 this.select(cell[0], cell[1]);
36611 var walk = function(row, col, step){
36612 return g.walkCells(row, col, step, sm.isSelectable, sm);
36614 var k = e.getKey(), r = s.cell[0], c = s.cell[1];
36621 // handled by onEditorKey
36622 if (g.isEditor && g.editing) {
36626 newCell = walk(r, c-1, -1);
36628 newCell = walk(r, c+1, 1);
36633 newCell = walk(r+1, c, 1);
36637 newCell = walk(r-1, c, -1);
36641 newCell = walk(r, c+1, 1);
36645 newCell = walk(r, c-1, -1);
36650 if(g.isEditor && !g.editing){
36651 g.startEditing(r, c);
36660 this.select(newCell[0], newCell[1]);
36666 acceptsNav : function(row, col, cm){
36667 return !cm.isHidden(col) && cm.isCellEditable(col, row);
36671 * @param {Number} field (not used) - as it's normally used as a listener
36672 * @param {Number} e - event - fake it by using
36674 * var e = Roo.EventObjectImpl.prototype;
36675 * e.keyCode = e.TAB
36679 onEditorKey : function(field, e){
36681 var k = e.getKey(),
36684 ed = g.activeEditor,
36686 ///Roo.log('onEditorKey' + k);
36689 if (this.enter_is_tab && k == e.ENTER) {
36695 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
36697 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36703 } else if(k == e.ENTER && !e.ctrlKey){
36706 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36708 } else if(k == e.ESC){
36713 var ecall = { cell : newCell, forward : forward };
36714 this.fireEvent('beforeeditnext', ecall );
36715 newCell = ecall.cell;
36716 forward = ecall.forward;
36720 //Roo.log('next cell after edit');
36721 g.startEditing.defer(100, g, [newCell[0], newCell[1]]);
36722 } else if (forward) {
36723 // tabbed past last
36724 this.fireEvent.defer(100, this, ['tabend',this]);
36729 * Ext JS Library 1.1.1
36730 * Copyright(c) 2006-2007, Ext JS, LLC.
36732 * Originally Released Under LGPL - original licence link has changed is not relivant.
36735 * <script type="text/javascript">
36739 * @class Roo.grid.EditorGrid
36740 * @extends Roo.grid.Grid
36741 * Class for creating and editable grid.
36742 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
36743 * The container MUST have some type of size defined for the grid to fill. The container will be
36744 * automatically set to position relative if it isn't already.
36745 * @param {Object} dataSource The data model to bind to
36746 * @param {Object} colModel The column model with info about this grid's columns
36748 Roo.grid.EditorGrid = function(container, config){
36749 Roo.grid.EditorGrid.superclass.constructor.call(this, container, config);
36750 this.getGridEl().addClass("xedit-grid");
36752 if(!this.selModel){
36753 this.selModel = new Roo.grid.CellSelectionModel();
36756 this.activeEditor = null;
36760 * @event beforeedit
36761 * Fires before cell editing is triggered. The edit event object has the following properties <br />
36762 * <ul style="padding:5px;padding-left:16px;">
36763 * <li>grid - This grid</li>
36764 * <li>record - The record being edited</li>
36765 * <li>field - The field name being edited</li>
36766 * <li>value - The value for the field being edited.</li>
36767 * <li>row - The grid row index</li>
36768 * <li>column - The grid column index</li>
36769 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
36771 * @param {Object} e An edit event (see above for description)
36773 "beforeedit" : true,
36776 * Fires after a cell is edited. <br />
36777 * <ul style="padding:5px;padding-left:16px;">
36778 * <li>grid - This grid</li>
36779 * <li>record - The record being edited</li>
36780 * <li>field - The field name being edited</li>
36781 * <li>value - The value being set</li>
36782 * <li>originalValue - The original value for the field, before the edit.</li>
36783 * <li>row - The grid row index</li>
36784 * <li>column - The grid column index</li>
36786 * @param {Object} e An edit event (see above for description)
36788 "afteredit" : true,
36790 * @event validateedit
36791 * Fires after a cell is edited, but before the value is set in the record.
36792 * You can use this to modify the value being set in the field, Return false
36793 * to cancel the change. The edit event object has the following properties <br />
36794 * <ul style="padding:5px;padding-left:16px;">
36795 * <li>editor - This editor</li>
36796 * <li>grid - This grid</li>
36797 * <li>record - The record being edited</li>
36798 * <li>field - The field name being edited</li>
36799 * <li>value - The value being set</li>
36800 * <li>originalValue - The original value for the field, before the edit.</li>
36801 * <li>row - The grid row index</li>
36802 * <li>column - The grid column index</li>
36803 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
36805 * @param {Object} e An edit event (see above for description)
36807 "validateedit" : true
36809 this.on("bodyscroll", this.stopEditing, this);
36810 this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick, this);
36813 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
36815 * @cfg {Number} clicksToEdit
36816 * The number of clicks on a cell required to display the cell's editor (defaults to 2)
36823 trackMouseOver: false, // causes very odd FF errors
36825 onCellDblClick : function(g, row, col){
36826 this.startEditing(row, col);
36829 onEditComplete : function(ed, value, startValue){
36830 this.editing = false;
36831 this.activeEditor = null;
36832 ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
36834 var field = this.colModel.getDataIndex(ed.col);
36839 originalValue: startValue,
36846 var cell = Roo.get(this.view.getCell(ed.row,ed.col));
36849 if(String(value) !== String(startValue)){
36851 if(this.fireEvent("validateedit", e) !== false && !e.cancel){
36852 r.set(field, e.value);
36853 // if we are dealing with a combo box..
36854 // then we also set the 'name' colum to be the displayField
36855 if (ed.field.displayField && ed.field.name) {
36856 r.set(ed.field.name, ed.field.el.dom.value);
36859 delete e.cancel; //?? why!!!
36860 this.fireEvent("afteredit", e);
36863 this.fireEvent("afteredit", e); // always fire it!
36865 this.view.focusCell(ed.row, ed.col);
36869 * Starts editing the specified for the specified row/column
36870 * @param {Number} rowIndex
36871 * @param {Number} colIndex
36873 startEditing : function(row, col){
36874 this.stopEditing();
36875 if(this.colModel.isCellEditable(col, row)){
36876 this.view.ensureVisible(row, col, true);
36878 var r = this.dataSource.getAt(row);
36879 var field = this.colModel.getDataIndex(col);
36880 var cell = Roo.get(this.view.getCell(row,col));
36885 value: r.data[field],
36890 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
36891 this.editing = true;
36892 var ed = this.colModel.getCellEditor(col, row);
36898 ed.render(ed.parentEl || document.body);
36904 (function(){ // complex but required for focus issues in safari, ie and opera
36908 ed.on("complete", this.onEditComplete, this, {single: true});
36909 ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
36910 this.activeEditor = ed;
36911 var v = r.data[field];
36912 ed.startEdit(this.view.getCell(row, col), v);
36913 // combo's with 'displayField and name set
36914 if (ed.field.displayField && ed.field.name) {
36915 ed.field.el.dom.value = r.data[ed.field.name];
36919 }).defer(50, this);
36925 * Stops any active editing
36927 stopEditing : function(){
36928 if(this.activeEditor){
36929 this.activeEditor.completeEdit();
36931 this.activeEditor = null;
36935 * Called to get grid's drag proxy text, by default returns this.ddText.
36938 getDragDropText : function(){
36939 var count = this.selModel.getSelectedCell() ? 1 : 0;
36940 return String.format(this.ddText, count, count == 1 ? '' : 's');
36945 * Ext JS Library 1.1.1
36946 * Copyright(c) 2006-2007, Ext JS, LLC.
36948 * Originally Released Under LGPL - original licence link has changed is not relivant.
36951 * <script type="text/javascript">
36954 // private - not really -- you end up using it !
36955 // This is a support class used internally by the Grid components
36958 * @class Roo.grid.GridEditor
36959 * @extends Roo.Editor
36960 * Class for creating and editable grid elements.
36961 * @param {Object} config any settings (must include field)
36963 Roo.grid.GridEditor = function(field, config){
36964 if (!config && field.field) {
36966 field = Roo.factory(config.field, Roo.form);
36968 Roo.grid.GridEditor.superclass.constructor.call(this, field, config);
36969 field.monitorTab = false;
36972 Roo.extend(Roo.grid.GridEditor, Roo.Editor, {
36975 * @cfg {Roo.form.Field} field Field to wrap (or xtyped)
36978 alignment: "tl-tl",
36981 cls: "x-small-editor x-grid-editor",
36986 * Ext JS Library 1.1.1
36987 * Copyright(c) 2006-2007, Ext JS, LLC.
36989 * Originally Released Under LGPL - original licence link has changed is not relivant.
36992 * <script type="text/javascript">
36997 Roo.grid.PropertyRecord = Roo.data.Record.create([
36998 {name:'name',type:'string'}, 'value'
37002 Roo.grid.PropertyStore = function(grid, source){
37004 this.store = new Roo.data.Store({
37005 recordType : Roo.grid.PropertyRecord
37007 this.store.on('update', this.onUpdate, this);
37009 this.setSource(source);
37011 Roo.grid.PropertyStore.superclass.constructor.call(this);
37016 Roo.extend(Roo.grid.PropertyStore, Roo.util.Observable, {
37017 setSource : function(o){
37019 this.store.removeAll();
37022 if(this.isEditableValue(o[k])){
37023 data.push(new Roo.grid.PropertyRecord({name: k, value: o[k]}, k));
37026 this.store.loadRecords({records: data}, {}, true);
37029 onUpdate : function(ds, record, type){
37030 if(type == Roo.data.Record.EDIT){
37031 var v = record.data['value'];
37032 var oldValue = record.modified['value'];
37033 if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
37034 this.source[record.id] = v;
37036 this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
37043 getProperty : function(row){
37044 return this.store.getAt(row);
37047 isEditableValue: function(val){
37048 if(val && val instanceof Date){
37050 }else if(typeof val == 'object' || typeof val == 'function'){
37056 setValue : function(prop, value){
37057 this.source[prop] = value;
37058 this.store.getById(prop).set('value', value);
37061 getSource : function(){
37062 return this.source;
37066 Roo.grid.PropertyColumnModel = function(grid, store){
37069 g.PropertyColumnModel.superclass.constructor.call(this, [
37070 {header: this.nameText, sortable: true, dataIndex:'name', id: 'name'},
37071 {header: this.valueText, resizable:false, dataIndex: 'value', id: 'value'}
37073 this.store = store;
37074 this.bselect = Roo.DomHelper.append(document.body, {
37075 tag: 'select', style:'display:none', cls: 'x-grid-editor', children: [
37076 {tag: 'option', value: 'true', html: 'true'},
37077 {tag: 'option', value: 'false', html: 'false'}
37080 Roo.id(this.bselect);
37083 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
37084 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
37085 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
37086 'int' : new g.GridEditor(new f.NumberField({selectOnFocus:true, allowDecimals:false, style:'text-align:left;'})),
37087 'boolean' : new g.GridEditor(new f.Field({el:this.bselect,selectOnFocus:true}))
37089 this.renderCellDelegate = this.renderCell.createDelegate(this);
37090 this.renderPropDelegate = this.renderProp.createDelegate(this);
37093 Roo.extend(Roo.grid.PropertyColumnModel, Roo.grid.ColumnModel, {
37097 valueText : 'Value',
37099 dateFormat : 'm/j/Y',
37102 renderDate : function(dateVal){
37103 return dateVal.dateFormat(this.dateFormat);
37106 renderBool : function(bVal){
37107 return bVal ? 'true' : 'false';
37110 isCellEditable : function(colIndex, rowIndex){
37111 return colIndex == 1;
37114 getRenderer : function(col){
37116 this.renderCellDelegate : this.renderPropDelegate;
37119 renderProp : function(v){
37120 return this.getPropertyName(v);
37123 renderCell : function(val){
37125 if(val instanceof Date){
37126 rv = this.renderDate(val);
37127 }else if(typeof val == 'boolean'){
37128 rv = this.renderBool(val);
37130 return Roo.util.Format.htmlEncode(rv);
37133 getPropertyName : function(name){
37134 var pn = this.grid.propertyNames;
37135 return pn && pn[name] ? pn[name] : name;
37138 getCellEditor : function(colIndex, rowIndex){
37139 var p = this.store.getProperty(rowIndex);
37140 var n = p.data['name'], val = p.data['value'];
37142 if(typeof(this.grid.customEditors[n]) == 'string'){
37143 return this.editors[this.grid.customEditors[n]];
37145 if(typeof(this.grid.customEditors[n]) != 'undefined'){
37146 return this.grid.customEditors[n];
37148 if(val instanceof Date){
37149 return this.editors['date'];
37150 }else if(typeof val == 'number'){
37151 return this.editors['number'];
37152 }else if(typeof val == 'boolean'){
37153 return this.editors['boolean'];
37155 return this.editors['string'];
37161 * @class Roo.grid.PropertyGrid
37162 * @extends Roo.grid.EditorGrid
37163 * This class represents the interface of a component based property grid control.
37164 * <br><br>Usage:<pre><code>
37165 var grid = new Roo.grid.PropertyGrid("my-container-id", {
37173 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
37174 * The container MUST have some type of size defined for the grid to fill. The container will be
37175 * automatically set to position relative if it isn't already.
37176 * @param {Object} config A config object that sets properties on this grid.
37178 Roo.grid.PropertyGrid = function(container, config){
37179 config = config || {};
37180 var store = new Roo.grid.PropertyStore(this);
37181 this.store = store;
37182 var cm = new Roo.grid.PropertyColumnModel(this, store);
37183 store.store.sort('name', 'ASC');
37184 Roo.grid.PropertyGrid.superclass.constructor.call(this, container, Roo.apply({
37187 enableColLock:false,
37188 enableColumnMove:false,
37190 trackMouseOver: false,
37193 this.getGridEl().addClass('x-props-grid');
37194 this.lastEditRow = null;
37195 this.on('columnresize', this.onColumnResize, this);
37198 * @event beforepropertychange
37199 * Fires before a property changes (return false to stop?)
37200 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
37201 * @param {String} id Record Id
37202 * @param {String} newval New Value
37203 * @param {String} oldval Old Value
37205 "beforepropertychange": true,
37207 * @event propertychange
37208 * Fires after a property changes
37209 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
37210 * @param {String} id Record Id
37211 * @param {String} newval New Value
37212 * @param {String} oldval Old Value
37214 "propertychange": true
37216 this.customEditors = this.customEditors || {};
37218 Roo.extend(Roo.grid.PropertyGrid, Roo.grid.EditorGrid, {
37221 * @cfg {Object} customEditors map of colnames=> custom editors.
37222 * the custom editor can be one of the standard ones (date|string|number|int|boolean), or a
37223 * grid editor eg. Roo.grid.GridEditor(new Roo.form.TextArea({selectOnFocus:true})),
37224 * false disables editing of the field.
37228 * @cfg {Object} propertyNames map of property Names to their displayed value
37231 render : function(){
37232 Roo.grid.PropertyGrid.superclass.render.call(this);
37233 this.autoSize.defer(100, this);
37236 autoSize : function(){
37237 Roo.grid.PropertyGrid.superclass.autoSize.call(this);
37239 this.view.fitColumns();
37243 onColumnResize : function(){
37244 this.colModel.setColumnWidth(1, this.container.getWidth(true)-this.colModel.getColumnWidth(0));
37248 * Sets the data for the Grid
37249 * accepts a Key => Value object of all the elements avaiable.
37250 * @param {Object} data to appear in grid.
37252 setSource : function(source){
37253 this.store.setSource(source);
37257 * Gets all the data from the grid.
37258 * @return {Object} data data stored in grid
37260 getSource : function(){
37261 return this.store.getSource();
37270 * @class Roo.grid.Calendar
37271 * @extends Roo.util.Grid
37272 * This class extends the Grid to provide a calendar widget
37273 * <br><br>Usage:<pre><code>
37274 var grid = new Roo.grid.Calendar("my-container-id", {
37277 selModel: mySelectionModel,
37278 autoSizeColumns: true,
37279 monitorWindowResize: false,
37280 trackMouseOver: true
37281 eventstore : real data store..
37287 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
37288 * The container MUST have some type of size defined for the grid to fill. The container will be
37289 * automatically set to position relative if it isn't already.
37290 * @param {Object} config A config object that sets properties on this grid.
37292 Roo.grid.Calendar = function(container, config){
37293 // initialize the container
37294 this.container = Roo.get(container);
37295 this.container.update("");
37296 this.container.setStyle("overflow", "hidden");
37297 this.container.addClass('x-grid-container');
37299 this.id = this.container.id;
37301 Roo.apply(this, config);
37302 // check and correct shorthanded configs
37306 for (var r = 0;r < 6;r++) {
37309 for (var c =0;c < 7;c++) {
37313 if (this.eventStore) {
37314 this.eventStore= Roo.factory(this.eventStore, Roo.data);
37315 this.eventStore.on('load',this.onLoad, this);
37316 this.eventStore.on('beforeload',this.clearEvents, this);
37320 this.dataSource = new Roo.data.Store({
37321 proxy: new Roo.data.MemoryProxy(rows),
37322 reader: new Roo.data.ArrayReader({}, [
37323 'weekday0', 'weekday1', 'weekday2', 'weekday3', 'weekday4', 'weekday5', 'weekday6' ])
37326 this.dataSource.load();
37327 this.ds = this.dataSource;
37328 this.ds.xmodule = this.xmodule || false;
37331 var cellRender = function(v,x,r)
37333 return String.format(
37334 '<div class="fc-day fc-widget-content"><div>' +
37335 '<div class="fc-event-container"></div>' +
37336 '<div class="fc-day-number">{0}</div>'+
37338 '<div class="fc-day-content"><div style="position:relative"></div></div>' +
37339 '</div></div>', v);
37344 this.colModel = new Roo.grid.ColumnModel( [
37346 xtype: 'ColumnModel',
37348 dataIndex : 'weekday0',
37350 renderer : cellRender
37353 xtype: 'ColumnModel',
37355 dataIndex : 'weekday1',
37357 renderer : cellRender
37360 xtype: 'ColumnModel',
37362 dataIndex : 'weekday2',
37363 header : 'Tuesday',
37364 renderer : cellRender
37367 xtype: 'ColumnModel',
37369 dataIndex : 'weekday3',
37370 header : 'Wednesday',
37371 renderer : cellRender
37374 xtype: 'ColumnModel',
37376 dataIndex : 'weekday4',
37377 header : 'Thursday',
37378 renderer : cellRender
37381 xtype: 'ColumnModel',
37383 dataIndex : 'weekday5',
37385 renderer : cellRender
37388 xtype: 'ColumnModel',
37390 dataIndex : 'weekday6',
37391 header : 'Saturday',
37392 renderer : cellRender
37395 this.cm = this.colModel;
37396 this.cm.xmodule = this.xmodule || false;
37400 //this.selModel = new Roo.grid.CellSelectionModel();
37401 //this.sm = this.selModel;
37402 //this.selModel.init(this);
37406 this.container.setWidth(this.width);
37410 this.container.setHeight(this.height);
37417 * The raw click event for the entire grid.
37418 * @param {Roo.EventObject} e
37423 * The raw dblclick event for the entire grid.
37424 * @param {Roo.EventObject} e
37428 * @event contextmenu
37429 * The raw contextmenu event for the entire grid.
37430 * @param {Roo.EventObject} e
37432 "contextmenu" : true,
37435 * The raw mousedown event for the entire grid.
37436 * @param {Roo.EventObject} e
37438 "mousedown" : true,
37441 * The raw mouseup event for the entire grid.
37442 * @param {Roo.EventObject} e
37447 * The raw mouseover event for the entire grid.
37448 * @param {Roo.EventObject} e
37450 "mouseover" : true,
37453 * The raw mouseout event for the entire grid.
37454 * @param {Roo.EventObject} e
37459 * The raw keypress event for the entire grid.
37460 * @param {Roo.EventObject} e
37465 * The raw keydown event for the entire grid.
37466 * @param {Roo.EventObject} e
37474 * Fires when a cell is clicked
37475 * @param {Grid} this
37476 * @param {Number} rowIndex
37477 * @param {Number} columnIndex
37478 * @param {Roo.EventObject} e
37480 "cellclick" : true,
37482 * @event celldblclick
37483 * Fires when a cell is double clicked
37484 * @param {Grid} this
37485 * @param {Number} rowIndex
37486 * @param {Number} columnIndex
37487 * @param {Roo.EventObject} e
37489 "celldblclick" : true,
37492 * Fires when a row is clicked
37493 * @param {Grid} this
37494 * @param {Number} rowIndex
37495 * @param {Roo.EventObject} e
37499 * @event rowdblclick
37500 * Fires when a row is double clicked
37501 * @param {Grid} this
37502 * @param {Number} rowIndex
37503 * @param {Roo.EventObject} e
37505 "rowdblclick" : true,
37507 * @event headerclick
37508 * Fires when a header is clicked
37509 * @param {Grid} this
37510 * @param {Number} columnIndex
37511 * @param {Roo.EventObject} e
37513 "headerclick" : true,
37515 * @event headerdblclick
37516 * Fires when a header cell is double clicked
37517 * @param {Grid} this
37518 * @param {Number} columnIndex
37519 * @param {Roo.EventObject} e
37521 "headerdblclick" : true,
37523 * @event rowcontextmenu
37524 * Fires when a row is right clicked
37525 * @param {Grid} this
37526 * @param {Number} rowIndex
37527 * @param {Roo.EventObject} e
37529 "rowcontextmenu" : true,
37531 * @event cellcontextmenu
37532 * Fires when a cell is right clicked
37533 * @param {Grid} this
37534 * @param {Number} rowIndex
37535 * @param {Number} cellIndex
37536 * @param {Roo.EventObject} e
37538 "cellcontextmenu" : true,
37540 * @event headercontextmenu
37541 * Fires when a header is right clicked
37542 * @param {Grid} this
37543 * @param {Number} columnIndex
37544 * @param {Roo.EventObject} e
37546 "headercontextmenu" : true,
37548 * @event bodyscroll
37549 * Fires when the body element is scrolled
37550 * @param {Number} scrollLeft
37551 * @param {Number} scrollTop
37553 "bodyscroll" : true,
37555 * @event columnresize
37556 * Fires when the user resizes a column
37557 * @param {Number} columnIndex
37558 * @param {Number} newSize
37560 "columnresize" : true,
37562 * @event columnmove
37563 * Fires when the user moves a column
37564 * @param {Number} oldIndex
37565 * @param {Number} newIndex
37567 "columnmove" : true,
37570 * Fires when row(s) start being dragged
37571 * @param {Grid} this
37572 * @param {Roo.GridDD} dd The drag drop object
37573 * @param {event} e The raw browser event
37575 "startdrag" : true,
37578 * Fires when a drag operation is complete
37579 * @param {Grid} this
37580 * @param {Roo.GridDD} dd The drag drop object
37581 * @param {event} e The raw browser event
37586 * Fires when dragged row(s) are dropped on a valid DD target
37587 * @param {Grid} this
37588 * @param {Roo.GridDD} dd The drag drop object
37589 * @param {String} targetId The target drag drop object
37590 * @param {event} e The raw browser event
37595 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
37596 * @param {Grid} this
37597 * @param {Roo.GridDD} dd The drag drop object
37598 * @param {String} targetId The target drag drop object
37599 * @param {event} e The raw browser event
37604 * Fires when the dragged row(s) first cross another DD target while being dragged
37605 * @param {Grid} this
37606 * @param {Roo.GridDD} dd The drag drop object
37607 * @param {String} targetId The target drag drop object
37608 * @param {event} e The raw browser event
37610 "dragenter" : true,
37613 * Fires when the dragged row(s) leave another DD target while being dragged
37614 * @param {Grid} this
37615 * @param {Roo.GridDD} dd The drag drop object
37616 * @param {String} targetId The target drag drop object
37617 * @param {event} e The raw browser event
37622 * Fires when a row is rendered, so you can change add a style to it.
37623 * @param {GridView} gridview The grid view
37624 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
37630 * Fires when the grid is rendered
37631 * @param {Grid} grid
37636 * Fires when a date is selected
37637 * @param {DatePicker} this
37638 * @param {Date} date The selected date
37642 * @event monthchange
37643 * Fires when the displayed month changes
37644 * @param {DatePicker} this
37645 * @param {Date} date The selected month
37647 'monthchange': true,
37649 * @event evententer
37650 * Fires when mouse over an event
37651 * @param {Calendar} this
37652 * @param {event} Event
37654 'evententer': true,
37656 * @event eventleave
37657 * Fires when the mouse leaves an
37658 * @param {Calendar} this
37661 'eventleave': true,
37663 * @event eventclick
37664 * Fires when the mouse click an
37665 * @param {Calendar} this
37668 'eventclick': true,
37670 * @event eventrender
37671 * Fires before each cell is rendered, so you can modify the contents, like cls / title / qtip
37672 * @param {Calendar} this
37673 * @param {data} data to be modified
37675 'eventrender': true
37679 Roo.grid.Grid.superclass.constructor.call(this);
37680 this.on('render', function() {
37681 this.view.el.addClass('x-grid-cal');
37683 (function() { this.setDate(new Date()); }).defer(100,this); //default today..
37687 if (!Roo.grid.Calendar.style) {
37688 Roo.grid.Calendar.style = Roo.util.CSS.createStyleSheet({
37691 '.x-grid-cal .x-grid-col' : {
37692 height: 'auto !important',
37693 'vertical-align': 'top'
37695 '.x-grid-cal .fc-event-hori' : {
37706 Roo.extend(Roo.grid.Calendar, Roo.grid.Grid, {
37708 * @cfg {Store} eventStore The store that loads events.
37713 activeDate : false,
37716 monitorWindowResize : false,
37719 resizeColumns : function() {
37720 var col = (this.view.el.getWidth() / 7) - 3;
37721 // loop through cols, and setWidth
37722 for(var i =0 ; i < 7 ; i++){
37723 this.cm.setColumnWidth(i, col);
37726 setDate :function(date) {
37728 Roo.log('setDate?');
37730 this.resizeColumns();
37731 var vd = this.activeDate;
37732 this.activeDate = date;
37733 // if(vd && this.el){
37734 // var t = date.getTime();
37735 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
37736 // Roo.log('using add remove');
37738 // this.fireEvent('monthchange', this, date);
37740 // this.cells.removeClass("fc-state-highlight");
37741 // this.cells.each(function(c){
37742 // if(c.dateValue == t){
37743 // c.addClass("fc-state-highlight");
37744 // setTimeout(function(){
37745 // try{c.dom.firstChild.focus();}catch(e){}
37755 var days = date.getDaysInMonth();
37757 var firstOfMonth = date.getFirstDateOfMonth();
37758 var startingPos = firstOfMonth.getDay()-this.startDay;
37760 if(startingPos < this.startDay){
37764 var pm = date.add(Date.MONTH, -1);
37765 var prevStart = pm.getDaysInMonth()-startingPos;
37769 this.cells = this.view.el.select('.x-grid-row .x-grid-col',true);
37771 this.textNodes = this.view.el.query('.x-grid-row .x-grid-col .x-grid-cell-text');
37772 //this.cells.addClassOnOver('fc-state-hover');
37774 var cells = this.cells.elements;
37775 var textEls = this.textNodes;
37777 //Roo.each(cells, function(cell){
37778 // cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
37781 days += startingPos;
37783 // convert everything to numbers so it's fast
37784 var day = 86400000;
37785 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
37788 //Roo.log(prevStart);
37790 var today = new Date().clearTime().getTime();
37791 var sel = date.clearTime().getTime();
37792 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
37793 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
37794 var ddMatch = this.disabledDatesRE;
37795 var ddText = this.disabledDatesText;
37796 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
37797 var ddaysText = this.disabledDaysText;
37798 var format = this.format;
37800 var setCellClass = function(cal, cell){
37802 //Roo.log('set Cell Class');
37804 var t = d.getTime();
37809 cell.dateValue = t;
37811 cell.className += " fc-today";
37812 cell.className += " fc-state-highlight";
37813 cell.title = cal.todayText;
37816 // disable highlight in other month..
37817 cell.className += " fc-state-highlight";
37822 //cell.className = " fc-state-disabled";
37823 cell.title = cal.minText;
37827 //cell.className = " fc-state-disabled";
37828 cell.title = cal.maxText;
37832 if(ddays.indexOf(d.getDay()) != -1){
37833 // cell.title = ddaysText;
37834 // cell.className = " fc-state-disabled";
37837 if(ddMatch && format){
37838 var fvalue = d.dateFormat(format);
37839 if(ddMatch.test(fvalue)){
37840 cell.title = ddText.replace("%0", fvalue);
37841 cell.className = " fc-state-disabled";
37845 if (!cell.initialClassName) {
37846 cell.initialClassName = cell.dom.className;
37849 cell.dom.className = cell.initialClassName + ' ' + cell.className;
37854 for(; i < startingPos; i++) {
37855 cells[i].dayName = (++prevStart);
37856 Roo.log(textEls[i]);
37857 d.setDate(d.getDate()+1);
37859 //cells[i].className = "fc-past fc-other-month";
37860 setCellClass(this, cells[i]);
37865 for(; i < days; i++){
37866 intDay = i - startingPos + 1;
37867 cells[i].dayName = (intDay);
37868 d.setDate(d.getDate()+1);
37870 cells[i].className = ''; // "x-date-active";
37871 setCellClass(this, cells[i]);
37875 for(; i < 42; i++) {
37876 //textEls[i].innerHTML = (++extraDays);
37878 d.setDate(d.getDate()+1);
37879 cells[i].dayName = (++extraDays);
37880 cells[i].className = "fc-future fc-other-month";
37881 setCellClass(this, cells[i]);
37884 //this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
37886 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
37888 // this will cause all the cells to mis
37891 for (var r = 0;r < 6;r++) {
37892 for (var c =0;c < 7;c++) {
37893 this.ds.getAt(r).set('weekday' + c ,cells[i++].dayName );
37897 this.cells = this.view.el.select('.x-grid-row .x-grid-col',true);
37898 for(i=0;i<cells.length;i++) {
37900 this.cells.elements[i].dayName = cells[i].dayName ;
37901 this.cells.elements[i].className = cells[i].className;
37902 this.cells.elements[i].initialClassName = cells[i].initialClassName ;
37903 this.cells.elements[i].title = cells[i].title ;
37904 this.cells.elements[i].dateValue = cells[i].dateValue ;
37910 //this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
37911 //this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
37913 ////if(totalRows != 6){
37914 //this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
37915 // this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
37918 this.fireEvent('monthchange', this, date);
37923 * Returns the grid's SelectionModel.
37924 * @return {SelectionModel}
37926 getSelectionModel : function(){
37927 if(!this.selModel){
37928 this.selModel = new Roo.grid.CellSelectionModel();
37930 return this.selModel;
37934 this.eventStore.load()
37940 findCell : function(dt) {
37941 dt = dt.clearTime().getTime();
37943 this.cells.each(function(c){
37944 //Roo.log("check " +c.dateValue + '?=' + dt);
37945 if(c.dateValue == dt){
37955 findCells : function(rec) {
37956 var s = rec.data.start_dt.clone().clearTime().getTime();
37958 var e= rec.data.end_dt.clone().clearTime().getTime();
37961 this.cells.each(function(c){
37962 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
37964 if(c.dateValue > e){
37967 if(c.dateValue < s){
37976 findBestRow: function(cells)
37980 for (var i =0 ; i < cells.length;i++) {
37981 ret = Math.max(cells[i].rows || 0,ret);
37988 addItem : function(rec)
37990 // look for vertical location slot in
37991 var cells = this.findCells(rec);
37993 rec.row = this.findBestRow(cells);
37995 // work out the location.
37999 for(var i =0; i < cells.length; i++) {
38007 if (crow.start.getY() == cells[i].getY()) {
38009 crow.end = cells[i];
38025 for (var i = 0; i < cells.length;i++) {
38026 cells[i].rows = Math.max(cells[i].rows || 0 , rec.row + 1 );
38033 clearEvents: function() {
38035 if (!this.eventStore.getCount()) {
38038 // reset number of rows in cells.
38039 Roo.each(this.cells.elements, function(c){
38043 this.eventStore.each(function(e) {
38044 this.clearEvent(e);
38049 clearEvent : function(ev)
38052 Roo.each(ev.els, function(el) {
38053 el.un('mouseenter' ,this.onEventEnter, this);
38054 el.un('mouseleave' ,this.onEventLeave, this);
38062 renderEvent : function(ev,ctr) {
38064 ctr = this.view.el.select('.fc-event-container',true).first();
38068 this.clearEvent(ev);
38074 var cells = ev.cells;
38075 var rows = ev.rows;
38076 this.fireEvent('eventrender', this, ev);
38078 for(var i =0; i < rows.length; i++) {
38082 cls += ' fc-event-start';
38084 if ((i+1) == rows.length) {
38085 cls += ' fc-event-end';
38088 //Roo.log(ev.data);
38089 // how many rows should it span..
38090 var cg = this.eventTmpl.append(ctr,Roo.apply({
38093 }, ev.data) , true);
38096 cg.on('mouseenter' ,this.onEventEnter, this, ev);
38097 cg.on('mouseleave' ,this.onEventLeave, this, ev);
38098 cg.on('click', this.onEventClick, this, ev);
38102 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
38103 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
38106 cg.setXY([sbox.x +2, sbox.y +(ev.row * 20)]);
38107 cg.setWidth(ebox.right - sbox.x -2);
38111 renderEvents: function()
38113 // first make sure there is enough space..
38115 if (!this.eventTmpl) {
38116 this.eventTmpl = new Roo.Template(
38117 '<div class="roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable {fccls} {cls}" style="position: absolute" unselectable="on">' +
38118 '<div class="fc-event-inner">' +
38119 '<span class="fc-event-time">{time}</span>' +
38120 '<span class="fc-event-title" qtip="{qtip}">{title}</span>' +
38122 '<div class="ui-resizable-heandle ui-resizable-e"> </div>' +
38130 this.cells.each(function(c) {
38131 //Roo.log(c.select('.fc-day-content div',true).first());
38132 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, (c.rows || 1) * 20));
38135 var ctr = this.view.el.select('.fc-event-container',true).first();
38138 this.eventStore.each(function(ev){
38140 this.renderEvent(ev);
38144 this.view.layout();
38148 onEventEnter: function (e, el,event,d) {
38149 this.fireEvent('evententer', this, el, event);
38152 onEventLeave: function (e, el,event,d) {
38153 this.fireEvent('eventleave', this, el, event);
38156 onEventClick: function (e, el,event,d) {
38157 this.fireEvent('eventclick', this, el, event);
38160 onMonthChange: function () {
38164 onLoad: function () {
38166 //Roo.log('calendar onload');
38168 if(this.eventStore.getCount() > 0){
38172 this.eventStore.each(function(d){
38177 if (typeof(add.end_dt) == 'undefined') {
38178 Roo.log("Missing End time in calendar data: ");
38182 if (typeof(add.start_dt) == 'undefined') {
38183 Roo.log("Missing Start time in calendar data: ");
38187 add.start_dt = typeof(add.start_dt) == 'string' ? Date.parseDate(add.start_dt,'Y-m-d H:i:s') : add.start_dt,
38188 add.end_dt = typeof(add.end_dt) == 'string' ? Date.parseDate(add.end_dt,'Y-m-d H:i:s') : add.end_dt,
38189 add.id = add.id || d.id;
38190 add.title = add.title || '??';
38198 this.renderEvents();
38208 render : function ()
38212 if (!this.view.el.hasClass('course-timesheet')) {
38213 this.view.el.addClass('course-timesheet');
38215 if (this.tsStyle) {
38220 Roo.log(_this.grid.view.el.getWidth());
38223 this.tsStyle = Roo.util.CSS.createStyleSheet({
38224 '.course-timesheet .x-grid-row' : {
38227 '.x-grid-row td' : {
38228 'vertical-align' : 0
38230 '.course-edit-link' : {
38232 'text-overflow' : 'ellipsis',
38233 'overflow' : 'hidden',
38234 'white-space' : 'nowrap',
38235 'cursor' : 'pointer'
38240 '.de-act-sup-link' : {
38241 'color' : 'purple',
38242 'text-decoration' : 'line-through'
38246 'text-decoration' : 'line-through'
38248 '.course-timesheet .course-highlight' : {
38249 'border-top-style': 'dashed !important',
38250 'border-bottom-bottom': 'dashed !important'
38252 '.course-timesheet .course-item' : {
38253 'font-family' : 'tahoma, arial, helvetica',
38254 'font-size' : '11px',
38255 'overflow' : 'hidden',
38256 'padding-left' : '10px',
38257 'padding-right' : '10px',
38258 'padding-top' : '10px'
38266 monitorWindowResize : false,
38267 cellrenderer : function(v,x,r)
38272 xtype: 'CellSelectionModel',
38279 beforeload : function (_self, options)
38281 options.params = options.params || {};
38282 options.params._month = _this.monthField.getValue();
38283 options.params.limit = 9999;
38284 options.params['sort'] = 'when_dt';
38285 options.params['dir'] = 'ASC';
38286 this.proxy.loadResponse = this.loadResponse;
38288 //this.addColumns();
38290 load : function (_self, records, options)
38292 _this.grid.view.el.select('.course-edit-link', true).on('click', function() {
38293 // if you click on the translation.. you can edit it...
38294 var el = Roo.get(this);
38295 var id = el.dom.getAttribute('data-id');
38296 var d = el.dom.getAttribute('data-date');
38297 var t = el.dom.getAttribute('data-time');
38298 //var id = this.child('span').dom.textContent;
38301 Pman.Dialog.CourseCalendar.show({
38305 productitem_active : id ? 1 : 0
38307 _this.grid.ds.load({});
38312 _this.panel.fireEvent('resize', [ '', '' ]);
38315 loadResponse : function(o, success, response){
38316 // this is overridden on before load..
38318 Roo.log("our code?");
38319 //Roo.log(success);
38320 //Roo.log(response)
38321 delete this.activeRequest;
38323 this.fireEvent("loadexception", this, o, response);
38324 o.request.callback.call(o.request.scope, null, o.request.arg, false);
38329 result = o.reader.read(response);
38331 Roo.log("load exception?");
38332 this.fireEvent("loadexception", this, o, response, e);
38333 o.request.callback.call(o.request.scope, null, o.request.arg, false);
38336 Roo.log("ready...");
38337 // loop through result.records;
38338 // and set this.tdate[date] = [] << array of records..
38340 Roo.each(result.records, function(r){
38342 if(typeof(_this.tdata[r.data.when_dt.format('j')]) == 'undefined'){
38343 _this.tdata[r.data.when_dt.format('j')] = [];
38345 _this.tdata[r.data.when_dt.format('j')].push(r.data);
38348 //Roo.log(_this.tdata);
38350 result.records = [];
38351 result.totalRecords = 6;
38353 // let's generate some duumy records for the rows.
38354 //var st = _this.dateField.getValue();
38356 // work out monday..
38357 //st = st.add(Date.DAY, -1 * st.format('w'));
38359 var date = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38361 var firstOfMonth = date.getFirstDayOfMonth();
38362 var days = date.getDaysInMonth();
38364 var firstAdded = false;
38365 for (var i = 0; i < result.totalRecords ; i++) {
38366 //var d= st.add(Date.DAY, i);
38369 for(var w = 0 ; w < 7 ; w++){
38370 if(!firstAdded && firstOfMonth != w){
38377 var dd = (d > 0 && d < 10) ? "0"+d : d;
38378 row['weekday'+w] = String.format(
38379 '<span style="font-size: 16px;"><b>{0}</b></span>'+
38380 '<span class="course-edit-link" style="color:blue;" data-id="0" data-date="{1}"> Add New</span>',
38382 date.format('Y-m-')+dd
38385 if(typeof(_this.tdata[d]) != 'undefined'){
38386 Roo.each(_this.tdata[d], function(r){
38390 var desc = (r.productitem_id_descrip) ? r.productitem_id_descrip : '';
38391 if(r.parent_id*1>0){
38392 is_sub = (r.productitem_id_visible*1 < 1) ? 'de-act-sup-link' :'sub-link';
38395 if(r.productitem_id_visible*1 < 1 && r.parent_id*1 < 1){
38396 deactive = 'de-act-link';
38399 row['weekday'+w] += String.format(
38400 '<br /><span class="course-edit-link {3} {4}" qtip="{5}" data-id="{0}">{2} - {1}</span>',
38402 r.product_id_name, //1
38403 r.when_dt.format('h:ia'), //2
38413 // only do this if something added..
38415 result.records.push(_this.grid.dataSource.reader.newRow(row));
38419 // push it twice. (second one with an hour..
38423 this.fireEvent("load", this, o, o.request.arg);
38424 o.request.callback.call(o.request.scope, result, o.request.arg, true);
38426 sortInfo : {field: 'when_dt', direction : 'ASC' },
38428 xtype: 'HttpProxy',
38431 url : baseURL + '/Roo/Shop_course.php'
38434 xtype: 'JsonReader',
38451 'name': 'parent_id',
38455 'name': 'product_id',
38459 'name': 'productitem_id',
38477 click : function (_self, e)
38479 var sd = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38480 sd.setMonth(sd.getMonth()-1);
38481 _this.monthField.setValue(sd.format('Y-m-d'));
38482 _this.grid.ds.load({});
38488 xtype: 'Separator',
38492 xtype: 'MonthField',
38495 render : function (_self)
38497 _this.monthField = _self;
38498 // _this.monthField.set today
38500 select : function (combo, date)
38502 _this.grid.ds.load({});
38505 value : (function() { return new Date(); })()
38508 xtype: 'Separator',
38514 text : "Blue: in-active, green: in-active sup-event, red: de-active, purple: de-active sup-event"
38524 click : function (_self, e)
38526 var sd = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38527 sd.setMonth(sd.getMonth()+1);
38528 _this.monthField.setValue(sd.format('Y-m-d'));
38529 _this.grid.ds.load({});
38542 * Ext JS Library 1.1.1
38543 * Copyright(c) 2006-2007, Ext JS, LLC.
38545 * Originally Released Under LGPL - original licence link has changed is not relivant.
38548 * <script type="text/javascript">
38552 * @class Roo.LoadMask
38553 * A simple utility class for generically masking elements while loading data. If the element being masked has
38554 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
38555 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
38556 * element's UpdateManager load indicator and will be destroyed after the initial load.
38558 * Create a new LoadMask
38559 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
38560 * @param {Object} config The config object
38562 Roo.LoadMask = function(el, config){
38563 this.el = Roo.get(el);
38564 Roo.apply(this, config);
38566 this.store.on('beforeload', this.onBeforeLoad, this);
38567 this.store.on('load', this.onLoad, this);
38568 this.store.on('loadexception', this.onLoadException, this);
38569 this.removeMask = false;
38571 var um = this.el.getUpdateManager();
38572 um.showLoadIndicator = false; // disable the default indicator
38573 um.on('beforeupdate', this.onBeforeLoad, this);
38574 um.on('update', this.onLoad, this);
38575 um.on('failure', this.onLoad, this);
38576 this.removeMask = true;
38580 Roo.LoadMask.prototype = {
38582 * @cfg {Boolean} removeMask
38583 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
38584 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
38587 * @cfg {String} msg
38588 * The text to display in a centered loading message box (defaults to 'Loading...')
38590 msg : 'Loading...',
38592 * @cfg {String} msgCls
38593 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
38595 msgCls : 'x-mask-loading',
38598 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
38604 * Disables the mask to prevent it from being displayed
38606 disable : function(){
38607 this.disabled = true;
38611 * Enables the mask so that it can be displayed
38613 enable : function(){
38614 this.disabled = false;
38617 onLoadException : function()
38619 Roo.log(arguments);
38621 if (typeof(arguments[3]) != 'undefined') {
38622 Roo.MessageBox.alert("Error loading",arguments[3]);
38626 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
38627 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
38634 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
38637 onLoad : function()
38639 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
38643 onBeforeLoad : function(){
38644 if(!this.disabled){
38645 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
38650 destroy : function(){
38652 this.store.un('beforeload', this.onBeforeLoad, this);
38653 this.store.un('load', this.onLoad, this);
38654 this.store.un('loadexception', this.onLoadException, this);
38656 var um = this.el.getUpdateManager();
38657 um.un('beforeupdate', this.onBeforeLoad, this);
38658 um.un('update', this.onLoad, this);
38659 um.un('failure', this.onLoad, this);
38664 * Ext JS Library 1.1.1
38665 * Copyright(c) 2006-2007, Ext JS, LLC.
38667 * Originally Released Under LGPL - original licence link has changed is not relivant.
38670 * <script type="text/javascript">
38675 * @class Roo.XTemplate
38676 * @extends Roo.Template
38677 * Provides a template that can have nested templates for loops or conditionals. The syntax is:
38679 var t = new Roo.XTemplate(
38680 '<select name="{name}">',
38681 '<tpl for="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
38685 // then append, applying the master template values
38688 * Supported features:
38693 {a_variable} - output encoded.
38694 {a_variable.format:("Y-m-d")} - call a method on the variable
38695 {a_variable:raw} - unencoded output
38696 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
38697 {a_variable:this.method_on_template(...)} - call a method on the template object.
38702 <tpl for="a_variable or condition.."></tpl>
38703 <tpl if="a_variable or condition"></tpl>
38704 <tpl exec="some javascript"></tpl>
38705 <tpl name="named_template"></tpl> (experimental)
38707 <tpl for="."></tpl> - just iterate the property..
38708 <tpl for=".."></tpl> - iterates with the parent (probably the template)
38712 Roo.XTemplate = function()
38714 Roo.XTemplate.superclass.constructor.apply(this, arguments);
38721 Roo.extend(Roo.XTemplate, Roo.Template, {
38724 * The various sub templates
38729 * basic tag replacing syntax
38732 * // you can fake an object call by doing this
38736 re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
38739 * compile the template
38741 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
38744 compile: function()
38748 s = ['<tpl>', s, '</tpl>'].join('');
38750 var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
38751 nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
38752 ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
38753 execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
38754 namedRe = /^<tpl\b[^>]*?name="(\w+)"/, // named templates..
38759 while(true == !!(m = s.match(re))){
38760 var forMatch = m[0].match(nameRe),
38761 ifMatch = m[0].match(ifRe),
38762 execMatch = m[0].match(execRe),
38763 namedMatch = m[0].match(namedRe),
38768 name = forMatch && forMatch[1] ? forMatch[1] : '';
38771 // if - puts fn into test..
38772 exp = ifMatch && ifMatch[1] ? ifMatch[1] : null;
38774 fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
38779 // exec - calls a function... returns empty if true is returned.
38780 exp = execMatch && execMatch[1] ? execMatch[1] : null;
38782 exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
38790 case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
38791 case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
38792 default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
38795 var uid = namedMatch ? namedMatch[1] : id;
38799 id: namedMatch ? namedMatch[1] : id,
38806 s = s.replace(m[0], '');
38808 s = s.replace(m[0], '{xtpl'+ id + '}');
38813 for(var i = tpls.length-1; i >= 0; --i){
38814 this.compileTpl(tpls[i]);
38815 this.tpls[tpls[i].id] = tpls[i];
38817 this.master = tpls[tpls.length-1];
38821 * same as applyTemplate, except it's done to one of the subTemplates
38822 * when using named templates, you can do:
38824 * var str = pl.applySubTemplate('your-name', values);
38827 * @param {Number} id of the template
38828 * @param {Object} values to apply to template
38829 * @param {Object} parent (normaly the instance of this object)
38831 applySubTemplate : function(id, values, parent)
38835 var t = this.tpls[id];
38839 if(t.test && !t.test.call(this, values, parent)){
38843 Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");
38844 Roo.log(e.toString());
38850 if(t.exec && t.exec.call(this, values, parent)){
38854 Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");
38855 Roo.log(e.toString());
38860 var vs = t.target ? t.target.call(this, values, parent) : values;
38861 parent = t.target ? values : parent;
38862 if(t.target && vs instanceof Array){
38864 for(var i = 0, len = vs.length; i < len; i++){
38865 buf[buf.length] = t.compiled.call(this, vs[i], parent);
38867 return buf.join('');
38869 return t.compiled.call(this, vs, parent);
38871 Roo.log("Xtemplate.applySubTemplate : Exception thrown");
38872 Roo.log(e.toString());
38873 Roo.log(t.compiled);
38878 compileTpl : function(tpl)
38880 var fm = Roo.util.Format;
38881 var useF = this.disableFormats !== true;
38882 var sep = Roo.isGecko ? "+" : ",";
38883 var undef = function(str) {
38884 Roo.log("Property not found :" + str);
38888 var fn = function(m, name, format, args)
38890 //Roo.log(arguments);
38891 args = args ? args.replace(/\\'/g,"'") : args;
38892 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
38893 if (typeof(format) == 'undefined') {
38894 format= 'htmlEncode';
38896 if (format == 'raw' ) {
38900 if(name.substr(0, 4) == 'xtpl'){
38901 return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent)'+sep+"'";
38904 // build an array of options to determine if value is undefined..
38906 // basically get 'xxxx.yyyy' then do
38907 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
38908 // (function () { Roo.log("Property not found"); return ''; })() :
38913 Roo.each(name.split('.'), function(st) {
38914 lookfor += (lookfor.length ? '.': '') + st;
38915 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
38918 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
38921 if(format && useF){
38923 args = args ? ',' + args : "";
38925 if(format.substr(0, 5) != "this."){
38926 format = "fm." + format + '(';
38928 format = 'this.call("'+ format.substr(5) + '", ';
38932 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
38936 // called with xxyx.yuu:(test,test)
38938 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
38940 // raw.. - :raw modifier..
38941 return "'"+ sep + udef_st + name + ")"+sep+"'";
38945 // branched to use + in gecko and [].join() in others
38947 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
38948 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
38951 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
38952 body.push(tpl.body.replace(/(\r\n|\n)/g,
38953 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
38954 body.push("'].join('');};};");
38955 body = body.join('');
38958 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
38960 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
38966 applyTemplate : function(values){
38967 return this.master.compiled.call(this, values, {});
38968 //var s = this.subs;
38971 apply : function(){
38972 return this.applyTemplate.apply(this, arguments);
38977 Roo.XTemplate.from = function(el){
38978 el = Roo.getDom(el);
38979 return new Roo.XTemplate(el.value || el.innerHTML);