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 * using 'cn' the nested child reader read the child array into it's child stores.
790 * @param {Object} rec The record with a 'children array
792 loadDataFromChildren : function(rec)
794 this.loadData(this.reader.toLoadData(rec));
799 * Gets the number of cached records.
801 * <em>If using paging, this may not be the total size of the dataset. If the data object
802 * used by the Reader contains the dataset size, then the getTotalCount() function returns
803 * the data set size</em>
805 getCount : function(){
806 return this.data.length || 0;
810 * Gets the total number of records in the dataset as returned by the server.
812 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
813 * the dataset size</em>
815 getTotalCount : function(){
816 return this.totalLength || 0;
820 * Returns the sort state of the Store as an object with two properties:
822 field {String} The name of the field by which the Records are sorted
823 direction {String} The sort order, "ASC" or "DESC"
826 getSortState : function(){
827 return this.sortInfo;
831 applySort : function(){
832 if(this.sortInfo && !this.remoteSort){
833 var s = this.sortInfo, f = s.field;
834 var st = this.fields.get(f).sortType;
835 var fn = function(r1, r2){
836 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
837 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
839 this.data.sort(s.direction, fn);
840 if(this.snapshot && this.snapshot != this.data){
841 this.snapshot.sort(s.direction, fn);
847 * Sets the default sort column and order to be used by the next load operation.
848 * @param {String} fieldName The name of the field to sort by.
849 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
851 setDefaultSort : function(field, dir){
852 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
857 * If remote sorting is used, the sort is performed on the server, and the cache is
858 * reloaded. If local sorting is used, the cache is sorted internally.
859 * @param {String} fieldName The name of the field to sort by.
860 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
862 sort : function(fieldName, dir){
863 var f = this.fields.get(fieldName);
865 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
867 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
868 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
873 this.sortToggle[f.name] = dir;
874 this.sortInfo = {field: f.name, direction: dir};
875 if(!this.remoteSort){
877 this.fireEvent("datachanged", this);
879 this.load(this.lastOptions);
884 * Calls the specified function for each of the Records in the cache.
885 * @param {Function} fn The function to call. The Record is passed as the first parameter.
886 * Returning <em>false</em> aborts and exits the iteration.
887 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
889 each : function(fn, scope){
890 this.data.each(fn, scope);
894 * Gets all records modified since the last commit. Modified records are persisted across load operations
895 * (e.g., during paging).
896 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
898 getModifiedRecords : function(){
899 return this.modified;
903 createFilterFn : function(property, value, anyMatch){
904 if(!value.exec){ // not a regex
905 value = String(value);
906 if(value.length == 0){
909 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
912 return value.test(r.data[property]);
917 * Sums the value of <i>property</i> for each record between start and end and returns the result.
918 * @param {String} property A field on your records
919 * @param {Number} start The record index to start at (defaults to 0)
920 * @param {Number} end The last record index to include (defaults to length - 1)
921 * @return {Number} The sum
923 sum : function(property, start, end){
924 var rs = this.data.items, v = 0;
926 end = (end || end === 0) ? end : rs.length-1;
928 for(var i = start; i <= end; i++){
929 v += (rs[i].data[property] || 0);
935 * Filter the records by a specified property.
936 * @param {String} field A field on your records
937 * @param {String/RegExp} value Either a string that the field
938 * should start with or a RegExp to test against the field
939 * @param {Boolean} anyMatch True to match any part not just the beginning
941 filter : function(property, value, anyMatch){
942 var fn = this.createFilterFn(property, value, anyMatch);
943 return fn ? this.filterBy(fn) : this.clearFilter();
947 * Filter by a function. The specified function will be called with each
948 * record in this data source. If the function returns true the record is included,
949 * otherwise it is filtered.
950 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
951 * @param {Object} scope (optional) The scope of the function (defaults to this)
953 filterBy : function(fn, scope){
954 this.snapshot = this.snapshot || this.data;
955 this.data = this.queryBy(fn, scope||this);
956 this.fireEvent("datachanged", this);
960 * Query the records by a specified property.
961 * @param {String} field A field on your records
962 * @param {String/RegExp} value Either a string that the field
963 * should start with or a RegExp to test against the field
964 * @param {Boolean} anyMatch True to match any part not just the beginning
965 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
967 query : function(property, value, anyMatch){
968 var fn = this.createFilterFn(property, value, anyMatch);
969 return fn ? this.queryBy(fn) : this.data.clone();
973 * Query by a function. The specified function will be called with each
974 * record in this data source. If the function returns true the record is included
976 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
977 * @param {Object} scope (optional) The scope of the function (defaults to this)
978 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
980 queryBy : function(fn, scope){
981 var data = this.snapshot || this.data;
982 return data.filterBy(fn, scope||this);
986 * Collects unique values for a particular dataIndex from this store.
987 * @param {String} dataIndex The property to collect
988 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
989 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
990 * @return {Array} An array of the unique values
992 collect : function(dataIndex, allowNull, bypassFilter){
993 var d = (bypassFilter === true && this.snapshot) ?
994 this.snapshot.items : this.data.items;
995 var v, sv, r = [], l = {};
996 for(var i = 0, len = d.length; i < len; i++){
997 v = d[i].data[dataIndex];
999 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
1008 * Revert to a view of the Record cache with no filtering applied.
1009 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
1011 clearFilter : function(suppressEvent){
1012 if(this.snapshot && this.snapshot != this.data){
1013 this.data = this.snapshot;
1014 delete this.snapshot;
1015 if(suppressEvent !== true){
1016 this.fireEvent("datachanged", this);
1022 afterEdit : function(record){
1023 if(this.modified.indexOf(record) == -1){
1024 this.modified.push(record);
1026 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
1030 afterReject : function(record){
1031 this.modified.remove(record);
1032 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
1036 afterCommit : function(record){
1037 this.modified.remove(record);
1038 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
1042 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
1043 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
1045 commitChanges : function(){
1046 var m = this.modified.slice(0);
1048 for(var i = 0, len = m.length; i < len; i++){
1054 * Cancel outstanding changes on all changed records.
1056 rejectChanges : function(){
1057 var m = this.modified.slice(0);
1059 for(var i = 0, len = m.length; i < len; i++){
1064 onMetaChange : function(meta, rtype, o){
1065 this.recordType = rtype;
1066 this.fields = rtype.prototype.fields;
1067 delete this.snapshot;
1068 this.sortInfo = meta.sortInfo || this.sortInfo;
1070 this.fireEvent('metachange', this, this.reader.meta);
1073 moveIndex : function(data, type)
1075 var index = this.indexOf(data);
1077 var newIndex = index + type;
1081 this.insert(newIndex, data);
1086 * Ext JS Library 1.1.1
1087 * Copyright(c) 2006-2007, Ext JS, LLC.
1089 * Originally Released Under LGPL - original licence link has changed is not relivant.
1092 * <script type="text/javascript">
1096 * @class Roo.data.SimpleStore
1097 * @extends Roo.data.Store
1098 * Small helper class to make creating Stores from Array data easier.
1099 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
1100 * @cfg {Array} fields An array of field definition objects, or field name strings.
1101 * @cfg {Object} an existing reader (eg. copied from another store)
1102 * @cfg {Array} data The multi-dimensional array of data
1104 * @param {Object} config
1106 Roo.data.SimpleStore = function(config)
1108 Roo.data.SimpleStore.superclass.constructor.call(this, {
1110 reader: typeof(config.reader) != 'undefined' ? config.reader : new Roo.data.ArrayReader({
1113 Roo.data.Record.create(config.fields)
1115 proxy : new Roo.data.MemoryProxy(config.data)
1119 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
1121 * Ext JS Library 1.1.1
1122 * Copyright(c) 2006-2007, Ext JS, LLC.
1124 * Originally Released Under LGPL - original licence link has changed is not relivant.
1127 * <script type="text/javascript">
1132 * @extends Roo.data.Store
1133 * @class Roo.data.JsonStore
1134 * Small helper class to make creating Stores for JSON data easier. <br/>
1136 var store = new Roo.data.JsonStore({
1137 url: 'get-images.php',
1139 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
1142 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
1143 * JsonReader and HttpProxy (unless inline data is provided).</b>
1144 * @cfg {Array} fields An array of field definition objects, or field name strings.
1146 * @param {Object} config
1148 Roo.data.JsonStore = function(c){
1149 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
1150 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
1151 reader: new Roo.data.JsonReader(c, c.fields)
1154 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
1156 * Ext JS Library 1.1.1
1157 * Copyright(c) 2006-2007, Ext JS, LLC.
1159 * Originally Released Under LGPL - original licence link has changed is not relivant.
1162 * <script type="text/javascript">
1166 Roo.data.Field = function(config){
1167 if(typeof config == "string"){
1168 config = {name: config};
1170 Roo.apply(this, config);
1176 var st = Roo.data.SortTypes;
1177 // named sortTypes are supported, here we look them up
1178 if(typeof this.sortType == "string"){
1179 this.sortType = st[this.sortType];
1182 // set default sortType for strings and dates
1186 this.sortType = st.asUCString;
1189 this.sortType = st.asDate;
1192 this.sortType = st.none;
1197 var stripRe = /[\$,%]/g;
1199 // prebuilt conversion function for this field, instead of
1200 // switching every time we're reading a value
1202 var cv, dateFormat = this.dateFormat;
1207 cv = function(v){ return v; };
1210 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
1214 return v !== undefined && v !== null && v !== '' ?
1215 parseInt(String(v).replace(stripRe, ""), 10) : '';
1220 return v !== undefined && v !== null && v !== '' ?
1221 parseFloat(String(v).replace(stripRe, ""), 10) : '';
1226 cv = function(v){ return v === true || v === "true" || v == 1; };
1233 if(v instanceof Date){
1237 if(dateFormat == "timestamp"){
1238 return new Date(v*1000);
1240 return Date.parseDate(v, dateFormat);
1242 var parsed = Date.parse(v);
1243 return parsed ? new Date(parsed) : null;
1252 Roo.data.Field.prototype = {
1260 * Ext JS Library 1.1.1
1261 * Copyright(c) 2006-2007, Ext JS, LLC.
1263 * Originally Released Under LGPL - original licence link has changed is not relivant.
1266 * <script type="text/javascript">
1269 // Base class for reading structured data from a data source. This class is intended to be
1270 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
1273 * @class Roo.data.DataReader
1274 * Base class for reading structured data from a data source. This class is intended to be
1275 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
1278 Roo.data.DataReader = function(meta, recordType){
1282 this.recordType = recordType instanceof Array ?
1283 Roo.data.Record.create(recordType) : recordType;
1286 Roo.data.DataReader.prototype = {
1289 readerType : 'Data',
1291 * Create an empty record
1292 * @param {Object} data (optional) - overlay some values
1293 * @return {Roo.data.Record} record created.
1295 newRow : function(d) {
1297 this.recordType.prototype.fields.each(function(c) {
1299 case 'int' : da[c.name] = 0; break;
1300 case 'date' : da[c.name] = new Date(); break;
1301 case 'float' : da[c.name] = 0.0; break;
1302 case 'boolean' : da[c.name] = false; break;
1303 default : da[c.name] = ""; break;
1307 return new this.recordType(Roo.apply(da, d));
1313 * Ext JS Library 1.1.1
1314 * Copyright(c) 2006-2007, Ext JS, LLC.
1316 * Originally Released Under LGPL - original licence link has changed is not relivant.
1319 * <script type="text/javascript">
1323 * @class Roo.data.DataProxy
1324 * @extends Roo.data.Observable
1325 * This class is an abstract base class for implementations which provide retrieval of
1326 * unformatted data objects.<br>
1328 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
1329 * (of the appropriate type which knows how to parse the data object) to provide a block of
1330 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
1332 * Custom implementations must implement the load method as described in
1333 * {@link Roo.data.HttpProxy#load}.
1335 Roo.data.DataProxy = function(){
1339 * Fires before a network request is made to retrieve a data object.
1340 * @param {Object} This DataProxy object.
1341 * @param {Object} params The params parameter to the load function.
1346 * Fires before the load method's callback is called.
1347 * @param {Object} This DataProxy object.
1348 * @param {Object} o The data object.
1349 * @param {Object} arg The callback argument object passed to the load function.
1353 * @event loadexception
1354 * Fires if an Exception occurs during data retrieval.
1355 * @param {Object} This DataProxy object.
1356 * @param {Object} o The data object.
1357 * @param {Object} arg The callback argument object passed to the load function.
1358 * @param {Object} e The Exception.
1360 loadexception : true
1362 Roo.data.DataProxy.superclass.constructor.call(this);
1365 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
1368 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
1372 * Ext JS Library 1.1.1
1373 * Copyright(c) 2006-2007, Ext JS, LLC.
1375 * Originally Released Under LGPL - original licence link has changed is not relivant.
1378 * <script type="text/javascript">
1381 * @class Roo.data.MemoryProxy
1382 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
1383 * to the Reader when its load method is called.
1385 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
1387 Roo.data.MemoryProxy = function(data){
1391 Roo.data.MemoryProxy.superclass.constructor.call(this);
1395 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
1398 * Load data from the requested source (in this case an in-memory
1399 * data object passed to the constructor), read the data object into
1400 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
1401 * process that block using the passed callback.
1402 * @param {Object} params This parameter is not used by the MemoryProxy class.
1403 * @param {Roo.data.DataReader} reader The Reader object which converts the data
1404 * object into a block of Roo.data.Records.
1405 * @param {Function} callback The function into which to pass the block of Roo.data.records.
1406 * The function must be passed <ul>
1407 * <li>The Record block object</li>
1408 * <li>The "arg" argument from the load function</li>
1409 * <li>A boolean success indicator</li>
1411 * @param {Object} scope The scope in which to call the callback
1412 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
1414 load : function(params, reader, callback, scope, arg){
1415 params = params || {};
1418 result = reader.readRecords(params.data ? params.data :this.data);
1420 this.fireEvent("loadexception", this, arg, null, e);
1421 callback.call(scope, null, arg, false);
1424 callback.call(scope, result, arg, true);
1428 update : function(params, records){
1433 * Ext JS Library 1.1.1
1434 * Copyright(c) 2006-2007, Ext JS, LLC.
1436 * Originally Released Under LGPL - original licence link has changed is not relivant.
1439 * <script type="text/javascript">
1442 * @class Roo.data.HttpProxy
1443 * @extends Roo.data.DataProxy
1444 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
1445 * configured to reference a certain URL.<br><br>
1447 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
1448 * from which the running page was served.<br><br>
1450 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
1452 * Be aware that to enable the browser to parse an XML document, the server must set
1453 * the Content-Type header in the HTTP response to "text/xml".
1455 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
1456 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
1457 * will be used to make the request.
1459 Roo.data.HttpProxy = function(conn){
1460 Roo.data.HttpProxy.superclass.constructor.call(this);
1461 // is conn a conn config or a real conn?
1463 this.useAjax = !conn || !conn.events;
1467 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
1468 // thse are take from connection...
1471 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
1474 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
1475 * extra parameters to each request made by this object. (defaults to undefined)
1478 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
1479 * to each request made by this object. (defaults to undefined)
1482 * @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)
1485 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
1488 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
1494 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
1498 * Return the {@link Roo.data.Connection} object being used by this Proxy.
1499 * @return {Connection} The Connection object. This object may be used to subscribe to events on
1500 * a finer-grained basis than the DataProxy events.
1502 getConnection : function(){
1503 return this.useAjax ? Roo.Ajax : this.conn;
1507 * Load data from the configured {@link Roo.data.Connection}, read the data object into
1508 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
1509 * process that block using the passed callback.
1510 * @param {Object} params An object containing properties which are to be used as HTTP parameters
1511 * for the request to the remote server.
1512 * @param {Roo.data.DataReader} reader The Reader object which converts the data
1513 * object into a block of Roo.data.Records.
1514 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
1515 * The function must be passed <ul>
1516 * <li>The Record block object</li>
1517 * <li>The "arg" argument from the load function</li>
1518 * <li>A boolean success indicator</li>
1520 * @param {Object} scope The scope in which to call the callback
1521 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
1523 load : function(params, reader, callback, scope, arg){
1524 if(this.fireEvent("beforeload", this, params) !== false){
1526 params : params || {},
1528 callback : callback,
1533 callback : this.loadResponse,
1537 Roo.applyIf(o, this.conn);
1538 if(this.activeRequest){
1539 Roo.Ajax.abort(this.activeRequest);
1541 this.activeRequest = Roo.Ajax.request(o);
1543 this.conn.request(o);
1546 callback.call(scope||this, null, arg, false);
1551 loadResponse : function(o, success, response){
1552 delete this.activeRequest;
1554 this.fireEvent("loadexception", this, o, response);
1555 o.request.callback.call(o.request.scope, null, o.request.arg, false);
1560 result = o.reader.read(response);
1562 this.fireEvent("loadexception", this, o, response, e);
1563 o.request.callback.call(o.request.scope, null, o.request.arg, false);
1567 this.fireEvent("load", this, o, o.request.arg);
1568 o.request.callback.call(o.request.scope, result, o.request.arg, true);
1572 update : function(dataSet){
1577 updateResponse : function(dataSet){
1582 * Ext JS Library 1.1.1
1583 * Copyright(c) 2006-2007, Ext JS, LLC.
1585 * Originally Released Under LGPL - original licence link has changed is not relivant.
1588 * <script type="text/javascript">
1592 * @class Roo.data.ScriptTagProxy
1593 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
1594 * other than the originating domain of the running page.<br><br>
1596 * <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
1597 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
1599 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
1600 * source code that is used as the source inside a <script> tag.<br><br>
1602 * In order for the browser to process the returned data, the server must wrap the data object
1603 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
1604 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
1605 * depending on whether the callback name was passed:
1608 boolean scriptTag = false;
1609 String cb = request.getParameter("callback");
1612 response.setContentType("text/javascript");
1614 response.setContentType("application/x-json");
1616 Writer out = response.getWriter();
1618 out.write(cb + "(");
1620 out.print(dataBlock.toJsonString());
1627 * @param {Object} config A configuration object.
1629 Roo.data.ScriptTagProxy = function(config){
1630 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
1631 Roo.apply(this, config);
1632 this.head = document.getElementsByTagName("head")[0];
1635 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
1637 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
1639 * @cfg {String} url The URL from which to request the data object.
1642 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
1646 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
1647 * the server the name of the callback function set up by the load call to process the returned data object.
1648 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
1649 * javascript output which calls this named function passing the data object as its only parameter.
1651 callbackParam : "callback",
1653 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
1654 * name to the request.
1659 * Load data from the configured URL, read the data object into
1660 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
1661 * process that block using the passed callback.
1662 * @param {Object} params An object containing properties which are to be used as HTTP parameters
1663 * for the request to the remote server.
1664 * @param {Roo.data.DataReader} reader The Reader object which converts the data
1665 * object into a block of Roo.data.Records.
1666 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
1667 * The function must be passed <ul>
1668 * <li>The Record block object</li>
1669 * <li>The "arg" argument from the load function</li>
1670 * <li>A boolean success indicator</li>
1672 * @param {Object} scope The scope in which to call the callback
1673 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
1675 load : function(params, reader, callback, scope, arg){
1676 if(this.fireEvent("beforeload", this, params) !== false){
1678 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
1681 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
1683 url += "&_dc=" + (new Date().getTime());
1685 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
1688 cb : "stcCallback"+transId,
1689 scriptId : "stcScript"+transId,
1693 callback : callback,
1699 window[trans.cb] = function(o){
1700 conn.handleResponse(o, trans);
1703 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
1705 if(this.autoAbort !== false){
1709 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
1711 var script = document.createElement("script");
1712 script.setAttribute("src", url);
1713 script.setAttribute("type", "text/javascript");
1714 script.setAttribute("id", trans.scriptId);
1715 this.head.appendChild(script);
1719 callback.call(scope||this, null, arg, false);
1724 isLoading : function(){
1725 return this.trans ? true : false;
1729 * Abort the current server request.
1732 if(this.isLoading()){
1733 this.destroyTrans(this.trans);
1738 destroyTrans : function(trans, isLoaded){
1739 this.head.removeChild(document.getElementById(trans.scriptId));
1740 clearTimeout(trans.timeoutId);
1742 window[trans.cb] = undefined;
1744 delete window[trans.cb];
1747 // if hasn't been loaded, wait for load to remove it to prevent script error
1748 window[trans.cb] = function(){
1749 window[trans.cb] = undefined;
1751 delete window[trans.cb];
1758 handleResponse : function(o, trans){
1760 this.destroyTrans(trans, true);
1763 result = trans.reader.readRecords(o);
1765 this.fireEvent("loadexception", this, o, trans.arg, e);
1766 trans.callback.call(trans.scope||window, null, trans.arg, false);
1769 this.fireEvent("load", this, o, trans.arg);
1770 trans.callback.call(trans.scope||window, result, trans.arg, true);
1774 handleFailure : function(trans){
1776 this.destroyTrans(trans, false);
1777 this.fireEvent("loadexception", this, null, trans.arg);
1778 trans.callback.call(trans.scope||window, null, trans.arg, false);
1782 * Ext JS Library 1.1.1
1783 * Copyright(c) 2006-2007, Ext JS, LLC.
1785 * Originally Released Under LGPL - original licence link has changed is not relivant.
1788 * <script type="text/javascript">
1792 * @class Roo.data.JsonReader
1793 * @extends Roo.data.DataReader
1794 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
1795 * based on mappings in a provided Roo.data.Record constructor.
1797 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
1798 * in the reply previously.
1803 var RecordDef = Roo.data.Record.create([
1804 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
1805 {name: 'occupation'} // This field will use "occupation" as the mapping.
1807 var myReader = new Roo.data.JsonReader({
1808 totalProperty: "results", // The property which contains the total dataset size (optional)
1809 root: "rows", // The property which contains an Array of row objects
1810 id: "id" // The property within each row object that provides an ID for the record (optional)
1814 * This would consume a JSON file like this:
1816 { 'results': 2, 'rows': [
1817 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
1818 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
1821 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
1822 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
1823 * paged from the remote server.
1824 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
1825 * @cfg {String} root name of the property which contains the Array of row objects.
1826 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
1827 * @cfg {Array} fields Array of field definition objects
1829 * Create a new JsonReader
1830 * @param {Object} meta Metadata configuration options
1831 * @param {Object} recordType Either an Array of field definition objects,
1832 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
1834 Roo.data.JsonReader = function(meta, recordType){
1837 // set some defaults:
1839 totalProperty: 'total',
1840 successProperty : 'success',
1845 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
1847 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
1849 readerType : 'Json',
1852 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
1853 * Used by Store query builder to append _requestMeta to params.
1856 metaFromRemote : false,
1858 * This method is only used by a DataProxy which has retrieved data from a remote server.
1859 * @param {Object} response The XHR object which contains the JSON data in its responseText.
1860 * @return {Object} data A data block which is used by an Roo.data.Store object as
1861 * a cache of Roo.data.Records.
1863 read : function(response){
1864 var json = response.responseText;
1866 var o = /* eval:var:o */ eval("("+json+")");
1868 throw {message: "JsonReader.read: Json object not found"};
1874 this.metaFromRemote = true;
1875 this.meta = o.metaData;
1876 this.recordType = Roo.data.Record.create(o.metaData.fields);
1877 this.onMetaChange(this.meta, this.recordType, o);
1879 return this.readRecords(o);
1882 // private function a store will implement
1883 onMetaChange : function(meta, recordType, o){
1890 simpleAccess: function(obj, subsc) {
1897 getJsonAccessor: function(){
1899 return function(expr) {
1901 return(re.test(expr))
1902 ? new Function("obj", "return obj." + expr)
1912 * Create a data block containing Roo.data.Records from an XML document.
1913 * @param {Object} o An object which contains an Array of row objects in the property specified
1914 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
1915 * which contains the total size of the dataset.
1916 * @return {Object} data A data block which is used by an Roo.data.Store object as
1917 * a cache of Roo.data.Records.
1919 readRecords : function(o){
1921 * After any data loads, the raw JSON data is available for further custom processing.
1925 var s = this.meta, Record = this.recordType,
1926 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
1928 // Generate extraction functions for the totalProperty, the root, the id, and for each field
1930 if(s.totalProperty) {
1931 this.getTotal = this.getJsonAccessor(s.totalProperty);
1933 if(s.successProperty) {
1934 this.getSuccess = this.getJsonAccessor(s.successProperty);
1936 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
1938 var g = this.getJsonAccessor(s.id);
1939 this.getId = function(rec) {
1941 return (r === undefined || r === "") ? null : r;
1944 this.getId = function(){return null;};
1947 for(var jj = 0; jj < fl; jj++){
1949 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
1950 this.ef[jj] = this.getJsonAccessor(map);
1954 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
1955 if(s.totalProperty){
1956 var vt = parseInt(this.getTotal(o), 10);
1961 if(s.successProperty){
1962 var vs = this.getSuccess(o);
1963 if(vs === false || vs === 'false'){
1968 for(var i = 0; i < c; i++){
1971 var id = this.getId(n);
1972 for(var j = 0; j < fl; j++){
1974 var v = this.ef[j](n);
1976 Roo.log('missing convert for ' + f.name);
1980 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
1982 var record = new Record(values, id);
1984 records[i] = record;
1990 totalRecords : totalRecords
1993 // used when loading children.. @see loadDataFromChildren
1994 toLoadData: function(rec)
1996 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
1997 var data = typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
1998 return { data : data, total : data.length };
2003 * Ext JS Library 1.1.1
2004 * Copyright(c) 2006-2007, Ext JS, LLC.
2006 * Originally Released Under LGPL - original licence link has changed is not relivant.
2009 * <script type="text/javascript">
2013 * @class Roo.data.XmlReader
2014 * @extends Roo.data.DataReader
2015 * Data reader class to create an Array of {@link Roo.data.Record} objects from an XML document
2016 * based on mappings in a provided Roo.data.Record constructor.<br><br>
2018 * <em>Note that in order for the browser to parse a returned XML document, the Content-Type
2019 * header in the HTTP response must be set to "text/xml".</em>
2023 var RecordDef = Roo.data.Record.create([
2024 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
2025 {name: 'occupation'} // This field will use "occupation" as the mapping.
2027 var myReader = new Roo.data.XmlReader({
2028 totalRecords: "results", // The element which contains the total dataset size (optional)
2029 record: "row", // The repeated element which contains row information
2030 id: "id" // The element within the row that provides an ID for the record (optional)
2034 * This would consume an XML file like this:
2038 <results>2</results>
2041 <name>Bill</name>
2042 <occupation>Gardener</occupation>
2046 <name>Ben</name>
2047 <occupation>Horticulturalist</occupation>
2051 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
2052 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
2053 * paged from the remote server.
2054 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
2055 * @cfg {String} success The DomQuery path to the success attribute used by forms.
2056 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
2057 * a record identifier value.
2059 * Create a new XmlReader
2060 * @param {Object} meta Metadata configuration options
2061 * @param {Mixed} recordType The definition of the data record type to produce. This can be either a valid
2062 * Record subclass created with {@link Roo.data.Record#create}, or an array of objects with which to call
2063 * Roo.data.Record.create. See the {@link Roo.data.Record} class for more details.
2065 Roo.data.XmlReader = function(meta, recordType){
2067 Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields);
2069 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
2074 * This method is only used by a DataProxy which has retrieved data from a remote server.
2075 * @param {Object} response The XHR object which contains the parsed XML document. The response is expected
2076 * to contain a method called 'responseXML' that returns an XML document object.
2077 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
2078 * a cache of Roo.data.Records.
2080 read : function(response){
2081 var doc = response.responseXML;
2083 throw {message: "XmlReader.read: XML Document not available"};
2085 return this.readRecords(doc);
2089 * Create a data block containing Roo.data.Records from an XML document.
2090 * @param {Object} doc A parsed XML document.
2091 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
2092 * a cache of Roo.data.Records.
2094 readRecords : function(doc){
2096 * After any data loads/reads, the raw XML Document is available for further custom processing.
2100 var root = doc.documentElement || doc;
2101 var q = Roo.DomQuery;
2102 var recordType = this.recordType, fields = recordType.prototype.fields;
2103 var sid = this.meta.id;
2104 var totalRecords = 0, success = true;
2105 if(this.meta.totalRecords){
2106 totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
2109 if(this.meta.success){
2110 var sv = q.selectValue(this.meta.success, root, true);
2111 success = sv !== false && sv !== 'false';
2114 var ns = q.select(this.meta.record, root);
2115 for(var i = 0, len = ns.length; i < len; i++) {
2118 var id = sid ? q.selectValue(sid, n) : undefined;
2119 for(var j = 0, jlen = fields.length; j < jlen; j++){
2120 var f = fields.items[j];
2121 var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
2125 var record = new recordType(values, id);
2127 records[records.length] = record;
2133 totalRecords : totalRecords || records.length
2138 * Ext JS Library 1.1.1
2139 * Copyright(c) 2006-2007, Ext JS, LLC.
2141 * Originally Released Under LGPL - original licence link has changed is not relivant.
2144 * <script type="text/javascript">
2148 * @class Roo.data.ArrayReader
2149 * @extends Roo.data.DataReader
2150 * Data reader class to create an Array of Roo.data.Record objects from an Array.
2151 * Each element of that Array represents a row of data fields. The
2152 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
2153 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
2157 var RecordDef = Roo.data.Record.create([
2158 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
2159 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
2161 var myReader = new Roo.data.ArrayReader({
2162 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
2166 * This would consume an Array like this:
2168 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
2172 * Create a new JsonReader
2173 * @param {Object} meta Metadata configuration options.
2174 * @param {Object|Array} recordType Either an Array of field definition objects
2176 * @cfg {Array} fields Array of field definition objects
2177 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
2178 * as specified to {@link Roo.data.Record#create},
2179 * or an {@link Roo.data.Record} object
2182 * created using {@link Roo.data.Record#create}.
2184 Roo.data.ArrayReader = function(meta, recordType)
2186 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType||meta.fields);
2189 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
2192 * Create a data block containing Roo.data.Records from an XML document.
2193 * @param {Object} o An Array of row objects which represents the dataset.
2194 * @return {Object} A data block which is used by an {@link Roo.data.Store} object as
2195 * a cache of Roo.data.Records.
2197 readRecords : function(o)
2199 var sid = this.meta ? this.meta.id : null;
2200 var recordType = this.recordType, fields = recordType.prototype.fields;
2203 for(var i = 0; i < root.length; i++){
2206 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
2207 for(var j = 0, jlen = fields.length; j < jlen; j++){
2208 var f = fields.items[j];
2209 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
2210 var v = n[k] !== undefined ? n[k] : f.defaultValue;
2214 var record = new recordType(values, id);
2216 records[records.length] = record;
2220 totalRecords : records.length
2223 // used when loading children.. @see loadDataFromChildren
2224 toLoadData: function(rec)
2226 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
2227 return typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
2234 * Ext JS Library 1.1.1
2235 * Copyright(c) 2006-2007, Ext JS, LLC.
2237 * Originally Released Under LGPL - original licence link has changed is not relivant.
2240 * <script type="text/javascript">
2245 * @class Roo.data.Tree
2246 * @extends Roo.util.Observable
2247 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
2248 * in the tree have most standard DOM functionality.
2250 * @param {Node} root (optional) The root node
2252 Roo.data.Tree = function(root){
2255 * The root node for this tree
2260 this.setRootNode(root);
2265 * Fires when a new child node is appended to a node in this tree.
2266 * @param {Tree} tree The owner tree
2267 * @param {Node} parent The parent node
2268 * @param {Node} node The newly appended node
2269 * @param {Number} index The index of the newly appended node
2274 * Fires when a child node is removed from a node in this tree.
2275 * @param {Tree} tree The owner tree
2276 * @param {Node} parent The parent node
2277 * @param {Node} node The child node removed
2282 * Fires when a node is moved to a new location in the tree
2283 * @param {Tree} tree The owner tree
2284 * @param {Node} node The node moved
2285 * @param {Node} oldParent The old parent of this node
2286 * @param {Node} newParent The new parent of this node
2287 * @param {Number} index The index it was moved to
2292 * Fires when a new child node is inserted in a node in this tree.
2293 * @param {Tree} tree The owner tree
2294 * @param {Node} parent The parent node
2295 * @param {Node} node The child node inserted
2296 * @param {Node} refNode The child node the node was inserted before
2300 * @event beforeappend
2301 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
2302 * @param {Tree} tree The owner tree
2303 * @param {Node} parent The parent node
2304 * @param {Node} node The child node to be appended
2306 "beforeappend" : true,
2308 * @event beforeremove
2309 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
2310 * @param {Tree} tree The owner tree
2311 * @param {Node} parent The parent node
2312 * @param {Node} node The child node to be removed
2314 "beforeremove" : true,
2317 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
2318 * @param {Tree} tree The owner tree
2319 * @param {Node} node The node being moved
2320 * @param {Node} oldParent The parent of the node
2321 * @param {Node} newParent The new parent the node is moving to
2322 * @param {Number} index The index it is being moved to
2324 "beforemove" : true,
2326 * @event beforeinsert
2327 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
2328 * @param {Tree} tree The owner tree
2329 * @param {Node} parent The parent node
2330 * @param {Node} node The child node to be inserted
2331 * @param {Node} refNode The child node the node is being inserted before
2333 "beforeinsert" : true
2336 Roo.data.Tree.superclass.constructor.call(this);
2339 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
2342 proxyNodeEvent : function(){
2343 return this.fireEvent.apply(this, arguments);
2347 * Returns the root node for this tree.
2350 getRootNode : function(){
2355 * Sets the root node for this tree.
2356 * @param {Node} node
2359 setRootNode : function(node){
2361 node.ownerTree = this;
2363 this.registerNode(node);
2368 * Gets a node in this tree by its id.
2369 * @param {String} id
2372 getNodeById : function(id){
2373 return this.nodeHash[id];
2376 registerNode : function(node){
2377 this.nodeHash[node.id] = node;
2380 unregisterNode : function(node){
2381 delete this.nodeHash[node.id];
2384 toString : function(){
2385 return "[Tree"+(this.id?" "+this.id:"")+"]";
2390 * @class Roo.data.Node
2391 * @extends Roo.util.Observable
2392 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
2393 * @cfg {String} id The id for this node. If one is not specified, one is generated.
2395 * @param {Object} attributes The attributes/config for the node
2397 Roo.data.Node = function(attributes){
2399 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
2402 this.attributes = attributes || {};
2403 this.leaf = this.attributes.leaf;
2405 * The node id. @type String
2407 this.id = this.attributes.id;
2409 this.id = Roo.id(null, "ynode-");
2410 this.attributes.id = this.id;
2415 * All child nodes of this node. @type Array
2417 this.childNodes = [];
2418 if(!this.childNodes.indexOf){ // indexOf is a must
2419 this.childNodes.indexOf = function(o){
2420 for(var i = 0, len = this.length; i < len; i++){
2429 * The parent node for this node. @type Node
2431 this.parentNode = null;
2433 * The first direct child node of this node, or null if this node has no child nodes. @type Node
2435 this.firstChild = null;
2437 * The last direct child node of this node, or null if this node has no child nodes. @type Node
2439 this.lastChild = null;
2441 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
2443 this.previousSibling = null;
2445 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
2447 this.nextSibling = null;
2452 * Fires when a new child node is appended
2453 * @param {Tree} tree The owner tree
2454 * @param {Node} this This node
2455 * @param {Node} node The newly appended node
2456 * @param {Number} index The index of the newly appended node
2461 * Fires when a child node is removed
2462 * @param {Tree} tree The owner tree
2463 * @param {Node} this This node
2464 * @param {Node} node The removed node
2469 * Fires when this node is moved to a new location in the tree
2470 * @param {Tree} tree The owner tree
2471 * @param {Node} this This node
2472 * @param {Node} oldParent The old parent of this node
2473 * @param {Node} newParent The new parent of this node
2474 * @param {Number} index The index it was moved to
2479 * Fires when a new child node is inserted.
2480 * @param {Tree} tree The owner tree
2481 * @param {Node} this This node
2482 * @param {Node} node The child node inserted
2483 * @param {Node} refNode The child node the node was inserted before
2487 * @event beforeappend
2488 * Fires before a new child is appended, return false to cancel the append.
2489 * @param {Tree} tree The owner tree
2490 * @param {Node} this This node
2491 * @param {Node} node The child node to be appended
2493 "beforeappend" : true,
2495 * @event beforeremove
2496 * Fires before a child is removed, return false to cancel the remove.
2497 * @param {Tree} tree The owner tree
2498 * @param {Node} this This node
2499 * @param {Node} node The child node to be removed
2501 "beforeremove" : true,
2504 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
2505 * @param {Tree} tree The owner tree
2506 * @param {Node} this This node
2507 * @param {Node} oldParent The parent of this node
2508 * @param {Node} newParent The new parent this node is moving to
2509 * @param {Number} index The index it is being moved to
2511 "beforemove" : true,
2513 * @event beforeinsert
2514 * Fires before a new child is inserted, return false to cancel the insert.
2515 * @param {Tree} tree The owner tree
2516 * @param {Node} this This node
2517 * @param {Node} node The child node to be inserted
2518 * @param {Node} refNode The child node the node is being inserted before
2520 "beforeinsert" : true
2522 this.listeners = this.attributes.listeners;
2523 Roo.data.Node.superclass.constructor.call(this);
2526 Roo.extend(Roo.data.Node, Roo.util.Observable, {
2527 fireEvent : function(evtName){
2528 // first do standard event for this node
2529 if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
2532 // then bubble it up to the tree if the event wasn't cancelled
2533 var ot = this.getOwnerTree();
2535 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
2543 * Returns true if this node is a leaf
2546 isLeaf : function(){
2547 return this.leaf === true;
2551 setFirstChild : function(node){
2552 this.firstChild = node;
2556 setLastChild : function(node){
2557 this.lastChild = node;
2562 * Returns true if this node is the last child of its parent
2565 isLast : function(){
2566 return (!this.parentNode ? true : this.parentNode.lastChild == this);
2570 * Returns true if this node is the first child of its parent
2573 isFirst : function(){
2574 return (!this.parentNode ? true : this.parentNode.firstChild == this);
2577 hasChildNodes : function(){
2578 return !this.isLeaf() && this.childNodes.length > 0;
2582 * Insert node(s) as the last child node of this node.
2583 * @param {Node/Array} node The node or Array of nodes to append
2584 * @return {Node} The appended node if single append, or null if an array was passed
2586 appendChild : function(node){
2588 if(node instanceof Array){
2590 }else if(arguments.length > 1){
2594 // if passed an array or multiple args do them one by one
2596 for(var i = 0, len = multi.length; i < len; i++) {
2597 this.appendChild(multi[i]);
2600 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
2603 var index = this.childNodes.length;
2604 var oldParent = node.parentNode;
2605 // it's a move, make sure we move it cleanly
2607 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
2610 oldParent.removeChild(node);
2613 index = this.childNodes.length;
2615 this.setFirstChild(node);
2617 this.childNodes.push(node);
2618 node.parentNode = this;
2619 var ps = this.childNodes[index-1];
2621 node.previousSibling = ps;
2622 ps.nextSibling = node;
2624 node.previousSibling = null;
2626 node.nextSibling = null;
2627 this.setLastChild(node);
2628 node.setOwnerTree(this.getOwnerTree());
2629 this.fireEvent("append", this.ownerTree, this, node, index);
2630 if(this.ownerTree) {
2631 this.ownerTree.fireEvent("appendnode", this, node, index);
2634 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
2641 * Removes a child node from this node.
2642 * @param {Node} node The node to remove
2643 * @return {Node} The removed node
2645 removeChild : function(node){
2646 var index = this.childNodes.indexOf(node);
2650 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
2654 // remove it from childNodes collection
2655 this.childNodes.splice(index, 1);
2658 if(node.previousSibling){
2659 node.previousSibling.nextSibling = node.nextSibling;
2661 if(node.nextSibling){
2662 node.nextSibling.previousSibling = node.previousSibling;
2665 // update child refs
2666 if(this.firstChild == node){
2667 this.setFirstChild(node.nextSibling);
2669 if(this.lastChild == node){
2670 this.setLastChild(node.previousSibling);
2673 node.setOwnerTree(null);
2674 // clear any references from the node
2675 node.parentNode = null;
2676 node.previousSibling = null;
2677 node.nextSibling = null;
2678 this.fireEvent("remove", this.ownerTree, this, node);
2683 * Inserts the first node before the second node in this nodes childNodes collection.
2684 * @param {Node} node The node to insert
2685 * @param {Node} refNode The node to insert before (if null the node is appended)
2686 * @return {Node} The inserted node
2688 insertBefore : function(node, refNode){
2689 if(!refNode){ // like standard Dom, refNode can be null for append
2690 return this.appendChild(node);
2693 if(node == refNode){
2697 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
2700 var index = this.childNodes.indexOf(refNode);
2701 var oldParent = node.parentNode;
2702 var refIndex = index;
2704 // when moving internally, indexes will change after remove
2705 if(oldParent == this && this.childNodes.indexOf(node) < index){
2709 // it's a move, make sure we move it cleanly
2711 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
2714 oldParent.removeChild(node);
2717 this.setFirstChild(node);
2719 this.childNodes.splice(refIndex, 0, node);
2720 node.parentNode = this;
2721 var ps = this.childNodes[refIndex-1];
2723 node.previousSibling = ps;
2724 ps.nextSibling = node;
2726 node.previousSibling = null;
2728 node.nextSibling = refNode;
2729 refNode.previousSibling = node;
2730 node.setOwnerTree(this.getOwnerTree());
2731 this.fireEvent("insert", this.ownerTree, this, node, refNode);
2733 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
2739 * Returns the child node at the specified index.
2740 * @param {Number} index
2743 item : function(index){
2744 return this.childNodes[index];
2748 * Replaces one child node in this node with another.
2749 * @param {Node} newChild The replacement node
2750 * @param {Node} oldChild The node to replace
2751 * @return {Node} The replaced node
2753 replaceChild : function(newChild, oldChild){
2754 this.insertBefore(newChild, oldChild);
2755 this.removeChild(oldChild);
2760 * Returns the index of a child node
2761 * @param {Node} node
2762 * @return {Number} The index of the node or -1 if it was not found
2764 indexOf : function(child){
2765 return this.childNodes.indexOf(child);
2769 * Returns the tree this node is in.
2772 getOwnerTree : function(){
2773 // if it doesn't have one, look for one
2774 if(!this.ownerTree){
2778 this.ownerTree = p.ownerTree;
2784 return this.ownerTree;
2788 * Returns depth of this node (the root node has a depth of 0)
2791 getDepth : function(){
2794 while(p.parentNode){
2802 setOwnerTree : function(tree){
2803 // if it's move, we need to update everyone
2804 if(tree != this.ownerTree){
2806 this.ownerTree.unregisterNode(this);
2808 this.ownerTree = tree;
2809 var cs = this.childNodes;
2810 for(var i = 0, len = cs.length; i < len; i++) {
2811 cs[i].setOwnerTree(tree);
2814 tree.registerNode(this);
2820 * Returns the path for this node. The path can be used to expand or select this node programmatically.
2821 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
2822 * @return {String} The path
2824 getPath : function(attr){
2825 attr = attr || "id";
2826 var p = this.parentNode;
2827 var b = [this.attributes[attr]];
2829 b.unshift(p.attributes[attr]);
2832 var sep = this.getOwnerTree().pathSeparator;
2833 return sep + b.join(sep);
2837 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
2838 * function call will be the scope provided or the current node. The arguments to the function
2839 * will be the args provided or the current node. If the function returns false at any point,
2840 * the bubble is stopped.
2841 * @param {Function} fn The function to call
2842 * @param {Object} scope (optional) The scope of the function (defaults to current node)
2843 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
2845 bubble : function(fn, scope, args){
2848 if(fn.call(scope || p, args || p) === false){
2856 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
2857 * function call will be the scope provided or the current node. The arguments to the function
2858 * will be the args provided or the current node. If the function returns false at any point,
2859 * the cascade is stopped on that branch.
2860 * @param {Function} fn The function to call
2861 * @param {Object} scope (optional) The scope of the function (defaults to current node)
2862 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
2864 cascade : function(fn, scope, args){
2865 if(fn.call(scope || this, args || this) !== false){
2866 var cs = this.childNodes;
2867 for(var i = 0, len = cs.length; i < len; i++) {
2868 cs[i].cascade(fn, scope, args);
2874 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
2875 * function call will be the scope provided or the current node. The arguments to the function
2876 * will be the args provided or the current node. If the function returns false at any point,
2877 * the iteration stops.
2878 * @param {Function} fn The function to call
2879 * @param {Object} scope (optional) The scope of the function (defaults to current node)
2880 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
2882 eachChild : function(fn, scope, args){
2883 var cs = this.childNodes;
2884 for(var i = 0, len = cs.length; i < len; i++) {
2885 if(fn.call(scope || this, args || cs[i]) === false){
2892 * Finds the first child that has the attribute with the specified value.
2893 * @param {String} attribute The attribute name
2894 * @param {Mixed} value The value to search for
2895 * @return {Node} The found child or null if none was found
2897 findChild : function(attribute, value){
2898 var cs = this.childNodes;
2899 for(var i = 0, len = cs.length; i < len; i++) {
2900 if(cs[i].attributes[attribute] == value){
2908 * Finds the first child by a custom function. The child matches if the function passed
2910 * @param {Function} fn
2911 * @param {Object} scope (optional)
2912 * @return {Node} The found child or null if none was found
2914 findChildBy : function(fn, scope){
2915 var cs = this.childNodes;
2916 for(var i = 0, len = cs.length; i < len; i++) {
2917 if(fn.call(scope||cs[i], cs[i]) === true){
2925 * Sorts this nodes children using the supplied sort function
2926 * @param {Function} fn
2927 * @param {Object} scope (optional)
2929 sort : function(fn, scope){
2930 var cs = this.childNodes;
2931 var len = cs.length;
2933 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
2935 for(var i = 0; i < len; i++){
2937 n.previousSibling = cs[i-1];
2938 n.nextSibling = cs[i+1];
2940 this.setFirstChild(n);
2943 this.setLastChild(n);
2950 * Returns true if this node is an ancestor (at any point) of the passed node.
2951 * @param {Node} node
2954 contains : function(node){
2955 return node.isAncestor(this);
2959 * Returns true if the passed node is an ancestor (at any point) of this node.
2960 * @param {Node} node
2963 isAncestor : function(node){
2964 var p = this.parentNode;
2974 toString : function(){
2975 return "[Node"+(this.id?" "+this.id:"")+"]";
2979 * Ext JS Library 1.1.1
2980 * Copyright(c) 2006-2007, Ext JS, LLC.
2982 * Originally Released Under LGPL - original licence link has changed is not relivant.
2985 * <script type="text/javascript">
2991 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
2992 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
2993 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
2995 * Create a new Shadow
2996 * @param {Object} config The config object
2998 Roo.Shadow = function(config){
2999 Roo.apply(this, config);
3000 if(typeof this.mode != "string"){
3001 this.mode = this.defaultMode;
3003 var o = this.offset, a = {h: 0};
3004 var rad = Math.floor(this.offset/2);
3005 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
3011 a.l -= this.offset + rad;
3012 a.t -= this.offset + rad;
3023 a.l -= (this.offset - rad);
3024 a.t -= this.offset + rad;
3026 a.w -= (this.offset - rad)*2;
3037 a.l -= (this.offset - rad);
3038 a.t -= (this.offset - rad);
3040 a.w -= (this.offset + rad + 1);
3041 a.h -= (this.offset + rad);
3050 Roo.Shadow.prototype = {
3052 * @cfg {String} mode
3053 * The shadow display mode. Supports the following options:<br />
3054 * sides: Shadow displays on both sides and bottom only<br />
3055 * frame: Shadow displays equally on all four sides<br />
3056 * drop: Traditional bottom-right drop shadow (default)
3059 * @cfg {String} offset
3060 * The number of pixels to offset the shadow from the element (defaults to 4)
3065 defaultMode: "drop",
3068 * Displays the shadow under the target element
3069 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
3071 show : function(target){
3072 target = Roo.get(target);
3074 this.el = Roo.Shadow.Pool.pull();
3075 if(this.el.dom.nextSibling != target.dom){
3076 this.el.insertBefore(target);
3079 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
3081 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
3084 target.getLeft(true),
3085 target.getTop(true),
3089 this.el.dom.style.display = "block";
3093 * Returns true if the shadow is visible, else false
3095 isVisible : function(){
3096 return this.el ? true : false;
3100 * Direct alignment when values are already available. Show must be called at least once before
3101 * calling this method to ensure it is initialized.
3102 * @param {Number} left The target element left position
3103 * @param {Number} top The target element top position
3104 * @param {Number} width The target element width
3105 * @param {Number} height The target element height
3107 realign : function(l, t, w, h){
3111 var a = this.adjusts, d = this.el.dom, s = d.style;
3113 s.left = (l+a.l)+"px";
3114 s.top = (t+a.t)+"px";
3115 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
3117 if(s.width != sws || s.height != shs){
3121 var cn = d.childNodes;
3122 var sww = Math.max(0, (sw-12))+"px";
3123 cn[0].childNodes[1].style.width = sww;
3124 cn[1].childNodes[1].style.width = sww;
3125 cn[2].childNodes[1].style.width = sww;
3126 cn[1].style.height = Math.max(0, (sh-12))+"px";
3136 this.el.dom.style.display = "none";
3137 Roo.Shadow.Pool.push(this.el);
3143 * Adjust the z-index of this shadow
3144 * @param {Number} zindex The new z-index
3146 setZIndex : function(z){
3149 this.el.setStyle("z-index", z);
3154 // Private utility class that manages the internal Shadow cache
3155 Roo.Shadow.Pool = function(){
3157 var markup = Roo.isIE ?
3158 '<div class="x-ie-shadow"></div>' :
3159 '<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>';
3164 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
3165 sh.autoBoxAdjust = false;
3170 push : function(sh){
3176 * Ext JS Library 1.1.1
3177 * Copyright(c) 2006-2007, Ext JS, LLC.
3179 * Originally Released Under LGPL - original licence link has changed is not relivant.
3182 * <script type="text/javascript">
3187 * @class Roo.SplitBar
3188 * @extends Roo.util.Observable
3189 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
3193 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
3194 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
3195 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
3196 split.minSize = 100;
3197 split.maxSize = 600;
3198 split.animate = true;
3199 split.on('moved', splitterMoved);
3202 * Create a new SplitBar
3203 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
3204 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
3205 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
3206 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
3207 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
3208 position of the SplitBar).
3210 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
3213 this.el = Roo.get(dragElement, true);
3214 this.el.dom.unselectable = "on";
3216 this.resizingEl = Roo.get(resizingElement, true);
3220 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
3221 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
3224 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
3227 * The minimum size of the resizing element. (Defaults to 0)
3233 * The maximum size of the resizing element. (Defaults to 2000)
3236 this.maxSize = 2000;
3239 * Whether to animate the transition to the new size
3242 this.animate = false;
3245 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
3248 this.useShim = false;
3255 this.proxy = Roo.SplitBar.createProxy(this.orientation);
3257 this.proxy = Roo.get(existingProxy).dom;
3260 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
3263 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
3266 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
3269 this.dragSpecs = {};
3272 * @private The adapter to use to positon and resize elements
3274 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
3275 this.adapter.init(this);
3277 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3279 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
3280 this.el.addClass("x-splitbar-h");
3283 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
3284 this.el.addClass("x-splitbar-v");
3290 * Fires when the splitter is moved (alias for {@link #event-moved})
3291 * @param {Roo.SplitBar} this
3292 * @param {Number} newSize the new width or height
3297 * Fires when the splitter is moved
3298 * @param {Roo.SplitBar} this
3299 * @param {Number} newSize the new width or height
3303 * @event beforeresize
3304 * Fires before the splitter is dragged
3305 * @param {Roo.SplitBar} this
3307 "beforeresize" : true,
3309 "beforeapply" : true
3312 Roo.util.Observable.call(this);
3315 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
3316 onStartProxyDrag : function(x, y){
3317 this.fireEvent("beforeresize", this);
3319 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
3321 o.enableDisplayMode("block");
3322 // all splitbars share the same overlay
3323 Roo.SplitBar.prototype.overlay = o;
3325 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
3326 this.overlay.show();
3327 Roo.get(this.proxy).setDisplayed("block");
3328 var size = this.adapter.getElementSize(this);
3329 this.activeMinSize = this.getMinimumSize();;
3330 this.activeMaxSize = this.getMaximumSize();;
3331 var c1 = size - this.activeMinSize;
3332 var c2 = Math.max(this.activeMaxSize - size, 0);
3333 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3334 this.dd.resetConstraints();
3335 this.dd.setXConstraint(
3336 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
3337 this.placement == Roo.SplitBar.LEFT ? c2 : c1
3339 this.dd.setYConstraint(0, 0);
3341 this.dd.resetConstraints();
3342 this.dd.setXConstraint(0, 0);
3343 this.dd.setYConstraint(
3344 this.placement == Roo.SplitBar.TOP ? c1 : c2,
3345 this.placement == Roo.SplitBar.TOP ? c2 : c1
3348 this.dragSpecs.startSize = size;
3349 this.dragSpecs.startPoint = [x, y];
3350 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
3354 * @private Called after the drag operation by the DDProxy
3356 onEndProxyDrag : function(e){
3357 Roo.get(this.proxy).setDisplayed(false);
3358 var endPoint = Roo.lib.Event.getXY(e);
3360 this.overlay.hide();
3363 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3364 newSize = this.dragSpecs.startSize +
3365 (this.placement == Roo.SplitBar.LEFT ?
3366 endPoint[0] - this.dragSpecs.startPoint[0] :
3367 this.dragSpecs.startPoint[0] - endPoint[0]
3370 newSize = this.dragSpecs.startSize +
3371 (this.placement == Roo.SplitBar.TOP ?
3372 endPoint[1] - this.dragSpecs.startPoint[1] :
3373 this.dragSpecs.startPoint[1] - endPoint[1]
3376 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
3377 if(newSize != this.dragSpecs.startSize){
3378 if(this.fireEvent('beforeapply', this, newSize) !== false){
3379 this.adapter.setElementSize(this, newSize);
3380 this.fireEvent("moved", this, newSize);
3381 this.fireEvent("resize", this, newSize);
3387 * Get the adapter this SplitBar uses
3388 * @return The adapter object
3390 getAdapter : function(){
3391 return this.adapter;
3395 * Set the adapter this SplitBar uses
3396 * @param {Object} adapter A SplitBar adapter object
3398 setAdapter : function(adapter){
3399 this.adapter = adapter;
3400 this.adapter.init(this);
3404 * Gets the minimum size for the resizing element
3405 * @return {Number} The minimum size
3407 getMinimumSize : function(){
3408 return this.minSize;
3412 * Sets the minimum size for the resizing element
3413 * @param {Number} minSize The minimum size
3415 setMinimumSize : function(minSize){
3416 this.minSize = minSize;
3420 * Gets the maximum size for the resizing element
3421 * @return {Number} The maximum size
3423 getMaximumSize : function(){
3424 return this.maxSize;
3428 * Sets the maximum size for the resizing element
3429 * @param {Number} maxSize The maximum size
3431 setMaximumSize : function(maxSize){
3432 this.maxSize = maxSize;
3436 * Sets the initialize size for the resizing element
3437 * @param {Number} size The initial size
3439 setCurrentSize : function(size){
3440 var oldAnimate = this.animate;
3441 this.animate = false;
3442 this.adapter.setElementSize(this, size);
3443 this.animate = oldAnimate;
3447 * Destroy this splitbar.
3448 * @param {Boolean} removeEl True to remove the element
3450 destroy : function(removeEl){
3455 this.proxy.parentNode.removeChild(this.proxy);
3463 * @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.
3465 Roo.SplitBar.createProxy = function(dir){
3466 var proxy = new Roo.Element(document.createElement("div"));
3467 proxy.unselectable();
3468 var cls = 'x-splitbar-proxy';
3469 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
3470 document.body.appendChild(proxy.dom);
3475 * @class Roo.SplitBar.BasicLayoutAdapter
3476 * Default Adapter. It assumes the splitter and resizing element are not positioned
3477 * elements and only gets/sets the width of the element. Generally used for table based layouts.
3479 Roo.SplitBar.BasicLayoutAdapter = function(){
3482 Roo.SplitBar.BasicLayoutAdapter.prototype = {
3483 // do nothing for now
3488 * Called before drag operations to get the current size of the resizing element.
3489 * @param {Roo.SplitBar} s The SplitBar using this adapter
3491 getElementSize : function(s){
3492 if(s.orientation == Roo.SplitBar.HORIZONTAL){
3493 return s.resizingEl.getWidth();
3495 return s.resizingEl.getHeight();
3500 * Called after drag operations to set the size of the resizing element.
3501 * @param {Roo.SplitBar} s The SplitBar using this adapter
3502 * @param {Number} newSize The new size to set
3503 * @param {Function} onComplete A function to be invoked when resizing is complete
3505 setElementSize : function(s, newSize, onComplete){
3506 if(s.orientation == Roo.SplitBar.HORIZONTAL){
3508 s.resizingEl.setWidth(newSize);
3510 onComplete(s, newSize);
3513 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
3518 s.resizingEl.setHeight(newSize);
3520 onComplete(s, newSize);
3523 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
3530 *@class Roo.SplitBar.AbsoluteLayoutAdapter
3531 * @extends Roo.SplitBar.BasicLayoutAdapter
3532 * Adapter that moves the splitter element to align with the resized sizing element.
3533 * Used with an absolute positioned SplitBar.
3534 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
3535 * document.body, make sure you assign an id to the body element.
3537 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
3538 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
3539 this.container = Roo.get(container);
3542 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
3547 getElementSize : function(s){
3548 return this.basic.getElementSize(s);
3551 setElementSize : function(s, newSize, onComplete){
3552 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
3555 moveSplitter : function(s){
3556 var yes = Roo.SplitBar;
3557 switch(s.placement){
3559 s.el.setX(s.resizingEl.getRight());
3562 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
3565 s.el.setY(s.resizingEl.getBottom());
3568 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
3575 * Orientation constant - Create a vertical SplitBar
3579 Roo.SplitBar.VERTICAL = 1;
3582 * Orientation constant - Create a horizontal SplitBar
3586 Roo.SplitBar.HORIZONTAL = 2;
3589 * Placement constant - The resizing element is to the left of the splitter element
3593 Roo.SplitBar.LEFT = 1;
3596 * Placement constant - The resizing element is to the right of the splitter element
3600 Roo.SplitBar.RIGHT = 2;
3603 * Placement constant - The resizing element is positioned above the splitter element
3607 Roo.SplitBar.TOP = 3;
3610 * Placement constant - The resizing element is positioned under splitter element
3614 Roo.SplitBar.BOTTOM = 4;
3617 * Ext JS Library 1.1.1
3618 * Copyright(c) 2006-2007, Ext JS, LLC.
3620 * Originally Released Under LGPL - original licence link has changed is not relivant.
3623 * <script type="text/javascript">
3628 * @extends Roo.util.Observable
3629 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
3630 * This class also supports single and multi selection modes. <br>
3631 * Create a data model bound view:
3633 var store = new Roo.data.Store(...);
3635 var view = new Roo.View({
3637 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
3640 selectedClass: "ydataview-selected",
3644 // listen for node click?
3645 view.on("click", function(vw, index, node, e){
3646 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
3650 dataModel.load("foobar.xml");
3652 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
3654 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
3655 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
3657 * Note: old style constructor is still suported (container, template, config)
3661 * @param {Object} config The config object
3664 Roo.View = function(config, depreciated_tpl, depreciated_config){
3666 this.parent = false;
3668 if (typeof(depreciated_tpl) == 'undefined') {
3669 // new way.. - universal constructor.
3670 Roo.apply(this, config);
3671 this.el = Roo.get(this.el);
3674 this.el = Roo.get(config);
3675 this.tpl = depreciated_tpl;
3676 Roo.apply(this, depreciated_config);
3678 this.wrapEl = this.el.wrap().wrap();
3679 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
3682 if(typeof(this.tpl) == "string"){
3683 this.tpl = new Roo.Template(this.tpl);
3685 // support xtype ctors..
3686 this.tpl = new Roo.factory(this.tpl, Roo);
3695 * @event beforeclick
3696 * Fires before a click is processed. Returns false to cancel the default action.
3697 * @param {Roo.View} this
3698 * @param {Number} index The index of the target node
3699 * @param {HTMLElement} node The target node
3700 * @param {Roo.EventObject} e The raw event object
3702 "beforeclick" : true,
3705 * Fires when a template node is clicked.
3706 * @param {Roo.View} this
3707 * @param {Number} index The index of the target node
3708 * @param {HTMLElement} node The target node
3709 * @param {Roo.EventObject} e The raw event object
3714 * Fires when a template node is double clicked.
3715 * @param {Roo.View} this
3716 * @param {Number} index The index of the target node
3717 * @param {HTMLElement} node The target node
3718 * @param {Roo.EventObject} e The raw event object
3722 * @event contextmenu
3723 * Fires when a template node is right clicked.
3724 * @param {Roo.View} this
3725 * @param {Number} index The index of the target node
3726 * @param {HTMLElement} node The target node
3727 * @param {Roo.EventObject} e The raw event object
3729 "contextmenu" : true,
3731 * @event selectionchange
3732 * Fires when the selected nodes change.
3733 * @param {Roo.View} this
3734 * @param {Array} selections Array of the selected nodes
3736 "selectionchange" : true,
3739 * @event beforeselect
3740 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
3741 * @param {Roo.View} this
3742 * @param {HTMLElement} node The node to be selected
3743 * @param {Array} selections Array of currently selected nodes
3745 "beforeselect" : true,
3747 * @event preparedata
3748 * Fires on every row to render, to allow you to change the data.
3749 * @param {Roo.View} this
3750 * @param {Object} data to be rendered (change this)
3752 "preparedata" : true
3760 "click": this.onClick,
3761 "dblclick": this.onDblClick,
3762 "contextmenu": this.onContextMenu,
3766 this.selections = [];
3768 this.cmp = new Roo.CompositeElementLite([]);
3770 this.store = Roo.factory(this.store, Roo.data);
3771 this.setStore(this.store, true);
3774 if ( this.footer && this.footer.xtype) {
3776 var fctr = this.wrapEl.appendChild(document.createElement("div"));
3778 this.footer.dataSource = this.store;
3779 this.footer.container = fctr;
3780 this.footer = Roo.factory(this.footer, Roo);
3781 fctr.insertFirst(this.el);
3783 // this is a bit insane - as the paging toolbar seems to detach the el..
3784 // dom.parentNode.parentNode.parentNode
3785 // they get detached?
3789 Roo.View.superclass.constructor.call(this);
3794 Roo.extend(Roo.View, Roo.util.Observable, {
3797 * @cfg {Roo.data.Store} store Data store to load data from.
3802 * @cfg {String|Roo.Element} el The container element.
3807 * @cfg {String|Roo.Template} tpl The template used by this View
3811 * @cfg {String} dataName the named area of the template to use as the data area
3812 * Works with domtemplates roo-name="name"
3816 * @cfg {String} selectedClass The css class to add to selected nodes
3818 selectedClass : "x-view-selected",
3820 * @cfg {String} emptyText The empty text to show when nothing is loaded.
3825 * @cfg {String} text to display on mask (default Loading)
3829 * @cfg {Boolean} multiSelect Allow multiple selection
3831 multiSelect : false,
3833 * @cfg {Boolean} singleSelect Allow single selection
3835 singleSelect: false,
3838 * @cfg {Boolean} toggleSelect - selecting
3840 toggleSelect : false,
3843 * @cfg {Boolean} tickable - selecting
3848 * Returns the element this view is bound to.
3849 * @return {Roo.Element}
3858 * Refreshes the view. - called by datachanged on the store. - do not call directly.
3860 refresh : function(){
3861 //Roo.log('refresh');
3864 // if we are using something like 'domtemplate', then
3865 // the what gets used is:
3866 // t.applySubtemplate(NAME, data, wrapping data..)
3867 // the outer template then get' applied with
3868 // the store 'extra data'
3869 // and the body get's added to the
3870 // roo-name="data" node?
3871 // <span class='roo-tpl-{name}'></span> ?????
3875 this.clearSelections();
3878 var records = this.store.getRange();
3879 if(records.length < 1) {
3881 // is this valid?? = should it render a template??
3883 this.el.update(this.emptyText);
3887 if (this.dataName) {
3888 this.el.update(t.apply(this.store.meta)); //????
3889 el = this.el.child('.roo-tpl-' + this.dataName);
3892 for(var i = 0, len = records.length; i < len; i++){
3893 var data = this.prepareData(records[i].data, i, records[i]);
3894 this.fireEvent("preparedata", this, data, i, records[i]);
3896 var d = Roo.apply({}, data);
3899 Roo.apply(d, {'roo-id' : Roo.id()});
3903 Roo.each(this.parent.item, function(item){
3904 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
3907 Roo.apply(d, {'roo-data-checked' : 'checked'});
3911 html[html.length] = Roo.util.Format.trim(
3913 t.applySubtemplate(this.dataName, d, this.store.meta) :
3920 el.update(html.join(""));
3921 this.nodes = el.dom.childNodes;
3922 this.updateIndexes(0);
3927 * Function to override to reformat the data that is sent to
3928 * the template for each node.
3929 * DEPRICATED - use the preparedata event handler.
3930 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
3931 * a JSON object for an UpdateManager bound view).
3933 prepareData : function(data, index, record)
3935 this.fireEvent("preparedata", this, data, index, record);
3939 onUpdate : function(ds, record){
3940 // Roo.log('on update');
3941 this.clearSelections();
3942 var index = this.store.indexOf(record);
3943 var n = this.nodes[index];
3944 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
3945 n.parentNode.removeChild(n);
3946 this.updateIndexes(index, index);
3952 onAdd : function(ds, records, index)
3954 //Roo.log(['on Add', ds, records, index] );
3955 this.clearSelections();
3956 if(this.nodes.length == 0){
3960 var n = this.nodes[index];
3961 for(var i = 0, len = records.length; i < len; i++){
3962 var d = this.prepareData(records[i].data, i, records[i]);
3964 this.tpl.insertBefore(n, d);
3967 this.tpl.append(this.el, d);
3970 this.updateIndexes(index);
3973 onRemove : function(ds, record, index){
3974 // Roo.log('onRemove');
3975 this.clearSelections();
3976 var el = this.dataName ?
3977 this.el.child('.roo-tpl-' + this.dataName) :
3980 el.dom.removeChild(this.nodes[index]);
3981 this.updateIndexes(index);
3985 * Refresh an individual node.
3986 * @param {Number} index
3988 refreshNode : function(index){
3989 this.onUpdate(this.store, this.store.getAt(index));
3992 updateIndexes : function(startIndex, endIndex){
3993 var ns = this.nodes;
3994 startIndex = startIndex || 0;
3995 endIndex = endIndex || ns.length - 1;
3996 for(var i = startIndex; i <= endIndex; i++){
3997 ns[i].nodeIndex = i;
4002 * Changes the data store this view uses and refresh the view.
4003 * @param {Store} store
4005 setStore : function(store, initial){
4006 if(!initial && this.store){
4007 this.store.un("datachanged", this.refresh);
4008 this.store.un("add", this.onAdd);
4009 this.store.un("remove", this.onRemove);
4010 this.store.un("update", this.onUpdate);
4011 this.store.un("clear", this.refresh);
4012 this.store.un("beforeload", this.onBeforeLoad);
4013 this.store.un("load", this.onLoad);
4014 this.store.un("loadexception", this.onLoad);
4018 store.on("datachanged", this.refresh, this);
4019 store.on("add", this.onAdd, this);
4020 store.on("remove", this.onRemove, this);
4021 store.on("update", this.onUpdate, this);
4022 store.on("clear", this.refresh, this);
4023 store.on("beforeload", this.onBeforeLoad, this);
4024 store.on("load", this.onLoad, this);
4025 store.on("loadexception", this.onLoad, this);
4033 * onbeforeLoad - masks the loading area.
4036 onBeforeLoad : function(store,opts)
4038 //Roo.log('onBeforeLoad');
4042 this.el.mask(this.mask ? this.mask : "Loading" );
4044 onLoad : function ()
4051 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
4052 * @param {HTMLElement} node
4053 * @return {HTMLElement} The template node
4055 findItemFromChild : function(node){
4056 var el = this.dataName ?
4057 this.el.child('.roo-tpl-' + this.dataName,true) :
4060 if(!node || node.parentNode == el){
4063 var p = node.parentNode;
4064 while(p && p != el){
4065 if(p.parentNode == el){
4074 onClick : function(e){
4075 var item = this.findItemFromChild(e.getTarget());
4077 var index = this.indexOf(item);
4078 if(this.onItemClick(item, index, e) !== false){
4079 this.fireEvent("click", this, index, item, e);
4082 this.clearSelections();
4087 onContextMenu : function(e){
4088 var item = this.findItemFromChild(e.getTarget());
4090 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
4095 onDblClick : function(e){
4096 var item = this.findItemFromChild(e.getTarget());
4098 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
4102 onItemClick : function(item, index, e)
4104 if(this.fireEvent("beforeclick", this, index, item, e) === false){
4107 if (this.toggleSelect) {
4108 var m = this.isSelected(item) ? 'unselect' : 'select';
4111 _t[m](item, true, false);
4114 if(this.multiSelect || this.singleSelect){
4115 if(this.multiSelect && e.shiftKey && this.lastSelection){
4116 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
4118 this.select(item, this.multiSelect && e.ctrlKey);
4119 this.lastSelection = item;
4131 * Get the number of selected nodes.
4134 getSelectionCount : function(){
4135 return this.selections.length;
4139 * Get the currently selected nodes.
4140 * @return {Array} An array of HTMLElements
4142 getSelectedNodes : function(){
4143 return this.selections;
4147 * Get the indexes of the selected nodes.
4150 getSelectedIndexes : function(){
4151 var indexes = [], s = this.selections;
4152 for(var i = 0, len = s.length; i < len; i++){
4153 indexes.push(s[i].nodeIndex);
4159 * Clear all selections
4160 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
4162 clearSelections : function(suppressEvent){
4163 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
4164 this.cmp.elements = this.selections;
4165 this.cmp.removeClass(this.selectedClass);
4166 this.selections = [];
4168 this.fireEvent("selectionchange", this, this.selections);
4174 * Returns true if the passed node is selected
4175 * @param {HTMLElement/Number} node The node or node index
4178 isSelected : function(node){
4179 var s = this.selections;
4183 node = this.getNode(node);
4184 return s.indexOf(node) !== -1;
4189 * @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
4190 * @param {Boolean} keepExisting (optional) true to keep existing selections
4191 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
4193 select : function(nodeInfo, keepExisting, suppressEvent){
4194 if(nodeInfo instanceof Array){
4196 this.clearSelections(true);
4198 for(var i = 0, len = nodeInfo.length; i < len; i++){
4199 this.select(nodeInfo[i], true, true);
4203 var node = this.getNode(nodeInfo);
4204 if(!node || this.isSelected(node)){
4205 return; // already selected.
4208 this.clearSelections(true);
4211 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
4212 Roo.fly(node).addClass(this.selectedClass);
4213 this.selections.push(node);
4215 this.fireEvent("selectionchange", this, this.selections);
4223 * @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
4224 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
4225 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
4227 unselect : function(nodeInfo, keepExisting, suppressEvent)
4229 if(nodeInfo instanceof Array){
4230 Roo.each(this.selections, function(s) {
4231 this.unselect(s, nodeInfo);
4235 var node = this.getNode(nodeInfo);
4236 if(!node || !this.isSelected(node)){
4237 //Roo.log("not selected");
4238 return; // not selected.
4242 Roo.each(this.selections, function(s) {
4244 Roo.fly(node).removeClass(this.selectedClass);
4251 this.selections= ns;
4252 this.fireEvent("selectionchange", this, this.selections);
4256 * Gets a template node.
4257 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
4258 * @return {HTMLElement} The node or null if it wasn't found
4260 getNode : function(nodeInfo){
4261 if(typeof nodeInfo == "string"){
4262 return document.getElementById(nodeInfo);
4263 }else if(typeof nodeInfo == "number"){
4264 return this.nodes[nodeInfo];
4270 * Gets a range template nodes.
4271 * @param {Number} startIndex
4272 * @param {Number} endIndex
4273 * @return {Array} An array of nodes
4275 getNodes : function(start, end){
4276 var ns = this.nodes;
4278 end = typeof end == "undefined" ? ns.length - 1 : end;
4281 for(var i = start; i <= end; i++){
4285 for(var i = start; i >= end; i--){
4293 * Finds the index of the passed node
4294 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
4295 * @return {Number} The index of the node or -1
4297 indexOf : function(node){
4298 node = this.getNode(node);
4299 if(typeof node.nodeIndex == "number"){
4300 return node.nodeIndex;
4302 var ns = this.nodes;
4303 for(var i = 0, len = ns.length; i < len; i++){
4313 * Ext JS Library 1.1.1
4314 * Copyright(c) 2006-2007, Ext JS, LLC.
4316 * Originally Released Under LGPL - original licence link has changed is not relivant.
4319 * <script type="text/javascript">
4323 * @class Roo.JsonView
4325 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
4327 var view = new Roo.JsonView({
4328 container: "my-element",
4329 tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
4334 // listen for node click?
4335 view.on("click", function(vw, index, node, e){
4336 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
4339 // direct load of JSON data
4340 view.load("foobar.php");
4342 // Example from my blog list
4343 var tpl = new Roo.Template(
4344 '<div class="entry">' +
4345 '<a class="entry-title" href="{link}">{title}</a>' +
4346 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
4347 "</div><hr />"
4350 var moreView = new Roo.JsonView({
4351 container : "entry-list",
4355 moreView.on("beforerender", this.sortEntries, this);
4357 url: "/blog/get-posts.php",
4358 params: "allposts=true",
4359 text: "Loading Blog Entries..."
4363 * Note: old code is supported with arguments : (container, template, config)
4367 * Create a new JsonView
4369 * @param {Object} config The config object
4372 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
4375 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
4377 var um = this.el.getUpdateManager();
4378 um.setRenderer(this);
4379 um.on("update", this.onLoad, this);
4380 um.on("failure", this.onLoadException, this);
4383 * @event beforerender
4384 * Fires before rendering of the downloaded JSON data.
4385 * @param {Roo.JsonView} this
4386 * @param {Object} data The JSON data loaded
4390 * Fires when data is loaded.
4391 * @param {Roo.JsonView} this
4392 * @param {Object} data The JSON data loaded
4393 * @param {Object} response The raw Connect response object
4396 * @event loadexception
4397 * Fires when loading fails.
4398 * @param {Roo.JsonView} this
4399 * @param {Object} response The raw Connect response object
4402 'beforerender' : true,
4404 'loadexception' : true
4407 Roo.extend(Roo.JsonView, Roo.View, {
4409 * @type {String} The root property in the loaded JSON object that contains the data
4414 * Refreshes the view.
4416 refresh : function(){
4417 this.clearSelections();
4420 var o = this.jsonData;
4421 if(o && o.length > 0){
4422 for(var i = 0, len = o.length; i < len; i++){
4423 var data = this.prepareData(o[i], i, o);
4424 html[html.length] = this.tpl.apply(data);
4427 html.push(this.emptyText);
4429 this.el.update(html.join(""));
4430 this.nodes = this.el.dom.childNodes;
4431 this.updateIndexes(0);
4435 * 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.
4436 * @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:
4439 url: "your-url.php",
4440 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
4441 callback: yourFunction,
4442 scope: yourObject, //(optional scope)
4450 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
4451 * 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.
4452 * @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}
4453 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
4454 * @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.
4457 var um = this.el.getUpdateManager();
4458 um.update.apply(um, arguments);
4461 // note - render is a standard framework call...
4462 // using it for the response is really flaky... - it's called by UpdateManager normally, except when called by the XComponent/addXtype.
4463 render : function(el, response){
4465 this.clearSelections();
4469 if (response != '') {
4470 o = Roo.util.JSON.decode(response.responseText);
4473 o = o[this.jsonRoot];
4479 * The current JSON data or null
4482 this.beforeRender();
4487 * Get the number of records in the current JSON dataset
4490 getCount : function(){
4491 return this.jsonData ? this.jsonData.length : 0;
4495 * Returns the JSON object for the specified node(s)
4496 * @param {HTMLElement/Array} node The node or an array of nodes
4497 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
4498 * you get the JSON object for the node
4500 getNodeData : function(node){
4501 if(node instanceof Array){
4503 for(var i = 0, len = node.length; i < len; i++){
4504 data.push(this.getNodeData(node[i]));
4508 return this.jsonData[this.indexOf(node)] || null;
4511 beforeRender : function(){
4512 this.snapshot = this.jsonData;
4514 this.sort.apply(this, this.sortInfo);
4516 this.fireEvent("beforerender", this, this.jsonData);
4519 onLoad : function(el, o){
4520 this.fireEvent("load", this, this.jsonData, o);
4523 onLoadException : function(el, o){
4524 this.fireEvent("loadexception", this, o);
4528 * Filter the data by a specific property.
4529 * @param {String} property A property on your JSON objects
4530 * @param {String/RegExp} value Either string that the property values
4531 * should start with, or a RegExp to test against the property
4533 filter : function(property, value){
4536 var ss = this.snapshot;
4537 if(typeof value == "string"){
4538 var vlen = value.length;
4543 value = value.toLowerCase();
4544 for(var i = 0, len = ss.length; i < len; i++){
4546 if(o[property].substr(0, vlen).toLowerCase() == value){
4550 } else if(value.exec){ // regex?
4551 for(var i = 0, len = ss.length; i < len; i++){
4553 if(value.test(o[property])){
4560 this.jsonData = data;
4566 * Filter by a function. The passed function will be called with each
4567 * object in the current dataset. If the function returns true the value is kept,
4568 * otherwise it is filtered.
4569 * @param {Function} fn
4570 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
4572 filterBy : function(fn, scope){
4575 var ss = this.snapshot;
4576 for(var i = 0, len = ss.length; i < len; i++){
4578 if(fn.call(scope || this, o)){
4582 this.jsonData = data;
4588 * Clears the current filter.
4590 clearFilter : function(){
4591 if(this.snapshot && this.jsonData != this.snapshot){
4592 this.jsonData = this.snapshot;
4599 * Sorts the data for this view and refreshes it.
4600 * @param {String} property A property on your JSON objects to sort on
4601 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
4602 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
4604 sort : function(property, dir, sortType){
4605 this.sortInfo = Array.prototype.slice.call(arguments, 0);
4608 var dsc = dir && dir.toLowerCase() == "desc";
4609 var f = function(o1, o2){
4610 var v1 = sortType ? sortType(o1[p]) : o1[p];
4611 var v2 = sortType ? sortType(o2[p]) : o2[p];
4614 return dsc ? +1 : -1;
4616 return dsc ? -1 : +1;
4621 this.jsonData.sort(f);
4623 if(this.jsonData != this.snapshot){
4624 this.snapshot.sort(f);
4630 * Ext JS Library 1.1.1
4631 * Copyright(c) 2006-2007, Ext JS, LLC.
4633 * Originally Released Under LGPL - original licence link has changed is not relivant.
4636 * <script type="text/javascript">
4641 * @class Roo.ColorPalette
4642 * @extends Roo.Component
4643 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
4644 * Here's an example of typical usage:
4646 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
4647 cp.render('my-div');
4649 cp.on('select', function(palette, selColor){
4650 // do something with selColor
4654 * Create a new ColorPalette
4655 * @param {Object} config The config object
4657 Roo.ColorPalette = function(config){
4658 Roo.ColorPalette.superclass.constructor.call(this, config);
4662 * Fires when a color is selected
4663 * @param {ColorPalette} this
4664 * @param {String} color The 6-digit color hex code (without the # symbol)
4670 this.on("select", this.handler, this.scope, true);
4673 Roo.extend(Roo.ColorPalette, Roo.Component, {
4675 * @cfg {String} itemCls
4676 * The CSS class to apply to the containing element (defaults to "x-color-palette")
4678 itemCls : "x-color-palette",
4680 * @cfg {String} value
4681 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
4682 * the hex codes are case-sensitive.
4687 ctype: "Roo.ColorPalette",
4690 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
4692 allowReselect : false,
4695 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
4696 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
4697 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
4698 * of colors with the width setting until the box is symmetrical.</p>
4699 * <p>You can override individual colors if needed:</p>
4701 var cp = new Roo.ColorPalette();
4702 cp.colors[0] = "FF0000"; // change the first box to red
4705 Or you can provide a custom array of your own for complete control:
4707 var cp = new Roo.ColorPalette();
4708 cp.colors = ["000000", "993300", "333300"];
4713 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
4714 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
4715 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
4716 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
4717 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
4721 onRender : function(container, position){
4722 var t = new Roo.MasterTemplate(
4723 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
4725 var c = this.colors;
4726 for(var i = 0, len = c.length; i < len; i++){
4729 var el = document.createElement("div");
4730 el.className = this.itemCls;
4732 container.dom.insertBefore(el, position);
4733 this.el = Roo.get(el);
4734 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
4735 if(this.clickEvent != 'click'){
4736 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
4741 afterRender : function(){
4742 Roo.ColorPalette.superclass.afterRender.call(this);
4751 handleClick : function(e, t){
4754 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
4755 this.select(c.toUpperCase());
4760 * Selects the specified color in the palette (fires the select event)
4761 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
4763 select : function(color){
4764 color = color.replace("#", "");
4765 if(color != this.value || this.allowReselect){
4768 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
4770 el.child("a.color-"+color).addClass("x-color-palette-sel");
4772 this.fireEvent("select", this, color);
4777 * Ext JS Library 1.1.1
4778 * Copyright(c) 2006-2007, Ext JS, LLC.
4780 * Originally Released Under LGPL - original licence link has changed is not relivant.
4783 * <script type="text/javascript">
4787 * @class Roo.DatePicker
4788 * @extends Roo.Component
4789 * Simple date picker class.
4791 * Create a new DatePicker
4792 * @param {Object} config The config object
4794 Roo.DatePicker = function(config){
4795 Roo.DatePicker.superclass.constructor.call(this, config);
4797 this.value = config && config.value ?
4798 config.value.clearTime() : new Date().clearTime();
4803 * Fires when a date is selected
4804 * @param {DatePicker} this
4805 * @param {Date} date The selected date
4809 * @event monthchange
4810 * Fires when the displayed month changes
4811 * @param {DatePicker} this
4812 * @param {Date} date The selected month
4818 this.on("select", this.handler, this.scope || this);
4820 // build the disabledDatesRE
4821 if(!this.disabledDatesRE && this.disabledDates){
4822 var dd = this.disabledDates;
4824 for(var i = 0; i < dd.length; i++){
4826 if(i != dd.length-1) {
4830 this.disabledDatesRE = new RegExp(re + ")");
4834 Roo.extend(Roo.DatePicker, Roo.Component, {
4836 * @cfg {String} todayText
4837 * The text to display on the button that selects the current date (defaults to "Today")
4839 todayText : "Today",
4841 * @cfg {String} okText
4842 * The text to display on the ok button
4844 okText : " OK ", //   to give the user extra clicking room
4846 * @cfg {String} cancelText
4847 * The text to display on the cancel button
4849 cancelText : "Cancel",
4851 * @cfg {String} todayTip
4852 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
4854 todayTip : "{0} (Spacebar)",
4856 * @cfg {Date} minDate
4857 * Minimum allowable date (JavaScript date object, defaults to null)
4861 * @cfg {Date} maxDate
4862 * Maximum allowable date (JavaScript date object, defaults to null)
4866 * @cfg {String} minText
4867 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
4869 minText : "This date is before the minimum date",
4871 * @cfg {String} maxText
4872 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
4874 maxText : "This date is after the maximum date",
4876 * @cfg {String} format
4877 * The default date format string which can be overriden for localization support. The format must be
4878 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
4882 * @cfg {Array} disabledDays
4883 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
4885 disabledDays : null,
4887 * @cfg {String} disabledDaysText
4888 * The tooltip to display when the date falls on a disabled day (defaults to "")
4890 disabledDaysText : "",
4892 * @cfg {RegExp} disabledDatesRE
4893 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
4895 disabledDatesRE : null,
4897 * @cfg {String} disabledDatesText
4898 * The tooltip text to display when the date falls on a disabled date (defaults to "")
4900 disabledDatesText : "",
4902 * @cfg {Boolean} constrainToViewport
4903 * True to constrain the date picker to the viewport (defaults to true)
4905 constrainToViewport : true,
4907 * @cfg {Array} monthNames
4908 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
4910 monthNames : Date.monthNames,
4912 * @cfg {Array} dayNames
4913 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
4915 dayNames : Date.dayNames,
4917 * @cfg {String} nextText
4918 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
4920 nextText: 'Next Month (Control+Right)',
4922 * @cfg {String} prevText
4923 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
4925 prevText: 'Previous Month (Control+Left)',
4927 * @cfg {String} monthYearText
4928 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
4930 monthYearText: 'Choose a month (Control+Up/Down to move years)',
4932 * @cfg {Number} startDay
4933 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
4937 * @cfg {Bool} showClear
4938 * Show a clear button (usefull for date form elements that can be blank.)
4944 * Sets the value of the date field
4945 * @param {Date} value The date to set
4947 setValue : function(value){
4948 var old = this.value;
4950 if (typeof(value) == 'string') {
4952 value = Date.parseDate(value, this.format);
4958 this.value = value.clearTime(true);
4960 this.update(this.value);
4965 * Gets the current selected value of the date field
4966 * @return {Date} The selected date
4968 getValue : function(){
4975 this.update(this.activeDate);
4980 onRender : function(container, position){
4983 '<table cellspacing="0">',
4984 '<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>',
4985 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
4986 var dn = this.dayNames;
4987 for(var i = 0; i < 7; i++){
4988 var d = this.startDay+i;
4992 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
4994 m[m.length] = "</tr></thead><tbody><tr>";
4995 for(var i = 0; i < 42; i++) {
4996 if(i % 7 == 0 && i != 0){
4997 m[m.length] = "</tr><tr>";
4999 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
5001 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
5002 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
5004 var el = document.createElement("div");
5005 el.className = "x-date-picker";
5006 el.innerHTML = m.join("");
5008 container.dom.insertBefore(el, position);
5010 this.el = Roo.get(el);
5011 this.eventEl = Roo.get(el.firstChild);
5013 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
5014 handler: this.showPrevMonth,
5016 preventDefault:true,
5020 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
5021 handler: this.showNextMonth,
5023 preventDefault:true,
5027 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
5029 this.monthPicker = this.el.down('div.x-date-mp');
5030 this.monthPicker.enableDisplayMode('block');
5032 var kn = new Roo.KeyNav(this.eventEl, {
5033 "left" : function(e){
5035 this.showPrevMonth() :
5036 this.update(this.activeDate.add("d", -1));
5039 "right" : function(e){
5041 this.showNextMonth() :
5042 this.update(this.activeDate.add("d", 1));
5047 this.showNextYear() :
5048 this.update(this.activeDate.add("d", -7));
5051 "down" : function(e){
5053 this.showPrevYear() :
5054 this.update(this.activeDate.add("d", 7));
5057 "pageUp" : function(e){
5058 this.showNextMonth();
5061 "pageDown" : function(e){
5062 this.showPrevMonth();
5065 "enter" : function(e){
5066 e.stopPropagation();
5073 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
5075 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
5077 this.el.unselectable();
5079 this.cells = this.el.select("table.x-date-inner tbody td");
5080 this.textNodes = this.el.query("table.x-date-inner tbody span");
5082 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
5084 tooltip: this.monthYearText
5087 this.mbtn.on('click', this.showMonthPicker, this);
5088 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
5091 var today = (new Date()).dateFormat(this.format);
5093 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
5094 if (this.showClear) {
5095 baseTb.add( new Roo.Toolbar.Fill());
5098 text: String.format(this.todayText, today),
5099 tooltip: String.format(this.todayTip, today),
5100 handler: this.selectToday,
5104 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
5107 if (this.showClear) {
5109 baseTb.add( new Roo.Toolbar.Fill());
5112 cls: 'x-btn-icon x-btn-clear',
5113 handler: function() {
5115 this.fireEvent("select", this, '');
5125 this.update(this.value);
5128 createMonthPicker : function(){
5129 if(!this.monthPicker.dom.firstChild){
5130 var buf = ['<table border="0" cellspacing="0">'];
5131 for(var i = 0; i < 6; i++){
5133 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
5134 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
5136 '<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>' :
5137 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
5141 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
5143 '</button><button type="button" class="x-date-mp-cancel">',
5145 '</button></td></tr>',
5148 this.monthPicker.update(buf.join(''));
5149 this.monthPicker.on('click', this.onMonthClick, this);
5150 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
5152 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
5153 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
5155 this.mpMonths.each(function(m, a, i){
5158 m.dom.xmonth = 5 + Math.round(i * .5);
5160 m.dom.xmonth = Math.round((i-1) * .5);
5166 showMonthPicker : function(){
5167 this.createMonthPicker();
5168 var size = this.el.getSize();
5169 this.monthPicker.setSize(size);
5170 this.monthPicker.child('table').setSize(size);
5172 this.mpSelMonth = (this.activeDate || this.value).getMonth();
5173 this.updateMPMonth(this.mpSelMonth);
5174 this.mpSelYear = (this.activeDate || this.value).getFullYear();
5175 this.updateMPYear(this.mpSelYear);
5177 this.monthPicker.slideIn('t', {duration:.2});
5180 updateMPYear : function(y){
5182 var ys = this.mpYears.elements;
5183 for(var i = 1; i <= 10; i++){
5184 var td = ys[i-1], y2;
5186 y2 = y + Math.round(i * .5);
5187 td.firstChild.innerHTML = y2;
5190 y2 = y - (5-Math.round(i * .5));
5191 td.firstChild.innerHTML = y2;
5194 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
5198 updateMPMonth : function(sm){
5199 this.mpMonths.each(function(m, a, i){
5200 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
5204 selectMPMonth: function(m){
5208 onMonthClick : function(e, t){
5210 var el = new Roo.Element(t), pn;
5211 if(el.is('button.x-date-mp-cancel')){
5212 this.hideMonthPicker();
5214 else if(el.is('button.x-date-mp-ok')){
5215 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
5216 this.hideMonthPicker();
5218 else if(pn = el.up('td.x-date-mp-month', 2)){
5219 this.mpMonths.removeClass('x-date-mp-sel');
5220 pn.addClass('x-date-mp-sel');
5221 this.mpSelMonth = pn.dom.xmonth;
5223 else if(pn = el.up('td.x-date-mp-year', 2)){
5224 this.mpYears.removeClass('x-date-mp-sel');
5225 pn.addClass('x-date-mp-sel');
5226 this.mpSelYear = pn.dom.xyear;
5228 else if(el.is('a.x-date-mp-prev')){
5229 this.updateMPYear(this.mpyear-10);
5231 else if(el.is('a.x-date-mp-next')){
5232 this.updateMPYear(this.mpyear+10);
5236 onMonthDblClick : function(e, t){
5238 var el = new Roo.Element(t), pn;
5239 if(pn = el.up('td.x-date-mp-month', 2)){
5240 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
5241 this.hideMonthPicker();
5243 else if(pn = el.up('td.x-date-mp-year', 2)){
5244 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
5245 this.hideMonthPicker();
5249 hideMonthPicker : function(disableAnim){
5250 if(this.monthPicker){
5251 if(disableAnim === true){
5252 this.monthPicker.hide();
5254 this.monthPicker.slideOut('t', {duration:.2});
5260 showPrevMonth : function(e){
5261 this.update(this.activeDate.add("mo", -1));
5265 showNextMonth : function(e){
5266 this.update(this.activeDate.add("mo", 1));
5270 showPrevYear : function(){
5271 this.update(this.activeDate.add("y", -1));
5275 showNextYear : function(){
5276 this.update(this.activeDate.add("y", 1));
5280 handleMouseWheel : function(e){
5281 var delta = e.getWheelDelta();
5283 this.showPrevMonth();
5285 } else if(delta < 0){
5286 this.showNextMonth();
5292 handleDateClick : function(e, t){
5294 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
5295 this.setValue(new Date(t.dateValue));
5296 this.fireEvent("select", this, this.value);
5301 selectToday : function(){
5302 this.setValue(new Date().clearTime());
5303 this.fireEvent("select", this, this.value);
5307 update : function(date)
5309 var vd = this.activeDate;
5310 this.activeDate = date;
5312 var t = date.getTime();
5313 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
5314 this.cells.removeClass("x-date-selected");
5315 this.cells.each(function(c){
5316 if(c.dom.firstChild.dateValue == t){
5317 c.addClass("x-date-selected");
5318 setTimeout(function(){
5319 try{c.dom.firstChild.focus();}catch(e){}
5328 var days = date.getDaysInMonth();
5329 var firstOfMonth = date.getFirstDateOfMonth();
5330 var startingPos = firstOfMonth.getDay()-this.startDay;
5332 if(startingPos <= this.startDay){
5336 var pm = date.add("mo", -1);
5337 var prevStart = pm.getDaysInMonth()-startingPos;
5339 var cells = this.cells.elements;
5340 var textEls = this.textNodes;
5341 days += startingPos;
5343 // convert everything to numbers so it's fast
5345 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
5346 var today = new Date().clearTime().getTime();
5347 var sel = date.clearTime().getTime();
5348 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
5349 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
5350 var ddMatch = this.disabledDatesRE;
5351 var ddText = this.disabledDatesText;
5352 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
5353 var ddaysText = this.disabledDaysText;
5354 var format = this.format;
5356 var setCellClass = function(cal, cell){
5358 var t = d.getTime();
5359 cell.firstChild.dateValue = t;
5361 cell.className += " x-date-today";
5362 cell.title = cal.todayText;
5365 cell.className += " x-date-selected";
5366 setTimeout(function(){
5367 try{cell.firstChild.focus();}catch(e){}
5372 cell.className = " x-date-disabled";
5373 cell.title = cal.minText;
5377 cell.className = " x-date-disabled";
5378 cell.title = cal.maxText;
5382 if(ddays.indexOf(d.getDay()) != -1){
5383 cell.title = ddaysText;
5384 cell.className = " x-date-disabled";
5387 if(ddMatch && format){
5388 var fvalue = d.dateFormat(format);
5389 if(ddMatch.test(fvalue)){
5390 cell.title = ddText.replace("%0", fvalue);
5391 cell.className = " x-date-disabled";
5397 for(; i < startingPos; i++) {
5398 textEls[i].innerHTML = (++prevStart);
5399 d.setDate(d.getDate()+1);
5400 cells[i].className = "x-date-prevday";
5401 setCellClass(this, cells[i]);
5403 for(; i < days; i++){
5404 intDay = i - startingPos + 1;
5405 textEls[i].innerHTML = (intDay);
5406 d.setDate(d.getDate()+1);
5407 cells[i].className = "x-date-active";
5408 setCellClass(this, cells[i]);
5411 for(; i < 42; i++) {
5412 textEls[i].innerHTML = (++extraDays);
5413 d.setDate(d.getDate()+1);
5414 cells[i].className = "x-date-nextday";
5415 setCellClass(this, cells[i]);
5418 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
5419 this.fireEvent('monthchange', this, date);
5421 if(!this.internalRender){
5422 var main = this.el.dom.firstChild;
5423 var w = main.offsetWidth;
5424 this.el.setWidth(w + this.el.getBorderWidth("lr"));
5425 Roo.fly(main).setWidth(w);
5426 this.internalRender = true;
5427 // opera does not respect the auto grow header center column
5428 // then, after it gets a width opera refuses to recalculate
5429 // without a second pass
5430 if(Roo.isOpera && !this.secondPass){
5431 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
5432 this.secondPass = true;
5433 this.update.defer(10, this, [date]);
5441 * Ext JS Library 1.1.1
5442 * Copyright(c) 2006-2007, Ext JS, LLC.
5444 * Originally Released Under LGPL - original licence link has changed is not relivant.
5447 * <script type="text/javascript">
5450 * @class Roo.TabPanel
5451 * @extends Roo.util.Observable
5452 * A lightweight tab container.
5456 // basic tabs 1, built from existing content
5457 var tabs = new Roo.TabPanel("tabs1");
5458 tabs.addTab("script", "View Script");
5459 tabs.addTab("markup", "View Markup");
5460 tabs.activate("script");
5462 // more advanced tabs, built from javascript
5463 var jtabs = new Roo.TabPanel("jtabs");
5464 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
5466 // set up the UpdateManager
5467 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
5468 var updater = tab2.getUpdateManager();
5469 updater.setDefaultUrl("ajax1.htm");
5470 tab2.on('activate', updater.refresh, updater, true);
5472 // Use setUrl for Ajax loading
5473 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
5474 tab3.setUrl("ajax2.htm", null, true);
5477 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
5480 jtabs.activate("jtabs-1");
5483 * Create a new TabPanel.
5484 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
5485 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
5487 Roo.TabPanel = function(container, config){
5489 * The container element for this TabPanel.
5492 this.el = Roo.get(container, true);
5494 if(typeof config == "boolean"){
5495 this.tabPosition = config ? "bottom" : "top";
5497 Roo.apply(this, config);
5500 if(this.tabPosition == "bottom"){
5501 this.bodyEl = Roo.get(this.createBody(this.el.dom));
5502 this.el.addClass("x-tabs-bottom");
5504 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
5505 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
5506 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
5508 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
5510 if(this.tabPosition != "bottom"){
5511 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
5514 this.bodyEl = Roo.get(this.createBody(this.el.dom));
5515 this.el.addClass("x-tabs-top");
5519 this.bodyEl.setStyle("position", "relative");
5522 this.activateDelegate = this.activate.createDelegate(this);
5527 * Fires when the active tab changes
5528 * @param {Roo.TabPanel} this
5529 * @param {Roo.TabPanelItem} activePanel The new active tab
5533 * @event beforetabchange
5534 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
5535 * @param {Roo.TabPanel} this
5536 * @param {Object} e Set cancel to true on this object to cancel the tab change
5537 * @param {Roo.TabPanelItem} tab The tab being changed to
5539 "beforetabchange" : true
5542 Roo.EventManager.onWindowResize(this.onResize, this);
5543 this.cpad = this.el.getPadding("lr");
5544 this.hiddenCount = 0;
5547 // toolbar on the tabbar support...
5549 var tcfg = this.toolbar;
5550 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
5551 this.toolbar = new Roo.Toolbar(tcfg);
5553 var tbl = tcfg.container.child('table', true);
5554 tbl.setAttribute('width', '100%');
5561 Roo.TabPanel.superclass.constructor.call(this);
5564 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
5566 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
5568 tabPosition : "top",
5570 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
5572 currentTabWidth : 0,
5574 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
5578 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
5582 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
5584 preferredTabWidth : 175,
5586 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
5590 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
5592 monitorResize : true,
5594 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
5599 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
5600 * @param {String} id The id of the div to use <b>or create</b>
5601 * @param {String} text The text for the tab
5602 * @param {String} content (optional) Content to put in the TabPanelItem body
5603 * @param {Boolean} closable (optional) True to create a close icon on the tab
5604 * @return {Roo.TabPanelItem} The created TabPanelItem
5606 addTab : function(id, text, content, closable){
5607 var item = new Roo.TabPanelItem(this, id, text, closable);
5608 this.addTabItem(item);
5610 item.setContent(content);
5616 * Returns the {@link Roo.TabPanelItem} with the specified id/index
5617 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
5618 * @return {Roo.TabPanelItem}
5620 getTab : function(id){
5621 return this.items[id];
5625 * Hides the {@link Roo.TabPanelItem} with the specified id/index
5626 * @param {String/Number} id The id or index of the TabPanelItem to hide.
5628 hideTab : function(id){
5629 var t = this.items[id];
5633 this.autoSizeTabs();
5638 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
5639 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
5641 unhideTab : function(id){
5642 var t = this.items[id];
5646 this.autoSizeTabs();
5651 * Adds an existing {@link Roo.TabPanelItem}.
5652 * @param {Roo.TabPanelItem} item The TabPanelItem to add
5654 addTabItem : function(item){
5655 this.items[item.id] = item;
5656 this.items.push(item);
5657 if(this.resizeTabs){
5658 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
5659 this.autoSizeTabs();
5666 * Removes a {@link Roo.TabPanelItem}.
5667 * @param {String/Number} id The id or index of the TabPanelItem to remove.
5669 removeTab : function(id){
5670 var items = this.items;
5671 var tab = items[id];
5672 if(!tab) { return; }
5673 var index = items.indexOf(tab);
5674 if(this.active == tab && items.length > 1){
5675 var newTab = this.getNextAvailable(index);
5680 this.stripEl.dom.removeChild(tab.pnode.dom);
5681 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
5682 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
5684 items.splice(index, 1);
5685 delete this.items[tab.id];
5686 tab.fireEvent("close", tab);
5687 tab.purgeListeners();
5688 this.autoSizeTabs();
5691 getNextAvailable : function(start){
5692 var items = this.items;
5694 // look for a next tab that will slide over to
5695 // replace the one being removed
5696 while(index < items.length){
5697 var item = items[++index];
5698 if(item && !item.isHidden()){
5702 // if one isn't found select the previous tab (on the left)
5705 var item = items[--index];
5706 if(item && !item.isHidden()){
5714 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
5715 * @param {String/Number} id The id or index of the TabPanelItem to disable.
5717 disableTab : function(id){
5718 var tab = this.items[id];
5719 if(tab && this.active != tab){
5725 * Enables a {@link Roo.TabPanelItem} that is disabled.
5726 * @param {String/Number} id The id or index of the TabPanelItem to enable.
5728 enableTab : function(id){
5729 var tab = this.items[id];
5734 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
5735 * @param {String/Number} id The id or index of the TabPanelItem to activate.
5736 * @return {Roo.TabPanelItem} The TabPanelItem.
5738 activate : function(id){
5739 var tab = this.items[id];
5743 if(tab == this.active || tab.disabled){
5747 this.fireEvent("beforetabchange", this, e, tab);
5748 if(e.cancel !== true && !tab.disabled){
5752 this.active = this.items[id];
5754 this.fireEvent("tabchange", this, this.active);
5760 * Gets the active {@link Roo.TabPanelItem}.
5761 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
5763 getActiveTab : function(){
5768 * Updates the tab body element to fit the height of the container element
5769 * for overflow scrolling
5770 * @param {Number} targetHeight (optional) Override the starting height from the elements height
5772 syncHeight : function(targetHeight){
5773 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
5774 var bm = this.bodyEl.getMargins();
5775 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
5776 this.bodyEl.setHeight(newHeight);
5780 onResize : function(){
5781 if(this.monitorResize){
5782 this.autoSizeTabs();
5787 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
5789 beginUpdate : function(){
5790 this.updating = true;
5794 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
5796 endUpdate : function(){
5797 this.updating = false;
5798 this.autoSizeTabs();
5802 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
5804 autoSizeTabs : function(){
5805 var count = this.items.length;
5806 var vcount = count - this.hiddenCount;
5807 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
5810 var w = Math.max(this.el.getWidth() - this.cpad, 10);
5811 var availWidth = Math.floor(w / vcount);
5812 var b = this.stripBody;
5813 if(b.getWidth() > w){
5814 var tabs = this.items;
5815 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
5816 if(availWidth < this.minTabWidth){
5817 /*if(!this.sleft){ // incomplete scrolling code
5818 this.createScrollButtons();
5821 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
5824 if(this.currentTabWidth < this.preferredTabWidth){
5825 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
5831 * Returns the number of tabs in this TabPanel.
5834 getCount : function(){
5835 return this.items.length;
5839 * Resizes all the tabs to the passed width
5840 * @param {Number} The new width
5842 setTabWidth : function(width){
5843 this.currentTabWidth = width;
5844 for(var i = 0, len = this.items.length; i < len; i++) {
5845 if(!this.items[i].isHidden()) {
5846 this.items[i].setWidth(width);
5852 * Destroys this TabPanel
5853 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
5855 destroy : function(removeEl){
5856 Roo.EventManager.removeResizeListener(this.onResize, this);
5857 for(var i = 0, len = this.items.length; i < len; i++){
5858 this.items[i].purgeListeners();
5860 if(removeEl === true){
5868 * @class Roo.TabPanelItem
5869 * @extends Roo.util.Observable
5870 * Represents an individual item (tab plus body) in a TabPanel.
5871 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
5872 * @param {String} id The id of this TabPanelItem
5873 * @param {String} text The text for the tab of this TabPanelItem
5874 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
5876 Roo.TabPanelItem = function(tabPanel, id, text, closable){
5878 * The {@link Roo.TabPanel} this TabPanelItem belongs to
5879 * @type Roo.TabPanel
5881 this.tabPanel = tabPanel;
5883 * The id for this TabPanelItem
5888 this.disabled = false;
5892 this.loaded = false;
5893 this.closable = closable;
5896 * The body element for this TabPanelItem.
5899 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
5900 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
5901 this.bodyEl.setStyle("display", "block");
5902 this.bodyEl.setStyle("zoom", "1");
5905 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
5907 this.el = Roo.get(els.el, true);
5908 this.inner = Roo.get(els.inner, true);
5909 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
5910 this.pnode = Roo.get(els.el.parentNode, true);
5911 this.el.on("mousedown", this.onTabMouseDown, this);
5912 this.el.on("click", this.onTabClick, this);
5915 var c = Roo.get(els.close, true);
5916 c.dom.title = this.closeText;
5917 c.addClassOnOver("close-over");
5918 c.on("click", this.closeClick, this);
5924 * Fires when this tab becomes the active tab.
5925 * @param {Roo.TabPanel} tabPanel The parent TabPanel
5926 * @param {Roo.TabPanelItem} this
5930 * @event beforeclose
5931 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
5932 * @param {Roo.TabPanelItem} this
5933 * @param {Object} e Set cancel to true on this object to cancel the close.
5935 "beforeclose": true,
5938 * Fires when this tab is closed.
5939 * @param {Roo.TabPanelItem} this
5944 * Fires when this tab is no longer the active tab.
5945 * @param {Roo.TabPanel} tabPanel The parent TabPanel
5946 * @param {Roo.TabPanelItem} this
5950 this.hidden = false;
5952 Roo.TabPanelItem.superclass.constructor.call(this);
5955 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
5956 purgeListeners : function(){
5957 Roo.util.Observable.prototype.purgeListeners.call(this);
5958 this.el.removeAllListeners();
5961 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
5964 this.pnode.addClass("on");
5967 this.tabPanel.stripWrap.repaint();
5969 this.fireEvent("activate", this.tabPanel, this);
5973 * Returns true if this tab is the active tab.
5976 isActive : function(){
5977 return this.tabPanel.getActiveTab() == this;
5981 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
5984 this.pnode.removeClass("on");
5986 this.fireEvent("deactivate", this.tabPanel, this);
5989 hideAction : function(){
5991 this.bodyEl.setStyle("position", "absolute");
5992 this.bodyEl.setLeft("-20000px");
5993 this.bodyEl.setTop("-20000px");
5996 showAction : function(){
5997 this.bodyEl.setStyle("position", "relative");
5998 this.bodyEl.setTop("");
5999 this.bodyEl.setLeft("");
6004 * Set the tooltip for the tab.
6005 * @param {String} tooltip The tab's tooltip
6007 setTooltip : function(text){
6008 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
6009 this.textEl.dom.qtip = text;
6010 this.textEl.dom.removeAttribute('title');
6012 this.textEl.dom.title = text;
6016 onTabClick : function(e){
6018 this.tabPanel.activate(this.id);
6021 onTabMouseDown : function(e){
6023 this.tabPanel.activate(this.id);
6026 getWidth : function(){
6027 return this.inner.getWidth();
6030 setWidth : function(width){
6031 var iwidth = width - this.pnode.getPadding("lr");
6032 this.inner.setWidth(iwidth);
6033 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
6034 this.pnode.setWidth(width);
6038 * Show or hide the tab
6039 * @param {Boolean} hidden True to hide or false to show.
6041 setHidden : function(hidden){
6042 this.hidden = hidden;
6043 this.pnode.setStyle("display", hidden ? "none" : "");
6047 * Returns true if this tab is "hidden"
6050 isHidden : function(){
6055 * Returns the text for this tab
6058 getText : function(){
6062 autoSize : function(){
6063 //this.el.beginMeasure();
6064 this.textEl.setWidth(1);
6066 * #2804 [new] Tabs in Roojs
6067 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
6069 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
6070 //this.el.endMeasure();
6074 * Sets the text for the tab (Note: this also sets the tooltip text)
6075 * @param {String} text The tab's text and tooltip
6077 setText : function(text){
6079 this.textEl.update(text);
6080 this.setTooltip(text);
6081 if(!this.tabPanel.resizeTabs){
6086 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
6088 activate : function(){
6089 this.tabPanel.activate(this.id);
6093 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
6095 disable : function(){
6096 if(this.tabPanel.active != this){
6097 this.disabled = true;
6098 this.pnode.addClass("disabled");
6103 * Enables this TabPanelItem if it was previously disabled.
6105 enable : function(){
6106 this.disabled = false;
6107 this.pnode.removeClass("disabled");
6111 * Sets the content for this TabPanelItem.
6112 * @param {String} content The content
6113 * @param {Boolean} loadScripts true to look for and load scripts
6115 setContent : function(content, loadScripts){
6116 this.bodyEl.update(content, loadScripts);
6120 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
6121 * @return {Roo.UpdateManager} The UpdateManager
6123 getUpdateManager : function(){
6124 return this.bodyEl.getUpdateManager();
6128 * Set a URL to be used to load the content for this TabPanelItem.
6129 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
6130 * @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)
6131 * @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)
6132 * @return {Roo.UpdateManager} The UpdateManager
6134 setUrl : function(url, params, loadOnce){
6135 if(this.refreshDelegate){
6136 this.un('activate', this.refreshDelegate);
6138 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
6139 this.on("activate", this.refreshDelegate);
6140 return this.bodyEl.getUpdateManager();
6144 _handleRefresh : function(url, params, loadOnce){
6145 if(!loadOnce || !this.loaded){
6146 var updater = this.bodyEl.getUpdateManager();
6147 updater.update(url, params, this._setLoaded.createDelegate(this));
6152 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
6153 * Will fail silently if the setUrl method has not been called.
6154 * This does not activate the panel, just updates its content.
6156 refresh : function(){
6157 if(this.refreshDelegate){
6158 this.loaded = false;
6159 this.refreshDelegate();
6164 _setLoaded : function(){
6169 closeClick : function(e){
6172 this.fireEvent("beforeclose", this, o);
6173 if(o.cancel !== true){
6174 this.tabPanel.removeTab(this.id);
6178 * The text displayed in the tooltip for the close icon.
6181 closeText : "Close this tab"
6185 Roo.TabPanel.prototype.createStrip = function(container){
6186 var strip = document.createElement("div");
6187 strip.className = "x-tabs-wrap";
6188 container.appendChild(strip);
6192 Roo.TabPanel.prototype.createStripList = function(strip){
6193 // div wrapper for retard IE
6194 // returns the "tr" element.
6195 strip.innerHTML = '<div class="x-tabs-strip-wrap">'+
6196 '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
6197 '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
6198 return strip.firstChild.firstChild.firstChild.firstChild;
6201 Roo.TabPanel.prototype.createBody = function(container){
6202 var body = document.createElement("div");
6203 Roo.id(body, "tab-body");
6204 Roo.fly(body).addClass("x-tabs-body");
6205 container.appendChild(body);
6209 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
6210 var body = Roo.getDom(id);
6212 body = document.createElement("div");
6215 Roo.fly(body).addClass("x-tabs-item-body");
6216 bodyEl.insertBefore(body, bodyEl.firstChild);
6220 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
6221 var td = document.createElement("td");
6222 stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
6223 //stripEl.appendChild(td);
6225 td.className = "x-tabs-closable";
6227 this.closeTpl = new Roo.Template(
6228 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
6229 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
6230 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
6233 var el = this.closeTpl.overwrite(td, {"text": text});
6234 var close = el.getElementsByTagName("div")[0];
6235 var inner = el.getElementsByTagName("em")[0];
6236 return {"el": el, "close": close, "inner": inner};
6239 this.tabTpl = new Roo.Template(
6240 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
6241 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
6244 var el = this.tabTpl.overwrite(td, {"text": text});
6245 var inner = el.getElementsByTagName("em")[0];
6246 return {"el": el, "inner": inner};
6250 * Ext JS Library 1.1.1
6251 * Copyright(c) 2006-2007, Ext JS, LLC.
6253 * Originally Released Under LGPL - original licence link has changed is not relivant.
6256 * <script type="text/javascript">
6261 * @extends Roo.util.Observable
6262 * Simple Button class
6263 * @cfg {String} text The button text
6264 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
6265 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
6266 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
6267 * @cfg {Object} scope The scope of the handler
6268 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
6269 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
6270 * @cfg {Boolean} hidden True to start hidden (defaults to false)
6271 * @cfg {Boolean} disabled True to start disabled (defaults to false)
6272 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
6273 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
6274 applies if enableToggle = true)
6275 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
6276 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
6277 an {@link Roo.util.ClickRepeater} config object (defaults to false).
6279 * Create a new button
6280 * @param {Object} config The config object
6282 Roo.Button = function(renderTo, config)
6286 renderTo = config.renderTo || false;
6289 Roo.apply(this, config);
6293 * Fires when this button is clicked
6294 * @param {Button} this
6295 * @param {EventObject} e The click event
6300 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
6301 * @param {Button} this
6302 * @param {Boolean} pressed
6307 * Fires when the mouse hovers over the button
6308 * @param {Button} this
6309 * @param {Event} e The event object
6314 * Fires when the mouse exits the button
6315 * @param {Button} this
6316 * @param {Event} e The event object
6321 * Fires when the button is rendered
6322 * @param {Button} this
6327 this.menu = Roo.menu.MenuMgr.get(this.menu);
6329 // register listeners first!! - so render can be captured..
6330 Roo.util.Observable.call(this);
6332 this.render(renderTo);
6338 Roo.extend(Roo.Button, Roo.util.Observable, {
6344 * Read-only. True if this button is hidden
6349 * Read-only. True if this button is disabled
6354 * Read-only. True if this button is pressed (only if enableToggle = true)
6360 * @cfg {Number} tabIndex
6361 * The DOM tabIndex for this button (defaults to undefined)
6363 tabIndex : undefined,
6366 * @cfg {Boolean} enableToggle
6367 * True to enable pressed/not pressed toggling (defaults to false)
6369 enableToggle: false,
6372 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
6376 * @cfg {String} menuAlign
6377 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
6379 menuAlign : "tl-bl?",
6382 * @cfg {String} iconCls
6383 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
6385 iconCls : undefined,
6387 * @cfg {String} type
6388 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
6393 menuClassTarget: 'tr',
6396 * @cfg {String} clickEvent
6397 * The type of event to map to the button's event handler (defaults to 'click')
6399 clickEvent : 'click',
6402 * @cfg {Boolean} handleMouseEvents
6403 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
6405 handleMouseEvents : true,
6408 * @cfg {String} tooltipType
6409 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
6411 tooltipType : 'qtip',
6415 * A CSS class to apply to the button's main element.
6419 * @cfg {Roo.Template} template (Optional)
6420 * An {@link Roo.Template} with which to create the Button's main element. This Template must
6421 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
6422 * require code modifications if required elements (e.g. a button) aren't present.
6426 render : function(renderTo){
6428 if(this.hideParent){
6429 this.parentEl = Roo.get(renderTo);
6433 if(!Roo.Button.buttonTemplate){
6434 // hideous table template
6435 Roo.Button.buttonTemplate = new Roo.Template(
6436 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
6437 '<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>',
6438 "</tr></tbody></table>");
6440 this.template = Roo.Button.buttonTemplate;
6442 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
6443 var btnEl = btn.child("button:first");
6444 btnEl.on('focus', this.onFocus, this);
6445 btnEl.on('blur', this.onBlur, this);
6447 btn.addClass(this.cls);
6450 btnEl.setStyle('background-image', 'url(' +this.icon +')');
6453 btnEl.addClass(this.iconCls);
6455 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
6458 if(this.tabIndex !== undefined){
6459 btnEl.dom.tabIndex = this.tabIndex;
6462 if(typeof this.tooltip == 'object'){
6463 Roo.QuickTips.tips(Roo.apply({
6467 btnEl.dom[this.tooltipType] = this.tooltip;
6471 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
6475 this.el.dom.id = this.el.id = this.id;
6478 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
6479 this.menu.on("show", this.onMenuShow, this);
6480 this.menu.on("hide", this.onMenuHide, this);
6482 btn.addClass("x-btn");
6483 if(Roo.isIE && !Roo.isIE7){
6484 this.autoWidth.defer(1, this);
6488 if(this.handleMouseEvents){
6489 btn.on("mouseover", this.onMouseOver, this);
6490 btn.on("mouseout", this.onMouseOut, this);
6491 btn.on("mousedown", this.onMouseDown, this);
6493 btn.on(this.clickEvent, this.onClick, this);
6494 //btn.on("mouseup", this.onMouseUp, this);
6501 Roo.ButtonToggleMgr.register(this);
6503 this.el.addClass("x-btn-pressed");
6506 var repeater = new Roo.util.ClickRepeater(btn,
6507 typeof this.repeat == "object" ? this.repeat : {}
6509 repeater.on("click", this.onClick, this);
6512 this.fireEvent('render', this);
6516 * Returns the button's underlying element
6517 * @return {Roo.Element} The element
6524 * Destroys this Button and removes any listeners.
6526 destroy : function(){
6527 Roo.ButtonToggleMgr.unregister(this);
6528 this.el.removeAllListeners();
6529 this.purgeListeners();
6534 autoWidth : function(){
6536 this.el.setWidth("auto");
6537 if(Roo.isIE7 && Roo.isStrict){
6538 var ib = this.el.child('button');
6539 if(ib && ib.getWidth() > 20){
6541 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
6546 this.el.beginMeasure();
6548 if(this.el.getWidth() < this.minWidth){
6549 this.el.setWidth(this.minWidth);
6552 this.el.endMeasure();
6559 * Assigns this button's click handler
6560 * @param {Function} handler The function to call when the button is clicked
6561 * @param {Object} scope (optional) Scope for the function passed in
6563 setHandler : function(handler, scope){
6564 this.handler = handler;
6569 * Sets this button's text
6570 * @param {String} text The button text
6572 setText : function(text){
6575 this.el.child("td.x-btn-center button.x-btn-text").update(text);
6581 * Gets the text for this button
6582 * @return {String} The button text
6584 getText : function(){
6592 this.hidden = false;
6594 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
6604 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
6609 * Convenience function for boolean show/hide
6610 * @param {Boolean} visible True to show, false to hide
6612 setVisible: function(visible){
6621 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
6622 * @param {Boolean} state (optional) Force a particular state
6624 toggle : function(state){
6625 state = state === undefined ? !this.pressed : state;
6626 if(state != this.pressed){
6628 this.el.addClass("x-btn-pressed");
6629 this.pressed = true;
6630 this.fireEvent("toggle", this, true);
6632 this.el.removeClass("x-btn-pressed");
6633 this.pressed = false;
6634 this.fireEvent("toggle", this, false);
6636 if(this.toggleHandler){
6637 this.toggleHandler.call(this.scope || this, this, state);
6646 this.el.child('button:first').focus();
6650 * Disable this button
6652 disable : function(){
6654 this.el.addClass("x-btn-disabled");
6656 this.disabled = true;
6660 * Enable this button
6662 enable : function(){
6664 this.el.removeClass("x-btn-disabled");
6666 this.disabled = false;
6670 * Convenience function for boolean enable/disable
6671 * @param {Boolean} enabled True to enable, false to disable
6673 setDisabled : function(v){
6674 this[v !== true ? "enable" : "disable"]();
6678 onClick : function(e)
6687 if(this.enableToggle){
6690 if(this.menu && !this.menu.isVisible()){
6691 this.menu.show(this.el, this.menuAlign);
6693 this.fireEvent("click", this, e);
6695 this.el.removeClass("x-btn-over");
6696 this.handler.call(this.scope || this, this, e);
6701 onMouseOver : function(e){
6703 this.el.addClass("x-btn-over");
6704 this.fireEvent('mouseover', this, e);
6708 onMouseOut : function(e){
6709 if(!e.within(this.el, true)){
6710 this.el.removeClass("x-btn-over");
6711 this.fireEvent('mouseout', this, e);
6715 onFocus : function(e){
6717 this.el.addClass("x-btn-focus");
6721 onBlur : function(e){
6722 this.el.removeClass("x-btn-focus");
6725 onMouseDown : function(e){
6726 if(!this.disabled && e.button == 0){
6727 this.el.addClass("x-btn-click");
6728 Roo.get(document).on('mouseup', this.onMouseUp, this);
6732 onMouseUp : function(e){
6734 this.el.removeClass("x-btn-click");
6735 Roo.get(document).un('mouseup', this.onMouseUp, this);
6739 onMenuShow : function(e){
6740 this.el.addClass("x-btn-menu-active");
6743 onMenuHide : function(e){
6744 this.el.removeClass("x-btn-menu-active");
6748 // Private utility class used by Button
6749 Roo.ButtonToggleMgr = function(){
6752 function toggleGroup(btn, state){
6754 var g = groups[btn.toggleGroup];
6755 for(var i = 0, l = g.length; i < l; i++){
6764 register : function(btn){
6765 if(!btn.toggleGroup){
6768 var g = groups[btn.toggleGroup];
6770 g = groups[btn.toggleGroup] = [];
6773 btn.on("toggle", toggleGroup);
6776 unregister : function(btn){
6777 if(!btn.toggleGroup){
6780 var g = groups[btn.toggleGroup];
6783 btn.un("toggle", toggleGroup);
6789 * Ext JS Library 1.1.1
6790 * Copyright(c) 2006-2007, Ext JS, LLC.
6792 * Originally Released Under LGPL - original licence link has changed is not relivant.
6795 * <script type="text/javascript">
6799 * @class Roo.SplitButton
6800 * @extends Roo.Button
6801 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
6802 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
6803 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
6804 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
6805 * @cfg {String} arrowTooltip The title attribute of the arrow
6807 * Create a new menu button
6808 * @param {String/HTMLElement/Element} renderTo The element to append the button to
6809 * @param {Object} config The config object
6811 Roo.SplitButton = function(renderTo, config){
6812 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
6815 * Fires when this button's arrow is clicked
6816 * @param {SplitButton} this
6817 * @param {EventObject} e The click event
6819 this.addEvents({"arrowclick":true});
6822 Roo.extend(Roo.SplitButton, Roo.Button, {
6823 render : function(renderTo){
6824 // this is one sweet looking template!
6825 var tpl = new Roo.Template(
6826 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
6827 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
6828 '<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>',
6829 "</tbody></table></td><td>",
6830 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
6831 '<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>',
6832 "</tbody></table></td></tr></table>"
6834 var btn = tpl.append(renderTo, [this.text, this.type], true);
6835 var btnEl = btn.child("button");
6837 btn.addClass(this.cls);
6840 btnEl.setStyle('background-image', 'url(' +this.icon +')');
6843 btnEl.addClass(this.iconCls);
6845 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
6849 if(this.handleMouseEvents){
6850 btn.on("mouseover", this.onMouseOver, this);
6851 btn.on("mouseout", this.onMouseOut, this);
6852 btn.on("mousedown", this.onMouseDown, this);
6853 btn.on("mouseup", this.onMouseUp, this);
6855 btn.on(this.clickEvent, this.onClick, this);
6857 if(typeof this.tooltip == 'object'){
6858 Roo.QuickTips.tips(Roo.apply({
6862 btnEl.dom[this.tooltipType] = this.tooltip;
6865 if(this.arrowTooltip){
6866 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
6875 this.el.addClass("x-btn-pressed");
6877 if(Roo.isIE && !Roo.isIE7){
6878 this.autoWidth.defer(1, this);
6883 this.menu.on("show", this.onMenuShow, this);
6884 this.menu.on("hide", this.onMenuHide, this);
6886 this.fireEvent('render', this);
6890 autoWidth : function(){
6892 var tbl = this.el.child("table:first");
6893 var tbl2 = this.el.child("table:last");
6894 this.el.setWidth("auto");
6895 tbl.setWidth("auto");
6896 if(Roo.isIE7 && Roo.isStrict){
6897 var ib = this.el.child('button:first');
6898 if(ib && ib.getWidth() > 20){
6900 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
6905 this.el.beginMeasure();
6907 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
6908 tbl.setWidth(this.minWidth-tbl2.getWidth());
6911 this.el.endMeasure();
6914 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
6918 * Sets this button's click handler
6919 * @param {Function} handler The function to call when the button is clicked
6920 * @param {Object} scope (optional) Scope for the function passed above
6922 setHandler : function(handler, scope){
6923 this.handler = handler;
6928 * Sets this button's arrow click handler
6929 * @param {Function} handler The function to call when the arrow is clicked
6930 * @param {Object} scope (optional) Scope for the function passed above
6932 setArrowHandler : function(handler, scope){
6933 this.arrowHandler = handler;
6942 this.el.child("button:first").focus();
6947 onClick : function(e){
6950 if(e.getTarget(".x-btn-menu-arrow-wrap")){
6951 if(this.menu && !this.menu.isVisible()){
6952 this.menu.show(this.el, this.menuAlign);
6954 this.fireEvent("arrowclick", this, e);
6955 if(this.arrowHandler){
6956 this.arrowHandler.call(this.scope || this, this, e);
6959 this.fireEvent("click", this, e);
6961 this.handler.call(this.scope || this, this, e);
6967 onMouseDown : function(e){
6969 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
6973 onMouseUp : function(e){
6974 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
6980 Roo.MenuButton = Roo.SplitButton;/*
6982 * Ext JS Library 1.1.1
6983 * Copyright(c) 2006-2007, Ext JS, LLC.
6985 * Originally Released Under LGPL - original licence link has changed is not relivant.
6988 * <script type="text/javascript">
6992 * @class Roo.Toolbar
6993 * Basic Toolbar class.
6995 * Creates a new Toolbar
6996 * @param {Object} container The config object
6998 Roo.Toolbar = function(container, buttons, config)
7000 /// old consturctor format still supported..
7001 if(container instanceof Array){ // omit the container for later rendering
7002 buttons = container;
7006 if (typeof(container) == 'object' && container.xtype) {
7008 container = config.container;
7009 buttons = config.buttons || []; // not really - use items!!
7012 if (config && config.items) {
7013 xitems = config.items;
7014 delete config.items;
7016 Roo.apply(this, config);
7017 this.buttons = buttons;
7020 this.render(container);
7022 this.xitems = xitems;
7023 Roo.each(xitems, function(b) {
7029 Roo.Toolbar.prototype = {
7031 * @cfg {Array} items
7032 * array of button configs or elements to add (will be converted to a MixedCollection)
7036 * @cfg {String/HTMLElement/Element} container
7037 * The id or element that will contain the toolbar
7040 render : function(ct){
7041 this.el = Roo.get(ct);
7043 this.el.addClass(this.cls);
7045 // using a table allows for vertical alignment
7046 // 100% width is needed by Safari...
7047 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
7048 this.tr = this.el.child("tr", true);
7050 this.items = new Roo.util.MixedCollection(false, function(o){
7051 return o.id || ("item" + (++autoId));
7054 this.add.apply(this, this.buttons);
7055 delete this.buttons;
7060 * Adds element(s) to the toolbar -- this function takes a variable number of
7061 * arguments of mixed type and adds them to the toolbar.
7062 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
7064 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
7065 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
7066 * <li>Field: Any form field (equivalent to {@link #addField})</li>
7067 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
7068 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
7069 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
7070 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
7071 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
7072 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
7074 * @param {Mixed} arg2
7075 * @param {Mixed} etc.
7078 var a = arguments, l = a.length;
7079 for(var i = 0; i < l; i++){
7084 _add : function(el) {
7087 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
7090 if (el.applyTo){ // some kind of form field
7091 return this.addField(el);
7093 if (el.render){ // some kind of Toolbar.Item
7094 return this.addItem(el);
7096 if (typeof el == "string"){ // string
7097 if(el == "separator" || el == "-"){
7098 return this.addSeparator();
7101 return this.addSpacer();
7104 return this.addFill();
7106 return this.addText(el);
7109 if(el.tagName){ // element
7110 return this.addElement(el);
7112 if(typeof el == "object"){ // must be button config?
7113 return this.addButton(el);
7121 * Add an Xtype element
7122 * @param {Object} xtype Xtype Object
7123 * @return {Object} created Object
7125 addxtype : function(e){
7130 * Returns the Element for this toolbar.
7131 * @return {Roo.Element}
7139 * @return {Roo.Toolbar.Item} The separator item
7141 addSeparator : function(){
7142 return this.addItem(new Roo.Toolbar.Separator());
7146 * Adds a spacer element
7147 * @return {Roo.Toolbar.Spacer} The spacer item
7149 addSpacer : function(){
7150 return this.addItem(new Roo.Toolbar.Spacer());
7154 * Adds a fill element that forces subsequent additions to the right side of the toolbar
7155 * @return {Roo.Toolbar.Fill} The fill item
7157 addFill : function(){
7158 return this.addItem(new Roo.Toolbar.Fill());
7162 * Adds any standard HTML element to the toolbar
7163 * @param {String/HTMLElement/Element} el The element or id of the element to add
7164 * @return {Roo.Toolbar.Item} The element's item
7166 addElement : function(el){
7167 return this.addItem(new Roo.Toolbar.Item(el));
7170 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
7171 * @type Roo.util.MixedCollection
7176 * Adds any Toolbar.Item or subclass
7177 * @param {Roo.Toolbar.Item} item
7178 * @return {Roo.Toolbar.Item} The item
7180 addItem : function(item){
7181 var td = this.nextBlock();
7183 this.items.add(item);
7188 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
7189 * @param {Object/Array} config A button config or array of configs
7190 * @return {Roo.Toolbar.Button/Array}
7192 addButton : function(config){
7193 if(config instanceof Array){
7195 for(var i = 0, len = config.length; i < len; i++) {
7196 buttons.push(this.addButton(config[i]));
7201 if(!(config instanceof Roo.Toolbar.Button)){
7203 new Roo.Toolbar.SplitButton(config) :
7204 new Roo.Toolbar.Button(config);
7206 var td = this.nextBlock();
7213 * Adds text to the toolbar
7214 * @param {String} text The text to add
7215 * @return {Roo.Toolbar.Item} The element's item
7217 addText : function(text){
7218 return this.addItem(new Roo.Toolbar.TextItem(text));
7222 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
7223 * @param {Number} index The index where the item is to be inserted
7224 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
7225 * @return {Roo.Toolbar.Button/Item}
7227 insertButton : function(index, item){
7228 if(item instanceof Array){
7230 for(var i = 0, len = item.length; i < len; i++) {
7231 buttons.push(this.insertButton(index + i, item[i]));
7235 if (!(item instanceof Roo.Toolbar.Button)){
7236 item = new Roo.Toolbar.Button(item);
7238 var td = document.createElement("td");
7239 this.tr.insertBefore(td, this.tr.childNodes[index]);
7241 this.items.insert(index, item);
7246 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
7247 * @param {Object} config
7248 * @return {Roo.Toolbar.Item} The element's item
7250 addDom : function(config, returnEl){
7251 var td = this.nextBlock();
7252 Roo.DomHelper.overwrite(td, config);
7253 var ti = new Roo.Toolbar.Item(td.firstChild);
7260 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
7261 * @type Roo.util.MixedCollection
7266 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc).
7267 * Note: the field should not have been rendered yet. For a field that has already been
7268 * rendered, use {@link #addElement}.
7269 * @param {Roo.form.Field} field
7270 * @return {Roo.ToolbarItem}
7274 addField : function(field) {
7277 this.fields = new Roo.util.MixedCollection(false, function(o){
7278 return o.id || ("item" + (++autoId));
7283 var td = this.nextBlock();
7285 var ti = new Roo.Toolbar.Item(td.firstChild);
7288 this.fields.add(field);
7299 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
7300 this.el.child('div').hide();
7308 this.el.child('div').show();
7312 nextBlock : function(){
7313 var td = document.createElement("td");
7314 this.tr.appendChild(td);
7319 destroy : function(){
7320 if(this.items){ // rendered?
7321 Roo.destroy.apply(Roo, this.items.items);
7323 if(this.fields){ // rendered?
7324 Roo.destroy.apply(Roo, this.fields.items);
7326 Roo.Element.uncache(this.el, this.tr);
7331 * @class Roo.Toolbar.Item
7332 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
7334 * Creates a new Item
7335 * @param {HTMLElement} el
7337 Roo.Toolbar.Item = function(el){
7339 if (typeof (el.xtype) != 'undefined') {
7344 this.el = Roo.getDom(el);
7345 this.id = Roo.id(this.el);
7346 this.hidden = false;
7351 * Fires when the button is rendered
7352 * @param {Button} this
7356 Roo.Toolbar.Item.superclass.constructor.call(this,cfg);
7358 Roo.extend(Roo.Toolbar.Item, Roo.util.Observable, {
7359 //Roo.Toolbar.Item.prototype = {
7362 * Get this item's HTML Element
7363 * @return {HTMLElement}
7370 render : function(td){
7373 td.appendChild(this.el);
7375 this.fireEvent('render', this);
7379 * Removes and destroys this item.
7381 destroy : function(){
7382 this.td.parentNode.removeChild(this.td);
7389 this.hidden = false;
7390 this.td.style.display = "";
7398 this.td.style.display = "none";
7402 * Convenience function for boolean show/hide.
7403 * @param {Boolean} visible true to show/false to hide
7405 setVisible: function(visible){
7414 * Try to focus this item.
7417 Roo.fly(this.el).focus();
7421 * Disables this item.
7423 disable : function(){
7424 Roo.fly(this.td).addClass("x-item-disabled");
7425 this.disabled = true;
7426 this.el.disabled = true;
7430 * Enables this item.
7432 enable : function(){
7433 Roo.fly(this.td).removeClass("x-item-disabled");
7434 this.disabled = false;
7435 this.el.disabled = false;
7441 * @class Roo.Toolbar.Separator
7442 * @extends Roo.Toolbar.Item
7443 * A simple toolbar separator class
7445 * Creates a new Separator
7447 Roo.Toolbar.Separator = function(cfg){
7449 var s = document.createElement("span");
7450 s.className = "ytb-sep";
7455 Roo.Toolbar.Separator.superclass.constructor.call(this, cfg || s);
7457 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
7459 disable:Roo.emptyFn,
7464 * @class Roo.Toolbar.Spacer
7465 * @extends Roo.Toolbar.Item
7466 * A simple element that adds extra horizontal space to a toolbar.
7468 * Creates a new Spacer
7470 Roo.Toolbar.Spacer = function(cfg){
7471 var s = document.createElement("div");
7472 s.className = "ytb-spacer";
7476 Roo.Toolbar.Spacer.superclass.constructor.call(this, cfg || s);
7478 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
7480 disable:Roo.emptyFn,
7485 * @class Roo.Toolbar.Fill
7486 * @extends Roo.Toolbar.Spacer
7487 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
7489 * Creates a new Spacer
7491 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
7493 render : function(td){
7494 td.style.width = '100%';
7495 Roo.Toolbar.Fill.superclass.render.call(this, td);
7500 * @class Roo.Toolbar.TextItem
7501 * @extends Roo.Toolbar.Item
7502 * A simple class that renders text directly into a toolbar.
7504 * Creates a new TextItem
7505 * @cfg {string} text
7507 Roo.Toolbar.TextItem = function(cfg){
7508 var text = cfg || "";
7509 if (typeof(cfg) == 'object') {
7510 text = cfg.text || "";
7514 var s = document.createElement("span");
7515 s.className = "ytb-text";
7521 Roo.Toolbar.TextItem.superclass.constructor.call(this, cfg || s);
7523 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
7527 disable:Roo.emptyFn,
7532 * @class Roo.Toolbar.Button
7533 * @extends Roo.Button
7534 * A button that renders into a toolbar.
7536 * Creates a new Button
7537 * @param {Object} config A standard {@link Roo.Button} config object
7539 Roo.Toolbar.Button = function(config){
7540 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
7542 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
7543 render : function(td){
7545 Roo.Toolbar.Button.superclass.render.call(this, td);
7549 * Removes and destroys this button
7551 destroy : function(){
7552 Roo.Toolbar.Button.superclass.destroy.call(this);
7553 this.td.parentNode.removeChild(this.td);
7560 this.hidden = false;
7561 this.td.style.display = "";
7569 this.td.style.display = "none";
7573 * Disables this item
7575 disable : function(){
7576 Roo.fly(this.td).addClass("x-item-disabled");
7577 this.disabled = true;
7583 enable : function(){
7584 Roo.fly(this.td).removeClass("x-item-disabled");
7585 this.disabled = false;
7589 Roo.ToolbarButton = Roo.Toolbar.Button;
7592 * @class Roo.Toolbar.SplitButton
7593 * @extends Roo.SplitButton
7594 * A menu button that renders into a toolbar.
7596 * Creates a new SplitButton
7597 * @param {Object} config A standard {@link Roo.SplitButton} config object
7599 Roo.Toolbar.SplitButton = function(config){
7600 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
7602 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
7603 render : function(td){
7605 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
7609 * Removes and destroys this button
7611 destroy : function(){
7612 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
7613 this.td.parentNode.removeChild(this.td);
7620 this.hidden = false;
7621 this.td.style.display = "";
7629 this.td.style.display = "none";
7634 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
7636 * Ext JS Library 1.1.1
7637 * Copyright(c) 2006-2007, Ext JS, LLC.
7639 * Originally Released Under LGPL - original licence link has changed is not relivant.
7642 * <script type="text/javascript">
7646 * @class Roo.PagingToolbar
7647 * @extends Roo.Toolbar
7648 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
7650 * Create a new PagingToolbar
7651 * @param {Object} config The config object
7653 Roo.PagingToolbar = function(el, ds, config)
7655 // old args format still supported... - xtype is prefered..
7656 if (typeof(el) == 'object' && el.xtype) {
7657 // created from xtype...
7660 el = config.container;
7664 items = config.items;
7668 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
7671 this.renderButtons(this.el);
7674 // supprot items array.
7676 Roo.each(items, function(e) {
7677 this.add(Roo.factory(e));
7682 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
7684 * @cfg {Roo.data.Store} dataSource
7685 * The underlying data store providing the paged data
7688 * @cfg {String/HTMLElement/Element} container
7689 * container The id or element that will contain the toolbar
7692 * @cfg {Boolean} displayInfo
7693 * True to display the displayMsg (defaults to false)
7696 * @cfg {Number} pageSize
7697 * The number of records to display per page (defaults to 20)
7701 * @cfg {String} displayMsg
7702 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
7704 displayMsg : 'Displaying {0} - {1} of {2}',
7706 * @cfg {String} emptyMsg
7707 * The message to display when no records are found (defaults to "No data to display")
7709 emptyMsg : 'No data to display',
7711 * Customizable piece of the default paging text (defaults to "Page")
7714 beforePageText : "Page",
7716 * Customizable piece of the default paging text (defaults to "of %0")
7719 afterPageText : "of {0}",
7721 * Customizable piece of the default paging text (defaults to "First Page")
7724 firstText : "First Page",
7726 * Customizable piece of the default paging text (defaults to "Previous Page")
7729 prevText : "Previous Page",
7731 * Customizable piece of the default paging text (defaults to "Next Page")
7734 nextText : "Next Page",
7736 * Customizable piece of the default paging text (defaults to "Last Page")
7739 lastText : "Last Page",
7741 * Customizable piece of the default paging text (defaults to "Refresh")
7744 refreshText : "Refresh",
7747 renderButtons : function(el){
7748 Roo.PagingToolbar.superclass.render.call(this, el);
7749 this.first = this.addButton({
7750 tooltip: this.firstText,
7751 cls: "x-btn-icon x-grid-page-first",
7753 handler: this.onClick.createDelegate(this, ["first"])
7755 this.prev = this.addButton({
7756 tooltip: this.prevText,
7757 cls: "x-btn-icon x-grid-page-prev",
7759 handler: this.onClick.createDelegate(this, ["prev"])
7761 //this.addSeparator();
7762 this.add(this.beforePageText);
7763 this.field = Roo.get(this.addDom({
7768 cls: "x-grid-page-number"
7770 this.field.on("keydown", this.onPagingKeydown, this);
7771 this.field.on("focus", function(){this.dom.select();});
7772 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
7773 this.field.setHeight(18);
7774 //this.addSeparator();
7775 this.next = this.addButton({
7776 tooltip: this.nextText,
7777 cls: "x-btn-icon x-grid-page-next",
7779 handler: this.onClick.createDelegate(this, ["next"])
7781 this.last = this.addButton({
7782 tooltip: this.lastText,
7783 cls: "x-btn-icon x-grid-page-last",
7785 handler: this.onClick.createDelegate(this, ["last"])
7787 //this.addSeparator();
7788 this.loading = this.addButton({
7789 tooltip: this.refreshText,
7790 cls: "x-btn-icon x-grid-loading",
7791 handler: this.onClick.createDelegate(this, ["refresh"])
7794 if(this.displayInfo){
7795 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
7800 updateInfo : function(){
7802 var count = this.ds.getCount();
7803 var msg = count == 0 ?
7807 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
7809 this.displayEl.update(msg);
7814 onLoad : function(ds, r, o){
7815 this.cursor = o.params ? o.params.start : 0;
7816 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
7818 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
7819 this.field.dom.value = ap;
7820 this.first.setDisabled(ap == 1);
7821 this.prev.setDisabled(ap == 1);
7822 this.next.setDisabled(ap == ps);
7823 this.last.setDisabled(ap == ps);
7824 this.loading.enable();
7829 getPageData : function(){
7830 var total = this.ds.getTotalCount();
7833 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
7834 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
7839 onLoadError : function(){
7840 this.loading.enable();
7844 onPagingKeydown : function(e){
7846 var d = this.getPageData();
7848 var v = this.field.dom.value, pageNum;
7849 if(!v || isNaN(pageNum = parseInt(v, 10))){
7850 this.field.dom.value = d.activePage;
7853 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
7854 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
7857 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))
7859 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
7860 this.field.dom.value = pageNum;
7861 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
7864 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
7866 var v = this.field.dom.value, pageNum;
7867 var increment = (e.shiftKey) ? 10 : 1;
7868 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
7871 if(!v || isNaN(pageNum = parseInt(v, 10))) {
7872 this.field.dom.value = d.activePage;
7875 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
7877 this.field.dom.value = parseInt(v, 10) + increment;
7878 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
7879 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
7886 beforeLoad : function(){
7888 this.loading.disable();
7893 onClick : function(which){
7897 ds.load({params:{start: 0, limit: this.pageSize}});
7900 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
7903 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
7906 var total = ds.getTotalCount();
7907 var extra = total % this.pageSize;
7908 var lastStart = extra ? (total - extra) : total-this.pageSize;
7909 ds.load({params:{start: lastStart, limit: this.pageSize}});
7912 ds.load({params:{start: this.cursor, limit: this.pageSize}});
7918 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
7919 * @param {Roo.data.Store} store The data store to unbind
7921 unbind : function(ds){
7922 ds.un("beforeload", this.beforeLoad, this);
7923 ds.un("load", this.onLoad, this);
7924 ds.un("loadexception", this.onLoadError, this);
7925 ds.un("remove", this.updateInfo, this);
7926 ds.un("add", this.updateInfo, this);
7927 this.ds = undefined;
7931 * Binds the paging toolbar to the specified {@link Roo.data.Store}
7932 * @param {Roo.data.Store} store The data store to bind
7934 bind : function(ds){
7935 ds.on("beforeload", this.beforeLoad, this);
7936 ds.on("load", this.onLoad, this);
7937 ds.on("loadexception", this.onLoadError, this);
7938 ds.on("remove", this.updateInfo, this);
7939 ds.on("add", this.updateInfo, this);
7944 * Ext JS Library 1.1.1
7945 * Copyright(c) 2006-2007, Ext JS, LLC.
7947 * Originally Released Under LGPL - original licence link has changed is not relivant.
7950 * <script type="text/javascript">
7954 * @class Roo.Resizable
7955 * @extends Roo.util.Observable
7956 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
7957 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
7958 * 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
7959 * the element will be wrapped for you automatically.</p>
7960 * <p>Here is the list of valid resize handles:</p>
7963 ------ -------------------
7972 'hd' horizontal drag
7975 * <p>Here's an example showing the creation of a typical Resizable:</p>
7977 var resizer = new Roo.Resizable("element-id", {
7985 resizer.on("resize", myHandler);
7987 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
7988 * resizer.east.setDisplayed(false);</p>
7989 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
7990 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
7991 * resize operation's new size (defaults to [0, 0])
7992 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
7993 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
7994 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
7995 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
7996 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
7997 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
7998 * @cfg {Number} width The width of the element in pixels (defaults to null)
7999 * @cfg {Number} height The height of the element in pixels (defaults to null)
8000 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
8001 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
8002 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
8003 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
8004 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
8005 * in favor of the handles config option (defaults to false)
8006 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
8007 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
8008 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
8009 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
8010 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
8011 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
8012 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
8013 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
8014 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
8015 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
8016 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
8018 * Create a new resizable component
8019 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
8020 * @param {Object} config configuration options
8022 Roo.Resizable = function(el, config)
8024 this.el = Roo.get(el);
8026 if(config && config.wrap){
8027 config.resizeChild = this.el;
8028 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
8029 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
8030 this.el.setStyle("overflow", "hidden");
8031 this.el.setPositioning(config.resizeChild.getPositioning());
8032 config.resizeChild.clearPositioning();
8033 if(!config.width || !config.height){
8034 var csize = config.resizeChild.getSize();
8035 this.el.setSize(csize.width, csize.height);
8037 if(config.pinned && !config.adjustments){
8038 config.adjustments = "auto";
8042 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
8043 this.proxy.unselectable();
8044 this.proxy.enableDisplayMode('block');
8046 Roo.apply(this, config);
8049 this.disableTrackOver = true;
8050 this.el.addClass("x-resizable-pinned");
8052 // if the element isn't positioned, make it relative
8053 var position = this.el.getStyle("position");
8054 if(position != "absolute" && position != "fixed"){
8055 this.el.setStyle("position", "relative");
8057 if(!this.handles){ // no handles passed, must be legacy style
8058 this.handles = 's,e,se';
8059 if(this.multiDirectional){
8060 this.handles += ',n,w';
8063 if(this.handles == "all"){
8064 this.handles = "n s e w ne nw se sw";
8066 var hs = this.handles.split(/\s*?[,;]\s*?| /);
8067 var ps = Roo.Resizable.positions;
8068 for(var i = 0, len = hs.length; i < len; i++){
8069 if(hs[i] && ps[hs[i]]){
8070 var pos = ps[hs[i]];
8071 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
8075 this.corner = this.southeast;
8077 // updateBox = the box can move..
8078 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1 || this.handles.indexOf("hd") != -1) {
8079 this.updateBox = true;
8082 this.activeHandle = null;
8084 if(this.resizeChild){
8085 if(typeof this.resizeChild == "boolean"){
8086 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
8088 this.resizeChild = Roo.get(this.resizeChild, true);
8092 if(this.adjustments == "auto"){
8093 var rc = this.resizeChild;
8094 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
8095 if(rc && (hw || hn)){
8096 rc.position("relative");
8097 rc.setLeft(hw ? hw.el.getWidth() : 0);
8098 rc.setTop(hn ? hn.el.getHeight() : 0);
8100 this.adjustments = [
8101 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
8102 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
8107 this.dd = this.dynamic ?
8108 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
8109 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
8115 * @event beforeresize
8116 * Fired before resize is allowed. Set enabled to false to cancel resize.
8117 * @param {Roo.Resizable} this
8118 * @param {Roo.EventObject} e The mousedown event
8120 "beforeresize" : true,
8124 * @param {Roo.Resizable} this
8125 * @param {Number} x The new x position
8126 * @param {Number} y The new y position
8127 * @param {Number} w The new w width
8128 * @param {Number} h The new h hight
8129 * @param {Roo.EventObject} e The mouseup event
8134 * Fired after a resize.
8135 * @param {Roo.Resizable} this
8136 * @param {Number} width The new width
8137 * @param {Number} height The new height
8138 * @param {Roo.EventObject} e The mouseup event
8143 if(this.width !== null && this.height !== null){
8144 this.resizeTo(this.width, this.height);
8146 this.updateChildSize();
8149 this.el.dom.style.zoom = 1;
8151 Roo.Resizable.superclass.constructor.call(this);
8154 Roo.extend(Roo.Resizable, Roo.util.Observable, {
8155 resizeChild : false,
8156 adjustments : [0, 0],
8166 multiDirectional : false,
8167 disableTrackOver : false,
8168 easing : 'easeOutStrong',
8170 heightIncrement : 0,
8174 preserveRatio : false,
8181 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
8183 constrainTo: undefined,
8185 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
8187 resizeRegion: undefined,
8191 * Perform a manual resize
8192 * @param {Number} width
8193 * @param {Number} height
8195 resizeTo : function(width, height){
8196 this.el.setSize(width, height);
8197 this.updateChildSize();
8198 this.fireEvent("resize", this, width, height, null);
8202 startSizing : function(e, handle){
8203 this.fireEvent("beforeresize", this, e);
8204 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
8207 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
8208 this.overlay.unselectable();
8209 this.overlay.enableDisplayMode("block");
8210 this.overlay.on("mousemove", this.onMouseMove, this);
8211 this.overlay.on("mouseup", this.onMouseUp, this);
8213 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
8215 this.resizing = true;
8216 this.startBox = this.el.getBox();
8217 this.startPoint = e.getXY();
8218 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
8219 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
8221 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
8222 this.overlay.show();
8224 if(this.constrainTo) {
8225 var ct = Roo.get(this.constrainTo);
8226 this.resizeRegion = ct.getRegion().adjust(
8227 ct.getFrameWidth('t'),
8228 ct.getFrameWidth('l'),
8229 -ct.getFrameWidth('b'),
8230 -ct.getFrameWidth('r')
8234 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
8236 this.proxy.setBox(this.startBox);
8238 this.proxy.setStyle('visibility', 'visible');
8244 onMouseDown : function(handle, e){
8247 this.activeHandle = handle;
8248 this.startSizing(e, handle);
8253 onMouseUp : function(e){
8254 var size = this.resizeElement();
8255 this.resizing = false;
8257 this.overlay.hide();
8259 this.fireEvent("resize", this, size.width, size.height, e);
8263 updateChildSize : function(){
8265 if(this.resizeChild){
8267 var child = this.resizeChild;
8268 var adj = this.adjustments;
8269 if(el.dom.offsetWidth){
8270 var b = el.getSize(true);
8271 child.setSize(b.width+adj[0], b.height+adj[1]);
8273 // Second call here for IE
8274 // The first call enables instant resizing and
8275 // the second call corrects scroll bars if they
8278 setTimeout(function(){
8279 if(el.dom.offsetWidth){
8280 var b = el.getSize(true);
8281 child.setSize(b.width+adj[0], b.height+adj[1]);
8289 snap : function(value, inc, min){
8290 if(!inc || !value) {
8293 var newValue = value;
8294 var m = value % inc;
8297 newValue = value + (inc-m);
8299 newValue = value - m;
8302 return Math.max(min, newValue);
8306 resizeElement : function(){
8307 var box = this.proxy.getBox();
8309 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
8311 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
8313 this.updateChildSize();
8321 constrain : function(v, diff, m, mx){
8324 }else if(v - diff > mx){
8331 onMouseMove : function(e){
8334 try{// try catch so if something goes wrong the user doesn't get hung
8336 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
8340 //var curXY = this.startPoint;
8341 var curSize = this.curSize || this.startBox;
8342 var x = this.startBox.x, y = this.startBox.y;
8344 var w = curSize.width, h = curSize.height;
8346 var mw = this.minWidth, mh = this.minHeight;
8347 var mxw = this.maxWidth, mxh = this.maxHeight;
8348 var wi = this.widthIncrement;
8349 var hi = this.heightIncrement;
8351 var eventXY = e.getXY();
8352 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
8353 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
8355 var pos = this.activeHandle.position;
8360 w = Math.min(Math.max(mw, w), mxw);
8365 h = Math.min(Math.max(mh, h), mxh);
8370 w = Math.min(Math.max(mw, w), mxw);
8371 h = Math.min(Math.max(mh, h), mxh);
8374 diffY = this.constrain(h, diffY, mh, mxh);
8381 var adiffX = Math.abs(diffX);
8382 var sub = (adiffX % wi); // how much
8383 if (sub > (wi/2)) { // far enough to snap
8384 diffX = (diffX > 0) ? diffX-sub + wi : diffX+sub - wi;
8386 // remove difference..
8387 diffX = (diffX > 0) ? diffX-sub : diffX+sub;
8391 x = Math.max(this.minX, x);
8394 diffX = this.constrain(w, diffX, mw, mxw);
8400 w = Math.min(Math.max(mw, w), mxw);
8401 diffY = this.constrain(h, diffY, mh, mxh);
8406 diffX = this.constrain(w, diffX, mw, mxw);
8407 diffY = this.constrain(h, diffY, mh, mxh);
8414 diffX = this.constrain(w, diffX, mw, mxw);
8416 h = Math.min(Math.max(mh, h), mxh);
8422 var sw = this.snap(w, wi, mw);
8423 var sh = this.snap(h, hi, mh);
8424 if(sw != w || sh != h){
8447 if(this.preserveRatio){
8452 h = Math.min(Math.max(mh, h), mxh);
8457 w = Math.min(Math.max(mw, w), mxw);
8462 w = Math.min(Math.max(mw, w), mxw);
8468 w = Math.min(Math.max(mw, w), mxw);
8474 h = Math.min(Math.max(mh, h), mxh);
8482 h = Math.min(Math.max(mh, h), mxh);
8492 h = Math.min(Math.max(mh, h), mxh);
8500 if (pos == 'hdrag') {
8503 this.proxy.setBounds(x, y, w, h);
8505 this.resizeElement();
8509 this.fireEvent("resizing", this, x, y, w, h, e);
8513 handleOver : function(){
8515 this.el.addClass("x-resizable-over");
8520 handleOut : function(){
8522 this.el.removeClass("x-resizable-over");
8527 * Returns the element this component is bound to.
8528 * @return {Roo.Element}
8535 * Returns the resizeChild element (or null).
8536 * @return {Roo.Element}
8538 getResizeChild : function(){
8539 return this.resizeChild;
8541 groupHandler : function()
8546 * Destroys this resizable. If the element was wrapped and
8547 * removeEl is not true then the element remains.
8548 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
8550 destroy : function(removeEl){
8551 this.proxy.remove();
8553 this.overlay.removeAllListeners();
8554 this.overlay.remove();
8556 var ps = Roo.Resizable.positions;
8558 if(typeof ps[k] != "function" && this[ps[k]]){
8559 var h = this[ps[k]];
8560 h.el.removeAllListeners();
8572 // hash to map config positions to true positions
8573 Roo.Resizable.positions = {
8574 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast",
8579 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
8581 // only initialize the template if resizable is used
8582 var tpl = Roo.DomHelper.createTemplate(
8583 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
8586 Roo.Resizable.Handle.prototype.tpl = tpl;
8588 this.position = pos;
8590 // show north drag fro topdra
8591 var handlepos = pos == 'hdrag' ? 'north' : pos;
8593 this.el = this.tpl.append(rz.el.dom, [handlepos], true);
8594 if (pos == 'hdrag') {
8595 this.el.setStyle('cursor', 'pointer');
8597 this.el.unselectable();
8599 this.el.setOpacity(0);
8601 this.el.on("mousedown", this.onMouseDown, this);
8602 if(!disableTrackOver){
8603 this.el.on("mouseover", this.onMouseOver, this);
8604 this.el.on("mouseout", this.onMouseOut, this);
8609 Roo.Resizable.Handle.prototype = {
8610 afterResize : function(rz){
8615 onMouseDown : function(e){
8616 this.rz.onMouseDown(this, e);
8619 onMouseOver : function(e){
8620 this.rz.handleOver(this, e);
8623 onMouseOut : function(e){
8624 this.rz.handleOut(this, e);
8628 * Ext JS Library 1.1.1
8629 * Copyright(c) 2006-2007, Ext JS, LLC.
8631 * Originally Released Under LGPL - original licence link has changed is not relivant.
8634 * <script type="text/javascript">
8639 * @extends Roo.Component
8640 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
8642 * Create a new Editor
8643 * @param {Roo.form.Field} field The Field object (or descendant)
8644 * @param {Object} config The config object
8646 Roo.Editor = function(field, config){
8647 Roo.Editor.superclass.constructor.call(this, config);
8651 * @event beforestartedit
8652 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
8653 * false from the handler of this event.
8654 * @param {Editor} this
8655 * @param {Roo.Element} boundEl The underlying element bound to this editor
8656 * @param {Mixed} value The field value being set
8658 "beforestartedit" : true,
8661 * Fires when this editor is displayed
8662 * @param {Roo.Element} boundEl The underlying element bound to this editor
8663 * @param {Mixed} value The starting field value
8667 * @event beforecomplete
8668 * Fires after a change has been made to the field, but before the change is reflected in the underlying
8669 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
8670 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
8671 * event will not fire since no edit actually occurred.
8672 * @param {Editor} this
8673 * @param {Mixed} value The current field value
8674 * @param {Mixed} startValue The original field value
8676 "beforecomplete" : true,
8679 * Fires after editing is complete and any changed value has been written to the underlying field.
8680 * @param {Editor} this
8681 * @param {Mixed} value The current field value
8682 * @param {Mixed} startValue The original field value
8687 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8688 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8689 * @param {Roo.form.Field} this
8690 * @param {Roo.EventObject} e The event object
8696 Roo.extend(Roo.Editor, Roo.Component, {
8698 * @cfg {Boolean/String} autosize
8699 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
8700 * or "height" to adopt the height only (defaults to false)
8703 * @cfg {Boolean} revertInvalid
8704 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
8705 * validation fails (defaults to true)
8708 * @cfg {Boolean} ignoreNoChange
8709 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
8710 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
8711 * will never be ignored.
8714 * @cfg {Boolean} hideEl
8715 * False to keep the bound element visible while the editor is displayed (defaults to true)
8718 * @cfg {Mixed} value
8719 * The data value of the underlying field (defaults to "")
8723 * @cfg {String} alignment
8724 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
8728 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
8729 * for bottom-right shadow (defaults to "frame")
8733 * @cfg {Boolean} constrain True to constrain the editor to the viewport
8737 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
8739 completeOnEnter : false,
8741 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
8743 cancelOnEsc : false,
8745 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
8750 onRender : function(ct, position){
8751 this.el = new Roo.Layer({
8752 shadow: this.shadow,
8758 constrain: this.constrain
8760 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
8761 if(this.field.msgTarget != 'title'){
8762 this.field.msgTarget = 'qtip';
8764 this.field.render(this.el);
8766 this.field.el.dom.setAttribute('autocomplete', 'off');
8768 this.field.on("specialkey", this.onSpecialKey, this);
8769 if(this.swallowKeys){
8770 this.field.el.swallowEvent(['keydown','keypress']);
8773 this.field.on("blur", this.onBlur, this);
8774 if(this.field.grow){
8775 this.field.on("autosize", this.el.sync, this.el, {delay:1});
8779 onSpecialKey : function(field, e)
8781 //Roo.log('editor onSpecialKey');
8782 if(this.completeOnEnter && e.getKey() == e.ENTER){
8784 this.completeEdit();
8787 // do not fire special key otherwise it might hide close the editor...
8788 if(e.getKey() == e.ENTER){
8791 if(this.cancelOnEsc && e.getKey() == e.ESC){
8795 this.fireEvent('specialkey', field, e);
8800 * Starts the editing process and shows the editor.
8801 * @param {String/HTMLElement/Element} el The element to edit
8802 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
8803 * to the innerHTML of el.
8805 startEdit : function(el, value){
8807 this.completeEdit();
8809 this.boundEl = Roo.get(el);
8810 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
8812 this.render(this.parentEl || document.body);
8814 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
8817 this.startValue = v;
8818 this.field.setValue(v);
8820 var sz = this.boundEl.getSize();
8821 switch(this.autoSize){
8823 this.setSize(sz.width, "");
8826 this.setSize("", sz.height);
8829 this.setSize(sz.width, sz.height);
8832 this.el.alignTo(this.boundEl, this.alignment);
8833 this.editing = true;
8835 Roo.QuickTips.disable();
8841 * Sets the height and width of this editor.
8842 * @param {Number} width The new width
8843 * @param {Number} height The new height
8845 setSize : function(w, h){
8846 this.field.setSize(w, h);
8853 * Realigns the editor to the bound field based on the current alignment config value.
8855 realign : function(){
8856 this.el.alignTo(this.boundEl, this.alignment);
8860 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
8861 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
8863 completeEdit : function(remainVisible){
8867 var v = this.getValue();
8868 if(this.revertInvalid !== false && !this.field.isValid()){
8869 v = this.startValue;
8870 this.cancelEdit(true);
8872 if(String(v) === String(this.startValue) && this.ignoreNoChange){
8873 this.editing = false;
8877 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
8878 this.editing = false;
8879 if(this.updateEl && this.boundEl){
8880 this.boundEl.update(v);
8882 if(remainVisible !== true){
8885 this.fireEvent("complete", this, v, this.startValue);
8890 onShow : function(){
8892 if(this.hideEl !== false){
8893 this.boundEl.hide();
8896 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
8897 this.fixIEFocus = true;
8898 this.deferredFocus.defer(50, this);
8902 this.fireEvent("startedit", this.boundEl, this.startValue);
8905 deferredFocus : function(){
8912 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
8913 * reverted to the original starting value.
8914 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
8915 * cancel (defaults to false)
8917 cancelEdit : function(remainVisible){
8919 this.setValue(this.startValue);
8920 if(remainVisible !== true){
8927 onBlur : function(){
8928 if(this.allowBlur !== true && this.editing){
8929 this.completeEdit();
8934 onHide : function(){
8936 this.completeEdit();
8940 if(this.field.collapse){
8941 this.field.collapse();
8944 if(this.hideEl !== false){
8945 this.boundEl.show();
8948 Roo.QuickTips.enable();
8953 * Sets the data value of the editor
8954 * @param {Mixed} value Any valid value supported by the underlying field
8956 setValue : function(v){
8957 this.field.setValue(v);
8961 * Gets the data value of the editor
8962 * @return {Mixed} The data value
8964 getValue : function(){
8965 return this.field.getValue();
8969 * Ext JS Library 1.1.1
8970 * Copyright(c) 2006-2007, Ext JS, LLC.
8972 * Originally Released Under LGPL - original licence link has changed is not relivant.
8975 * <script type="text/javascript">
8979 * @class Roo.BasicDialog
8980 * @extends Roo.util.Observable
8981 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
8983 var dlg = new Roo.BasicDialog("my-dlg", {
8992 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
8993 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
8994 dlg.addButton('Cancel', dlg.hide, dlg);
8997 <b>A Dialog should always be a direct child of the body element.</b>
8998 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
8999 * @cfg {String} title Default text to display in the title bar (defaults to null)
9000 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
9001 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
9002 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
9003 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
9004 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
9005 * (defaults to null with no animation)
9006 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
9007 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
9008 * property for valid values (defaults to 'all')
9009 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
9010 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
9011 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
9012 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
9013 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
9014 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
9015 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
9016 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
9017 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
9018 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
9019 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
9020 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
9021 * draggable = true (defaults to false)
9022 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
9023 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
9024 * shadow (defaults to false)
9025 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
9026 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
9027 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
9028 * @cfg {Array} buttons Array of buttons
9029 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
9031 * Create a new BasicDialog.
9032 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
9033 * @param {Object} config Configuration options
9035 Roo.BasicDialog = function(el, config){
9036 this.el = Roo.get(el);
9037 var dh = Roo.DomHelper;
9038 if(!this.el && config && config.autoCreate){
9039 if(typeof config.autoCreate == "object"){
9040 if(!config.autoCreate.id){
9041 config.autoCreate.id = el;
9043 this.el = dh.append(document.body,
9044 config.autoCreate, true);
9046 this.el = dh.append(document.body,
9047 {tag: "div", id: el, style:'visibility:hidden;'}, true);
9051 el.setDisplayed(true);
9052 el.hide = this.hideAction;
9054 el.addClass("x-dlg");
9056 Roo.apply(this, config);
9058 this.proxy = el.createProxy("x-dlg-proxy");
9059 this.proxy.hide = this.hideAction;
9060 this.proxy.setOpacity(.5);
9064 el.setWidth(config.width);
9067 el.setHeight(config.height);
9069 this.size = el.getSize();
9070 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
9071 this.xy = [config.x,config.y];
9073 this.xy = el.getCenterXY(true);
9075 /** The header element @type Roo.Element */
9076 this.header = el.child("> .x-dlg-hd");
9077 /** The body element @type Roo.Element */
9078 this.body = el.child("> .x-dlg-bd");
9079 /** The footer element @type Roo.Element */
9080 this.footer = el.child("> .x-dlg-ft");
9083 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
9086 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
9089 this.header.unselectable();
9091 this.header.update(this.title);
9093 // this element allows the dialog to be focused for keyboard event
9094 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
9095 this.focusEl.swallowEvent("click", true);
9097 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
9099 // wrap the body and footer for special rendering
9100 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
9102 this.bwrap.dom.appendChild(this.footer.dom);
9105 this.bg = this.el.createChild({
9106 tag: "div", cls:"x-dlg-bg",
9107 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
9109 this.centerBg = this.bg.child("div.x-dlg-bg-center");
9112 if(this.autoScroll !== false && !this.autoTabs){
9113 this.body.setStyle("overflow", "auto");
9116 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
9118 if(this.closable !== false){
9119 this.el.addClass("x-dlg-closable");
9120 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
9121 this.close.on("click", this.closeClick, this);
9122 this.close.addClassOnOver("x-dlg-close-over");
9124 if(this.collapsible !== false){
9125 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
9126 this.collapseBtn.on("click", this.collapseClick, this);
9127 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
9128 this.header.on("dblclick", this.collapseClick, this);
9130 if(this.resizable !== false){
9131 this.el.addClass("x-dlg-resizable");
9132 this.resizer = new Roo.Resizable(el, {
9133 minWidth: this.minWidth || 80,
9134 minHeight:this.minHeight || 80,
9135 handles: this.resizeHandles || "all",
9138 this.resizer.on("beforeresize", this.beforeResize, this);
9139 this.resizer.on("resize", this.onResize, this);
9141 if(this.draggable !== false){
9142 el.addClass("x-dlg-draggable");
9143 if (!this.proxyDrag) {
9144 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
9147 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
9149 dd.setHandleElId(this.header.id);
9150 dd.endDrag = this.endMove.createDelegate(this);
9151 dd.startDrag = this.startMove.createDelegate(this);
9152 dd.onDrag = this.onDrag.createDelegate(this);
9157 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
9158 this.mask.enableDisplayMode("block");
9160 this.el.addClass("x-dlg-modal");
9163 this.shadow = new Roo.Shadow({
9164 mode : typeof this.shadow == "string" ? this.shadow : "sides",
9165 offset : this.shadowOffset
9168 this.shadowOffset = 0;
9170 if(Roo.useShims && this.shim !== false){
9171 this.shim = this.el.createShim();
9172 this.shim.hide = this.hideAction;
9181 var bts= this.buttons;
9183 Roo.each(bts, function(b) {
9192 * Fires when a key is pressed
9193 * @param {Roo.BasicDialog} this
9194 * @param {Roo.EventObject} e
9199 * Fires when this dialog is moved by the user.
9200 * @param {Roo.BasicDialog} this
9201 * @param {Number} x The new page X
9202 * @param {Number} y The new page Y
9207 * Fires when this dialog is resized by the user.
9208 * @param {Roo.BasicDialog} this
9209 * @param {Number} width The new width
9210 * @param {Number} height The new height
9215 * Fires before this dialog is hidden.
9216 * @param {Roo.BasicDialog} this
9218 "beforehide" : true,
9221 * Fires when this dialog is hidden.
9222 * @param {Roo.BasicDialog} this
9227 * Fires before this dialog is shown.
9228 * @param {Roo.BasicDialog} this
9230 "beforeshow" : true,
9233 * Fires when this dialog is shown.
9234 * @param {Roo.BasicDialog} this
9238 el.on("keydown", this.onKeyDown, this);
9239 el.on("mousedown", this.toFront, this);
9240 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
9242 Roo.DialogManager.register(this);
9243 Roo.BasicDialog.superclass.constructor.call(this);
9246 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
9247 shadowOffset: Roo.isIE ? 6 : 5,
9251 defaultButton: null,
9252 buttonAlign: "right",
9257 * Sets the dialog title text
9258 * @param {String} text The title text to display
9259 * @return {Roo.BasicDialog} this
9261 setTitle : function(text){
9262 this.header.update(text);
9267 closeClick : function(){
9272 collapseClick : function(){
9273 this[this.collapsed ? "expand" : "collapse"]();
9277 * Collapses the dialog to its minimized state (only the title bar is visible).
9278 * Equivalent to the user clicking the collapse dialog button.
9280 collapse : function(){
9281 if(!this.collapsed){
9282 this.collapsed = true;
9283 this.el.addClass("x-dlg-collapsed");
9284 this.restoreHeight = this.el.getHeight();
9285 this.resizeTo(this.el.getWidth(), this.header.getHeight());
9290 * Expands a collapsed dialog back to its normal state. Equivalent to the user
9291 * clicking the expand dialog button.
9293 expand : function(){
9295 this.collapsed = false;
9296 this.el.removeClass("x-dlg-collapsed");
9297 this.resizeTo(this.el.getWidth(), this.restoreHeight);
9302 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
9303 * @return {Roo.TabPanel} The tabs component
9305 initTabs : function(){
9306 var tabs = this.getTabs();
9307 while(tabs.getTab(0)){
9310 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
9312 tabs.addTab(Roo.id(dom), dom.title);
9320 beforeResize : function(){
9321 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
9325 onResize : function(){
9327 this.syncBodyHeight();
9328 this.adjustAssets();
9330 this.fireEvent("resize", this, this.size.width, this.size.height);
9334 onKeyDown : function(e){
9335 if(this.isVisible()){
9336 this.fireEvent("keydown", this, e);
9341 * Resizes the dialog.
9342 * @param {Number} width
9343 * @param {Number} height
9344 * @return {Roo.BasicDialog} this
9346 resizeTo : function(width, height){
9347 this.el.setSize(width, height);
9348 this.size = {width: width, height: height};
9349 this.syncBodyHeight();
9350 if(this.fixedcenter){
9353 if(this.isVisible()){
9355 this.adjustAssets();
9357 this.fireEvent("resize", this, width, height);
9363 * Resizes the dialog to fit the specified content size.
9364 * @param {Number} width
9365 * @param {Number} height
9366 * @return {Roo.BasicDialog} this
9368 setContentSize : function(w, h){
9369 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
9370 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
9371 //if(!this.el.isBorderBox()){
9372 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
9373 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
9376 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
9377 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
9379 this.resizeTo(w, h);
9384 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
9385 * executed in response to a particular key being pressed while the dialog is active.
9386 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
9387 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9388 * @param {Function} fn The function to call
9389 * @param {Object} scope (optional) The scope of the function
9390 * @return {Roo.BasicDialog} this
9392 addKeyListener : function(key, fn, scope){
9393 var keyCode, shift, ctrl, alt;
9394 if(typeof key == "object" && !(key instanceof Array)){
9395 keyCode = key["key"];
9396 shift = key["shift"];
9402 var handler = function(dlg, e){
9403 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
9405 if(keyCode instanceof Array){
9406 for(var i = 0, len = keyCode.length; i < len; i++){
9407 if(keyCode[i] == k){
9408 fn.call(scope || window, dlg, k, e);
9414 fn.call(scope || window, dlg, k, e);
9419 this.on("keydown", handler);
9424 * Returns the TabPanel component (creates it if it doesn't exist).
9425 * Note: If you wish to simply check for the existence of tabs without creating them,
9426 * check for a null 'tabs' property.
9427 * @return {Roo.TabPanel} The tabs component
9429 getTabs : function(){
9431 this.el.addClass("x-dlg-auto-tabs");
9432 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
9433 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
9439 * Adds a button to the footer section of the dialog.
9440 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
9441 * object or a valid Roo.DomHelper element config
9442 * @param {Function} handler The function called when the button is clicked
9443 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
9444 * @return {Roo.Button} The new button
9446 addButton : function(config, handler, scope){
9447 var dh = Roo.DomHelper;
9449 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
9451 if(!this.btnContainer){
9452 var tb = this.footer.createChild({
9454 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
9455 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
9457 this.btnContainer = tb.firstChild.firstChild.firstChild;
9462 minWidth: this.minButtonWidth,
9465 if(typeof config == "string"){
9466 bconfig.text = config;
9469 bconfig.dhconfig = config;
9471 Roo.apply(bconfig, config);
9475 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
9476 bconfig.position = Math.max(0, bconfig.position);
9477 fc = this.btnContainer.childNodes[bconfig.position];
9480 var btn = new Roo.Button(
9482 this.btnContainer.insertBefore(document.createElement("td"),fc)
9483 : this.btnContainer.appendChild(document.createElement("td")),
9484 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
9487 this.syncBodyHeight();
9490 * Array of all the buttons that have been added to this dialog via addButton
9495 this.buttons.push(btn);
9500 * Sets the default button to be focused when the dialog is displayed.
9501 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
9502 * @return {Roo.BasicDialog} this
9504 setDefaultButton : function(btn){
9505 this.defaultButton = btn;
9510 getHeaderFooterHeight : function(safe){
9513 height += this.header.getHeight();
9516 var fm = this.footer.getMargins();
9517 height += (this.footer.getHeight()+fm.top+fm.bottom);
9519 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
9520 height += this.centerBg.getPadding("tb");
9525 syncBodyHeight : function()
9527 var bd = this.body, // the text
9528 cb = this.centerBg, // wrapper around bottom.. but does not seem to be used..
9530 var height = this.size.height - this.getHeaderFooterHeight(false);
9531 bd.setHeight(height-bd.getMargins("tb"));
9532 var hh = this.header.getHeight();
9533 var h = this.size.height-hh;
9536 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
9537 bw.setHeight(h-cb.getPadding("tb"));
9539 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
9540 bd.setWidth(bw.getWidth(true));
9542 this.tabs.syncHeight();
9544 this.tabs.el.repaint();
9550 * Restores the previous state of the dialog if Roo.state is configured.
9551 * @return {Roo.BasicDialog} this
9553 restoreState : function(){
9554 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
9555 if(box && box.width){
9556 this.xy = [box.x, box.y];
9557 this.resizeTo(box.width, box.height);
9563 beforeShow : function(){
9565 if(this.fixedcenter){
9566 this.xy = this.el.getCenterXY(true);
9569 Roo.get(document.body).addClass("x-body-masked");
9570 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
9577 animShow : function(){
9578 var b = Roo.get(this.animateTarget).getBox();
9579 this.proxy.setSize(b.width, b.height);
9580 this.proxy.setLocation(b.x, b.y);
9582 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
9583 true, .35, this.showEl.createDelegate(this));
9588 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
9589 * @return {Roo.BasicDialog} this
9591 show : function(animateTarget){
9592 if (this.fireEvent("beforeshow", this) === false){
9595 if(this.syncHeightBeforeShow){
9596 this.syncBodyHeight();
9597 }else if(this.firstShow){
9598 this.firstShow = false;
9599 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
9601 this.animateTarget = animateTarget || this.animateTarget;
9602 if(!this.el.isVisible()){
9604 if(this.animateTarget && Roo.get(this.animateTarget)){
9614 showEl : function(){
9616 this.el.setXY(this.xy);
9618 this.adjustAssets(true);
9621 // IE peekaboo bug - fix found by Dave Fenwick
9625 this.fireEvent("show", this);
9629 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
9630 * dialog itself will receive focus.
9633 if(this.defaultButton){
9634 this.defaultButton.focus();
9636 this.focusEl.focus();
9641 constrainXY : function(){
9642 if(this.constraintoviewport !== false){
9645 var s = this.container.getSize();
9646 this.viewSize = [s.width, s.height];
9648 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
9651 var s = Roo.get(this.container||document).getScroll();
9653 var x = this.xy[0], y = this.xy[1];
9654 var w = this.size.width, h = this.size.height;
9655 var vw = this.viewSize[0], vh = this.viewSize[1];
9656 // only move it if it needs it
9658 // first validate right/bottom
9659 if(x + w > vw+s.left){
9663 if(y + h > vh+s.top){
9667 // then make sure top/left isn't negative
9679 if(this.isVisible()){
9680 this.el.setLocation(x, y);
9681 this.adjustAssets();
9688 onDrag : function(){
9689 if(!this.proxyDrag){
9690 this.xy = this.el.getXY();
9691 this.adjustAssets();
9696 adjustAssets : function(doShow){
9697 var x = this.xy[0], y = this.xy[1];
9698 var w = this.size.width, h = this.size.height;
9699 if(doShow === true){
9701 this.shadow.show(this.el);
9707 if(this.shadow && this.shadow.isVisible()){
9708 this.shadow.show(this.el);
9710 if(this.shim && this.shim.isVisible()){
9711 this.shim.setBounds(x, y, w, h);
9716 adjustViewport : function(w, h){
9718 w = Roo.lib.Dom.getViewWidth();
9719 h = Roo.lib.Dom.getViewHeight();
9722 this.viewSize = [w, h];
9723 if(this.modal && this.mask.isVisible()){
9724 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
9725 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
9727 if(this.isVisible()){
9733 * Destroys this dialog and all its supporting elements (including any tabs, shim,
9734 * shadow, proxy, mask, etc.) Also removes all event listeners.
9735 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
9737 destroy : function(removeEl){
9738 if(this.isVisible()){
9739 this.animateTarget = null;
9742 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
9744 this.tabs.destroy(removeEl);
9757 for(var i = 0, len = this.buttons.length; i < len; i++){
9758 this.buttons[i].destroy();
9761 this.el.removeAllListeners();
9762 if(removeEl === true){
9766 Roo.DialogManager.unregister(this);
9770 startMove : function(){
9774 if(this.constraintoviewport !== false){
9775 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
9780 endMove : function(){
9781 if(!this.proxyDrag){
9782 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
9784 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
9788 this.adjustAssets();
9790 this.fireEvent("move", this, this.xy[0], this.xy[1]);
9794 * Brings this dialog to the front of any other visible dialogs
9795 * @return {Roo.BasicDialog} this
9797 toFront : function(){
9798 Roo.DialogManager.bringToFront(this);
9803 * Sends this dialog to the back (under) of any other visible dialogs
9804 * @return {Roo.BasicDialog} this
9806 toBack : function(){
9807 Roo.DialogManager.sendToBack(this);
9812 * Centers this dialog in the viewport
9813 * @return {Roo.BasicDialog} this
9815 center : function(){
9816 var xy = this.el.getCenterXY(true);
9817 this.moveTo(xy[0], xy[1]);
9822 * Moves the dialog's top-left corner to the specified point
9825 * @return {Roo.BasicDialog} this
9827 moveTo : function(x, y){
9829 if(this.isVisible()){
9830 this.el.setXY(this.xy);
9831 this.adjustAssets();
9837 * Aligns the dialog to the specified element
9838 * @param {String/HTMLElement/Roo.Element} element The element to align to.
9839 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
9840 * @param {Array} offsets (optional) Offset the positioning by [x, y]
9841 * @return {Roo.BasicDialog} this
9843 alignTo : function(element, position, offsets){
9844 this.xy = this.el.getAlignToXY(element, position, offsets);
9845 if(this.isVisible()){
9846 this.el.setXY(this.xy);
9847 this.adjustAssets();
9853 * Anchors an element to another element and realigns it when the window is resized.
9854 * @param {String/HTMLElement/Roo.Element} element The element to align to.
9855 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
9856 * @param {Array} offsets (optional) Offset the positioning by [x, y]
9857 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
9858 * is a number, it is used as the buffer delay (defaults to 50ms).
9859 * @return {Roo.BasicDialog} this
9861 anchorTo : function(el, alignment, offsets, monitorScroll){
9862 var action = function(){
9863 this.alignTo(el, alignment, offsets);
9865 Roo.EventManager.onWindowResize(action, this);
9866 var tm = typeof monitorScroll;
9867 if(tm != 'undefined'){
9868 Roo.EventManager.on(window, 'scroll', action, this,
9869 {buffer: tm == 'number' ? monitorScroll : 50});
9876 * Returns true if the dialog is visible
9879 isVisible : function(){
9880 return this.el.isVisible();
9884 animHide : function(callback){
9885 var b = Roo.get(this.animateTarget).getBox();
9887 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
9889 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
9890 this.hideEl.createDelegate(this, [callback]));
9895 * @param {Function} callback (optional) Function to call when the dialog is hidden
9896 * @return {Roo.BasicDialog} this
9898 hide : function(callback){
9899 if (this.fireEvent("beforehide", this) === false){
9908 // sometimes animateTarget seems to get set.. causing problems...
9909 // this just double checks..
9910 if(this.animateTarget && Roo.get(this.animateTarget)) {
9911 this.animHide(callback);
9914 this.hideEl(callback);
9920 hideEl : function(callback){
9924 Roo.get(document.body).removeClass("x-body-masked");
9926 this.fireEvent("hide", this);
9927 if(typeof callback == "function"){
9933 hideAction : function(){
9934 this.setLeft("-10000px");
9935 this.setTop("-10000px");
9936 this.setStyle("visibility", "hidden");
9940 refreshSize : function(){
9941 this.size = this.el.getSize();
9942 this.xy = this.el.getXY();
9943 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
9947 // z-index is managed by the DialogManager and may be overwritten at any time
9948 setZIndex : function(index){
9950 this.mask.setStyle("z-index", index);
9953 this.shim.setStyle("z-index", ++index);
9956 this.shadow.setZIndex(++index);
9958 this.el.setStyle("z-index", ++index);
9960 this.proxy.setStyle("z-index", ++index);
9963 this.resizer.proxy.setStyle("z-index", ++index);
9966 this.lastZIndex = index;
9970 * Returns the element for this dialog
9971 * @return {Roo.Element} The underlying dialog Element
9979 * @class Roo.DialogManager
9980 * Provides global access to BasicDialogs that have been created and
9981 * support for z-indexing (layering) multiple open dialogs.
9983 Roo.DialogManager = function(){
9985 var accessList = [];
9989 var sortDialogs = function(d1, d2){
9990 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
9994 var orderDialogs = function(){
9995 accessList.sort(sortDialogs);
9996 var seed = Roo.DialogManager.zseed;
9997 for(var i = 0, len = accessList.length; i < len; i++){
9998 var dlg = accessList[i];
10000 dlg.setZIndex(seed + (i*10));
10007 * The starting z-index for BasicDialogs (defaults to 9000)
10008 * @type Number The z-index value
10013 register : function(dlg){
10014 list[dlg.id] = dlg;
10015 accessList.push(dlg);
10019 unregister : function(dlg){
10020 delete list[dlg.id];
10023 if(!accessList.indexOf){
10024 for( i = 0, len = accessList.length; i < len; i++){
10025 if(accessList[i] == dlg){
10026 accessList.splice(i, 1);
10031 i = accessList.indexOf(dlg);
10033 accessList.splice(i, 1);
10039 * Gets a registered dialog by id
10040 * @param {String/Object} id The id of the dialog or a dialog
10041 * @return {Roo.BasicDialog} this
10043 get : function(id){
10044 return typeof id == "object" ? id : list[id];
10048 * Brings the specified dialog to the front
10049 * @param {String/Object} dlg The id of the dialog or a dialog
10050 * @return {Roo.BasicDialog} this
10052 bringToFront : function(dlg){
10053 dlg = this.get(dlg);
10056 dlg._lastAccess = new Date().getTime();
10063 * Sends the specified dialog to the back
10064 * @param {String/Object} dlg The id of the dialog or a dialog
10065 * @return {Roo.BasicDialog} this
10067 sendToBack : function(dlg){
10068 dlg = this.get(dlg);
10069 dlg._lastAccess = -(new Date().getTime());
10075 * Hides all dialogs
10077 hideAll : function(){
10078 for(var id in list){
10079 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
10088 * @class Roo.LayoutDialog
10089 * @extends Roo.BasicDialog
10090 * Dialog which provides adjustments for working with a layout in a Dialog.
10091 * Add your necessary layout config options to the dialog's config.<br>
10092 * Example usage (including a nested layout):
10095 dialog = new Roo.LayoutDialog("download-dlg", {
10104 // layout config merges with the dialog config
10106 tabPosition: "top",
10107 alwaysShowTabs: true
10110 dialog.addKeyListener(27, dialog.hide, dialog);
10111 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
10112 dialog.addButton("Build It!", this.getDownload, this);
10114 // we can even add nested layouts
10115 var innerLayout = new Roo.BorderLayout("dl-inner", {
10125 innerLayout.beginUpdate();
10126 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
10127 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
10128 innerLayout.endUpdate(true);
10130 var layout = dialog.getLayout();
10131 layout.beginUpdate();
10132 layout.add("center", new Roo.ContentPanel("standard-panel",
10133 {title: "Download the Source", fitToFrame:true}));
10134 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
10135 {title: "Build your own roo.js"}));
10136 layout.getRegion("center").showPanel(sp);
10137 layout.endUpdate();
10141 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
10142 * @param {Object} config configuration options
10144 Roo.LayoutDialog = function(el, cfg){
10147 if (typeof(cfg) == 'undefined') {
10148 config = Roo.apply({}, el);
10149 // not sure why we use documentElement here.. - it should always be body.
10150 // IE7 borks horribly if we use documentElement.
10151 // webkit also does not like documentElement - it creates a body element...
10152 el = Roo.get( document.body || document.documentElement ).createChild();
10153 //config.autoCreate = true;
10157 config.autoTabs = false;
10158 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
10159 this.body.setStyle({overflow:"hidden", position:"relative"});
10160 this.layout = new Roo.BorderLayout(this.body.dom, config);
10161 this.layout.monitorWindowResize = false;
10162 this.el.addClass("x-dlg-auto-layout");
10163 // fix case when center region overwrites center function
10164 this.center = Roo.BasicDialog.prototype.center;
10165 this.on("show", this.layout.layout, this.layout, true);
10166 if (config.items) {
10167 var xitems = config.items;
10168 delete config.items;
10169 Roo.each(xitems, this.addxtype, this);
10174 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
10176 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
10179 endUpdate : function(){
10180 this.layout.endUpdate();
10184 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
10187 beginUpdate : function(){
10188 this.layout.beginUpdate();
10192 * Get the BorderLayout for this dialog
10193 * @return {Roo.BorderLayout}
10195 getLayout : function(){
10196 return this.layout;
10199 showEl : function(){
10200 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
10202 this.layout.layout();
10207 // Use the syncHeightBeforeShow config option to control this automatically
10208 syncBodyHeight : function(){
10209 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
10210 if(this.layout){this.layout.layout();}
10214 * Add an xtype element (actually adds to the layout.)
10215 * @return {Object} xdata xtype object data.
10218 addxtype : function(c) {
10219 return this.layout.addxtype(c);
10223 * Ext JS Library 1.1.1
10224 * Copyright(c) 2006-2007, Ext JS, LLC.
10226 * Originally Released Under LGPL - original licence link has changed is not relivant.
10229 * <script type="text/javascript">
10233 * @class Roo.MessageBox
10234 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
10238 Roo.Msg.alert('Status', 'Changes saved successfully.');
10240 // Prompt for user data:
10241 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
10243 // process text value...
10247 // Show a dialog using config options:
10249 title:'Save Changes?',
10250 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
10251 buttons: Roo.Msg.YESNOCANCEL,
10258 Roo.MessageBox = function(){
10259 var dlg, opt, mask, waitTimer;
10260 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
10261 var buttons, activeTextEl, bwidth;
10264 var handleButton = function(button){
10266 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
10270 var handleHide = function(){
10271 if(opt && opt.cls){
10272 dlg.el.removeClass(opt.cls);
10275 Roo.TaskMgr.stop(waitTimer);
10281 var updateButtons = function(b){
10284 buttons["ok"].hide();
10285 buttons["cancel"].hide();
10286 buttons["yes"].hide();
10287 buttons["no"].hide();
10288 dlg.footer.dom.style.display = 'none';
10291 dlg.footer.dom.style.display = '';
10292 for(var k in buttons){
10293 if(typeof buttons[k] != "function"){
10296 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
10297 width += buttons[k].el.getWidth()+15;
10307 var handleEsc = function(d, k, e){
10308 if(opt && opt.closable !== false){
10318 * Returns a reference to the underlying {@link Roo.BasicDialog} element
10319 * @return {Roo.BasicDialog} The BasicDialog element
10321 getDialog : function(){
10323 dlg = new Roo.BasicDialog("x-msg-box", {
10328 constraintoviewport:false,
10330 collapsible : false,
10333 width:400, height:100,
10334 buttonAlign:"center",
10335 closeClick : function(){
10336 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
10337 handleButton("no");
10339 handleButton("cancel");
10343 dlg.on("hide", handleHide);
10345 dlg.addKeyListener(27, handleEsc);
10347 var bt = this.buttonText;
10348 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
10349 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
10350 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
10351 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
10352 bodyEl = dlg.body.createChild({
10354 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>'
10356 msgEl = bodyEl.dom.firstChild;
10357 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
10358 textboxEl.enableDisplayMode();
10359 textboxEl.addKeyListener([10,13], function(){
10360 if(dlg.isVisible() && opt && opt.buttons){
10361 if(opt.buttons.ok){
10362 handleButton("ok");
10363 }else if(opt.buttons.yes){
10364 handleButton("yes");
10368 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
10369 textareaEl.enableDisplayMode();
10370 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
10371 progressEl.enableDisplayMode();
10372 var pf = progressEl.dom.firstChild;
10374 pp = Roo.get(pf.firstChild);
10375 pp.setHeight(pf.offsetHeight);
10383 * Updates the message box body text
10384 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
10385 * the XHTML-compliant non-breaking space character '&#160;')
10386 * @return {Roo.MessageBox} This message box
10388 updateText : function(text){
10389 if(!dlg.isVisible() && !opt.width){
10390 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
10392 msgEl.innerHTML = text || ' ';
10394 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
10395 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
10397 Math.min(opt.width || cw , this.maxWidth),
10398 Math.max(opt.minWidth || this.minWidth, bwidth)
10401 activeTextEl.setWidth(w);
10403 if(dlg.isVisible()){
10404 dlg.fixedcenter = false;
10406 // to big, make it scroll. = But as usual stupid IE does not support
10409 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
10410 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
10411 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
10413 bodyEl.dom.style.height = '';
10414 bodyEl.dom.style.overflowY = '';
10417 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
10419 bodyEl.dom.style.overflowX = '';
10422 dlg.setContentSize(w, bodyEl.getHeight());
10423 if(dlg.isVisible()){
10424 dlg.fixedcenter = true;
10430 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
10431 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
10432 * @param {Number} value Any number between 0 and 1 (e.g., .5)
10433 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
10434 * @return {Roo.MessageBox} This message box
10436 updateProgress : function(value, text){
10438 this.updateText(text);
10440 if (pp) { // weird bug on my firefox - for some reason this is not defined
10441 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
10447 * Returns true if the message box is currently displayed
10448 * @return {Boolean} True if the message box is visible, else false
10450 isVisible : function(){
10451 return dlg && dlg.isVisible();
10455 * Hides the message box if it is displayed
10458 if(this.isVisible()){
10464 * Displays a new message box, or reinitializes an existing message box, based on the config options
10465 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
10466 * The following config object properties are supported:
10468 Property Type Description
10469 ---------- --------------- ------------------------------------------------------------------------------------
10470 animEl String/Element An id or Element from which the message box should animate as it opens and
10471 closes (defaults to undefined)
10472 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
10473 cancel:'Bar'}), or false to not show any buttons (defaults to false)
10474 closable Boolean False to hide the top-right close button (defaults to true). Note that
10475 progress and wait dialogs will ignore this property and always hide the
10476 close button as they can only be closed programmatically.
10477 cls String A custom CSS class to apply to the message box element
10478 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
10479 displayed (defaults to 75)
10480 fn Function A callback function to execute after closing the dialog. The arguments to the
10481 function will be btn (the name of the button that was clicked, if applicable,
10482 e.g. "ok"), and text (the value of the active text field, if applicable).
10483 Progress and wait dialogs will ignore this option since they do not respond to
10484 user actions and can only be closed programmatically, so any required function
10485 should be called by the same code after it closes the dialog.
10486 icon String A CSS class that provides a background image to be used as an icon for
10487 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
10488 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
10489 minWidth Number The minimum width in pixels of the message box (defaults to 100)
10490 modal Boolean False to allow user interaction with the page while the message box is
10491 displayed (defaults to true)
10492 msg String A string that will replace the existing message box body text (defaults
10493 to the XHTML-compliant non-breaking space character ' ')
10494 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
10495 progress Boolean True to display a progress bar (defaults to false)
10496 progressText String The text to display inside the progress bar if progress = true (defaults to '')
10497 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
10498 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
10499 title String The title text
10500 value String The string value to set into the active textbox element if displayed
10501 wait Boolean True to display a progress bar (defaults to false)
10502 width Number The width of the dialog in pixels
10509 msg: 'Please enter your address:',
10511 buttons: Roo.MessageBox.OKCANCEL,
10514 animEl: 'addAddressBtn'
10517 * @param {Object} config Configuration options
10518 * @return {Roo.MessageBox} This message box
10520 show : function(options)
10523 // this causes nightmares if you show one dialog after another
10524 // especially on callbacks..
10526 if(this.isVisible()){
10529 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
10530 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
10531 Roo.log("New Dialog Message:" + options.msg )
10532 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
10533 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
10536 var d = this.getDialog();
10538 d.setTitle(opt.title || " ");
10539 d.close.setDisplayed(opt.closable !== false);
10540 activeTextEl = textboxEl;
10541 opt.prompt = opt.prompt || (opt.multiline ? true : false);
10546 textareaEl.setHeight(typeof opt.multiline == "number" ?
10547 opt.multiline : this.defaultTextHeight);
10548 activeTextEl = textareaEl;
10557 progressEl.setDisplayed(opt.progress === true);
10558 this.updateProgress(0);
10559 activeTextEl.dom.value = opt.value || "";
10561 dlg.setDefaultButton(activeTextEl);
10563 var bs = opt.buttons;
10566 db = buttons["ok"];
10567 }else if(bs && bs.yes){
10568 db = buttons["yes"];
10570 dlg.setDefaultButton(db);
10572 bwidth = updateButtons(opt.buttons);
10573 this.updateText(opt.msg);
10575 d.el.addClass(opt.cls);
10577 d.proxyDrag = opt.proxyDrag === true;
10578 d.modal = opt.modal !== false;
10579 d.mask = opt.modal !== false ? mask : false;
10580 if(!d.isVisible()){
10581 // force it to the end of the z-index stack so it gets a cursor in FF
10582 document.body.appendChild(dlg.el.dom);
10583 d.animateTarget = null;
10584 d.show(options.animEl);
10590 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
10591 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
10592 * and closing the message box when the process is complete.
10593 * @param {String} title The title bar text
10594 * @param {String} msg The message box body text
10595 * @return {Roo.MessageBox} This message box
10597 progress : function(title, msg){
10604 minWidth: this.minProgressWidth,
10611 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
10612 * If a callback function is passed it will be called after the user clicks the button, and the
10613 * id of the button that was clicked will be passed as the only parameter to the callback
10614 * (could also be the top-right close button).
10615 * @param {String} title The title bar text
10616 * @param {String} msg The message box body text
10617 * @param {Function} fn (optional) The callback function invoked after the message box is closed
10618 * @param {Object} scope (optional) The scope of the callback function
10619 * @return {Roo.MessageBox} This message box
10621 alert : function(title, msg, fn, scope){
10634 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
10635 * interaction while waiting for a long-running process to complete that does not have defined intervals.
10636 * You are responsible for closing the message box when the process is complete.
10637 * @param {String} msg The message box body text
10638 * @param {String} title (optional) The title bar text
10639 * @return {Roo.MessageBox} This message box
10641 wait : function(msg, title){
10652 waitTimer = Roo.TaskMgr.start({
10654 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
10662 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
10663 * If a callback function is passed it will be called after the user clicks either button, and the id of the
10664 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
10665 * @param {String} title The title bar text
10666 * @param {String} msg The message box body text
10667 * @param {Function} fn (optional) The callback function invoked after the message box is closed
10668 * @param {Object} scope (optional) The scope of the callback function
10669 * @return {Roo.MessageBox} This message box
10671 confirm : function(title, msg, fn, scope){
10675 buttons: this.YESNO,
10684 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
10685 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
10686 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
10687 * (could also be the top-right close button) and the text that was entered will be passed as the two
10688 * parameters to the callback.
10689 * @param {String} title The title bar text
10690 * @param {String} msg The message box body text
10691 * @param {Function} fn (optional) The callback function invoked after the message box is closed
10692 * @param {Object} scope (optional) The scope of the callback function
10693 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
10694 * property, or the height in pixels to create the textbox (defaults to false / single-line)
10695 * @return {Roo.MessageBox} This message box
10697 prompt : function(title, msg, fn, scope, multiline){
10701 buttons: this.OKCANCEL,
10706 multiline: multiline,
10713 * Button config that displays a single OK button
10718 * Button config that displays Yes and No buttons
10721 YESNO : {yes:true, no:true},
10723 * Button config that displays OK and Cancel buttons
10726 OKCANCEL : {ok:true, cancel:true},
10728 * Button config that displays Yes, No and Cancel buttons
10731 YESNOCANCEL : {yes:true, no:true, cancel:true},
10734 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
10737 defaultTextHeight : 75,
10739 * The maximum width in pixels of the message box (defaults to 600)
10744 * The minimum width in pixels of the message box (defaults to 100)
10749 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
10750 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
10753 minProgressWidth : 250,
10755 * An object containing the default button text strings that can be overriden for localized language support.
10756 * Supported properties are: ok, cancel, yes and no.
10757 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
10770 * Shorthand for {@link Roo.MessageBox}
10772 Roo.Msg = Roo.MessageBox;/*
10774 * Ext JS Library 1.1.1
10775 * Copyright(c) 2006-2007, Ext JS, LLC.
10777 * Originally Released Under LGPL - original licence link has changed is not relivant.
10780 * <script type="text/javascript">
10783 * @class Roo.QuickTips
10784 * Provides attractive and customizable tooltips for any element.
10787 Roo.QuickTips = function(){
10788 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
10789 var ce, bd, xy, dd;
10790 var visible = false, disabled = true, inited = false;
10791 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
10793 var onOver = function(e){
10797 var t = e.getTarget();
10798 if(!t || t.nodeType !== 1 || t == document || t == document.body){
10801 if(ce && t == ce.el){
10802 clearTimeout(hideProc);
10805 if(t && tagEls[t.id]){
10806 tagEls[t.id].el = t;
10807 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
10810 var ttp, et = Roo.fly(t);
10811 var ns = cfg.namespace;
10812 if(tm.interceptTitles && t.title){
10815 t.removeAttribute("title");
10816 e.preventDefault();
10818 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute) || et.getAttributeNS(cfg.alt_namespace, cfg.attribute) ;
10821 showProc = show.defer(tm.showDelay, tm, [{
10823 text: ttp.replace(/\\n/g,'<br/>'),
10824 width: et.getAttributeNS(ns, cfg.width),
10825 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
10826 title: et.getAttributeNS(ns, cfg.title),
10827 cls: et.getAttributeNS(ns, cfg.cls)
10832 var onOut = function(e){
10833 clearTimeout(showProc);
10834 var t = e.getTarget();
10835 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
10836 hideProc = setTimeout(hide, tm.hideDelay);
10840 var onMove = function(e){
10846 if(tm.trackMouse && ce){
10851 var onDown = function(e){
10852 clearTimeout(showProc);
10853 clearTimeout(hideProc);
10855 if(tm.hideOnClick){
10858 tm.enable.defer(100, tm);
10863 var getPad = function(){
10864 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
10867 var show = function(o){
10871 clearTimeout(dismissProc);
10873 if(removeCls){ // in case manually hidden
10874 el.removeClass(removeCls);
10878 el.addClass(ce.cls);
10879 removeCls = ce.cls;
10882 tipTitle.update(ce.title);
10885 tipTitle.update('');
10888 el.dom.style.width = tm.maxWidth+'px';
10889 //tipBody.dom.style.width = '';
10890 tipBodyText.update(o.text);
10891 var p = getPad(), w = ce.width;
10893 var td = tipBodyText.dom;
10894 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
10895 if(aw > tm.maxWidth){
10897 }else if(aw < tm.minWidth){
10903 //tipBody.setWidth(w);
10904 el.setWidth(parseInt(w, 10) + p);
10905 if(ce.autoHide === false){
10906 close.setDisplayed(true);
10911 close.setDisplayed(false);
10917 el.avoidY = xy[1]-18;
10922 el.setStyle("visibility", "visible");
10923 el.fadeIn({callback: afterShow});
10929 var afterShow = function(){
10933 if(tm.autoDismiss && ce.autoHide !== false){
10934 dismissProc = setTimeout(hide, tm.autoDismissDelay);
10939 var hide = function(noanim){
10940 clearTimeout(dismissProc);
10941 clearTimeout(hideProc);
10943 if(el.isVisible()){
10945 if(noanim !== true && tm.animate){
10946 el.fadeOut({callback: afterHide});
10953 var afterHide = function(){
10956 el.removeClass(removeCls);
10963 * @cfg {Number} minWidth
10964 * The minimum width of the quick tip (defaults to 40)
10968 * @cfg {Number} maxWidth
10969 * The maximum width of the quick tip (defaults to 300)
10973 * @cfg {Boolean} interceptTitles
10974 * True to automatically use the element's DOM title value if available (defaults to false)
10976 interceptTitles : false,
10978 * @cfg {Boolean} trackMouse
10979 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
10981 trackMouse : false,
10983 * @cfg {Boolean} hideOnClick
10984 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
10986 hideOnClick : true,
10988 * @cfg {Number} showDelay
10989 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
10993 * @cfg {Number} hideDelay
10994 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
10998 * @cfg {Boolean} autoHide
10999 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
11000 * Used in conjunction with hideDelay.
11005 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
11006 * (defaults to true). Used in conjunction with autoDismissDelay.
11008 autoDismiss : true,
11011 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
11013 autoDismissDelay : 5000,
11015 * @cfg {Boolean} animate
11016 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
11021 * @cfg {String} title
11022 * Title text to display (defaults to ''). This can be any valid HTML markup.
11026 * @cfg {String} text
11027 * Body text to display (defaults to ''). This can be any valid HTML markup.
11031 * @cfg {String} cls
11032 * A CSS class to apply to the base quick tip element (defaults to '').
11036 * @cfg {Number} width
11037 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
11038 * minWidth or maxWidth.
11043 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
11044 * or display QuickTips in a page.
11047 tm = Roo.QuickTips;
11048 cfg = tm.tagConfig;
11050 if(!Roo.isReady){ // allow calling of init() before onReady
11051 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
11054 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
11055 el.fxDefaults = {stopFx: true};
11056 // maximum custom styling
11057 //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>');
11058 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>');
11059 tipTitle = el.child('h3');
11060 tipTitle.enableDisplayMode("block");
11061 tipBody = el.child('div.x-tip-bd');
11062 tipBodyText = el.child('div.x-tip-bd-inner');
11063 //bdLeft = el.child('div.x-tip-bd-left');
11064 //bdRight = el.child('div.x-tip-bd-right');
11065 close = el.child('div.x-tip-close');
11066 close.enableDisplayMode("block");
11067 close.on("click", hide);
11068 var d = Roo.get(document);
11069 d.on("mousedown", onDown);
11070 d.on("mouseover", onOver);
11071 d.on("mouseout", onOut);
11072 d.on("mousemove", onMove);
11073 esc = d.addKeyListener(27, hide);
11076 dd = el.initDD("default", null, {
11077 onDrag : function(){
11081 dd.setHandleElId(tipTitle.id);
11090 * Configures a new quick tip instance and assigns it to a target element. The following config options
11093 Property Type Description
11094 ---------- --------------------- ------------------------------------------------------------------------
11095 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
11097 * @param {Object} config The config object
11099 register : function(config){
11100 var cs = config instanceof Array ? config : arguments;
11101 for(var i = 0, len = cs.length; i < len; i++) {
11103 var target = c.target;
11105 if(target instanceof Array){
11106 for(var j = 0, jlen = target.length; j < jlen; j++){
11107 tagEls[target[j]] = c;
11110 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
11117 * Removes this quick tip from its element and destroys it.
11118 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
11120 unregister : function(el){
11121 delete tagEls[Roo.id(el)];
11125 * Enable this quick tip.
11127 enable : function(){
11128 if(inited && disabled){
11130 if(locks.length < 1){
11137 * Disable this quick tip.
11139 disable : function(){
11141 clearTimeout(showProc);
11142 clearTimeout(hideProc);
11143 clearTimeout(dismissProc);
11151 * Returns true if the quick tip is enabled, else false.
11153 isEnabled : function(){
11159 namespace : "roo", // was ext?? this may break..
11160 alt_namespace : "ext",
11161 attribute : "qtip",
11171 // backwards compat
11172 Roo.QuickTips.tips = Roo.QuickTips.register;/*
11174 * Ext JS Library 1.1.1
11175 * Copyright(c) 2006-2007, Ext JS, LLC.
11177 * Originally Released Under LGPL - original licence link has changed is not relivant.
11180 * <script type="text/javascript">
11185 * @class Roo.tree.TreePanel
11186 * @extends Roo.data.Tree
11188 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
11189 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
11190 * @cfg {Boolean} enableDD true to enable drag and drop
11191 * @cfg {Boolean} enableDrag true to enable just drag
11192 * @cfg {Boolean} enableDrop true to enable just drop
11193 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
11194 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
11195 * @cfg {String} ddGroup The DD group this TreePanel belongs to
11196 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
11197 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
11198 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
11199 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
11200 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
11201 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
11202 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
11203 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
11204 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
11205 * @cfg {Object|Roo.tree.TreeEditor} editor The TreeEditor or xtype data to display when clicked.
11206 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
11207 * @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>
11208 * @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>
11211 * @param {String/HTMLElement/Element} el The container element
11212 * @param {Object} config
11214 Roo.tree.TreePanel = function(el, config){
11216 var loader = false;
11218 root = config.root;
11219 delete config.root;
11221 if (config.loader) {
11222 loader = config.loader;
11223 delete config.loader;
11226 Roo.apply(this, config);
11227 Roo.tree.TreePanel.superclass.constructor.call(this);
11228 this.el = Roo.get(el);
11229 this.el.addClass('x-tree');
11230 //console.log(root);
11232 this.setRootNode( Roo.factory(root, Roo.tree));
11235 this.loader = Roo.factory(loader, Roo.tree);
11238 * Read-only. The id of the container element becomes this TreePanel's id.
11240 this.id = this.el.id;
11243 * @event beforeload
11244 * Fires before a node is loaded, return false to cancel
11245 * @param {Node} node The node being loaded
11247 "beforeload" : true,
11250 * Fires when a node is loaded
11251 * @param {Node} node The node that was loaded
11255 * @event textchange
11256 * Fires when the text for a node is changed
11257 * @param {Node} node The node
11258 * @param {String} text The new text
11259 * @param {String} oldText The old text
11261 "textchange" : true,
11263 * @event beforeexpand
11264 * Fires before a node is expanded, return false to cancel.
11265 * @param {Node} node The node
11266 * @param {Boolean} deep
11267 * @param {Boolean} anim
11269 "beforeexpand" : true,
11271 * @event beforecollapse
11272 * Fires before a node is collapsed, return false to cancel.
11273 * @param {Node} node The node
11274 * @param {Boolean} deep
11275 * @param {Boolean} anim
11277 "beforecollapse" : true,
11280 * Fires when a node is expanded
11281 * @param {Node} node The node
11285 * @event disabledchange
11286 * Fires when the disabled status of a node changes
11287 * @param {Node} node The node
11288 * @param {Boolean} disabled
11290 "disabledchange" : true,
11293 * Fires when a node is collapsed
11294 * @param {Node} node The node
11298 * @event beforeclick
11299 * Fires before click processing on a node. Return false to cancel the default action.
11300 * @param {Node} node The node
11301 * @param {Roo.EventObject} e The event object
11303 "beforeclick":true,
11305 * @event checkchange
11306 * Fires when a node with a checkbox's checked property changes
11307 * @param {Node} this This node
11308 * @param {Boolean} checked
11310 "checkchange":true,
11313 * Fires when a node is clicked
11314 * @param {Node} node The node
11315 * @param {Roo.EventObject} e The event object
11320 * Fires when a node is double clicked
11321 * @param {Node} node The node
11322 * @param {Roo.EventObject} e The event object
11326 * @event contextmenu
11327 * Fires when a node is right clicked
11328 * @param {Node} node The node
11329 * @param {Roo.EventObject} e The event object
11331 "contextmenu":true,
11333 * @event beforechildrenrendered
11334 * Fires right before the child nodes for a node are rendered
11335 * @param {Node} node The node
11337 "beforechildrenrendered":true,
11340 * Fires when a node starts being dragged
11341 * @param {Roo.tree.TreePanel} this
11342 * @param {Roo.tree.TreeNode} node
11343 * @param {event} e The raw browser event
11345 "startdrag" : true,
11348 * Fires when a drag operation is complete
11349 * @param {Roo.tree.TreePanel} this
11350 * @param {Roo.tree.TreeNode} node
11351 * @param {event} e The raw browser event
11356 * Fires when a dragged node is dropped on a valid DD target
11357 * @param {Roo.tree.TreePanel} this
11358 * @param {Roo.tree.TreeNode} node
11359 * @param {DD} dd The dd it was dropped on
11360 * @param {event} e The raw browser event
11364 * @event beforenodedrop
11365 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
11366 * passed to handlers has the following properties:<br />
11367 * <ul style="padding:5px;padding-left:16px;">
11368 * <li>tree - The TreePanel</li>
11369 * <li>target - The node being targeted for the drop</li>
11370 * <li>data - The drag data from the drag source</li>
11371 * <li>point - The point of the drop - append, above or below</li>
11372 * <li>source - The drag source</li>
11373 * <li>rawEvent - Raw mouse event</li>
11374 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
11375 * to be inserted by setting them on this object.</li>
11376 * <li>cancel - Set this to true to cancel the drop.</li>
11378 * @param {Object} dropEvent
11380 "beforenodedrop" : true,
11383 * Fires after a DD object is dropped on a node in this tree. The dropEvent
11384 * passed to handlers has the following properties:<br />
11385 * <ul style="padding:5px;padding-left:16px;">
11386 * <li>tree - The TreePanel</li>
11387 * <li>target - The node being targeted for the drop</li>
11388 * <li>data - The drag data from the drag source</li>
11389 * <li>point - The point of the drop - append, above or below</li>
11390 * <li>source - The drag source</li>
11391 * <li>rawEvent - Raw mouse event</li>
11392 * <li>dropNode - Dropped node(s).</li>
11394 * @param {Object} dropEvent
11398 * @event nodedragover
11399 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
11400 * passed to handlers has the following properties:<br />
11401 * <ul style="padding:5px;padding-left:16px;">
11402 * <li>tree - The TreePanel</li>
11403 * <li>target - The node being targeted for the drop</li>
11404 * <li>data - The drag data from the drag source</li>
11405 * <li>point - The point of the drop - append, above or below</li>
11406 * <li>source - The drag source</li>
11407 * <li>rawEvent - Raw mouse event</li>
11408 * <li>dropNode - Drop node(s) provided by the source.</li>
11409 * <li>cancel - Set this to true to signal drop not allowed.</li>
11411 * @param {Object} dragOverEvent
11413 "nodedragover" : true,
11415 * @event appendnode
11416 * Fires when append node to the tree
11417 * @param {Roo.tree.TreePanel} this
11418 * @param {Roo.tree.TreeNode} node
11419 * @param {Number} index The index of the newly appended node
11421 "appendnode" : true
11424 if(this.singleExpand){
11425 this.on("beforeexpand", this.restrictExpand, this);
11428 this.editor.tree = this;
11429 this.editor = Roo.factory(this.editor, Roo.tree);
11432 if (this.selModel) {
11433 this.selModel = Roo.factory(this.selModel, Roo.tree);
11437 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
11438 rootVisible : true,
11439 animate: Roo.enableFx,
11442 hlDrop : Roo.enableFx,
11446 rendererTip: false,
11448 restrictExpand : function(node){
11449 var p = node.parentNode;
11451 if(p.expandedChild && p.expandedChild.parentNode == p){
11452 p.expandedChild.collapse();
11454 p.expandedChild = node;
11458 // private override
11459 setRootNode : function(node){
11460 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
11461 if(!this.rootVisible){
11462 node.ui = new Roo.tree.RootTreeNodeUI(node);
11468 * Returns the container element for this TreePanel
11470 getEl : function(){
11475 * Returns the default TreeLoader for this TreePanel
11477 getLoader : function(){
11478 return this.loader;
11484 expandAll : function(){
11485 this.root.expand(true);
11489 * Collapse all nodes
11491 collapseAll : function(){
11492 this.root.collapse(true);
11496 * Returns the selection model used by this TreePanel
11498 getSelectionModel : function(){
11499 if(!this.selModel){
11500 this.selModel = new Roo.tree.DefaultSelectionModel();
11502 return this.selModel;
11506 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
11507 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
11508 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
11511 getChecked : function(a, startNode){
11512 startNode = startNode || this.root;
11514 var f = function(){
11515 if(this.attributes.checked){
11516 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
11519 startNode.cascade(f);
11524 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
11525 * @param {String} path
11526 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
11527 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
11528 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
11530 expandPath : function(path, attr, callback){
11531 attr = attr || "id";
11532 var keys = path.split(this.pathSeparator);
11533 var curNode = this.root;
11534 if(curNode.attributes[attr] != keys[1]){ // invalid root
11536 callback(false, null);
11541 var f = function(){
11542 if(++index == keys.length){
11544 callback(true, curNode);
11548 var c = curNode.findChild(attr, keys[index]);
11551 callback(false, curNode);
11556 c.expand(false, false, f);
11558 curNode.expand(false, false, f);
11562 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
11563 * @param {String} path
11564 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
11565 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
11566 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
11568 selectPath : function(path, attr, callback){
11569 attr = attr || "id";
11570 var keys = path.split(this.pathSeparator);
11571 var v = keys.pop();
11572 if(keys.length > 0){
11573 var f = function(success, node){
11574 if(success && node){
11575 var n = node.findChild(attr, v);
11581 }else if(callback){
11582 callback(false, n);
11586 callback(false, n);
11590 this.expandPath(keys.join(this.pathSeparator), attr, f);
11592 this.root.select();
11594 callback(true, this.root);
11599 getTreeEl : function(){
11604 * Trigger rendering of this TreePanel
11606 render : function(){
11607 if (this.innerCt) {
11608 return this; // stop it rendering more than once!!
11611 this.innerCt = this.el.createChild({tag:"ul",
11612 cls:"x-tree-root-ct " +
11613 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
11615 if(this.containerScroll){
11616 Roo.dd.ScrollManager.register(this.el);
11618 if((this.enableDD || this.enableDrop) && !this.dropZone){
11620 * The dropZone used by this tree if drop is enabled
11621 * @type Roo.tree.TreeDropZone
11623 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
11624 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
11627 if((this.enableDD || this.enableDrag) && !this.dragZone){
11629 * The dragZone used by this tree if drag is enabled
11630 * @type Roo.tree.TreeDragZone
11632 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
11633 ddGroup: this.ddGroup || "TreeDD",
11634 scroll: this.ddScroll
11637 this.getSelectionModel().init(this);
11639 Roo.log("ROOT not set in tree");
11642 this.root.render();
11643 if(!this.rootVisible){
11644 this.root.renderChildren();
11650 * Ext JS Library 1.1.1
11651 * Copyright(c) 2006-2007, Ext JS, LLC.
11653 * Originally Released Under LGPL - original licence link has changed is not relivant.
11656 * <script type="text/javascript">
11661 * @class Roo.tree.DefaultSelectionModel
11662 * @extends Roo.util.Observable
11663 * The default single selection for a TreePanel.
11664 * @param {Object} cfg Configuration
11666 Roo.tree.DefaultSelectionModel = function(cfg){
11667 this.selNode = null;
11673 * @event selectionchange
11674 * Fires when the selected node changes
11675 * @param {DefaultSelectionModel} this
11676 * @param {TreeNode} node the new selection
11678 "selectionchange" : true,
11681 * @event beforeselect
11682 * Fires before the selected node changes, return false to cancel the change
11683 * @param {DefaultSelectionModel} this
11684 * @param {TreeNode} node the new selection
11685 * @param {TreeNode} node the old selection
11687 "beforeselect" : true
11690 Roo.tree.DefaultSelectionModel.superclass.constructor.call(this,cfg);
11693 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
11694 init : function(tree){
11696 tree.getTreeEl().on("keydown", this.onKeyDown, this);
11697 tree.on("click", this.onNodeClick, this);
11700 onNodeClick : function(node, e){
11701 if (e.ctrlKey && this.selNode == node) {
11702 this.unselect(node);
11710 * @param {TreeNode} node The node to select
11711 * @return {TreeNode} The selected node
11713 select : function(node){
11714 var last = this.selNode;
11715 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
11717 last.ui.onSelectedChange(false);
11719 this.selNode = node;
11720 node.ui.onSelectedChange(true);
11721 this.fireEvent("selectionchange", this, node, last);
11728 * @param {TreeNode} node The node to unselect
11730 unselect : function(node){
11731 if(this.selNode == node){
11732 this.clearSelections();
11737 * Clear all selections
11739 clearSelections : function(){
11740 var n = this.selNode;
11742 n.ui.onSelectedChange(false);
11743 this.selNode = null;
11744 this.fireEvent("selectionchange", this, null);
11750 * Get the selected node
11751 * @return {TreeNode} The selected node
11753 getSelectedNode : function(){
11754 return this.selNode;
11758 * Returns true if the node is selected
11759 * @param {TreeNode} node The node to check
11760 * @return {Boolean}
11762 isSelected : function(node){
11763 return this.selNode == node;
11767 * Selects the node above the selected node in the tree, intelligently walking the nodes
11768 * @return TreeNode The new selection
11770 selectPrevious : function(){
11771 var s = this.selNode || this.lastSelNode;
11775 var ps = s.previousSibling;
11777 if(!ps.isExpanded() || ps.childNodes.length < 1){
11778 return this.select(ps);
11780 var lc = ps.lastChild;
11781 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
11784 return this.select(lc);
11786 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
11787 return this.select(s.parentNode);
11793 * Selects the node above the selected node in the tree, intelligently walking the nodes
11794 * @return TreeNode The new selection
11796 selectNext : function(){
11797 var s = this.selNode || this.lastSelNode;
11801 if(s.firstChild && s.isExpanded()){
11802 return this.select(s.firstChild);
11803 }else if(s.nextSibling){
11804 return this.select(s.nextSibling);
11805 }else if(s.parentNode){
11807 s.parentNode.bubble(function(){
11808 if(this.nextSibling){
11809 newS = this.getOwnerTree().selModel.select(this.nextSibling);
11818 onKeyDown : function(e){
11819 var s = this.selNode || this.lastSelNode;
11820 // undesirable, but required
11825 var k = e.getKey();
11833 this.selectPrevious();
11836 e.preventDefault();
11837 if(s.hasChildNodes()){
11838 if(!s.isExpanded()){
11840 }else if(s.firstChild){
11841 this.select(s.firstChild, e);
11846 e.preventDefault();
11847 if(s.hasChildNodes() && s.isExpanded()){
11849 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
11850 this.select(s.parentNode, e);
11858 * @class Roo.tree.MultiSelectionModel
11859 * @extends Roo.util.Observable
11860 * Multi selection for a TreePanel.
11861 * @param {Object} cfg Configuration
11863 Roo.tree.MultiSelectionModel = function(){
11864 this.selNodes = [];
11868 * @event selectionchange
11869 * Fires when the selected nodes change
11870 * @param {MultiSelectionModel} this
11871 * @param {Array} nodes Array of the selected nodes
11873 "selectionchange" : true
11875 Roo.tree.MultiSelectionModel.superclass.constructor.call(this,cfg);
11879 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
11880 init : function(tree){
11882 tree.getTreeEl().on("keydown", this.onKeyDown, this);
11883 tree.on("click", this.onNodeClick, this);
11886 onNodeClick : function(node, e){
11887 this.select(node, e, e.ctrlKey);
11892 * @param {TreeNode} node The node to select
11893 * @param {EventObject} e (optional) An event associated with the selection
11894 * @param {Boolean} keepExisting True to retain existing selections
11895 * @return {TreeNode} The selected node
11897 select : function(node, e, keepExisting){
11898 if(keepExisting !== true){
11899 this.clearSelections(true);
11901 if(this.isSelected(node)){
11902 this.lastSelNode = node;
11905 this.selNodes.push(node);
11906 this.selMap[node.id] = node;
11907 this.lastSelNode = node;
11908 node.ui.onSelectedChange(true);
11909 this.fireEvent("selectionchange", this, this.selNodes);
11915 * @param {TreeNode} node The node to unselect
11917 unselect : function(node){
11918 if(this.selMap[node.id]){
11919 node.ui.onSelectedChange(false);
11920 var sn = this.selNodes;
11923 index = sn.indexOf(node);
11925 for(var i = 0, len = sn.length; i < len; i++){
11933 this.selNodes.splice(index, 1);
11935 delete this.selMap[node.id];
11936 this.fireEvent("selectionchange", this, this.selNodes);
11941 * Clear all selections
11943 clearSelections : function(suppressEvent){
11944 var sn = this.selNodes;
11946 for(var i = 0, len = sn.length; i < len; i++){
11947 sn[i].ui.onSelectedChange(false);
11949 this.selNodes = [];
11951 if(suppressEvent !== true){
11952 this.fireEvent("selectionchange", this, this.selNodes);
11958 * Returns true if the node is selected
11959 * @param {TreeNode} node The node to check
11960 * @return {Boolean}
11962 isSelected : function(node){
11963 return this.selMap[node.id] ? true : false;
11967 * Returns an array of the selected nodes
11970 getSelectedNodes : function(){
11971 return this.selNodes;
11974 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
11976 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
11978 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
11981 * Ext JS Library 1.1.1
11982 * Copyright(c) 2006-2007, Ext JS, LLC.
11984 * Originally Released Under LGPL - original licence link has changed is not relivant.
11987 * <script type="text/javascript">
11991 * @class Roo.tree.TreeNode
11992 * @extends Roo.data.Node
11993 * @cfg {String} text The text for this node
11994 * @cfg {Boolean} expanded true to start the node expanded
11995 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
11996 * @cfg {Boolean} allowDrop false if this node cannot be drop on
11997 * @cfg {Boolean} disabled true to start the node disabled
11998 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
11999 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
12000 * @cfg {String} cls A css class to be added to the node
12001 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
12002 * @cfg {String} href URL of the link used for the node (defaults to #)
12003 * @cfg {String} hrefTarget target frame for the link
12004 * @cfg {String} qtip An Ext QuickTip for the node
12005 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
12006 * @cfg {Boolean} singleClickExpand True for single click expand on this node
12007 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
12008 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
12009 * (defaults to undefined with no checkbox rendered)
12011 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
12013 Roo.tree.TreeNode = function(attributes){
12014 attributes = attributes || {};
12015 if(typeof attributes == "string"){
12016 attributes = {text: attributes};
12018 this.childrenRendered = false;
12019 this.rendered = false;
12020 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
12021 this.expanded = attributes.expanded === true;
12022 this.isTarget = attributes.isTarget !== false;
12023 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
12024 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
12027 * Read-only. The text for this node. To change it use setText().
12030 this.text = attributes.text;
12032 * True if this node is disabled.
12035 this.disabled = attributes.disabled === true;
12039 * @event textchange
12040 * Fires when the text for this node is changed
12041 * @param {Node} this This node
12042 * @param {String} text The new text
12043 * @param {String} oldText The old text
12045 "textchange" : true,
12047 * @event beforeexpand
12048 * Fires before this node is expanded, return false to cancel.
12049 * @param {Node} this This node
12050 * @param {Boolean} deep
12051 * @param {Boolean} anim
12053 "beforeexpand" : true,
12055 * @event beforecollapse
12056 * Fires before this node is collapsed, return false to cancel.
12057 * @param {Node} this This node
12058 * @param {Boolean} deep
12059 * @param {Boolean} anim
12061 "beforecollapse" : true,
12064 * Fires when this node is expanded
12065 * @param {Node} this This node
12069 * @event disabledchange
12070 * Fires when the disabled status of this node changes
12071 * @param {Node} this This node
12072 * @param {Boolean} disabled
12074 "disabledchange" : true,
12077 * Fires when this node is collapsed
12078 * @param {Node} this This node
12082 * @event beforeclick
12083 * Fires before click processing. Return false to cancel the default action.
12084 * @param {Node} this This node
12085 * @param {Roo.EventObject} e The event object
12087 "beforeclick":true,
12089 * @event checkchange
12090 * Fires when a node with a checkbox's checked property changes
12091 * @param {Node} this This node
12092 * @param {Boolean} checked
12094 "checkchange":true,
12097 * Fires when this node is clicked
12098 * @param {Node} this This node
12099 * @param {Roo.EventObject} e The event object
12104 * Fires when this node is double clicked
12105 * @param {Node} this This node
12106 * @param {Roo.EventObject} e The event object
12110 * @event contextmenu
12111 * Fires when this node is right clicked
12112 * @param {Node} this This node
12113 * @param {Roo.EventObject} e The event object
12115 "contextmenu":true,
12117 * @event beforechildrenrendered
12118 * Fires right before the child nodes for this node are rendered
12119 * @param {Node} this This node
12121 "beforechildrenrendered":true
12124 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
12127 * Read-only. The UI for this node
12130 this.ui = new uiClass(this);
12132 // finally support items[]
12133 if (typeof(this.attributes.items) == 'undefined' || !this.attributes.items) {
12138 Roo.each(this.attributes.items, function(c) {
12139 this.appendChild(Roo.factory(c,Roo.Tree));
12141 delete this.attributes.items;
12146 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
12147 preventHScroll: true,
12149 * Returns true if this node is expanded
12150 * @return {Boolean}
12152 isExpanded : function(){
12153 return this.expanded;
12157 * Returns the UI object for this node
12158 * @return {TreeNodeUI}
12160 getUI : function(){
12164 // private override
12165 setFirstChild : function(node){
12166 var of = this.firstChild;
12167 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
12168 if(this.childrenRendered && of && node != of){
12169 of.renderIndent(true, true);
12172 this.renderIndent(true, true);
12176 // private override
12177 setLastChild : function(node){
12178 var ol = this.lastChild;
12179 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
12180 if(this.childrenRendered && ol && node != ol){
12181 ol.renderIndent(true, true);
12184 this.renderIndent(true, true);
12188 // these methods are overridden to provide lazy rendering support
12189 // private override
12190 appendChild : function()
12192 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
12193 if(node && this.childrenRendered){
12196 this.ui.updateExpandIcon();
12200 // private override
12201 removeChild : function(node){
12202 this.ownerTree.getSelectionModel().unselect(node);
12203 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
12204 // if it's been rendered remove dom node
12205 if(this.childrenRendered){
12208 if(this.childNodes.length < 1){
12209 this.collapse(false, false);
12211 this.ui.updateExpandIcon();
12213 if(!this.firstChild) {
12214 this.childrenRendered = false;
12219 // private override
12220 insertBefore : function(node, refNode){
12221 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
12222 if(newNode && refNode && this.childrenRendered){
12225 this.ui.updateExpandIcon();
12230 * Sets the text for this node
12231 * @param {String} text
12233 setText : function(text){
12234 var oldText = this.text;
12236 this.attributes.text = text;
12237 if(this.rendered){ // event without subscribing
12238 this.ui.onTextChange(this, text, oldText);
12240 this.fireEvent("textchange", this, text, oldText);
12244 * Triggers selection of this node
12246 select : function(){
12247 this.getOwnerTree().getSelectionModel().select(this);
12251 * Triggers deselection of this node
12253 unselect : function(){
12254 this.getOwnerTree().getSelectionModel().unselect(this);
12258 * Returns true if this node is selected
12259 * @return {Boolean}
12261 isSelected : function(){
12262 return this.getOwnerTree().getSelectionModel().isSelected(this);
12266 * Expand this node.
12267 * @param {Boolean} deep (optional) True to expand all children as well
12268 * @param {Boolean} anim (optional) false to cancel the default animation
12269 * @param {Function} callback (optional) A callback to be called when
12270 * expanding this node completes (does not wait for deep expand to complete).
12271 * Called with 1 parameter, this node.
12273 expand : function(deep, anim, callback){
12274 if(!this.expanded){
12275 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
12278 if(!this.childrenRendered){
12279 this.renderChildren();
12281 this.expanded = true;
12283 if(!this.isHiddenRoot() && (this.getOwnerTree() && this.getOwnerTree().animate && anim !== false) || anim){
12284 this.ui.animExpand(function(){
12285 this.fireEvent("expand", this);
12286 if(typeof callback == "function"){
12290 this.expandChildNodes(true);
12292 }.createDelegate(this));
12296 this.fireEvent("expand", this);
12297 if(typeof callback == "function"){
12302 if(typeof callback == "function"){
12307 this.expandChildNodes(true);
12311 isHiddenRoot : function(){
12312 return this.isRoot && !this.getOwnerTree().rootVisible;
12316 * Collapse this node.
12317 * @param {Boolean} deep (optional) True to collapse all children as well
12318 * @param {Boolean} anim (optional) false to cancel the default animation
12320 collapse : function(deep, anim){
12321 if(this.expanded && !this.isHiddenRoot()){
12322 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
12325 this.expanded = false;
12326 if((this.getOwnerTree().animate && anim !== false) || anim){
12327 this.ui.animCollapse(function(){
12328 this.fireEvent("collapse", this);
12330 this.collapseChildNodes(true);
12332 }.createDelegate(this));
12335 this.ui.collapse();
12336 this.fireEvent("collapse", this);
12340 var cs = this.childNodes;
12341 for(var i = 0, len = cs.length; i < len; i++) {
12342 cs[i].collapse(true, false);
12348 delayedExpand : function(delay){
12349 if(!this.expandProcId){
12350 this.expandProcId = this.expand.defer(delay, this);
12355 cancelExpand : function(){
12356 if(this.expandProcId){
12357 clearTimeout(this.expandProcId);
12359 this.expandProcId = false;
12363 * Toggles expanded/collapsed state of the node
12365 toggle : function(){
12374 * Ensures all parent nodes are expanded
12376 ensureVisible : function(callback){
12377 var tree = this.getOwnerTree();
12378 tree.expandPath(this.parentNode.getPath(), false, function(){
12379 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
12380 Roo.callback(callback);
12381 }.createDelegate(this));
12385 * Expand all child nodes
12386 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
12388 expandChildNodes : function(deep){
12389 var cs = this.childNodes;
12390 for(var i = 0, len = cs.length; i < len; i++) {
12391 cs[i].expand(deep);
12396 * Collapse all child nodes
12397 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
12399 collapseChildNodes : function(deep){
12400 var cs = this.childNodes;
12401 for(var i = 0, len = cs.length; i < len; i++) {
12402 cs[i].collapse(deep);
12407 * Disables this node
12409 disable : function(){
12410 this.disabled = true;
12412 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
12413 this.ui.onDisableChange(this, true);
12415 this.fireEvent("disabledchange", this, true);
12419 * Enables this node
12421 enable : function(){
12422 this.disabled = false;
12423 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
12424 this.ui.onDisableChange(this, false);
12426 this.fireEvent("disabledchange", this, false);
12430 renderChildren : function(suppressEvent){
12431 if(suppressEvent !== false){
12432 this.fireEvent("beforechildrenrendered", this);
12434 var cs = this.childNodes;
12435 for(var i = 0, len = cs.length; i < len; i++){
12436 cs[i].render(true);
12438 this.childrenRendered = true;
12442 sort : function(fn, scope){
12443 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
12444 if(this.childrenRendered){
12445 var cs = this.childNodes;
12446 for(var i = 0, len = cs.length; i < len; i++){
12447 cs[i].render(true);
12453 render : function(bulkRender){
12454 this.ui.render(bulkRender);
12455 if(!this.rendered){
12456 this.rendered = true;
12458 this.expanded = false;
12459 this.expand(false, false);
12465 renderIndent : function(deep, refresh){
12467 this.ui.childIndent = null;
12469 this.ui.renderIndent();
12470 if(deep === true && this.childrenRendered){
12471 var cs = this.childNodes;
12472 for(var i = 0, len = cs.length; i < len; i++){
12473 cs[i].renderIndent(true, refresh);
12479 * Ext JS Library 1.1.1
12480 * Copyright(c) 2006-2007, Ext JS, LLC.
12482 * Originally Released Under LGPL - original licence link has changed is not relivant.
12485 * <script type="text/javascript">
12489 * @class Roo.tree.AsyncTreeNode
12490 * @extends Roo.tree.TreeNode
12491 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
12493 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
12495 Roo.tree.AsyncTreeNode = function(config){
12496 this.loaded = false;
12497 this.loading = false;
12498 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
12500 * @event beforeload
12501 * Fires before this node is loaded, return false to cancel
12502 * @param {Node} this This node
12504 this.addEvents({'beforeload':true, 'load': true});
12507 * Fires when this node is loaded
12508 * @param {Node} this This node
12511 * The loader used by this node (defaults to using the tree's defined loader)
12516 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
12517 expand : function(deep, anim, callback){
12518 if(this.loading){ // if an async load is already running, waiting til it's done
12520 var f = function(){
12521 if(!this.loading){ // done loading
12522 clearInterval(timer);
12523 this.expand(deep, anim, callback);
12525 }.createDelegate(this);
12526 timer = setInterval(f, 200);
12530 if(this.fireEvent("beforeload", this) === false){
12533 this.loading = true;
12534 this.ui.beforeLoad(this);
12535 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
12537 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
12541 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
12545 * Returns true if this node is currently loading
12546 * @return {Boolean}
12548 isLoading : function(){
12549 return this.loading;
12552 loadComplete : function(deep, anim, callback){
12553 this.loading = false;
12554 this.loaded = true;
12555 this.ui.afterLoad(this);
12556 this.fireEvent("load", this);
12557 this.expand(deep, anim, callback);
12561 * Returns true if this node has been loaded
12562 * @return {Boolean}
12564 isLoaded : function(){
12565 return this.loaded;
12568 hasChildNodes : function(){
12569 if(!this.isLeaf() && !this.loaded){
12572 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
12577 * Trigger a reload for this node
12578 * @param {Function} callback
12580 reload : function(callback){
12581 this.collapse(false, false);
12582 while(this.firstChild){
12583 this.removeChild(this.firstChild);
12585 this.childrenRendered = false;
12586 this.loaded = false;
12587 if(this.isHiddenRoot()){
12588 this.expanded = false;
12590 this.expand(false, false, callback);
12594 * Ext JS Library 1.1.1
12595 * Copyright(c) 2006-2007, Ext JS, LLC.
12597 * Originally Released Under LGPL - original licence link has changed is not relivant.
12600 * <script type="text/javascript">
12604 * @class Roo.tree.TreeNodeUI
12606 * @param {Object} node The node to render
12607 * The TreeNode UI implementation is separate from the
12608 * tree implementation. Unless you are customizing the tree UI,
12609 * you should never have to use this directly.
12611 Roo.tree.TreeNodeUI = function(node){
12613 this.rendered = false;
12614 this.animating = false;
12615 this.emptyIcon = Roo.BLANK_IMAGE_URL;
12618 Roo.tree.TreeNodeUI.prototype = {
12619 removeChild : function(node){
12621 this.ctNode.removeChild(node.ui.getEl());
12625 beforeLoad : function(){
12626 this.addClass("x-tree-node-loading");
12629 afterLoad : function(){
12630 this.removeClass("x-tree-node-loading");
12633 onTextChange : function(node, text, oldText){
12635 this.textNode.innerHTML = text;
12639 onDisableChange : function(node, state){
12640 this.disabled = state;
12642 this.addClass("x-tree-node-disabled");
12644 this.removeClass("x-tree-node-disabled");
12648 onSelectedChange : function(state){
12651 this.addClass("x-tree-selected");
12654 this.removeClass("x-tree-selected");
12658 onMove : function(tree, node, oldParent, newParent, index, refNode){
12659 this.childIndent = null;
12661 var targetNode = newParent.ui.getContainer();
12662 if(!targetNode){//target not rendered
12663 this.holder = document.createElement("div");
12664 this.holder.appendChild(this.wrap);
12667 var insertBefore = refNode ? refNode.ui.getEl() : null;
12669 targetNode.insertBefore(this.wrap, insertBefore);
12671 targetNode.appendChild(this.wrap);
12673 this.node.renderIndent(true);
12677 addClass : function(cls){
12679 Roo.fly(this.elNode).addClass(cls);
12683 removeClass : function(cls){
12685 Roo.fly(this.elNode).removeClass(cls);
12689 remove : function(){
12691 this.holder = document.createElement("div");
12692 this.holder.appendChild(this.wrap);
12696 fireEvent : function(){
12697 return this.node.fireEvent.apply(this.node, arguments);
12700 initEvents : function(){
12701 this.node.on("move", this.onMove, this);
12702 var E = Roo.EventManager;
12703 var a = this.anchor;
12705 var el = Roo.fly(a, '_treeui');
12707 if(Roo.isOpera){ // opera render bug ignores the CSS
12708 el.setStyle("text-decoration", "none");
12711 el.on("click", this.onClick, this);
12712 el.on("dblclick", this.onDblClick, this);
12715 Roo.EventManager.on(this.checkbox,
12716 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
12719 el.on("contextmenu", this.onContextMenu, this);
12721 var icon = Roo.fly(this.iconNode);
12722 icon.on("click", this.onClick, this);
12723 icon.on("dblclick", this.onDblClick, this);
12724 icon.on("contextmenu", this.onContextMenu, this);
12725 E.on(this.ecNode, "click", this.ecClick, this, true);
12727 if(this.node.disabled){
12728 this.addClass("x-tree-node-disabled");
12730 if(this.node.hidden){
12731 this.addClass("x-tree-node-disabled");
12733 var ot = this.node.getOwnerTree();
12734 var dd = ot ? (ot.enableDD || ot.enableDrag || ot.enableDrop) : false;
12735 if(dd && (!this.node.isRoot || ot.rootVisible)){
12736 Roo.dd.Registry.register(this.elNode, {
12738 handles: this.getDDHandles(),
12744 getDDHandles : function(){
12745 return [this.iconNode, this.textNode];
12750 this.wrap.style.display = "none";
12756 this.wrap.style.display = "";
12760 onContextMenu : function(e){
12761 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
12762 e.preventDefault();
12764 this.fireEvent("contextmenu", this.node, e);
12768 onClick : function(e){
12773 if(this.fireEvent("beforeclick", this.node, e) !== false){
12774 if(!this.disabled && this.node.attributes.href){
12775 this.fireEvent("click", this.node, e);
12778 e.preventDefault();
12783 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
12784 this.node.toggle();
12787 this.fireEvent("click", this.node, e);
12793 onDblClick : function(e){
12794 e.preventDefault();
12799 this.toggleCheck();
12801 if(!this.animating && this.node.hasChildNodes()){
12802 this.node.toggle();
12804 this.fireEvent("dblclick", this.node, e);
12807 onCheckChange : function(){
12808 var checked = this.checkbox.checked;
12809 this.node.attributes.checked = checked;
12810 this.fireEvent('checkchange', this.node, checked);
12813 ecClick : function(e){
12814 if(!this.animating && this.node.hasChildNodes()){
12815 this.node.toggle();
12819 startDrop : function(){
12820 this.dropping = true;
12823 // delayed drop so the click event doesn't get fired on a drop
12824 endDrop : function(){
12825 setTimeout(function(){
12826 this.dropping = false;
12827 }.createDelegate(this), 50);
12830 expand : function(){
12831 this.updateExpandIcon();
12832 this.ctNode.style.display = "";
12835 focus : function(){
12836 if(!this.node.preventHScroll){
12837 try{this.anchor.focus();
12839 }else if(!Roo.isIE){
12841 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
12842 var l = noscroll.scrollLeft;
12843 this.anchor.focus();
12844 noscroll.scrollLeft = l;
12849 toggleCheck : function(value){
12850 var cb = this.checkbox;
12852 cb.checked = (value === undefined ? !cb.checked : value);
12858 this.anchor.blur();
12862 animExpand : function(callback){
12863 var ct = Roo.get(this.ctNode);
12865 if(!this.node.hasChildNodes()){
12866 this.updateExpandIcon();
12867 this.ctNode.style.display = "";
12868 Roo.callback(callback);
12871 this.animating = true;
12872 this.updateExpandIcon();
12875 callback : function(){
12876 this.animating = false;
12877 Roo.callback(callback);
12880 duration: this.node.ownerTree.duration || .25
12884 highlight : function(){
12885 var tree = this.node.getOwnerTree();
12886 Roo.fly(this.wrap).highlight(
12887 tree.hlColor || "C3DAF9",
12888 {endColor: tree.hlBaseColor}
12892 collapse : function(){
12893 this.updateExpandIcon();
12894 this.ctNode.style.display = "none";
12897 animCollapse : function(callback){
12898 var ct = Roo.get(this.ctNode);
12899 ct.enableDisplayMode('block');
12902 this.animating = true;
12903 this.updateExpandIcon();
12906 callback : function(){
12907 this.animating = false;
12908 Roo.callback(callback);
12911 duration: this.node.ownerTree.duration || .25
12915 getContainer : function(){
12916 return this.ctNode;
12919 getEl : function(){
12923 appendDDGhost : function(ghostNode){
12924 ghostNode.appendChild(this.elNode.cloneNode(true));
12927 getDDRepairXY : function(){
12928 return Roo.lib.Dom.getXY(this.iconNode);
12931 onRender : function(){
12935 render : function(bulkRender){
12936 var n = this.node, a = n.attributes;
12937 var targetNode = n.parentNode ?
12938 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
12940 if(!this.rendered){
12941 this.rendered = true;
12943 this.renderElements(n, a, targetNode, bulkRender);
12946 if(this.textNode.setAttributeNS){
12947 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
12949 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
12952 this.textNode.setAttribute("ext:qtip", a.qtip);
12954 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
12957 }else if(a.qtipCfg){
12958 a.qtipCfg.target = Roo.id(this.textNode);
12959 Roo.QuickTips.register(a.qtipCfg);
12962 if(!this.node.expanded){
12963 this.updateExpandIcon();
12966 if(bulkRender === true) {
12967 targetNode.appendChild(this.wrap);
12972 renderElements : function(n, a, targetNode, bulkRender)
12974 // add some indent caching, this helps performance when rendering a large tree
12975 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
12976 var t = n.getOwnerTree();
12977 var txt = t && t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
12978 if (typeof(n.attributes.html) != 'undefined') {
12979 txt = n.attributes.html;
12981 var tip = t && t.rendererTip ? t.rendererTip(n.attributes) : txt;
12982 var cb = typeof a.checked == 'boolean';
12983 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
12984 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
12985 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
12986 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
12987 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
12988 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
12989 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
12990 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
12991 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
12992 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
12995 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
12996 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
12997 n.nextSibling.ui.getEl(), buf.join(""));
12999 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
13002 this.elNode = this.wrap.childNodes[0];
13003 this.ctNode = this.wrap.childNodes[1];
13004 var cs = this.elNode.childNodes;
13005 this.indentNode = cs[0];
13006 this.ecNode = cs[1];
13007 this.iconNode = cs[2];
13010 this.checkbox = cs[3];
13013 this.anchor = cs[index];
13014 this.textNode = cs[index].firstChild;
13017 getAnchor : function(){
13018 return this.anchor;
13021 getTextEl : function(){
13022 return this.textNode;
13025 getIconEl : function(){
13026 return this.iconNode;
13029 isChecked : function(){
13030 return this.checkbox ? this.checkbox.checked : false;
13033 updateExpandIcon : function(){
13035 var n = this.node, c1, c2;
13036 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
13037 var hasChild = n.hasChildNodes();
13041 c1 = "x-tree-node-collapsed";
13042 c2 = "x-tree-node-expanded";
13045 c1 = "x-tree-node-expanded";
13046 c2 = "x-tree-node-collapsed";
13049 this.removeClass("x-tree-node-leaf");
13050 this.wasLeaf = false;
13052 if(this.c1 != c1 || this.c2 != c2){
13053 Roo.fly(this.elNode).replaceClass(c1, c2);
13054 this.c1 = c1; this.c2 = c2;
13057 // this changes non-leafs into leafs if they have no children.
13058 // it's not very rational behaviour..
13060 if(!this.wasLeaf && this.node.leaf){
13061 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
13064 this.wasLeaf = true;
13067 var ecc = "x-tree-ec-icon "+cls;
13068 if(this.ecc != ecc){
13069 this.ecNode.className = ecc;
13075 getChildIndent : function(){
13076 if(!this.childIndent){
13080 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
13082 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
13084 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
13089 this.childIndent = buf.join("");
13091 return this.childIndent;
13094 renderIndent : function(){
13097 var p = this.node.parentNode;
13099 indent = p.ui.getChildIndent();
13101 if(this.indentMarkup != indent){ // don't rerender if not required
13102 this.indentNode.innerHTML = indent;
13103 this.indentMarkup = indent;
13105 this.updateExpandIcon();
13110 Roo.tree.RootTreeNodeUI = function(){
13111 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
13113 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
13114 render : function(){
13115 if(!this.rendered){
13116 var targetNode = this.node.ownerTree.innerCt.dom;
13117 this.node.expanded = true;
13118 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
13119 this.wrap = this.ctNode = targetNode.firstChild;
13122 collapse : function(){
13124 expand : function(){
13128 * Ext JS Library 1.1.1
13129 * Copyright(c) 2006-2007, Ext JS, LLC.
13131 * Originally Released Under LGPL - original licence link has changed is not relivant.
13134 * <script type="text/javascript">
13137 * @class Roo.tree.TreeLoader
13138 * @extends Roo.util.Observable
13139 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
13140 * nodes from a specified URL. The response must be a javascript Array definition
13141 * who's elements are node definition objects. eg:
13146 { 'id': 1, 'text': 'A folder Node', 'leaf': false },
13147 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }
13154 * The old style respose with just an array is still supported, but not recommended.
13157 * A server request is sent, and child nodes are loaded only when a node is expanded.
13158 * The loading node's id is passed to the server under the parameter name "node" to
13159 * enable the server to produce the correct child nodes.
13161 * To pass extra parameters, an event handler may be attached to the "beforeload"
13162 * event, and the parameters specified in the TreeLoader's baseParams property:
13164 myTreeLoader.on("beforeload", function(treeLoader, node) {
13165 this.baseParams.category = node.attributes.category;
13170 * This would pass an HTTP parameter called "category" to the server containing
13171 * the value of the Node's "category" attribute.
13173 * Creates a new Treeloader.
13174 * @param {Object} config A config object containing config properties.
13176 Roo.tree.TreeLoader = function(config){
13177 this.baseParams = {};
13178 this.requestMethod = "POST";
13179 Roo.apply(this, config);
13184 * @event beforeload
13185 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
13186 * @param {Object} This TreeLoader object.
13187 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13188 * @param {Object} callback The callback function specified in the {@link #load} call.
13193 * Fires when the node has been successfuly loaded.
13194 * @param {Object} This TreeLoader object.
13195 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13196 * @param {Object} response The response object containing the data from the server.
13200 * @event loadexception
13201 * Fires if the network request failed.
13202 * @param {Object} This TreeLoader object.
13203 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13204 * @param {Object} response The response object containing the data from the server.
13206 loadexception : true,
13209 * Fires before a node is created, enabling you to return custom Node types
13210 * @param {Object} This TreeLoader object.
13211 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
13216 Roo.tree.TreeLoader.superclass.constructor.call(this);
13219 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
13221 * @cfg {String} dataUrl The URL from which to request a Json string which
13222 * specifies an array of node definition object representing the child nodes
13226 * @cfg {String} requestMethod either GET or POST
13227 * defaults to POST (due to BC)
13231 * @cfg {Object} baseParams (optional) An object containing properties which
13232 * specify HTTP parameters to be passed to each request for child nodes.
13235 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
13236 * created by this loader. If the attributes sent by the server have an attribute in this object,
13237 * they take priority.
13240 * @cfg {Object} uiProviders (optional) An object containing properties which
13242 * DEPRECATED - use 'create' event handler to modify attributes - which affect creation.
13243 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
13244 * <i>uiProvider</i> attribute of a returned child node is a string rather
13245 * than a reference to a TreeNodeUI implementation, this that string value
13246 * is used as a property name in the uiProviders object. You can define the provider named
13247 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
13252 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
13253 * child nodes before loading.
13255 clearOnLoad : true,
13258 * @cfg {String} root (optional) Default to false. Use this to read data from an object
13259 * property on loading, rather than expecting an array. (eg. more compatible to a standard
13260 * Grid query { data : [ .....] }
13265 * @cfg {String} queryParam (optional)
13266 * Name of the query as it will be passed on the querystring (defaults to 'node')
13267 * eg. the request will be ?node=[id]
13274 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
13275 * This is called automatically when a node is expanded, but may be used to reload
13276 * a node (or append new children if the {@link #clearOnLoad} option is false.)
13277 * @param {Roo.tree.TreeNode} node
13278 * @param {Function} callback
13280 load : function(node, callback){
13281 if(this.clearOnLoad){
13282 while(node.firstChild){
13283 node.removeChild(node.firstChild);
13286 if(node.attributes.children){ // preloaded json children
13287 var cs = node.attributes.children;
13288 for(var i = 0, len = cs.length; i < len; i++){
13289 node.appendChild(this.createNode(cs[i]));
13291 if(typeof callback == "function"){
13294 }else if(this.dataUrl){
13295 this.requestData(node, callback);
13299 getParams: function(node){
13300 var buf = [], bp = this.baseParams;
13301 for(var key in bp){
13302 if(typeof bp[key] != "function"){
13303 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
13306 var n = this.queryParam === false ? 'node' : this.queryParam;
13307 buf.push(n + "=", encodeURIComponent(node.id));
13308 return buf.join("");
13311 requestData : function(node, callback){
13312 if(this.fireEvent("beforeload", this, node, callback) !== false){
13313 this.transId = Roo.Ajax.request({
13314 method:this.requestMethod,
13315 url: this.dataUrl||this.url,
13316 success: this.handleResponse,
13317 failure: this.handleFailure,
13319 argument: {callback: callback, node: node},
13320 params: this.getParams(node)
13323 // if the load is cancelled, make sure we notify
13324 // the node that we are done
13325 if(typeof callback == "function"){
13331 isLoading : function(){
13332 return this.transId ? true : false;
13335 abort : function(){
13336 if(this.isLoading()){
13337 Roo.Ajax.abort(this.transId);
13342 createNode : function(attr)
13344 // apply baseAttrs, nice idea Corey!
13345 if(this.baseAttrs){
13346 Roo.applyIf(attr, this.baseAttrs);
13348 if(this.applyLoader !== false){
13349 attr.loader = this;
13351 // uiProvider = depreciated..
13353 if(typeof(attr.uiProvider) == 'string'){
13354 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
13355 /** eval:var:attr */ eval(attr.uiProvider);
13357 if(typeof(this.uiProviders['default']) != 'undefined') {
13358 attr.uiProvider = this.uiProviders['default'];
13361 this.fireEvent('create', this, attr);
13363 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
13365 new Roo.tree.TreeNode(attr) :
13366 new Roo.tree.AsyncTreeNode(attr));
13369 processResponse : function(response, node, callback)
13371 var json = response.responseText;
13374 var o = Roo.decode(json);
13376 if (this.root === false && typeof(o.success) != undefined) {
13377 this.root = 'data'; // the default behaviour for list like data..
13380 if (this.root !== false && !o.success) {
13381 // it's a failure condition.
13382 var a = response.argument;
13383 this.fireEvent("loadexception", this, a.node, response);
13384 Roo.log("Load failed - should have a handler really");
13390 if (this.root !== false) {
13394 for(var i = 0, len = o.length; i < len; i++){
13395 var n = this.createNode(o[i]);
13397 node.appendChild(n);
13400 if(typeof callback == "function"){
13401 callback(this, node);
13404 this.handleFailure(response);
13408 handleResponse : function(response){
13409 this.transId = false;
13410 var a = response.argument;
13411 this.processResponse(response, a.node, a.callback);
13412 this.fireEvent("load", this, a.node, response);
13415 handleFailure : function(response)
13417 // should handle failure better..
13418 this.transId = false;
13419 var a = response.argument;
13420 this.fireEvent("loadexception", this, a.node, response);
13421 if(typeof a.callback == "function"){
13422 a.callback(this, a.node);
13427 * Ext JS Library 1.1.1
13428 * Copyright(c) 2006-2007, Ext JS, LLC.
13430 * Originally Released Under LGPL - original licence link has changed is not relivant.
13433 * <script type="text/javascript">
13437 * @class Roo.tree.TreeFilter
13438 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
13439 * @param {TreePanel} tree
13440 * @param {Object} config (optional)
13442 Roo.tree.TreeFilter = function(tree, config){
13444 this.filtered = {};
13445 Roo.apply(this, config);
13448 Roo.tree.TreeFilter.prototype = {
13455 * Filter the data by a specific attribute.
13456 * @param {String/RegExp} value Either string that the attribute value
13457 * should start with or a RegExp to test against the attribute
13458 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
13459 * @param {TreeNode} startNode (optional) The node to start the filter at.
13461 filter : function(value, attr, startNode){
13462 attr = attr || "text";
13464 if(typeof value == "string"){
13465 var vlen = value.length;
13466 // auto clear empty filter
13467 if(vlen == 0 && this.clearBlank){
13471 value = value.toLowerCase();
13473 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
13475 }else if(value.exec){ // regex?
13477 return value.test(n.attributes[attr]);
13480 throw 'Illegal filter type, must be string or regex';
13482 this.filterBy(f, null, startNode);
13486 * Filter by a function. The passed function will be called with each
13487 * node in the tree (or from the startNode). If the function returns true, the node is kept
13488 * otherwise it is filtered. If a node is filtered, its children are also filtered.
13489 * @param {Function} fn The filter function
13490 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
13492 filterBy : function(fn, scope, startNode){
13493 startNode = startNode || this.tree.root;
13494 if(this.autoClear){
13497 var af = this.filtered, rv = this.reverse;
13498 var f = function(n){
13499 if(n == startNode){
13505 var m = fn.call(scope || n, n);
13513 startNode.cascade(f);
13516 if(typeof id != "function"){
13518 if(n && n.parentNode){
13519 n.parentNode.removeChild(n);
13527 * Clears the current filter. Note: with the "remove" option
13528 * set a filter cannot be cleared.
13530 clear : function(){
13532 var af = this.filtered;
13534 if(typeof id != "function"){
13541 this.filtered = {};
13546 * Ext JS Library 1.1.1
13547 * Copyright(c) 2006-2007, Ext JS, LLC.
13549 * Originally Released Under LGPL - original licence link has changed is not relivant.
13552 * <script type="text/javascript">
13557 * @class Roo.tree.TreeSorter
13558 * Provides sorting of nodes in a TreePanel
13560 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
13561 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
13562 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
13563 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
13564 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
13565 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
13567 * @param {TreePanel} tree
13568 * @param {Object} config
13570 Roo.tree.TreeSorter = function(tree, config){
13571 Roo.apply(this, config);
13572 tree.on("beforechildrenrendered", this.doSort, this);
13573 tree.on("append", this.updateSort, this);
13574 tree.on("insert", this.updateSort, this);
13576 var dsc = this.dir && this.dir.toLowerCase() == "desc";
13577 var p = this.property || "text";
13578 var sortType = this.sortType;
13579 var fs = this.folderSort;
13580 var cs = this.caseSensitive === true;
13581 var leafAttr = this.leafAttr || 'leaf';
13583 this.sortFn = function(n1, n2){
13585 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
13588 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
13592 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
13593 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
13595 return dsc ? +1 : -1;
13597 return dsc ? -1 : +1;
13604 Roo.tree.TreeSorter.prototype = {
13605 doSort : function(node){
13606 node.sort(this.sortFn);
13609 compareNodes : function(n1, n2){
13610 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
13613 updateSort : function(tree, node){
13614 if(node.childrenRendered){
13615 this.doSort.defer(1, this, [node]);
13620 * Ext JS Library 1.1.1
13621 * Copyright(c) 2006-2007, Ext JS, LLC.
13623 * Originally Released Under LGPL - original licence link has changed is not relivant.
13626 * <script type="text/javascript">
13629 if(Roo.dd.DropZone){
13631 Roo.tree.TreeDropZone = function(tree, config){
13632 this.allowParentInsert = false;
13633 this.allowContainerDrop = false;
13634 this.appendOnly = false;
13635 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
13637 this.lastInsertClass = "x-tree-no-status";
13638 this.dragOverData = {};
13641 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
13642 ddGroup : "TreeDD",
13645 expandDelay : 1000,
13647 expandNode : function(node){
13648 if(node.hasChildNodes() && !node.isExpanded()){
13649 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
13653 queueExpand : function(node){
13654 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
13657 cancelExpand : function(){
13658 if(this.expandProcId){
13659 clearTimeout(this.expandProcId);
13660 this.expandProcId = false;
13664 isValidDropPoint : function(n, pt, dd, e, data){
13665 if(!n || !data){ return false; }
13666 var targetNode = n.node;
13667 var dropNode = data.node;
13668 // default drop rules
13669 if(!(targetNode && targetNode.isTarget && pt)){
13672 if(pt == "append" && targetNode.allowChildren === false){
13675 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
13678 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
13681 // reuse the object
13682 var overEvent = this.dragOverData;
13683 overEvent.tree = this.tree;
13684 overEvent.target = targetNode;
13685 overEvent.data = data;
13686 overEvent.point = pt;
13687 overEvent.source = dd;
13688 overEvent.rawEvent = e;
13689 overEvent.dropNode = dropNode;
13690 overEvent.cancel = false;
13691 var result = this.tree.fireEvent("nodedragover", overEvent);
13692 return overEvent.cancel === false && result !== false;
13695 getDropPoint : function(e, n, dd)
13699 return tn.allowChildren !== false ? "append" : false; // always append for root
13701 var dragEl = n.ddel;
13702 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
13703 var y = Roo.lib.Event.getPageY(e);
13704 //var noAppend = tn.allowChildren === false || tn.isLeaf();
13706 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
13707 var noAppend = tn.allowChildren === false;
13708 if(this.appendOnly || tn.parentNode.allowChildren === false){
13709 return noAppend ? false : "append";
13711 var noBelow = false;
13712 if(!this.allowParentInsert){
13713 noBelow = tn.hasChildNodes() && tn.isExpanded();
13715 var q = (b - t) / (noAppend ? 2 : 3);
13716 if(y >= t && y < (t + q)){
13718 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
13725 onNodeEnter : function(n, dd, e, data)
13727 this.cancelExpand();
13730 onNodeOver : function(n, dd, e, data)
13733 var pt = this.getDropPoint(e, n, dd);
13736 // auto node expand check
13737 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
13738 this.queueExpand(node);
13739 }else if(pt != "append"){
13740 this.cancelExpand();
13743 // set the insert point style on the target node
13744 var returnCls = this.dropNotAllowed;
13745 if(this.isValidDropPoint(n, pt, dd, e, data)){
13750 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
13751 cls = "x-tree-drag-insert-above";
13752 }else if(pt == "below"){
13753 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
13754 cls = "x-tree-drag-insert-below";
13756 returnCls = "x-tree-drop-ok-append";
13757 cls = "x-tree-drag-append";
13759 if(this.lastInsertClass != cls){
13760 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
13761 this.lastInsertClass = cls;
13768 onNodeOut : function(n, dd, e, data){
13770 this.cancelExpand();
13771 this.removeDropIndicators(n);
13774 onNodeDrop : function(n, dd, e, data){
13775 var point = this.getDropPoint(e, n, dd);
13776 var targetNode = n.node;
13777 targetNode.ui.startDrop();
13778 if(!this.isValidDropPoint(n, point, dd, e, data)){
13779 targetNode.ui.endDrop();
13782 // first try to find the drop node
13783 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
13786 target: targetNode,
13791 dropNode: dropNode,
13794 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
13795 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
13796 targetNode.ui.endDrop();
13799 // allow target changing
13800 targetNode = dropEvent.target;
13801 if(point == "append" && !targetNode.isExpanded()){
13802 targetNode.expand(false, null, function(){
13803 this.completeDrop(dropEvent);
13804 }.createDelegate(this));
13806 this.completeDrop(dropEvent);
13811 completeDrop : function(de){
13812 var ns = de.dropNode, p = de.point, t = de.target;
13813 if(!(ns instanceof Array)){
13817 for(var i = 0, len = ns.length; i < len; i++){
13820 t.parentNode.insertBefore(n, t);
13821 }else if(p == "below"){
13822 t.parentNode.insertBefore(n, t.nextSibling);
13828 if(this.tree.hlDrop){
13832 this.tree.fireEvent("nodedrop", de);
13835 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
13836 if(this.tree.hlDrop){
13837 dropNode.ui.focus();
13838 dropNode.ui.highlight();
13840 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
13843 getTree : function(){
13847 removeDropIndicators : function(n){
13850 Roo.fly(el).removeClass([
13851 "x-tree-drag-insert-above",
13852 "x-tree-drag-insert-below",
13853 "x-tree-drag-append"]);
13854 this.lastInsertClass = "_noclass";
13858 beforeDragDrop : function(target, e, id){
13859 this.cancelExpand();
13863 afterRepair : function(data){
13864 if(data && Roo.enableFx){
13865 data.node.ui.highlight();
13875 * Ext JS Library 1.1.1
13876 * Copyright(c) 2006-2007, Ext JS, LLC.
13878 * Originally Released Under LGPL - original licence link has changed is not relivant.
13881 * <script type="text/javascript">
13885 if(Roo.dd.DragZone){
13886 Roo.tree.TreeDragZone = function(tree, config){
13887 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
13891 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
13892 ddGroup : "TreeDD",
13894 onBeforeDrag : function(data, e){
13896 return n && n.draggable && !n.disabled;
13900 onInitDrag : function(e){
13901 var data = this.dragData;
13902 this.tree.getSelectionModel().select(data.node);
13903 this.proxy.update("");
13904 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
13905 this.tree.fireEvent("startdrag", this.tree, data.node, e);
13908 getRepairXY : function(e, data){
13909 return data.node.ui.getDDRepairXY();
13912 onEndDrag : function(data, e){
13913 this.tree.fireEvent("enddrag", this.tree, data.node, e);
13918 onValidDrop : function(dd, e, id){
13919 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
13923 beforeInvalidDrop : function(e, id){
13924 // this scrolls the original position back into view
13925 var sm = this.tree.getSelectionModel();
13926 sm.clearSelections();
13927 sm.select(this.dragData.node);
13932 * Ext JS Library 1.1.1
13933 * Copyright(c) 2006-2007, Ext JS, LLC.
13935 * Originally Released Under LGPL - original licence link has changed is not relivant.
13938 * <script type="text/javascript">
13941 * @class Roo.tree.TreeEditor
13942 * @extends Roo.Editor
13943 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
13944 * as the editor field.
13946 * @param {Object} config (used to be the tree panel.)
13947 * @param {Object} oldconfig DEPRECIATED Either a prebuilt {@link Roo.form.Field} instance or a Field config object
13949 * @cfg {Roo.tree.TreePanel} tree The tree to bind to.
13950 * @cfg {Roo.form.TextField|Object} field The field configuration
13954 Roo.tree.TreeEditor = function(config, oldconfig) { // was -- (tree, config){
13957 if (oldconfig) { // old style..
13958 field = oldconfig.events ? oldconfig : new Roo.form.TextField(oldconfig);
13961 tree = config.tree;
13962 config.field = config.field || {};
13963 config.field.xtype = 'TextField';
13964 field = Roo.factory(config.field, Roo.form);
13966 config = config || {};
13971 * @event beforenodeedit
13972 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
13973 * false from the handler of this event.
13974 * @param {Editor} this
13975 * @param {Roo.tree.Node} node
13977 "beforenodeedit" : true
13981 Roo.tree.TreeEditor.superclass.constructor.call(this, field, config);
13985 tree.on('beforeclick', this.beforeNodeClick, this);
13986 tree.getTreeEl().on('mousedown', this.hide, this);
13987 this.on('complete', this.updateNode, this);
13988 this.on('beforestartedit', this.fitToTree, this);
13989 this.on('startedit', this.bindScroll, this, {delay:10});
13990 this.on('specialkey', this.onSpecialKey, this);
13993 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
13995 * @cfg {String} alignment
13996 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
14002 * @cfg {Boolean} hideEl
14003 * True to hide the bound element while the editor is displayed (defaults to false)
14007 * @cfg {String} cls
14008 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
14010 cls: "x-small-editor x-tree-editor",
14012 * @cfg {Boolean} shim
14013 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
14019 * @cfg {Number} maxWidth
14020 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
14021 * the containing tree element's size, it will be automatically limited for you to the container width, taking
14022 * scroll and client offsets into account prior to each edit.
14029 fitToTree : function(ed, el){
14030 var td = this.tree.getTreeEl().dom, nd = el.dom;
14031 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
14032 td.scrollLeft = nd.offsetLeft;
14036 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
14037 this.setSize(w, '');
14039 return this.fireEvent('beforenodeedit', this, this.editNode);
14044 triggerEdit : function(node){
14045 this.completeEdit();
14046 this.editNode = node;
14047 this.startEdit(node.ui.textNode, node.text);
14051 bindScroll : function(){
14052 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
14056 beforeNodeClick : function(node, e){
14057 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
14058 this.lastClick = new Date();
14059 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
14061 this.triggerEdit(node);
14068 updateNode : function(ed, value){
14069 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
14070 this.editNode.setText(value);
14074 onHide : function(){
14075 Roo.tree.TreeEditor.superclass.onHide.call(this);
14077 this.editNode.ui.focus();
14082 onSpecialKey : function(field, e){
14083 var k = e.getKey();
14087 }else if(k == e.ENTER && !e.hasModifier()){
14089 this.completeEdit();
14092 });//<Script type="text/javascript">
14095 * Ext JS Library 1.1.1
14096 * Copyright(c) 2006-2007, Ext JS, LLC.
14098 * Originally Released Under LGPL - original licence link has changed is not relivant.
14101 * <script type="text/javascript">
14105 * Not documented??? - probably should be...
14108 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
14109 //focus: Roo.emptyFn, // prevent odd scrolling behavior
14111 renderElements : function(n, a, targetNode, bulkRender){
14112 //consel.log("renderElements?");
14113 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
14115 var t = n.getOwnerTree();
14116 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
14118 var cols = t.columns;
14119 var bw = t.borderWidth;
14121 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
14122 var cb = typeof a.checked == "boolean";
14123 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
14124 var colcls = 'x-t-' + tid + '-c0';
14126 '<li class="x-tree-node">',
14129 '<div class="x-tree-node-el ', a.cls,'">',
14131 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
14134 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
14135 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
14136 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
14137 (a.icon ? ' x-tree-node-inline-icon' : ''),
14138 (a.iconCls ? ' '+a.iconCls : ''),
14139 '" unselectable="on" />',
14140 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
14141 (a.checked ? 'checked="checked" />' : ' />')) : ''),
14143 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
14144 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
14145 '<span unselectable="on" qtip="' + tx + '">',
14149 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
14150 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>'
14152 for(var i = 1, len = cols.length; i < len; i++){
14154 colcls = 'x-t-' + tid + '-c' +i;
14155 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
14156 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
14157 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
14163 '<div class="x-clear"></div></div>',
14164 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
14167 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
14168 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
14169 n.nextSibling.ui.getEl(), buf.join(""));
14171 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
14173 var el = this.wrap.firstChild;
14175 this.elNode = el.firstChild;
14176 this.ranchor = el.childNodes[1];
14177 this.ctNode = this.wrap.childNodes[1];
14178 var cs = el.firstChild.childNodes;
14179 this.indentNode = cs[0];
14180 this.ecNode = cs[1];
14181 this.iconNode = cs[2];
14184 this.checkbox = cs[3];
14187 this.anchor = cs[index];
14189 this.textNode = cs[index].firstChild;
14191 //el.on("click", this.onClick, this);
14192 //el.on("dblclick", this.onDblClick, this);
14195 // console.log(this);
14197 initEvents : function(){
14198 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
14201 var a = this.ranchor;
14203 var el = Roo.get(a);
14205 if(Roo.isOpera){ // opera render bug ignores the CSS
14206 el.setStyle("text-decoration", "none");
14209 el.on("click", this.onClick, this);
14210 el.on("dblclick", this.onDblClick, this);
14211 el.on("contextmenu", this.onContextMenu, this);
14215 /*onSelectedChange : function(state){
14218 this.addClass("x-tree-selected");
14221 this.removeClass("x-tree-selected");
14224 addClass : function(cls){
14226 Roo.fly(this.elRow).addClass(cls);
14232 removeClass : function(cls){
14234 Roo.fly(this.elRow).removeClass(cls);
14240 });//<Script type="text/javascript">
14244 * Ext JS Library 1.1.1
14245 * Copyright(c) 2006-2007, Ext JS, LLC.
14247 * Originally Released Under LGPL - original licence link has changed is not relivant.
14250 * <script type="text/javascript">
14255 * @class Roo.tree.ColumnTree
14256 * @extends Roo.data.TreePanel
14257 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
14258 * @cfg {int} borderWidth compined right/left border allowance
14260 * @param {String/HTMLElement/Element} el The container element
14261 * @param {Object} config
14263 Roo.tree.ColumnTree = function(el, config)
14265 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
14269 * Fire this event on a container when it resizes
14270 * @param {int} w Width
14271 * @param {int} h Height
14275 this.on('resize', this.onResize, this);
14278 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
14282 borderWidth: Roo.isBorderBox ? 0 : 2,
14285 render : function(){
14286 // add the header.....
14288 Roo.tree.ColumnTree.superclass.render.apply(this);
14290 this.el.addClass('x-column-tree');
14292 this.headers = this.el.createChild(
14293 {cls:'x-tree-headers'},this.innerCt.dom);
14295 var cols = this.columns, c;
14296 var totalWidth = 0;
14298 var len = cols.length;
14299 for(var i = 0; i < len; i++){
14301 totalWidth += c.width;
14302 this.headEls.push(this.headers.createChild({
14303 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
14305 cls:'x-tree-hd-text',
14308 style:'width:'+(c.width-this.borderWidth)+'px;'
14311 this.headers.createChild({cls:'x-clear'});
14312 // prevent floats from wrapping when clipped
14313 this.headers.setWidth(totalWidth);
14314 //this.innerCt.setWidth(totalWidth);
14315 this.innerCt.setStyle({ overflow: 'auto' });
14316 this.onResize(this.width, this.height);
14320 onResize : function(w,h)
14325 this.innerCt.setWidth(this.width);
14326 this.innerCt.setHeight(this.height-20);
14329 var cols = this.columns, c;
14330 var totalWidth = 0;
14332 var len = cols.length;
14333 for(var i = 0; i < len; i++){
14335 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
14336 // it's the expander..
14337 expEl = this.headEls[i];
14340 totalWidth += c.width;
14344 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
14346 this.headers.setWidth(w-20);
14355 * Ext JS Library 1.1.1
14356 * Copyright(c) 2006-2007, Ext JS, LLC.
14358 * Originally Released Under LGPL - original licence link has changed is not relivant.
14361 * <script type="text/javascript">
14365 * @class Roo.menu.Menu
14366 * @extends Roo.util.Observable
14367 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
14368 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
14370 * Creates a new Menu
14371 * @param {Object} config Configuration options
14373 Roo.menu.Menu = function(config){
14375 Roo.menu.Menu.superclass.constructor.call(this, config);
14377 this.id = this.id || Roo.id();
14380 * @event beforeshow
14381 * Fires before this menu is displayed
14382 * @param {Roo.menu.Menu} this
14386 * @event beforehide
14387 * Fires before this menu is hidden
14388 * @param {Roo.menu.Menu} this
14393 * Fires after this menu is displayed
14394 * @param {Roo.menu.Menu} this
14399 * Fires after this menu is hidden
14400 * @param {Roo.menu.Menu} this
14405 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
14406 * @param {Roo.menu.Menu} this
14407 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14408 * @param {Roo.EventObject} e
14413 * Fires when the mouse is hovering over this menu
14414 * @param {Roo.menu.Menu} this
14415 * @param {Roo.EventObject} e
14416 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14421 * Fires when the mouse exits this menu
14422 * @param {Roo.menu.Menu} this
14423 * @param {Roo.EventObject} e
14424 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14429 * Fires when a menu item contained in this menu is clicked
14430 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
14431 * @param {Roo.EventObject} e
14435 if (this.registerMenu) {
14436 Roo.menu.MenuMgr.register(this);
14439 var mis = this.items;
14440 this.items = new Roo.util.MixedCollection();
14442 this.add.apply(this, mis);
14446 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
14448 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
14452 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
14453 * for bottom-right shadow (defaults to "sides")
14457 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
14458 * this menu (defaults to "tl-tr?")
14460 subMenuAlign : "tl-tr?",
14462 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
14463 * relative to its element of origin (defaults to "tl-bl?")
14465 defaultAlign : "tl-bl?",
14467 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
14469 allowOtherMenus : false,
14471 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
14473 registerMenu : true,
14478 render : function(){
14482 var el = this.el = new Roo.Layer({
14484 shadow:this.shadow,
14486 parentEl: this.parentEl || document.body,
14490 this.keyNav = new Roo.menu.MenuNav(this);
14493 el.addClass("x-menu-plain");
14496 el.addClass(this.cls);
14498 // generic focus element
14499 this.focusEl = el.createChild({
14500 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
14502 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
14503 //disabling touch- as it's causing issues ..
14504 //ul.on(Roo.isTouch ? 'touchstart' : 'click' , this.onClick, this);
14505 ul.on('click' , this.onClick, this);
14508 ul.on("mouseover", this.onMouseOver, this);
14509 ul.on("mouseout", this.onMouseOut, this);
14510 this.items.each(function(item){
14515 var li = document.createElement("li");
14516 li.className = "x-menu-list-item";
14517 ul.dom.appendChild(li);
14518 item.render(li, this);
14525 autoWidth : function(){
14526 var el = this.el, ul = this.ul;
14530 var w = this.width;
14533 }else if(Roo.isIE){
14534 el.setWidth(this.minWidth);
14535 var t = el.dom.offsetWidth; // force recalc
14536 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
14541 delayAutoWidth : function(){
14544 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
14546 this.awTask.delay(20);
14551 findTargetItem : function(e){
14552 var t = e.getTarget(".x-menu-list-item", this.ul, true);
14553 if(t && t.menuItemId){
14554 return this.items.get(t.menuItemId);
14559 onClick : function(e){
14560 Roo.log("menu.onClick");
14561 var t = this.findTargetItem(e);
14566 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
14567 if(t == this.activeItem && t.shouldDeactivate(e)){
14568 this.activeItem.deactivate();
14569 delete this.activeItem;
14573 this.setActiveItem(t, true);
14581 this.fireEvent("click", this, t, e);
14585 setActiveItem : function(item, autoExpand){
14586 if(item != this.activeItem){
14587 if(this.activeItem){
14588 this.activeItem.deactivate();
14590 this.activeItem = item;
14591 item.activate(autoExpand);
14592 }else if(autoExpand){
14598 tryActivate : function(start, step){
14599 var items = this.items;
14600 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
14601 var item = items.get(i);
14602 if(!item.disabled && item.canActivate){
14603 this.setActiveItem(item, false);
14611 onMouseOver : function(e){
14613 if(t = this.findTargetItem(e)){
14614 if(t.canActivate && !t.disabled){
14615 this.setActiveItem(t, true);
14618 this.fireEvent("mouseover", this, e, t);
14622 onMouseOut : function(e){
14624 if(t = this.findTargetItem(e)){
14625 if(t == this.activeItem && t.shouldDeactivate(e)){
14626 this.activeItem.deactivate();
14627 delete this.activeItem;
14630 this.fireEvent("mouseout", this, e, t);
14634 * Read-only. Returns true if the menu is currently displayed, else false.
14637 isVisible : function(){
14638 return this.el && !this.hidden;
14642 * Displays this menu relative to another element
14643 * @param {String/HTMLElement/Roo.Element} element The element to align to
14644 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
14645 * the element (defaults to this.defaultAlign)
14646 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
14648 show : function(el, pos, parentMenu){
14649 this.parentMenu = parentMenu;
14653 this.fireEvent("beforeshow", this);
14654 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
14658 * Displays this menu at a specific xy position
14659 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
14660 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
14662 showAt : function(xy, parentMenu, /* private: */_e){
14663 this.parentMenu = parentMenu;
14668 this.fireEvent("beforeshow", this);
14669 xy = this.el.adjustForConstraints(xy);
14673 this.hidden = false;
14675 this.fireEvent("show", this);
14678 focus : function(){
14680 this.doFocus.defer(50, this);
14684 doFocus : function(){
14686 this.focusEl.focus();
14691 * Hides this menu and optionally all parent menus
14692 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
14694 hide : function(deep){
14695 if(this.el && this.isVisible()){
14696 this.fireEvent("beforehide", this);
14697 if(this.activeItem){
14698 this.activeItem.deactivate();
14699 this.activeItem = null;
14702 this.hidden = true;
14703 this.fireEvent("hide", this);
14705 if(deep === true && this.parentMenu){
14706 this.parentMenu.hide(true);
14711 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
14712 * Any of the following are valid:
14714 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
14715 * <li>An HTMLElement object which will be converted to a menu item</li>
14716 * <li>A menu item config object that will be created as a new menu item</li>
14717 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
14718 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
14723 var menu = new Roo.menu.Menu();
14725 // Create a menu item to add by reference
14726 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
14728 // Add a bunch of items at once using different methods.
14729 // Only the last item added will be returned.
14730 var item = menu.add(
14731 menuItem, // add existing item by ref
14732 'Dynamic Item', // new TextItem
14733 '-', // new separator
14734 { text: 'Config Item' } // new item by config
14737 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
14738 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
14741 var a = arguments, l = a.length, item;
14742 for(var i = 0; i < l; i++){
14744 if ((typeof(el) == "object") && el.xtype && el.xns) {
14745 el = Roo.factory(el, Roo.menu);
14748 if(el.render){ // some kind of Item
14749 item = this.addItem(el);
14750 }else if(typeof el == "string"){ // string
14751 if(el == "separator" || el == "-"){
14752 item = this.addSeparator();
14754 item = this.addText(el);
14756 }else if(el.tagName || el.el){ // element
14757 item = this.addElement(el);
14758 }else if(typeof el == "object"){ // must be menu item config?
14759 item = this.addMenuItem(el);
14766 * Returns this menu's underlying {@link Roo.Element} object
14767 * @return {Roo.Element} The element
14769 getEl : function(){
14777 * Adds a separator bar to the menu
14778 * @return {Roo.menu.Item} The menu item that was added
14780 addSeparator : function(){
14781 return this.addItem(new Roo.menu.Separator());
14785 * Adds an {@link Roo.Element} object to the menu
14786 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
14787 * @return {Roo.menu.Item} The menu item that was added
14789 addElement : function(el){
14790 return this.addItem(new Roo.menu.BaseItem(el));
14794 * Adds an existing object based on {@link Roo.menu.Item} to the menu
14795 * @param {Roo.menu.Item} item The menu item to add
14796 * @return {Roo.menu.Item} The menu item that was added
14798 addItem : function(item){
14799 this.items.add(item);
14801 var li = document.createElement("li");
14802 li.className = "x-menu-list-item";
14803 this.ul.dom.appendChild(li);
14804 item.render(li, this);
14805 this.delayAutoWidth();
14811 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
14812 * @param {Object} config A MenuItem config object
14813 * @return {Roo.menu.Item} The menu item that was added
14815 addMenuItem : function(config){
14816 if(!(config instanceof Roo.menu.Item)){
14817 if(typeof config.checked == "boolean"){ // must be check menu item config?
14818 config = new Roo.menu.CheckItem(config);
14820 config = new Roo.menu.Item(config);
14823 return this.addItem(config);
14827 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
14828 * @param {String} text The text to display in the menu item
14829 * @return {Roo.menu.Item} The menu item that was added
14831 addText : function(text){
14832 return this.addItem(new Roo.menu.TextItem({ text : text }));
14836 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
14837 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
14838 * @param {Roo.menu.Item} item The menu item to add
14839 * @return {Roo.menu.Item} The menu item that was added
14841 insert : function(index, item){
14842 this.items.insert(index, item);
14844 var li = document.createElement("li");
14845 li.className = "x-menu-list-item";
14846 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
14847 item.render(li, this);
14848 this.delayAutoWidth();
14854 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
14855 * @param {Roo.menu.Item} item The menu item to remove
14857 remove : function(item){
14858 this.items.removeKey(item.id);
14863 * Removes and destroys all items in the menu
14865 removeAll : function(){
14867 while(f = this.items.first()){
14873 // MenuNav is a private utility class used internally by the Menu
14874 Roo.menu.MenuNav = function(menu){
14875 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
14876 this.scope = this.menu = menu;
14879 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
14880 doRelay : function(e, h){
14881 var k = e.getKey();
14882 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
14883 this.menu.tryActivate(0, 1);
14886 return h.call(this.scope || this, e, this.menu);
14889 up : function(e, m){
14890 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
14891 m.tryActivate(m.items.length-1, -1);
14895 down : function(e, m){
14896 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
14897 m.tryActivate(0, 1);
14901 right : function(e, m){
14903 m.activeItem.expandMenu(true);
14907 left : function(e, m){
14909 if(m.parentMenu && m.parentMenu.activeItem){
14910 m.parentMenu.activeItem.activate();
14914 enter : function(e, m){
14916 e.stopPropagation();
14917 m.activeItem.onClick(e);
14918 m.fireEvent("click", this, m.activeItem);
14924 * Ext JS Library 1.1.1
14925 * Copyright(c) 2006-2007, Ext JS, LLC.
14927 * Originally Released Under LGPL - original licence link has changed is not relivant.
14930 * <script type="text/javascript">
14934 * @class Roo.menu.MenuMgr
14935 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
14938 Roo.menu.MenuMgr = function(){
14939 var menus, active, groups = {}, attached = false, lastShow = new Date();
14941 // private - called when first menu is created
14944 active = new Roo.util.MixedCollection();
14945 Roo.get(document).addKeyListener(27, function(){
14946 if(active.length > 0){
14953 function hideAll(){
14954 if(active && active.length > 0){
14955 var c = active.clone();
14956 c.each(function(m){
14963 function onHide(m){
14965 if(active.length < 1){
14966 Roo.get(document).un("mousedown", onMouseDown);
14972 function onShow(m){
14973 var last = active.last();
14974 lastShow = new Date();
14977 Roo.get(document).on("mousedown", onMouseDown);
14981 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
14982 m.parentMenu.activeChild = m;
14983 }else if(last && last.isVisible()){
14984 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
14989 function onBeforeHide(m){
14991 m.activeChild.hide();
14993 if(m.autoHideTimer){
14994 clearTimeout(m.autoHideTimer);
14995 delete m.autoHideTimer;
15000 function onBeforeShow(m){
15001 var pm = m.parentMenu;
15002 if(!pm && !m.allowOtherMenus){
15004 }else if(pm && pm.activeChild && active != m){
15005 pm.activeChild.hide();
15010 function onMouseDown(e){
15011 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
15017 function onBeforeCheck(mi, state){
15019 var g = groups[mi.group];
15020 for(var i = 0, l = g.length; i < l; i++){
15022 g[i].setChecked(false);
15031 * Hides all menus that are currently visible
15033 hideAll : function(){
15038 register : function(menu){
15042 menus[menu.id] = menu;
15043 menu.on("beforehide", onBeforeHide);
15044 menu.on("hide", onHide);
15045 menu.on("beforeshow", onBeforeShow);
15046 menu.on("show", onShow);
15047 var g = menu.group;
15048 if(g && menu.events["checkchange"]){
15052 groups[g].push(menu);
15053 menu.on("checkchange", onCheck);
15058 * Returns a {@link Roo.menu.Menu} object
15059 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
15060 * be used to generate and return a new Menu instance.
15062 get : function(menu){
15063 if(typeof menu == "string"){ // menu id
15064 return menus[menu];
15065 }else if(menu.events){ // menu instance
15067 }else if(typeof menu.length == 'number'){ // array of menu items?
15068 return new Roo.menu.Menu({items:menu});
15069 }else{ // otherwise, must be a config
15070 return new Roo.menu.Menu(menu);
15075 unregister : function(menu){
15076 delete menus[menu.id];
15077 menu.un("beforehide", onBeforeHide);
15078 menu.un("hide", onHide);
15079 menu.un("beforeshow", onBeforeShow);
15080 menu.un("show", onShow);
15081 var g = menu.group;
15082 if(g && menu.events["checkchange"]){
15083 groups[g].remove(menu);
15084 menu.un("checkchange", onCheck);
15089 registerCheckable : function(menuItem){
15090 var g = menuItem.group;
15095 groups[g].push(menuItem);
15096 menuItem.on("beforecheckchange", onBeforeCheck);
15101 unregisterCheckable : function(menuItem){
15102 var g = menuItem.group;
15104 groups[g].remove(menuItem);
15105 menuItem.un("beforecheckchange", onBeforeCheck);
15111 * Ext JS Library 1.1.1
15112 * Copyright(c) 2006-2007, Ext JS, LLC.
15114 * Originally Released Under LGPL - original licence link has changed is not relivant.
15117 * <script type="text/javascript">
15122 * @class Roo.menu.BaseItem
15123 * @extends Roo.Component
15124 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
15125 * management and base configuration options shared by all menu components.
15127 * Creates a new BaseItem
15128 * @param {Object} config Configuration options
15130 Roo.menu.BaseItem = function(config){
15131 Roo.menu.BaseItem.superclass.constructor.call(this, config);
15136 * Fires when this item is clicked
15137 * @param {Roo.menu.BaseItem} this
15138 * @param {Roo.EventObject} e
15143 * Fires when this item is activated
15144 * @param {Roo.menu.BaseItem} this
15148 * @event deactivate
15149 * Fires when this item is deactivated
15150 * @param {Roo.menu.BaseItem} this
15156 this.on("click", this.handler, this.scope, true);
15160 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
15162 * @cfg {Function} handler
15163 * A function that will handle the click event of this menu item (defaults to undefined)
15166 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
15168 canActivate : false,
15171 * @cfg {Boolean} hidden True to prevent creation of this menu item (defaults to false)
15176 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
15178 activeClass : "x-menu-item-active",
15180 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
15182 hideOnClick : true,
15184 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
15189 ctype: "Roo.menu.BaseItem",
15192 actionMode : "container",
15195 render : function(container, parentMenu){
15196 this.parentMenu = parentMenu;
15197 Roo.menu.BaseItem.superclass.render.call(this, container);
15198 this.container.menuItemId = this.id;
15202 onRender : function(container, position){
15203 this.el = Roo.get(this.el);
15204 container.dom.appendChild(this.el.dom);
15208 onClick : function(e){
15209 if(!this.disabled && this.fireEvent("click", this, e) !== false
15210 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
15211 this.handleClick(e);
15218 activate : function(){
15222 var li = this.container;
15223 li.addClass(this.activeClass);
15224 this.region = li.getRegion().adjust(2, 2, -2, -2);
15225 this.fireEvent("activate", this);
15230 deactivate : function(){
15231 this.container.removeClass(this.activeClass);
15232 this.fireEvent("deactivate", this);
15236 shouldDeactivate : function(e){
15237 return !this.region || !this.region.contains(e.getPoint());
15241 handleClick : function(e){
15242 if(this.hideOnClick){
15243 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
15248 expandMenu : function(autoActivate){
15253 hideMenu : function(){
15258 * Ext JS Library 1.1.1
15259 * Copyright(c) 2006-2007, Ext JS, LLC.
15261 * Originally Released Under LGPL - original licence link has changed is not relivant.
15264 * <script type="text/javascript">
15268 * @class Roo.menu.Adapter
15269 * @extends Roo.menu.BaseItem
15270 * 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.
15271 * It provides basic rendering, activation management and enable/disable logic required to work in menus.
15273 * Creates a new Adapter
15274 * @param {Object} config Configuration options
15276 Roo.menu.Adapter = function(component, config){
15277 Roo.menu.Adapter.superclass.constructor.call(this, config);
15278 this.component = component;
15280 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
15282 canActivate : true,
15285 onRender : function(container, position){
15286 this.component.render(container);
15287 this.el = this.component.getEl();
15291 activate : function(){
15295 this.component.focus();
15296 this.fireEvent("activate", this);
15301 deactivate : function(){
15302 this.fireEvent("deactivate", this);
15306 disable : function(){
15307 this.component.disable();
15308 Roo.menu.Adapter.superclass.disable.call(this);
15312 enable : function(){
15313 this.component.enable();
15314 Roo.menu.Adapter.superclass.enable.call(this);
15318 * Ext JS Library 1.1.1
15319 * Copyright(c) 2006-2007, Ext JS, LLC.
15321 * Originally Released Under LGPL - original licence link has changed is not relivant.
15324 * <script type="text/javascript">
15328 * @class Roo.menu.TextItem
15329 * @extends Roo.menu.BaseItem
15330 * Adds a static text string to a menu, usually used as either a heading or group separator.
15331 * Note: old style constructor with text is still supported.
15334 * Creates a new TextItem
15335 * @param {Object} cfg Configuration
15337 Roo.menu.TextItem = function(cfg){
15338 if (typeof(cfg) == 'string') {
15341 Roo.apply(this,cfg);
15344 Roo.menu.TextItem.superclass.constructor.call(this);
15347 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
15349 * @cfg {Boolean} text Text to show on item.
15354 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
15356 hideOnClick : false,
15358 * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
15360 itemCls : "x-menu-text",
15363 onRender : function(){
15364 var s = document.createElement("span");
15365 s.className = this.itemCls;
15366 s.innerHTML = this.text;
15368 Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
15372 * Ext JS Library 1.1.1
15373 * Copyright(c) 2006-2007, Ext JS, LLC.
15375 * Originally Released Under LGPL - original licence link has changed is not relivant.
15378 * <script type="text/javascript">
15382 * @class Roo.menu.Separator
15383 * @extends Roo.menu.BaseItem
15384 * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
15385 * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
15387 * @param {Object} config Configuration options
15389 Roo.menu.Separator = function(config){
15390 Roo.menu.Separator.superclass.constructor.call(this, config);
15393 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
15395 * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
15397 itemCls : "x-menu-sep",
15399 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
15401 hideOnClick : false,
15404 onRender : function(li){
15405 var s = document.createElement("span");
15406 s.className = this.itemCls;
15407 s.innerHTML = " ";
15409 li.addClass("x-menu-sep-li");
15410 Roo.menu.Separator.superclass.onRender.apply(this, arguments);
15414 * Ext JS Library 1.1.1
15415 * Copyright(c) 2006-2007, Ext JS, LLC.
15417 * Originally Released Under LGPL - original licence link has changed is not relivant.
15420 * <script type="text/javascript">
15423 * @class Roo.menu.Item
15424 * @extends Roo.menu.BaseItem
15425 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
15426 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
15427 * activation and click handling.
15429 * Creates a new Item
15430 * @param {Object} config Configuration options
15432 Roo.menu.Item = function(config){
15433 Roo.menu.Item.superclass.constructor.call(this, config);
15435 this.menu = Roo.menu.MenuMgr.get(this.menu);
15438 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
15441 * @cfg {String} text
15442 * The text to show on the menu item.
15446 * @cfg {String} HTML to render in menu
15447 * The text to show on the menu item (HTML version).
15451 * @cfg {String} icon
15452 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
15456 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
15458 itemCls : "x-menu-item",
15460 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
15462 canActivate : true,
15464 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
15467 // doc'd in BaseItem
15471 ctype: "Roo.menu.Item",
15474 onRender : function(container, position){
15475 var el = document.createElement("a");
15476 el.hideFocus = true;
15477 el.unselectable = "on";
15478 el.href = this.href || "#";
15479 if(this.hrefTarget){
15480 el.target = this.hrefTarget;
15482 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
15484 var html = this.html.length ? this.html : String.format('{0}',this.text);
15486 el.innerHTML = String.format(
15487 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
15488 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
15490 Roo.menu.Item.superclass.onRender.call(this, container, position);
15494 * Sets the text to display in this menu item
15495 * @param {String} text The text to display
15496 * @param {Boolean} isHTML true to indicate text is pure html.
15498 setText : function(text, isHTML){
15506 var html = this.html.length ? this.html : String.format('{0}',this.text);
15508 this.el.update(String.format(
15509 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
15510 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
15511 this.parentMenu.autoWidth();
15516 handleClick : function(e){
15517 if(!this.href){ // if no link defined, stop the event automatically
15520 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
15524 activate : function(autoExpand){
15525 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
15535 shouldDeactivate : function(e){
15536 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
15537 if(this.menu && this.menu.isVisible()){
15538 return !this.menu.getEl().getRegion().contains(e.getPoint());
15546 deactivate : function(){
15547 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
15552 expandMenu : function(autoActivate){
15553 if(!this.disabled && this.menu){
15554 clearTimeout(this.hideTimer);
15555 delete this.hideTimer;
15556 if(!this.menu.isVisible() && !this.showTimer){
15557 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
15558 }else if (this.menu.isVisible() && autoActivate){
15559 this.menu.tryActivate(0, 1);
15565 deferExpand : function(autoActivate){
15566 delete this.showTimer;
15567 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
15569 this.menu.tryActivate(0, 1);
15574 hideMenu : function(){
15575 clearTimeout(this.showTimer);
15576 delete this.showTimer;
15577 if(!this.hideTimer && this.menu && this.menu.isVisible()){
15578 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
15583 deferHide : function(){
15584 delete this.hideTimer;
15589 * Ext JS Library 1.1.1
15590 * Copyright(c) 2006-2007, Ext JS, LLC.
15592 * Originally Released Under LGPL - original licence link has changed is not relivant.
15595 * <script type="text/javascript">
15599 * @class Roo.menu.CheckItem
15600 * @extends Roo.menu.Item
15601 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
15603 * Creates a new CheckItem
15604 * @param {Object} config Configuration options
15606 Roo.menu.CheckItem = function(config){
15607 Roo.menu.CheckItem.superclass.constructor.call(this, config);
15610 * @event beforecheckchange
15611 * Fires before the checked value is set, providing an opportunity to cancel if needed
15612 * @param {Roo.menu.CheckItem} this
15613 * @param {Boolean} checked The new checked value that will be set
15615 "beforecheckchange" : true,
15617 * @event checkchange
15618 * Fires after the checked value has been set
15619 * @param {Roo.menu.CheckItem} this
15620 * @param {Boolean} checked The checked value that was set
15622 "checkchange" : true
15624 if(this.checkHandler){
15625 this.on('checkchange', this.checkHandler, this.scope);
15628 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
15630 * @cfg {String} group
15631 * All check items with the same group name will automatically be grouped into a single-select
15632 * radio button group (defaults to '')
15635 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
15637 itemCls : "x-menu-item x-menu-check-item",
15639 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
15641 groupClass : "x-menu-group-item",
15644 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
15645 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
15646 * initialized with checked = true will be rendered as checked.
15651 ctype: "Roo.menu.CheckItem",
15654 onRender : function(c){
15655 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
15657 this.el.addClass(this.groupClass);
15659 Roo.menu.MenuMgr.registerCheckable(this);
15661 this.checked = false;
15662 this.setChecked(true, true);
15667 destroy : function(){
15669 Roo.menu.MenuMgr.unregisterCheckable(this);
15671 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
15675 * Set the checked state of this item
15676 * @param {Boolean} checked The new checked value
15677 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
15679 setChecked : function(state, suppressEvent){
15680 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
15681 if(this.container){
15682 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
15684 this.checked = state;
15685 if(suppressEvent !== true){
15686 this.fireEvent("checkchange", this, state);
15692 handleClick : function(e){
15693 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
15694 this.setChecked(!this.checked);
15696 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
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.DateItem
15711 * @extends Roo.menu.Adapter
15712 * A menu item that wraps the {@link Roo.DatPicker} component.
15714 * Creates a new DateItem
15715 * @param {Object} config Configuration options
15717 Roo.menu.DateItem = function(config){
15718 Roo.menu.DateItem.superclass.constructor.call(this, new Roo.DatePicker(config), config);
15719 /** The Roo.DatePicker object @type Roo.DatePicker */
15720 this.picker = this.component;
15721 this.addEvents({select: true});
15723 this.picker.on("render", function(picker){
15724 picker.getEl().swallowEvent("click");
15725 picker.container.addClass("x-menu-date-item");
15728 this.picker.on("select", this.onSelect, this);
15731 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
15733 onSelect : function(picker, date){
15734 this.fireEvent("select", this, date, picker);
15735 Roo.menu.DateItem.superclass.handleClick.call(this);
15739 * Ext JS Library 1.1.1
15740 * Copyright(c) 2006-2007, Ext JS, LLC.
15742 * Originally Released Under LGPL - original licence link has changed is not relivant.
15745 * <script type="text/javascript">
15749 * @class Roo.menu.ColorItem
15750 * @extends Roo.menu.Adapter
15751 * A menu item that wraps the {@link Roo.ColorPalette} component.
15753 * Creates a new ColorItem
15754 * @param {Object} config Configuration options
15756 Roo.menu.ColorItem = function(config){
15757 Roo.menu.ColorItem.superclass.constructor.call(this, new Roo.ColorPalette(config), config);
15758 /** The Roo.ColorPalette object @type Roo.ColorPalette */
15759 this.palette = this.component;
15760 this.relayEvents(this.palette, ["select"]);
15761 if(this.selectHandler){
15762 this.on('select', this.selectHandler, this.scope);
15765 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);/*
15767 * Ext JS Library 1.1.1
15768 * Copyright(c) 2006-2007, Ext JS, LLC.
15770 * Originally Released Under LGPL - original licence link has changed is not relivant.
15773 * <script type="text/javascript">
15778 * @class Roo.menu.DateMenu
15779 * @extends Roo.menu.Menu
15780 * A menu containing a {@link Roo.menu.DateItem} component (which provides a date picker).
15782 * Creates a new DateMenu
15783 * @param {Object} config Configuration options
15785 Roo.menu.DateMenu = function(config){
15786 Roo.menu.DateMenu.superclass.constructor.call(this, config);
15788 var di = new Roo.menu.DateItem(config);
15791 * The {@link Roo.DatePicker} instance for this DateMenu
15794 this.picker = di.picker;
15797 * @param {DatePicker} picker
15798 * @param {Date} date
15800 this.relayEvents(di, ["select"]);
15801 this.on('beforeshow', function(){
15803 this.picker.hideMonthPicker(false);
15807 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
15811 * Ext JS Library 1.1.1
15812 * Copyright(c) 2006-2007, Ext JS, LLC.
15814 * Originally Released Under LGPL - original licence link has changed is not relivant.
15817 * <script type="text/javascript">
15822 * @class Roo.menu.ColorMenu
15823 * @extends Roo.menu.Menu
15824 * A menu containing a {@link Roo.menu.ColorItem} component (which provides a basic color picker).
15826 * Creates a new ColorMenu
15827 * @param {Object} config Configuration options
15829 Roo.menu.ColorMenu = function(config){
15830 Roo.menu.ColorMenu.superclass.constructor.call(this, config);
15832 var ci = new Roo.menu.ColorItem(config);
15835 * The {@link Roo.ColorPalette} instance for this ColorMenu
15836 * @type ColorPalette
15838 this.palette = ci.palette;
15841 * @param {ColorPalette} palette
15842 * @param {String} color
15844 this.relayEvents(ci, ["select"]);
15846 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);/*
15848 * Ext JS Library 1.1.1
15849 * Copyright(c) 2006-2007, Ext JS, LLC.
15851 * Originally Released Under LGPL - original licence link has changed is not relivant.
15854 * <script type="text/javascript">
15858 * @class Roo.form.TextItem
15859 * @extends Roo.BoxComponent
15860 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
15862 * Creates a new TextItem
15863 * @param {Object} config Configuration options
15865 Roo.form.TextItem = function(config){
15866 Roo.form.TextItem.superclass.constructor.call(this, config);
15869 Roo.extend(Roo.form.TextItem, Roo.BoxComponent, {
15872 * @cfg {String} tag the tag for this item (default div)
15876 * @cfg {String} html the content for this item
15880 getAutoCreate : function()
15893 onRender : function(ct, position)
15895 Roo.form.TextItem.superclass.onRender.call(this, ct, position);
15898 var cfg = this.getAutoCreate();
15900 cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
15902 if (!cfg.name.length) {
15905 this.el = ct.createChild(cfg, position);
15910 * @param {String} html update the Contents of the element.
15912 setHTML : function(html)
15914 this.fieldEl.dom.innerHTML = html;
15919 * Ext JS Library 1.1.1
15920 * Copyright(c) 2006-2007, Ext JS, LLC.
15922 * Originally Released Under LGPL - original licence link has changed is not relivant.
15925 * <script type="text/javascript">
15929 * @class Roo.form.Field
15930 * @extends Roo.BoxComponent
15931 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
15933 * Creates a new Field
15934 * @param {Object} config Configuration options
15936 Roo.form.Field = function(config){
15937 Roo.form.Field.superclass.constructor.call(this, config);
15940 Roo.extend(Roo.form.Field, Roo.BoxComponent, {
15942 * @cfg {String} fieldLabel Label to use when rendering a form.
15945 * @cfg {String} qtip Mouse over tip
15949 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
15951 invalidClass : "x-form-invalid",
15953 * @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")
15955 invalidText : "The value in this field is invalid",
15957 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
15959 focusClass : "x-form-focus",
15961 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
15962 automatic validation (defaults to "keyup").
15964 validationEvent : "keyup",
15966 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
15968 validateOnBlur : true,
15970 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
15972 validationDelay : 250,
15974 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
15975 * {tag: "input", type: "text", size: "20", autocomplete: "off"})
15977 defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "new-password"},
15979 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field")
15981 fieldClass : "x-form-field",
15983 * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'):
15986 ----------- ----------------------------------------------------------------------
15987 qtip Display a quick tip when the user hovers over the field
15988 title Display a default browser title attribute popup
15989 under Add a block div beneath the field containing the error text
15990 side Add an error icon to the right of the field with a popup on hover
15991 [element id] Add the error text directly to the innerHTML of the specified element
15994 msgTarget : 'qtip',
15996 * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal').
16001 * @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.
16006 * @cfg {Boolean} disabled True to disable the field (defaults to false).
16011 * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password (defaults to "text").
16013 inputType : undefined,
16016 * @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).
16018 tabIndex : undefined,
16021 isFormField : true,
16026 * @property {Roo.Element} fieldEl
16027 * Element Containing the rendered Field (with label etc.)
16030 * @cfg {Mixed} value A value to initialize this field with.
16035 * @cfg {String} name The field's HTML name attribute.
16038 * @cfg {String} cls A CSS class to apply to the field's underlying element.
16041 loadedValue : false,
16045 initComponent : function(){
16046 Roo.form.Field.superclass.initComponent.call(this);
16050 * Fires when this field receives input focus.
16051 * @param {Roo.form.Field} this
16056 * Fires when this field loses input focus.
16057 * @param {Roo.form.Field} this
16061 * @event specialkey
16062 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
16063 * {@link Roo.EventObject#getKey} to determine which key was pressed.
16064 * @param {Roo.form.Field} this
16065 * @param {Roo.EventObject} e The event object
16070 * Fires just before the field blurs if the field value has changed.
16071 * @param {Roo.form.Field} this
16072 * @param {Mixed} newValue The new value
16073 * @param {Mixed} oldValue The original value
16078 * Fires after the field has been marked as invalid.
16079 * @param {Roo.form.Field} this
16080 * @param {String} msg The validation message
16085 * Fires after the field has been validated with no errors.
16086 * @param {Roo.form.Field} this
16091 * Fires after the key up
16092 * @param {Roo.form.Field} this
16093 * @param {Roo.EventObject} e The event Object
16100 * Returns the name attribute of the field if available
16101 * @return {String} name The field name
16103 getName: function(){
16104 return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
16108 onRender : function(ct, position){
16109 Roo.form.Field.superclass.onRender.call(this, ct, position);
16111 var cfg = this.getAutoCreate();
16113 cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
16115 if (!cfg.name.length) {
16118 if(this.inputType){
16119 cfg.type = this.inputType;
16121 this.el = ct.createChild(cfg, position);
16123 var type = this.el.dom.type;
16125 if(type == 'password'){
16128 this.el.addClass('x-form-'+type);
16131 this.el.dom.readOnly = true;
16133 if(this.tabIndex !== undefined){
16134 this.el.dom.setAttribute('tabIndex', this.tabIndex);
16137 this.el.addClass([this.fieldClass, this.cls]);
16142 * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b>
16143 * @param {String/HTMLElement/Element} el The id of the node, a DOM node or an existing Element
16144 * @return {Roo.form.Field} this
16146 applyTo : function(target){
16147 this.allowDomMove = false;
16148 this.el = Roo.get(target);
16149 this.render(this.el.dom.parentNode);
16154 initValue : function(){
16155 if(this.value !== undefined){
16156 this.setValue(this.value);
16157 }else if(this.el.dom.value.length > 0){
16158 this.setValue(this.el.dom.value);
16163 * Returns true if this field has been changed since it was originally loaded and is not disabled.
16164 * DEPRICATED - it never worked well - use hasChanged/resetHasChanged.
16166 isDirty : function() {
16167 if(this.disabled) {
16170 return String(this.getValue()) !== String(this.originalValue);
16174 * stores the current value in loadedValue
16176 resetHasChanged : function()
16178 this.loadedValue = String(this.getValue());
16181 * checks the current value against the 'loaded' value.
16182 * Note - will return false if 'resetHasChanged' has not been called first.
16184 hasChanged : function()
16186 if(this.disabled || this.readOnly) {
16189 return this.loadedValue !== false && String(this.getValue()) !== this.loadedValue;
16195 afterRender : function(){
16196 Roo.form.Field.superclass.afterRender.call(this);
16201 fireKey : function(e){
16202 //Roo.log('field ' + e.getKey());
16203 if(e.isNavKeyPress()){
16204 this.fireEvent("specialkey", this, e);
16209 * Resets the current field value to the originally loaded value and clears any validation messages
16211 reset : function(){
16212 this.setValue(this.resetValue);
16213 this.originalValue = this.getValue();
16214 this.clearInvalid();
16218 initEvents : function(){
16219 // safari killled keypress - so keydown is now used..
16220 this.el.on("keydown" , this.fireKey, this);
16221 this.el.on("focus", this.onFocus, this);
16222 this.el.on("blur", this.onBlur, this);
16223 this.el.relayEvent('keyup', this);
16225 // reference to original value for reset
16226 this.originalValue = this.getValue();
16227 this.resetValue = this.getValue();
16231 onFocus : function(){
16232 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
16233 this.el.addClass(this.focusClass);
16235 if(!this.hasFocus){
16236 this.hasFocus = true;
16237 this.startValue = this.getValue();
16238 this.fireEvent("focus", this);
16242 beforeBlur : Roo.emptyFn,
16245 onBlur : function(){
16247 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
16248 this.el.removeClass(this.focusClass);
16250 this.hasFocus = false;
16251 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
16254 var v = this.getValue();
16255 if(String(v) !== String(this.startValue)){
16256 this.fireEvent('change', this, v, this.startValue);
16258 this.fireEvent("blur", this);
16262 * Returns whether or not the field value is currently valid
16263 * @param {Boolean} preventMark True to disable marking the field invalid
16264 * @return {Boolean} True if the value is valid, else false
16266 isValid : function(preventMark){
16270 var restore = this.preventMark;
16271 this.preventMark = preventMark === true;
16272 var v = this.validateValue(this.processValue(this.getRawValue()));
16273 this.preventMark = restore;
16278 * Validates the field value
16279 * @return {Boolean} True if the value is valid, else false
16281 validate : function(){
16282 if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
16283 this.clearInvalid();
16289 processValue : function(value){
16294 // Subclasses should provide the validation implementation by overriding this
16295 validateValue : function(value){
16300 * Mark this field as invalid
16301 * @param {String} msg The validation message
16303 markInvalid : function(msg){
16304 if(!this.rendered || this.preventMark){ // not rendered
16308 var obj = (typeof(this.combo) != 'undefined') ? this.combo : this; // fix the combox array!!
16310 obj.el.addClass(this.invalidClass);
16311 msg = msg || this.invalidText;
16312 switch(this.msgTarget){
16314 obj.el.dom.qtip = msg;
16315 obj.el.dom.qclass = 'x-form-invalid-tip';
16316 if(Roo.QuickTips){ // fix for floating editors interacting with DND
16317 Roo.QuickTips.enable();
16321 this.el.dom.title = msg;
16325 var elp = this.el.findParent('.x-form-element', 5, true);
16326 this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
16327 this.errorEl.setWidth(elp.getWidth(true)-20);
16329 this.errorEl.update(msg);
16330 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
16333 if(!this.errorIcon){
16334 var elp = this.el.findParent('.x-form-element', 5, true);
16335 this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
16337 this.alignErrorIcon();
16338 this.errorIcon.dom.qtip = msg;
16339 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
16340 this.errorIcon.show();
16341 this.on('resize', this.alignErrorIcon, this);
16344 var t = Roo.getDom(this.msgTarget);
16346 t.style.display = this.msgDisplay;
16349 this.fireEvent('invalid', this, msg);
16353 alignErrorIcon : function(){
16354 this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
16358 * Clear any invalid styles/messages for this field
16360 clearInvalid : function(){
16361 if(!this.rendered || this.preventMark){ // not rendered
16364 var obj = (typeof(this.combo) != 'undefined') ? this.combo : this; // fix the combox array!!
16366 obj.el.removeClass(this.invalidClass);
16367 switch(this.msgTarget){
16369 obj.el.dom.qtip = '';
16372 this.el.dom.title = '';
16376 Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
16380 if(this.errorIcon){
16381 this.errorIcon.dom.qtip = '';
16382 this.errorIcon.hide();
16383 this.un('resize', this.alignErrorIcon, this);
16387 var t = Roo.getDom(this.msgTarget);
16389 t.style.display = 'none';
16392 this.fireEvent('valid', this);
16396 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
16397 * @return {Mixed} value The field value
16399 getRawValue : function(){
16400 var v = this.el.getValue();
16406 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
16407 * @return {Mixed} value The field value
16409 getValue : function(){
16410 var v = this.el.getValue();
16416 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
16417 * @param {Mixed} value The value to set
16419 setRawValue : function(v){
16420 return this.el.dom.value = (v === null || v === undefined ? '' : v);
16424 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
16425 * @param {Mixed} value The value to set
16427 setValue : function(v){
16430 this.el.dom.value = (v === null || v === undefined ? '' : v);
16435 adjustSize : function(w, h){
16436 var s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
16437 s.width = this.adjustWidth(this.el.dom.tagName, s.width);
16441 adjustWidth : function(tag, w){
16442 tag = tag.toLowerCase();
16443 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
16444 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
16445 if(tag == 'input'){
16448 if(tag == 'textarea'){
16451 }else if(Roo.isOpera){
16452 if(tag == 'input'){
16455 if(tag == 'textarea'){
16465 // anything other than normal should be considered experimental
16466 Roo.form.Field.msgFx = {
16468 show: function(msgEl, f){
16469 msgEl.setDisplayed('block');
16472 hide : function(msgEl, f){
16473 msgEl.setDisplayed(false).update('');
16478 show: function(msgEl, f){
16479 msgEl.slideIn('t', {stopFx:true});
16482 hide : function(msgEl, f){
16483 msgEl.slideOut('t', {stopFx:true,useDisplay:true});
16488 show: function(msgEl, f){
16489 msgEl.fixDisplay();
16490 msgEl.alignTo(f.el, 'tl-tr');
16491 msgEl.slideIn('l', {stopFx:true});
16494 hide : function(msgEl, f){
16495 msgEl.slideOut('l', {stopFx:true,useDisplay:true});
16500 * Ext JS Library 1.1.1
16501 * Copyright(c) 2006-2007, Ext JS, LLC.
16503 * Originally Released Under LGPL - original licence link has changed is not relivant.
16506 * <script type="text/javascript">
16511 * @class Roo.form.TextField
16512 * @extends Roo.form.Field
16513 * Basic text field. Can be used as a direct replacement for traditional text inputs, or as the base
16514 * class for more sophisticated input controls (like {@link Roo.form.TextArea} and {@link Roo.form.ComboBox}).
16516 * Creates a new TextField
16517 * @param {Object} config Configuration options
16519 Roo.form.TextField = function(config){
16520 Roo.form.TextField.superclass.constructor.call(this, config);
16524 * Fires when the autosize function is triggered. The field may or may not have actually changed size
16525 * according to the default logic, but this event provides a hook for the developer to apply additional
16526 * logic at runtime to resize the field if needed.
16527 * @param {Roo.form.Field} this This text field
16528 * @param {Number} width The new field width
16534 Roo.extend(Roo.form.TextField, Roo.form.Field, {
16536 * @cfg {Boolean} grow True if this field should automatically grow and shrink to its content
16540 * @cfg {Number} growMin The minimum width to allow when grow = true (defaults to 30)
16544 * @cfg {Number} growMax The maximum width to allow when grow = true (defaults to 800)
16548 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
16552 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
16556 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
16558 disableKeyFilter : false,
16560 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
16564 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
16568 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
16570 maxLength : Number.MAX_VALUE,
16572 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
16574 minLengthText : "The minimum length for this field is {0}",
16576 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
16578 maxLengthText : "The maximum length for this field is {0}",
16580 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
16582 selectOnFocus : false,
16584 * @cfg {Boolean} allowLeadingSpace True to prevent the stripping of leading white space
16586 allowLeadingSpace : false,
16588 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
16590 blankText : "This field is required",
16592 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
16593 * If available, this function will be called only after the basic validators all return true, and will be passed the
16594 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
16598 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
16599 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
16600 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
16604 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
16608 * @cfg {String} emptyText The default text to display in an empty field - placeholder... (defaults to null).
16614 initEvents : function()
16616 if (this.emptyText) {
16617 this.el.attr('placeholder', this.emptyText);
16620 Roo.form.TextField.superclass.initEvents.call(this);
16621 if(this.validationEvent == 'keyup'){
16622 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
16623 this.el.on('keyup', this.filterValidation, this);
16625 else if(this.validationEvent !== false){
16626 this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
16629 if(this.selectOnFocus){
16630 this.on("focus", this.preFocus, this);
16632 if (!this.allowLeadingSpace) {
16633 this.on('blur', this.cleanLeadingSpace, this);
16636 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
16637 this.el.on("keypress", this.filterKeys, this);
16640 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
16641 this.el.on("click", this.autoSize, this);
16643 if(this.el.is('input[type=password]') && Roo.isSafari){
16644 this.el.on('keydown', this.SafariOnKeyDown, this);
16648 processValue : function(value){
16649 if(this.stripCharsRe){
16650 var newValue = value.replace(this.stripCharsRe, '');
16651 if(newValue !== value){
16652 this.setRawValue(newValue);
16659 filterValidation : function(e){
16660 if(!e.isNavKeyPress()){
16661 this.validationTask.delay(this.validationDelay);
16666 onKeyUp : function(e){
16667 if(!e.isNavKeyPress()){
16671 // private - clean the leading white space
16672 cleanLeadingSpace : function(e)
16674 if ( this.inputType == 'file') {
16678 this.setValue((this.getValue() + '').replace(/^\s+/,''));
16681 * Resets the current field value to the originally-loaded value and clears any validation messages.
16684 reset : function(){
16685 Roo.form.TextField.superclass.reset.call(this);
16689 preFocus : function(){
16691 if(this.selectOnFocus){
16692 this.el.dom.select();
16698 filterKeys : function(e){
16699 var k = e.getKey();
16700 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
16703 var c = e.getCharCode(), cc = String.fromCharCode(c);
16704 if(Roo.isIE && (e.isSpecialKey() || !cc)){
16707 if(!this.maskRe.test(cc)){
16712 setValue : function(v){
16714 Roo.form.TextField.superclass.setValue.apply(this, arguments);
16720 * Validates a value according to the field's validation rules and marks the field as invalid
16721 * if the validation fails
16722 * @param {Mixed} value The value to validate
16723 * @return {Boolean} True if the value is valid, else false
16725 validateValue : function(value){
16726 if(value.length < 1) { // if it's blank
16727 if(this.allowBlank){
16728 this.clearInvalid();
16731 this.markInvalid(this.blankText);
16735 if(value.length < this.minLength){
16736 this.markInvalid(String.format(this.minLengthText, this.minLength));
16739 if(value.length > this.maxLength){
16740 this.markInvalid(String.format(this.maxLengthText, this.maxLength));
16744 var vt = Roo.form.VTypes;
16745 if(!vt[this.vtype](value, this)){
16746 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
16750 if(typeof this.validator == "function"){
16751 var msg = this.validator(value);
16753 this.markInvalid(msg);
16757 if(this.regex && !this.regex.test(value)){
16758 this.markInvalid(this.regexText);
16765 * Selects text in this field
16766 * @param {Number} start (optional) The index where the selection should start (defaults to 0)
16767 * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
16769 selectText : function(start, end){
16770 var v = this.getRawValue();
16772 start = start === undefined ? 0 : start;
16773 end = end === undefined ? v.length : end;
16774 var d = this.el.dom;
16775 if(d.setSelectionRange){
16776 d.setSelectionRange(start, end);
16777 }else if(d.createTextRange){
16778 var range = d.createTextRange();
16779 range.moveStart("character", start);
16780 range.moveEnd("character", v.length-end);
16787 * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
16788 * This only takes effect if grow = true, and fires the autosize event.
16790 autoSize : function(){
16791 if(!this.grow || !this.rendered){
16795 this.metrics = Roo.util.TextMetrics.createInstance(this.el);
16798 var v = el.dom.value;
16799 var d = document.createElement('div');
16800 d.appendChild(document.createTextNode(v));
16804 var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
16805 this.el.setWidth(w);
16806 this.fireEvent("autosize", this, w);
16810 SafariOnKeyDown : function(event)
16812 // this is a workaround for a password hang bug on chrome/ webkit.
16814 var isSelectAll = false;
16816 if(this.el.dom.selectionEnd > 0){
16817 isSelectAll = (this.el.dom.selectionEnd - this.el.dom.selectionStart - this.getValue().length == 0) ? true : false;
16819 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
16820 event.preventDefault();
16825 if(isSelectAll && event.getCharCode() > 31){ // backspace and delete key
16827 event.preventDefault();
16828 // this is very hacky as keydown always get's upper case.
16830 var cc = String.fromCharCode(event.getCharCode());
16833 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
16841 * Ext JS Library 1.1.1
16842 * Copyright(c) 2006-2007, Ext JS, LLC.
16844 * Originally Released Under LGPL - original licence link has changed is not relivant.
16847 * <script type="text/javascript">
16851 * @class Roo.form.Hidden
16852 * @extends Roo.form.TextField
16853 * Simple Hidden element used on forms
16855 * usage: form.add(new Roo.form.HiddenField({ 'name' : 'test1' }));
16858 * Creates a new Hidden form element.
16859 * @param {Object} config Configuration options
16864 // easy hidden field...
16865 Roo.form.Hidden = function(config){
16866 Roo.form.Hidden.superclass.constructor.call(this, config);
16869 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
16871 inputType: 'hidden',
16874 labelSeparator: '',
16876 itemCls : 'x-form-item-display-none'
16884 * Ext JS Library 1.1.1
16885 * Copyright(c) 2006-2007, Ext JS, LLC.
16887 * Originally Released Under LGPL - original licence link has changed is not relivant.
16890 * <script type="text/javascript">
16894 * @class Roo.form.TriggerField
16895 * @extends Roo.form.TextField
16896 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
16897 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
16898 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
16899 * for which you can provide a custom implementation. For example:
16901 var trigger = new Roo.form.TriggerField();
16902 trigger.onTriggerClick = myTriggerFn;
16903 trigger.applyTo('my-field');
16906 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
16907 * {@link Roo.form.DateField} and {@link Roo.form.ComboBox} are perfect examples of this.
16908 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
16909 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
16911 * Create a new TriggerField.
16912 * @param {Object} config Configuration options (valid {@Roo.form.TextField} config options will also be applied
16913 * to the base TextField)
16915 Roo.form.TriggerField = function(config){
16916 this.mimicing = false;
16917 Roo.form.TriggerField.superclass.constructor.call(this, config);
16920 Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
16922 * @cfg {String} triggerClass A CSS class to apply to the trigger
16925 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
16926 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
16928 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "new-password"},
16930 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
16934 /** @cfg {Boolean} grow @hide */
16935 /** @cfg {Number} growMin @hide */
16936 /** @cfg {Number} growMax @hide */
16942 autoSize: Roo.emptyFn,
16946 deferHeight : true,
16949 actionMode : 'wrap',
16951 onResize : function(w, h){
16952 Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
16953 if(typeof w == 'number'){
16954 var x = w - this.trigger.getWidth();
16955 this.el.setWidth(this.adjustWidth('input', x));
16956 this.trigger.setStyle('left', x+'px');
16961 adjustSize : Roo.BoxComponent.prototype.adjustSize,
16964 getResizeEl : function(){
16969 getPositionEl : function(){
16974 alignErrorIcon : function(){
16975 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
16979 onRender : function(ct, position){
16980 Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
16981 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
16982 this.trigger = this.wrap.createChild(this.triggerConfig ||
16983 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
16984 if(this.hideTrigger){
16985 this.trigger.setDisplayed(false);
16987 this.initTrigger();
16989 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
16994 initTrigger : function(){
16995 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
16996 this.trigger.addClassOnOver('x-form-trigger-over');
16997 this.trigger.addClassOnClick('x-form-trigger-click');
17001 onDestroy : function(){
17003 this.trigger.removeAllListeners();
17004 this.trigger.remove();
17007 this.wrap.remove();
17009 Roo.form.TriggerField.superclass.onDestroy.call(this);
17013 onFocus : function(){
17014 Roo.form.TriggerField.superclass.onFocus.call(this);
17015 if(!this.mimicing){
17016 this.wrap.addClass('x-trigger-wrap-focus');
17017 this.mimicing = true;
17018 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
17019 if(this.monitorTab){
17020 this.el.on("keydown", this.checkTab, this);
17026 checkTab : function(e){
17027 if(e.getKey() == e.TAB){
17028 this.triggerBlur();
17033 onBlur : function(){
17038 mimicBlur : function(e, t){
17039 if(!this.wrap.contains(t) && this.validateBlur()){
17040 this.triggerBlur();
17045 triggerBlur : function(){
17046 this.mimicing = false;
17047 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
17048 if(this.monitorTab){
17049 this.el.un("keydown", this.checkTab, this);
17051 this.wrap.removeClass('x-trigger-wrap-focus');
17052 Roo.form.TriggerField.superclass.onBlur.call(this);
17056 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
17057 validateBlur : function(e, t){
17062 onDisable : function(){
17063 Roo.form.TriggerField.superclass.onDisable.call(this);
17065 this.wrap.addClass('x-item-disabled');
17070 onEnable : function(){
17071 Roo.form.TriggerField.superclass.onEnable.call(this);
17073 this.wrap.removeClass('x-item-disabled');
17078 onShow : function(){
17079 var ae = this.getActionEl();
17082 ae.dom.style.display = '';
17083 ae.dom.style.visibility = 'visible';
17089 onHide : function(){
17090 var ae = this.getActionEl();
17091 ae.dom.style.display = 'none';
17095 * The function that should handle the trigger's click event. This method does nothing by default until overridden
17096 * by an implementing function.
17098 * @param {EventObject} e
17100 onTriggerClick : Roo.emptyFn
17103 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
17104 // to be extended by an implementing class. For an example of implementing this class, see the custom
17105 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
17106 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
17107 initComponent : function(){
17108 Roo.form.TwinTriggerField.superclass.initComponent.call(this);
17110 this.triggerConfig = {
17111 tag:'span', cls:'x-form-twin-triggers', cn:[
17112 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
17113 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
17117 getTrigger : function(index){
17118 return this.triggers[index];
17121 initTrigger : function(){
17122 var ts = this.trigger.select('.x-form-trigger', true);
17123 this.wrap.setStyle('overflow', 'hidden');
17124 var triggerField = this;
17125 ts.each(function(t, all, index){
17126 t.hide = function(){
17127 var w = triggerField.wrap.getWidth();
17128 this.dom.style.display = 'none';
17129 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
17131 t.show = function(){
17132 var w = triggerField.wrap.getWidth();
17133 this.dom.style.display = '';
17134 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
17136 var triggerIndex = 'Trigger'+(index+1);
17138 if(this['hide'+triggerIndex]){
17139 t.dom.style.display = 'none';
17141 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
17142 t.addClassOnOver('x-form-trigger-over');
17143 t.addClassOnClick('x-form-trigger-click');
17145 this.triggers = ts.elements;
17148 onTrigger1Click : Roo.emptyFn,
17149 onTrigger2Click : Roo.emptyFn
17152 * Ext JS Library 1.1.1
17153 * Copyright(c) 2006-2007, Ext JS, LLC.
17155 * Originally Released Under LGPL - original licence link has changed is not relivant.
17158 * <script type="text/javascript">
17162 * @class Roo.form.TextArea
17163 * @extends Roo.form.TextField
17164 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
17165 * support for auto-sizing.
17167 * Creates a new TextArea
17168 * @param {Object} config Configuration options
17170 Roo.form.TextArea = function(config){
17171 Roo.form.TextArea.superclass.constructor.call(this, config);
17172 // these are provided exchanges for backwards compat
17173 // minHeight/maxHeight were replaced by growMin/growMax to be
17174 // compatible with TextField growing config values
17175 if(this.minHeight !== undefined){
17176 this.growMin = this.minHeight;
17178 if(this.maxHeight !== undefined){
17179 this.growMax = this.maxHeight;
17183 Roo.extend(Roo.form.TextArea, Roo.form.TextField, {
17185 * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
17189 * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
17193 * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
17194 * in the field (equivalent to setting overflow: hidden, defaults to false)
17196 preventScrollbars: false,
17198 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
17199 * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"})
17203 onRender : function(ct, position){
17205 this.defaultAutoCreate = {
17207 style:"width:300px;height:60px;",
17208 autocomplete: "new-password"
17211 Roo.form.TextArea.superclass.onRender.call(this, ct, position);
17213 this.textSizeEl = Roo.DomHelper.append(document.body, {
17214 tag: "pre", cls: "x-form-grow-sizer"
17216 if(this.preventScrollbars){
17217 this.el.setStyle("overflow", "hidden");
17219 this.el.setHeight(this.growMin);
17223 onDestroy : function(){
17224 if(this.textSizeEl){
17225 this.textSizeEl.parentNode.removeChild(this.textSizeEl);
17227 Roo.form.TextArea.superclass.onDestroy.call(this);
17231 onKeyUp : function(e){
17232 if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
17238 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
17239 * This only takes effect if grow = true, and fires the autosize event if the height changes.
17241 autoSize : function(){
17242 if(!this.grow || !this.textSizeEl){
17246 var v = el.dom.value;
17247 var ts = this.textSizeEl;
17250 ts.appendChild(document.createTextNode(v));
17253 Roo.fly(ts).setWidth(this.el.getWidth());
17255 v = "  ";
17258 v = v.replace(/\n/g, '<p> </p>');
17260 v += " \n ";
17263 var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
17264 if(h != this.lastHeight){
17265 this.lastHeight = h;
17266 this.el.setHeight(h);
17267 this.fireEvent("autosize", this, h);
17272 * Ext JS Library 1.1.1
17273 * Copyright(c) 2006-2007, Ext JS, LLC.
17275 * Originally Released Under LGPL - original licence link has changed is not relivant.
17278 * <script type="text/javascript">
17283 * @class Roo.form.NumberField
17284 * @extends Roo.form.TextField
17285 * Numeric text field that provides automatic keystroke filtering and numeric validation.
17287 * Creates a new NumberField
17288 * @param {Object} config Configuration options
17290 Roo.form.NumberField = function(config){
17291 Roo.form.NumberField.superclass.constructor.call(this, config);
17294 Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
17296 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
17298 fieldClass: "x-form-field x-form-num-field",
17300 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
17302 allowDecimals : true,
17304 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
17306 decimalSeparator : ".",
17308 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
17310 decimalPrecision : 2,
17312 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
17314 allowNegative : true,
17316 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
17318 minValue : Number.NEGATIVE_INFINITY,
17320 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
17322 maxValue : Number.MAX_VALUE,
17324 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
17326 minText : "The minimum value for this field is {0}",
17328 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
17330 maxText : "The maximum value for this field is {0}",
17332 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
17333 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
17335 nanText : "{0} is not a valid number",
17338 initEvents : function(){
17339 Roo.form.NumberField.superclass.initEvents.call(this);
17340 var allowed = "0123456789";
17341 if(this.allowDecimals){
17342 allowed += this.decimalSeparator;
17344 if(this.allowNegative){
17347 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
17348 var keyPress = function(e){
17349 var k = e.getKey();
17350 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
17353 var c = e.getCharCode();
17354 if(allowed.indexOf(String.fromCharCode(c)) === -1){
17358 this.el.on("keypress", keyPress, this);
17362 validateValue : function(value){
17363 if(!Roo.form.NumberField.superclass.validateValue.call(this, value)){
17366 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
17369 var num = this.parseValue(value);
17371 this.markInvalid(String.format(this.nanText, value));
17374 if(num < this.minValue){
17375 this.markInvalid(String.format(this.minText, this.minValue));
17378 if(num > this.maxValue){
17379 this.markInvalid(String.format(this.maxText, this.maxValue));
17385 getValue : function(){
17386 return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
17390 parseValue : function(value){
17391 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
17392 return isNaN(value) ? '' : value;
17396 fixPrecision : function(value){
17397 var nan = isNaN(value);
17398 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
17399 return nan ? '' : value;
17401 return parseFloat(value).toFixed(this.decimalPrecision);
17404 setValue : function(v){
17405 v = this.fixPrecision(v);
17406 Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
17410 decimalPrecisionFcn : function(v){
17411 return Math.floor(v);
17414 beforeBlur : function(){
17415 var v = this.parseValue(this.getRawValue());
17422 * Ext JS Library 1.1.1
17423 * Copyright(c) 2006-2007, Ext JS, LLC.
17425 * Originally Released Under LGPL - original licence link has changed is not relivant.
17428 * <script type="text/javascript">
17432 * @class Roo.form.DateField
17433 * @extends Roo.form.TriggerField
17434 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
17436 * Create a new DateField
17437 * @param {Object} config
17439 Roo.form.DateField = function(config)
17441 Roo.form.DateField.superclass.constructor.call(this, config);
17447 * Fires when a date is selected
17448 * @param {Roo.form.DateField} combo This combo box
17449 * @param {Date} date The date selected
17456 if(typeof this.minValue == "string") {
17457 this.minValue = this.parseDate(this.minValue);
17459 if(typeof this.maxValue == "string") {
17460 this.maxValue = this.parseDate(this.maxValue);
17462 this.ddMatch = null;
17463 if(this.disabledDates){
17464 var dd = this.disabledDates;
17466 for(var i = 0; i < dd.length; i++){
17468 if(i != dd.length-1) {
17472 this.ddMatch = new RegExp(re + ")");
17476 Roo.extend(Roo.form.DateField, Roo.form.TriggerField, {
17478 * @cfg {String} format
17479 * The default date format string which can be overriden for localization support. The format must be
17480 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
17484 * @cfg {String} altFormats
17485 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
17486 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
17488 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
17490 * @cfg {Array} disabledDays
17491 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
17493 disabledDays : null,
17495 * @cfg {String} disabledDaysText
17496 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
17498 disabledDaysText : "Disabled",
17500 * @cfg {Array} disabledDates
17501 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
17502 * expression so they are very powerful. Some examples:
17504 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
17505 * <li>["03/08", "09/16"] would disable those days for every year</li>
17506 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
17507 * <li>["03/../2006"] would disable every day in March 2006</li>
17508 * <li>["^03"] would disable every day in every March</li>
17510 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
17511 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
17513 disabledDates : null,
17515 * @cfg {String} disabledDatesText
17516 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
17518 disabledDatesText : "Disabled",
17520 * @cfg {Date/String} minValue
17521 * The minimum allowed date. Can be either a Javascript date object or a string date in a
17522 * valid format (defaults to null).
17526 * @cfg {Date/String} maxValue
17527 * The maximum allowed date. Can be either a Javascript date object or a string date in a
17528 * valid format (defaults to null).
17532 * @cfg {String} minText
17533 * The error text to display when the date in the cell is before minValue (defaults to
17534 * 'The date in this field must be after {minValue}').
17536 minText : "The date in this field must be equal to or after {0}",
17538 * @cfg {String} maxText
17539 * The error text to display when the date in the cell is after maxValue (defaults to
17540 * 'The date in this field must be before {maxValue}').
17542 maxText : "The date in this field must be equal to or before {0}",
17544 * @cfg {String} invalidText
17545 * The error text to display when the date in the field is invalid (defaults to
17546 * '{value} is not a valid date - it must be in the format {format}').
17548 invalidText : "{0} is not a valid date - it must be in the format {1}",
17550 * @cfg {String} triggerClass
17551 * An additional CSS class used to style the trigger button. The trigger will always get the
17552 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
17553 * which displays a calendar icon).
17555 triggerClass : 'x-form-date-trigger',
17559 * @cfg {Boolean} useIso
17560 * if enabled, then the date field will use a hidden field to store the
17561 * real value as iso formated date. default (false)
17565 * @cfg {String/Object} autoCreate
17566 * A DomHelper element spec, or true for a default element spec (defaults to
17567 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
17570 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
17573 hiddenField: false,
17575 onRender : function(ct, position)
17577 Roo.form.DateField.superclass.onRender.call(this, ct, position);
17579 //this.el.dom.removeAttribute('name');
17580 Roo.log("Changing name?");
17581 this.el.dom.setAttribute('name', this.name + '____hidden___' );
17582 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
17584 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
17585 // prevent input submission
17586 this.hiddenName = this.name;
17593 validateValue : function(value)
17595 value = this.formatDate(value);
17596 if(!Roo.form.DateField.superclass.validateValue.call(this, value)){
17597 Roo.log('super failed');
17600 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
17603 var svalue = value;
17604 value = this.parseDate(value);
17606 Roo.log('parse date failed' + svalue);
17607 this.markInvalid(String.format(this.invalidText, svalue, this.format));
17610 var time = value.getTime();
17611 if(this.minValue && time < this.minValue.getTime()){
17612 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
17615 if(this.maxValue && time > this.maxValue.getTime()){
17616 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
17619 if(this.disabledDays){
17620 var day = value.getDay();
17621 for(var i = 0; i < this.disabledDays.length; i++) {
17622 if(day === this.disabledDays[i]){
17623 this.markInvalid(this.disabledDaysText);
17628 var fvalue = this.formatDate(value);
17629 if(this.ddMatch && this.ddMatch.test(fvalue)){
17630 this.markInvalid(String.format(this.disabledDatesText, fvalue));
17637 // Provides logic to override the default TriggerField.validateBlur which just returns true
17638 validateBlur : function(){
17639 return !this.menu || !this.menu.isVisible();
17642 getName: function()
17644 // returns hidden if it's set..
17645 if (!this.rendered) {return ''};
17646 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
17651 * Returns the current date value of the date field.
17652 * @return {Date} The date value
17654 getValue : function(){
17656 return this.hiddenField ?
17657 this.hiddenField.value :
17658 this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
17662 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
17663 * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}
17664 * (the default format used is "m/d/y").
17667 //All of these calls set the same date value (May 4, 2006)
17669 //Pass a date object:
17670 var dt = new Date('5/4/06');
17671 dateField.setValue(dt);
17673 //Pass a date string (default format):
17674 dateField.setValue('5/4/06');
17676 //Pass a date string (custom format):
17677 dateField.format = 'Y-m-d';
17678 dateField.setValue('2006-5-4');
17680 * @param {String/Date} date The date or valid date string
17682 setValue : function(date){
17683 if (this.hiddenField) {
17684 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
17686 Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
17687 // make sure the value field is always stored as a date..
17688 this.value = this.parseDate(date);
17694 parseDate : function(value){
17695 if(!value || value instanceof Date){
17698 var v = Date.parseDate(value, this.format);
17699 if (!v && this.useIso) {
17700 v = Date.parseDate(value, 'Y-m-d');
17702 if(!v && this.altFormats){
17703 if(!this.altFormatsArray){
17704 this.altFormatsArray = this.altFormats.split("|");
17706 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
17707 v = Date.parseDate(value, this.altFormatsArray[i]);
17714 formatDate : function(date, fmt){
17715 return (!date || !(date instanceof Date)) ?
17716 date : date.dateFormat(fmt || this.format);
17721 select: function(m, d){
17724 this.fireEvent('select', this, d);
17726 show : function(){ // retain focus styling
17730 this.focus.defer(10, this);
17731 var ml = this.menuListeners;
17732 this.menu.un("select", ml.select, this);
17733 this.menu.un("show", ml.show, this);
17734 this.menu.un("hide", ml.hide, this);
17739 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
17740 onTriggerClick : function(){
17744 if(this.menu == null){
17745 this.menu = new Roo.menu.DateMenu();
17747 Roo.apply(this.menu.picker, {
17748 showClear: this.allowBlank,
17749 minDate : this.minValue,
17750 maxDate : this.maxValue,
17751 disabledDatesRE : this.ddMatch,
17752 disabledDatesText : this.disabledDatesText,
17753 disabledDays : this.disabledDays,
17754 disabledDaysText : this.disabledDaysText,
17755 format : this.useIso ? 'Y-m-d' : this.format,
17756 minText : String.format(this.minText, this.formatDate(this.minValue)),
17757 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
17759 this.menu.on(Roo.apply({}, this.menuListeners, {
17762 this.menu.picker.setValue(this.getValue() || new Date());
17763 this.menu.show(this.el, "tl-bl?");
17766 beforeBlur : function(){
17767 var v = this.parseDate(this.getRawValue());
17777 isDirty : function() {
17778 if(this.disabled) {
17782 if(typeof(this.startValue) === 'undefined'){
17786 return String(this.getValue()) !== String(this.startValue);
17790 cleanLeadingSpace : function(e)
17797 * Ext JS Library 1.1.1
17798 * Copyright(c) 2006-2007, Ext JS, LLC.
17800 * Originally Released Under LGPL - original licence link has changed is not relivant.
17803 * <script type="text/javascript">
17807 * @class Roo.form.MonthField
17808 * @extends Roo.form.TriggerField
17809 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
17811 * Create a new MonthField
17812 * @param {Object} config
17814 Roo.form.MonthField = function(config){
17816 Roo.form.MonthField.superclass.constructor.call(this, config);
17822 * Fires when a date is selected
17823 * @param {Roo.form.MonthFieeld} combo This combo box
17824 * @param {Date} date The date selected
17831 if(typeof this.minValue == "string") {
17832 this.minValue = this.parseDate(this.minValue);
17834 if(typeof this.maxValue == "string") {
17835 this.maxValue = this.parseDate(this.maxValue);
17837 this.ddMatch = null;
17838 if(this.disabledDates){
17839 var dd = this.disabledDates;
17841 for(var i = 0; i < dd.length; i++){
17843 if(i != dd.length-1) {
17847 this.ddMatch = new RegExp(re + ")");
17851 Roo.extend(Roo.form.MonthField, Roo.form.TriggerField, {
17853 * @cfg {String} format
17854 * The default date format string which can be overriden for localization support. The format must be
17855 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
17859 * @cfg {String} altFormats
17860 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
17861 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
17863 altFormats : "M Y|m/Y|m-y|m-Y|my|mY",
17865 * @cfg {Array} disabledDays
17866 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
17868 disabledDays : [0,1,2,3,4,5,6],
17870 * @cfg {String} disabledDaysText
17871 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
17873 disabledDaysText : "Disabled",
17875 * @cfg {Array} disabledDates
17876 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
17877 * expression so they are very powerful. Some examples:
17879 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
17880 * <li>["03/08", "09/16"] would disable those days for every year</li>
17881 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
17882 * <li>["03/../2006"] would disable every day in March 2006</li>
17883 * <li>["^03"] would disable every day in every March</li>
17885 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
17886 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
17888 disabledDates : null,
17890 * @cfg {String} disabledDatesText
17891 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
17893 disabledDatesText : "Disabled",
17895 * @cfg {Date/String} minValue
17896 * The minimum allowed date. Can be either a Javascript date object or a string date in a
17897 * valid format (defaults to null).
17901 * @cfg {Date/String} maxValue
17902 * The maximum allowed date. Can be either a Javascript date object or a string date in a
17903 * valid format (defaults to null).
17907 * @cfg {String} minText
17908 * The error text to display when the date in the cell is before minValue (defaults to
17909 * 'The date in this field must be after {minValue}').
17911 minText : "The date in this field must be equal to or after {0}",
17913 * @cfg {String} maxTextf
17914 * The error text to display when the date in the cell is after maxValue (defaults to
17915 * 'The date in this field must be before {maxValue}').
17917 maxText : "The date in this field must be equal to or before {0}",
17919 * @cfg {String} invalidText
17920 * The error text to display when the date in the field is invalid (defaults to
17921 * '{value} is not a valid date - it must be in the format {format}').
17923 invalidText : "{0} is not a valid date - it must be in the format {1}",
17925 * @cfg {String} triggerClass
17926 * An additional CSS class used to style the trigger button. The trigger will always get the
17927 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
17928 * which displays a calendar icon).
17930 triggerClass : 'x-form-date-trigger',
17934 * @cfg {Boolean} useIso
17935 * if enabled, then the date field will use a hidden field to store the
17936 * real value as iso formated date. default (true)
17940 * @cfg {String/Object} autoCreate
17941 * A DomHelper element spec, or true for a default element spec (defaults to
17942 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
17945 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "new-password"},
17948 hiddenField: false,
17950 hideMonthPicker : false,
17952 onRender : function(ct, position)
17954 Roo.form.MonthField.superclass.onRender.call(this, ct, position);
17956 this.el.dom.removeAttribute('name');
17957 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
17959 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
17960 // prevent input submission
17961 this.hiddenName = this.name;
17968 validateValue : function(value)
17970 value = this.formatDate(value);
17971 if(!Roo.form.MonthField.superclass.validateValue.call(this, value)){
17974 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
17977 var svalue = value;
17978 value = this.parseDate(value);
17980 this.markInvalid(String.format(this.invalidText, svalue, this.format));
17983 var time = value.getTime();
17984 if(this.minValue && time < this.minValue.getTime()){
17985 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
17988 if(this.maxValue && time > this.maxValue.getTime()){
17989 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
17992 /*if(this.disabledDays){
17993 var day = value.getDay();
17994 for(var i = 0; i < this.disabledDays.length; i++) {
17995 if(day === this.disabledDays[i]){
17996 this.markInvalid(this.disabledDaysText);
18002 var fvalue = this.formatDate(value);
18003 /*if(this.ddMatch && this.ddMatch.test(fvalue)){
18004 this.markInvalid(String.format(this.disabledDatesText, fvalue));
18012 // Provides logic to override the default TriggerField.validateBlur which just returns true
18013 validateBlur : function(){
18014 return !this.menu || !this.menu.isVisible();
18018 * Returns the current date value of the date field.
18019 * @return {Date} The date value
18021 getValue : function(){
18025 return this.hiddenField ?
18026 this.hiddenField.value :
18027 this.parseDate(Roo.form.MonthField.superclass.getValue.call(this)) || "";
18031 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
18032 * date, using MonthField.format as the date format, according to the same rules as {@link Date#parseDate}
18033 * (the default format used is "m/d/y").
18036 //All of these calls set the same date value (May 4, 2006)
18038 //Pass a date object:
18039 var dt = new Date('5/4/06');
18040 monthField.setValue(dt);
18042 //Pass a date string (default format):
18043 monthField.setValue('5/4/06');
18045 //Pass a date string (custom format):
18046 monthField.format = 'Y-m-d';
18047 monthField.setValue('2006-5-4');
18049 * @param {String/Date} date The date or valid date string
18051 setValue : function(date){
18052 Roo.log('month setValue' + date);
18053 // can only be first of month..
18055 var val = this.parseDate(date);
18057 if (this.hiddenField) {
18058 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
18060 Roo.form.MonthField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
18061 this.value = this.parseDate(date);
18065 parseDate : function(value){
18066 if(!value || value instanceof Date){
18067 value = value ? Date.parseDate(value.format('Y-m') + '-01', 'Y-m-d') : null;
18070 var v = Date.parseDate(value, this.format);
18071 if (!v && this.useIso) {
18072 v = Date.parseDate(value, 'Y-m-d');
18076 v = Date.parseDate(v.format('Y-m') +'-01', 'Y-m-d');
18080 if(!v && this.altFormats){
18081 if(!this.altFormatsArray){
18082 this.altFormatsArray = this.altFormats.split("|");
18084 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18085 v = Date.parseDate(value, this.altFormatsArray[i]);
18092 formatDate : function(date, fmt){
18093 return (!date || !(date instanceof Date)) ?
18094 date : date.dateFormat(fmt || this.format);
18099 select: function(m, d){
18101 this.fireEvent('select', this, d);
18103 show : function(){ // retain focus styling
18107 this.focus.defer(10, this);
18108 var ml = this.menuListeners;
18109 this.menu.un("select", ml.select, this);
18110 this.menu.un("show", ml.show, this);
18111 this.menu.un("hide", ml.hide, this);
18115 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
18116 onTriggerClick : function(){
18120 if(this.menu == null){
18121 this.menu = new Roo.menu.DateMenu();
18125 Roo.apply(this.menu.picker, {
18127 showClear: this.allowBlank,
18128 minDate : this.minValue,
18129 maxDate : this.maxValue,
18130 disabledDatesRE : this.ddMatch,
18131 disabledDatesText : this.disabledDatesText,
18133 format : this.useIso ? 'Y-m-d' : this.format,
18134 minText : String.format(this.minText, this.formatDate(this.minValue)),
18135 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
18138 this.menu.on(Roo.apply({}, this.menuListeners, {
18146 // hide month picker get's called when we called by 'before hide';
18148 var ignorehide = true;
18149 p.hideMonthPicker = function(disableAnim){
18153 if(this.monthPicker){
18154 Roo.log("hideMonthPicker called");
18155 if(disableAnim === true){
18156 this.monthPicker.hide();
18158 this.monthPicker.slideOut('t', {duration:.2});
18159 p.setValue(new Date(m.picker.mpSelYear, m.picker.mpSelMonth, 1));
18160 p.fireEvent("select", this, this.value);
18166 Roo.log('picker set value');
18167 Roo.log(this.getValue());
18168 p.setValue(this.getValue() ? this.parseDate(this.getValue()) : new Date());
18169 m.show(this.el, 'tl-bl?');
18170 ignorehide = false;
18171 // this will trigger hideMonthPicker..
18174 // hidden the day picker
18175 Roo.select('.x-date-picker table', true).first().dom.style.visibility = "hidden";
18181 p.showMonthPicker.defer(100, p);
18187 beforeBlur : function(){
18188 var v = this.parseDate(this.getRawValue());
18194 /** @cfg {Boolean} grow @hide */
18195 /** @cfg {Number} growMin @hide */
18196 /** @cfg {Number} growMax @hide */
18203 * Ext JS Library 1.1.1
18204 * Copyright(c) 2006-2007, Ext JS, LLC.
18206 * Originally Released Under LGPL - original licence link has changed is not relivant.
18209 * <script type="text/javascript">
18214 * @class Roo.form.ComboBox
18215 * @extends Roo.form.TriggerField
18216 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
18218 * Create a new ComboBox.
18219 * @param {Object} config Configuration options
18221 Roo.form.ComboBox = function(config){
18222 Roo.form.ComboBox.superclass.constructor.call(this, config);
18226 * Fires when the dropdown list is expanded
18227 * @param {Roo.form.ComboBox} combo This combo box
18232 * Fires when the dropdown list is collapsed
18233 * @param {Roo.form.ComboBox} combo This combo box
18237 * @event beforeselect
18238 * Fires before a list item is selected. Return false to cancel the selection.
18239 * @param {Roo.form.ComboBox} combo This combo box
18240 * @param {Roo.data.Record} record The data record returned from the underlying store
18241 * @param {Number} index The index of the selected item in the dropdown list
18243 'beforeselect' : true,
18246 * Fires when a list item is selected
18247 * @param {Roo.form.ComboBox} combo This combo box
18248 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
18249 * @param {Number} index The index of the selected item in the dropdown list
18253 * @event beforequery
18254 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
18255 * The event object passed has these properties:
18256 * @param {Roo.form.ComboBox} combo This combo box
18257 * @param {String} query The query
18258 * @param {Boolean} forceAll true to force "all" query
18259 * @param {Boolean} cancel true to cancel the query
18260 * @param {Object} e The query event object
18262 'beforequery': true,
18265 * Fires when the 'add' icon is pressed (add a listener to enable add button)
18266 * @param {Roo.form.ComboBox} combo This combo box
18271 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
18272 * @param {Roo.form.ComboBox} combo This combo box
18273 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
18279 if(this.transform){
18280 this.allowDomMove = false;
18281 var s = Roo.getDom(this.transform);
18282 if(!this.hiddenName){
18283 this.hiddenName = s.name;
18286 this.mode = 'local';
18287 var d = [], opts = s.options;
18288 for(var i = 0, len = opts.length;i < len; i++){
18290 var value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
18292 this.value = value;
18294 d.push([value, o.text]);
18296 this.store = new Roo.data.SimpleStore({
18298 fields: ['value', 'text'],
18301 this.valueField = 'value';
18302 this.displayField = 'text';
18304 s.name = Roo.id(); // wipe out the name in case somewhere else they have a reference
18305 if(!this.lazyRender){
18306 this.target = true;
18307 this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
18308 s.parentNode.removeChild(s); // remove it
18309 this.render(this.el.parentNode);
18311 s.parentNode.removeChild(s); // remove it
18316 this.store = Roo.factory(this.store, Roo.data);
18319 this.selectedIndex = -1;
18320 if(this.mode == 'local'){
18321 if(config.queryDelay === undefined){
18322 this.queryDelay = 10;
18324 if(config.minChars === undefined){
18330 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
18332 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
18335 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
18336 * rendering into an Roo.Editor, defaults to false)
18339 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
18340 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
18343 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
18346 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
18347 * the dropdown list (defaults to undefined, with no header element)
18351 * @cfg {String/Roo.Template} tpl The template to use to render the output
18355 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
18357 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
18359 listWidth: undefined,
18361 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
18362 * mode = 'remote' or 'text' if mode = 'local')
18364 displayField: undefined,
18366 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
18367 * mode = 'remote' or 'value' if mode = 'local').
18368 * Note: use of a valueField requires the user make a selection
18369 * in order for a value to be mapped.
18371 valueField: undefined,
18375 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
18376 * field's data value (defaults to the underlying DOM element's name)
18378 hiddenName: undefined,
18380 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
18384 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
18386 selectedClass: 'x-combo-selected',
18388 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
18389 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
18390 * which displays a downward arrow icon).
18392 triggerClass : 'x-form-arrow-trigger',
18394 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
18398 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
18399 * anchor positions (defaults to 'tl-bl')
18401 listAlign: 'tl-bl?',
18403 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
18407 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
18408 * query specified by the allQuery config option (defaults to 'query')
18410 triggerAction: 'query',
18412 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
18413 * (defaults to 4, does not apply if editable = false)
18417 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
18418 * delay (typeAheadDelay) if it matches a known value (defaults to false)
18422 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
18423 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
18427 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
18428 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
18432 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
18433 * when editable = true (defaults to false)
18435 selectOnFocus:false,
18437 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
18439 queryParam: 'query',
18441 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
18442 * when mode = 'remote' (defaults to 'Loading...')
18444 loadingText: 'Loading...',
18446 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
18450 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
18454 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
18455 * traditional select (defaults to true)
18459 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
18463 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
18467 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
18468 * listWidth has a higher value)
18472 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
18473 * allow the user to set arbitrary text into the field (defaults to false)
18475 forceSelection:false,
18477 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
18478 * if typeAhead = true (defaults to 250)
18480 typeAheadDelay : 250,
18482 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
18483 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
18485 valueNotFoundText : undefined,
18487 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
18489 blockFocus : false,
18492 * @cfg {Boolean} disableClear Disable showing of clear button.
18494 disableClear : false,
18496 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
18498 alwaysQuery : false,
18504 // element that contains real text value.. (when hidden is used..)
18507 onRender : function(ct, position)
18509 Roo.form.ComboBox.superclass.onRender.call(this, ct, position);
18511 if(this.hiddenName){
18512 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
18514 this.hiddenField.value =
18515 this.hiddenValue !== undefined ? this.hiddenValue :
18516 this.value !== undefined ? this.value : '';
18518 // prevent input submission
18519 this.el.dom.removeAttribute('name');
18525 this.el.dom.setAttribute('autocomplete', 'off');
18528 var cls = 'x-combo-list';
18530 this.list = new Roo.Layer({
18531 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
18534 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
18535 this.list.setWidth(lw);
18536 this.list.swallowEvent('mousewheel');
18537 this.assetHeight = 0;
18540 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
18541 this.assetHeight += this.header.getHeight();
18544 this.innerList = this.list.createChild({cls:cls+'-inner'});
18545 this.innerList.on('mouseover', this.onViewOver, this);
18546 this.innerList.on('mousemove', this.onViewMove, this);
18547 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
18549 if(this.allowBlank && !this.pageSize && !this.disableClear){
18550 this.footer = this.list.createChild({cls:cls+'-ft'});
18551 this.pageTb = new Roo.Toolbar(this.footer);
18555 this.footer = this.list.createChild({cls:cls+'-ft'});
18556 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
18557 {pageSize: this.pageSize});
18561 if (this.pageTb && this.allowBlank && !this.disableClear) {
18563 this.pageTb.add(new Roo.Toolbar.Fill(), {
18564 cls: 'x-btn-icon x-btn-clear',
18566 handler: function()
18569 _this.clearValue();
18570 _this.onSelect(false, -1);
18575 this.assetHeight += this.footer.getHeight();
18580 this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
18583 this.view = new Roo.View(this.innerList, this.tpl, {
18586 selectedClass: this.selectedClass
18589 this.view.on('click', this.onViewClick, this);
18591 this.store.on('beforeload', this.onBeforeLoad, this);
18592 this.store.on('load', this.onLoad, this);
18593 this.store.on('loadexception', this.onLoadException, this);
18595 if(this.resizable){
18596 this.resizer = new Roo.Resizable(this.list, {
18597 pinned:true, handles:'se'
18599 this.resizer.on('resize', function(r, w, h){
18600 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
18601 this.listWidth = w;
18602 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
18603 this.restrictHeight();
18605 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
18607 if(!this.editable){
18608 this.editable = true;
18609 this.setEditable(false);
18613 if (typeof(this.events.add.listeners) != 'undefined') {
18615 this.addicon = this.wrap.createChild(
18616 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
18618 this.addicon.on('click', function(e) {
18619 this.fireEvent('add', this);
18622 if (typeof(this.events.edit.listeners) != 'undefined') {
18624 this.editicon = this.wrap.createChild(
18625 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
18626 if (this.addicon) {
18627 this.editicon.setStyle('margin-left', '40px');
18629 this.editicon.on('click', function(e) {
18631 // we fire even if inothing is selected..
18632 this.fireEvent('edit', this, this.lastData );
18642 initEvents : function(){
18643 Roo.form.ComboBox.superclass.initEvents.call(this);
18645 this.keyNav = new Roo.KeyNav(this.el, {
18646 "up" : function(e){
18647 this.inKeyMode = true;
18651 "down" : function(e){
18652 if(!this.isExpanded()){
18653 this.onTriggerClick();
18655 this.inKeyMode = true;
18660 "enter" : function(e){
18661 this.onViewClick();
18665 "esc" : function(e){
18669 "tab" : function(e){
18670 this.onViewClick(false);
18671 this.fireEvent("specialkey", this, e);
18677 doRelay : function(foo, bar, hname){
18678 if(hname == 'down' || this.scope.isExpanded()){
18679 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
18686 this.queryDelay = Math.max(this.queryDelay || 10,
18687 this.mode == 'local' ? 10 : 250);
18688 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
18689 if(this.typeAhead){
18690 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
18692 if(this.editable !== false){
18693 this.el.on("keyup", this.onKeyUp, this);
18695 if(this.forceSelection){
18696 this.on('blur', this.doForce, this);
18700 onDestroy : function(){
18702 this.view.setStore(null);
18703 this.view.el.removeAllListeners();
18704 this.view.el.remove();
18705 this.view.purgeListeners();
18708 this.list.destroy();
18711 this.store.un('beforeload', this.onBeforeLoad, this);
18712 this.store.un('load', this.onLoad, this);
18713 this.store.un('loadexception', this.onLoadException, this);
18715 Roo.form.ComboBox.superclass.onDestroy.call(this);
18719 fireKey : function(e){
18720 if(e.isNavKeyPress() && !this.list.isVisible()){
18721 this.fireEvent("specialkey", this, e);
18726 onResize: function(w, h){
18727 Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
18729 if(typeof w != 'number'){
18730 // we do not handle it!?!?
18733 var tw = this.trigger.getWidth();
18734 tw += this.addicon ? this.addicon.getWidth() : 0;
18735 tw += this.editicon ? this.editicon.getWidth() : 0;
18737 this.el.setWidth( this.adjustWidth('input', x));
18739 this.trigger.setStyle('left', x+'px');
18741 if(this.list && this.listWidth === undefined){
18742 var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
18743 this.list.setWidth(lw);
18744 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
18752 * Allow or prevent the user from directly editing the field text. If false is passed,
18753 * the user will only be able to select from the items defined in the dropdown list. This method
18754 * is the runtime equivalent of setting the 'editable' config option at config time.
18755 * @param {Boolean} value True to allow the user to directly edit the field text
18757 setEditable : function(value){
18758 if(value == this.editable){
18761 this.editable = value;
18763 this.el.dom.setAttribute('readOnly', true);
18764 this.el.on('mousedown', this.onTriggerClick, this);
18765 this.el.addClass('x-combo-noedit');
18767 this.el.dom.setAttribute('readOnly', false);
18768 this.el.un('mousedown', this.onTriggerClick, this);
18769 this.el.removeClass('x-combo-noedit');
18774 onBeforeLoad : function(){
18775 if(!this.hasFocus){
18778 this.innerList.update(this.loadingText ?
18779 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
18780 this.restrictHeight();
18781 this.selectedIndex = -1;
18785 onLoad : function(){
18786 if(!this.hasFocus){
18789 if(this.store.getCount() > 0){
18791 this.restrictHeight();
18792 if(this.lastQuery == this.allQuery){
18794 this.el.dom.select();
18796 if(!this.selectByValue(this.value, true)){
18797 this.select(0, true);
18801 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
18802 this.taTask.delay(this.typeAheadDelay);
18806 this.onEmptyResults();
18811 onLoadException : function()
18814 Roo.log(this.store.reader.jsonData);
18815 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
18816 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
18822 onTypeAhead : function(){
18823 if(this.store.getCount() > 0){
18824 var r = this.store.getAt(0);
18825 var newValue = r.data[this.displayField];
18826 var len = newValue.length;
18827 var selStart = this.getRawValue().length;
18828 if(selStart != len){
18829 this.setRawValue(newValue);
18830 this.selectText(selStart, newValue.length);
18836 onSelect : function(record, index){
18837 if(this.fireEvent('beforeselect', this, record, index) !== false){
18838 this.setFromData(index > -1 ? record.data : false);
18840 this.fireEvent('select', this, record, index);
18845 * Returns the currently selected field value or empty string if no value is set.
18846 * @return {String} value The selected value
18848 getValue : function(){
18849 if(this.valueField){
18850 return typeof this.value != 'undefined' ? this.value : '';
18852 return Roo.form.ComboBox.superclass.getValue.call(this);
18856 * Clears any text/value currently set in the field
18858 clearValue : function(){
18859 if(this.hiddenField){
18860 this.hiddenField.value = '';
18863 this.setRawValue('');
18864 this.lastSelectionText = '';
18869 * Sets the specified value into the field. If the value finds a match, the corresponding record text
18870 * will be displayed in the field. If the value does not match the data value of an existing item,
18871 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
18872 * Otherwise the field will be blank (although the value will still be set).
18873 * @param {String} value The value to match
18875 setValue : function(v){
18877 if(this.valueField){
18878 var r = this.findRecord(this.valueField, v);
18880 text = r.data[this.displayField];
18881 }else if(this.valueNotFoundText !== undefined){
18882 text = this.valueNotFoundText;
18885 this.lastSelectionText = text;
18886 if(this.hiddenField){
18887 this.hiddenField.value = v;
18889 Roo.form.ComboBox.superclass.setValue.call(this, text);
18893 * @property {Object} the last set data for the element
18898 * Sets the value of the field based on a object which is related to the record format for the store.
18899 * @param {Object} value the value to set as. or false on reset?
18901 setFromData : function(o){
18902 var dv = ''; // display value
18903 var vv = ''; // value value..
18905 if (this.displayField) {
18906 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
18908 // this is an error condition!!!
18909 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
18912 if(this.valueField){
18913 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
18915 if(this.hiddenField){
18916 this.hiddenField.value = vv;
18918 this.lastSelectionText = dv;
18919 Roo.form.ComboBox.superclass.setValue.call(this, dv);
18923 // no hidden field.. - we store the value in 'value', but still display
18924 // display field!!!!
18925 this.lastSelectionText = dv;
18926 Roo.form.ComboBox.superclass.setValue.call(this, dv);
18932 reset : function(){
18933 // overridden so that last data is reset..
18934 this.setValue(this.resetValue);
18935 this.originalValue = this.getValue();
18936 this.clearInvalid();
18937 this.lastData = false;
18939 this.view.clearSelections();
18943 findRecord : function(prop, value){
18945 if(this.store.getCount() > 0){
18946 this.store.each(function(r){
18947 if(r.data[prop] == value){
18957 getName: function()
18959 // returns hidden if it's set..
18960 if (!this.rendered) {return ''};
18961 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
18965 onViewMove : function(e, t){
18966 this.inKeyMode = false;
18970 onViewOver : function(e, t){
18971 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
18974 var item = this.view.findItemFromChild(t);
18976 var index = this.view.indexOf(item);
18977 this.select(index, false);
18982 onViewClick : function(doFocus)
18984 var index = this.view.getSelectedIndexes()[0];
18985 var r = this.store.getAt(index);
18987 this.onSelect(r, index);
18989 if(doFocus !== false && !this.blockFocus){
18995 restrictHeight : function(){
18996 this.innerList.dom.style.height = '';
18997 var inner = this.innerList.dom;
18998 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
18999 this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
19000 this.list.beginUpdate();
19001 this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
19002 this.list.alignTo(this.el, this.listAlign);
19003 this.list.endUpdate();
19007 onEmptyResults : function(){
19012 * Returns true if the dropdown list is expanded, else false.
19014 isExpanded : function(){
19015 return this.list.isVisible();
19019 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
19020 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
19021 * @param {String} value The data value of the item to select
19022 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
19023 * selected item if it is not currently in view (defaults to true)
19024 * @return {Boolean} True if the value matched an item in the list, else false
19026 selectByValue : function(v, scrollIntoView){
19027 if(v !== undefined && v !== null){
19028 var r = this.findRecord(this.valueField || this.displayField, v);
19030 this.select(this.store.indexOf(r), scrollIntoView);
19038 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
19039 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
19040 * @param {Number} index The zero-based index of the list item to select
19041 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
19042 * selected item if it is not currently in view (defaults to true)
19044 select : function(index, scrollIntoView){
19045 this.selectedIndex = index;
19046 this.view.select(index);
19047 if(scrollIntoView !== false){
19048 var el = this.view.getNode(index);
19050 this.innerList.scrollChildIntoView(el, false);
19056 selectNext : function(){
19057 var ct = this.store.getCount();
19059 if(this.selectedIndex == -1){
19061 }else if(this.selectedIndex < ct-1){
19062 this.select(this.selectedIndex+1);
19068 selectPrev : function(){
19069 var ct = this.store.getCount();
19071 if(this.selectedIndex == -1){
19073 }else if(this.selectedIndex != 0){
19074 this.select(this.selectedIndex-1);
19080 onKeyUp : function(e){
19081 if(this.editable !== false && !e.isSpecialKey()){
19082 this.lastKey = e.getKey();
19083 this.dqTask.delay(this.queryDelay);
19088 validateBlur : function(){
19089 return !this.list || !this.list.isVisible();
19093 initQuery : function(){
19094 this.doQuery(this.getRawValue());
19098 doForce : function(){
19099 if(this.el.dom.value.length > 0){
19100 this.el.dom.value =
19101 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
19107 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
19108 * query allowing the query action to be canceled if needed.
19109 * @param {String} query The SQL query to execute
19110 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
19111 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
19112 * saved in the current store (defaults to false)
19114 doQuery : function(q, forceAll){
19115 if(q === undefined || q === null){
19120 forceAll: forceAll,
19124 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
19128 forceAll = qe.forceAll;
19129 if(forceAll === true || (q.length >= this.minChars)){
19130 if(this.lastQuery != q || this.alwaysQuery){
19131 this.lastQuery = q;
19132 if(this.mode == 'local'){
19133 this.selectedIndex = -1;
19135 this.store.clearFilter();
19137 this.store.filter(this.displayField, q);
19141 this.store.baseParams[this.queryParam] = q;
19143 params: this.getParams(q)
19148 this.selectedIndex = -1;
19155 getParams : function(q){
19157 //p[this.queryParam] = q;
19160 p.limit = this.pageSize;
19166 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
19168 collapse : function(){
19169 if(!this.isExpanded()){
19173 Roo.get(document).un('mousedown', this.collapseIf, this);
19174 Roo.get(document).un('mousewheel', this.collapseIf, this);
19175 if (!this.editable) {
19176 Roo.get(document).un('keydown', this.listKeyPress, this);
19178 this.fireEvent('collapse', this);
19182 collapseIf : function(e){
19183 if(!e.within(this.wrap) && !e.within(this.list)){
19189 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
19191 expand : function(){
19192 if(this.isExpanded() || !this.hasFocus){
19195 this.list.alignTo(this.el, this.listAlign);
19197 Roo.get(document).on('mousedown', this.collapseIf, this);
19198 Roo.get(document).on('mousewheel', this.collapseIf, this);
19199 if (!this.editable) {
19200 Roo.get(document).on('keydown', this.listKeyPress, this);
19203 this.fireEvent('expand', this);
19207 // Implements the default empty TriggerField.onTriggerClick function
19208 onTriggerClick : function(){
19212 if(this.isExpanded()){
19214 if (!this.blockFocus) {
19219 this.hasFocus = true;
19220 if(this.triggerAction == 'all') {
19221 this.doQuery(this.allQuery, true);
19223 this.doQuery(this.getRawValue());
19225 if (!this.blockFocus) {
19230 listKeyPress : function(e)
19232 //Roo.log('listkeypress');
19233 // scroll to first matching element based on key pres..
19234 if (e.isSpecialKey()) {
19237 var k = String.fromCharCode(e.getKey()).toUpperCase();
19240 var csel = this.view.getSelectedNodes();
19241 var cselitem = false;
19243 var ix = this.view.indexOf(csel[0]);
19244 cselitem = this.store.getAt(ix);
19245 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
19251 this.store.each(function(v) {
19253 // start at existing selection.
19254 if (cselitem.id == v.id) {
19260 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
19261 match = this.store.indexOf(v);
19266 if (match === false) {
19267 return true; // no more action?
19270 this.view.select(match);
19271 var sn = Roo.get(this.view.getSelectedNodes()[0]);
19272 sn.scrollIntoView(sn.dom.parentNode, false);
19276 * @cfg {Boolean} grow
19280 * @cfg {Number} growMin
19284 * @cfg {Number} growMax
19292 * Copyright(c) 2010-2012, Roo J Solutions Limited
19299 * @class Roo.form.ComboBoxArray
19300 * @extends Roo.form.TextField
19301 * A facebook style adder... for lists of email / people / countries etc...
19302 * pick multiple items from a combo box, and shows each one.
19304 * Fred [x] Brian [x] [Pick another |v]
19307 * For this to work: it needs various extra information
19308 * - normal combo problay has
19310 * + displayField, valueField
19312 * For our purpose...
19315 * If we change from 'extends' to wrapping...
19322 * Create a new ComboBoxArray.
19323 * @param {Object} config Configuration options
19327 Roo.form.ComboBoxArray = function(config)
19331 * @event beforeremove
19332 * Fires before remove the value from the list
19333 * @param {Roo.form.ComboBoxArray} _self This combo box array
19334 * @param {Roo.form.ComboBoxArray.Item} item removed item
19336 'beforeremove' : true,
19339 * Fires when remove the value from the list
19340 * @param {Roo.form.ComboBoxArray} _self This combo box array
19341 * @param {Roo.form.ComboBoxArray.Item} item removed item
19348 Roo.form.ComboBoxArray.superclass.constructor.call(this, config);
19350 this.items = new Roo.util.MixedCollection(false);
19352 // construct the child combo...
19362 Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField,
19365 * @cfg {Roo.form.Combo} combo The combo box that is wrapped
19370 // behavies liek a hiddne field
19371 inputType: 'hidden',
19373 * @cfg {Number} width The width of the box that displays the selected element
19380 * @cfg {String} name The name of the visable items on this form (eg. titles not ids)
19384 * @cfg {String} hiddenName The hidden name of the field, often contains an comma seperated list of names
19386 hiddenName : false,
19388 * @cfg {String} seperator The value seperator normally ','
19392 // private the array of items that are displayed..
19394 // private - the hidden field el.
19396 // private - the filed el..
19399 //validateValue : function() { return true; }, // all values are ok!
19400 //onAddClick: function() { },
19402 onRender : function(ct, position)
19405 // create the standard hidden element
19406 //Roo.form.ComboBoxArray.superclass.onRender.call(this, ct, position);
19409 // give fake names to child combo;
19410 this.combo.hiddenName = this.hiddenName ? (this.hiddenName+'-subcombo') : this.hiddenName;
19411 this.combo.name = this.name ? (this.name+'-subcombo') : this.name;
19413 this.combo = Roo.factory(this.combo, Roo.form);
19414 this.combo.onRender(ct, position);
19415 if (typeof(this.combo.width) != 'undefined') {
19416 this.combo.onResize(this.combo.width,0);
19419 this.combo.initEvents();
19421 // assigned so form know we need to do this..
19422 this.store = this.combo.store;
19423 this.valueField = this.combo.valueField;
19424 this.displayField = this.combo.displayField ;
19427 this.combo.wrap.addClass('x-cbarray-grp');
19429 var cbwrap = this.combo.wrap.createChild(
19430 {tag: 'div', cls: 'x-cbarray-cb'},
19435 this.hiddenEl = this.combo.wrap.createChild({
19436 tag: 'input', type:'hidden' , name: this.hiddenName, value : ''
19438 this.el = this.combo.wrap.createChild({
19439 tag: 'input', type:'hidden' , name: this.name, value : ''
19441 // this.el.dom.removeAttribute("name");
19444 this.outerWrap = this.combo.wrap;
19445 this.wrap = cbwrap;
19447 this.outerWrap.setWidth(this.width);
19448 this.outerWrap.dom.removeChild(this.el.dom);
19450 this.wrap.dom.appendChild(this.el.dom);
19451 this.outerWrap.dom.removeChild(this.combo.trigger.dom);
19452 this.combo.wrap.dom.appendChild(this.combo.trigger.dom);
19454 this.combo.trigger.setStyle('position','relative');
19455 this.combo.trigger.setStyle('left', '0px');
19456 this.combo.trigger.setStyle('top', '2px');
19458 this.combo.el.setStyle('vertical-align', 'text-bottom');
19460 //this.trigger.setStyle('vertical-align', 'top');
19462 // this should use the code from combo really... on('add' ....)
19466 this.adder = this.outerWrap.createChild(
19467 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-adder', style: 'margin-left:2px'});
19469 this.adder.on('click', function(e) {
19470 _t.fireEvent('adderclick', this, e);
19474 //this.adder.on('click', this.onAddClick, _t);
19477 this.combo.on('select', function(cb, rec, ix) {
19478 this.addItem(rec.data);
19481 cb.el.dom.value = '';
19482 //cb.lastData = rec.data;
19491 getName: function()
19493 // returns hidden if it's set..
19494 if (!this.rendered) {return ''};
19495 return this.hiddenName ? this.hiddenName : this.name;
19500 onResize: function(w, h){
19503 // not sure if this is needed..
19504 //this.combo.onResize(w,h);
19506 if(typeof w != 'number'){
19507 // we do not handle it!?!?
19510 var tw = this.combo.trigger.getWidth();
19511 tw += this.addicon ? this.addicon.getWidth() : 0;
19512 tw += this.editicon ? this.editicon.getWidth() : 0;
19514 this.combo.el.setWidth( this.combo.adjustWidth('input', x));
19516 this.combo.trigger.setStyle('left', '0px');
19518 if(this.list && this.listWidth === undefined){
19519 var lw = Math.max(x + this.combo.trigger.getWidth(), this.combo.minListWidth);
19520 this.list.setWidth(lw);
19521 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
19528 addItem: function(rec)
19530 var valueField = this.combo.valueField;
19531 var displayField = this.combo.displayField;
19533 if (this.items.indexOfKey(rec[valueField]) > -1) {
19534 //console.log("GOT " + rec.data.id);
19538 var x = new Roo.form.ComboBoxArray.Item({
19539 //id : rec[this.idField],
19541 displayField : displayField ,
19542 tipField : displayField ,
19546 this.items.add(rec[valueField],x);
19547 // add it before the element..
19548 this.updateHiddenEl();
19549 x.render(this.outerWrap, this.wrap.dom);
19550 // add the image handler..
19553 updateHiddenEl : function()
19556 if (!this.hiddenEl) {
19560 var idField = this.combo.valueField;
19562 this.items.each(function(f) {
19563 ar.push(f.data[idField]);
19565 this.hiddenEl.dom.value = ar.join(this.seperator);
19571 this.items.clear();
19573 Roo.each(this.outerWrap.select('.x-cbarray-item', true).elements, function(el){
19577 this.el.dom.value = '';
19578 if (this.hiddenEl) {
19579 this.hiddenEl.dom.value = '';
19583 getValue: function()
19585 return this.hiddenEl ? this.hiddenEl.dom.value : '';
19587 setValue: function(v) // not a valid action - must use addItems..
19592 if (this.store.isLocal && (typeof(v) == 'string')) {
19593 // then we can use the store to find the values..
19594 // comma seperated at present.. this needs to allow JSON based encoding..
19595 this.hiddenEl.value = v;
19597 Roo.each(v.split(this.seperator), function(k) {
19598 Roo.log("CHECK " + this.valueField + ',' + k);
19599 var li = this.store.query(this.valueField, k);
19604 add[this.valueField] = k;
19605 add[this.displayField] = li.item(0).data[this.displayField];
19611 if (typeof(v) == 'object' ) {
19612 // then let's assume it's an array of objects..
19613 Roo.each(v, function(l) {
19615 if (typeof(l) == 'string') {
19617 add[this.valueField] = l;
19618 add[this.displayField] = l
19627 setFromData: function(v)
19629 // this recieves an object, if setValues is called.
19631 this.el.dom.value = v[this.displayField];
19632 this.hiddenEl.dom.value = v[this.valueField];
19633 if (typeof(v[this.valueField]) != 'string' || !v[this.valueField].length) {
19636 var kv = v[this.valueField];
19637 var dv = v[this.displayField];
19638 kv = typeof(kv) != 'string' ? '' : kv;
19639 dv = typeof(dv) != 'string' ? '' : dv;
19642 var keys = kv.split(this.seperator);
19643 var display = dv.split(this.seperator);
19644 for (var i = 0 ; i < keys.length; i++) {
19646 add[this.valueField] = keys[i];
19647 add[this.displayField] = display[i];
19655 * Validates the combox array value
19656 * @return {Boolean} True if the value is valid, else false
19658 validate : function(){
19659 if(this.disabled || this.validateValue(this.processValue(this.getValue()))){
19660 this.clearInvalid();
19666 validateValue : function(value){
19667 return Roo.form.ComboBoxArray.superclass.validateValue.call(this, this.getValue());
19675 isDirty : function() {
19676 if(this.disabled) {
19681 var d = Roo.decode(String(this.originalValue));
19683 return String(this.getValue()) !== String(this.originalValue);
19686 var originalValue = [];
19688 for (var i = 0; i < d.length; i++){
19689 originalValue.push(d[i][this.valueField]);
19692 return String(this.getValue()) !== String(originalValue.join(this.seperator));
19701 * @class Roo.form.ComboBoxArray.Item
19702 * @extends Roo.BoxComponent
19703 * A selected item in the list
19704 * Fred [x] Brian [x] [Pick another |v]
19707 * Create a new item.
19708 * @param {Object} config Configuration options
19711 Roo.form.ComboBoxArray.Item = function(config) {
19712 config.id = Roo.id();
19713 Roo.form.ComboBoxArray.Item.superclass.constructor.call(this, config);
19716 Roo.extend(Roo.form.ComboBoxArray.Item, Roo.BoxComponent, {
19719 displayField : false,
19723 defaultAutoCreate : {
19725 cls: 'x-cbarray-item',
19732 src : Roo.BLANK_IMAGE_URL ,
19740 onRender : function(ct, position)
19742 Roo.form.Field.superclass.onRender.call(this, ct, position);
19745 var cfg = this.getAutoCreate();
19746 this.el = ct.createChild(cfg, position);
19749 this.el.child('img').dom.setAttribute('src', Roo.BLANK_IMAGE_URL);
19751 this.el.child('div').dom.innerHTML = this.cb.renderer ?
19752 this.cb.renderer(this.data) :
19753 String.format('{0}',this.data[this.displayField]);
19756 this.el.child('div').dom.setAttribute('qtip',
19757 String.format('{0}',this.data[this.tipField])
19760 this.el.child('img').on('click', this.remove, this);
19764 remove : function()
19766 if(this.cb.disabled){
19770 if(false !== this.cb.fireEvent('beforeremove', this.cb, this)){
19771 this.cb.items.remove(this);
19772 this.el.child('img').un('click', this.remove, this);
19774 this.cb.updateHiddenEl();
19776 this.cb.fireEvent('remove', this.cb, this);
19781 * RooJS Library 1.1.1
19782 * Copyright(c) 2008-2011 Alan Knowles
19789 * @class Roo.form.ComboNested
19790 * @extends Roo.form.ComboBox
19791 * A combobox for that allows selection of nested items in a list,
19806 * Create a new ComboNested
19807 * @param {Object} config Configuration options
19809 Roo.form.ComboNested = function(config){
19810 Roo.form.ComboCheck.superclass.constructor.call(this, config);
19811 // should verify some data...
19813 // hiddenName = required..
19814 // displayField = required
19815 // valudField == required
19816 var req= [ 'hiddenName', 'displayField', 'valueField' ];
19818 Roo.each(req, function(e) {
19819 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
19820 throw "Roo.form.ComboNested : missing value for: " + e;
19827 Roo.extend(Roo.form.ComboNested, Roo.form.ComboBox, {
19830 * @config {Number} max Number of columns to show
19835 list : null, // the outermost div..
19836 innerLists : null, // the
19840 loadingChildren : false,
19842 onRender : function(ct, position)
19844 Roo.form.ComboBox.superclass.onRender.call(this, ct, position); // skip parent call - got to above..
19846 if(this.hiddenName){
19847 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
19849 this.hiddenField.value =
19850 this.hiddenValue !== undefined ? this.hiddenValue :
19851 this.value !== undefined ? this.value : '';
19853 // prevent input submission
19854 this.el.dom.removeAttribute('name');
19860 this.el.dom.setAttribute('autocomplete', 'off');
19863 var cls = 'x-combo-list';
19865 this.list = new Roo.Layer({
19866 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
19869 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
19870 this.list.setWidth(lw);
19871 this.list.swallowEvent('mousewheel');
19872 this.assetHeight = 0;
19875 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
19876 this.assetHeight += this.header.getHeight();
19878 this.innerLists = [];
19881 for (var i =0 ; i < this.maxColumns; i++) {
19882 this.onRenderList( cls, i);
19885 // always needs footer, as we are going to have an 'OK' button.
19886 this.footer = this.list.createChild({cls:cls+'-ft'});
19887 this.pageTb = new Roo.Toolbar(this.footer);
19892 handler: function()
19898 if ( this.allowBlank && !this.disableClear) {
19900 this.pageTb.add(new Roo.Toolbar.Fill(), {
19901 cls: 'x-btn-icon x-btn-clear',
19903 handler: function()
19906 _this.clearValue();
19907 _this.onSelect(false, -1);
19912 this.assetHeight += this.footer.getHeight();
19916 onRenderList : function ( cls, i)
19919 var lw = Math.floor(
19920 ((this.listWidth * this.maxColumns || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / this.maxColumns
19923 this.list.setWidth(lw); // default to '1'
19925 var il = this.innerLists[i] = this.list.createChild({cls:cls+'-inner'});
19926 //il.on('mouseover', this.onViewOver, this, { list: i });
19927 //il.on('mousemove', this.onViewMove, this, { list: i });
19929 il.setStyle({ 'overflow-x' : 'hidden'});
19932 this.tpl = new Roo.Template({
19933 html : '<div class="'+cls+'-item '+cls+'-item-{cn:this.isEmpty}">{' + this.displayField + '}</div>',
19934 isEmpty: function (value, allValues) {
19936 var dl = typeof(value.data) != 'undefined' ? value.data.length : value.length; ///json is a nested response..
19937 return dl ? 'has-children' : 'no-children'
19942 var store = this.store;
19944 store = new Roo.data.SimpleStore({
19945 //fields : this.store.reader.meta.fields,
19946 reader : this.store.reader,
19950 this.stores[i] = store;
19952 var view = this.views[i] = new Roo.View(
19958 selectedClass: this.selectedClass
19961 view.getEl().setWidth(lw);
19962 view.getEl().setStyle({
19963 position: i < 1 ? 'relative' : 'absolute',
19965 left: (i * lw ) + 'px',
19966 display : i > 0 ? 'none' : 'block'
19968 view.on('selectionchange', this.onSelectChange.createDelegate(this, {list : i }, true));
19969 view.on('dblclick', this.onDoubleClick.createDelegate(this, {list : i }, true));
19970 //view.on('click', this.onViewClick, this, { list : i });
19972 store.on('beforeload', this.onBeforeLoad, this);
19973 store.on('load', this.onLoad, this, { list : i});
19974 store.on('loadexception', this.onLoadException, this);
19976 // hide the other vies..
19982 restrictHeight : function()
19985 Roo.each(this.innerLists, function(il,i) {
19986 var el = this.views[i].getEl();
19987 el.dom.style.height = '';
19988 var inner = el.dom;
19989 var h = Math.max(il.clientHeight, il.offsetHeight, il.scrollHeight);
19990 // only adjust heights on other ones..
19991 mh = Math.max(h, mh);
19994 el.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
19995 il.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
20002 this.list.beginUpdate();
20003 this.list.setHeight(mh+this.list.getFrameWidth('tb')+this.assetHeight);
20004 this.list.alignTo(this.el, this.listAlign);
20005 this.list.endUpdate();
20010 // -- store handlers..
20012 onBeforeLoad : function()
20014 if(!this.hasFocus){
20017 this.innerLists[0].update(this.loadingText ?
20018 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
20019 this.restrictHeight();
20020 this.selectedIndex = -1;
20023 onLoad : function(a,b,c,d)
20025 if (!this.loadingChildren) {
20026 // then we are loading the top level. - hide the children
20027 for (var i = 1;i < this.views.length; i++) {
20028 this.views[i].getEl().setStyle({ display : 'none' });
20030 var lw = Math.floor(
20031 ((this.listWidth * this.maxColumns || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / this.maxColumns
20034 this.list.setWidth(lw); // default to '1'
20038 if(!this.hasFocus){
20042 if(this.store.getCount() > 0) {
20044 this.restrictHeight();
20046 this.onEmptyResults();
20049 if (!this.loadingChildren) {
20050 this.selectActive();
20053 this.stores[1].loadData([]);
20054 this.stores[2].loadData([]);
20063 onLoadException : function()
20066 Roo.log(this.store.reader.jsonData);
20067 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
20068 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
20073 // no cleaning of leading spaces on blur here.
20074 cleanLeadingSpace : function(e) { },
20077 onSelectChange : function (view, sels, opts )
20079 var ix = view.getSelectedIndexes();
20081 if (opts.list > this.maxColumns - 2) {
20082 if (view.store.getCount()< 1) {
20083 this.views[opts.list ].getEl().setStyle({ display : 'none' });
20087 // used to clear ?? but if we are loading unselected
20088 this.setFromData(view.store.getAt(ix[0]).data);
20097 // this get's fired when trigger opens..
20098 // this.setFromData({});
20099 var str = this.stores[opts.list+1];
20100 str.data.clear(); // removeall wihtout the fire events..
20104 var rec = view.store.getAt(ix[0]);
20106 this.setFromData(rec.data);
20107 this.fireEvent('select', this, rec, ix[0]);
20109 var lw = Math.floor(
20111 (this.listWidth * this.maxColumns || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')
20112 ) / this.maxColumns
20114 this.loadingChildren = true;
20115 this.stores[opts.list+1].loadDataFromChildren( rec );
20116 this.loadingChildren = false;
20117 var dl = this.stores[opts.list+1]. getTotalCount();
20119 this.views[opts.list+1].getEl().setHeight( this.innerLists[0].getHeight());
20121 this.views[opts.list+1].getEl().setStyle({ display : dl ? 'block' : 'none' });
20122 for (var i = opts.list+2; i < this.views.length;i++) {
20123 this.views[i].getEl().setStyle({ display : 'none' });
20126 this.innerLists[opts.list+1].setHeight( this.innerLists[0].getHeight());
20127 this.list.setWidth(lw * (opts.list + (dl ? 2 : 1)));
20129 if (this.isLoading) {
20130 // this.selectActive(opts.list);
20138 onDoubleClick : function()
20140 this.collapse(); //??
20148 recordToStack : function(store, prop, value, stack)
20150 var cstore = new Roo.data.SimpleStore({
20151 //fields : this.store.reader.meta.fields, // we need array reader.. for
20152 reader : this.store.reader,
20156 var record = false;
20158 if(store.getCount() < 1){
20161 store.each(function(r){
20162 if(r.data[prop] == value){
20167 if (r.data.cn && r.data.cn.length) {
20168 cstore.loadDataFromChildren( r);
20169 var cret = _this.recordToStack(cstore, prop, value, stack);
20170 if (cret !== false) {
20179 if (record == false) {
20182 stack.unshift(srec);
20187 * find the stack of stores that match our value.
20192 selectActive : function ()
20194 // if store is not loaded, then we will need to wait for that to happen first.
20196 this.recordToStack(this.store, this.valueField, this.getValue(), stack);
20197 for (var i = 0; i < stack.length; i++ ) {
20198 this.views[i].select(stack[i].store.indexOf(stack[i]), false, false );
20210 * Ext JS Library 1.1.1
20211 * Copyright(c) 2006-2007, Ext JS, LLC.
20213 * Originally Released Under LGPL - original licence link has changed is not relivant.
20216 * <script type="text/javascript">
20219 * @class Roo.form.Checkbox
20220 * @extends Roo.form.Field
20221 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
20223 * Creates a new Checkbox
20224 * @param {Object} config Configuration options
20226 Roo.form.Checkbox = function(config){
20227 Roo.form.Checkbox.superclass.constructor.call(this, config);
20231 * Fires when the checkbox is checked or unchecked.
20232 * @param {Roo.form.Checkbox} this This checkbox
20233 * @param {Boolean} checked The new checked value
20239 Roo.extend(Roo.form.Checkbox, Roo.form.Field, {
20241 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
20243 focusClass : undefined,
20245 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
20247 fieldClass: "x-form-field",
20249 * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
20253 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
20254 * {tag: "input", type: "checkbox", autocomplete: "off"})
20256 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
20258 * @cfg {String} boxLabel The text that appears beside the checkbox
20262 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
20266 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20268 valueOff: '0', // value when not checked..
20270 actionMode : 'viewEl',
20273 itemCls : 'x-menu-check-item x-form-item',
20274 groupClass : 'x-menu-group-item',
20275 inputType : 'hidden',
20278 inSetChecked: false, // check that we are not calling self...
20280 inputElement: false, // real input element?
20281 basedOn: false, // ????
20283 isFormField: true, // not sure where this is needed!!!!
20285 onResize : function(){
20286 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
20287 if(!this.boxLabel){
20288 this.el.alignTo(this.wrap, 'c-c');
20292 initEvents : function(){
20293 Roo.form.Checkbox.superclass.initEvents.call(this);
20294 this.el.on("click", this.onClick, this);
20295 this.el.on("change", this.onClick, this);
20299 getResizeEl : function(){
20303 getPositionEl : function(){
20308 onRender : function(ct, position){
20309 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
20311 if(this.inputValue !== undefined){
20312 this.el.dom.value = this.inputValue;
20315 //this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
20316 this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
20317 var viewEl = this.wrap.createChild({
20318 tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
20319 this.viewEl = viewEl;
20320 this.wrap.on('click', this.onClick, this);
20322 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
20323 this.el.on('propertychange', this.setFromHidden, this); //ie
20328 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
20329 // viewEl.on('click', this.onClick, this);
20331 //if(this.checked){
20332 this.setChecked(this.checked);
20334 //this.checked = this.el.dom;
20340 initValue : Roo.emptyFn,
20343 * Returns the checked state of the checkbox.
20344 * @return {Boolean} True if checked, else false
20346 getValue : function(){
20348 return String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
20350 return this.valueOff;
20355 onClick : function(){
20356 if (this.disabled) {
20359 this.setChecked(!this.checked);
20361 //if(this.el.dom.checked != this.checked){
20362 // this.setValue(this.el.dom.checked);
20367 * Sets the checked state of the checkbox.
20368 * On is always based on a string comparison between inputValue and the param.
20369 * @param {Boolean/String} value - the value to set
20370 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
20372 setValue : function(v,suppressEvent){
20375 //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
20376 //if(this.el && this.el.dom){
20377 // this.el.dom.checked = this.checked;
20378 // this.el.dom.defaultChecked = this.checked;
20380 this.setChecked(String(v) === String(this.inputValue), suppressEvent);
20381 //this.fireEvent("check", this, this.checked);
20384 setChecked : function(state,suppressEvent)
20386 if (this.inSetChecked) {
20387 this.checked = state;
20393 this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked');
20395 this.checked = state;
20396 if(suppressEvent !== true){
20397 this.fireEvent('check', this, state);
20399 this.inSetChecked = true;
20400 this.el.dom.value = state ? this.inputValue : this.valueOff;
20401 this.inSetChecked = false;
20404 // handle setting of hidden value by some other method!!?!?
20405 setFromHidden: function()
20410 //console.log("SET FROM HIDDEN");
20411 //alert('setFrom hidden');
20412 this.setValue(this.el.dom.value);
20415 onDestroy : function()
20418 Roo.get(this.viewEl).remove();
20421 Roo.form.Checkbox.superclass.onDestroy.call(this);
20424 setBoxLabel : function(str)
20426 this.wrap.select('.x-form-cb-label', true).first().dom.innerHTML = str;
20431 * Ext JS Library 1.1.1
20432 * Copyright(c) 2006-2007, Ext JS, LLC.
20434 * Originally Released Under LGPL - original licence link has changed is not relivant.
20437 * <script type="text/javascript">
20441 * @class Roo.form.Radio
20442 * @extends Roo.form.Checkbox
20443 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
20444 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
20446 * Creates a new Radio
20447 * @param {Object} config Configuration options
20449 Roo.form.Radio = function(){
20450 Roo.form.Radio.superclass.constructor.apply(this, arguments);
20452 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
20453 inputType: 'radio',
20456 * If this radio is part of a group, it will return the selected value
20459 getGroupValue : function(){
20460 return this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
20464 onRender : function(ct, position){
20465 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
20467 if(this.inputValue !== undefined){
20468 this.el.dom.value = this.inputValue;
20471 this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
20472 //this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
20473 //var viewEl = this.wrap.createChild({
20474 // tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
20475 //this.viewEl = viewEl;
20476 //this.wrap.on('click', this.onClick, this);
20478 //this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
20479 //this.el.on('propertychange', this.setFromHidden, this); //ie
20484 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
20485 // viewEl.on('click', this.onClick, this);
20488 this.el.dom.checked = 'checked' ;
20494 });//<script type="text/javascript">
20497 * Based Ext JS Library 1.1.1
20498 * Copyright(c) 2006-2007, Ext JS, LLC.
20504 * @class Roo.HtmlEditorCore
20505 * @extends Roo.Component
20506 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
20508 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
20511 Roo.HtmlEditorCore = function(config){
20514 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
20519 * @event initialize
20520 * Fires when the editor is fully initialized (including the iframe)
20521 * @param {Roo.HtmlEditorCore} this
20526 * Fires when the editor is first receives the focus. Any insertion must wait
20527 * until after this event.
20528 * @param {Roo.HtmlEditorCore} this
20532 * @event beforesync
20533 * Fires before the textarea is updated with content from the editor iframe. Return false
20534 * to cancel the sync.
20535 * @param {Roo.HtmlEditorCore} this
20536 * @param {String} html
20540 * @event beforepush
20541 * Fires before the iframe editor is updated with content from the textarea. Return false
20542 * to cancel the push.
20543 * @param {Roo.HtmlEditorCore} this
20544 * @param {String} html
20549 * Fires when the textarea is updated with content from the editor iframe.
20550 * @param {Roo.HtmlEditorCore} this
20551 * @param {String} html
20556 * Fires when the iframe editor is updated with content from the textarea.
20557 * @param {Roo.HtmlEditorCore} this
20558 * @param {String} html
20563 * @event editorevent
20564 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
20565 * @param {Roo.HtmlEditorCore} this
20571 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
20573 // defaults : white / black...
20574 this.applyBlacklists();
20581 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
20585 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
20591 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
20596 * @cfg {Number} height (in pixels)
20600 * @cfg {Number} width (in pixels)
20605 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
20608 stylesheets: false,
20613 // private properties
20614 validationEvent : false,
20616 initialized : false,
20618 sourceEditMode : false,
20619 onFocus : Roo.emptyFn,
20621 hideMode:'offsets',
20625 // blacklist + whitelisted elements..
20632 * Protected method that will not generally be called directly. It
20633 * is called when the editor initializes the iframe with HTML contents. Override this method if you
20634 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
20636 getDocMarkup : function(){
20640 // inherit styels from page...??
20641 if (this.stylesheets === false) {
20643 Roo.get(document.head).select('style').each(function(node) {
20644 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
20647 Roo.get(document.head).select('link').each(function(node) {
20648 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
20651 } else if (!this.stylesheets.length) {
20653 st = '<style type="text/css">' +
20654 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
20657 st = '<style type="text/css">' +
20662 st += '<style type="text/css">' +
20663 'IMG { cursor: pointer } ' +
20666 var cls = 'roo-htmleditor-body';
20668 if(this.bodyCls.length){
20669 cls += ' ' + this.bodyCls;
20672 return '<html><head>' + st +
20673 //<style type="text/css">' +
20674 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
20676 ' </head><body contenteditable="true" data-enable-grammerly="true" class="' + cls + '"></body></html>';
20680 onRender : function(ct, position)
20683 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
20684 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
20687 this.el.dom.style.border = '0 none';
20688 this.el.dom.setAttribute('tabIndex', -1);
20689 this.el.addClass('x-hidden hide');
20693 if(Roo.isIE){ // fix IE 1px bogus margin
20694 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
20698 this.frameId = Roo.id();
20702 var iframe = this.owner.wrap.createChild({
20704 cls: 'form-control', // bootstrap..
20706 name: this.frameId,
20707 frameBorder : 'no',
20708 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
20713 this.iframe = iframe.dom;
20715 this.assignDocWin();
20717 this.doc.designMode = 'on';
20720 this.doc.write(this.getDocMarkup());
20724 var task = { // must defer to wait for browser to be ready
20726 //console.log("run task?" + this.doc.readyState);
20727 this.assignDocWin();
20728 if(this.doc.body || this.doc.readyState == 'complete'){
20730 this.doc.designMode="on";
20734 Roo.TaskMgr.stop(task);
20735 this.initEditor.defer(10, this);
20742 Roo.TaskMgr.start(task);
20747 onResize : function(w, h)
20749 Roo.log('resize: ' +w + ',' + h );
20750 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
20754 if(typeof w == 'number'){
20756 this.iframe.style.width = w + 'px';
20758 if(typeof h == 'number'){
20760 this.iframe.style.height = h + 'px';
20762 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
20769 * Toggles the editor between standard and source edit mode.
20770 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
20772 toggleSourceEdit : function(sourceEditMode){
20774 this.sourceEditMode = sourceEditMode === true;
20776 if(this.sourceEditMode){
20778 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
20781 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
20782 //this.iframe.className = '';
20785 //this.setSize(this.owner.wrap.getSize());
20786 //this.fireEvent('editmodechange', this, this.sourceEditMode);
20793 * Protected method that will not generally be called directly. If you need/want
20794 * custom HTML cleanup, this is the method you should override.
20795 * @param {String} html The HTML to be cleaned
20796 * return {String} The cleaned HTML
20798 cleanHtml : function(html){
20799 html = String(html);
20800 if(html.length > 5){
20801 if(Roo.isSafari){ // strip safari nonsense
20802 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
20805 if(html == ' '){
20812 * HTML Editor -> Textarea
20813 * Protected method that will not generally be called directly. Syncs the contents
20814 * of the editor iframe with the textarea.
20816 syncValue : function(){
20817 if(this.initialized){
20818 var bd = (this.doc.body || this.doc.documentElement);
20819 //this.cleanUpPaste(); -- this is done else where and causes havoc..
20820 var html = bd.innerHTML;
20822 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
20823 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
20825 html = '<div style="'+m[0]+'">' + html + '</div>';
20828 html = this.cleanHtml(html);
20829 // fix up the special chars.. normaly like back quotes in word...
20830 // however we do not want to do this with chinese..
20831 html = html.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g, function(match) {
20833 var cc = match.charCodeAt();
20835 // Get the character value, handling surrogate pairs
20836 if (match.length == 2) {
20837 // It's a surrogate pair, calculate the Unicode code point
20838 var high = match.charCodeAt(0) - 0xD800;
20839 var low = match.charCodeAt(1) - 0xDC00;
20840 cc = (high * 0x400) + low + 0x10000;
20842 (cc >= 0x4E00 && cc < 0xA000 ) ||
20843 (cc >= 0x3400 && cc < 0x4E00 ) ||
20844 (cc >= 0xf900 && cc < 0xfb00 )
20849 // No, use a numeric entity. Here we brazenly (and possibly mistakenly)
20850 return "&#" + cc + ";";
20857 if(this.owner.fireEvent('beforesync', this, html) !== false){
20858 this.el.dom.value = html;
20859 this.owner.fireEvent('sync', this, html);
20865 * Protected method that will not generally be called directly. Pushes the value of the textarea
20866 * into the iframe editor.
20868 pushValue : function(){
20869 if(this.initialized){
20870 var v = this.el.dom.value.trim();
20872 // if(v.length < 1){
20876 if(this.owner.fireEvent('beforepush', this, v) !== false){
20877 var d = (this.doc.body || this.doc.documentElement);
20879 this.cleanUpPaste();
20880 this.el.dom.value = d.innerHTML;
20881 this.owner.fireEvent('push', this, v);
20887 deferFocus : function(){
20888 this.focus.defer(10, this);
20892 focus : function(){
20893 if(this.win && !this.sourceEditMode){
20900 assignDocWin: function()
20902 var iframe = this.iframe;
20905 this.doc = iframe.contentWindow.document;
20906 this.win = iframe.contentWindow;
20908 // if (!Roo.get(this.frameId)) {
20911 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
20912 // this.win = Roo.get(this.frameId).dom.contentWindow;
20914 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
20918 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
20919 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
20924 initEditor : function(){
20925 //console.log("INIT EDITOR");
20926 this.assignDocWin();
20930 this.doc.designMode="on";
20932 this.doc.write(this.getDocMarkup());
20935 var dbody = (this.doc.body || this.doc.documentElement);
20936 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
20937 // this copies styles from the containing element into thsi one..
20938 // not sure why we need all of this..
20939 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
20941 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
20942 //ss['background-attachment'] = 'fixed'; // w3c
20943 dbody.bgProperties = 'fixed'; // ie
20944 //Roo.DomHelper.applyStyles(dbody, ss);
20945 Roo.EventManager.on(this.doc, {
20946 //'mousedown': this.onEditorEvent,
20947 'mouseup': this.onEditorEvent,
20948 'dblclick': this.onEditorEvent,
20949 'click': this.onEditorEvent,
20950 'keyup': this.onEditorEvent,
20955 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
20957 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
20958 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
20960 this.initialized = true;
20962 this.owner.fireEvent('initialize', this);
20967 onDestroy : function(){
20973 //for (var i =0; i < this.toolbars.length;i++) {
20974 // // fixme - ask toolbars for heights?
20975 // this.toolbars[i].onDestroy();
20978 //this.wrap.dom.innerHTML = '';
20979 //this.wrap.remove();
20984 onFirstFocus : function(){
20986 this.assignDocWin();
20989 this.activated = true;
20992 if(Roo.isGecko){ // prevent silly gecko errors
20994 var s = this.win.getSelection();
20995 if(!s.focusNode || s.focusNode.nodeType != 3){
20996 var r = s.getRangeAt(0);
20997 r.selectNodeContents((this.doc.body || this.doc.documentElement));
21002 this.execCmd('useCSS', true);
21003 this.execCmd('styleWithCSS', false);
21006 this.owner.fireEvent('activate', this);
21010 adjustFont: function(btn){
21011 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
21012 //if(Roo.isSafari){ // safari
21015 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
21016 if(Roo.isSafari){ // safari
21017 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
21018 v = (v < 10) ? 10 : v;
21019 v = (v > 48) ? 48 : v;
21020 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
21025 v = Math.max(1, v+adjust);
21027 this.execCmd('FontSize', v );
21030 onEditorEvent : function(e)
21032 this.owner.fireEvent('editorevent', this, e);
21033 // this.updateToolbar();
21034 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
21037 insertTag : function(tg)
21039 // could be a bit smarter... -> wrap the current selected tRoo..
21040 if (tg.toLowerCase() == 'span' ||
21041 tg.toLowerCase() == 'code' ||
21042 tg.toLowerCase() == 'sup' ||
21043 tg.toLowerCase() == 'sub'
21046 range = this.createRange(this.getSelection());
21047 var wrappingNode = this.doc.createElement(tg.toLowerCase());
21048 wrappingNode.appendChild(range.extractContents());
21049 range.insertNode(wrappingNode);
21056 this.execCmd("formatblock", tg);
21060 insertText : function(txt)
21064 var range = this.createRange();
21065 range.deleteContents();
21066 //alert(Sender.getAttribute('label'));
21068 range.insertNode(this.doc.createTextNode(txt));
21074 * Executes a Midas editor command on the editor document and performs necessary focus and
21075 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
21076 * @param {String} cmd The Midas command
21077 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21079 relayCmd : function(cmd, value){
21081 this.execCmd(cmd, value);
21082 this.owner.fireEvent('editorevent', this);
21083 //this.updateToolbar();
21084 this.owner.deferFocus();
21088 * Executes a Midas editor command directly on the editor document.
21089 * For visual commands, you should use {@link #relayCmd} instead.
21090 * <b>This should only be called after the editor is initialized.</b>
21091 * @param {String} cmd The Midas command
21092 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21094 execCmd : function(cmd, value){
21095 this.doc.execCommand(cmd, false, value === undefined ? null : value);
21102 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
21104 * @param {String} text | dom node..
21106 insertAtCursor : function(text)
21109 if(!this.activated){
21115 var r = this.doc.selection.createRange();
21126 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
21130 // from jquery ui (MIT licenced)
21132 var win = this.win;
21134 if (win.getSelection && win.getSelection().getRangeAt) {
21135 range = win.getSelection().getRangeAt(0);
21136 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
21137 range.insertNode(node);
21138 } else if (win.document.selection && win.document.selection.createRange) {
21139 // no firefox support
21140 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21141 win.document.selection.createRange().pasteHTML(txt);
21143 // no firefox support
21144 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21145 this.execCmd('InsertHTML', txt);
21154 mozKeyPress : function(e){
21156 var c = e.getCharCode(), cmd;
21159 c = String.fromCharCode(c).toLowerCase();
21173 this.cleanUpPaste.defer(100, this);
21181 e.preventDefault();
21189 fixKeys : function(){ // load time branching for fastest keydown performance
21191 return function(e){
21192 var k = e.getKey(), r;
21195 r = this.doc.selection.createRange();
21198 r.pasteHTML('    ');
21205 r = this.doc.selection.createRange();
21207 var target = r.parentElement();
21208 if(!target || target.tagName.toLowerCase() != 'li'){
21210 r.pasteHTML('<br />');
21216 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21217 this.cleanUpPaste.defer(100, this);
21223 }else if(Roo.isOpera){
21224 return function(e){
21225 var k = e.getKey();
21229 this.execCmd('InsertHTML','    ');
21232 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21233 this.cleanUpPaste.defer(100, this);
21238 }else if(Roo.isSafari){
21239 return function(e){
21240 var k = e.getKey();
21244 this.execCmd('InsertText','\t');
21248 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21249 this.cleanUpPaste.defer(100, this);
21257 getAllAncestors: function()
21259 var p = this.getSelectedNode();
21262 a.push(p); // push blank onto stack..
21263 p = this.getParentElement();
21267 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
21271 a.push(this.doc.body);
21275 lastSelNode : false,
21278 getSelection : function()
21280 this.assignDocWin();
21281 return Roo.isIE ? this.doc.selection : this.win.getSelection();
21284 getSelectedNode: function()
21286 // this may only work on Gecko!!!
21288 // should we cache this!!!!
21293 var range = this.createRange(this.getSelection()).cloneRange();
21296 var parent = range.parentElement();
21298 var testRange = range.duplicate();
21299 testRange.moveToElementText(parent);
21300 if (testRange.inRange(range)) {
21303 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
21306 parent = parent.parentElement;
21311 // is ancestor a text element.
21312 var ac = range.commonAncestorContainer;
21313 if (ac.nodeType == 3) {
21314 ac = ac.parentNode;
21317 var ar = ac.childNodes;
21320 var other_nodes = [];
21321 var has_other_nodes = false;
21322 for (var i=0;i<ar.length;i++) {
21323 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
21326 // fullly contained node.
21328 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
21333 // probably selected..
21334 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
21335 other_nodes.push(ar[i]);
21339 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
21344 has_other_nodes = true;
21346 if (!nodes.length && other_nodes.length) {
21347 nodes= other_nodes;
21349 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
21355 createRange: function(sel)
21357 // this has strange effects when using with
21358 // top toolbar - not sure if it's a great idea.
21359 //this.editor.contentWindow.focus();
21360 if (typeof sel != "undefined") {
21362 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
21364 return this.doc.createRange();
21367 return this.doc.createRange();
21370 getParentElement: function()
21373 this.assignDocWin();
21374 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
21376 var range = this.createRange(sel);
21379 var p = range.commonAncestorContainer;
21380 while (p.nodeType == 3) { // text node
21391 * Range intersection.. the hard stuff...
21395 * [ -- selected range --- ]
21399 * if end is before start or hits it. fail.
21400 * if start is after end or hits it fail.
21402 * if either hits (but other is outside. - then it's not
21408 // @see http://www.thismuchiknow.co.uk/?p=64.
21409 rangeIntersectsNode : function(range, node)
21411 var nodeRange = node.ownerDocument.createRange();
21413 nodeRange.selectNode(node);
21415 nodeRange.selectNodeContents(node);
21418 var rangeStartRange = range.cloneRange();
21419 rangeStartRange.collapse(true);
21421 var rangeEndRange = range.cloneRange();
21422 rangeEndRange.collapse(false);
21424 var nodeStartRange = nodeRange.cloneRange();
21425 nodeStartRange.collapse(true);
21427 var nodeEndRange = nodeRange.cloneRange();
21428 nodeEndRange.collapse(false);
21430 return rangeStartRange.compareBoundaryPoints(
21431 Range.START_TO_START, nodeEndRange) == -1 &&
21432 rangeEndRange.compareBoundaryPoints(
21433 Range.START_TO_START, nodeStartRange) == 1;
21437 rangeCompareNode : function(range, node)
21439 var nodeRange = node.ownerDocument.createRange();
21441 nodeRange.selectNode(node);
21443 nodeRange.selectNodeContents(node);
21447 range.collapse(true);
21449 nodeRange.collapse(true);
21451 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
21452 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
21454 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
21456 var nodeIsBefore = ss == 1;
21457 var nodeIsAfter = ee == -1;
21459 if (nodeIsBefore && nodeIsAfter) {
21462 if (!nodeIsBefore && nodeIsAfter) {
21463 return 1; //right trailed.
21466 if (nodeIsBefore && !nodeIsAfter) {
21467 return 2; // left trailed.
21473 // private? - in a new class?
21474 cleanUpPaste : function()
21476 // cleans up the whole document..
21477 Roo.log('cleanuppaste');
21479 this.cleanUpChildren(this.doc.body);
21480 var clean = this.cleanWordChars(this.doc.body.innerHTML);
21481 if (clean != this.doc.body.innerHTML) {
21482 this.doc.body.innerHTML = clean;
21487 cleanWordChars : function(input) {// change the chars to hex code
21488 var he = Roo.HtmlEditorCore;
21490 var output = input;
21491 Roo.each(he.swapCodes, function(sw) {
21492 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
21494 output = output.replace(swapper, sw[1]);
21501 cleanUpChildren : function (n)
21503 if (!n.childNodes.length) {
21506 for (var i = n.childNodes.length-1; i > -1 ; i--) {
21507 this.cleanUpChild(n.childNodes[i]);
21514 cleanUpChild : function (node)
21517 //console.log(node);
21518 if (node.nodeName == "#text") {
21519 // clean up silly Windows -- stuff?
21522 if (node.nodeName == "#comment") {
21523 node.parentNode.removeChild(node);
21524 // clean up silly Windows -- stuff?
21527 var lcname = node.tagName.toLowerCase();
21528 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
21529 // whitelist of tags..
21531 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
21533 node.parentNode.removeChild(node);
21538 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
21540 // spans with no attributes - just remove them..
21541 if ((!node.attributes || !node.attributes.length) && lcname == 'span') {
21542 remove_keep_children = true;
21545 // remove <a name=....> as rendering on yahoo mailer is borked with this.
21546 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
21548 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
21549 // remove_keep_children = true;
21552 if (remove_keep_children) {
21553 this.cleanUpChildren(node);
21554 // inserts everything just before this node...
21555 while (node.childNodes.length) {
21556 var cn = node.childNodes[0];
21557 node.removeChild(cn);
21558 node.parentNode.insertBefore(cn, node);
21560 node.parentNode.removeChild(node);
21564 if (!node.attributes || !node.attributes.length) {
21569 this.cleanUpChildren(node);
21573 function cleanAttr(n,v)
21576 if (v.match(/^\./) || v.match(/^\//)) {
21579 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) {
21582 if (v.match(/^#/)) {
21585 if (v.match(/^\{/)) { // allow template editing.
21588 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
21589 node.removeAttribute(n);
21593 var cwhite = this.cwhite;
21594 var cblack = this.cblack;
21596 function cleanStyle(n,v)
21598 if (v.match(/expression/)) { //XSS?? should we even bother..
21599 node.removeAttribute(n);
21603 var parts = v.split(/;/);
21606 Roo.each(parts, function(p) {
21607 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
21611 var l = p.split(':').shift().replace(/\s+/g,'');
21612 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
21614 if ( cwhite.length && cblack.indexOf(l) > -1) {
21615 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
21616 //node.removeAttribute(n);
21620 // only allow 'c whitelisted system attributes'
21621 if ( cwhite.length && cwhite.indexOf(l) < 0) {
21622 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
21623 //node.removeAttribute(n);
21633 if (clean.length) {
21634 node.setAttribute(n, clean.join(';'));
21636 node.removeAttribute(n);
21642 for (var i = node.attributes.length-1; i > -1 ; i--) {
21643 var a = node.attributes[i];
21646 if (a.name.toLowerCase().substr(0,2)=='on') {
21647 node.removeAttribute(a.name);
21650 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
21651 node.removeAttribute(a.name);
21654 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
21655 cleanAttr(a.name,a.value); // fixme..
21658 if (a.name == 'style') {
21659 cleanStyle(a.name,a.value);
21662 /// clean up MS crap..
21663 // tecnically this should be a list of valid class'es..
21666 if (a.name == 'class') {
21667 if (a.value.match(/^Mso/)) {
21668 node.removeAttribute('class');
21671 if (a.value.match(/^body$/)) {
21672 node.removeAttribute('class');
21683 this.cleanUpChildren(node);
21689 * Clean up MS wordisms...
21691 cleanWord : function(node)
21694 this.cleanWord(this.doc.body);
21699 node.nodeName == 'SPAN' &&
21700 !node.hasAttributes() &&
21701 node.childNodes.length == 1 &&
21702 node.firstChild.nodeName == "#text"
21704 var textNode = node.firstChild;
21705 node.removeChild(textNode);
21706 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
21707 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" "), node);
21709 node.parentNode.insertBefore(textNode, node);
21710 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
21711 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" ") , node);
21713 node.parentNode.removeChild(node);
21716 if (node.nodeName == "#text") {
21717 // clean up silly Windows -- stuff?
21720 if (node.nodeName == "#comment") {
21721 node.parentNode.removeChild(node);
21722 // clean up silly Windows -- stuff?
21726 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
21727 node.parentNode.removeChild(node);
21730 //Roo.log(node.tagName);
21731 // remove - but keep children..
21732 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)) {
21733 //Roo.log('-- removed');
21734 while (node.childNodes.length) {
21735 var cn = node.childNodes[0];
21736 node.removeChild(cn);
21737 node.parentNode.insertBefore(cn, node);
21738 // move node to parent - and clean it..
21739 this.cleanWord(cn);
21741 node.parentNode.removeChild(node);
21742 /// no need to iterate chidlren = it's got none..
21743 //this.iterateChildren(node, this.cleanWord);
21747 if (node.className.length) {
21749 var cn = node.className.split(/\W+/);
21751 Roo.each(cn, function(cls) {
21752 if (cls.match(/Mso[a-zA-Z]+/)) {
21757 node.className = cna.length ? cna.join(' ') : '';
21759 node.removeAttribute("class");
21763 if (node.hasAttribute("lang")) {
21764 node.removeAttribute("lang");
21767 if (node.hasAttribute("style")) {
21769 var styles = node.getAttribute("style").split(";");
21771 Roo.each(styles, function(s) {
21772 if (!s.match(/:/)) {
21775 var kv = s.split(":");
21776 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
21779 // what ever is left... we allow.
21782 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
21783 if (!nstyle.length) {
21784 node.removeAttribute('style');
21787 this.iterateChildren(node, this.cleanWord);
21793 * iterateChildren of a Node, calling fn each time, using this as the scole..
21794 * @param {DomNode} node node to iterate children of.
21795 * @param {Function} fn method of this class to call on each item.
21797 iterateChildren : function(node, fn)
21799 if (!node.childNodes.length) {
21802 for (var i = node.childNodes.length-1; i > -1 ; i--) {
21803 fn.call(this, node.childNodes[i])
21809 * cleanTableWidths.
21811 * Quite often pasting from word etc.. results in tables with column and widths.
21812 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
21815 cleanTableWidths : function(node)
21820 this.cleanTableWidths(this.doc.body);
21825 if (node.nodeName == "#text" || node.nodeName == "#comment") {
21828 Roo.log(node.tagName);
21829 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
21830 this.iterateChildren(node, this.cleanTableWidths);
21833 if (node.hasAttribute('width')) {
21834 node.removeAttribute('width');
21838 if (node.hasAttribute("style")) {
21841 var styles = node.getAttribute("style").split(";");
21843 Roo.each(styles, function(s) {
21844 if (!s.match(/:/)) {
21847 var kv = s.split(":");
21848 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
21851 // what ever is left... we allow.
21854 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
21855 if (!nstyle.length) {
21856 node.removeAttribute('style');
21860 this.iterateChildren(node, this.cleanTableWidths);
21868 domToHTML : function(currentElement, depth, nopadtext) {
21870 depth = depth || 0;
21871 nopadtext = nopadtext || false;
21873 if (!currentElement) {
21874 return this.domToHTML(this.doc.body);
21877 //Roo.log(currentElement);
21879 var allText = false;
21880 var nodeName = currentElement.nodeName;
21881 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
21883 if (nodeName == '#text') {
21885 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
21890 if (nodeName != 'BODY') {
21893 // Prints the node tagName, such as <A>, <IMG>, etc
21896 for(i = 0; i < currentElement.attributes.length;i++) {
21898 var aname = currentElement.attributes.item(i).name;
21899 if (!currentElement.attributes.item(i).value.length) {
21902 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
21905 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
21914 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
21917 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
21922 // Traverse the tree
21924 var currentElementChild = currentElement.childNodes.item(i);
21925 var allText = true;
21926 var innerHTML = '';
21928 while (currentElementChild) {
21929 // Formatting code (indent the tree so it looks nice on the screen)
21930 var nopad = nopadtext;
21931 if (lastnode == 'SPAN') {
21935 if (currentElementChild.nodeName == '#text') {
21936 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
21937 toadd = nopadtext ? toadd : toadd.trim();
21938 if (!nopad && toadd.length > 80) {
21939 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
21941 innerHTML += toadd;
21944 currentElementChild = currentElement.childNodes.item(i);
21950 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
21952 // Recursively traverse the tree structure of the child node
21953 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
21954 lastnode = currentElementChild.nodeName;
21956 currentElementChild=currentElement.childNodes.item(i);
21962 // The remaining code is mostly for formatting the tree
21963 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
21968 ret+= "</"+tagName+">";
21974 applyBlacklists : function()
21976 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
21977 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
21981 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
21982 if (b.indexOf(tag) > -1) {
21985 this.white.push(tag);
21989 Roo.each(w, function(tag) {
21990 if (b.indexOf(tag) > -1) {
21993 if (this.white.indexOf(tag) > -1) {
21996 this.white.push(tag);
22001 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
22002 if (w.indexOf(tag) > -1) {
22005 this.black.push(tag);
22009 Roo.each(b, function(tag) {
22010 if (w.indexOf(tag) > -1) {
22013 if (this.black.indexOf(tag) > -1) {
22016 this.black.push(tag);
22021 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
22022 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
22026 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
22027 if (b.indexOf(tag) > -1) {
22030 this.cwhite.push(tag);
22034 Roo.each(w, function(tag) {
22035 if (b.indexOf(tag) > -1) {
22038 if (this.cwhite.indexOf(tag) > -1) {
22041 this.cwhite.push(tag);
22046 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
22047 if (w.indexOf(tag) > -1) {
22050 this.cblack.push(tag);
22054 Roo.each(b, function(tag) {
22055 if (w.indexOf(tag) > -1) {
22058 if (this.cblack.indexOf(tag) > -1) {
22061 this.cblack.push(tag);
22066 setStylesheets : function(stylesheets)
22068 if(typeof(stylesheets) == 'string'){
22069 Roo.get(this.iframe.contentDocument.head).createChild({
22071 rel : 'stylesheet',
22080 Roo.each(stylesheets, function(s) {
22085 Roo.get(_this.iframe.contentDocument.head).createChild({
22087 rel : 'stylesheet',
22096 removeStylesheets : function()
22100 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
22105 setStyle : function(style)
22107 Roo.get(this.iframe.contentDocument.head).createChild({
22116 // hide stuff that is not compatible
22130 * @event specialkey
22134 * @cfg {String} fieldClass @hide
22137 * @cfg {String} focusClass @hide
22140 * @cfg {String} autoCreate @hide
22143 * @cfg {String} inputType @hide
22146 * @cfg {String} invalidClass @hide
22149 * @cfg {String} invalidText @hide
22152 * @cfg {String} msgFx @hide
22155 * @cfg {String} validateOnBlur @hide
22159 Roo.HtmlEditorCore.white = [
22160 'area', 'br', 'img', 'input', 'hr', 'wbr',
22162 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
22163 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
22164 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
22165 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
22166 'table', 'ul', 'xmp',
22168 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
22171 'dir', 'menu', 'ol', 'ul', 'dl',
22177 Roo.HtmlEditorCore.black = [
22178 // 'embed', 'object', // enable - backend responsiblity to clean thiese
22180 'base', 'basefont', 'bgsound', 'blink', 'body',
22181 'frame', 'frameset', 'head', 'html', 'ilayer',
22182 'iframe', 'layer', 'link', 'meta', 'object',
22183 'script', 'style' ,'title', 'xml' // clean later..
22185 Roo.HtmlEditorCore.clean = [
22186 'script', 'style', 'title', 'xml'
22188 Roo.HtmlEditorCore.remove = [
22193 Roo.HtmlEditorCore.ablack = [
22197 Roo.HtmlEditorCore.aclean = [
22198 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
22202 Roo.HtmlEditorCore.pwhite= [
22203 'http', 'https', 'mailto'
22206 // white listed style attributes.
22207 Roo.HtmlEditorCore.cwhite= [
22208 // 'text-align', /// default is to allow most things..
22214 // black listed style attributes.
22215 Roo.HtmlEditorCore.cblack= [
22216 // 'font-size' -- this can be set by the project
22220 Roo.HtmlEditorCore.swapCodes =[
22231 //<script type="text/javascript">
22234 * Ext JS Library 1.1.1
22235 * Copyright(c) 2006-2007, Ext JS, LLC.
22241 Roo.form.HtmlEditor = function(config){
22245 Roo.form.HtmlEditor.superclass.constructor.call(this, config);
22247 if (!this.toolbars) {
22248 this.toolbars = [];
22250 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
22256 * @class Roo.form.HtmlEditor
22257 * @extends Roo.form.Field
22258 * Provides a lightweight HTML Editor component.
22260 * This has been tested on Fireforx / Chrome.. IE may not be so great..
22262 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
22263 * supported by this editor.</b><br/><br/>
22264 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
22265 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
22267 Roo.extend(Roo.form.HtmlEditor, Roo.form.Field, {
22269 * @cfg {Boolean} clearUp
22273 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
22278 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
22283 * @cfg {Number} height (in pixels)
22287 * @cfg {Number} width (in pixels)
22292 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
22295 stylesheets: false,
22299 * @cfg {Array} blacklist of css styles style attributes (blacklist overrides whitelist)
22304 * @cfg {Array} whitelist of css styles style attributes (blacklist overrides whitelist)
22310 * @cfg {Array} blacklist of html tags - in addition to standard blacklist.
22315 * @cfg {Array} whitelist of html tags - in addition to statndard whitelist
22323 // private properties
22324 validationEvent : false,
22326 initialized : false,
22329 onFocus : Roo.emptyFn,
22331 hideMode:'offsets',
22333 actionMode : 'container', // defaults to hiding it...
22335 defaultAutoCreate : { // modified by initCompnoent..
22337 style:"width:500px;height:300px;",
22338 autocomplete: "new-password"
22342 initComponent : function(){
22345 * @event initialize
22346 * Fires when the editor is fully initialized (including the iframe)
22347 * @param {HtmlEditor} this
22352 * Fires when the editor is first receives the focus. Any insertion must wait
22353 * until after this event.
22354 * @param {HtmlEditor} this
22358 * @event beforesync
22359 * Fires before the textarea is updated with content from the editor iframe. Return false
22360 * to cancel the sync.
22361 * @param {HtmlEditor} this
22362 * @param {String} html
22366 * @event beforepush
22367 * Fires before the iframe editor is updated with content from the textarea. Return false
22368 * to cancel the push.
22369 * @param {HtmlEditor} this
22370 * @param {String} html
22375 * Fires when the textarea is updated with content from the editor iframe.
22376 * @param {HtmlEditor} this
22377 * @param {String} html
22382 * Fires when the iframe editor is updated with content from the textarea.
22383 * @param {HtmlEditor} this
22384 * @param {String} html
22388 * @event editmodechange
22389 * Fires when the editor switches edit modes
22390 * @param {HtmlEditor} this
22391 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
22393 editmodechange: true,
22395 * @event editorevent
22396 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
22397 * @param {HtmlEditor} this
22401 * @event firstfocus
22402 * Fires when on first focus - needed by toolbars..
22403 * @param {HtmlEditor} this
22408 * Auto save the htmlEditor value as a file into Events
22409 * @param {HtmlEditor} this
22413 * @event savedpreview
22414 * preview the saved version of htmlEditor
22415 * @param {HtmlEditor} this
22417 savedpreview: true,
22420 * @event stylesheetsclick
22421 * Fires when press the Sytlesheets button
22422 * @param {Roo.HtmlEditorCore} this
22424 stylesheetsclick: true
22426 this.defaultAutoCreate = {
22428 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
22429 autocomplete: "new-password"
22434 * Protected method that will not generally be called directly. It
22435 * is called when the editor creates its toolbar. Override this method if you need to
22436 * add custom toolbar buttons.
22437 * @param {HtmlEditor} editor
22439 createToolbar : function(editor){
22440 Roo.log("create toolbars");
22441 if (!editor.toolbars || !editor.toolbars.length) {
22442 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
22445 for (var i =0 ; i < editor.toolbars.length;i++) {
22446 editor.toolbars[i] = Roo.factory(
22447 typeof(editor.toolbars[i]) == 'string' ?
22448 { xtype: editor.toolbars[i]} : editor.toolbars[i],
22449 Roo.form.HtmlEditor);
22450 editor.toolbars[i].init(editor);
22458 onRender : function(ct, position)
22461 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
22463 this.wrap = this.el.wrap({
22464 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
22467 this.editorcore.onRender(ct, position);
22469 if (this.resizable) {
22470 this.resizeEl = new Roo.Resizable(this.wrap, {
22474 minHeight : this.height,
22475 height: this.height,
22476 handles : this.resizable,
22479 resize : function(r, w, h) {
22480 _t.onResize(w,h); // -something
22486 this.createToolbar(this);
22490 this.setSize(this.wrap.getSize());
22492 if (this.resizeEl) {
22493 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
22494 // should trigger onReize..
22497 this.keyNav = new Roo.KeyNav(this.el, {
22499 "tab" : function(e){
22500 e.preventDefault();
22502 var value = this.getValue();
22504 var start = this.el.dom.selectionStart;
22505 var end = this.el.dom.selectionEnd;
22509 this.setValue(value.substring(0, start) + "\t" + value.substring(end));
22510 this.el.dom.setSelectionRange(end + 1, end + 1);
22514 var f = value.substring(0, start).split("\t");
22516 if(f.pop().length != 0){
22520 this.setValue(f.join("\t") + value.substring(end));
22521 this.el.dom.setSelectionRange(start - 1, start - 1);
22525 "home" : function(e){
22526 e.preventDefault();
22528 var curr = this.el.dom.selectionStart;
22529 var lines = this.getValue().split("\n");
22536 this.el.dom.setSelectionRange(0, 0);
22542 for (var i = 0; i < lines.length;i++) {
22543 pos += lines[i].length;
22553 pos -= lines[i].length;
22559 this.el.dom.setSelectionRange(pos, pos);
22563 this.el.dom.selectionStart = pos;
22564 this.el.dom.selectionEnd = curr;
22567 "end" : function(e){
22568 e.preventDefault();
22570 var curr = this.el.dom.selectionStart;
22571 var lines = this.getValue().split("\n");
22578 this.el.dom.setSelectionRange(this.getValue().length, this.getValue().length);
22584 for (var i = 0; i < lines.length;i++) {
22586 pos += lines[i].length;
22600 this.el.dom.setSelectionRange(pos, pos);
22604 this.el.dom.selectionStart = curr;
22605 this.el.dom.selectionEnd = pos;
22610 doRelay : function(foo, bar, hname){
22611 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
22617 // if(this.autosave && this.w){
22618 // this.autoSaveFn = setInterval(this.autosave, 1000);
22623 onResize : function(w, h)
22625 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
22630 if(typeof w == 'number'){
22631 var aw = w - this.wrap.getFrameWidth('lr');
22632 this.el.setWidth(this.adjustWidth('textarea', aw));
22635 if(typeof h == 'number'){
22637 for (var i =0; i < this.toolbars.length;i++) {
22638 // fixme - ask toolbars for heights?
22639 tbh += this.toolbars[i].tb.el.getHeight();
22640 if (this.toolbars[i].footer) {
22641 tbh += this.toolbars[i].footer.el.getHeight();
22648 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
22649 ah -= 5; // knock a few pixes off for look..
22651 this.el.setHeight(this.adjustWidth('textarea', ah));
22655 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
22656 this.editorcore.onResize(ew,eh);
22661 * Toggles the editor between standard and source edit mode.
22662 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
22664 toggleSourceEdit : function(sourceEditMode)
22666 this.editorcore.toggleSourceEdit(sourceEditMode);
22668 if(this.editorcore.sourceEditMode){
22669 Roo.log('editor - showing textarea');
22672 // Roo.log(this.syncValue());
22673 this.editorcore.syncValue();
22674 this.el.removeClass('x-hidden');
22675 this.el.dom.removeAttribute('tabIndex');
22678 for (var i = 0; i < this.toolbars.length; i++) {
22679 if(this.toolbars[i] instanceof Roo.form.HtmlEditor.ToolbarContext){
22680 this.toolbars[i].tb.hide();
22681 this.toolbars[i].footer.hide();
22686 Roo.log('editor - hiding textarea');
22688 // Roo.log(this.pushValue());
22689 this.editorcore.pushValue();
22691 this.el.addClass('x-hidden');
22692 this.el.dom.setAttribute('tabIndex', -1);
22694 for (var i = 0; i < this.toolbars.length; i++) {
22695 if(this.toolbars[i] instanceof Roo.form.HtmlEditor.ToolbarContext){
22696 this.toolbars[i].tb.show();
22697 this.toolbars[i].footer.show();
22701 //this.deferFocus();
22704 this.setSize(this.wrap.getSize());
22705 this.onResize(this.wrap.getSize().width, this.wrap.getSize().height);
22707 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
22710 // private (for BoxComponent)
22711 adjustSize : Roo.BoxComponent.prototype.adjustSize,
22713 // private (for BoxComponent)
22714 getResizeEl : function(){
22718 // private (for BoxComponent)
22719 getPositionEl : function(){
22724 initEvents : function(){
22725 this.originalValue = this.getValue();
22729 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
22732 markInvalid : Roo.emptyFn,
22734 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
22737 clearInvalid : Roo.emptyFn,
22739 setValue : function(v){
22740 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
22741 this.editorcore.pushValue();
22746 deferFocus : function(){
22747 this.focus.defer(10, this);
22751 focus : function(){
22752 this.editorcore.focus();
22758 onDestroy : function(){
22764 for (var i =0; i < this.toolbars.length;i++) {
22765 // fixme - ask toolbars for heights?
22766 this.toolbars[i].onDestroy();
22769 this.wrap.dom.innerHTML = '';
22770 this.wrap.remove();
22775 onFirstFocus : function(){
22776 //Roo.log("onFirstFocus");
22777 this.editorcore.onFirstFocus();
22778 for (var i =0; i < this.toolbars.length;i++) {
22779 this.toolbars[i].onFirstFocus();
22785 syncValue : function()
22787 this.editorcore.syncValue();
22790 pushValue : function()
22792 this.editorcore.pushValue();
22795 setStylesheets : function(stylesheets)
22797 this.editorcore.setStylesheets(stylesheets);
22800 removeStylesheets : function()
22802 this.editorcore.removeStylesheets();
22806 // hide stuff that is not compatible
22820 * @event specialkey
22824 * @cfg {String} fieldClass @hide
22827 * @cfg {String} focusClass @hide
22830 * @cfg {String} autoCreate @hide
22833 * @cfg {String} inputType @hide
22836 * @cfg {String} invalidClass @hide
22839 * @cfg {String} invalidText @hide
22842 * @cfg {String} msgFx @hide
22845 * @cfg {String} validateOnBlur @hide
22849 // <script type="text/javascript">
22852 * Ext JS Library 1.1.1
22853 * Copyright(c) 2006-2007, Ext JS, LLC.
22859 * @class Roo.form.HtmlEditorToolbar1
22864 new Roo.form.HtmlEditor({
22867 new Roo.form.HtmlEditorToolbar1({
22868 disable : { fonts: 1 , format: 1, ..., ... , ...],
22874 * @cfg {Object} disable List of elements to disable..
22875 * @cfg {Array} btns List of additional buttons.
22879 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
22882 Roo.form.HtmlEditor.ToolbarStandard = function(config)
22885 Roo.apply(this, config);
22887 // default disabled, based on 'good practice'..
22888 this.disable = this.disable || {};
22889 Roo.applyIf(this.disable, {
22892 specialElements : true
22896 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
22897 // dont call parent... till later.
22900 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
22907 editorcore : false,
22909 * @cfg {Object} disable List of toolbar elements to disable
22916 * @cfg {String} createLinkText The default text for the create link prompt
22918 createLinkText : 'Please enter the URL for the link:',
22920 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
22922 defaultLinkValue : 'http:/'+'/',
22926 * @cfg {Array} fontFamilies An array of available font families
22944 // "á" , ?? a acute?
22949 "°" // , // degrees
22951 // "é" , // e ecute
22952 // "ú" , // u ecute?
22955 specialElements : [
22957 text: "Insert Table",
22960 ihtml : '<table><tr><td>Cell</td></tr></table>'
22964 text: "Insert Image",
22967 ihtml : '<img src="about:blank"/>'
22976 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
22977 "input:submit", "input:button", "select", "textarea", "label" ],
22980 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
22982 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"],
22991 * @cfg {String} defaultFont default font to use.
22993 defaultFont: 'tahoma',
22995 fontSelect : false,
22998 formatCombo : false,
23000 init : function(editor)
23002 this.editor = editor;
23003 this.editorcore = editor.editorcore ? editor.editorcore : editor;
23004 var editorcore = this.editorcore;
23008 var fid = editorcore.frameId;
23010 function btn(id, toggle, handler){
23011 var xid = fid + '-'+ id ;
23015 cls : 'x-btn-icon x-edit-'+id,
23016 enableToggle:toggle !== false,
23017 scope: _t, // was editor...
23018 handler:handler||_t.relayBtnCmd,
23019 clickEvent:'mousedown',
23020 tooltip: etb.buttonTips[id] || undefined, ///tips ???
23027 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
23029 // stop form submits
23030 tb.el.on('click', function(e){
23031 e.preventDefault(); // what does this do?
23034 if(!this.disable.font) { // && !Roo.isSafari){
23035 /* why no safari for fonts
23036 editor.fontSelect = tb.el.createChild({
23039 cls:'x-font-select',
23040 html: this.createFontOptions()
23043 editor.fontSelect.on('change', function(){
23044 var font = editor.fontSelect.dom.value;
23045 editor.relayCmd('fontname', font);
23046 editor.deferFocus();
23050 editor.fontSelect.dom,
23056 if(!this.disable.formats){
23057 this.formatCombo = new Roo.form.ComboBox({
23058 store: new Roo.data.SimpleStore({
23061 data : this.formats // from states.js
23065 //autoCreate : {tag: "div", size: "20"},
23066 displayField:'tag',
23070 triggerAction: 'all',
23071 emptyText:'Add tag',
23072 selectOnFocus:true,
23075 'select': function(c, r, i) {
23076 editorcore.insertTag(r.get('tag'));
23082 tb.addField(this.formatCombo);
23086 if(!this.disable.format){
23091 btn('strikethrough')
23094 if(!this.disable.fontSize){
23099 btn('increasefontsize', false, editorcore.adjustFont),
23100 btn('decreasefontsize', false, editorcore.adjustFont)
23105 if(!this.disable.colors){
23108 id:editorcore.frameId +'-forecolor',
23109 cls:'x-btn-icon x-edit-forecolor',
23110 clickEvent:'mousedown',
23111 tooltip: this.buttonTips['forecolor'] || undefined,
23113 menu : new Roo.menu.ColorMenu({
23114 allowReselect: true,
23115 focus: Roo.emptyFn,
23118 selectHandler: function(cp, color){
23119 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
23120 editor.deferFocus();
23123 clickEvent:'mousedown'
23126 id:editorcore.frameId +'backcolor',
23127 cls:'x-btn-icon x-edit-backcolor',
23128 clickEvent:'mousedown',
23129 tooltip: this.buttonTips['backcolor'] || undefined,
23131 menu : new Roo.menu.ColorMenu({
23132 focus: Roo.emptyFn,
23135 allowReselect: true,
23136 selectHandler: function(cp, color){
23138 editorcore.execCmd('useCSS', false);
23139 editorcore.execCmd('hilitecolor', color);
23140 editorcore.execCmd('useCSS', true);
23141 editor.deferFocus();
23143 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
23144 Roo.isSafari || Roo.isIE ? '#'+color : color);
23145 editor.deferFocus();
23149 clickEvent:'mousedown'
23154 // now add all the items...
23157 if(!this.disable.alignments){
23160 btn('justifyleft'),
23161 btn('justifycenter'),
23162 btn('justifyright')
23166 //if(!Roo.isSafari){
23167 if(!this.disable.links){
23170 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
23174 if(!this.disable.lists){
23177 btn('insertorderedlist'),
23178 btn('insertunorderedlist')
23181 if(!this.disable.sourceEdit){
23184 btn('sourceedit', true, function(btn){
23185 this.toggleSourceEdit(btn.pressed);
23192 // special menu.. - needs to be tidied up..
23193 if (!this.disable.special) {
23196 cls: 'x-edit-none',
23202 for (var i =0; i < this.specialChars.length; i++) {
23203 smenu.menu.items.push({
23205 html: this.specialChars[i],
23206 handler: function(a,b) {
23207 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
23208 //editor.insertAtCursor(a.html);
23222 if (!this.disable.cleanStyles) {
23224 cls: 'x-btn-icon x-btn-clear',
23230 for (var i =0; i < this.cleanStyles.length; i++) {
23231 cmenu.menu.items.push({
23232 actiontype : this.cleanStyles[i],
23233 html: 'Remove ' + this.cleanStyles[i],
23234 handler: function(a,b) {
23237 var c = Roo.get(editorcore.doc.body);
23238 c.select('[style]').each(function(s) {
23239 s.dom.style.removeProperty(a.actiontype);
23241 editorcore.syncValue();
23246 cmenu.menu.items.push({
23247 actiontype : 'tablewidths',
23248 html: 'Remove Table Widths',
23249 handler: function(a,b) {
23250 editorcore.cleanTableWidths();
23251 editorcore.syncValue();
23255 cmenu.menu.items.push({
23256 actiontype : 'word',
23257 html: 'Remove MS Word Formating',
23258 handler: function(a,b) {
23259 editorcore.cleanWord();
23260 editorcore.syncValue();
23265 cmenu.menu.items.push({
23266 actiontype : 'all',
23267 html: 'Remove All Styles',
23268 handler: function(a,b) {
23270 var c = Roo.get(editorcore.doc.body);
23271 c.select('[style]').each(function(s) {
23272 s.dom.removeAttribute('style');
23274 editorcore.syncValue();
23279 cmenu.menu.items.push({
23280 actiontype : 'all',
23281 html: 'Remove All CSS Classes',
23282 handler: function(a,b) {
23284 var c = Roo.get(editorcore.doc.body);
23285 c.select('[class]').each(function(s) {
23286 s.dom.removeAttribute('class');
23288 editorcore.cleanWord();
23289 editorcore.syncValue();
23294 cmenu.menu.items.push({
23295 actiontype : 'tidy',
23296 html: 'Tidy HTML Source',
23297 handler: function(a,b) {
23298 editorcore.doc.body.innerHTML = editorcore.domToHTML();
23299 editorcore.syncValue();
23308 if (!this.disable.specialElements) {
23311 cls: 'x-edit-none',
23316 for (var i =0; i < this.specialElements.length; i++) {
23317 semenu.menu.items.push(
23319 handler: function(a,b) {
23320 editor.insertAtCursor(this.ihtml);
23322 }, this.specialElements[i])
23334 for(var i =0; i< this.btns.length;i++) {
23335 var b = Roo.factory(this.btns[i],Roo.form);
23336 b.cls = 'x-edit-none';
23338 if(typeof(this.btns[i].cls) != 'undefined' && this.btns[i].cls.indexOf('x-init-enable') !== -1){
23339 b.cls += ' x-init-enable';
23342 b.scope = editorcore;
23350 // disable everything...
23352 this.tb.items.each(function(item){
23355 item.id != editorcore.frameId+ '-sourceedit' &&
23356 (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)
23362 this.rendered = true;
23364 // the all the btns;
23365 editor.on('editorevent', this.updateToolbar, this);
23366 // other toolbars need to implement this..
23367 //editor.on('editmodechange', this.updateToolbar, this);
23371 relayBtnCmd : function(btn) {
23372 this.editorcore.relayCmd(btn.cmd);
23374 // private used internally
23375 createLink : function(){
23376 Roo.log("create link?");
23377 var url = prompt(this.createLinkText, this.defaultLinkValue);
23378 if(url && url != 'http:/'+'/'){
23379 this.editorcore.relayCmd('createlink', url);
23385 * Protected method that will not generally be called directly. It triggers
23386 * a toolbar update by reading the markup state of the current selection in the editor.
23388 updateToolbar: function(){
23390 if(!this.editorcore.activated){
23391 this.editor.onFirstFocus();
23395 var btns = this.tb.items.map,
23396 doc = this.editorcore.doc,
23397 frameId = this.editorcore.frameId;
23399 if(!this.disable.font && !Roo.isSafari){
23401 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
23402 if(name != this.fontSelect.dom.value){
23403 this.fontSelect.dom.value = name;
23407 if(!this.disable.format){
23408 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
23409 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
23410 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
23411 btns[frameId + '-strikethrough'].toggle(doc.queryCommandState('strikethrough'));
23413 if(!this.disable.alignments){
23414 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
23415 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
23416 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
23418 if(!Roo.isSafari && !this.disable.lists){
23419 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
23420 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
23423 var ans = this.editorcore.getAllAncestors();
23424 if (this.formatCombo) {
23427 var store = this.formatCombo.store;
23428 this.formatCombo.setValue("");
23429 for (var i =0; i < ans.length;i++) {
23430 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23432 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23440 // hides menus... - so this cant be on a menu...
23441 Roo.menu.MenuMgr.hideAll();
23443 //this.editorsyncValue();
23447 createFontOptions : function(){
23448 var buf = [], fs = this.fontFamilies, ff, lc;
23452 for(var i = 0, len = fs.length; i< len; i++){
23454 lc = ff.toLowerCase();
23456 '<option value="',lc,'" style="font-family:',ff,';"',
23457 (this.defaultFont == lc ? ' selected="true">' : '>'),
23462 return buf.join('');
23465 toggleSourceEdit : function(sourceEditMode){
23467 Roo.log("toolbar toogle");
23468 if(sourceEditMode === undefined){
23469 sourceEditMode = !this.sourceEditMode;
23471 this.sourceEditMode = sourceEditMode === true;
23472 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
23473 // just toggle the button?
23474 if(btn.pressed !== this.sourceEditMode){
23475 btn.toggle(this.sourceEditMode);
23479 if(sourceEditMode){
23480 Roo.log("disabling buttons");
23481 this.tb.items.each(function(item){
23482 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
23488 Roo.log("enabling buttons");
23489 if(this.editorcore.initialized){
23490 this.tb.items.each(function(item){
23496 Roo.log("calling toggole on editor");
23497 // tell the editor that it's been pressed..
23498 this.editor.toggleSourceEdit(sourceEditMode);
23502 * Object collection of toolbar tooltips for the buttons in the editor. The key
23503 * is the command id associated with that button and the value is a valid QuickTips object.
23508 title: 'Bold (Ctrl+B)',
23509 text: 'Make the selected text bold.',
23510 cls: 'x-html-editor-tip'
23513 title: 'Italic (Ctrl+I)',
23514 text: 'Make the selected text italic.',
23515 cls: 'x-html-editor-tip'
23523 title: 'Bold (Ctrl+B)',
23524 text: 'Make the selected text bold.',
23525 cls: 'x-html-editor-tip'
23528 title: 'Italic (Ctrl+I)',
23529 text: 'Make the selected text italic.',
23530 cls: 'x-html-editor-tip'
23533 title: 'Underline (Ctrl+U)',
23534 text: 'Underline the selected text.',
23535 cls: 'x-html-editor-tip'
23538 title: 'Strikethrough',
23539 text: 'Strikethrough the selected text.',
23540 cls: 'x-html-editor-tip'
23542 increasefontsize : {
23543 title: 'Grow Text',
23544 text: 'Increase the font size.',
23545 cls: 'x-html-editor-tip'
23547 decreasefontsize : {
23548 title: 'Shrink Text',
23549 text: 'Decrease the font size.',
23550 cls: 'x-html-editor-tip'
23553 title: 'Text Highlight Color',
23554 text: 'Change the background color of the selected text.',
23555 cls: 'x-html-editor-tip'
23558 title: 'Font Color',
23559 text: 'Change the color of the selected text.',
23560 cls: 'x-html-editor-tip'
23563 title: 'Align Text Left',
23564 text: 'Align text to the left.',
23565 cls: 'x-html-editor-tip'
23568 title: 'Center Text',
23569 text: 'Center text in the editor.',
23570 cls: 'x-html-editor-tip'
23573 title: 'Align Text Right',
23574 text: 'Align text to the right.',
23575 cls: 'x-html-editor-tip'
23577 insertunorderedlist : {
23578 title: 'Bullet List',
23579 text: 'Start a bulleted list.',
23580 cls: 'x-html-editor-tip'
23582 insertorderedlist : {
23583 title: 'Numbered List',
23584 text: 'Start a numbered list.',
23585 cls: 'x-html-editor-tip'
23588 title: 'Hyperlink',
23589 text: 'Make the selected text a hyperlink.',
23590 cls: 'x-html-editor-tip'
23593 title: 'Source Edit',
23594 text: 'Switch to source editing mode.',
23595 cls: 'x-html-editor-tip'
23599 onDestroy : function(){
23602 this.tb.items.each(function(item){
23604 item.menu.removeAll();
23606 item.menu.el.destroy();
23614 onFirstFocus: function() {
23615 this.tb.items.each(function(item){
23624 // <script type="text/javascript">
23627 * Ext JS Library 1.1.1
23628 * Copyright(c) 2006-2007, Ext JS, LLC.
23635 * @class Roo.form.HtmlEditor.ToolbarContext
23640 new Roo.form.HtmlEditor({
23643 { xtype: 'ToolbarStandard', styles : {} }
23644 { xtype: 'ToolbarContext', disable : {} }
23650 * @config : {Object} disable List of elements to disable.. (not done yet.)
23651 * @config : {Object} styles Map of styles available.
23655 Roo.form.HtmlEditor.ToolbarContext = function(config)
23658 Roo.apply(this, config);
23659 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23660 // dont call parent... till later.
23661 this.styles = this.styles || {};
23666 Roo.form.HtmlEditor.ToolbarContext.types = {
23678 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
23744 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
23749 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
23759 style : 'fontFamily',
23760 displayField: 'display',
23761 optname : 'font-family',
23810 // should we really allow this??
23811 // should this just be
23822 style : 'fontFamily',
23823 displayField: 'display',
23824 optname : 'font-family',
23831 style : 'fontFamily',
23832 displayField: 'display',
23833 optname : 'font-family',
23840 style : 'fontFamily',
23841 displayField: 'display',
23842 optname : 'font-family',
23853 // this should be configurable.. - you can either set it up using stores, or modify options somehwere..
23854 Roo.form.HtmlEditor.ToolbarContext.stores = false;
23856 Roo.form.HtmlEditor.ToolbarContext.options = {
23858 [ 'Helvetica,Arial,sans-serif', 'Helvetica'],
23859 [ 'Courier New', 'Courier New'],
23860 [ 'Tahoma', 'Tahoma'],
23861 [ 'Times New Roman,serif', 'Times'],
23862 [ 'Verdana','Verdana' ]
23866 // fixme - these need to be configurable..
23869 //Roo.form.HtmlEditor.ToolbarContext.types
23872 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
23879 editorcore : false,
23881 * @cfg {Object} disable List of toolbar elements to disable
23886 * @cfg {Object} styles List of styles
23887 * eg. { '*' : [ 'headline' ] , 'TD' : [ 'underline', 'double-underline' ] }
23889 * These must be defined in the page, so they get rendered correctly..
23900 init : function(editor)
23902 this.editor = editor;
23903 this.editorcore = editor.editorcore ? editor.editorcore : editor;
23904 var editorcore = this.editorcore;
23906 var fid = editorcore.frameId;
23908 function btn(id, toggle, handler){
23909 var xid = fid + '-'+ id ;
23913 cls : 'x-btn-icon x-edit-'+id,
23914 enableToggle:toggle !== false,
23915 scope: editorcore, // was editor...
23916 handler:handler||editorcore.relayBtnCmd,
23917 clickEvent:'mousedown',
23918 tooltip: etb.buttonTips[id] || undefined, ///tips ???
23922 // create a new element.
23923 var wdiv = editor.wrap.createChild({
23925 }, editor.wrap.dom.firstChild.nextSibling, true);
23927 // can we do this more than once??
23929 // stop form submits
23932 // disable everything...
23933 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
23934 this.toolbars = {};
23936 for (var i in ty) {
23938 this.toolbars[i] = this.buildToolbar(ty[i],i);
23940 this.tb = this.toolbars.BODY;
23942 this.buildFooter();
23943 this.footer.show();
23944 editor.on('hide', function( ) { this.footer.hide() }, this);
23945 editor.on('show', function( ) { this.footer.show() }, this);
23948 this.rendered = true;
23950 // the all the btns;
23951 editor.on('editorevent', this.updateToolbar, this);
23952 // other toolbars need to implement this..
23953 //editor.on('editmodechange', this.updateToolbar, this);
23959 * Protected method that will not generally be called directly. It triggers
23960 * a toolbar update by reading the markup state of the current selection in the editor.
23962 * Note you can force an update by calling on('editorevent', scope, false)
23964 updateToolbar: function(editor,ev,sel){
23967 // capture mouse up - this is handy for selecting images..
23968 // perhaps should go somewhere else...
23969 if(!this.editorcore.activated){
23970 this.editor.onFirstFocus();
23976 // http://developer.yahoo.com/yui/docs/simple-editor.js.html
23977 // selectNode - might want to handle IE?
23979 (ev.type == 'mouseup' || ev.type == 'click' ) &&
23980 ev.target && ev.target.tagName == 'IMG') {
23981 // they have click on an image...
23982 // let's see if we can change the selection...
23985 var nodeRange = sel.ownerDocument.createRange();
23987 nodeRange.selectNode(sel);
23989 nodeRange.selectNodeContents(sel);
23991 //nodeRange.collapse(true);
23992 var s = this.editorcore.win.getSelection();
23993 s.removeAllRanges();
23994 s.addRange(nodeRange);
23998 var updateFooter = sel ? false : true;
24001 var ans = this.editorcore.getAllAncestors();
24004 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
24007 sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editorcore.doc.body;
24008 sel = sel ? sel : this.editorcore.doc.body;
24009 sel = sel.tagName.length ? sel : this.editorcore.doc.body;
24012 // pick a menu that exists..
24013 var tn = sel.tagName.toUpperCase();
24014 //sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
24016 tn = sel.tagName.toUpperCase();
24018 var lastSel = this.tb.selectedNode;
24020 this.tb.selectedNode = sel;
24022 // if current menu does not match..
24024 if ((this.tb.name != tn) || (lastSel != this.tb.selectedNode) || ev === false) {
24027 ///console.log("show: " + tn);
24028 this.tb = typeof(ty[tn]) != 'undefined' ? this.toolbars[tn] : this.toolbars['*'];
24031 this.tb.items.first().el.innerHTML = tn + ': ';
24034 // update attributes
24035 if (this.tb.fields) {
24036 this.tb.fields.each(function(e) {
24038 e.setValue(sel.style[e.stylename]);
24041 e.setValue(sel.getAttribute(e.attrname));
24045 var hasStyles = false;
24046 for(var i in this.styles) {
24053 var st = this.tb.fields.item(0);
24055 st.store.removeAll();
24058 var cn = sel.className.split(/\s+/);
24061 if (this.styles['*']) {
24063 Roo.each(this.styles['*'], function(v) {
24064 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
24067 if (this.styles[tn]) {
24068 Roo.each(this.styles[tn], function(v) {
24069 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
24073 st.store.loadData(avs);
24077 // flag our selected Node.
24078 this.tb.selectedNode = sel;
24081 Roo.menu.MenuMgr.hideAll();
24085 if (!updateFooter) {
24086 //this.footDisp.dom.innerHTML = '';
24089 // update the footer
24093 this.footerEls = ans.reverse();
24094 Roo.each(this.footerEls, function(a,i) {
24095 if (!a) { return; }
24096 html += html.length ? ' > ' : '';
24098 html += '<span class="x-ed-loc-' + i + '">' + a.tagName + '</span>';
24103 var sz = this.footDisp.up('td').getSize();
24104 this.footDisp.dom.style.width = (sz.width -10) + 'px';
24105 this.footDisp.dom.style.marginLeft = '5px';
24107 this.footDisp.dom.style.overflow = 'hidden';
24109 this.footDisp.dom.innerHTML = html;
24111 //this.editorsyncValue();
24118 onDestroy : function(){
24121 this.tb.items.each(function(item){
24123 item.menu.removeAll();
24125 item.menu.el.destroy();
24133 onFirstFocus: function() {
24134 // need to do this for all the toolbars..
24135 this.tb.items.each(function(item){
24139 buildToolbar: function(tlist, nm)
24141 var editor = this.editor;
24142 var editorcore = this.editorcore;
24143 // create a new element.
24144 var wdiv = editor.wrap.createChild({
24146 }, editor.wrap.dom.firstChild.nextSibling, true);
24149 var tb = new Roo.Toolbar(wdiv);
24152 tb.add(nm+ ": ");
24155 for(var i in this.styles) {
24160 if (styles && styles.length) {
24162 // this needs a multi-select checkbox...
24163 tb.addField( new Roo.form.ComboBox({
24164 store: new Roo.data.SimpleStore({
24166 fields: ['val', 'selected'],
24169 name : '-roo-edit-className',
24170 attrname : 'className',
24171 displayField: 'val',
24175 triggerAction: 'all',
24176 emptyText:'Select Style',
24177 selectOnFocus:true,
24180 'select': function(c, r, i) {
24181 // initial support only for on class per el..
24182 tb.selectedNode.className = r ? r.get('val') : '';
24183 editorcore.syncValue();
24190 var tbc = Roo.form.HtmlEditor.ToolbarContext;
24191 var tbops = tbc.options;
24193 for (var i in tlist) {
24195 var item = tlist[i];
24196 tb.add(item.title + ": ");
24199 //optname == used so you can configure the options available..
24200 var opts = item.opts ? item.opts : false;
24201 if (item.optname) {
24202 opts = tbops[item.optname];
24207 // opts == pulldown..
24208 tb.addField( new Roo.form.ComboBox({
24209 store: typeof(tbc.stores[i]) != 'undefined' ? Roo.factory(tbc.stores[i],Roo.data) : new Roo.data.SimpleStore({
24211 fields: ['val', 'display'],
24214 name : '-roo-edit-' + i,
24216 stylename : item.style ? item.style : false,
24217 displayField: item.displayField ? item.displayField : 'val',
24218 valueField : 'val',
24220 mode: typeof(tbc.stores[i]) != 'undefined' ? 'remote' : 'local',
24222 triggerAction: 'all',
24223 emptyText:'Select',
24224 selectOnFocus:true,
24225 width: item.width ? item.width : 130,
24227 'select': function(c, r, i) {
24229 tb.selectedNode.style[c.stylename] = r.get('val');
24232 tb.selectedNode.setAttribute(c.attrname, r.get('val'));
24241 tb.addField( new Roo.form.TextField({
24244 //allowBlank:false,
24249 tb.addField( new Roo.form.TextField({
24250 name: '-roo-edit-' + i,
24257 'change' : function(f, nv, ov) {
24258 tb.selectedNode.setAttribute(f.attrname, nv);
24259 editorcore.syncValue();
24272 text: 'Stylesheets',
24275 click : function ()
24277 _this.editor.fireEvent('stylesheetsclick', _this.editor);
24285 text: 'Remove Tag',
24288 click : function ()
24291 // undo does not work.
24293 var sn = tb.selectedNode;
24295 var pn = sn.parentNode;
24297 var stn = sn.childNodes[0];
24298 var en = sn.childNodes[sn.childNodes.length - 1 ];
24299 while (sn.childNodes.length) {
24300 var node = sn.childNodes[0];
24301 sn.removeChild(node);
24303 pn.insertBefore(node, sn);
24306 pn.removeChild(sn);
24307 var range = editorcore.createRange();
24309 range.setStart(stn,0);
24310 range.setEnd(en,0); //????
24311 //range.selectNode(sel);
24314 var selection = editorcore.getSelection();
24315 selection.removeAllRanges();
24316 selection.addRange(range);
24320 //_this.updateToolbar(null, null, pn);
24321 _this.updateToolbar(null, null, null);
24322 _this.footDisp.dom.innerHTML = '';
24332 tb.el.on('click', function(e){
24333 e.preventDefault(); // what does this do?
24335 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
24338 // dont need to disable them... as they will get hidden
24343 buildFooter : function()
24346 var fel = this.editor.wrap.createChild();
24347 this.footer = new Roo.Toolbar(fel);
24348 // toolbar has scrolly on left / right?
24349 var footDisp= new Roo.Toolbar.Fill();
24355 handler : function() {
24356 _t.footDisp.scrollTo('left',0,true)
24360 this.footer.add( footDisp );
24365 handler : function() {
24367 _t.footDisp.select('span').last().scrollIntoView(_t.footDisp,true);
24371 var fel = Roo.get(footDisp.el);
24372 fel.addClass('x-editor-context');
24373 this.footDispWrap = fel;
24374 this.footDispWrap.overflow = 'hidden';
24376 this.footDisp = fel.createChild();
24377 this.footDispWrap.on('click', this.onContextClick, this)
24381 onContextClick : function (ev,dom)
24383 ev.preventDefault();
24384 var cn = dom.className;
24386 if (!cn.match(/x-ed-loc-/)) {
24389 var n = cn.split('-').pop();
24390 var ans = this.footerEls;
24394 var range = this.editorcore.createRange();
24396 range.selectNodeContents(sel);
24397 //range.selectNode(sel);
24400 var selection = this.editorcore.getSelection();
24401 selection.removeAllRanges();
24402 selection.addRange(range);
24406 this.updateToolbar(null, null, sel);
24423 * Ext JS Library 1.1.1
24424 * Copyright(c) 2006-2007, Ext JS, LLC.
24426 * Originally Released Under LGPL - original licence link has changed is not relivant.
24429 * <script type="text/javascript">
24433 * @class Roo.form.BasicForm
24434 * @extends Roo.util.Observable
24435 * Supplies the functionality to do "actions" on forms and initialize Roo.form.Field types on existing markup.
24437 * @param {String/HTMLElement/Roo.Element} el The form element or its id
24438 * @param {Object} config Configuration options
24440 Roo.form.BasicForm = function(el, config){
24441 this.allItems = [];
24442 this.childForms = [];
24443 Roo.apply(this, config);
24445 * The Roo.form.Field items in this form.
24446 * @type MixedCollection
24450 this.items = new Roo.util.MixedCollection(false, function(o){
24451 return o.id || (o.id = Roo.id());
24455 * @event beforeaction
24456 * Fires before any action is performed. Return false to cancel the action.
24457 * @param {Form} this
24458 * @param {Action} action The action to be performed
24460 beforeaction: true,
24462 * @event actionfailed
24463 * Fires when an action fails.
24464 * @param {Form} this
24465 * @param {Action} action The action that failed
24467 actionfailed : true,
24469 * @event actioncomplete
24470 * Fires when an action is completed.
24471 * @param {Form} this
24472 * @param {Action} action The action that completed
24474 actioncomplete : true
24479 Roo.form.BasicForm.superclass.constructor.call(this);
24481 Roo.form.BasicForm.popover.apply();
24484 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
24486 * @cfg {String} method
24487 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
24490 * @cfg {DataReader} reader
24491 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when executing "load" actions.
24492 * This is optional as there is built-in support for processing JSON.
24495 * @cfg {DataReader} errorReader
24496 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
24497 * This is completely optional as there is built-in support for processing JSON.
24500 * @cfg {String} url
24501 * The URL to use for form actions if one isn't supplied in the action options.
24504 * @cfg {Boolean} fileUpload
24505 * Set to true if this form is a file upload.
24509 * @cfg {Object} baseParams
24510 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
24515 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
24520 activeAction : null,
24523 * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded
24524 * or setValues() data instead of when the form was first created.
24526 trackResetOnLoad : false,
24530 * childForms - used for multi-tab forms
24533 childForms : false,
24536 * allItems - full list of fields.
24542 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
24543 * element by passing it or its id or mask the form itself by passing in true.
24546 waitMsgTarget : false,
24551 disableMask : false,
24554 * @cfg {Boolean} errorMask (true|false) default false
24559 * @cfg {Number} maskOffset Default 100
24564 initEl : function(el){
24565 this.el = Roo.get(el);
24566 this.id = this.el.id || Roo.id();
24567 this.el.on('submit', this.onSubmit, this);
24568 this.el.addClass('x-form');
24572 onSubmit : function(e){
24577 * Returns true if client-side validation on the form is successful.
24580 isValid : function(){
24582 var target = false;
24583 this.items.each(function(f){
24590 if(!target && f.el.isVisible(true)){
24595 if(this.errorMask && !valid){
24596 Roo.form.BasicForm.popover.mask(this, target);
24603 * DEPRICATED Returns true if any fields in this form have changed since their original load.
24606 isDirty : function(){
24608 this.items.each(function(f){
24618 * Returns true if any fields in this form have changed since their original load. (New version)
24622 hasChanged : function()
24625 this.items.each(function(f){
24626 if(f.hasChanged()){
24635 * Resets all hasChanged to 'false' -
24636 * The old 'isDirty' used 'original value..' however this breaks reset() and a few other things.
24637 * So hasChanged storage is only to be used for this purpose
24640 resetHasChanged : function()
24642 this.items.each(function(f){
24643 f.resetHasChanged();
24650 * Performs a predefined action (submit or load) or custom actions you define on this form.
24651 * @param {String} actionName The name of the action type
24652 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
24653 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
24654 * accept other config options):
24656 Property Type Description
24657 ---------------- --------------- ----------------------------------------------------------------------------------
24658 url String The url for the action (defaults to the form's url)
24659 method String The form method to use (defaults to the form's method, or POST if not defined)
24660 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
24661 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
24662 validate the form on the client (defaults to false)
24664 * @return {BasicForm} this
24666 doAction : function(action, options){
24667 if(typeof action == 'string'){
24668 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
24670 if(this.fireEvent('beforeaction', this, action) !== false){
24671 this.beforeAction(action);
24672 action.run.defer(100, action);
24678 * Shortcut to do a submit action.
24679 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
24680 * @return {BasicForm} this
24682 submit : function(options){
24683 this.doAction('submit', options);
24688 * Shortcut to do a load action.
24689 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
24690 * @return {BasicForm} this
24692 load : function(options){
24693 this.doAction('load', options);
24698 * Persists the values in this form into the passed Roo.data.Record object in a beginEdit/endEdit block.
24699 * @param {Record} record The record to edit
24700 * @return {BasicForm} this
24702 updateRecord : function(record){
24703 record.beginEdit();
24704 var fs = record.fields;
24705 fs.each(function(f){
24706 var field = this.findField(f.name);
24708 record.set(f.name, field.getValue());
24716 * Loads an Roo.data.Record into this form.
24717 * @param {Record} record The record to load
24718 * @return {BasicForm} this
24720 loadRecord : function(record){
24721 this.setValues(record.data);
24726 beforeAction : function(action){
24727 var o = action.options;
24729 if(!this.disableMask) {
24730 if(this.waitMsgTarget === true){
24731 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
24732 }else if(this.waitMsgTarget){
24733 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
24734 this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
24736 Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
24744 afterAction : function(action, success){
24745 this.activeAction = null;
24746 var o = action.options;
24748 if(!this.disableMask) {
24749 if(this.waitMsgTarget === true){
24751 }else if(this.waitMsgTarget){
24752 this.waitMsgTarget.unmask();
24754 Roo.MessageBox.updateProgress(1);
24755 Roo.MessageBox.hide();
24763 Roo.callback(o.success, o.scope, [this, action]);
24764 this.fireEvent('actioncomplete', this, action);
24768 // failure condition..
24769 // we have a scenario where updates need confirming.
24770 // eg. if a locking scenario exists..
24771 // we look for { errors : { needs_confirm : true }} in the response.
24773 (typeof(action.result) != 'undefined') &&
24774 (typeof(action.result.errors) != 'undefined') &&
24775 (typeof(action.result.errors.needs_confirm) != 'undefined')
24778 Roo.MessageBox.confirm(
24779 "Change requires confirmation",
24780 action.result.errorMsg,
24785 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
24795 Roo.callback(o.failure, o.scope, [this, action]);
24796 // show an error message if no failed handler is set..
24797 if (!this.hasListener('actionfailed')) {
24798 Roo.MessageBox.alert("Error",
24799 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
24800 action.result.errorMsg :
24801 "Saving Failed, please check your entries or try again"
24805 this.fireEvent('actionfailed', this, action);
24811 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
24812 * @param {String} id The value to search for
24815 findField : function(id){
24816 var field = this.items.get(id);
24818 this.items.each(function(f){
24819 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
24825 return field || null;
24829 * Add a secondary form to this one,
24830 * Used to provide tabbed forms. One form is primary, with hidden values
24831 * which mirror the elements from the other forms.
24833 * @param {Roo.form.Form} form to add.
24836 addForm : function(form)
24839 if (this.childForms.indexOf(form) > -1) {
24843 this.childForms.push(form);
24845 Roo.each(form.allItems, function (fe) {
24847 n = typeof(fe.getName) == 'undefined' ? fe.name : fe.getName();
24848 if (this.findField(n)) { // already added..
24851 var add = new Roo.form.Hidden({
24854 add.render(this.el);
24861 * Mark fields in this form invalid in bulk.
24862 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
24863 * @return {BasicForm} this
24865 markInvalid : function(errors){
24866 if(errors instanceof Array){
24867 for(var i = 0, len = errors.length; i < len; i++){
24868 var fieldError = errors[i];
24869 var f = this.findField(fieldError.id);
24871 f.markInvalid(fieldError.msg);
24877 if(typeof errors[id] != 'function' && (field = this.findField(id))){
24878 field.markInvalid(errors[id]);
24882 Roo.each(this.childForms || [], function (f) {
24883 f.markInvalid(errors);
24890 * Set values for fields in this form in bulk.
24891 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
24892 * @return {BasicForm} this
24894 setValues : function(values){
24895 if(values instanceof Array){ // array of objects
24896 for(var i = 0, len = values.length; i < len; i++){
24898 var f = this.findField(v.id);
24900 f.setValue(v.value);
24901 if(this.trackResetOnLoad){
24902 f.originalValue = f.getValue();
24906 }else{ // object hash
24909 if(typeof values[id] != 'function' && (field = this.findField(id))){
24911 if (field.setFromData &&
24912 field.valueField &&
24913 field.displayField &&
24914 // combos' with local stores can
24915 // be queried via setValue()
24916 // to set their value..
24917 (field.store && !field.store.isLocal)
24921 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
24922 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
24923 field.setFromData(sd);
24926 field.setValue(values[id]);
24930 if(this.trackResetOnLoad){
24931 field.originalValue = field.getValue();
24936 this.resetHasChanged();
24939 Roo.each(this.childForms || [], function (f) {
24940 f.setValues(values);
24941 f.resetHasChanged();
24948 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
24949 * they are returned as an array.
24950 * @param {Boolean} asString
24953 getValues : function(asString){
24954 if (this.childForms) {
24955 // copy values from the child forms
24956 Roo.each(this.childForms, function (f) {
24957 this.setValues(f.getValues());
24962 if (typeof(FormData) != 'undefined' && asString !== true) {
24963 // this relies on a 'recent' version of chrome apparently...
24965 var fd = (new FormData(this.el.dom)).entries();
24967 var ent = fd.next();
24968 while (!ent.done) {
24969 ret[ent.value[0]] = ent.value[1]; // not sure how this will handle duplicates..
24980 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
24981 if(asString === true){
24984 return Roo.urlDecode(fs);
24988 * Returns the fields in this form as an object with key/value pairs.
24989 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
24992 getFieldValues : function(with_hidden)
24994 if (this.childForms) {
24995 // copy values from the child forms
24996 // should this call getFieldValues - probably not as we do not currently copy
24997 // hidden fields when we generate..
24998 Roo.each(this.childForms, function (f) {
24999 this.setValues(f.getValues());
25004 this.items.each(function(f){
25005 if (!f.getName()) {
25008 var v = f.getValue();
25009 if (f.inputType =='radio') {
25010 if (typeof(ret[f.getName()]) == 'undefined') {
25011 ret[f.getName()] = ''; // empty..
25014 if (!f.el.dom.checked) {
25018 v = f.el.dom.value;
25022 // not sure if this supported any more..
25023 if ((typeof(v) == 'object') && f.getRawValue) {
25024 v = f.getRawValue() ; // dates..
25026 // combo boxes where name != hiddenName...
25027 if (f.name != f.getName()) {
25028 ret[f.name] = f.getRawValue();
25030 ret[f.getName()] = v;
25037 * Clears all invalid messages in this form.
25038 * @return {BasicForm} this
25040 clearInvalid : function(){
25041 this.items.each(function(f){
25045 Roo.each(this.childForms || [], function (f) {
25054 * Resets this form.
25055 * @return {BasicForm} this
25057 reset : function(){
25058 this.items.each(function(f){
25062 Roo.each(this.childForms || [], function (f) {
25065 this.resetHasChanged();
25071 * Add Roo.form components to this form.
25072 * @param {Field} field1
25073 * @param {Field} field2 (optional)
25074 * @param {Field} etc (optional)
25075 * @return {BasicForm} this
25078 this.items.addAll(Array.prototype.slice.call(arguments, 0));
25084 * Removes a field from the items collection (does NOT remove its markup).
25085 * @param {Field} field
25086 * @return {BasicForm} this
25088 remove : function(field){
25089 this.items.remove(field);
25094 * Looks at the fields in this form, checks them for an id attribute,
25095 * and calls applyTo on the existing dom element with that id.
25096 * @return {BasicForm} this
25098 render : function(){
25099 this.items.each(function(f){
25100 if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
25108 * Calls {@link Ext#apply} for all fields in this form with the passed object.
25109 * @param {Object} values
25110 * @return {BasicForm} this
25112 applyToFields : function(o){
25113 this.items.each(function(f){
25120 * Calls {@link Ext#applyIf} for all field in this form with the passed object.
25121 * @param {Object} values
25122 * @return {BasicForm} this
25124 applyIfToFields : function(o){
25125 this.items.each(function(f){
25133 Roo.BasicForm = Roo.form.BasicForm;
25135 Roo.apply(Roo.form.BasicForm, {
25149 intervalID : false,
25155 if(this.isApplied){
25160 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
25161 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
25162 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
25163 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
25166 this.maskEl.top.enableDisplayMode("block");
25167 this.maskEl.left.enableDisplayMode("block");
25168 this.maskEl.bottom.enableDisplayMode("block");
25169 this.maskEl.right.enableDisplayMode("block");
25171 Roo.get(document.body).on('click', function(){
25175 Roo.get(document.body).on('touchstart', function(){
25179 this.isApplied = true
25182 mask : function(form, target)
25186 this.target = target;
25188 if(!this.form.errorMask || !target.el){
25192 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.x-layout-active-content', 100, true) || Roo.get(document.body);
25194 var ot = this.target.el.calcOffsetsTo(scrollable);
25196 var scrollTo = ot[1] - this.form.maskOffset;
25198 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
25200 scrollable.scrollTo('top', scrollTo);
25202 var el = this.target.wrap || this.target.el;
25204 var box = el.getBox();
25206 this.maskEl.top.setStyle('position', 'absolute');
25207 this.maskEl.top.setStyle('z-index', 10000);
25208 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
25209 this.maskEl.top.setLeft(0);
25210 this.maskEl.top.setTop(0);
25211 this.maskEl.top.show();
25213 this.maskEl.left.setStyle('position', 'absolute');
25214 this.maskEl.left.setStyle('z-index', 10000);
25215 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
25216 this.maskEl.left.setLeft(0);
25217 this.maskEl.left.setTop(box.y - this.padding);
25218 this.maskEl.left.show();
25220 this.maskEl.bottom.setStyle('position', 'absolute');
25221 this.maskEl.bottom.setStyle('z-index', 10000);
25222 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
25223 this.maskEl.bottom.setLeft(0);
25224 this.maskEl.bottom.setTop(box.bottom + this.padding);
25225 this.maskEl.bottom.show();
25227 this.maskEl.right.setStyle('position', 'absolute');
25228 this.maskEl.right.setStyle('z-index', 10000);
25229 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
25230 this.maskEl.right.setLeft(box.right + this.padding);
25231 this.maskEl.right.setTop(box.y - this.padding);
25232 this.maskEl.right.show();
25234 this.intervalID = window.setInterval(function() {
25235 Roo.form.BasicForm.popover.unmask();
25238 window.onwheel = function(){ return false;};
25240 (function(){ this.isMasked = true; }).defer(500, this);
25244 unmask : function()
25246 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
25250 this.maskEl.top.setStyle('position', 'absolute');
25251 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
25252 this.maskEl.top.hide();
25254 this.maskEl.left.setStyle('position', 'absolute');
25255 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
25256 this.maskEl.left.hide();
25258 this.maskEl.bottom.setStyle('position', 'absolute');
25259 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
25260 this.maskEl.bottom.hide();
25262 this.maskEl.right.setStyle('position', 'absolute');
25263 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
25264 this.maskEl.right.hide();
25266 window.onwheel = function(){ return true;};
25268 if(this.intervalID){
25269 window.clearInterval(this.intervalID);
25270 this.intervalID = false;
25273 this.isMasked = false;
25281 * Ext JS Library 1.1.1
25282 * Copyright(c) 2006-2007, Ext JS, LLC.
25284 * Originally Released Under LGPL - original licence link has changed is not relivant.
25287 * <script type="text/javascript">
25291 * @class Roo.form.Form
25292 * @extends Roo.form.BasicForm
25293 * Adds the ability to dynamically render forms with JavaScript to {@link Roo.form.BasicForm}.
25295 * @param {Object} config Configuration options
25297 Roo.form.Form = function(config){
25299 if (config.items) {
25300 xitems = config.items;
25301 delete config.items;
25305 Roo.form.Form.superclass.constructor.call(this, null, config);
25306 this.url = this.url || this.action;
25308 this.root = new Roo.form.Layout(Roo.applyIf({
25312 this.active = this.root;
25314 * Array of all the buttons that have been added to this form via {@link addButton}
25318 this.allItems = [];
25321 * @event clientvalidation
25322 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
25323 * @param {Form} this
25324 * @param {Boolean} valid true if the form has passed client-side validation
25326 clientvalidation: true,
25329 * Fires when the form is rendered
25330 * @param {Roo.form.Form} form
25335 if (this.progressUrl) {
25336 // push a hidden field onto the list of fields..
25340 name : 'UPLOAD_IDENTIFIER'
25345 Roo.each(xitems, this.addxtype, this);
25349 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
25351 * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
25354 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
25357 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
25359 buttonAlign:'center',
25362 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
25367 * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
25368 * This property cascades to child containers if not set.
25373 * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
25374 * fires a looping event with that state. This is required to bind buttons to the valid
25375 * state using the config value formBind:true on the button.
25377 monitorValid : false,
25380 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
25385 * @cfg {String} progressUrl - Url to return progress data
25388 progressUrl : false,
25390 * @cfg {boolean|FormData} formData - true to use new 'FormData' post, or set to a new FormData({dom form}) Object, if
25391 * sending a formdata with extra parameters - eg uploaded elements.
25397 * Opens a new {@link Roo.form.Column} container in the layout stack. If fields are passed after the config, the
25398 * fields are added and the column is closed. If no fields are passed the column remains open
25399 * until end() is called.
25400 * @param {Object} config The config to pass to the column
25401 * @param {Field} field1 (optional)
25402 * @param {Field} field2 (optional)
25403 * @param {Field} etc (optional)
25404 * @return Column The column container object
25406 column : function(c){
25407 var col = new Roo.form.Column(c);
25409 if(arguments.length > 1){ // duplicate code required because of Opera
25410 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25417 * Opens a new {@link Roo.form.FieldSet} container in the layout stack. If fields are passed after the config, the
25418 * fields are added and the fieldset is closed. If no fields are passed the fieldset remains open
25419 * until end() is called.
25420 * @param {Object} config The config to pass to the fieldset
25421 * @param {Field} field1 (optional)
25422 * @param {Field} field2 (optional)
25423 * @param {Field} etc (optional)
25424 * @return FieldSet The fieldset container object
25426 fieldset : function(c){
25427 var fs = new Roo.form.FieldSet(c);
25429 if(arguments.length > 1){ // duplicate code required because of Opera
25430 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25437 * Opens a new {@link Roo.form.Layout} container in the layout stack. If fields are passed after the config, the
25438 * fields are added and the container is closed. If no fields are passed the container remains open
25439 * until end() is called.
25440 * @param {Object} config The config to pass to the Layout
25441 * @param {Field} field1 (optional)
25442 * @param {Field} field2 (optional)
25443 * @param {Field} etc (optional)
25444 * @return Layout The container object
25446 container : function(c){
25447 var l = new Roo.form.Layout(c);
25449 if(arguments.length > 1){ // duplicate code required because of Opera
25450 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25457 * Opens the passed container in the layout stack. The container can be any {@link Roo.form.Layout} or subclass.
25458 * @param {Object} container A Roo.form.Layout or subclass of Layout
25459 * @return {Form} this
25461 start : function(c){
25462 // cascade label info
25463 Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
25464 this.active.stack.push(c);
25465 c.ownerCt = this.active;
25471 * Closes the current open container
25472 * @return {Form} this
25475 if(this.active == this.root){
25478 this.active = this.active.ownerCt;
25483 * Add Roo.form components to the current open container (e.g. column, fieldset, etc.). Fields added via this method
25484 * can also be passed with an additional property of fieldLabel, which if supplied, will provide the text to display
25485 * as the label of the field.
25486 * @param {Field} field1
25487 * @param {Field} field2 (optional)
25488 * @param {Field} etc. (optional)
25489 * @return {Form} this
25492 this.active.stack.push.apply(this.active.stack, arguments);
25493 this.allItems.push.apply(this.allItems,arguments);
25495 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
25496 if(a[i].isFormField){
25501 Roo.form.Form.superclass.add.apply(this, r);
25511 * Find any element that has been added to a form, using it's ID or name
25512 * This can include framesets, columns etc. along with regular fields..
25513 * @param {String} id - id or name to find.
25515 * @return {Element} e - or false if nothing found.
25517 findbyId : function(id)
25523 Roo.each(this.allItems, function(f){
25524 if (f.id == id || f.name == id ){
25535 * Render this form into the passed container. This should only be called once!
25536 * @param {String/HTMLElement/Element} container The element this component should be rendered into
25537 * @return {Form} this
25539 render : function(ct)
25545 var o = this.autoCreate || {
25547 method : this.method || 'POST',
25548 id : this.id || Roo.id()
25550 this.initEl(ct.createChild(o));
25552 this.root.render(this.el);
25556 this.items.each(function(f){
25557 f.render('x-form-el-'+f.id);
25560 if(this.buttons.length > 0){
25561 // tables are required to maintain order and for correct IE layout
25562 var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
25563 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
25564 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
25566 var tr = tb.getElementsByTagName('tr')[0];
25567 for(var i = 0, len = this.buttons.length; i < len; i++) {
25568 var b = this.buttons[i];
25569 var td = document.createElement('td');
25570 td.className = 'x-form-btn-td';
25571 b.render(tr.appendChild(td));
25574 if(this.monitorValid){ // initialize after render
25575 this.startMonitoring();
25577 this.fireEvent('rendered', this);
25582 * Adds a button to the footer of the form - this <b>must</b> be called before the form is rendered.
25583 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
25584 * object or a valid Roo.DomHelper element config
25585 * @param {Function} handler The function called when the button is clicked
25586 * @param {Object} scope (optional) The scope of the handler function
25587 * @return {Roo.Button}
25589 addButton : function(config, handler, scope){
25593 minWidth: this.minButtonWidth,
25596 if(typeof config == "string"){
25599 Roo.apply(bc, config);
25601 var btn = new Roo.Button(null, bc);
25602 this.buttons.push(btn);
25607 * Adds a series of form elements (using the xtype property as the factory method.
25608 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column, (and 'end' to close a block)
25609 * @param {Object} config
25612 addxtype : function()
25614 var ar = Array.prototype.slice.call(arguments, 0);
25616 for(var i = 0; i < ar.length; i++) {
25618 continue; // skip -- if this happends something invalid got sent, we
25619 // should ignore it, as basically that interface element will not show up
25620 // and that should be pretty obvious!!
25623 if (Roo.form[ar[i].xtype]) {
25625 var fe = Roo.factory(ar[i], Roo.form);
25631 fe.store.form = this;
25636 this.allItems.push(fe);
25637 if (fe.items && fe.addxtype) {
25638 fe.addxtype.apply(fe, fe.items);
25648 // console.log('adding ' + ar[i].xtype);
25650 if (ar[i].xtype == 'Button') {
25651 //console.log('adding button');
25652 //console.log(ar[i]);
25653 this.addButton(ar[i]);
25654 this.allItems.push(fe);
25658 if (ar[i].xtype == 'end') { // so we can add fieldsets... / layout etc.
25659 alert('end is not supported on xtype any more, use items');
25661 // //console.log('adding end');
25669 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
25670 * option "monitorValid"
25672 startMonitoring : function(){
25675 Roo.TaskMgr.start({
25676 run : this.bindHandler,
25677 interval : this.monitorPoll || 200,
25684 * Stops monitoring of the valid state of this form
25686 stopMonitoring : function(){
25687 this.bound = false;
25691 bindHandler : function(){
25693 return false; // stops binding
25696 this.items.each(function(f){
25697 if(!f.isValid(true)){
25702 for(var i = 0, len = this.buttons.length; i < len; i++){
25703 var btn = this.buttons[i];
25704 if(btn.formBind === true && btn.disabled === valid){
25705 btn.setDisabled(!valid);
25708 this.fireEvent('clientvalidation', this, valid);
25722 Roo.Form = Roo.form.Form;
25725 * Ext JS Library 1.1.1
25726 * Copyright(c) 2006-2007, Ext JS, LLC.
25728 * Originally Released Under LGPL - original licence link has changed is not relivant.
25731 * <script type="text/javascript">
25734 // as we use this in bootstrap.
25735 Roo.namespace('Roo.form');
25737 * @class Roo.form.Action
25738 * Internal Class used to handle form actions
25740 * @param {Roo.form.BasicForm} el The form element or its id
25741 * @param {Object} config Configuration options
25746 // define the action interface
25747 Roo.form.Action = function(form, options){
25749 this.options = options || {};
25752 * Client Validation Failed
25755 Roo.form.Action.CLIENT_INVALID = 'client';
25757 * Server Validation Failed
25760 Roo.form.Action.SERVER_INVALID = 'server';
25762 * Connect to Server Failed
25765 Roo.form.Action.CONNECT_FAILURE = 'connect';
25767 * Reading Data from Server Failed
25770 Roo.form.Action.LOAD_FAILURE = 'load';
25772 Roo.form.Action.prototype = {
25774 failureType : undefined,
25775 response : undefined,
25776 result : undefined,
25778 // interface method
25779 run : function(options){
25783 // interface method
25784 success : function(response){
25788 // interface method
25789 handleResponse : function(response){
25793 // default connection failure
25794 failure : function(response){
25796 this.response = response;
25797 this.failureType = Roo.form.Action.CONNECT_FAILURE;
25798 this.form.afterAction(this, false);
25801 processResponse : function(response){
25802 this.response = response;
25803 if(!response.responseText){
25806 this.result = this.handleResponse(response);
25807 return this.result;
25810 // utility functions used internally
25811 getUrl : function(appendParams){
25812 var url = this.options.url || this.form.url || this.form.el.dom.action;
25814 var p = this.getParams();
25816 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
25822 getMethod : function(){
25823 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
25826 getParams : function(){
25827 var bp = this.form.baseParams;
25828 var p = this.options.params;
25830 if(typeof p == "object"){
25831 p = Roo.urlEncode(Roo.applyIf(p, bp));
25832 }else if(typeof p == 'string' && bp){
25833 p += '&' + Roo.urlEncode(bp);
25836 p = Roo.urlEncode(bp);
25841 createCallback : function(){
25843 success: this.success,
25844 failure: this.failure,
25846 timeout: (this.form.timeout*1000),
25847 upload: this.form.fileUpload ? this.success : undefined
25852 Roo.form.Action.Submit = function(form, options){
25853 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
25856 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
25859 haveProgress : false,
25860 uploadComplete : false,
25862 // uploadProgress indicator.
25863 uploadProgress : function()
25865 if (!this.form.progressUrl) {
25869 if (!this.haveProgress) {
25870 Roo.MessageBox.progress("Uploading", "Uploading");
25872 if (this.uploadComplete) {
25873 Roo.MessageBox.hide();
25877 this.haveProgress = true;
25879 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
25881 var c = new Roo.data.Connection();
25883 url : this.form.progressUrl,
25888 success : function(req){
25889 //console.log(data);
25893 rdata = Roo.decode(req.responseText)
25895 Roo.log("Invalid data from server..");
25899 if (!rdata || !rdata.success) {
25901 Roo.MessageBox.alert(Roo.encode(rdata));
25904 var data = rdata.data;
25906 if (this.uploadComplete) {
25907 Roo.MessageBox.hide();
25912 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
25913 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
25916 this.uploadProgress.defer(2000,this);
25919 failure: function(data) {
25920 Roo.log('progress url failed ');
25931 // run get Values on the form, so it syncs any secondary forms.
25932 this.form.getValues();
25934 var o = this.options;
25935 var method = this.getMethod();
25936 var isPost = method == 'POST';
25937 if(o.clientValidation === false || this.form.isValid()){
25939 if (this.form.progressUrl) {
25940 this.form.findField('UPLOAD_IDENTIFIER').setValue(
25941 (new Date() * 1) + '' + Math.random());
25946 Roo.Ajax.request(Roo.apply(this.createCallback(), {
25947 form:this.form.el.dom,
25948 url:this.getUrl(!isPost),
25950 params:isPost ? this.getParams() : null,
25951 isUpload: this.form.fileUpload,
25952 formData : this.form.formData
25955 this.uploadProgress();
25957 }else if (o.clientValidation !== false){ // client validation failed
25958 this.failureType = Roo.form.Action.CLIENT_INVALID;
25959 this.form.afterAction(this, false);
25963 success : function(response)
25965 this.uploadComplete= true;
25966 if (this.haveProgress) {
25967 Roo.MessageBox.hide();
25971 var result = this.processResponse(response);
25972 if(result === true || result.success){
25973 this.form.afterAction(this, true);
25977 this.form.markInvalid(result.errors);
25978 this.failureType = Roo.form.Action.SERVER_INVALID;
25980 this.form.afterAction(this, false);
25982 failure : function(response)
25984 this.uploadComplete= true;
25985 if (this.haveProgress) {
25986 Roo.MessageBox.hide();
25989 this.response = response;
25990 this.failureType = Roo.form.Action.CONNECT_FAILURE;
25991 this.form.afterAction(this, false);
25994 handleResponse : function(response){
25995 if(this.form.errorReader){
25996 var rs = this.form.errorReader.read(response);
25999 for(var i = 0, len = rs.records.length; i < len; i++) {
26000 var r = rs.records[i];
26001 errors[i] = r.data;
26004 if(errors.length < 1){
26008 success : rs.success,
26014 ret = Roo.decode(response.responseText);
26018 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
26028 Roo.form.Action.Load = function(form, options){
26029 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
26030 this.reader = this.form.reader;
26033 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
26038 Roo.Ajax.request(Roo.apply(
26039 this.createCallback(), {
26040 method:this.getMethod(),
26041 url:this.getUrl(false),
26042 params:this.getParams()
26046 success : function(response){
26048 var result = this.processResponse(response);
26049 if(result === true || !result.success || !result.data){
26050 this.failureType = Roo.form.Action.LOAD_FAILURE;
26051 this.form.afterAction(this, false);
26054 this.form.clearInvalid();
26055 this.form.setValues(result.data);
26056 this.form.afterAction(this, true);
26059 handleResponse : function(response){
26060 if(this.form.reader){
26061 var rs = this.form.reader.read(response);
26062 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
26064 success : rs.success,
26068 return Roo.decode(response.responseText);
26072 Roo.form.Action.ACTION_TYPES = {
26073 'load' : Roo.form.Action.Load,
26074 'submit' : Roo.form.Action.Submit
26077 * Ext JS Library 1.1.1
26078 * Copyright(c) 2006-2007, Ext JS, LLC.
26080 * Originally Released Under LGPL - original licence link has changed is not relivant.
26083 * <script type="text/javascript">
26087 * @class Roo.form.Layout
26088 * @extends Roo.Component
26089 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
26091 * @param {Object} config Configuration options
26093 Roo.form.Layout = function(config){
26095 if (config.items) {
26096 xitems = config.items;
26097 delete config.items;
26099 Roo.form.Layout.superclass.constructor.call(this, config);
26101 Roo.each(xitems, this.addxtype, this);
26105 Roo.extend(Roo.form.Layout, Roo.Component, {
26107 * @cfg {String/Object} autoCreate
26108 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
26111 * @cfg {String/Object/Function} style
26112 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
26113 * a function which returns such a specification.
26116 * @cfg {String} labelAlign
26117 * Valid values are "left," "top" and "right" (defaults to "left")
26120 * @cfg {Number} labelWidth
26121 * Fixed width in pixels of all field labels (defaults to undefined)
26124 * @cfg {Boolean} clear
26125 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
26129 * @cfg {String} labelSeparator
26130 * The separator to use after field labels (defaults to ':')
26132 labelSeparator : ':',
26134 * @cfg {Boolean} hideLabels
26135 * True to suppress the display of field labels in this layout (defaults to false)
26137 hideLabels : false,
26140 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
26145 onRender : function(ct, position){
26146 if(this.el){ // from markup
26147 this.el = Roo.get(this.el);
26148 }else { // generate
26149 var cfg = this.getAutoCreate();
26150 this.el = ct.createChild(cfg, position);
26153 this.el.applyStyles(this.style);
26155 if(this.labelAlign){
26156 this.el.addClass('x-form-label-'+this.labelAlign);
26158 if(this.hideLabels){
26159 this.labelStyle = "display:none";
26160 this.elementStyle = "padding-left:0;";
26162 if(typeof this.labelWidth == 'number'){
26163 this.labelStyle = "width:"+this.labelWidth+"px;";
26164 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
26166 if(this.labelAlign == 'top'){
26167 this.labelStyle = "width:auto;";
26168 this.elementStyle = "padding-left:0;";
26171 var stack = this.stack;
26172 var slen = stack.length;
26174 if(!this.fieldTpl){
26175 var t = new Roo.Template(
26176 '<div class="x-form-item {5}">',
26177 '<label for="{0}" style="{2}">{1}{4}</label>',
26178 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
26180 '</div><div class="x-form-clear-left"></div>'
26182 t.disableFormats = true;
26184 Roo.form.Layout.prototype.fieldTpl = t;
26186 for(var i = 0; i < slen; i++) {
26187 if(stack[i].isFormField){
26188 this.renderField(stack[i]);
26190 this.renderComponent(stack[i]);
26195 this.el.createChild({cls:'x-form-clear'});
26200 renderField : function(f){
26201 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
26204 f.labelStyle||this.labelStyle||'', //2
26205 this.elementStyle||'', //3
26206 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
26207 f.itemCls||this.itemCls||'' //5
26208 ], true).getPrevSibling());
26212 renderComponent : function(c){
26213 c.render(c.isLayout ? this.el : this.el.createChild());
26216 * Adds a object form elements (using the xtype property as the factory method.)
26217 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
26218 * @param {Object} config
26220 addxtype : function(o)
26222 // create the lement.
26223 o.form = this.form;
26224 var fe = Roo.factory(o, Roo.form);
26225 this.form.allItems.push(fe);
26226 this.stack.push(fe);
26228 if (fe.isFormField) {
26229 this.form.items.add(fe);
26237 * @class Roo.form.Column
26238 * @extends Roo.form.Layout
26239 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
26241 * @param {Object} config Configuration options
26243 Roo.form.Column = function(config){
26244 Roo.form.Column.superclass.constructor.call(this, config);
26247 Roo.extend(Roo.form.Column, Roo.form.Layout, {
26249 * @cfg {Number/String} width
26250 * The fixed width of the column in pixels or CSS value (defaults to "auto")
26253 * @cfg {String/Object} autoCreate
26254 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
26258 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
26261 onRender : function(ct, position){
26262 Roo.form.Column.superclass.onRender.call(this, ct, position);
26264 this.el.setWidth(this.width);
26271 * @class Roo.form.Row
26272 * @extends Roo.form.Layout
26273 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
26275 * @param {Object} config Configuration options
26279 Roo.form.Row = function(config){
26280 Roo.form.Row.superclass.constructor.call(this, config);
26283 Roo.extend(Roo.form.Row, Roo.form.Layout, {
26285 * @cfg {Number/String} width
26286 * The fixed width of the column in pixels or CSS value (defaults to "auto")
26289 * @cfg {Number/String} height
26290 * The fixed height of the column in pixels or CSS value (defaults to "auto")
26292 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
26296 onRender : function(ct, position){
26297 //console.log('row render');
26299 var t = new Roo.Template(
26300 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
26301 '<label for="{0}" style="{2}">{1}{4}</label>',
26302 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
26306 t.disableFormats = true;
26308 Roo.form.Layout.prototype.rowTpl = t;
26310 this.fieldTpl = this.rowTpl;
26312 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
26313 var labelWidth = 100;
26315 if ((this.labelAlign != 'top')) {
26316 if (typeof this.labelWidth == 'number') {
26317 labelWidth = this.labelWidth
26319 this.padWidth = 20 + labelWidth;
26323 Roo.form.Column.superclass.onRender.call(this, ct, position);
26325 this.el.setWidth(this.width);
26328 this.el.setHeight(this.height);
26333 renderField : function(f){
26334 f.fieldEl = this.fieldTpl.append(this.el, [
26335 f.id, f.fieldLabel,
26336 f.labelStyle||this.labelStyle||'',
26337 this.elementStyle||'',
26338 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
26339 f.itemCls||this.itemCls||'',
26340 f.width ? f.width + this.padWidth : 160 + this.padWidth
26347 * @class Roo.form.FieldSet
26348 * @extends Roo.form.Layout
26349 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
26351 * @param {Object} config Configuration options
26353 Roo.form.FieldSet = function(config){
26354 Roo.form.FieldSet.superclass.constructor.call(this, config);
26357 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
26359 * @cfg {String} legend
26360 * The text to display as the legend for the FieldSet (defaults to '')
26363 * @cfg {String/Object} autoCreate
26364 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
26368 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
26371 onRender : function(ct, position){
26372 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
26374 this.setLegend(this.legend);
26379 setLegend : function(text){
26381 this.el.child('legend').update(text);
26386 * Ext JS Library 1.1.1
26387 * Copyright(c) 2006-2007, Ext JS, LLC.
26389 * Originally Released Under LGPL - original licence link has changed is not relivant.
26392 * <script type="text/javascript">
26395 * @class Roo.form.VTypes
26396 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
26399 Roo.form.VTypes = function(){
26400 // closure these in so they are only created once.
26401 var alpha = /^[a-zA-Z_]+$/;
26402 var alphanum = /^[a-zA-Z0-9_]+$/;
26403 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
26404 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
26406 // All these messages and functions are configurable
26409 * The function used to validate email addresses
26410 * @param {String} value The email address
26412 'email' : function(v){
26413 return email.test(v);
26416 * The error text to display when the email validation function returns false
26419 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
26421 * The keystroke filter mask to be applied on email input
26424 'emailMask' : /[a-z0-9_\.\-@]/i,
26427 * The function used to validate URLs
26428 * @param {String} value The URL
26430 'url' : function(v){
26431 return url.test(v);
26434 * The error text to display when the url validation function returns false
26437 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
26440 * The function used to validate alpha values
26441 * @param {String} value The value
26443 'alpha' : function(v){
26444 return alpha.test(v);
26447 * The error text to display when the alpha validation function returns false
26450 'alphaText' : 'This field should only contain letters and _',
26452 * The keystroke filter mask to be applied on alpha input
26455 'alphaMask' : /[a-z_]/i,
26458 * The function used to validate alphanumeric values
26459 * @param {String} value The value
26461 'alphanum' : function(v){
26462 return alphanum.test(v);
26465 * The error text to display when the alphanumeric validation function returns false
26468 'alphanumText' : 'This field should only contain letters, numbers and _',
26470 * The keystroke filter mask to be applied on alphanumeric input
26473 'alphanumMask' : /[a-z0-9_]/i
26475 }();//<script type="text/javascript">
26478 * @class Roo.form.FCKeditor
26479 * @extends Roo.form.TextArea
26480 * Wrapper around the FCKEditor http://www.fckeditor.net
26482 * Creates a new FCKeditor
26483 * @param {Object} config Configuration options
26485 Roo.form.FCKeditor = function(config){
26486 Roo.form.FCKeditor.superclass.constructor.call(this, config);
26489 * @event editorinit
26490 * Fired when the editor is initialized - you can add extra handlers here..
26491 * @param {FCKeditor} this
26492 * @param {Object} the FCK object.
26499 Roo.form.FCKeditor.editors = { };
26500 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
26502 //defaultAutoCreate : {
26503 // tag : "textarea",style : "width:100px;height:60px;" ,autocomplete : "off"
26507 * @cfg {Object} fck options - see fck manual for details.
26512 * @cfg {Object} fck toolbar set (Basic or Default)
26514 toolbarSet : 'Basic',
26516 * @cfg {Object} fck BasePath
26518 basePath : '/fckeditor/',
26526 onRender : function(ct, position)
26529 this.defaultAutoCreate = {
26531 style:"width:300px;height:60px;",
26532 autocomplete: "new-password"
26535 Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
26538 this.textSizeEl = Roo.DomHelper.append(document.body, {tag: "pre", cls: "x-form-grow-sizer"});
26539 if(this.preventScrollbars){
26540 this.el.setStyle("overflow", "hidden");
26542 this.el.setHeight(this.growMin);
26545 //console.log('onrender' + this.getId() );
26546 Roo.form.FCKeditor.editors[this.getId()] = this;
26549 this.replaceTextarea() ;
26553 getEditor : function() {
26554 return this.fckEditor;
26557 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
26558 * @param {Mixed} value The value to set
26562 setValue : function(value)
26564 //console.log('setValue: ' + value);
26566 if(typeof(value) == 'undefined') { // not sure why this is happending...
26569 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
26571 //if(!this.el || !this.getEditor()) {
26572 // this.value = value;
26573 //this.setValue.defer(100,this,[value]);
26577 if(!this.getEditor()) {
26581 this.getEditor().SetData(value);
26588 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
26589 * @return {Mixed} value The field value
26591 getValue : function()
26594 if (this.frame && this.frame.dom.style.display == 'none') {
26595 return Roo.form.FCKeditor.superclass.getValue.call(this);
26598 if(!this.el || !this.getEditor()) {
26600 // this.getValue.defer(100,this);
26605 var value=this.getEditor().GetData();
26606 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
26607 return Roo.form.FCKeditor.superclass.getValue.call(this);
26613 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
26614 * @return {Mixed} value The field value
26616 getRawValue : function()
26618 if (this.frame && this.frame.dom.style.display == 'none') {
26619 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
26622 if(!this.el || !this.getEditor()) {
26623 //this.getRawValue.defer(100,this);
26630 var value=this.getEditor().GetData();
26631 Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
26632 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
26636 setSize : function(w,h) {
26640 //if (this.frame && this.frame.dom.style.display == 'none') {
26641 // Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
26644 //if(!this.el || !this.getEditor()) {
26645 // this.setSize.defer(100,this, [w,h]);
26651 Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
26653 this.frame.dom.setAttribute('width', w);
26654 this.frame.dom.setAttribute('height', h);
26655 this.frame.setSize(w,h);
26659 toggleSourceEdit : function(value) {
26663 this.el.dom.style.display = value ? '' : 'none';
26664 this.frame.dom.style.display = value ? 'none' : '';
26669 focus: function(tag)
26671 if (this.frame.dom.style.display == 'none') {
26672 return Roo.form.FCKeditor.superclass.focus.call(this);
26674 if(!this.el || !this.getEditor()) {
26675 this.focus.defer(100,this, [tag]);
26682 var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
26683 this.getEditor().Focus();
26685 if (!this.getEditor().Selection.GetSelection()) {
26686 this.focus.defer(100,this, [tag]);
26691 var r = this.getEditor().EditorDocument.createRange();
26692 r.setStart(tgs[0],0);
26693 r.setEnd(tgs[0],0);
26694 this.getEditor().Selection.GetSelection().removeAllRanges();
26695 this.getEditor().Selection.GetSelection().addRange(r);
26696 this.getEditor().Focus();
26703 replaceTextarea : function()
26705 if ( document.getElementById( this.getId() + '___Frame' ) ) {
26708 //if ( !this.checkBrowser || this._isCompatibleBrowser() )
26710 // We must check the elements firstly using the Id and then the name.
26711 var oTextarea = document.getElementById( this.getId() );
26713 var colElementsByName = document.getElementsByName( this.getId() ) ;
26715 oTextarea.style.display = 'none' ;
26717 if ( oTextarea.tabIndex ) {
26718 this.TabIndex = oTextarea.tabIndex ;
26721 this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
26722 this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
26723 this.frame = Roo.get(this.getId() + '___Frame')
26726 _getConfigHtml : function()
26730 for ( var o in this.fckconfig ) {
26731 sConfig += sConfig.length > 0 ? '&' : '';
26732 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
26735 return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
26739 _getIFrameHtml : function()
26741 var sFile = 'fckeditor.html' ;
26742 /* no idea what this is about..
26745 if ( (/fcksource=true/i).test( window.top.location.search ) )
26746 sFile = 'fckeditor.original.html' ;
26751 var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
26752 sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
26755 var html = '<iframe id="' + this.getId() +
26756 '___Frame" src="' + sLink +
26757 '" width="' + this.width +
26758 '" height="' + this.height + '"' +
26759 (this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
26760 ' frameborder="0" scrolling="no"></iframe>' ;
26765 _insertHtmlBefore : function( html, element )
26767 if ( element.insertAdjacentHTML ) {
26769 element.insertAdjacentHTML( 'beforeBegin', html ) ;
26771 var oRange = document.createRange() ;
26772 oRange.setStartBefore( element ) ;
26773 var oFragment = oRange.createContextualFragment( html );
26774 element.parentNode.insertBefore( oFragment, element ) ;
26787 //Roo.reg('fckeditor', Roo.form.FCKeditor);
26789 function FCKeditor_OnComplete(editorInstance){
26790 var f = Roo.form.FCKeditor.editors[editorInstance.Name];
26791 f.fckEditor = editorInstance;
26792 //console.log("loaded");
26793 f.fireEvent('editorinit', f, editorInstance);
26813 //<script type="text/javascript">
26815 * @class Roo.form.GridField
26816 * @extends Roo.form.Field
26817 * Embed a grid (or editable grid into a form)
26820 * This embeds a grid in a form, the value of the field should be the json encoded array of rows
26822 * xgrid.store = Roo.data.Store
26823 * xgrid.store.proxy = Roo.data.MemoryProxy (data = [] )
26824 * xgrid.store.reader = Roo.data.JsonReader
26828 * Creates a new GridField
26829 * @param {Object} config Configuration options
26831 Roo.form.GridField = function(config){
26832 Roo.form.GridField.superclass.constructor.call(this, config);
26836 Roo.extend(Roo.form.GridField, Roo.form.Field, {
26838 * @cfg {Number} width - used to restrict width of grid..
26842 * @cfg {Number} height - used to restrict height of grid..
26846 * @cfg {Object} xgrid (xtype'd description of grid) { xtype : 'Grid', dataSource: .... }
26852 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
26853 * {tag: "input", type: "checkbox", autocomplete: "off"})
26855 // defaultAutoCreate : { tag: 'div' },
26856 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'new-password'},
26858 * @cfg {String} addTitle Text to include for adding a title.
26862 onResize : function(){
26863 Roo.form.Field.superclass.onResize.apply(this, arguments);
26866 initEvents : function(){
26867 // Roo.form.Checkbox.superclass.initEvents.call(this);
26868 // has no events...
26873 getResizeEl : function(){
26877 getPositionEl : function(){
26882 onRender : function(ct, position){
26884 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
26885 var style = this.style;
26888 Roo.form.GridField.superclass.onRender.call(this, ct, position);
26889 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
26890 this.viewEl = this.wrap.createChild({ tag: 'div' });
26892 this.viewEl.applyStyles(style);
26895 this.viewEl.setWidth(this.width);
26898 this.viewEl.setHeight(this.height);
26900 //if(this.inputValue !== undefined){
26901 //this.setValue(this.value);
26904 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
26907 this.grid.render();
26908 this.grid.getDataSource().on('remove', this.refreshValue, this);
26909 this.grid.getDataSource().on('update', this.refreshValue, this);
26910 this.grid.on('afteredit', this.refreshValue, this);
26916 * Sets the value of the item.
26917 * @param {String} either an object or a string..
26919 setValue : function(v){
26921 v = v || []; // empty set..
26922 // this does not seem smart - it really only affects memoryproxy grids..
26923 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
26924 var ds = this.grid.getDataSource();
26925 // assumes a json reader..
26927 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
26928 ds.loadData( data);
26930 // clear selection so it does not get stale.
26931 if (this.grid.sm) {
26932 this.grid.sm.clearSelections();
26935 Roo.form.GridField.superclass.setValue.call(this, v);
26936 this.refreshValue();
26937 // should load data in the grid really....
26941 refreshValue: function() {
26943 this.grid.getDataSource().each(function(r) {
26946 this.el.dom.value = Roo.encode(val);
26954 * Ext JS Library 1.1.1
26955 * Copyright(c) 2006-2007, Ext JS, LLC.
26957 * Originally Released Under LGPL - original licence link has changed is not relivant.
26960 * <script type="text/javascript">
26963 * @class Roo.form.DisplayField
26964 * @extends Roo.form.Field
26965 * A generic Field to display non-editable data.
26966 * @cfg {Boolean} closable (true|false) default false
26968 * Creates a new Display Field item.
26969 * @param {Object} config Configuration options
26971 Roo.form.DisplayField = function(config){
26972 Roo.form.DisplayField.superclass.constructor.call(this, config);
26977 * Fires after the click the close btn
26978 * @param {Roo.form.DisplayField} this
26984 Roo.extend(Roo.form.DisplayField, Roo.form.TextField, {
26985 inputType: 'hidden',
26991 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
26993 focusClass : undefined,
26995 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
26997 fieldClass: 'x-form-field',
27000 * @cfg {Function} valueRenderer The renderer for the field (so you can reformat output). should return raw HTML
27002 valueRenderer: undefined,
27006 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27007 * {tag: "input", type: "checkbox", autocomplete: "off"})
27010 // defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
27014 onResize : function(){
27015 Roo.form.DisplayField.superclass.onResize.apply(this, arguments);
27019 initEvents : function(){
27020 // Roo.form.Checkbox.superclass.initEvents.call(this);
27021 // has no events...
27024 this.closeEl.on('click', this.onClose, this);
27030 getResizeEl : function(){
27034 getPositionEl : function(){
27039 onRender : function(ct, position){
27041 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
27042 //if(this.inputValue !== undefined){
27043 this.wrap = this.el.wrap();
27045 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
27048 this.closeEl = this.wrap.createChild({ tag: 'div', cls: 'x-dlg-close'});
27051 if (this.bodyStyle) {
27052 this.viewEl.applyStyles(this.bodyStyle);
27054 //this.viewEl.setStyle('padding', '2px');
27056 this.setValue(this.value);
27061 initValue : Roo.emptyFn,
27066 onClick : function(){
27071 * Sets the checked state of the checkbox.
27072 * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
27074 setValue : function(v){
27076 var html = this.valueRenderer ? this.valueRenderer(v) : String.format('{0}', v);
27077 // this might be called before we have a dom element..
27078 if (!this.viewEl) {
27081 this.viewEl.dom.innerHTML = html;
27082 Roo.form.DisplayField.superclass.setValue.call(this, v);
27086 onClose : function(e)
27088 e.preventDefault();
27090 this.fireEvent('close', this);
27099 * @class Roo.form.DayPicker
27100 * @extends Roo.form.Field
27101 * A Day picker show [M] [T] [W] ....
27103 * Creates a new Day Picker
27104 * @param {Object} config Configuration options
27106 Roo.form.DayPicker= function(config){
27107 Roo.form.DayPicker.superclass.constructor.call(this, config);
27111 Roo.extend(Roo.form.DayPicker, Roo.form.Field, {
27113 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
27115 focusClass : undefined,
27117 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
27119 fieldClass: "x-form-field",
27122 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27123 * {tag: "input", type: "checkbox", autocomplete: "off"})
27125 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "new-password"},
27128 actionMode : 'viewEl',
27132 inputType : 'hidden',
27135 inputElement: false, // real input element?
27136 basedOn: false, // ????
27138 isFormField: true, // not sure where this is needed!!!!
27140 onResize : function(){
27141 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
27142 if(!this.boxLabel){
27143 this.el.alignTo(this.wrap, 'c-c');
27147 initEvents : function(){
27148 Roo.form.Checkbox.superclass.initEvents.call(this);
27149 this.el.on("click", this.onClick, this);
27150 this.el.on("change", this.onClick, this);
27154 getResizeEl : function(){
27158 getPositionEl : function(){
27164 onRender : function(ct, position){
27165 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
27167 this.wrap = this.el.wrap({cls: 'x-form-daypick-item '});
27169 var r1 = '<table><tr>';
27170 var r2 = '<tr class="x-form-daypick-icons">';
27171 for (var i=0; i < 7; i++) {
27172 r1+= '<td><div>' + Date.dayNames[i].substring(0,3) + '</div></td>';
27173 r2+= '<td><img class="x-menu-item-icon" src="' + Roo.BLANK_IMAGE_URL +'"></td>';
27176 var viewEl = this.wrap.createChild( r1 + '</tr>' + r2 + '</tr></table>');
27177 viewEl.select('img').on('click', this.onClick, this);
27178 this.viewEl = viewEl;
27181 // this will not work on Chrome!!!
27182 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
27183 this.el.on('propertychange', this.setFromHidden, this); //ie
27191 initValue : Roo.emptyFn,
27194 * Returns the checked state of the checkbox.
27195 * @return {Boolean} True if checked, else false
27197 getValue : function(){
27198 return this.el.dom.value;
27203 onClick : function(e){
27204 //this.setChecked(!this.checked);
27205 Roo.get(e.target).toggleClass('x-menu-item-checked');
27206 this.refreshValue();
27207 //if(this.el.dom.checked != this.checked){
27208 // this.setValue(this.el.dom.checked);
27213 refreshValue : function()
27216 this.viewEl.select('img',true).each(function(e,i,n) {
27217 val += e.is(".x-menu-item-checked") ? String(n) : '';
27219 this.setValue(val, true);
27223 * Sets the checked state of the checkbox.
27224 * On is always based on a string comparison between inputValue and the param.
27225 * @param {Boolean/String} value - the value to set
27226 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
27228 setValue : function(v,suppressEvent){
27229 if (!this.el.dom) {
27232 var old = this.el.dom.value ;
27233 this.el.dom.value = v;
27234 if (suppressEvent) {
27238 // update display..
27239 this.viewEl.select('img',true).each(function(e,i,n) {
27241 var on = e.is(".x-menu-item-checked");
27242 var newv = v.indexOf(String(n)) > -1;
27244 e.toggleClass('x-menu-item-checked');
27250 this.fireEvent('change', this, v, old);
27255 // handle setting of hidden value by some other method!!?!?
27256 setFromHidden: function()
27261 //console.log("SET FROM HIDDEN");
27262 //alert('setFrom hidden');
27263 this.setValue(this.el.dom.value);
27266 onDestroy : function()
27269 Roo.get(this.viewEl).remove();
27272 Roo.form.DayPicker.superclass.onDestroy.call(this);
27276 * RooJS Library 1.1.1
27277 * Copyright(c) 2008-2011 Alan Knowles
27284 * @class Roo.form.ComboCheck
27285 * @extends Roo.form.ComboBox
27286 * A combobox for multiple select items.
27288 * FIXME - could do with a reset button..
27291 * Create a new ComboCheck
27292 * @param {Object} config Configuration options
27294 Roo.form.ComboCheck = function(config){
27295 Roo.form.ComboCheck.superclass.constructor.call(this, config);
27296 // should verify some data...
27298 // hiddenName = required..
27299 // displayField = required
27300 // valudField == required
27301 var req= [ 'hiddenName', 'displayField', 'valueField' ];
27303 Roo.each(req, function(e) {
27304 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
27305 throw "Roo.form.ComboCheck : missing value for: " + e;
27312 Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
27317 selectedClass: 'x-menu-item-checked',
27320 onRender : function(ct, position){
27326 var cls = 'x-combo-list';
27329 this.tpl = new Roo.Template({
27330 html : '<div class="'+cls+'-item x-menu-check-item">' +
27331 '<img class="x-menu-item-icon" style="margin: 0px;" src="' + Roo.BLANK_IMAGE_URL + '">' +
27332 '<span>{' + this.displayField + '}</span>' +
27339 Roo.form.ComboCheck.superclass.onRender.call(this, ct, position);
27340 this.view.singleSelect = false;
27341 this.view.multiSelect = true;
27342 this.view.toggleSelect = true;
27343 this.pageTb.add(new Roo.Toolbar.Fill(), {
27346 handler: function()
27353 onViewOver : function(e, t){
27359 onViewClick : function(doFocus,index){
27363 select: function () {
27364 //Roo.log("SELECT CALLED");
27367 selectByValue : function(xv, scrollIntoView){
27368 var ar = this.getValueArray();
27371 Roo.each(ar, function(v) {
27372 if(v === undefined || v === null){
27375 var r = this.findRecord(this.valueField, v);
27377 sels.push(this.store.indexOf(r))
27381 this.view.select(sels);
27387 onSelect : function(record, index){
27388 // Roo.log("onselect Called");
27389 // this is only called by the clear button now..
27390 this.view.clearSelections();
27391 this.setValue('[]');
27392 if (this.value != this.valueBefore) {
27393 this.fireEvent('change', this, this.value, this.valueBefore);
27394 this.valueBefore = this.value;
27397 getValueArray : function()
27402 //Roo.log(this.value);
27403 if (typeof(this.value) == 'undefined') {
27406 var ar = Roo.decode(this.value);
27407 return ar instanceof Array ? ar : []; //?? valid?
27410 Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
27415 expand : function ()
27418 Roo.form.ComboCheck.superclass.expand.call(this);
27419 this.valueBefore = typeof(this.value) == 'undefined' ? '' : this.value;
27420 //this.valueBefore = typeof(this.valueBefore) == 'undefined' ? '' : this.valueBefore;
27425 collapse : function(){
27426 Roo.form.ComboCheck.superclass.collapse.call(this);
27427 var sl = this.view.getSelectedIndexes();
27428 var st = this.store;
27432 Roo.each(sl, function(i) {
27434 nv.push(r.get(this.valueField));
27436 this.setValue(Roo.encode(nv));
27437 if (this.value != this.valueBefore) {
27439 this.fireEvent('change', this, this.value, this.valueBefore);
27440 this.valueBefore = this.value;
27445 setValue : function(v){
27449 var vals = this.getValueArray();
27451 Roo.each(vals, function(k) {
27452 var r = this.findRecord(this.valueField, k);
27454 tv.push(r.data[this.displayField]);
27455 }else if(this.valueNotFoundText !== undefined){
27456 tv.push( this.valueNotFoundText );
27461 Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
27462 this.hiddenField.value = v;
27468 * Ext JS Library 1.1.1
27469 * Copyright(c) 2006-2007, Ext JS, LLC.
27471 * Originally Released Under LGPL - original licence link has changed is not relivant.
27474 * <script type="text/javascript">
27478 * @class Roo.form.Signature
27479 * @extends Roo.form.Field
27483 * @param {Object} config Configuration options
27486 Roo.form.Signature = function(config){
27487 Roo.form.Signature.superclass.constructor.call(this, config);
27489 this.addEvents({// not in used??
27492 * Fires when the 'confirm' icon is pressed (add a listener to enable add button)
27493 * @param {Roo.form.Signature} combo This combo box
27498 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
27499 * @param {Roo.form.ComboBox} combo This combo box
27500 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
27506 Roo.extend(Roo.form.Signature, Roo.form.Field, {
27508 * @cfg {Object} labels Label to use when rendering a form.
27512 * confirm : "Confirm"
27517 confirm : "Confirm"
27520 * @cfg {Number} width The signature panel width (defaults to 300)
27524 * @cfg {Number} height The signature panel height (defaults to 100)
27528 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to false)
27530 allowBlank : false,
27533 // {Object} signPanel The signature SVG panel element (defaults to {})
27535 // {Boolean} isMouseDown False to validate that the mouse down event (defaults to false)
27536 isMouseDown : false,
27537 // {Boolean} isConfirmed validate the signature is confirmed or not for submitting form (defaults to false)
27538 isConfirmed : false,
27539 // {String} signatureTmp SVG mapping string (defaults to empty string)
27543 defaultAutoCreate : { // modified by initCompnoent..
27549 onRender : function(ct, position){
27551 Roo.form.Signature.superclass.onRender.call(this, ct, position);
27553 this.wrap = this.el.wrap({
27554 cls:'x-form-signature-wrap', style : 'width: ' + this.width + 'px', cn:{cls:'x-form-signature'}
27557 this.createToolbar(this);
27558 this.signPanel = this.wrap.createChild({
27560 style: 'width: ' + this.width + 'px; height: ' + this.height + 'px; border: 0;'
27564 this.svgID = Roo.id();
27565 this.svgEl = this.signPanel.createChild({
27566 xmlns : 'http://www.w3.org/2000/svg',
27568 id : this.svgID + "-svg",
27570 height: this.height,
27571 viewBox: '0 0 '+this.width+' '+this.height,
27575 id: this.svgID + "-svg-r",
27577 height: this.height,
27582 id: this.svgID + "-svg-l",
27584 y1: (this.height*0.8), // start set the line in 80% of height
27585 x2: this.width, // end
27586 y2: (this.height*0.8), // end set the line in 80% of height
27588 'stroke-width': "1",
27589 'stroke-dasharray': "3",
27590 'shape-rendering': "crispEdges",
27591 'pointer-events': "none"
27595 id: this.svgID + "-svg-p",
27597 'stroke-width': "3",
27599 'pointer-events': 'none'
27604 this.svgBox = this.svgEl.dom.getScreenCTM();
27606 createSVG : function(){
27607 var svg = this.signPanel;
27608 var r = svg.select('#'+ this.svgID + '-svg-r', true).first().dom;
27611 r.addEventListener('mousedown', function(e) { return t.down(e); }, false);
27612 r.addEventListener('mousemove', function(e) { return t.move(e); }, false);
27613 r.addEventListener('mouseup', function(e) { return t.up(e); }, false);
27614 r.addEventListener('mouseout', function(e) { return t.up(e); }, false);
27615 r.addEventListener('touchstart', function(e) { return t.down(e); }, false);
27616 r.addEventListener('touchmove', function(e) { return t.move(e); }, false);
27617 r.addEventListener('touchend', function(e) { return t.up(e); }, false);
27620 isTouchEvent : function(e){
27621 return e.type.match(/^touch/);
27623 getCoords : function (e) {
27624 var pt = this.svgEl.dom.createSVGPoint();
27627 if (this.isTouchEvent(e)) {
27628 pt.x = e.targetTouches[0].clientX;
27629 pt.y = e.targetTouches[0].clientY;
27631 var a = this.svgEl.dom.getScreenCTM();
27632 var b = a.inverse();
27633 var mx = pt.matrixTransform(b);
27634 return mx.x + ',' + mx.y;
27636 //mouse event headler
27637 down : function (e) {
27638 this.signatureTmp += 'M' + this.getCoords(e) + ' ';
27639 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr('d', this.signatureTmp);
27641 this.isMouseDown = true;
27643 e.preventDefault();
27645 move : function (e) {
27646 if (this.isMouseDown) {
27647 this.signatureTmp += 'L' + this.getCoords(e) + ' ';
27648 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', this.signatureTmp);
27651 e.preventDefault();
27653 up : function (e) {
27654 this.isMouseDown = false;
27655 var sp = this.signatureTmp.split(' ');
27658 if(!sp[sp.length-2].match(/^L/)){
27662 this.signatureTmp = sp.join(" ");
27665 if(this.getValue() != this.signatureTmp){
27666 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
27667 this.isConfirmed = false;
27669 e.preventDefault();
27673 * Protected method that will not generally be called directly. It
27674 * is called when the editor creates its toolbar. Override this method if you need to
27675 * add custom toolbar buttons.
27676 * @param {HtmlEditor} editor
27678 createToolbar : function(editor){
27679 function btn(id, toggle, handler){
27680 var xid = fid + '-'+ id ;
27684 cls : 'x-btn-icon x-edit-'+id,
27685 enableToggle:toggle !== false,
27686 scope: editor, // was editor...
27687 handler:handler||editor.relayBtnCmd,
27688 clickEvent:'mousedown',
27689 tooltip: etb.buttonTips[id] || undefined, ///tips ???
27695 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
27699 cls : ' x-signature-btn x-signature-'+id,
27700 scope: editor, // was editor...
27701 handler: this.reset,
27702 clickEvent:'mousedown',
27703 text: this.labels.clear
27710 cls : ' x-signature-btn x-signature-'+id,
27711 scope: editor, // was editor...
27712 handler: this.confirmHandler,
27713 clickEvent:'mousedown',
27714 text: this.labels.confirm
27721 * when user is clicked confirm then show this image.....
27723 * @return {String} Image Data URI
27725 getImageDataURI : function(){
27726 var svg = this.svgEl.dom.parentNode.innerHTML;
27727 var src = 'data:image/svg+xml;base64,'+window.btoa(svg);
27732 * @return {Boolean} this.isConfirmed
27734 getConfirmed : function(){
27735 return this.isConfirmed;
27739 * @return {Number} this.width
27741 getWidth : function(){
27746 * @return {Number} this.height
27748 getHeight : function(){
27749 return this.height;
27752 getSignature : function(){
27753 return this.signatureTmp;
27756 reset : function(){
27757 this.signatureTmp = '';
27758 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
27759 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', '');
27760 this.isConfirmed = false;
27761 Roo.form.Signature.superclass.reset.call(this);
27763 setSignature : function(s){
27764 this.signatureTmp = s;
27765 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
27766 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', s);
27768 this.isConfirmed = false;
27769 Roo.form.Signature.superclass.reset.call(this);
27772 // Roo.log(this.signPanel.dom.contentWindow.up())
27775 setConfirmed : function(){
27779 // Roo.log(Roo.get(this.signPanel.dom.contentWindow.r).attr('fill', '#cfc'));
27782 confirmHandler : function(){
27783 if(!this.getSignature()){
27787 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#cfc');
27788 this.setValue(this.getSignature());
27789 this.isConfirmed = true;
27791 this.fireEvent('confirm', this);
27794 // Subclasses should provide the validation implementation by overriding this
27795 validateValue : function(value){
27796 if(this.allowBlank){
27800 if(this.isConfirmed){
27807 * Ext JS Library 1.1.1
27808 * Copyright(c) 2006-2007, Ext JS, LLC.
27810 * Originally Released Under LGPL - original licence link has changed is not relivant.
27813 * <script type="text/javascript">
27818 * @class Roo.form.ComboBox
27819 * @extends Roo.form.TriggerField
27820 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
27822 * Create a new ComboBox.
27823 * @param {Object} config Configuration options
27825 Roo.form.Select = function(config){
27826 Roo.form.Select.superclass.constructor.call(this, config);
27830 Roo.extend(Roo.form.Select , Roo.form.ComboBox, {
27832 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
27835 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
27836 * rendering into an Roo.Editor, defaults to false)
27839 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
27840 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
27843 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
27846 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
27847 * the dropdown list (defaults to undefined, with no header element)
27851 * @cfg {String/Roo.Template} tpl The template to use to render the output
27855 defaultAutoCreate : {tag: "select" },
27857 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
27859 listWidth: undefined,
27861 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
27862 * mode = 'remote' or 'text' if mode = 'local')
27864 displayField: undefined,
27866 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
27867 * mode = 'remote' or 'value' if mode = 'local').
27868 * Note: use of a valueField requires the user make a selection
27869 * in order for a value to be mapped.
27871 valueField: undefined,
27875 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
27876 * field's data value (defaults to the underlying DOM element's name)
27878 hiddenName: undefined,
27880 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
27884 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
27886 selectedClass: 'x-combo-selected',
27888 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
27889 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
27890 * which displays a downward arrow icon).
27892 triggerClass : 'x-form-arrow-trigger',
27894 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
27898 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
27899 * anchor positions (defaults to 'tl-bl')
27901 listAlign: 'tl-bl?',
27903 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
27907 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
27908 * query specified by the allQuery config option (defaults to 'query')
27910 triggerAction: 'query',
27912 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
27913 * (defaults to 4, does not apply if editable = false)
27917 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
27918 * delay (typeAheadDelay) if it matches a known value (defaults to false)
27922 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
27923 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
27927 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
27928 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
27932 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
27933 * when editable = true (defaults to false)
27935 selectOnFocus:false,
27937 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
27939 queryParam: 'query',
27941 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
27942 * when mode = 'remote' (defaults to 'Loading...')
27944 loadingText: 'Loading...',
27946 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
27950 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
27954 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
27955 * traditional select (defaults to true)
27959 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
27963 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
27967 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
27968 * listWidth has a higher value)
27972 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
27973 * allow the user to set arbitrary text into the field (defaults to false)
27975 forceSelection:false,
27977 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
27978 * if typeAhead = true (defaults to 250)
27980 typeAheadDelay : 250,
27982 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
27983 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
27985 valueNotFoundText : undefined,
27988 * @cfg {String} defaultValue The value displayed after loading the store.
27993 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
27995 blockFocus : false,
27998 * @cfg {Boolean} disableClear Disable showing of clear button.
28000 disableClear : false,
28002 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
28004 alwaysQuery : false,
28010 // element that contains real text value.. (when hidden is used..)
28013 onRender : function(ct, position){
28014 Roo.form.Field.prototype.onRender.call(this, ct, position);
28017 this.store.on('beforeload', this.onBeforeLoad, this);
28018 this.store.on('load', this.onLoad, this);
28019 this.store.on('loadexception', this.onLoadException, this);
28020 this.store.load({});
28028 initEvents : function(){
28029 //Roo.form.ComboBox.superclass.initEvents.call(this);
28033 onDestroy : function(){
28036 this.store.un('beforeload', this.onBeforeLoad, this);
28037 this.store.un('load', this.onLoad, this);
28038 this.store.un('loadexception', this.onLoadException, this);
28040 //Roo.form.ComboBox.superclass.onDestroy.call(this);
28044 fireKey : function(e){
28045 if(e.isNavKeyPress() && !this.list.isVisible()){
28046 this.fireEvent("specialkey", this, e);
28051 onResize: function(w, h){
28059 * Allow or prevent the user from directly editing the field text. If false is passed,
28060 * the user will only be able to select from the items defined in the dropdown list. This method
28061 * is the runtime equivalent of setting the 'editable' config option at config time.
28062 * @param {Boolean} value True to allow the user to directly edit the field text
28064 setEditable : function(value){
28069 onBeforeLoad : function(){
28071 Roo.log("Select before load");
28074 this.innerList.update(this.loadingText ?
28075 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
28076 //this.restrictHeight();
28077 this.selectedIndex = -1;
28081 onLoad : function(){
28084 var dom = this.el.dom;
28085 dom.innerHTML = '';
28086 var od = dom.ownerDocument;
28088 if (this.emptyText) {
28089 var op = od.createElement('option');
28090 op.setAttribute('value', '');
28091 op.innerHTML = String.format('{0}', this.emptyText);
28092 dom.appendChild(op);
28094 if(this.store.getCount() > 0){
28096 var vf = this.valueField;
28097 var df = this.displayField;
28098 this.store.data.each(function(r) {
28099 // which colmsn to use... testing - cdoe / title..
28100 var op = od.createElement('option');
28101 op.setAttribute('value', r.data[vf]);
28102 op.innerHTML = String.format('{0}', r.data[df]);
28103 dom.appendChild(op);
28105 if (typeof(this.defaultValue != 'undefined')) {
28106 this.setValue(this.defaultValue);
28111 //this.onEmptyResults();
28116 onLoadException : function()
28118 dom.innerHTML = '';
28120 Roo.log("Select on load exception");
28124 Roo.log(this.store.reader.jsonData);
28125 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
28126 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
28132 onTypeAhead : function(){
28137 onSelect : function(record, index){
28138 Roo.log('on select?');
28140 if(this.fireEvent('beforeselect', this, record, index) !== false){
28141 this.setFromData(index > -1 ? record.data : false);
28143 this.fireEvent('select', this, record, index);
28148 * Returns the currently selected field value or empty string if no value is set.
28149 * @return {String} value The selected value
28151 getValue : function(){
28152 var dom = this.el.dom;
28153 this.value = dom.options[dom.selectedIndex].value;
28159 * Clears any text/value currently set in the field
28161 clearValue : function(){
28163 this.el.dom.selectedIndex = this.emptyText ? 0 : -1;
28168 * Sets the specified value into the field. If the value finds a match, the corresponding record text
28169 * will be displayed in the field. If the value does not match the data value of an existing item,
28170 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
28171 * Otherwise the field will be blank (although the value will still be set).
28172 * @param {String} value The value to match
28174 setValue : function(v){
28175 var d = this.el.dom;
28176 for (var i =0; i < d.options.length;i++) {
28177 if (v == d.options[i].value) {
28178 d.selectedIndex = i;
28186 * @property {Object} the last set data for the element
28191 * Sets the value of the field based on a object which is related to the record format for the store.
28192 * @param {Object} value the value to set as. or false on reset?
28194 setFromData : function(o){
28195 Roo.log('setfrom data?');
28201 reset : function(){
28205 findRecord : function(prop, value){
28210 if(this.store.getCount() > 0){
28211 this.store.each(function(r){
28212 if(r.data[prop] == value){
28222 getName: function()
28224 // returns hidden if it's set..
28225 if (!this.rendered) {return ''};
28226 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
28234 onEmptyResults : function(){
28235 Roo.log('empty results');
28240 * Returns true if the dropdown list is expanded, else false.
28242 isExpanded : function(){
28247 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
28248 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
28249 * @param {String} value The data value of the item to select
28250 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
28251 * selected item if it is not currently in view (defaults to true)
28252 * @return {Boolean} True if the value matched an item in the list, else false
28254 selectByValue : function(v, scrollIntoView){
28255 Roo.log('select By Value');
28258 if(v !== undefined && v !== null){
28259 var r = this.findRecord(this.valueField || this.displayField, v);
28261 this.select(this.store.indexOf(r), scrollIntoView);
28269 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
28270 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
28271 * @param {Number} index The zero-based index of the list item to select
28272 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
28273 * selected item if it is not currently in view (defaults to true)
28275 select : function(index, scrollIntoView){
28276 Roo.log('select ');
28279 this.selectedIndex = index;
28280 this.view.select(index);
28281 if(scrollIntoView !== false){
28282 var el = this.view.getNode(index);
28284 this.innerList.scrollChildIntoView(el, false);
28292 validateBlur : function(){
28299 initQuery : function(){
28300 this.doQuery(this.getRawValue());
28304 doForce : function(){
28305 if(this.el.dom.value.length > 0){
28306 this.el.dom.value =
28307 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
28313 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
28314 * query allowing the query action to be canceled if needed.
28315 * @param {String} query The SQL query to execute
28316 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
28317 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
28318 * saved in the current store (defaults to false)
28320 doQuery : function(q, forceAll){
28322 Roo.log('doQuery?');
28323 if(q === undefined || q === null){
28328 forceAll: forceAll,
28332 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
28336 forceAll = qe.forceAll;
28337 if(forceAll === true || (q.length >= this.minChars)){
28338 if(this.lastQuery != q || this.alwaysQuery){
28339 this.lastQuery = q;
28340 if(this.mode == 'local'){
28341 this.selectedIndex = -1;
28343 this.store.clearFilter();
28345 this.store.filter(this.displayField, q);
28349 this.store.baseParams[this.queryParam] = q;
28351 params: this.getParams(q)
28356 this.selectedIndex = -1;
28363 getParams : function(q){
28365 //p[this.queryParam] = q;
28368 p.limit = this.pageSize;
28374 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
28376 collapse : function(){
28381 collapseIf : function(e){
28386 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
28388 expand : function(){
28396 * @cfg {Boolean} grow
28400 * @cfg {Number} growMin
28404 * @cfg {Number} growMax
28412 setWidth : function()
28416 getResizeEl : function(){
28419 });//<script type="text/javasscript">
28423 * @class Roo.DDView
28424 * A DnD enabled version of Roo.View.
28425 * @param {Element/String} container The Element in which to create the View.
28426 * @param {String} tpl The template string used to create the markup for each element of the View
28427 * @param {Object} config The configuration properties. These include all the config options of
28428 * {@link Roo.View} plus some specific to this class.<br>
28430 * Drag/drop is implemented by adding {@link Roo.data.Record}s to the target DDView. If copying is
28431 * not being performed, the original {@link Roo.data.Record} is removed from the source DDView.<br>
28433 * The following extra CSS rules are needed to provide insertion point highlighting:<pre><code>
28434 .x-view-drag-insert-above {
28435 border-top:1px dotted #3366cc;
28437 .x-view-drag-insert-below {
28438 border-bottom:1px dotted #3366cc;
28444 Roo.DDView = function(container, tpl, config) {
28445 Roo.DDView.superclass.constructor.apply(this, arguments);
28446 this.getEl().setStyle("outline", "0px none");
28447 this.getEl().unselectable();
28448 if (this.dragGroup) {
28449 this.setDraggable(this.dragGroup.split(","));
28451 if (this.dropGroup) {
28452 this.setDroppable(this.dropGroup.split(","));
28454 if (this.deletable) {
28455 this.setDeletable();
28457 this.isDirtyFlag = false;
28463 Roo.extend(Roo.DDView, Roo.View, {
28464 /** @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone. */
28465 /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
28466 /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
28467 /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
28471 reset: Roo.emptyFn,
28473 clearInvalid: Roo.form.Field.prototype.clearInvalid,
28475 validate: function() {
28479 destroy: function() {
28480 this.purgeListeners();
28481 this.getEl.removeAllListeners();
28482 this.getEl().remove();
28483 if (this.dragZone) {
28484 if (this.dragZone.destroy) {
28485 this.dragZone.destroy();
28488 if (this.dropZone) {
28489 if (this.dropZone.destroy) {
28490 this.dropZone.destroy();
28495 /** Allows this class to be an Roo.form.Field so it can be found using {@link Roo.form.BasicForm#findField}. */
28496 getName: function() {
28500 /** Loads the View from a JSON string representing the Records to put into the Store. */
28501 setValue: function(v) {
28503 throw "DDView.setValue(). DDView must be constructed with a valid Store";
28506 data[this.store.reader.meta.root] = v ? [].concat(v) : [];
28507 this.store.proxy = new Roo.data.MemoryProxy(data);
28511 /** @return {String} a parenthesised list of the ids of the Records in the View. */
28512 getValue: function() {
28514 this.store.each(function(rec) {
28515 result += rec.id + ',';
28517 return result.substr(0, result.length - 1) + ')';
28520 getIds: function() {
28521 var i = 0, result = new Array(this.store.getCount());
28522 this.store.each(function(rec) {
28523 result[i++] = rec.id;
28528 isDirty: function() {
28529 return this.isDirtyFlag;
28533 * Part of the Roo.dd.DropZone interface. If no target node is found, the
28534 * whole Element becomes the target, and this causes the drop gesture to append.
28536 getTargetFromEvent : function(e) {
28537 var target = e.getTarget();
28538 while ((target !== null) && (target.parentNode != this.el.dom)) {
28539 target = target.parentNode;
28542 target = this.el.dom.lastChild || this.el.dom;
28548 * Create the drag data which consists of an object which has the property "ddel" as
28549 * the drag proxy element.
28551 getDragData : function(e) {
28552 var target = this.findItemFromChild(e.getTarget());
28554 this.handleSelection(e);
28555 var selNodes = this.getSelectedNodes();
28558 copy: this.copy || (this.allowCopy && e.ctrlKey),
28562 var selectedIndices = this.getSelectedIndexes();
28563 for (var i = 0; i < selectedIndices.length; i++) {
28564 dragData.records.push(this.store.getAt(selectedIndices[i]));
28566 if (selNodes.length == 1) {
28567 dragData.ddel = target.cloneNode(true); // the div element
28569 var div = document.createElement('div'); // create the multi element drag "ghost"
28570 div.className = 'multi-proxy';
28571 for (var i = 0, len = selNodes.length; i < len; i++) {
28572 div.appendChild(selNodes[i].cloneNode(true));
28574 dragData.ddel = div;
28576 //console.log(dragData)
28577 //console.log(dragData.ddel.innerHTML)
28580 //console.log('nodragData')
28584 /** Specify to which ddGroup items in this DDView may be dragged. */
28585 setDraggable: function(ddGroup) {
28586 if (ddGroup instanceof Array) {
28587 Roo.each(ddGroup, this.setDraggable, this);
28590 if (this.dragZone) {
28591 this.dragZone.addToGroup(ddGroup);
28593 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
28594 containerScroll: true,
28598 // Draggability implies selection. DragZone's mousedown selects the element.
28599 if (!this.multiSelect) { this.singleSelect = true; }
28601 // Wire the DragZone's handlers up to methods in *this*
28602 this.dragZone.getDragData = this.getDragData.createDelegate(this);
28606 /** Specify from which ddGroup this DDView accepts drops. */
28607 setDroppable: function(ddGroup) {
28608 if (ddGroup instanceof Array) {
28609 Roo.each(ddGroup, this.setDroppable, this);
28612 if (this.dropZone) {
28613 this.dropZone.addToGroup(ddGroup);
28615 this.dropZone = new Roo.dd.DropZone(this.getEl(), {
28616 containerScroll: true,
28620 // Wire the DropZone's handlers up to methods in *this*
28621 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
28622 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
28623 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
28624 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
28625 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
28629 /** Decide whether to drop above or below a View node. */
28630 getDropPoint : function(e, n, dd){
28631 if (n == this.el.dom) { return "above"; }
28632 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
28633 var c = t + (b - t) / 2;
28634 var y = Roo.lib.Event.getPageY(e);
28642 onNodeEnter : function(n, dd, e, data){
28646 onNodeOver : function(n, dd, e, data){
28647 var pt = this.getDropPoint(e, n, dd);
28648 // set the insert point style on the target node
28649 var dragElClass = this.dropNotAllowed;
28652 if (pt == "above"){
28653 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
28654 targetElClass = "x-view-drag-insert-above";
28656 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
28657 targetElClass = "x-view-drag-insert-below";
28659 if (this.lastInsertClass != targetElClass){
28660 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
28661 this.lastInsertClass = targetElClass;
28664 return dragElClass;
28667 onNodeOut : function(n, dd, e, data){
28668 this.removeDropIndicators(n);
28671 onNodeDrop : function(n, dd, e, data){
28672 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
28675 var pt = this.getDropPoint(e, n, dd);
28676 var insertAt = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
28677 if (pt == "below") { insertAt++; }
28678 for (var i = 0; i < data.records.length; i++) {
28679 var r = data.records[i];
28680 var dup = this.store.getById(r.id);
28681 if (dup && (dd != this.dragZone)) {
28682 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
28685 this.store.insert(insertAt++, r.copy());
28687 data.source.isDirtyFlag = true;
28689 this.store.insert(insertAt++, r);
28691 this.isDirtyFlag = true;
28694 this.dragZone.cachedTarget = null;
28698 removeDropIndicators : function(n){
28700 Roo.fly(n).removeClass([
28701 "x-view-drag-insert-above",
28702 "x-view-drag-insert-below"]);
28703 this.lastInsertClass = "_noclass";
28708 * Utility method. Add a delete option to the DDView's context menu.
28709 * @param {String} imageUrl The URL of the "delete" icon image.
28711 setDeletable: function(imageUrl) {
28712 if (!this.singleSelect && !this.multiSelect) {
28713 this.singleSelect = true;
28715 var c = this.getContextMenu();
28716 this.contextMenu.on("itemclick", function(item) {
28719 this.remove(this.getSelectedIndexes());
28723 this.contextMenu.add({
28730 /** Return the context menu for this DDView. */
28731 getContextMenu: function() {
28732 if (!this.contextMenu) {
28733 // Create the View's context menu
28734 this.contextMenu = new Roo.menu.Menu({
28735 id: this.id + "-contextmenu"
28737 this.el.on("contextmenu", this.showContextMenu, this);
28739 return this.contextMenu;
28742 disableContextMenu: function() {
28743 if (this.contextMenu) {
28744 this.el.un("contextmenu", this.showContextMenu, this);
28748 showContextMenu: function(e, item) {
28749 item = this.findItemFromChild(e.getTarget());
28752 this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true);
28753 this.contextMenu.showAt(e.getXY());
28758 * Remove {@link Roo.data.Record}s at the specified indices.
28759 * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove.
28761 remove: function(selectedIndices) {
28762 selectedIndices = [].concat(selectedIndices);
28763 for (var i = 0; i < selectedIndices.length; i++) {
28764 var rec = this.store.getAt(selectedIndices[i]);
28765 this.store.remove(rec);
28770 * Double click fires the event, but also, if this is draggable, and there is only one other
28771 * related DropZone, it transfers the selected node.
28773 onDblClick : function(e){
28774 var item = this.findItemFromChild(e.getTarget());
28776 if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) {
28779 if (this.dragGroup) {
28780 var targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
28781 while (targets.indexOf(this.dropZone) > -1) {
28782 targets.remove(this.dropZone);
28784 if (targets.length == 1) {
28785 this.dragZone.cachedTarget = null;
28786 var el = Roo.get(targets[0].getEl());
28787 var box = el.getBox(true);
28788 targets[0].onNodeDrop(el.dom, {
28790 xy: [box.x, box.y + box.height - 1]
28791 }, null, this.getDragData(e));
28797 handleSelection: function(e) {
28798 this.dragZone.cachedTarget = null;
28799 var item = this.findItemFromChild(e.getTarget());
28801 this.clearSelections(true);
28804 if (item && (this.multiSelect || this.singleSelect)){
28805 if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
28806 this.select(this.getNodes(this.indexOf(this.lastSelection), item.nodeIndex), false);
28807 }else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
28808 this.unselect(item);
28810 this.select(item, this.multiSelect && e.ctrlKey);
28811 this.lastSelection = item;
28816 onItemClick : function(item, index, e){
28817 if(this.fireEvent("beforeclick", this, index, item, e) === false){
28823 unselect : function(nodeInfo, suppressEvent){
28824 var node = this.getNode(nodeInfo);
28825 if(node && this.isSelected(node)){
28826 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
28827 Roo.fly(node).removeClass(this.selectedClass);
28828 this.selections.remove(node);
28829 if(!suppressEvent){
28830 this.fireEvent("selectionchange", this, this.selections);
28838 * Ext JS Library 1.1.1
28839 * Copyright(c) 2006-2007, Ext JS, LLC.
28841 * Originally Released Under LGPL - original licence link has changed is not relivant.
28844 * <script type="text/javascript">
28848 * @class Roo.LayoutManager
28849 * @extends Roo.util.Observable
28850 * Base class for layout managers.
28852 Roo.LayoutManager = function(container, config){
28853 Roo.LayoutManager.superclass.constructor.call(this);
28854 this.el = Roo.get(container);
28855 // ie scrollbar fix
28856 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
28857 document.body.scroll = "no";
28858 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
28859 this.el.position('relative');
28861 this.id = this.el.id;
28862 this.el.addClass("x-layout-container");
28863 /** false to disable window resize monitoring @type Boolean */
28864 this.monitorWindowResize = true;
28869 * Fires when a layout is performed.
28870 * @param {Roo.LayoutManager} this
28874 * @event regionresized
28875 * Fires when the user resizes a region.
28876 * @param {Roo.LayoutRegion} region The resized region
28877 * @param {Number} newSize The new size (width for east/west, height for north/south)
28879 "regionresized" : true,
28881 * @event regioncollapsed
28882 * Fires when a region is collapsed.
28883 * @param {Roo.LayoutRegion} region The collapsed region
28885 "regioncollapsed" : true,
28887 * @event regionexpanded
28888 * Fires when a region is expanded.
28889 * @param {Roo.LayoutRegion} region The expanded region
28891 "regionexpanded" : true
28893 this.updating = false;
28894 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
28897 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
28899 * Returns true if this layout is currently being updated
28900 * @return {Boolean}
28902 isUpdating : function(){
28903 return this.updating;
28907 * Suspend the LayoutManager from doing auto-layouts while
28908 * making multiple add or remove calls
28910 beginUpdate : function(){
28911 this.updating = true;
28915 * Restore auto-layouts and optionally disable the manager from performing a layout
28916 * @param {Boolean} noLayout true to disable a layout update
28918 endUpdate : function(noLayout){
28919 this.updating = false;
28925 layout: function(){
28929 onRegionResized : function(region, newSize){
28930 this.fireEvent("regionresized", region, newSize);
28934 onRegionCollapsed : function(region){
28935 this.fireEvent("regioncollapsed", region);
28938 onRegionExpanded : function(region){
28939 this.fireEvent("regionexpanded", region);
28943 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
28944 * performs box-model adjustments.
28945 * @return {Object} The size as an object {width: (the width), height: (the height)}
28947 getViewSize : function(){
28949 if(this.el.dom != document.body){
28950 size = this.el.getSize();
28952 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
28954 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
28955 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
28960 * Returns the Element this layout is bound to.
28961 * @return {Roo.Element}
28963 getEl : function(){
28968 * Returns the specified region.
28969 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
28970 * @return {Roo.LayoutRegion}
28972 getRegion : function(target){
28973 return this.regions[target.toLowerCase()];
28976 onWindowResize : function(){
28977 if(this.monitorWindowResize){
28983 * Ext JS Library 1.1.1
28984 * Copyright(c) 2006-2007, Ext JS, LLC.
28986 * Originally Released Under LGPL - original licence link has changed is not relivant.
28989 * <script type="text/javascript">
28992 * @class Roo.BorderLayout
28993 * @extends Roo.LayoutManager
28994 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
28995 * please see: <br><br>
28996 * <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>
28997 * <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>
29000 var layout = new Roo.BorderLayout(document.body, {
29034 preferredTabWidth: 150
29039 var CP = Roo.ContentPanel;
29041 layout.beginUpdate();
29042 layout.add("north", new CP("north", "North"));
29043 layout.add("south", new CP("south", {title: "South", closable: true}));
29044 layout.add("west", new CP("west", {title: "West"}));
29045 layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
29046 layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
29047 layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
29048 layout.getRegion("center").showPanel("center1");
29049 layout.endUpdate();
29052 <b>The container the layout is rendered into can be either the body element or any other element.
29053 If it is not the body element, the container needs to either be an absolute positioned element,
29054 or you will need to add "position:relative" to the css of the container. You will also need to specify
29055 the container size if it is not the body element.</b>
29058 * Create a new BorderLayout
29059 * @param {String/HTMLElement/Element} container The container this layout is bound to
29060 * @param {Object} config Configuration options
29062 Roo.BorderLayout = function(container, config){
29063 config = config || {};
29064 Roo.BorderLayout.superclass.constructor.call(this, container, config);
29065 this.factory = config.factory || Roo.BorderLayout.RegionFactory;
29066 for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
29067 var target = this.factory.validRegions[i];
29068 if(config[target]){
29069 this.addRegion(target, config[target]);
29074 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
29076 * Creates and adds a new region if it doesn't already exist.
29077 * @param {String} target The target region key (north, south, east, west or center).
29078 * @param {Object} config The regions config object
29079 * @return {BorderLayoutRegion} The new region
29081 addRegion : function(target, config){
29082 if(!this.regions[target]){
29083 var r = this.factory.create(target, this, config);
29084 this.bindRegion(target, r);
29086 return this.regions[target];
29090 bindRegion : function(name, r){
29091 this.regions[name] = r;
29092 r.on("visibilitychange", this.layout, this);
29093 r.on("paneladded", this.layout, this);
29094 r.on("panelremoved", this.layout, this);
29095 r.on("invalidated", this.layout, this);
29096 r.on("resized", this.onRegionResized, this);
29097 r.on("collapsed", this.onRegionCollapsed, this);
29098 r.on("expanded", this.onRegionExpanded, this);
29102 * Performs a layout update.
29104 layout : function(){
29105 if(this.updating) {
29108 var size = this.getViewSize();
29109 var w = size.width;
29110 var h = size.height;
29115 //var x = 0, y = 0;
29117 var rs = this.regions;
29118 var north = rs["north"];
29119 var south = rs["south"];
29120 var west = rs["west"];
29121 var east = rs["east"];
29122 var center = rs["center"];
29123 //if(this.hideOnLayout){ // not supported anymore
29124 //c.el.setStyle("display", "none");
29126 if(north && north.isVisible()){
29127 var b = north.getBox();
29128 var m = north.getMargins();
29129 b.width = w - (m.left+m.right);
29132 centerY = b.height + b.y + m.bottom;
29133 centerH -= centerY;
29134 north.updateBox(this.safeBox(b));
29136 if(south && south.isVisible()){
29137 var b = south.getBox();
29138 var m = south.getMargins();
29139 b.width = w - (m.left+m.right);
29141 var totalHeight = (b.height + m.top + m.bottom);
29142 b.y = h - totalHeight + m.top;
29143 centerH -= totalHeight;
29144 south.updateBox(this.safeBox(b));
29146 if(west && west.isVisible()){
29147 var b = west.getBox();
29148 var m = west.getMargins();
29149 b.height = centerH - (m.top+m.bottom);
29151 b.y = centerY + m.top;
29152 var totalWidth = (b.width + m.left + m.right);
29153 centerX += totalWidth;
29154 centerW -= totalWidth;
29155 west.updateBox(this.safeBox(b));
29157 if(east && east.isVisible()){
29158 var b = east.getBox();
29159 var m = east.getMargins();
29160 b.height = centerH - (m.top+m.bottom);
29161 var totalWidth = (b.width + m.left + m.right);
29162 b.x = w - totalWidth + m.left;
29163 b.y = centerY + m.top;
29164 centerW -= totalWidth;
29165 east.updateBox(this.safeBox(b));
29168 var m = center.getMargins();
29170 x: centerX + m.left,
29171 y: centerY + m.top,
29172 width: centerW - (m.left+m.right),
29173 height: centerH - (m.top+m.bottom)
29175 //if(this.hideOnLayout){
29176 //center.el.setStyle("display", "block");
29178 center.updateBox(this.safeBox(centerBox));
29181 this.fireEvent("layout", this);
29185 safeBox : function(box){
29186 box.width = Math.max(0, box.width);
29187 box.height = Math.max(0, box.height);
29192 * Adds a ContentPanel (or subclass) to this layout.
29193 * @param {String} target The target region key (north, south, east, west or center).
29194 * @param {Roo.ContentPanel} panel The panel to add
29195 * @return {Roo.ContentPanel} The added panel
29197 add : function(target, panel){
29199 target = target.toLowerCase();
29200 return this.regions[target].add(panel);
29204 * Remove a ContentPanel (or subclass) to this layout.
29205 * @param {String} target The target region key (north, south, east, west or center).
29206 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
29207 * @return {Roo.ContentPanel} The removed panel
29209 remove : function(target, panel){
29210 target = target.toLowerCase();
29211 return this.regions[target].remove(panel);
29215 * Searches all regions for a panel with the specified id
29216 * @param {String} panelId
29217 * @return {Roo.ContentPanel} The panel or null if it wasn't found
29219 findPanel : function(panelId){
29220 var rs = this.regions;
29221 for(var target in rs){
29222 if(typeof rs[target] != "function"){
29223 var p = rs[target].getPanel(panelId);
29233 * Searches all regions for a panel with the specified id and activates (shows) it.
29234 * @param {String/ContentPanel} panelId The panels id or the panel itself
29235 * @return {Roo.ContentPanel} The shown panel or null
29237 showPanel : function(panelId) {
29238 var rs = this.regions;
29239 for(var target in rs){
29240 var r = rs[target];
29241 if(typeof r != "function"){
29242 if(r.hasPanel(panelId)){
29243 return r.showPanel(panelId);
29251 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
29252 * @param {Roo.state.Provider} provider (optional) An alternate state provider
29254 restoreState : function(provider){
29256 provider = Roo.state.Manager;
29258 var sm = new Roo.LayoutStateManager();
29259 sm.init(this, provider);
29263 * Adds a batch of multiple ContentPanels dynamically by passing a special regions config object. This config
29264 * object should contain properties for each region to add ContentPanels to, and each property's value should be
29265 * a valid ContentPanel config object. Example:
29267 // Create the main layout
29268 var layout = new Roo.BorderLayout('main-ct', {
29279 // Create and add multiple ContentPanels at once via configs
29282 id: 'source-files',
29284 title:'Ext Source Files',
29297 * @param {Object} regions An object containing ContentPanel configs by region name
29299 batchAdd : function(regions){
29300 this.beginUpdate();
29301 for(var rname in regions){
29302 var lr = this.regions[rname];
29304 this.addTypedPanels(lr, regions[rname]);
29311 addTypedPanels : function(lr, ps){
29312 if(typeof ps == 'string'){
29313 lr.add(new Roo.ContentPanel(ps));
29315 else if(ps instanceof Array){
29316 for(var i =0, len = ps.length; i < len; i++){
29317 this.addTypedPanels(lr, ps[i]);
29320 else if(!ps.events){ // raw config?
29322 delete ps.el; // prevent conflict
29323 lr.add(new Roo.ContentPanel(el || Roo.id(), ps));
29325 else { // panel object assumed!
29330 * Adds a xtype elements to the layout.
29334 xtype : 'ContentPanel',
29341 xtype : 'NestedLayoutPanel',
29347 items : [ ... list of content panels or nested layout panels.. ]
29351 * @param {Object} cfg Xtype definition of item to add.
29353 addxtype : function(cfg)
29355 // basically accepts a pannel...
29356 // can accept a layout region..!?!?
29357 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
29359 if (!cfg.xtype.match(/Panel$/)) {
29364 if (typeof(cfg.region) == 'undefined') {
29365 Roo.log("Failed to add Panel, region was not set");
29369 var region = cfg.region;
29375 xitems = cfg.items;
29382 case 'ContentPanel': // ContentPanel (el, cfg)
29383 case 'ScrollPanel': // ContentPanel (el, cfg)
29385 if(cfg.autoCreate) {
29386 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29388 var el = this.el.createChild();
29389 ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
29392 this.add(region, ret);
29396 case 'TreePanel': // our new panel!
29397 cfg.el = this.el.createChild();
29398 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29399 this.add(region, ret);
29402 case 'NestedLayoutPanel':
29403 // create a new Layout (which is a Border Layout...
29404 var el = this.el.createChild();
29405 var clayout = cfg.layout;
29407 clayout.items = clayout.items || [];
29408 // replace this exitems with the clayout ones..
29409 xitems = clayout.items;
29412 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
29413 cfg.background = false;
29415 var layout = new Roo.BorderLayout(el, clayout);
29417 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
29418 //console.log('adding nested layout panel ' + cfg.toSource());
29419 this.add(region, ret);
29420 nb = {}; /// find first...
29425 // needs grid and region
29427 //var el = this.getRegion(region).el.createChild();
29428 var el = this.el.createChild();
29429 // create the grid first...
29431 var grid = new Roo.grid[cfg.grid.xtype](el, cfg.grid);
29433 if (region == 'center' && this.active ) {
29434 cfg.background = false;
29436 ret = new Roo[cfg.xtype](grid, cfg); // new panel!!!!!
29438 this.add(region, ret);
29439 if (cfg.background) {
29440 ret.on('activate', function(gp) {
29441 if (!gp.grid.rendered) {
29456 if (typeof(Roo[cfg.xtype]) != 'undefined') {
29458 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29459 this.add(region, ret);
29462 alert("Can not add '" + cfg.xtype + "' to BorderLayout");
29466 // GridPanel (grid, cfg)
29469 this.beginUpdate();
29473 Roo.each(xitems, function(i) {
29474 region = nb && i.region ? i.region : false;
29476 var add = ret.addxtype(i);
29479 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
29480 if (!i.background) {
29481 abn[region] = nb[region] ;
29488 // make the last non-background panel active..
29489 //if (nb) { Roo.log(abn); }
29492 for(var r in abn) {
29493 region = this.getRegion(r);
29495 // tried using nb[r], but it does not work..
29497 region.showPanel(abn[r]);
29508 * Shortcut for creating a new BorderLayout object and adding one or more ContentPanels to it in a single step, handling
29509 * the beginUpdate and endUpdate calls internally. The key to this method is the <b>panels</b> property that can be
29510 * provided with each region config, which allows you to add ContentPanel configs in addition to the region configs
29511 * during creation. The following code is equivalent to the constructor-based example at the beginning of this class:
29514 var CP = Roo.ContentPanel;
29516 var layout = Roo.BorderLayout.create({
29520 panels: [new CP("north", "North")]
29529 panels: [new CP("west", {title: "West"})]
29538 panels: [new CP("autoTabs", {title: "Auto Tabs", closable: true})]
29547 panels: [new CP("south", {title: "South", closable: true})]
29554 preferredTabWidth: 150,
29556 new CP("center1", {title: "Close Me", closable: true}),
29557 new CP("center2", {title: "Center Panel", closable: false})
29562 layout.getRegion("center").showPanel("center1");
29567 Roo.BorderLayout.create = function(config, targetEl){
29568 var layout = new Roo.BorderLayout(targetEl || document.body, config);
29569 layout.beginUpdate();
29570 var regions = Roo.BorderLayout.RegionFactory.validRegions;
29571 for(var j = 0, jlen = regions.length; j < jlen; j++){
29572 var lr = regions[j];
29573 if(layout.regions[lr] && config[lr].panels){
29574 var r = layout.regions[lr];
29575 var ps = config[lr].panels;
29576 layout.addTypedPanels(r, ps);
29579 layout.endUpdate();
29584 Roo.BorderLayout.RegionFactory = {
29586 validRegions : ["north","south","east","west","center"],
29589 create : function(target, mgr, config){
29590 target = target.toLowerCase();
29591 if(config.lightweight || config.basic){
29592 return new Roo.BasicLayoutRegion(mgr, config, target);
29596 return new Roo.NorthLayoutRegion(mgr, config);
29598 return new Roo.SouthLayoutRegion(mgr, config);
29600 return new Roo.EastLayoutRegion(mgr, config);
29602 return new Roo.WestLayoutRegion(mgr, config);
29604 return new Roo.CenterLayoutRegion(mgr, config);
29606 throw 'Layout region "'+target+'" not supported.';
29610 * Ext JS Library 1.1.1
29611 * Copyright(c) 2006-2007, Ext JS, LLC.
29613 * Originally Released Under LGPL - original licence link has changed is not relivant.
29616 * <script type="text/javascript">
29620 * @class Roo.BasicLayoutRegion
29621 * @extends Roo.util.Observable
29622 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
29623 * and does not have a titlebar, tabs or any other features. All it does is size and position
29624 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
29626 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
29628 this.position = pos;
29631 * @scope Roo.BasicLayoutRegion
29635 * @event beforeremove
29636 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
29637 * @param {Roo.LayoutRegion} this
29638 * @param {Roo.ContentPanel} panel The panel
29639 * @param {Object} e The cancel event object
29641 "beforeremove" : true,
29643 * @event invalidated
29644 * Fires when the layout for this region is changed.
29645 * @param {Roo.LayoutRegion} this
29647 "invalidated" : true,
29649 * @event visibilitychange
29650 * Fires when this region is shown or hidden
29651 * @param {Roo.LayoutRegion} this
29652 * @param {Boolean} visibility true or false
29654 "visibilitychange" : true,
29656 * @event paneladded
29657 * Fires when a panel is added.
29658 * @param {Roo.LayoutRegion} this
29659 * @param {Roo.ContentPanel} panel The panel
29661 "paneladded" : true,
29663 * @event panelremoved
29664 * Fires when a panel is removed.
29665 * @param {Roo.LayoutRegion} this
29666 * @param {Roo.ContentPanel} panel The panel
29668 "panelremoved" : true,
29670 * @event beforecollapse
29671 * Fires when this region before collapse.
29672 * @param {Roo.LayoutRegion} this
29674 "beforecollapse" : true,
29677 * Fires when this region is collapsed.
29678 * @param {Roo.LayoutRegion} this
29680 "collapsed" : true,
29683 * Fires when this region is expanded.
29684 * @param {Roo.LayoutRegion} this
29689 * Fires when this region is slid into view.
29690 * @param {Roo.LayoutRegion} this
29692 "slideshow" : true,
29695 * Fires when this region slides out of view.
29696 * @param {Roo.LayoutRegion} this
29698 "slidehide" : true,
29700 * @event panelactivated
29701 * Fires when a panel is activated.
29702 * @param {Roo.LayoutRegion} this
29703 * @param {Roo.ContentPanel} panel The activated panel
29705 "panelactivated" : true,
29708 * Fires when the user resizes this region.
29709 * @param {Roo.LayoutRegion} this
29710 * @param {Number} newSize The new size (width for east/west, height for north/south)
29714 /** A collection of panels in this region. @type Roo.util.MixedCollection */
29715 this.panels = new Roo.util.MixedCollection();
29716 this.panels.getKey = this.getPanelId.createDelegate(this);
29718 this.activePanel = null;
29719 // ensure listeners are added...
29721 if (config.listeners || config.events) {
29722 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
29723 listeners : config.listeners || {},
29724 events : config.events || {}
29728 if(skipConfig !== true){
29729 this.applyConfig(config);
29733 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
29734 getPanelId : function(p){
29738 applyConfig : function(config){
29739 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
29740 this.config = config;
29745 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
29746 * the width, for horizontal (north, south) the height.
29747 * @param {Number} newSize The new width or height
29749 resizeTo : function(newSize){
29750 var el = this.el ? this.el :
29751 (this.activePanel ? this.activePanel.getEl() : null);
29753 switch(this.position){
29756 el.setWidth(newSize);
29757 this.fireEvent("resized", this, newSize);
29761 el.setHeight(newSize);
29762 this.fireEvent("resized", this, newSize);
29768 getBox : function(){
29769 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
29772 getMargins : function(){
29773 return this.margins;
29776 updateBox : function(box){
29778 var el = this.activePanel.getEl();
29779 el.dom.style.left = box.x + "px";
29780 el.dom.style.top = box.y + "px";
29781 this.activePanel.setSize(box.width, box.height);
29785 * Returns the container element for this region.
29786 * @return {Roo.Element}
29788 getEl : function(){
29789 return this.activePanel;
29793 * Returns true if this region is currently visible.
29794 * @return {Boolean}
29796 isVisible : function(){
29797 return this.activePanel ? true : false;
29800 setActivePanel : function(panel){
29801 panel = this.getPanel(panel);
29802 if(this.activePanel && this.activePanel != panel){
29803 this.activePanel.setActiveState(false);
29804 this.activePanel.getEl().setLeftTop(-10000,-10000);
29806 this.activePanel = panel;
29807 panel.setActiveState(true);
29809 panel.setSize(this.box.width, this.box.height);
29811 this.fireEvent("panelactivated", this, panel);
29812 this.fireEvent("invalidated");
29816 * Show the specified panel.
29817 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
29818 * @return {Roo.ContentPanel} The shown panel or null
29820 showPanel : function(panel){
29821 if(panel = this.getPanel(panel)){
29822 this.setActivePanel(panel);
29828 * Get the active panel for this region.
29829 * @return {Roo.ContentPanel} The active panel or null
29831 getActivePanel : function(){
29832 return this.activePanel;
29836 * Add the passed ContentPanel(s)
29837 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
29838 * @return {Roo.ContentPanel} The panel added (if only one was added)
29840 add : function(panel){
29841 if(arguments.length > 1){
29842 for(var i = 0, len = arguments.length; i < len; i++) {
29843 this.add(arguments[i]);
29847 if(this.hasPanel(panel)){
29848 this.showPanel(panel);
29851 var el = panel.getEl();
29852 if(el.dom.parentNode != this.mgr.el.dom){
29853 this.mgr.el.dom.appendChild(el.dom);
29855 if(panel.setRegion){
29856 panel.setRegion(this);
29858 this.panels.add(panel);
29859 el.setStyle("position", "absolute");
29860 if(!panel.background){
29861 this.setActivePanel(panel);
29862 if(this.config.initialSize && this.panels.getCount()==1){
29863 this.resizeTo(this.config.initialSize);
29866 this.fireEvent("paneladded", this, panel);
29871 * Returns true if the panel is in this region.
29872 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
29873 * @return {Boolean}
29875 hasPanel : function(panel){
29876 if(typeof panel == "object"){ // must be panel obj
29877 panel = panel.getId();
29879 return this.getPanel(panel) ? true : false;
29883 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
29884 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
29885 * @param {Boolean} preservePanel Overrides the config preservePanel option
29886 * @return {Roo.ContentPanel} The panel that was removed
29888 remove : function(panel, preservePanel){
29889 panel = this.getPanel(panel);
29894 this.fireEvent("beforeremove", this, panel, e);
29895 if(e.cancel === true){
29898 var panelId = panel.getId();
29899 this.panels.removeKey(panelId);
29904 * Returns the panel specified or null if it's not in this region.
29905 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
29906 * @return {Roo.ContentPanel}
29908 getPanel : function(id){
29909 if(typeof id == "object"){ // must be panel obj
29912 return this.panels.get(id);
29916 * Returns this regions position (north/south/east/west/center).
29919 getPosition: function(){
29920 return this.position;
29924 * Ext JS Library 1.1.1
29925 * Copyright(c) 2006-2007, Ext JS, LLC.
29927 * Originally Released Under LGPL - original licence link has changed is not relivant.
29930 * <script type="text/javascript">
29934 * @class Roo.LayoutRegion
29935 * @extends Roo.BasicLayoutRegion
29936 * This class represents a region in a layout manager.
29937 * @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
29938 * @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
29939 * @cfg {Boolean} floatable False to disable floating (defaults to true)
29940 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
29941 * @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})
29942 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
29943 * @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
29944 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
29945 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
29946 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
29947 * @cfg {String} title The title for the region (overrides panel titles)
29948 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
29949 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
29950 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
29951 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
29952 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
29953 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
29954 * the space available, similar to FireFox 1.5 tabs (defaults to false)
29955 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
29956 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
29957 * @cfg {Boolean} showPin True to show a pin button
29958 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
29959 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
29960 * @cfg {Boolean} disableTabTips True to disable tab tooltips
29961 * @cfg {Number} width For East/West panels
29962 * @cfg {Number} height For North/South panels
29963 * @cfg {Boolean} split To show the splitter
29964 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
29966 Roo.LayoutRegion = function(mgr, config, pos){
29967 Roo.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
29968 var dh = Roo.DomHelper;
29969 /** This region's container element
29970 * @type Roo.Element */
29971 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
29972 /** This region's title element
29973 * @type Roo.Element */
29975 this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
29976 {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
29977 {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
29979 this.titleEl.enableDisplayMode();
29980 /** This region's title text element
29981 * @type HTMLElement */
29982 this.titleTextEl = this.titleEl.dom.firstChild;
29983 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
29984 this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
29985 this.closeBtn.enableDisplayMode();
29986 this.closeBtn.on("click", this.closeClicked, this);
29987 this.closeBtn.hide();
29989 this.createBody(config);
29990 this.visible = true;
29991 this.collapsed = false;
29993 if(config.hideWhenEmpty){
29995 this.on("paneladded", this.validateVisibility, this);
29996 this.on("panelremoved", this.validateVisibility, this);
29998 this.applyConfig(config);
30001 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
30003 createBody : function(){
30004 /** This region's body element
30005 * @type Roo.Element */
30006 this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
30009 applyConfig : function(c){
30010 if(c.collapsible && this.position != "center" && !this.collapsedEl){
30011 var dh = Roo.DomHelper;
30012 if(c.titlebar !== false){
30013 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
30014 this.collapseBtn.on("click", this.collapse, this);
30015 this.collapseBtn.enableDisplayMode();
30017 if(c.showPin === true || this.showPin){
30018 this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
30019 this.stickBtn.enableDisplayMode();
30020 this.stickBtn.on("click", this.expand, this);
30021 this.stickBtn.hide();
30024 /** This region's collapsed element
30025 * @type Roo.Element */
30026 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
30027 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
30029 if(c.floatable !== false){
30030 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
30031 this.collapsedEl.on("click", this.collapseClick, this);
30034 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
30035 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
30036 id: "message", unselectable: "on", style:{"float":"left"}});
30037 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
30039 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
30040 this.expandBtn.on("click", this.expand, this);
30042 if(this.collapseBtn){
30043 this.collapseBtn.setVisible(c.collapsible == true);
30045 this.cmargins = c.cmargins || this.cmargins ||
30046 (this.position == "west" || this.position == "east" ?
30047 {top: 0, left: 2, right:2, bottom: 0} :
30048 {top: 2, left: 0, right:0, bottom: 2});
30049 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
30050 this.bottomTabs = c.tabPosition != "top";
30051 this.autoScroll = c.autoScroll || false;
30052 if(this.autoScroll){
30053 this.bodyEl.setStyle("overflow", "auto");
30055 this.bodyEl.setStyle("overflow", "hidden");
30057 //if(c.titlebar !== false){
30058 if((!c.titlebar && !c.title) || c.titlebar === false){
30059 this.titleEl.hide();
30061 this.titleEl.show();
30063 this.titleTextEl.innerHTML = c.title;
30067 this.duration = c.duration || .30;
30068 this.slideDuration = c.slideDuration || .45;
30071 this.collapse(true);
30078 * Returns true if this region is currently visible.
30079 * @return {Boolean}
30081 isVisible : function(){
30082 return this.visible;
30086 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
30087 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
30089 setCollapsedTitle : function(title){
30090 title = title || " ";
30091 if(this.collapsedTitleTextEl){
30092 this.collapsedTitleTextEl.innerHTML = title;
30096 getBox : function(){
30098 if(!this.collapsed){
30099 b = this.el.getBox(false, true);
30101 b = this.collapsedEl.getBox(false, true);
30106 getMargins : function(){
30107 return this.collapsed ? this.cmargins : this.margins;
30110 highlight : function(){
30111 this.el.addClass("x-layout-panel-dragover");
30114 unhighlight : function(){
30115 this.el.removeClass("x-layout-panel-dragover");
30118 updateBox : function(box){
30120 if(!this.collapsed){
30121 this.el.dom.style.left = box.x + "px";
30122 this.el.dom.style.top = box.y + "px";
30123 this.updateBody(box.width, box.height);
30125 this.collapsedEl.dom.style.left = box.x + "px";
30126 this.collapsedEl.dom.style.top = box.y + "px";
30127 this.collapsedEl.setSize(box.width, box.height);
30130 this.tabs.autoSizeTabs();
30134 updateBody : function(w, h){
30136 this.el.setWidth(w);
30137 w -= this.el.getBorderWidth("rl");
30138 if(this.config.adjustments){
30139 w += this.config.adjustments[0];
30143 this.el.setHeight(h);
30144 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
30145 h -= this.el.getBorderWidth("tb");
30146 if(this.config.adjustments){
30147 h += this.config.adjustments[1];
30149 this.bodyEl.setHeight(h);
30151 h = this.tabs.syncHeight(h);
30154 if(this.panelSize){
30155 w = w !== null ? w : this.panelSize.width;
30156 h = h !== null ? h : this.panelSize.height;
30158 if(this.activePanel){
30159 var el = this.activePanel.getEl();
30160 w = w !== null ? w : el.getWidth();
30161 h = h !== null ? h : el.getHeight();
30162 this.panelSize = {width: w, height: h};
30163 this.activePanel.setSize(w, h);
30165 if(Roo.isIE && this.tabs){
30166 this.tabs.el.repaint();
30171 * Returns the container element for this region.
30172 * @return {Roo.Element}
30174 getEl : function(){
30179 * Hides this region.
30182 if(!this.collapsed){
30183 this.el.dom.style.left = "-2000px";
30186 this.collapsedEl.dom.style.left = "-2000px";
30187 this.collapsedEl.hide();
30189 this.visible = false;
30190 this.fireEvent("visibilitychange", this, false);
30194 * Shows this region if it was previously hidden.
30197 if(!this.collapsed){
30200 this.collapsedEl.show();
30202 this.visible = true;
30203 this.fireEvent("visibilitychange", this, true);
30206 closeClicked : function(){
30207 if(this.activePanel){
30208 this.remove(this.activePanel);
30212 collapseClick : function(e){
30214 e.stopPropagation();
30217 e.stopPropagation();
30223 * Collapses this region.
30224 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
30226 collapse : function(skipAnim, skipCheck){
30227 if(this.collapsed) {
30231 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
30233 this.collapsed = true;
30235 this.split.el.hide();
30237 if(this.config.animate && skipAnim !== true){
30238 this.fireEvent("invalidated", this);
30239 this.animateCollapse();
30241 this.el.setLocation(-20000,-20000);
30243 this.collapsedEl.show();
30244 this.fireEvent("collapsed", this);
30245 this.fireEvent("invalidated", this);
30251 animateCollapse : function(){
30256 * Expands this region if it was previously collapsed.
30257 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
30258 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
30260 expand : function(e, skipAnim){
30262 e.stopPropagation();
30264 if(!this.collapsed || this.el.hasActiveFx()) {
30268 this.afterSlideIn();
30271 this.collapsed = false;
30272 if(this.config.animate && skipAnim !== true){
30273 this.animateExpand();
30277 this.split.el.show();
30279 this.collapsedEl.setLocation(-2000,-2000);
30280 this.collapsedEl.hide();
30281 this.fireEvent("invalidated", this);
30282 this.fireEvent("expanded", this);
30286 animateExpand : function(){
30290 initTabs : function()
30292 this.bodyEl.setStyle("overflow", "hidden");
30293 var ts = new Roo.TabPanel(
30296 tabPosition: this.bottomTabs ? 'bottom' : 'top',
30297 disableTooltips: this.config.disableTabTips,
30298 toolbar : this.config.toolbar
30301 if(this.config.hideTabs){
30302 ts.stripWrap.setDisplayed(false);
30305 ts.resizeTabs = this.config.resizeTabs === true;
30306 ts.minTabWidth = this.config.minTabWidth || 40;
30307 ts.maxTabWidth = this.config.maxTabWidth || 250;
30308 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
30309 ts.monitorResize = false;
30310 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
30311 ts.bodyEl.addClass('x-layout-tabs-body');
30312 this.panels.each(this.initPanelAsTab, this);
30315 initPanelAsTab : function(panel){
30316 var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
30317 this.config.closeOnTab && panel.isClosable());
30318 if(panel.tabTip !== undefined){
30319 ti.setTooltip(panel.tabTip);
30321 ti.on("activate", function(){
30322 this.setActivePanel(panel);
30324 if(this.config.closeOnTab){
30325 ti.on("beforeclose", function(t, e){
30327 this.remove(panel);
30333 updatePanelTitle : function(panel, title){
30334 if(this.activePanel == panel){
30335 this.updateTitle(title);
30338 var ti = this.tabs.getTab(panel.getEl().id);
30340 if(panel.tabTip !== undefined){
30341 ti.setTooltip(panel.tabTip);
30346 updateTitle : function(title){
30347 if(this.titleTextEl && !this.config.title){
30348 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
30352 setActivePanel : function(panel){
30353 panel = this.getPanel(panel);
30354 if(this.activePanel && this.activePanel != panel){
30355 this.activePanel.setActiveState(false);
30357 this.activePanel = panel;
30358 panel.setActiveState(true);
30359 if(this.panelSize){
30360 panel.setSize(this.panelSize.width, this.panelSize.height);
30363 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
30365 this.updateTitle(panel.getTitle());
30367 this.fireEvent("invalidated", this);
30369 this.fireEvent("panelactivated", this, panel);
30373 * Shows the specified panel.
30374 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
30375 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
30377 showPanel : function(panel)
30379 panel = this.getPanel(panel);
30382 var tab = this.tabs.getTab(panel.getEl().id);
30383 if(tab.isHidden()){
30384 this.tabs.unhideTab(tab.id);
30388 this.setActivePanel(panel);
30395 * Get the active panel for this region.
30396 * @return {Roo.ContentPanel} The active panel or null
30398 getActivePanel : function(){
30399 return this.activePanel;
30402 validateVisibility : function(){
30403 if(this.panels.getCount() < 1){
30404 this.updateTitle(" ");
30405 this.closeBtn.hide();
30408 if(!this.isVisible()){
30415 * Adds the passed ContentPanel(s) to this region.
30416 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
30417 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
30419 add : function(panel){
30420 if(arguments.length > 1){
30421 for(var i = 0, len = arguments.length; i < len; i++) {
30422 this.add(arguments[i]);
30426 if(this.hasPanel(panel)){
30427 this.showPanel(panel);
30430 panel.setRegion(this);
30431 this.panels.add(panel);
30432 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
30433 this.bodyEl.dom.appendChild(panel.getEl().dom);
30434 if(panel.background !== true){
30435 this.setActivePanel(panel);
30437 this.fireEvent("paneladded", this, panel);
30443 this.initPanelAsTab(panel);
30445 if(panel.background !== true){
30446 this.tabs.activate(panel.getEl().id);
30448 this.fireEvent("paneladded", this, panel);
30453 * Hides the tab for the specified panel.
30454 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30456 hidePanel : function(panel){
30457 if(this.tabs && (panel = this.getPanel(panel))){
30458 this.tabs.hideTab(panel.getEl().id);
30463 * Unhides the tab for a previously hidden panel.
30464 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30466 unhidePanel : function(panel){
30467 if(this.tabs && (panel = this.getPanel(panel))){
30468 this.tabs.unhideTab(panel.getEl().id);
30472 clearPanels : function(){
30473 while(this.panels.getCount() > 0){
30474 this.remove(this.panels.first());
30479 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
30480 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30481 * @param {Boolean} preservePanel Overrides the config preservePanel option
30482 * @return {Roo.ContentPanel} The panel that was removed
30484 remove : function(panel, preservePanel){
30485 panel = this.getPanel(panel);
30490 this.fireEvent("beforeremove", this, panel, e);
30491 if(e.cancel === true){
30494 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
30495 var panelId = panel.getId();
30496 this.panels.removeKey(panelId);
30498 document.body.appendChild(panel.getEl().dom);
30501 this.tabs.removeTab(panel.getEl().id);
30502 }else if (!preservePanel){
30503 this.bodyEl.dom.removeChild(panel.getEl().dom);
30505 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
30506 var p = this.panels.first();
30507 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
30508 tempEl.appendChild(p.getEl().dom);
30509 this.bodyEl.update("");
30510 this.bodyEl.dom.appendChild(p.getEl().dom);
30512 this.updateTitle(p.getTitle());
30514 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
30515 this.setActivePanel(p);
30517 panel.setRegion(null);
30518 if(this.activePanel == panel){
30519 this.activePanel = null;
30521 if(this.config.autoDestroy !== false && preservePanel !== true){
30522 try{panel.destroy();}catch(e){}
30524 this.fireEvent("panelremoved", this, panel);
30529 * Returns the TabPanel component used by this region
30530 * @return {Roo.TabPanel}
30532 getTabs : function(){
30536 createTool : function(parentEl, className){
30537 var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
30538 children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
30539 btn.addClassOnOver("x-layout-tools-button-over");
30544 * Ext JS Library 1.1.1
30545 * Copyright(c) 2006-2007, Ext JS, LLC.
30547 * Originally Released Under LGPL - original licence link has changed is not relivant.
30550 * <script type="text/javascript">
30556 * @class Roo.SplitLayoutRegion
30557 * @extends Roo.LayoutRegion
30558 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
30560 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
30561 this.cursor = cursor;
30562 Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
30565 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
30566 splitTip : "Drag to resize.",
30567 collapsibleSplitTip : "Drag to resize. Double click to hide.",
30568 useSplitTips : false,
30570 applyConfig : function(config){
30571 Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
30574 var splitEl = Roo.DomHelper.append(this.mgr.el.dom,
30575 {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: " "});
30576 /** The SplitBar for this region
30577 * @type Roo.SplitBar */
30578 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
30579 this.split.on("moved", this.onSplitMove, this);
30580 this.split.useShim = config.useShim === true;
30581 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
30582 if(this.useSplitTips){
30583 this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
30585 if(config.collapsible){
30586 this.split.el.on("dblclick", this.collapse, this);
30589 if(typeof config.minSize != "undefined"){
30590 this.split.minSize = config.minSize;
30592 if(typeof config.maxSize != "undefined"){
30593 this.split.maxSize = config.maxSize;
30595 if(config.hideWhenEmpty || config.hidden || config.collapsed){
30596 this.hideSplitter();
30601 getHMaxSize : function(){
30602 var cmax = this.config.maxSize || 10000;
30603 var center = this.mgr.getRegion("center");
30604 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
30607 getVMaxSize : function(){
30608 var cmax = this.config.maxSize || 10000;
30609 var center = this.mgr.getRegion("center");
30610 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
30613 onSplitMove : function(split, newSize){
30614 this.fireEvent("resized", this, newSize);
30618 * Returns the {@link Roo.SplitBar} for this region.
30619 * @return {Roo.SplitBar}
30621 getSplitBar : function(){
30626 this.hideSplitter();
30627 Roo.SplitLayoutRegion.superclass.hide.call(this);
30630 hideSplitter : function(){
30632 this.split.el.setLocation(-2000,-2000);
30633 this.split.el.hide();
30639 this.split.el.show();
30641 Roo.SplitLayoutRegion.superclass.show.call(this);
30644 beforeSlide: function(){
30645 if(Roo.isGecko){// firefox overflow auto bug workaround
30646 this.bodyEl.clip();
30648 this.tabs.bodyEl.clip();
30650 if(this.activePanel){
30651 this.activePanel.getEl().clip();
30653 if(this.activePanel.beforeSlide){
30654 this.activePanel.beforeSlide();
30660 afterSlide : function(){
30661 if(Roo.isGecko){// firefox overflow auto bug workaround
30662 this.bodyEl.unclip();
30664 this.tabs.bodyEl.unclip();
30666 if(this.activePanel){
30667 this.activePanel.getEl().unclip();
30668 if(this.activePanel.afterSlide){
30669 this.activePanel.afterSlide();
30675 initAutoHide : function(){
30676 if(this.autoHide !== false){
30677 if(!this.autoHideHd){
30678 var st = new Roo.util.DelayedTask(this.slideIn, this);
30679 this.autoHideHd = {
30680 "mouseout": function(e){
30681 if(!e.within(this.el, true)){
30685 "mouseover" : function(e){
30691 this.el.on(this.autoHideHd);
30695 clearAutoHide : function(){
30696 if(this.autoHide !== false){
30697 this.el.un("mouseout", this.autoHideHd.mouseout);
30698 this.el.un("mouseover", this.autoHideHd.mouseover);
30702 clearMonitor : function(){
30703 Roo.get(document).un("click", this.slideInIf, this);
30706 // these names are backwards but not changed for compat
30707 slideOut : function(){
30708 if(this.isSlid || this.el.hasActiveFx()){
30711 this.isSlid = true;
30712 if(this.collapseBtn){
30713 this.collapseBtn.hide();
30715 this.closeBtnState = this.closeBtn.getStyle('display');
30716 this.closeBtn.hide();
30718 this.stickBtn.show();
30721 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
30722 this.beforeSlide();
30723 this.el.setStyle("z-index", 10001);
30724 this.el.slideIn(this.getSlideAnchor(), {
30725 callback: function(){
30727 this.initAutoHide();
30728 Roo.get(document).on("click", this.slideInIf, this);
30729 this.fireEvent("slideshow", this);
30736 afterSlideIn : function(){
30737 this.clearAutoHide();
30738 this.isSlid = false;
30739 this.clearMonitor();
30740 this.el.setStyle("z-index", "");
30741 if(this.collapseBtn){
30742 this.collapseBtn.show();
30744 this.closeBtn.setStyle('display', this.closeBtnState);
30746 this.stickBtn.hide();
30748 this.fireEvent("slidehide", this);
30751 slideIn : function(cb){
30752 if(!this.isSlid || this.el.hasActiveFx()){
30756 this.isSlid = false;
30757 this.beforeSlide();
30758 this.el.slideOut(this.getSlideAnchor(), {
30759 callback: function(){
30760 this.el.setLeftTop(-10000, -10000);
30762 this.afterSlideIn();
30770 slideInIf : function(e){
30771 if(!e.within(this.el)){
30776 animateCollapse : function(){
30777 this.beforeSlide();
30778 this.el.setStyle("z-index", 20000);
30779 var anchor = this.getSlideAnchor();
30780 this.el.slideOut(anchor, {
30781 callback : function(){
30782 this.el.setStyle("z-index", "");
30783 this.collapsedEl.slideIn(anchor, {duration:.3});
30785 this.el.setLocation(-10000,-10000);
30787 this.fireEvent("collapsed", this);
30794 animateExpand : function(){
30795 this.beforeSlide();
30796 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
30797 this.el.setStyle("z-index", 20000);
30798 this.collapsedEl.hide({
30801 this.el.slideIn(this.getSlideAnchor(), {
30802 callback : function(){
30803 this.el.setStyle("z-index", "");
30806 this.split.el.show();
30808 this.fireEvent("invalidated", this);
30809 this.fireEvent("expanded", this);
30837 getAnchor : function(){
30838 return this.anchors[this.position];
30841 getCollapseAnchor : function(){
30842 return this.canchors[this.position];
30845 getSlideAnchor : function(){
30846 return this.sanchors[this.position];
30849 getAlignAdj : function(){
30850 var cm = this.cmargins;
30851 switch(this.position){
30867 getExpandAdj : function(){
30868 var c = this.collapsedEl, cm = this.cmargins;
30869 switch(this.position){
30871 return [-(cm.right+c.getWidth()+cm.left), 0];
30874 return [cm.right+c.getWidth()+cm.left, 0];
30877 return [0, -(cm.top+cm.bottom+c.getHeight())];
30880 return [0, cm.top+cm.bottom+c.getHeight()];
30886 * Ext JS Library 1.1.1
30887 * Copyright(c) 2006-2007, Ext JS, LLC.
30889 * Originally Released Under LGPL - original licence link has changed is not relivant.
30892 * <script type="text/javascript">
30895 * These classes are private internal classes
30897 Roo.CenterLayoutRegion = function(mgr, config){
30898 Roo.LayoutRegion.call(this, mgr, config, "center");
30899 this.visible = true;
30900 this.minWidth = config.minWidth || 20;
30901 this.minHeight = config.minHeight || 20;
30904 Roo.extend(Roo.CenterLayoutRegion, Roo.LayoutRegion, {
30906 // center panel can't be hidden
30910 // center panel can't be hidden
30913 getMinWidth: function(){
30914 return this.minWidth;
30917 getMinHeight: function(){
30918 return this.minHeight;
30923 Roo.NorthLayoutRegion = function(mgr, config){
30924 Roo.LayoutRegion.call(this, mgr, config, "north", "n-resize");
30926 this.split.placement = Roo.SplitBar.TOP;
30927 this.split.orientation = Roo.SplitBar.VERTICAL;
30928 this.split.el.addClass("x-layout-split-v");
30930 var size = config.initialSize || config.height;
30931 if(typeof size != "undefined"){
30932 this.el.setHeight(size);
30935 Roo.extend(Roo.NorthLayoutRegion, Roo.SplitLayoutRegion, {
30936 orientation: Roo.SplitBar.VERTICAL,
30937 getBox : function(){
30938 if(this.collapsed){
30939 return this.collapsedEl.getBox();
30941 var box = this.el.getBox();
30943 box.height += this.split.el.getHeight();
30948 updateBox : function(box){
30949 if(this.split && !this.collapsed){
30950 box.height -= this.split.el.getHeight();
30951 this.split.el.setLeft(box.x);
30952 this.split.el.setTop(box.y+box.height);
30953 this.split.el.setWidth(box.width);
30955 if(this.collapsed){
30956 this.updateBody(box.width, null);
30958 Roo.LayoutRegion.prototype.updateBox.call(this, box);
30962 Roo.SouthLayoutRegion = function(mgr, config){
30963 Roo.SplitLayoutRegion.call(this, mgr, config, "south", "s-resize");
30965 this.split.placement = Roo.SplitBar.BOTTOM;
30966 this.split.orientation = Roo.SplitBar.VERTICAL;
30967 this.split.el.addClass("x-layout-split-v");
30969 var size = config.initialSize || config.height;
30970 if(typeof size != "undefined"){
30971 this.el.setHeight(size);
30974 Roo.extend(Roo.SouthLayoutRegion, Roo.SplitLayoutRegion, {
30975 orientation: Roo.SplitBar.VERTICAL,
30976 getBox : function(){
30977 if(this.collapsed){
30978 return this.collapsedEl.getBox();
30980 var box = this.el.getBox();
30982 var sh = this.split.el.getHeight();
30989 updateBox : function(box){
30990 if(this.split && !this.collapsed){
30991 var sh = this.split.el.getHeight();
30994 this.split.el.setLeft(box.x);
30995 this.split.el.setTop(box.y-sh);
30996 this.split.el.setWidth(box.width);
30998 if(this.collapsed){
30999 this.updateBody(box.width, null);
31001 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31005 Roo.EastLayoutRegion = function(mgr, config){
31006 Roo.SplitLayoutRegion.call(this, mgr, config, "east", "e-resize");
31008 this.split.placement = Roo.SplitBar.RIGHT;
31009 this.split.orientation = Roo.SplitBar.HORIZONTAL;
31010 this.split.el.addClass("x-layout-split-h");
31012 var size = config.initialSize || config.width;
31013 if(typeof size != "undefined"){
31014 this.el.setWidth(size);
31017 Roo.extend(Roo.EastLayoutRegion, Roo.SplitLayoutRegion, {
31018 orientation: Roo.SplitBar.HORIZONTAL,
31019 getBox : function(){
31020 if(this.collapsed){
31021 return this.collapsedEl.getBox();
31023 var box = this.el.getBox();
31025 var sw = this.split.el.getWidth();
31032 updateBox : function(box){
31033 if(this.split && !this.collapsed){
31034 var sw = this.split.el.getWidth();
31036 this.split.el.setLeft(box.x);
31037 this.split.el.setTop(box.y);
31038 this.split.el.setHeight(box.height);
31041 if(this.collapsed){
31042 this.updateBody(null, box.height);
31044 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31048 Roo.WestLayoutRegion = function(mgr, config){
31049 Roo.SplitLayoutRegion.call(this, mgr, config, "west", "w-resize");
31051 this.split.placement = Roo.SplitBar.LEFT;
31052 this.split.orientation = Roo.SplitBar.HORIZONTAL;
31053 this.split.el.addClass("x-layout-split-h");
31055 var size = config.initialSize || config.width;
31056 if(typeof size != "undefined"){
31057 this.el.setWidth(size);
31060 Roo.extend(Roo.WestLayoutRegion, Roo.SplitLayoutRegion, {
31061 orientation: Roo.SplitBar.HORIZONTAL,
31062 getBox : function(){
31063 if(this.collapsed){
31064 return this.collapsedEl.getBox();
31066 var box = this.el.getBox();
31068 box.width += this.split.el.getWidth();
31073 updateBox : function(box){
31074 if(this.split && !this.collapsed){
31075 var sw = this.split.el.getWidth();
31077 this.split.el.setLeft(box.x+box.width);
31078 this.split.el.setTop(box.y);
31079 this.split.el.setHeight(box.height);
31081 if(this.collapsed){
31082 this.updateBody(null, box.height);
31084 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31089 * Ext JS Library 1.1.1
31090 * Copyright(c) 2006-2007, Ext JS, LLC.
31092 * Originally Released Under LGPL - original licence link has changed is not relivant.
31095 * <script type="text/javascript">
31100 * Private internal class for reading and applying state
31102 Roo.LayoutStateManager = function(layout){
31103 // default empty state
31112 Roo.LayoutStateManager.prototype = {
31113 init : function(layout, provider){
31114 this.provider = provider;
31115 var state = provider.get(layout.id+"-layout-state");
31117 var wasUpdating = layout.isUpdating();
31119 layout.beginUpdate();
31121 for(var key in state){
31122 if(typeof state[key] != "function"){
31123 var rstate = state[key];
31124 var r = layout.getRegion(key);
31127 r.resizeTo(rstate.size);
31129 if(rstate.collapsed == true){
31132 r.expand(null, true);
31138 layout.endUpdate();
31140 this.state = state;
31142 this.layout = layout;
31143 layout.on("regionresized", this.onRegionResized, this);
31144 layout.on("regioncollapsed", this.onRegionCollapsed, this);
31145 layout.on("regionexpanded", this.onRegionExpanded, this);
31148 storeState : function(){
31149 this.provider.set(this.layout.id+"-layout-state", this.state);
31152 onRegionResized : function(region, newSize){
31153 this.state[region.getPosition()].size = newSize;
31157 onRegionCollapsed : function(region){
31158 this.state[region.getPosition()].collapsed = true;
31162 onRegionExpanded : function(region){
31163 this.state[region.getPosition()].collapsed = false;
31168 * Ext JS Library 1.1.1
31169 * Copyright(c) 2006-2007, Ext JS, LLC.
31171 * Originally Released Under LGPL - original licence link has changed is not relivant.
31174 * <script type="text/javascript">
31177 * @class Roo.ContentPanel
31178 * @extends Roo.util.Observable
31179 * A basic ContentPanel element.
31180 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
31181 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
31182 * @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
31183 * @cfg {Boolean} closable True if the panel can be closed/removed
31184 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
31185 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
31186 * @cfg {Toolbar} toolbar A toolbar for this panel
31187 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
31188 * @cfg {String} title The title for this panel
31189 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
31190 * @cfg {String} url Calls {@link #setUrl} with this value
31191 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
31192 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
31193 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
31194 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
31197 * Create a new ContentPanel.
31198 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
31199 * @param {String/Object} config A string to set only the title or a config object
31200 * @param {String} content (optional) Set the HTML content for this panel
31201 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
31203 Roo.ContentPanel = function(el, config, content){
31207 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
31211 if (config && config.parentLayout) {
31212 el = config.parentLayout.el.createChild();
31215 if(el.autoCreate){ // xtype is available if this is called from factory
31219 this.el = Roo.get(el);
31220 if(!this.el && config && config.autoCreate){
31221 if(typeof config.autoCreate == "object"){
31222 if(!config.autoCreate.id){
31223 config.autoCreate.id = config.id||el;
31225 this.el = Roo.DomHelper.append(document.body,
31226 config.autoCreate, true);
31228 this.el = Roo.DomHelper.append(document.body,
31229 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
31232 this.closable = false;
31233 this.loaded = false;
31234 this.active = false;
31235 if(typeof config == "string"){
31236 this.title = config;
31238 Roo.apply(this, config);
31241 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
31242 this.wrapEl = this.el.wrap();
31243 this.toolbar.container = this.el.insertSibling(false, 'before');
31244 this.toolbar = new Roo.Toolbar(this.toolbar);
31247 // xtype created footer. - not sure if will work as we normally have to render first..
31248 if (this.footer && !this.footer.el && this.footer.xtype) {
31249 if (!this.wrapEl) {
31250 this.wrapEl = this.el.wrap();
31253 this.footer.container = this.wrapEl.createChild();
31255 this.footer = Roo.factory(this.footer, Roo);
31260 this.resizeEl = Roo.get(this.resizeEl, true);
31262 this.resizeEl = this.el;
31264 // handle view.xtype
31272 * Fires when this panel is activated.
31273 * @param {Roo.ContentPanel} this
31277 * @event deactivate
31278 * Fires when this panel is activated.
31279 * @param {Roo.ContentPanel} this
31281 "deactivate" : true,
31285 * Fires when this panel is resized if fitToFrame is true.
31286 * @param {Roo.ContentPanel} this
31287 * @param {Number} width The width after any component adjustments
31288 * @param {Number} height The height after any component adjustments
31294 * Fires when this tab is created
31295 * @param {Roo.ContentPanel} this
31305 if(this.autoScroll){
31306 this.resizeEl.setStyle("overflow", "auto");
31308 // fix randome scrolling
31309 this.el.on('scroll', function() {
31310 Roo.log('fix random scolling');
31311 this.scrollTo('top',0);
31314 content = content || this.content;
31316 this.setContent(content);
31318 if(config && config.url){
31319 this.setUrl(this.url, this.params, this.loadOnce);
31324 Roo.ContentPanel.superclass.constructor.call(this);
31326 if (this.view && typeof(this.view.xtype) != 'undefined') {
31327 this.view.el = this.el.appendChild(document.createElement("div"));
31328 this.view = Roo.factory(this.view);
31329 this.view.render && this.view.render(false, '');
31333 this.fireEvent('render', this);
31336 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
31338 setRegion : function(region){
31339 this.region = region;
31341 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
31343 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
31348 * Returns the toolbar for this Panel if one was configured.
31349 * @return {Roo.Toolbar}
31351 getToolbar : function(){
31352 return this.toolbar;
31355 setActiveState : function(active){
31356 this.active = active;
31358 this.fireEvent("deactivate", this);
31360 this.fireEvent("activate", this);
31364 * Updates this panel's element
31365 * @param {String} content The new content
31366 * @param {Boolean} loadScripts (optional) true to look for and process scripts
31368 setContent : function(content, loadScripts){
31369 this.el.update(content, loadScripts);
31372 ignoreResize : function(w, h){
31373 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
31376 this.lastSize = {width: w, height: h};
31381 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
31382 * @return {Roo.UpdateManager} The UpdateManager
31384 getUpdateManager : function(){
31385 return this.el.getUpdateManager();
31388 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
31389 * @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:
31392 url: "your-url.php",
31393 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
31394 callback: yourFunction,
31395 scope: yourObject, //(optional scope)
31398 text: "Loading...",
31403 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
31404 * 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.
31405 * @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}
31406 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
31407 * @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.
31408 * @return {Roo.ContentPanel} this
31411 var um = this.el.getUpdateManager();
31412 um.update.apply(um, arguments);
31418 * 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.
31419 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
31420 * @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)
31421 * @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)
31422 * @return {Roo.UpdateManager} The UpdateManager
31424 setUrl : function(url, params, loadOnce){
31425 if(this.refreshDelegate){
31426 this.removeListener("activate", this.refreshDelegate);
31428 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
31429 this.on("activate", this.refreshDelegate);
31430 return this.el.getUpdateManager();
31433 _handleRefresh : function(url, params, loadOnce){
31434 if(!loadOnce || !this.loaded){
31435 var updater = this.el.getUpdateManager();
31436 updater.update(url, params, this._setLoaded.createDelegate(this));
31440 _setLoaded : function(){
31441 this.loaded = true;
31445 * Returns this panel's id
31448 getId : function(){
31453 * Returns this panel's element - used by regiosn to add.
31454 * @return {Roo.Element}
31456 getEl : function(){
31457 return this.wrapEl || this.el;
31460 adjustForComponents : function(width, height)
31462 //Roo.log('adjustForComponents ');
31463 if(this.resizeEl != this.el){
31464 width -= this.el.getFrameWidth('lr');
31465 height -= this.el.getFrameWidth('tb');
31468 var te = this.toolbar.getEl();
31469 height -= te.getHeight();
31470 te.setWidth(width);
31473 var te = this.footer.getEl();
31474 //Roo.log("footer:" + te.getHeight());
31476 height -= te.getHeight();
31477 te.setWidth(width);
31481 if(this.adjustments){
31482 width += this.adjustments[0];
31483 height += this.adjustments[1];
31485 return {"width": width, "height": height};
31488 setSize : function(width, height){
31489 if(this.fitToFrame && !this.ignoreResize(width, height)){
31490 if(this.fitContainer && this.resizeEl != this.el){
31491 this.el.setSize(width, height);
31493 var size = this.adjustForComponents(width, height);
31494 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
31495 this.fireEvent('resize', this, size.width, size.height);
31500 * Returns this panel's title
31503 getTitle : function(){
31508 * Set this panel's title
31509 * @param {String} title
31511 setTitle : function(title){
31512 this.title = title;
31514 this.region.updatePanelTitle(this, title);
31519 * Returns true is this panel was configured to be closable
31520 * @return {Boolean}
31522 isClosable : function(){
31523 return this.closable;
31526 beforeSlide : function(){
31528 this.resizeEl.clip();
31531 afterSlide : function(){
31533 this.resizeEl.unclip();
31537 * Force a content refresh from the URL specified in the {@link #setUrl} method.
31538 * Will fail silently if the {@link #setUrl} method has not been called.
31539 * This does not activate the panel, just updates its content.
31541 refresh : function(){
31542 if(this.refreshDelegate){
31543 this.loaded = false;
31544 this.refreshDelegate();
31549 * Destroys this panel
31551 destroy : function(){
31552 this.el.removeAllListeners();
31553 var tempEl = document.createElement("span");
31554 tempEl.appendChild(this.el.dom);
31555 tempEl.innerHTML = "";
31561 * form - if the content panel contains a form - this is a reference to it.
31562 * @type {Roo.form.Form}
31566 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
31567 * This contains a reference to it.
31573 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
31583 * @param {Object} cfg Xtype definition of item to add.
31586 addxtype : function(cfg) {
31588 if (cfg.xtype.match(/^Form$/)) {
31591 //if (this.footer) {
31592 // el = this.footer.container.insertSibling(false, 'before');
31594 el = this.el.createChild();
31597 this.form = new Roo.form.Form(cfg);
31600 if ( this.form.allItems.length) {
31601 this.form.render(el.dom);
31605 // should only have one of theses..
31606 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
31607 // views.. should not be just added - used named prop 'view''
31609 cfg.el = this.el.appendChild(document.createElement("div"));
31612 var ret = new Roo.factory(cfg);
31614 ret.render && ret.render(false, ''); // render blank..
31623 * @class Roo.GridPanel
31624 * @extends Roo.ContentPanel
31626 * Create a new GridPanel.
31627 * @param {Roo.grid.Grid} grid The grid for this panel
31628 * @param {String/Object} config A string to set only the panel's title, or a config object
31630 Roo.GridPanel = function(grid, config){
31633 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
31634 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
31636 this.wrapper.dom.appendChild(grid.getGridEl().dom);
31638 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
31641 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
31643 // xtype created footer. - not sure if will work as we normally have to render first..
31644 if (this.footer && !this.footer.el && this.footer.xtype) {
31646 this.footer.container = this.grid.getView().getFooterPanel(true);
31647 this.footer.dataSource = this.grid.dataSource;
31648 this.footer = Roo.factory(this.footer, Roo);
31652 grid.monitorWindowResize = false; // turn off autosizing
31653 grid.autoHeight = false;
31654 grid.autoWidth = false;
31656 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
31659 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
31660 getId : function(){
31661 return this.grid.id;
31665 * Returns the grid for this panel
31666 * @return {Roo.grid.Grid}
31668 getGrid : function(){
31672 setSize : function(width, height){
31673 if(!this.ignoreResize(width, height)){
31674 var grid = this.grid;
31675 var size = this.adjustForComponents(width, height);
31676 grid.getGridEl().setSize(size.width, size.height);
31681 beforeSlide : function(){
31682 this.grid.getView().scroller.clip();
31685 afterSlide : function(){
31686 this.grid.getView().scroller.unclip();
31689 destroy : function(){
31690 this.grid.destroy();
31692 Roo.GridPanel.superclass.destroy.call(this);
31698 * @class Roo.NestedLayoutPanel
31699 * @extends Roo.ContentPanel
31701 * Create a new NestedLayoutPanel.
31704 * @param {Roo.BorderLayout} layout The layout for this panel
31705 * @param {String/Object} config A string to set only the title or a config object
31707 Roo.NestedLayoutPanel = function(layout, config)
31709 // construct with only one argument..
31710 /* FIXME - implement nicer consturctors
31711 if (layout.layout) {
31713 layout = config.layout;
31714 delete config.layout;
31716 if (layout.xtype && !layout.getEl) {
31717 // then layout needs constructing..
31718 layout = Roo.factory(layout, Roo);
31723 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
31725 layout.monitorWindowResize = false; // turn off autosizing
31726 this.layout = layout;
31727 this.layout.getEl().addClass("x-layout-nested-layout");
31734 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
31736 setSize : function(width, height){
31737 if(!this.ignoreResize(width, height)){
31738 var size = this.adjustForComponents(width, height);
31739 var el = this.layout.getEl();
31740 el.setSize(size.width, size.height);
31741 var touch = el.dom.offsetWidth;
31742 this.layout.layout();
31743 // ie requires a double layout on the first pass
31744 if(Roo.isIE && !this.initialized){
31745 this.initialized = true;
31746 this.layout.layout();
31751 // activate all subpanels if not currently active..
31753 setActiveState : function(active){
31754 this.active = active;
31756 this.fireEvent("deactivate", this);
31760 this.fireEvent("activate", this);
31761 // not sure if this should happen before or after..
31762 if (!this.layout) {
31763 return; // should not happen..
31766 for (var r in this.layout.regions) {
31767 reg = this.layout.getRegion(r);
31768 if (reg.getActivePanel()) {
31769 //reg.showPanel(reg.getActivePanel()); // force it to activate..
31770 reg.setActivePanel(reg.getActivePanel());
31773 if (!reg.panels.length) {
31776 reg.showPanel(reg.getPanel(0));
31785 * Returns the nested BorderLayout for this panel
31786 * @return {Roo.BorderLayout}
31788 getLayout : function(){
31789 return this.layout;
31793 * Adds a xtype elements to the layout of the nested panel
31797 xtype : 'ContentPanel',
31804 xtype : 'NestedLayoutPanel',
31810 items : [ ... list of content panels or nested layout panels.. ]
31814 * @param {Object} cfg Xtype definition of item to add.
31816 addxtype : function(cfg) {
31817 return this.layout.addxtype(cfg);
31822 Roo.ScrollPanel = function(el, config, content){
31823 config = config || {};
31824 config.fitToFrame = true;
31825 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
31827 this.el.dom.style.overflow = "hidden";
31828 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
31829 this.el.removeClass("x-layout-inactive-content");
31830 this.el.on("mousewheel", this.onWheel, this);
31832 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
31833 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
31834 up.unselectable(); down.unselectable();
31835 up.on("click", this.scrollUp, this);
31836 down.on("click", this.scrollDown, this);
31837 up.addClassOnOver("x-scroller-btn-over");
31838 down.addClassOnOver("x-scroller-btn-over");
31839 up.addClassOnClick("x-scroller-btn-click");
31840 down.addClassOnClick("x-scroller-btn-click");
31841 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
31843 this.resizeEl = this.el;
31844 this.el = wrap; this.up = up; this.down = down;
31847 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
31849 wheelIncrement : 5,
31850 scrollUp : function(){
31851 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
31854 scrollDown : function(){
31855 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
31858 afterScroll : function(){
31859 var el = this.resizeEl;
31860 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
31861 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
31862 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
31865 setSize : function(){
31866 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
31867 this.afterScroll();
31870 onWheel : function(e){
31871 var d = e.getWheelDelta();
31872 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
31873 this.afterScroll();
31877 setContent : function(content, loadScripts){
31878 this.resizeEl.update(content, loadScripts);
31892 * @class Roo.TreePanel
31893 * @extends Roo.ContentPanel
31895 * Create a new TreePanel. - defaults to fit/scoll contents.
31896 * @param {String/Object} config A string to set only the panel's title, or a config object
31897 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
31899 Roo.TreePanel = function(config){
31900 var el = config.el;
31901 var tree = config.tree;
31902 delete config.tree;
31903 delete config.el; // hopefull!
31905 // wrapper for IE7 strict & safari scroll issue
31907 var treeEl = el.createChild();
31908 config.resizeEl = treeEl;
31912 Roo.TreePanel.superclass.constructor.call(this, el, config);
31915 this.tree = new Roo.tree.TreePanel(treeEl , tree);
31916 //console.log(tree);
31917 this.on('activate', function()
31919 if (this.tree.rendered) {
31922 //console.log('render tree');
31923 this.tree.render();
31925 // this should not be needed.. - it's actually the 'el' that resizes?
31926 // actuall it breaks the containerScroll - dragging nodes auto scroll at top
31928 //this.on('resize', function (cp, w, h) {
31929 // this.tree.innerCt.setWidth(w);
31930 // this.tree.innerCt.setHeight(h);
31931 // //this.tree.innerCt.setStyle('overflow-y', 'auto');
31938 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {
31955 * Ext JS Library 1.1.1
31956 * Copyright(c) 2006-2007, Ext JS, LLC.
31958 * Originally Released Under LGPL - original licence link has changed is not relivant.
31961 * <script type="text/javascript">
31966 * @class Roo.ReaderLayout
31967 * @extends Roo.BorderLayout
31968 * This is a pre-built layout that represents a classic, 5-pane application. It consists of a header, a primary
31969 * center region containing two nested regions (a top one for a list view and one for item preview below),
31970 * and regions on either side that can be used for navigation, application commands, informational displays, etc.
31971 * The setup and configuration work exactly the same as it does for a {@link Roo.BorderLayout} - this class simply
31972 * expedites the setup of the overall layout and regions for this common application style.
31975 var reader = new Roo.ReaderLayout();
31976 var CP = Roo.ContentPanel; // shortcut for adding
31978 reader.beginUpdate();
31979 reader.add("north", new CP("north", "North"));
31980 reader.add("west", new CP("west", {title: "West"}));
31981 reader.add("east", new CP("east", {title: "East"}));
31983 reader.regions.listView.add(new CP("listView", "List"));
31984 reader.regions.preview.add(new CP("preview", "Preview"));
31985 reader.endUpdate();
31988 * Create a new ReaderLayout
31989 * @param {Object} config Configuration options
31990 * @param {String/HTMLElement/Element} container (optional) The container this layout is bound to (defaults to
31991 * document.body if omitted)
31993 Roo.ReaderLayout = function(config, renderTo){
31994 var c = config || {size:{}};
31995 Roo.ReaderLayout.superclass.constructor.call(this, renderTo || document.body, {
31996 north: c.north !== false ? Roo.apply({
32000 }, c.north) : false,
32001 west: c.west !== false ? Roo.apply({
32009 margins:{left:5,right:0,bottom:5,top:5},
32010 cmargins:{left:5,right:5,bottom:5,top:5}
32011 }, c.west) : false,
32012 east: c.east !== false ? Roo.apply({
32020 margins:{left:0,right:5,bottom:5,top:5},
32021 cmargins:{left:5,right:5,bottom:5,top:5}
32022 }, c.east) : false,
32023 center: Roo.apply({
32024 tabPosition: 'top',
32028 margins:{left:c.west!==false ? 0 : 5,right:c.east!==false ? 0 : 5,bottom:5,top:2}
32032 this.el.addClass('x-reader');
32034 this.beginUpdate();
32036 var inner = new Roo.BorderLayout(Roo.get(document.body).createChild(), {
32037 south: c.preview !== false ? Roo.apply({
32044 cmargins:{top:5,left:0, right:0, bottom:0}
32045 }, c.preview) : false,
32046 center: Roo.apply({
32052 this.add('center', new Roo.NestedLayoutPanel(inner,
32053 Roo.apply({title: c.mainTitle || '',tabTip:''},c.innerPanelCfg)));
32057 this.regions.preview = inner.getRegion('south');
32058 this.regions.listView = inner.getRegion('center');
32061 Roo.extend(Roo.ReaderLayout, Roo.BorderLayout);/*
32063 * Ext JS Library 1.1.1
32064 * Copyright(c) 2006-2007, Ext JS, LLC.
32066 * Originally Released Under LGPL - original licence link has changed is not relivant.
32069 * <script type="text/javascript">
32073 * @class Roo.grid.Grid
32074 * @extends Roo.util.Observable
32075 * This class represents the primary interface of a component based grid control.
32076 * <br><br>Usage:<pre><code>
32077 var grid = new Roo.grid.Grid("my-container-id", {
32080 selModel: mySelectionModel,
32081 autoSizeColumns: true,
32082 monitorWindowResize: false,
32083 trackMouseOver: true
32088 * <b>Common Problems:</b><br/>
32089 * - Grid does not resize properly when going smaller: Setting overflow hidden on the container
32090 * element will correct this<br/>
32091 * - If you get el.style[camel]= NaNpx or -2px or something related, be certain you have given your container element
32092 * dimensions. The grid adapts to your container's size, if your container has no size defined then the results
32093 * are unpredictable.<br/>
32094 * - Do not render the grid into an element with display:none. Try using visibility:hidden. Otherwise there is no way for the
32095 * grid to calculate dimensions/offsets.<br/>
32097 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
32098 * The container MUST have some type of size defined for the grid to fill. The container will be
32099 * automatically set to position relative if it isn't already.
32100 * @param {Object} config A config object that sets properties on this grid.
32102 Roo.grid.Grid = function(container, config){
32103 // initialize the container
32104 this.container = Roo.get(container);
32105 this.container.update("");
32106 this.container.setStyle("overflow", "hidden");
32107 this.container.addClass('x-grid-container');
32109 this.id = this.container.id;
32111 Roo.apply(this, config);
32112 // check and correct shorthanded configs
32114 this.dataSource = this.ds;
32118 this.colModel = this.cm;
32122 this.selModel = this.sm;
32126 if (this.selModel) {
32127 this.selModel = Roo.factory(this.selModel, Roo.grid);
32128 this.sm = this.selModel;
32129 this.sm.xmodule = this.xmodule || false;
32131 if (typeof(this.colModel.config) == 'undefined') {
32132 this.colModel = new Roo.grid.ColumnModel(this.colModel);
32133 this.cm = this.colModel;
32134 this.cm.xmodule = this.xmodule || false;
32136 if (this.dataSource) {
32137 this.dataSource= Roo.factory(this.dataSource, Roo.data);
32138 this.ds = this.dataSource;
32139 this.ds.xmodule = this.xmodule || false;
32146 this.container.setWidth(this.width);
32150 this.container.setHeight(this.height);
32157 * The raw click event for the entire grid.
32158 * @param {Roo.EventObject} e
32163 * The raw dblclick event for the entire grid.
32164 * @param {Roo.EventObject} e
32168 * @event contextmenu
32169 * The raw contextmenu event for the entire grid.
32170 * @param {Roo.EventObject} e
32172 "contextmenu" : true,
32175 * The raw mousedown event for the entire grid.
32176 * @param {Roo.EventObject} e
32178 "mousedown" : true,
32181 * The raw mouseup event for the entire grid.
32182 * @param {Roo.EventObject} e
32187 * The raw mouseover event for the entire grid.
32188 * @param {Roo.EventObject} e
32190 "mouseover" : true,
32193 * The raw mouseout event for the entire grid.
32194 * @param {Roo.EventObject} e
32199 * The raw keypress event for the entire grid.
32200 * @param {Roo.EventObject} e
32205 * The raw keydown event for the entire grid.
32206 * @param {Roo.EventObject} e
32214 * Fires when a cell is clicked
32215 * @param {Grid} this
32216 * @param {Number} rowIndex
32217 * @param {Number} columnIndex
32218 * @param {Roo.EventObject} e
32220 "cellclick" : true,
32222 * @event celldblclick
32223 * Fires when a cell is double clicked
32224 * @param {Grid} this
32225 * @param {Number} rowIndex
32226 * @param {Number} columnIndex
32227 * @param {Roo.EventObject} e
32229 "celldblclick" : true,
32232 * Fires when a row is clicked
32233 * @param {Grid} this
32234 * @param {Number} rowIndex
32235 * @param {Roo.EventObject} e
32239 * @event rowdblclick
32240 * Fires when a row is double clicked
32241 * @param {Grid} this
32242 * @param {Number} rowIndex
32243 * @param {Roo.EventObject} e
32245 "rowdblclick" : true,
32247 * @event headerclick
32248 * Fires when a header is clicked
32249 * @param {Grid} this
32250 * @param {Number} columnIndex
32251 * @param {Roo.EventObject} e
32253 "headerclick" : true,
32255 * @event headerdblclick
32256 * Fires when a header cell is double clicked
32257 * @param {Grid} this
32258 * @param {Number} columnIndex
32259 * @param {Roo.EventObject} e
32261 "headerdblclick" : true,
32263 * @event rowcontextmenu
32264 * Fires when a row is right clicked
32265 * @param {Grid} this
32266 * @param {Number} rowIndex
32267 * @param {Roo.EventObject} e
32269 "rowcontextmenu" : true,
32271 * @event cellcontextmenu
32272 * Fires when a cell is right clicked
32273 * @param {Grid} this
32274 * @param {Number} rowIndex
32275 * @param {Number} cellIndex
32276 * @param {Roo.EventObject} e
32278 "cellcontextmenu" : true,
32280 * @event headercontextmenu
32281 * Fires when a header is right clicked
32282 * @param {Grid} this
32283 * @param {Number} columnIndex
32284 * @param {Roo.EventObject} e
32286 "headercontextmenu" : true,
32288 * @event bodyscroll
32289 * Fires when the body element is scrolled
32290 * @param {Number} scrollLeft
32291 * @param {Number} scrollTop
32293 "bodyscroll" : true,
32295 * @event columnresize
32296 * Fires when the user resizes a column
32297 * @param {Number} columnIndex
32298 * @param {Number} newSize
32300 "columnresize" : true,
32302 * @event columnmove
32303 * Fires when the user moves a column
32304 * @param {Number} oldIndex
32305 * @param {Number} newIndex
32307 "columnmove" : true,
32310 * Fires when row(s) start being dragged
32311 * @param {Grid} this
32312 * @param {Roo.GridDD} dd The drag drop object
32313 * @param {event} e The raw browser event
32315 "startdrag" : true,
32318 * Fires when a drag operation is complete
32319 * @param {Grid} this
32320 * @param {Roo.GridDD} dd The drag drop object
32321 * @param {event} e The raw browser event
32326 * Fires when dragged row(s) are dropped on a valid DD target
32327 * @param {Grid} this
32328 * @param {Roo.GridDD} dd The drag drop object
32329 * @param {String} targetId The target drag drop object
32330 * @param {event} e The raw browser event
32335 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
32336 * @param {Grid} this
32337 * @param {Roo.GridDD} dd The drag drop object
32338 * @param {String} targetId The target drag drop object
32339 * @param {event} e The raw browser event
32344 * Fires when the dragged row(s) first cross another DD target while being dragged
32345 * @param {Grid} this
32346 * @param {Roo.GridDD} dd The drag drop object
32347 * @param {String} targetId The target drag drop object
32348 * @param {event} e The raw browser event
32350 "dragenter" : true,
32353 * Fires when the dragged row(s) leave another DD target while being dragged
32354 * @param {Grid} this
32355 * @param {Roo.GridDD} dd The drag drop object
32356 * @param {String} targetId The target drag drop object
32357 * @param {event} e The raw browser event
32362 * Fires when a row is rendered, so you can change add a style to it.
32363 * @param {GridView} gridview The grid view
32364 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
32370 * Fires when the grid is rendered
32371 * @param {Grid} grid
32376 Roo.grid.Grid.superclass.constructor.call(this);
32378 Roo.extend(Roo.grid.Grid, Roo.util.Observable, {
32381 * @cfg {String} ddGroup - drag drop group.
32385 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Default is 25.
32387 minColumnWidth : 25,
32390 * @cfg {Boolean} autoSizeColumns True to automatically resize the columns to fit their content
32391 * <b>on initial render.</b> It is more efficient to explicitly size the columns
32392 * through the ColumnModel's {@link Roo.grid.ColumnModel#width} config option. Default is false.
32394 autoSizeColumns : false,
32397 * @cfg {Boolean} autoSizeHeaders True to measure headers with column data when auto sizing columns. Default is true.
32399 autoSizeHeaders : true,
32402 * @cfg {Boolean} monitorWindowResize True to autoSize the grid when the window resizes. Default is true.
32404 monitorWindowResize : true,
32407 * @cfg {Boolean} maxRowsToMeasure If autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of
32408 * rows measured to get a columns size. Default is 0 (all rows).
32410 maxRowsToMeasure : 0,
32413 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is true.
32415 trackMouseOver : true,
32418 * @cfg {Boolean} enableDrag True to enable drag of rows. Default is false. (double check if this is needed?)
32422 * @cfg {Boolean} enableDragDrop True to enable drag and drop of rows. Default is false.
32424 enableDragDrop : false,
32427 * @cfg {Boolean} enableColumnMove True to enable drag and drop reorder of columns. Default is true.
32429 enableColumnMove : true,
32432 * @cfg {Boolean} enableColumnHide True to enable hiding of columns with the header context menu. Default is true.
32434 enableColumnHide : true,
32437 * @cfg {Boolean} enableRowHeightSync True to manually sync row heights across locked and not locked rows. Default is false.
32439 enableRowHeightSync : false,
32442 * @cfg {Boolean} stripeRows True to stripe the rows. Default is true.
32447 * @cfg {Boolean} autoHeight True to fit the height of the grid container to the height of the data. Default is false.
32449 autoHeight : false,
32452 * @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.
32454 autoExpandColumn : false,
32457 * @cfg {Number} autoExpandMin The minimum width the autoExpandColumn can have (if enabled).
32460 autoExpandMin : 50,
32463 * @cfg {Number} autoExpandMax The maximum width the autoExpandColumn can have (if enabled). Default is 1000.
32465 autoExpandMax : 1000,
32468 * @cfg {Object} view The {@link Roo.grid.GridView} used by the grid. This can be set before a call to render().
32473 * @cfg {Object} loadMask An {@link Roo.LoadMask} config or true to mask the grid while loading. Default is false.
32477 * @cfg {Roo.dd.DropTarget} dropTarget An {@link Roo.dd.DropTarget} config
32487 * @cfg {Boolean} autoWidth True to set the grid's width to the default total width of the grid's columns instead
32488 * of a fixed width. Default is false.
32491 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if autoHeight is not on.
32494 * Called once after all setup has been completed and the grid is ready to be rendered.
32495 * @return {Roo.grid.Grid} this
32497 render : function()
32499 var c = this.container;
32500 // try to detect autoHeight/width mode
32501 if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
32502 this.autoHeight = true;
32504 var view = this.getView();
32507 c.on("click", this.onClick, this);
32508 c.on("dblclick", this.onDblClick, this);
32509 c.on("contextmenu", this.onContextMenu, this);
32510 c.on("keydown", this.onKeyDown, this);
32512 c.on("touchstart", this.onTouchStart, this);
32515 this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
32517 this.getSelectionModel().init(this);
32522 this.loadMask = new Roo.LoadMask(this.container,
32523 Roo.apply({store:this.dataSource}, this.loadMask));
32527 if (this.toolbar && this.toolbar.xtype) {
32528 this.toolbar.container = this.getView().getHeaderPanel(true);
32529 this.toolbar = new Roo.Toolbar(this.toolbar);
32531 if (this.footer && this.footer.xtype) {
32532 this.footer.dataSource = this.getDataSource();
32533 this.footer.container = this.getView().getFooterPanel(true);
32534 this.footer = Roo.factory(this.footer, Roo);
32536 if (this.dropTarget && this.dropTarget.xtype) {
32537 delete this.dropTarget.xtype;
32538 this.dropTarget = new Roo.dd.DropTarget(this.getView().mainBody, this.dropTarget);
32542 this.rendered = true;
32543 this.fireEvent('render', this);
32548 * Reconfigures the grid to use a different Store and Column Model.
32549 * The View will be bound to the new objects and refreshed.
32550 * @param {Roo.data.Store} dataSource The new {@link Roo.data.Store} object
32551 * @param {Roo.grid.ColumnModel} The new {@link Roo.grid.ColumnModel} object
32553 reconfigure : function(dataSource, colModel){
32555 this.loadMask.destroy();
32556 this.loadMask = new Roo.LoadMask(this.container,
32557 Roo.apply({store:dataSource}, this.loadMask));
32559 this.view.bind(dataSource, colModel);
32560 this.dataSource = dataSource;
32561 this.colModel = colModel;
32562 this.view.refresh(true);
32566 * Add's a column, default at the end..
32568 * @param {int} position to add (default end)
32569 * @param {Array} of objects of column configuration see {@link Roo.grid.ColumnModel}
32571 addColumns : function(pos, ar)
32574 for (var i =0;i< ar.length;i++) {
32576 cfg.id = typeof(cfg.id) == 'undefined' ? Roo.id() : cfg.id; // don't normally use this..
32577 this.cm.lookup[cfg.id] = cfg;
32581 if (typeof(pos) == 'undefined' || pos >= this.cm.config.length) {
32582 pos = this.cm.config.length; //this.cm.config.push(cfg);
32584 pos = Math.max(0,pos);
32587 this.cm.config.splice.apply(this.cm.config, ar);
32591 this.view.generateRules(this.cm);
32592 this.view.refresh(true);
32600 onKeyDown : function(e){
32601 this.fireEvent("keydown", e);
32605 * Destroy this grid.
32606 * @param {Boolean} removeEl True to remove the element
32608 destroy : function(removeEl, keepListeners){
32610 this.loadMask.destroy();
32612 var c = this.container;
32613 c.removeAllListeners();
32614 this.view.destroy();
32615 this.colModel.purgeListeners();
32616 if(!keepListeners){
32617 this.purgeListeners();
32620 if(removeEl === true){
32626 processEvent : function(name, e){
32627 // does this fire select???
32628 //Roo.log('grid:processEvent ' + name);
32630 if (name != 'touchstart' ) {
32631 this.fireEvent(name, e);
32634 var t = e.getTarget();
32636 var header = v.findHeaderIndex(t);
32637 if(header !== false){
32638 var ename = name == 'touchstart' ? 'click' : name;
32640 this.fireEvent("header" + ename, this, header, e);
32642 var row = v.findRowIndex(t);
32643 var cell = v.findCellIndex(t);
32644 if (name == 'touchstart') {
32645 // first touch is always a click.
32646 // hopefull this happens after selection is updated.?
32649 if (typeof(this.selModel.getSelectedCell) != 'undefined') {
32650 var cs = this.selModel.getSelectedCell();
32651 if (row == cs[0] && cell == cs[1]){
32655 if (typeof(this.selModel.getSelections) != 'undefined') {
32656 var cs = this.selModel.getSelections();
32657 var ds = this.dataSource;
32658 if (cs.length == 1 && ds.getAt(row) == cs[0]){
32669 this.fireEvent("row" + name, this, row, e);
32670 if(cell !== false){
32671 this.fireEvent("cell" + name, this, row, cell, e);
32678 onClick : function(e){
32679 this.processEvent("click", e);
32682 onTouchStart : function(e){
32683 this.processEvent("touchstart", e);
32687 onContextMenu : function(e, t){
32688 this.processEvent("contextmenu", e);
32692 onDblClick : function(e){
32693 this.processEvent("dblclick", e);
32697 walkCells : function(row, col, step, fn, scope){
32698 var cm = this.colModel, clen = cm.getColumnCount();
32699 var ds = this.dataSource, rlen = ds.getCount(), first = true;
32711 if(fn.call(scope || this, row, col, cm) === true){
32729 if(fn.call(scope || this, row, col, cm) === true){
32741 getSelections : function(){
32742 return this.selModel.getSelections();
32746 * Causes the grid to manually recalculate its dimensions. Generally this is done automatically,
32747 * but if manual update is required this method will initiate it.
32749 autoSize : function(){
32751 this.view.layout();
32752 if(this.view.adjustForScroll){
32753 this.view.adjustForScroll();
32759 * Returns the grid's underlying element.
32760 * @return {Element} The element
32762 getGridEl : function(){
32763 return this.container;
32766 // private for compatibility, overridden by editor grid
32767 stopEditing : function(){},
32770 * Returns the grid's SelectionModel.
32771 * @return {SelectionModel}
32773 getSelectionModel : function(){
32774 if(!this.selModel){
32775 this.selModel = new Roo.grid.RowSelectionModel();
32777 return this.selModel;
32781 * Returns the grid's DataSource.
32782 * @return {DataSource}
32784 getDataSource : function(){
32785 return this.dataSource;
32789 * Returns the grid's ColumnModel.
32790 * @return {ColumnModel}
32792 getColumnModel : function(){
32793 return this.colModel;
32797 * Returns the grid's GridView object.
32798 * @return {GridView}
32800 getView : function(){
32802 this.view = new Roo.grid.GridView(this.viewConfig);
32807 * Called to get grid's drag proxy text, by default returns this.ddText.
32810 getDragDropText : function(){
32811 var count = this.selModel.getCount();
32812 return String.format(this.ddText, count, count == 1 ? '' : 's');
32816 * Configures the text is the drag proxy (defaults to "%0 selected row(s)").
32817 * %0 is replaced with the number of selected rows.
32820 Roo.grid.Grid.prototype.ddText = "{0} selected row{1}";/*
32822 * Ext JS Library 1.1.1
32823 * Copyright(c) 2006-2007, Ext JS, LLC.
32825 * Originally Released Under LGPL - original licence link has changed is not relivant.
32828 * <script type="text/javascript">
32831 Roo.grid.AbstractGridView = function(){
32835 "beforerowremoved" : true,
32836 "beforerowsinserted" : true,
32837 "beforerefresh" : true,
32838 "rowremoved" : true,
32839 "rowsinserted" : true,
32840 "rowupdated" : true,
32843 Roo.grid.AbstractGridView.superclass.constructor.call(this);
32846 Roo.extend(Roo.grid.AbstractGridView, Roo.util.Observable, {
32847 rowClass : "x-grid-row",
32848 cellClass : "x-grid-cell",
32849 tdClass : "x-grid-td",
32850 hdClass : "x-grid-hd",
32851 splitClass : "x-grid-hd-split",
32853 init: function(grid){
32855 var cid = this.grid.getGridEl().id;
32856 this.colSelector = "#" + cid + " ." + this.cellClass + "-";
32857 this.tdSelector = "#" + cid + " ." + this.tdClass + "-";
32858 this.hdSelector = "#" + cid + " ." + this.hdClass + "-";
32859 this.splitSelector = "#" + cid + " ." + this.splitClass + "-";
32862 getColumnRenderers : function(){
32863 var renderers = [];
32864 var cm = this.grid.colModel;
32865 var colCount = cm.getColumnCount();
32866 for(var i = 0; i < colCount; i++){
32867 renderers[i] = cm.getRenderer(i);
32872 getColumnIds : function(){
32874 var cm = this.grid.colModel;
32875 var colCount = cm.getColumnCount();
32876 for(var i = 0; i < colCount; i++){
32877 ids[i] = cm.getColumnId(i);
32882 getDataIndexes : function(){
32883 if(!this.indexMap){
32884 this.indexMap = this.buildIndexMap();
32886 return this.indexMap.colToData;
32889 getColumnIndexByDataIndex : function(dataIndex){
32890 if(!this.indexMap){
32891 this.indexMap = this.buildIndexMap();
32893 return this.indexMap.dataToCol[dataIndex];
32897 * Set a css style for a column dynamically.
32898 * @param {Number} colIndex The index of the column
32899 * @param {String} name The css property name
32900 * @param {String} value The css value
32902 setCSSStyle : function(colIndex, name, value){
32903 var selector = "#" + this.grid.id + " .x-grid-col-" + colIndex;
32904 Roo.util.CSS.updateRule(selector, name, value);
32907 generateRules : function(cm){
32908 var ruleBuf = [], rulesId = this.grid.id + '-cssrules';
32909 Roo.util.CSS.removeStyleSheet(rulesId);
32910 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
32911 var cid = cm.getColumnId(i);
32912 ruleBuf.push(this.colSelector, cid, " {\n", cm.config[i].css, "}\n",
32913 this.tdSelector, cid, " {\n}\n",
32914 this.hdSelector, cid, " {\n}\n",
32915 this.splitSelector, cid, " {\n}\n");
32917 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
32921 * Ext JS Library 1.1.1
32922 * Copyright(c) 2006-2007, Ext JS, LLC.
32924 * Originally Released Under LGPL - original licence link has changed is not relivant.
32927 * <script type="text/javascript">
32931 // This is a support class used internally by the Grid components
32932 Roo.grid.HeaderDragZone = function(grid, hd, hd2){
32934 this.view = grid.getView();
32935 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
32936 Roo.grid.HeaderDragZone.superclass.constructor.call(this, hd);
32938 this.setHandleElId(Roo.id(hd));
32939 this.setOuterHandleElId(Roo.id(hd2));
32941 this.scroll = false;
32943 Roo.extend(Roo.grid.HeaderDragZone, Roo.dd.DragZone, {
32945 getDragData : function(e){
32946 var t = Roo.lib.Event.getTarget(e);
32947 var h = this.view.findHeaderCell(t);
32949 return {ddel: h.firstChild, header:h};
32954 onInitDrag : function(e){
32955 this.view.headersDisabled = true;
32956 var clone = this.dragData.ddel.cloneNode(true);
32957 clone.id = Roo.id();
32958 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
32959 this.proxy.update(clone);
32963 afterValidDrop : function(){
32965 setTimeout(function(){
32966 v.headersDisabled = false;
32970 afterInvalidDrop : function(){
32972 setTimeout(function(){
32973 v.headersDisabled = false;
32979 * Ext JS Library 1.1.1
32980 * Copyright(c) 2006-2007, Ext JS, LLC.
32982 * Originally Released Under LGPL - original licence link has changed is not relivant.
32985 * <script type="text/javascript">
32988 // This is a support class used internally by the Grid components
32989 Roo.grid.HeaderDropZone = function(grid, hd, hd2){
32991 this.view = grid.getView();
32992 // split the proxies so they don't interfere with mouse events
32993 this.proxyTop = Roo.DomHelper.append(document.body, {
32994 cls:"col-move-top", html:" "
32996 this.proxyBottom = Roo.DomHelper.append(document.body, {
32997 cls:"col-move-bottom", html:" "
32999 this.proxyTop.hide = this.proxyBottom.hide = function(){
33000 this.setLeftTop(-100,-100);
33001 this.setStyle("visibility", "hidden");
33003 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
33004 // temporarily disabled
33005 //Roo.dd.ScrollManager.register(this.view.scroller.dom);
33006 Roo.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
33008 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
33009 proxyOffsets : [-4, -9],
33010 fly: Roo.Element.fly,
33012 getTargetFromEvent : function(e){
33013 var t = Roo.lib.Event.getTarget(e);
33014 var cindex = this.view.findCellIndex(t);
33015 if(cindex !== false){
33016 return this.view.getHeaderCell(cindex);
33021 nextVisible : function(h){
33022 var v = this.view, cm = this.grid.colModel;
33025 if(!cm.isHidden(v.getCellIndex(h))){
33033 prevVisible : function(h){
33034 var v = this.view, cm = this.grid.colModel;
33037 if(!cm.isHidden(v.getCellIndex(h))){
33045 positionIndicator : function(h, n, e){
33046 var x = Roo.lib.Event.getPageX(e);
33047 var r = Roo.lib.Dom.getRegion(n.firstChild);
33048 var px, pt, py = r.top + this.proxyOffsets[1];
33049 if((r.right - x) <= (r.right-r.left)/2){
33050 px = r.right+this.view.borderWidth;
33056 var oldIndex = this.view.getCellIndex(h);
33057 var newIndex = this.view.getCellIndex(n);
33059 if(this.grid.colModel.isFixed(newIndex)){
33063 var locked = this.grid.colModel.isLocked(newIndex);
33068 if(oldIndex < newIndex){
33071 if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){
33074 px += this.proxyOffsets[0];
33075 this.proxyTop.setLeftTop(px, py);
33076 this.proxyTop.show();
33077 if(!this.bottomOffset){
33078 this.bottomOffset = this.view.mainHd.getHeight();
33080 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
33081 this.proxyBottom.show();
33085 onNodeEnter : function(n, dd, e, data){
33086 if(data.header != n){
33087 this.positionIndicator(data.header, n, e);
33091 onNodeOver : function(n, dd, e, data){
33092 var result = false;
33093 if(data.header != n){
33094 result = this.positionIndicator(data.header, n, e);
33097 this.proxyTop.hide();
33098 this.proxyBottom.hide();
33100 return result ? this.dropAllowed : this.dropNotAllowed;
33103 onNodeOut : function(n, dd, e, data){
33104 this.proxyTop.hide();
33105 this.proxyBottom.hide();
33108 onNodeDrop : function(n, dd, e, data){
33109 var h = data.header;
33111 var cm = this.grid.colModel;
33112 var x = Roo.lib.Event.getPageX(e);
33113 var r = Roo.lib.Dom.getRegion(n.firstChild);
33114 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
33115 var oldIndex = this.view.getCellIndex(h);
33116 var newIndex = this.view.getCellIndex(n);
33117 var locked = cm.isLocked(newIndex);
33121 if(oldIndex < newIndex){
33124 if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){
33127 cm.setLocked(oldIndex, locked, true);
33128 cm.moveColumn(oldIndex, newIndex);
33129 this.grid.fireEvent("columnmove", oldIndex, newIndex);
33137 * Ext JS Library 1.1.1
33138 * Copyright(c) 2006-2007, Ext JS, LLC.
33140 * Originally Released Under LGPL - original licence link has changed is not relivant.
33143 * <script type="text/javascript">
33147 * @class Roo.grid.GridView
33148 * @extends Roo.util.Observable
33151 * @param {Object} config
33153 Roo.grid.GridView = function(config){
33154 Roo.grid.GridView.superclass.constructor.call(this);
33157 Roo.apply(this, config);
33160 Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
33162 unselectable : 'unselectable="on"',
33163 unselectableCls : 'x-unselectable',
33166 rowClass : "x-grid-row",
33168 cellClass : "x-grid-col",
33170 tdClass : "x-grid-td",
33172 hdClass : "x-grid-hd",
33174 splitClass : "x-grid-split",
33176 sortClasses : ["sort-asc", "sort-desc"],
33178 enableMoveAnim : false,
33182 dh : Roo.DomHelper,
33184 fly : Roo.Element.fly,
33186 css : Roo.util.CSS,
33192 scrollIncrement : 22,
33194 cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
33196 findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
33198 bind : function(ds, cm){
33200 this.ds.un("load", this.onLoad, this);
33201 this.ds.un("datachanged", this.onDataChange, this);
33202 this.ds.un("add", this.onAdd, this);
33203 this.ds.un("remove", this.onRemove, this);
33204 this.ds.un("update", this.onUpdate, this);
33205 this.ds.un("clear", this.onClear, this);
33208 ds.on("load", this.onLoad, this);
33209 ds.on("datachanged", this.onDataChange, this);
33210 ds.on("add", this.onAdd, this);
33211 ds.on("remove", this.onRemove, this);
33212 ds.on("update", this.onUpdate, this);
33213 ds.on("clear", this.onClear, this);
33218 this.cm.un("widthchange", this.onColWidthChange, this);
33219 this.cm.un("headerchange", this.onHeaderChange, this);
33220 this.cm.un("hiddenchange", this.onHiddenChange, this);
33221 this.cm.un("columnmoved", this.onColumnMove, this);
33222 this.cm.un("columnlockchange", this.onColumnLock, this);
33225 this.generateRules(cm);
33226 cm.on("widthchange", this.onColWidthChange, this);
33227 cm.on("headerchange", this.onHeaderChange, this);
33228 cm.on("hiddenchange", this.onHiddenChange, this);
33229 cm.on("columnmoved", this.onColumnMove, this);
33230 cm.on("columnlockchange", this.onColumnLock, this);
33235 init: function(grid){
33236 Roo.grid.GridView.superclass.init.call(this, grid);
33238 this.bind(grid.dataSource, grid.colModel);
33240 grid.on("headerclick", this.handleHeaderClick, this);
33242 if(grid.trackMouseOver){
33243 grid.on("mouseover", this.onRowOver, this);
33244 grid.on("mouseout", this.onRowOut, this);
33246 grid.cancelTextSelection = function(){};
33247 this.gridId = grid.id;
33249 var tpls = this.templates || {};
33252 tpls.master = new Roo.Template(
33253 '<div class="x-grid" hidefocus="true">',
33254 '<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
33255 '<div class="x-grid-topbar"></div>',
33256 '<div class="x-grid-scroller"><div></div></div>',
33257 '<div class="x-grid-locked">',
33258 '<div class="x-grid-header">{lockedHeader}</div>',
33259 '<div class="x-grid-body">{lockedBody}</div>',
33261 '<div class="x-grid-viewport">',
33262 '<div class="x-grid-header">{header}</div>',
33263 '<div class="x-grid-body">{body}</div>',
33265 '<div class="x-grid-bottombar"></div>',
33267 '<div class="x-grid-resize-proxy"> </div>',
33270 tpls.master.disableformats = true;
33274 tpls.header = new Roo.Template(
33275 '<table border="0" cellspacing="0" cellpadding="0">',
33276 '<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
33279 tpls.header.disableformats = true;
33281 tpls.header.compile();
33284 tpls.hcell = new Roo.Template(
33285 '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
33286 '<div class="x-grid-hd-text ' + this.unselectableCls + '" ' + this.unselectable +'>{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
33289 tpls.hcell.disableFormats = true;
33291 tpls.hcell.compile();
33294 tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style} ' +
33295 this.unselectableCls + '" ' + this.unselectable +'> </div>');
33296 tpls.hsplit.disableFormats = true;
33298 tpls.hsplit.compile();
33301 tpls.body = new Roo.Template(
33302 '<table border="0" cellspacing="0" cellpadding="0">',
33303 "<tbody>{rows}</tbody>",
33306 tpls.body.disableFormats = true;
33308 tpls.body.compile();
33311 tpls.row = new Roo.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
33312 tpls.row.disableFormats = true;
33314 tpls.row.compile();
33317 tpls.cell = new Roo.Template(
33318 '<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
33319 '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text ' +
33320 this.unselectableCls + '" ' + this.unselectable +'" {attr}>{value}</div></div>',
33323 tpls.cell.disableFormats = true;
33325 tpls.cell.compile();
33327 this.templates = tpls;
33330 // remap these for backwards compat
33331 onColWidthChange : function(){
33332 this.updateColumns.apply(this, arguments);
33334 onHeaderChange : function(){
33335 this.updateHeaders.apply(this, arguments);
33337 onHiddenChange : function(){
33338 this.handleHiddenChange.apply(this, arguments);
33340 onColumnMove : function(){
33341 this.handleColumnMove.apply(this, arguments);
33343 onColumnLock : function(){
33344 this.handleLockChange.apply(this, arguments);
33347 onDataChange : function(){
33349 this.updateHeaderSortState();
33352 onClear : function(){
33356 onUpdate : function(ds, record){
33357 this.refreshRow(record);
33360 refreshRow : function(record){
33361 var ds = this.ds, index;
33362 if(typeof record == 'number'){
33364 record = ds.getAt(index);
33366 index = ds.indexOf(record);
33368 this.insertRows(ds, index, index, true);
33369 this.onRemove(ds, record, index+1, true);
33370 this.syncRowHeights(index, index);
33372 this.fireEvent("rowupdated", this, index, record);
33375 onAdd : function(ds, records, index){
33376 this.insertRows(ds, index, index + (records.length-1));
33379 onRemove : function(ds, record, index, isUpdate){
33380 if(isUpdate !== true){
33381 this.fireEvent("beforerowremoved", this, index, record);
33383 var bt = this.getBodyTable(), lt = this.getLockedTable();
33384 if(bt.rows[index]){
33385 bt.firstChild.removeChild(bt.rows[index]);
33387 if(lt.rows[index]){
33388 lt.firstChild.removeChild(lt.rows[index]);
33390 if(isUpdate !== true){
33391 this.stripeRows(index);
33392 this.syncRowHeights(index, index);
33394 this.fireEvent("rowremoved", this, index, record);
33398 onLoad : function(){
33399 this.scrollToTop();
33403 * Scrolls the grid to the top
33405 scrollToTop : function(){
33407 this.scroller.dom.scrollTop = 0;
33413 * Gets a panel in the header of the grid that can be used for toolbars etc.
33414 * After modifying the contents of this panel a call to grid.autoSize() may be
33415 * required to register any changes in size.
33416 * @param {Boolean} doShow By default the header is hidden. Pass true to show the panel
33417 * @return Roo.Element
33419 getHeaderPanel : function(doShow){
33421 this.headerPanel.show();
33423 return this.headerPanel;
33427 * Gets a panel in the footer of the grid that can be used for toolbars etc.
33428 * After modifying the contents of this panel a call to grid.autoSize() may be
33429 * required to register any changes in size.
33430 * @param {Boolean} doShow By default the footer is hidden. Pass true to show the panel
33431 * @return Roo.Element
33433 getFooterPanel : function(doShow){
33435 this.footerPanel.show();
33437 return this.footerPanel;
33440 initElements : function(){
33441 var E = Roo.Element;
33442 var el = this.grid.getGridEl().dom.firstChild;
33443 var cs = el.childNodes;
33445 this.el = new E(el);
33447 this.focusEl = new E(el.firstChild);
33448 this.focusEl.swallowEvent("click", true);
33450 this.headerPanel = new E(cs[1]);
33451 this.headerPanel.enableDisplayMode("block");
33453 this.scroller = new E(cs[2]);
33454 this.scrollSizer = new E(this.scroller.dom.firstChild);
33456 this.lockedWrap = new E(cs[3]);
33457 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
33458 this.lockedBody = new E(this.lockedWrap.dom.childNodes[1]);
33460 this.mainWrap = new E(cs[4]);
33461 this.mainHd = new E(this.mainWrap.dom.firstChild);
33462 this.mainBody = new E(this.mainWrap.dom.childNodes[1]);
33464 this.footerPanel = new E(cs[5]);
33465 this.footerPanel.enableDisplayMode("block");
33467 this.resizeProxy = new E(cs[6]);
33469 this.headerSelector = String.format(
33470 '#{0} td.x-grid-hd, #{1} td.x-grid-hd',
33471 this.lockedHd.id, this.mainHd.id
33474 this.splitterSelector = String.format(
33475 '#{0} div.x-grid-split, #{1} div.x-grid-split',
33476 this.idToCssName(this.lockedHd.id), this.idToCssName(this.mainHd.id)
33479 idToCssName : function(s)
33481 return s.replace(/[^a-z0-9]+/ig, '-');
33484 getHeaderCell : function(index){
33485 return Roo.DomQuery.select(this.headerSelector)[index];
33488 getHeaderCellMeasure : function(index){
33489 return this.getHeaderCell(index).firstChild;
33492 getHeaderCellText : function(index){
33493 return this.getHeaderCell(index).firstChild.firstChild;
33496 getLockedTable : function(){
33497 return this.lockedBody.dom.firstChild;
33500 getBodyTable : function(){
33501 return this.mainBody.dom.firstChild;
33504 getLockedRow : function(index){
33505 return this.getLockedTable().rows[index];
33508 getRow : function(index){
33509 return this.getBodyTable().rows[index];
33512 getRowComposite : function(index){
33514 this.rowEl = new Roo.CompositeElementLite();
33516 var els = [], lrow, mrow;
33517 if(lrow = this.getLockedRow(index)){
33520 if(mrow = this.getRow(index)){
33523 this.rowEl.elements = els;
33527 * Gets the 'td' of the cell
33529 * @param {Integer} rowIndex row to select
33530 * @param {Integer} colIndex column to select
33534 getCell : function(rowIndex, colIndex){
33535 var locked = this.cm.getLockedCount();
33537 if(colIndex < locked){
33538 source = this.lockedBody.dom.firstChild;
33540 source = this.mainBody.dom.firstChild;
33541 colIndex -= locked;
33543 return source.rows[rowIndex].childNodes[colIndex];
33546 getCellText : function(rowIndex, colIndex){
33547 return this.getCell(rowIndex, colIndex).firstChild.firstChild;
33550 getCellBox : function(cell){
33551 var b = this.fly(cell).getBox();
33552 if(Roo.isOpera){ // opera fails to report the Y
33553 b.y = cell.offsetTop + this.mainBody.getY();
33558 getCellIndex : function(cell){
33559 var id = String(cell.className).match(this.cellRE);
33561 return parseInt(id[1], 10);
33566 findHeaderIndex : function(n){
33567 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
33568 return r ? this.getCellIndex(r) : false;
33571 findHeaderCell : function(n){
33572 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
33573 return r ? r : false;
33576 findRowIndex : function(n){
33580 var r = Roo.fly(n).findParent("tr." + this.rowClass, 6);
33581 return r ? r.rowIndex : false;
33584 findCellIndex : function(node){
33585 var stop = this.el.dom;
33586 while(node && node != stop){
33587 if(this.findRE.test(node.className)){
33588 return this.getCellIndex(node);
33590 node = node.parentNode;
33595 getColumnId : function(index){
33596 return this.cm.getColumnId(index);
33599 getSplitters : function()
33601 if(this.splitterSelector){
33602 return Roo.DomQuery.select(this.splitterSelector);
33608 getSplitter : function(index){
33609 return this.getSplitters()[index];
33612 onRowOver : function(e, t){
33614 if((row = this.findRowIndex(t)) !== false){
33615 this.getRowComposite(row).addClass("x-grid-row-over");
33619 onRowOut : function(e, t){
33621 if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){
33622 this.getRowComposite(row).removeClass("x-grid-row-over");
33626 renderHeaders : function(){
33628 var ct = this.templates.hcell, ht = this.templates.header, st = this.templates.hsplit;
33629 var cb = [], lb = [], sb = [], lsb = [], p = {};
33630 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
33631 p.cellId = "x-grid-hd-0-" + i;
33632 p.splitId = "x-grid-csplit-0-" + i;
33633 p.id = cm.getColumnId(i);
33634 p.value = cm.getColumnHeader(i) || "";
33635 p.title = cm.getColumnTooltip(i) || (''+p.value).match(/\</) ? '' : p.value || "";
33636 p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
33637 if(!cm.isLocked(i)){
33638 cb[cb.length] = ct.apply(p);
33639 sb[sb.length] = st.apply(p);
33641 lb[lb.length] = ct.apply(p);
33642 lsb[lsb.length] = st.apply(p);
33645 return [ht.apply({cells: lb.join(""), splits:lsb.join("")}),
33646 ht.apply({cells: cb.join(""), splits:sb.join("")})];
33649 updateHeaders : function(){
33650 var html = this.renderHeaders();
33651 this.lockedHd.update(html[0]);
33652 this.mainHd.update(html[1]);
33656 * Focuses the specified row.
33657 * @param {Number} row The row index
33659 focusRow : function(row)
33661 //Roo.log('GridView.focusRow');
33662 var x = this.scroller.dom.scrollLeft;
33663 this.focusCell(row, 0, false);
33664 this.scroller.dom.scrollLeft = x;
33668 * Focuses the specified cell.
33669 * @param {Number} row The row index
33670 * @param {Number} col The column index
33671 * @param {Boolean} hscroll false to disable horizontal scrolling
33673 focusCell : function(row, col, hscroll)
33675 //Roo.log('GridView.focusCell');
33676 var el = this.ensureVisible(row, col, hscroll);
33677 this.focusEl.alignTo(el, "tl-tl");
33679 this.focusEl.focus();
33681 this.focusEl.focus.defer(1, this.focusEl);
33686 * Scrolls the specified cell into view
33687 * @param {Number} row The row index
33688 * @param {Number} col The column index
33689 * @param {Boolean} hscroll false to disable horizontal scrolling
33691 ensureVisible : function(row, col, hscroll)
33693 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
33694 //return null; //disable for testing.
33695 if(typeof row != "number"){
33696 row = row.rowIndex;
33698 if(row < 0 && row >= this.ds.getCount()){
33701 col = (col !== undefined ? col : 0);
33702 var cm = this.grid.colModel;
33703 while(cm.isHidden(col)){
33707 var el = this.getCell(row, col);
33711 var c = this.scroller.dom;
33713 var ctop = parseInt(el.offsetTop, 10);
33714 var cleft = parseInt(el.offsetLeft, 10);
33715 var cbot = ctop + el.offsetHeight;
33716 var cright = cleft + el.offsetWidth;
33718 var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
33719 var stop = parseInt(c.scrollTop, 10);
33720 var sleft = parseInt(c.scrollLeft, 10);
33721 var sbot = stop + ch;
33722 var sright = sleft + c.clientWidth;
33724 Roo.log('GridView.ensureVisible:' +
33726 ' c.clientHeight:' + c.clientHeight +
33727 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
33735 c.scrollTop = ctop;
33736 //Roo.log("set scrolltop to ctop DISABLE?");
33737 }else if(cbot > sbot){
33738 //Roo.log("set scrolltop to cbot-ch");
33739 c.scrollTop = cbot-ch;
33742 if(hscroll !== false){
33744 c.scrollLeft = cleft;
33745 }else if(cright > sright){
33746 c.scrollLeft = cright-c.clientWidth;
33753 updateColumns : function(){
33754 this.grid.stopEditing();
33755 var cm = this.grid.colModel, colIds = this.getColumnIds();
33756 //var totalWidth = cm.getTotalWidth();
33758 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
33759 //if(cm.isHidden(i)) continue;
33760 var w = cm.getColumnWidth(i);
33761 this.css.updateRule(this.colSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
33762 this.css.updateRule(this.hdSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
33764 this.updateSplitters();
33767 generateRules : function(cm){
33768 var ruleBuf = [], rulesId = this.idToCssName(this.grid.id)+ '-cssrules';
33769 Roo.util.CSS.removeStyleSheet(rulesId);
33770 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
33771 var cid = cm.getColumnId(i);
33773 if(cm.config[i].align){
33774 align = 'text-align:'+cm.config[i].align+';';
33777 if(cm.isHidden(i)){
33778 hidden = 'display:none;';
33780 var width = "width:" + (cm.getColumnWidth(i) - this.borderWidth) + "px;";
33782 this.colSelector, cid, " {\n", cm.config[i].css, align, width, "\n}\n",
33783 this.hdSelector, cid, " {\n", align, width, "}\n",
33784 this.tdSelector, cid, " {\n",hidden,"\n}\n",
33785 this.splitSelector, cid, " {\n", hidden , "\n}\n");
33787 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
33790 updateSplitters : function(){
33791 var cm = this.cm, s = this.getSplitters();
33792 if(s){ // splitters not created yet
33793 var pos = 0, locked = true;
33794 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
33795 if(cm.isHidden(i)) {
33798 var w = cm.getColumnWidth(i); // make sure it's a number
33799 if(!cm.isLocked(i) && locked){
33804 s[i].style.left = (pos-this.splitOffset) + "px";
33809 handleHiddenChange : function(colModel, colIndex, hidden){
33811 this.hideColumn(colIndex);
33813 this.unhideColumn(colIndex);
33817 hideColumn : function(colIndex){
33818 var cid = this.getColumnId(colIndex);
33819 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "none");
33820 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "none");
33822 this.updateHeaders();
33824 this.updateSplitters();
33828 unhideColumn : function(colIndex){
33829 var cid = this.getColumnId(colIndex);
33830 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "");
33831 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "");
33834 this.updateHeaders();
33836 this.updateSplitters();
33840 insertRows : function(dm, firstRow, lastRow, isUpdate){
33841 if(firstRow == 0 && lastRow == dm.getCount()-1){
33845 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
33847 var s = this.getScrollState();
33848 var markup = this.renderRows(firstRow, lastRow);
33849 this.bufferRows(markup[0], this.getLockedTable(), firstRow);
33850 this.bufferRows(markup[1], this.getBodyTable(), firstRow);
33851 this.restoreScroll(s);
33853 this.fireEvent("rowsinserted", this, firstRow, lastRow);
33854 this.syncRowHeights(firstRow, lastRow);
33855 this.stripeRows(firstRow);
33861 bufferRows : function(markup, target, index){
33862 var before = null, trows = target.rows, tbody = target.tBodies[0];
33863 if(index < trows.length){
33864 before = trows[index];
33866 var b = document.createElement("div");
33867 b.innerHTML = "<table><tbody>"+markup+"</tbody></table>";
33868 var rows = b.firstChild.rows;
33869 for(var i = 0, len = rows.length; i < len; i++){
33871 tbody.insertBefore(rows[0], before);
33873 tbody.appendChild(rows[0]);
33880 deleteRows : function(dm, firstRow, lastRow){
33881 if(dm.getRowCount()<1){
33882 this.fireEvent("beforerefresh", this);
33883 this.mainBody.update("");
33884 this.lockedBody.update("");
33885 this.fireEvent("refresh", this);
33887 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
33888 var bt = this.getBodyTable();
33889 var tbody = bt.firstChild;
33890 var rows = bt.rows;
33891 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
33892 tbody.removeChild(rows[firstRow]);
33894 this.stripeRows(firstRow);
33895 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
33899 updateRows : function(dataSource, firstRow, lastRow){
33900 var s = this.getScrollState();
33902 this.restoreScroll(s);
33905 handleSort : function(dataSource, sortColumnIndex, sortDir, noRefresh){
33909 this.updateHeaderSortState();
33912 getScrollState : function(){
33914 var sb = this.scroller.dom;
33915 return {left: sb.scrollLeft, top: sb.scrollTop};
33918 stripeRows : function(startRow){
33919 if(!this.grid.stripeRows || this.ds.getCount() < 1){
33922 startRow = startRow || 0;
33923 var rows = this.getBodyTable().rows;
33924 var lrows = this.getLockedTable().rows;
33925 var cls = ' x-grid-row-alt ';
33926 for(var i = startRow, len = rows.length; i < len; i++){
33927 var row = rows[i], lrow = lrows[i];
33928 var isAlt = ((i+1) % 2 == 0);
33929 var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
33930 if(isAlt == hasAlt){
33934 row.className += " x-grid-row-alt";
33936 row.className = row.className.replace("x-grid-row-alt", "");
33939 lrow.className = row.className;
33944 restoreScroll : function(state){
33945 //Roo.log('GridView.restoreScroll');
33946 var sb = this.scroller.dom;
33947 sb.scrollLeft = state.left;
33948 sb.scrollTop = state.top;
33952 syncScroll : function(){
33953 //Roo.log('GridView.syncScroll');
33954 var sb = this.scroller.dom;
33955 var sh = this.mainHd.dom;
33956 var bs = this.mainBody.dom;
33957 var lv = this.lockedBody.dom;
33958 sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
33959 lv.scrollTop = bs.scrollTop = sb.scrollTop;
33962 handleScroll : function(e){
33964 var sb = this.scroller.dom;
33965 this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
33969 handleWheel : function(e){
33970 var d = e.getWheelDelta();
33971 this.scroller.dom.scrollTop -= d*22;
33972 // set this here to prevent jumpy scrolling on large tables
33973 this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
33977 renderRows : function(startRow, endRow){
33978 // pull in all the crap needed to render rows
33979 var g = this.grid, cm = g.colModel, ds = g.dataSource, stripe = g.stripeRows;
33980 var colCount = cm.getColumnCount();
33982 if(ds.getCount() < 1){
33986 // build a map for all the columns
33988 for(var i = 0; i < colCount; i++){
33989 var name = cm.getDataIndex(i);
33991 name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
33992 renderer : cm.getRenderer(i),
33993 id : cm.getColumnId(i),
33994 locked : cm.isLocked(i),
33995 has_editor : cm.isCellEditable(i)
33999 startRow = startRow || 0;
34000 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
34002 // records to render
34003 var rs = ds.getRange(startRow, endRow);
34005 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
34008 // As much as I hate to duplicate code, this was branched because FireFox really hates
34009 // [].join("") on strings. The performance difference was substantial enough to
34010 // branch this function
34011 doRender : Roo.isGecko ?
34012 function(cs, rs, ds, startRow, colCount, stripe){
34013 var ts = this.templates, ct = ts.cell, rt = ts.row;
34015 var buf = "", lbuf = "", cb, lcb, c, p = {}, rp = {}, r, rowIndex;
34017 var hasListener = this.grid.hasListener('rowclass');
34019 for(var j = 0, len = rs.length; j < len; j++){
34020 r = rs[j]; cb = ""; lcb = ""; rowIndex = (j+startRow);
34021 for(var i = 0; i < colCount; i++){
34023 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
34025 p.css = p.attr = "";
34026 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
34027 if(p.value == undefined || p.value === "") {
34028 p.value = " ";
34031 p.css += ' x-grid-editable-cell';
34033 if(c.dirty && typeof r.modified[c.name] !== 'undefined'){
34034 p.css += ' x-grid-dirty-cell';
34036 var markup = ct.apply(p);
34044 if(stripe && ((rowIndex+1) % 2 == 0)){
34045 alt.push("x-grid-row-alt")
34048 alt.push( " x-grid-dirty-row");
34051 if(this.getRowClass){
34052 alt.push(this.getRowClass(r, rowIndex));
34058 rowIndex : rowIndex,
34061 this.grid.fireEvent('rowclass', this, rowcfg);
34062 alt.push(rowcfg.rowClass);
34064 rp.alt = alt.join(" ");
34065 lbuf+= rt.apply(rp);
34067 buf+= rt.apply(rp);
34069 return [lbuf, buf];
34071 function(cs, rs, ds, startRow, colCount, stripe){
34072 var ts = this.templates, ct = ts.cell, rt = ts.row;
34074 var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
34075 var hasListener = this.grid.hasListener('rowclass');
34078 for(var j = 0, len = rs.length; j < len; j++){
34079 r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
34080 for(var i = 0; i < colCount; i++){
34082 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
34084 p.css = p.attr = "";
34085 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
34086 if(p.value == undefined || p.value === "") {
34087 p.value = " ";
34091 p.css += ' x-grid-editable-cell';
34093 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
34094 p.css += ' x-grid-dirty-cell'
34097 var markup = ct.apply(p);
34099 cb[cb.length] = markup;
34101 lcb[lcb.length] = markup;
34105 if(stripe && ((rowIndex+1) % 2 == 0)){
34106 alt.push( "x-grid-row-alt");
34109 alt.push(" x-grid-dirty-row");
34112 if(this.getRowClass){
34113 alt.push( this.getRowClass(r, rowIndex));
34119 rowIndex : rowIndex,
34122 this.grid.fireEvent('rowclass', this, rowcfg);
34123 alt.push(rowcfg.rowClass);
34126 rp.alt = alt.join(" ");
34127 rp.cells = lcb.join("");
34128 lbuf[lbuf.length] = rt.apply(rp);
34129 rp.cells = cb.join("");
34130 buf[buf.length] = rt.apply(rp);
34132 return [lbuf.join(""), buf.join("")];
34135 renderBody : function(){
34136 var markup = this.renderRows();
34137 var bt = this.templates.body;
34138 return [bt.apply({rows: markup[0]}), bt.apply({rows: markup[1]})];
34142 * Refreshes the grid
34143 * @param {Boolean} headersToo
34145 refresh : function(headersToo){
34146 this.fireEvent("beforerefresh", this);
34147 this.grid.stopEditing();
34148 var result = this.renderBody();
34149 this.lockedBody.update(result[0]);
34150 this.mainBody.update(result[1]);
34151 if(headersToo === true){
34152 this.updateHeaders();
34153 this.updateColumns();
34154 this.updateSplitters();
34155 this.updateHeaderSortState();
34157 this.syncRowHeights();
34159 this.fireEvent("refresh", this);
34162 handleColumnMove : function(cm, oldIndex, newIndex){
34163 this.indexMap = null;
34164 var s = this.getScrollState();
34165 this.refresh(true);
34166 this.restoreScroll(s);
34167 this.afterMove(newIndex);
34170 afterMove : function(colIndex){
34171 if(this.enableMoveAnim && Roo.enableFx){
34172 this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
34174 // if multisort - fix sortOrder, and reload..
34175 if (this.grid.dataSource.multiSort) {
34176 // the we can call sort again..
34177 var dm = this.grid.dataSource;
34178 var cm = this.grid.colModel;
34180 for(var i = 0; i < cm.config.length; i++ ) {
34182 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined')) {
34183 continue; // dont' bother, it's not in sort list or being set.
34186 so.push(cm.config[i].dataIndex);
34189 dm.load(dm.lastOptions);
34196 updateCell : function(dm, rowIndex, dataIndex){
34197 var colIndex = this.getColumnIndexByDataIndex(dataIndex);
34198 if(typeof colIndex == "undefined"){ // not present in grid
34201 var cm = this.grid.colModel;
34202 var cell = this.getCell(rowIndex, colIndex);
34203 var cellText = this.getCellText(rowIndex, colIndex);
34206 cellId : "x-grid-cell-" + rowIndex + "-" + colIndex,
34207 id : cm.getColumnId(colIndex),
34208 css: colIndex == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
34210 var renderer = cm.getRenderer(colIndex);
34211 var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
34212 if(typeof val == "undefined" || val === "") {
34215 cellText.innerHTML = val;
34216 cell.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
34217 this.syncRowHeights(rowIndex, rowIndex);
34220 calcColumnWidth : function(colIndex, maxRowsToMeasure){
34222 if(this.grid.autoSizeHeaders){
34223 var h = this.getHeaderCellMeasure(colIndex);
34224 maxWidth = Math.max(maxWidth, h.scrollWidth);
34227 if(this.cm.isLocked(colIndex)){
34228 tb = this.getLockedTable();
34231 tb = this.getBodyTable();
34232 index = colIndex - this.cm.getLockedCount();
34235 var rows = tb.rows;
34236 var stopIndex = Math.min(maxRowsToMeasure || rows.length, rows.length);
34237 for(var i = 0; i < stopIndex; i++){
34238 var cell = rows[i].childNodes[index].firstChild;
34239 maxWidth = Math.max(maxWidth, cell.scrollWidth);
34242 return maxWidth + /*margin for error in IE*/ 5;
34245 * Autofit a column to its content.
34246 * @param {Number} colIndex
34247 * @param {Boolean} forceMinSize true to force the column to go smaller if possible
34249 autoSizeColumn : function(colIndex, forceMinSize, suppressEvent){
34250 if(this.cm.isHidden(colIndex)){
34251 return; // can't calc a hidden column
34254 var cid = this.cm.getColumnId(colIndex);
34255 this.css.updateRule(this.colSelector +this.idToCssName( cid), "width", this.grid.minColumnWidth + "px");
34256 if(this.grid.autoSizeHeaders){
34257 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", this.grid.minColumnWidth + "px");
34260 var newWidth = this.calcColumnWidth(colIndex);
34261 this.cm.setColumnWidth(colIndex,
34262 Math.max(this.grid.minColumnWidth, newWidth), suppressEvent);
34263 if(!suppressEvent){
34264 this.grid.fireEvent("columnresize", colIndex, newWidth);
34269 * Autofits all columns to their content and then expands to fit any extra space in the grid
34271 autoSizeColumns : function(){
34272 var cm = this.grid.colModel;
34273 var colCount = cm.getColumnCount();
34274 for(var i = 0; i < colCount; i++){
34275 this.autoSizeColumn(i, true, true);
34277 if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
34280 this.updateColumns();
34286 * Autofits all columns to the grid's width proportionate with their current size
34287 * @param {Boolean} reserveScrollSpace Reserve space for a scrollbar
34289 fitColumns : function(reserveScrollSpace){
34290 var cm = this.grid.colModel;
34291 var colCount = cm.getColumnCount();
34295 for (i = 0; i < colCount; i++){
34296 if(!cm.isHidden(i) && !cm.isFixed(i)){
34297 w = cm.getColumnWidth(i);
34303 var avail = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
34304 if(reserveScrollSpace){
34307 var frac = (avail - cm.getTotalWidth())/width;
34308 while (cols.length){
34311 cm.setColumnWidth(i, Math.floor(w + w*frac), true);
34313 this.updateColumns();
34317 onRowSelect : function(rowIndex){
34318 var row = this.getRowComposite(rowIndex);
34319 row.addClass("x-grid-row-selected");
34322 onRowDeselect : function(rowIndex){
34323 var row = this.getRowComposite(rowIndex);
34324 row.removeClass("x-grid-row-selected");
34327 onCellSelect : function(row, col){
34328 var cell = this.getCell(row, col);
34330 Roo.fly(cell).addClass("x-grid-cell-selected");
34334 onCellDeselect : function(row, col){
34335 var cell = this.getCell(row, col);
34337 Roo.fly(cell).removeClass("x-grid-cell-selected");
34341 updateHeaderSortState : function(){
34343 // sort state can be single { field: xxx, direction : yyy}
34344 // or { xxx=>ASC , yyy : DESC ..... }
34347 if (!this.ds.multiSort) {
34348 var state = this.ds.getSortState();
34352 mstate[state.field] = state.direction;
34353 // FIXME... - this is not used here.. but might be elsewhere..
34354 this.sortState = state;
34357 mstate = this.ds.sortToggle;
34359 //remove existing sort classes..
34361 var sc = this.sortClasses;
34362 var hds = this.el.select(this.headerSelector).removeClass(sc);
34364 for(var f in mstate) {
34366 var sortColumn = this.cm.findColumnIndex(f);
34368 if(sortColumn != -1){
34369 var sortDir = mstate[f];
34370 hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
34379 handleHeaderClick : function(g, index,e){
34381 Roo.log("header click");
34384 // touch events on header are handled by context
34385 this.handleHdCtx(g,index,e);
34390 if(this.headersDisabled){
34393 var dm = g.dataSource, cm = g.colModel;
34394 if(!cm.isSortable(index)){
34399 if (dm.multiSort) {
34400 // update the sortOrder
34402 for(var i = 0; i < cm.config.length; i++ ) {
34404 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined') && (index != i)) {
34405 continue; // dont' bother, it's not in sort list or being set.
34408 so.push(cm.config[i].dataIndex);
34414 dm.sort(cm.getDataIndex(index));
34418 destroy : function(){
34420 this.colMenu.removeAll();
34421 Roo.menu.MenuMgr.unregister(this.colMenu);
34422 this.colMenu.getEl().remove();
34423 delete this.colMenu;
34426 this.hmenu.removeAll();
34427 Roo.menu.MenuMgr.unregister(this.hmenu);
34428 this.hmenu.getEl().remove();
34431 if(this.grid.enableColumnMove){
34432 var dds = Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
34434 for(var dd in dds){
34435 if(!dds[dd].config.isTarget && dds[dd].dragElId){
34436 var elid = dds[dd].dragElId;
34438 Roo.get(elid).remove();
34439 } else if(dds[dd].config.isTarget){
34440 dds[dd].proxyTop.remove();
34441 dds[dd].proxyBottom.remove();
34444 if(Roo.dd.DDM.locationCache[dd]){
34445 delete Roo.dd.DDM.locationCache[dd];
34448 delete Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
34451 Roo.util.CSS.removeStyleSheet(this.idToCssName(this.grid.id) + '-cssrules');
34452 this.bind(null, null);
34453 Roo.EventManager.removeResizeListener(this.onWindowResize, this);
34456 handleLockChange : function(){
34457 this.refresh(true);
34460 onDenyColumnLock : function(){
34464 onDenyColumnHide : function(){
34468 handleHdMenuClick : function(item){
34469 var index = this.hdCtxIndex;
34470 var cm = this.cm, ds = this.ds;
34473 ds.sort(cm.getDataIndex(index), "ASC");
34476 ds.sort(cm.getDataIndex(index), "DESC");
34479 var lc = cm.getLockedCount();
34480 if(cm.getColumnCount(true) <= lc+1){
34481 this.onDenyColumnLock();
34485 cm.setLocked(index, true, true);
34486 cm.moveColumn(index, lc);
34487 this.grid.fireEvent("columnmove", index, lc);
34489 cm.setLocked(index, true);
34493 var lc = cm.getLockedCount();
34494 if((lc-1) != index){
34495 cm.setLocked(index, false, true);
34496 cm.moveColumn(index, lc-1);
34497 this.grid.fireEvent("columnmove", index, lc-1);
34499 cm.setLocked(index, false);
34502 case 'wider': // used to expand cols on touch..
34504 var cw = cm.getColumnWidth(index);
34505 cw += (item.id == 'wider' ? 1 : -1) * 50;
34506 cw = Math.max(0, cw);
34507 cw = Math.min(cw,4000);
34508 cm.setColumnWidth(index, cw);
34512 index = cm.getIndexById(item.id.substr(4));
34514 if(item.checked && cm.getColumnCount(true) <= 1){
34515 this.onDenyColumnHide();
34518 cm.setHidden(index, item.checked);
34524 beforeColMenuShow : function(){
34525 var cm = this.cm, colCount = cm.getColumnCount();
34526 this.colMenu.removeAll();
34527 for(var i = 0; i < colCount; i++){
34528 this.colMenu.add(new Roo.menu.CheckItem({
34529 id: "col-"+cm.getColumnId(i),
34530 text: cm.getColumnHeader(i),
34531 checked: !cm.isHidden(i),
34537 handleHdCtx : function(g, index, e){
34539 var hd = this.getHeaderCell(index);
34540 this.hdCtxIndex = index;
34541 var ms = this.hmenu.items, cm = this.cm;
34542 ms.get("asc").setDisabled(!cm.isSortable(index));
34543 ms.get("desc").setDisabled(!cm.isSortable(index));
34544 if(this.grid.enableColLock !== false){
34545 ms.get("lock").setDisabled(cm.isLocked(index));
34546 ms.get("unlock").setDisabled(!cm.isLocked(index));
34548 this.hmenu.show(hd, "tl-bl");
34551 handleHdOver : function(e){
34552 var hd = this.findHeaderCell(e.getTarget());
34553 if(hd && !this.headersDisabled){
34554 if(this.grid.colModel.isSortable(this.getCellIndex(hd))){
34555 this.fly(hd).addClass("x-grid-hd-over");
34560 handleHdOut : function(e){
34561 var hd = this.findHeaderCell(e.getTarget());
34563 this.fly(hd).removeClass("x-grid-hd-over");
34567 handleSplitDblClick : function(e, t){
34568 var i = this.getCellIndex(t);
34569 if(this.grid.enableColumnResize !== false && this.cm.isResizable(i) && !this.cm.isFixed(i)){
34570 this.autoSizeColumn(i, true);
34575 render : function(){
34578 var colCount = cm.getColumnCount();
34580 if(this.grid.monitorWindowResize === true){
34581 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34583 var header = this.renderHeaders();
34584 var body = this.templates.body.apply({rows:""});
34585 var html = this.templates.master.apply({
34588 lockedHeader: header[0],
34592 //this.updateColumns();
34594 this.grid.getGridEl().dom.innerHTML = html;
34596 this.initElements();
34598 // a kludge to fix the random scolling effect in webkit
34599 this.el.on("scroll", function() {
34600 this.el.dom.scrollTop=0; // hopefully not recursive..
34603 this.scroller.on("scroll", this.handleScroll, this);
34604 this.lockedBody.on("mousewheel", this.handleWheel, this);
34605 this.mainBody.on("mousewheel", this.handleWheel, this);
34607 this.mainHd.on("mouseover", this.handleHdOver, this);
34608 this.mainHd.on("mouseout", this.handleHdOut, this);
34609 this.mainHd.on("dblclick", this.handleSplitDblClick, this,
34610 {delegate: "."+this.splitClass});
34612 this.lockedHd.on("mouseover", this.handleHdOver, this);
34613 this.lockedHd.on("mouseout", this.handleHdOut, this);
34614 this.lockedHd.on("dblclick", this.handleSplitDblClick, this,
34615 {delegate: "."+this.splitClass});
34617 if(this.grid.enableColumnResize !== false && Roo.grid.SplitDragZone){
34618 new Roo.grid.SplitDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34621 this.updateSplitters();
34623 if(this.grid.enableColumnMove && Roo.grid.HeaderDragZone){
34624 new Roo.grid.HeaderDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34625 new Roo.grid.HeaderDropZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34628 if(this.grid.enableCtxMenu !== false && Roo.menu.Menu){
34629 this.hmenu = new Roo.menu.Menu({id: this.grid.id + "-hctx"});
34631 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
34632 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
34634 if(this.grid.enableColLock !== false){
34635 this.hmenu.add('-',
34636 {id:"lock", text: this.lockText, cls: "xg-hmenu-lock"},
34637 {id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
34641 this.hmenu.add('-',
34642 {id:"wider", text: this.columnsWiderText},
34643 {id:"narrow", text: this.columnsNarrowText }
34649 if(this.grid.enableColumnHide !== false){
34651 this.colMenu = new Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
34652 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
34653 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
34655 this.hmenu.add('-',
34656 {id:"columns", text: this.columnsText, menu: this.colMenu}
34659 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
34661 this.grid.on("headercontextmenu", this.handleHdCtx, this);
34664 if((this.grid.enableDragDrop || this.grid.enableDrag) && Roo.grid.GridDragZone){
34665 this.dd = new Roo.grid.GridDragZone(this.grid, {
34666 ddGroup : this.grid.ddGroup || 'GridDD'
34672 for(var i = 0; i < colCount; i++){
34673 if(cm.isHidden(i)){
34674 this.hideColumn(i);
34676 if(cm.config[i].align){
34677 this.css.updateRule(this.colSelector + i, "textAlign", cm.config[i].align);
34678 this.css.updateRule(this.hdSelector + i, "textAlign", cm.config[i].align);
34682 this.updateHeaderSortState();
34684 this.beforeInitialResize();
34687 // two part rendering gives faster view to the user
34688 this.renderPhase2.defer(1, this);
34691 renderPhase2 : function(){
34692 // render the rows now
34694 if(this.grid.autoSizeColumns){
34695 this.autoSizeColumns();
34699 beforeInitialResize : function(){
34703 onColumnSplitterMoved : function(i, w){
34704 this.userResized = true;
34705 var cm = this.grid.colModel;
34706 cm.setColumnWidth(i, w, true);
34707 var cid = cm.getColumnId(i);
34708 this.css.updateRule(this.colSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
34709 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
34710 this.updateSplitters();
34712 this.grid.fireEvent("columnresize", i, w);
34715 syncRowHeights : function(startIndex, endIndex){
34716 if(this.grid.enableRowHeightSync === true && this.cm.getLockedCount() > 0){
34717 startIndex = startIndex || 0;
34718 var mrows = this.getBodyTable().rows;
34719 var lrows = this.getLockedTable().rows;
34720 var len = mrows.length-1;
34721 endIndex = Math.min(endIndex || len, len);
34722 for(var i = startIndex; i <= endIndex; i++){
34723 var m = mrows[i], l = lrows[i];
34724 var h = Math.max(m.offsetHeight, l.offsetHeight);
34725 m.style.height = l.style.height = h + "px";
34730 layout : function(initialRender, is2ndPass){
34732 var auto = g.autoHeight;
34733 var scrollOffset = 16;
34734 var c = g.getGridEl(), cm = this.cm,
34735 expandCol = g.autoExpandColumn,
34737 //c.beginMeasure();
34739 if(!c.dom.offsetWidth){ // display:none?
34741 this.lockedWrap.show();
34742 this.mainWrap.show();
34747 var hasLock = this.cm.isLocked(0);
34749 var tbh = this.headerPanel.getHeight();
34750 var bbh = this.footerPanel.getHeight();
34753 var ch = this.getBodyTable().offsetHeight + tbh + bbh + this.mainHd.getHeight();
34754 var newHeight = ch + c.getBorderWidth("tb");
34756 newHeight = Math.min(g.maxHeight, newHeight);
34758 c.setHeight(newHeight);
34762 c.setWidth(cm.getTotalWidth()+c.getBorderWidth('lr'));
34765 var s = this.scroller;
34767 var csize = c.getSize(true);
34769 this.el.setSize(csize.width, csize.height);
34771 this.headerPanel.setWidth(csize.width);
34772 this.footerPanel.setWidth(csize.width);
34774 var hdHeight = this.mainHd.getHeight();
34775 var vw = csize.width;
34776 var vh = csize.height - (tbh + bbh);
34780 var bt = this.getBodyTable();
34782 if(cm.getLockedCount() == cm.config.length){
34783 bt = this.getLockedTable();
34786 var ltWidth = hasLock ?
34787 Math.max(this.getLockedTable().offsetWidth, this.lockedHd.dom.firstChild.offsetWidth) : 0;
34789 var scrollHeight = bt.offsetHeight;
34790 var scrollWidth = ltWidth + bt.offsetWidth;
34791 var vscroll = false, hscroll = false;
34793 this.scrollSizer.setSize(scrollWidth, scrollHeight+hdHeight);
34795 var lw = this.lockedWrap, mw = this.mainWrap;
34796 var lb = this.lockedBody, mb = this.mainBody;
34798 setTimeout(function(){
34799 var t = s.dom.offsetTop;
34800 var w = s.dom.clientWidth,
34801 h = s.dom.clientHeight;
34804 lw.setSize(ltWidth, h);
34806 mw.setLeftTop(ltWidth, t);
34807 mw.setSize(w-ltWidth, h);
34809 lb.setHeight(h-hdHeight);
34810 mb.setHeight(h-hdHeight);
34812 if(is2ndPass !== true && !gv.userResized && expandCol){
34813 // high speed resize without full column calculation
34815 var ci = cm.getIndexById(expandCol);
34817 ci = cm.findColumnIndex(expandCol);
34819 ci = Math.max(0, ci); // make sure it's got at least the first col.
34820 var expandId = cm.getColumnId(ci);
34821 var tw = cm.getTotalWidth(false);
34822 var currentWidth = cm.getColumnWidth(ci);
34823 var cw = Math.min(Math.max(((w-tw)+currentWidth-2)-/*scrollbar*/(w <= s.dom.offsetWidth ? 0 : 18), g.autoExpandMin), g.autoExpandMax);
34824 if(currentWidth != cw){
34825 cm.setColumnWidth(ci, cw, true);
34826 gv.css.updateRule(gv.colSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
34827 gv.css.updateRule(gv.hdSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
34828 gv.updateSplitters();
34829 gv.layout(false, true);
34841 onWindowResize : function(){
34842 if(!this.grid.monitorWindowResize || this.grid.autoHeight){
34848 appendFooter : function(parentEl){
34852 sortAscText : "Sort Ascending",
34853 sortDescText : "Sort Descending",
34854 lockText : "Lock Column",
34855 unlockText : "Unlock Column",
34856 columnsText : "Columns",
34858 columnsWiderText : "Wider",
34859 columnsNarrowText : "Thinner"
34863 Roo.grid.GridView.ColumnDragZone = function(grid, hd){
34864 Roo.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
34865 this.proxy.el.addClass('x-grid3-col-dd');
34868 Roo.extend(Roo.grid.GridView.ColumnDragZone, Roo.grid.HeaderDragZone, {
34869 handleMouseDown : function(e){
34873 callHandleMouseDown : function(e){
34874 Roo.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
34879 * Ext JS Library 1.1.1
34880 * Copyright(c) 2006-2007, Ext JS, LLC.
34882 * Originally Released Under LGPL - original licence link has changed is not relivant.
34885 * <script type="text/javascript">
34889 // This is a support class used internally by the Grid components
34890 Roo.grid.SplitDragZone = function(grid, hd, hd2){
34892 this.view = grid.getView();
34893 this.proxy = this.view.resizeProxy;
34894 Roo.grid.SplitDragZone.superclass.constructor.call(this, hd,
34895 "gridSplitters" + this.grid.getGridEl().id, {
34896 dragElId : Roo.id(this.proxy.dom), resizeFrame:false
34898 this.setHandleElId(Roo.id(hd));
34899 this.setOuterHandleElId(Roo.id(hd2));
34900 this.scroll = false;
34902 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
34903 fly: Roo.Element.fly,
34905 b4StartDrag : function(x, y){
34906 this.view.headersDisabled = true;
34907 this.proxy.setHeight(this.view.mainWrap.getHeight());
34908 var w = this.cm.getColumnWidth(this.cellIndex);
34909 var minw = Math.max(w-this.grid.minColumnWidth, 0);
34910 this.resetConstraints();
34911 this.setXConstraint(minw, 1000);
34912 this.setYConstraint(0, 0);
34913 this.minX = x - minw;
34914 this.maxX = x + 1000;
34916 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
34920 handleMouseDown : function(e){
34921 ev = Roo.EventObject.setEvent(e);
34922 var t = this.fly(ev.getTarget());
34923 if(t.hasClass("x-grid-split")){
34924 this.cellIndex = this.view.getCellIndex(t.dom);
34925 this.split = t.dom;
34926 this.cm = this.grid.colModel;
34927 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
34928 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
34933 endDrag : function(e){
34934 this.view.headersDisabled = false;
34935 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
34936 var diff = endX - this.startPos;
34937 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
34940 autoOffset : function(){
34941 this.setDelta(0,0);
34945 * Ext JS Library 1.1.1
34946 * Copyright(c) 2006-2007, Ext JS, LLC.
34948 * Originally Released Under LGPL - original licence link has changed is not relivant.
34951 * <script type="text/javascript">
34955 // This is a support class used internally by the Grid components
34956 Roo.grid.GridDragZone = function(grid, config){
34957 this.view = grid.getView();
34958 Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
34959 if(this.view.lockedBody){
34960 this.setHandleElId(Roo.id(this.view.mainBody.dom));
34961 this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
34963 this.scroll = false;
34965 this.ddel = document.createElement('div');
34966 this.ddel.className = 'x-grid-dd-wrap';
34969 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
34970 ddGroup : "GridDD",
34972 getDragData : function(e){
34973 var t = Roo.lib.Event.getTarget(e);
34974 var rowIndex = this.view.findRowIndex(t);
34975 var sm = this.grid.selModel;
34977 //Roo.log(rowIndex);
34979 if (sm.getSelectedCell) {
34980 // cell selection..
34981 if (!sm.getSelectedCell()) {
34984 if (rowIndex != sm.getSelectedCell()[0]) {
34990 if(rowIndex !== false){
34995 //Roo.log([ sm.getSelectedCell() ? sm.getSelectedCell()[0] : 'NO' , rowIndex ]);
34997 //if(!sm.isSelected(rowIndex) || e.hasModifier()){
35000 if (e.hasModifier()){
35001 sm.handleMouseDown(e, t); // non modifier buttons are handled by row select.
35004 Roo.log("getDragData");
35009 rowIndex: rowIndex,
35010 selections:sm.getSelections ? sm.getSelections() : (
35011 sm.getSelectedCell() ? [ this.grid.ds.getAt(sm.getSelectedCell()[0]) ] : []
35018 onInitDrag : function(e){
35019 var data = this.dragData;
35020 this.ddel.innerHTML = this.grid.getDragDropText();
35021 this.proxy.update(this.ddel);
35022 // fire start drag?
35025 afterRepair : function(){
35026 this.dragging = false;
35029 getRepairXY : function(e, data){
35033 onEndDrag : function(data, e){
35037 onValidDrop : function(dd, e, id){
35042 beforeInvalidDrop : function(e, id){
35047 * Ext JS Library 1.1.1
35048 * Copyright(c) 2006-2007, Ext JS, LLC.
35050 * Originally Released Under LGPL - original licence link has changed is not relivant.
35053 * <script type="text/javascript">
35058 * @class Roo.grid.ColumnModel
35059 * @extends Roo.util.Observable
35060 * This is the default implementation of a ColumnModel used by the Grid. It defines
35061 * the columns in the grid.
35064 var colModel = new Roo.grid.ColumnModel([
35065 {header: "Ticker", width: 60, sortable: true, locked: true},
35066 {header: "Company Name", width: 150, sortable: true},
35067 {header: "Market Cap.", width: 100, sortable: true},
35068 {header: "$ Sales", width: 100, sortable: true, renderer: money},
35069 {header: "Employees", width: 100, sortable: true, resizable: false}
35074 * The config options listed for this class are options which may appear in each
35075 * individual column definition.
35076 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
35078 * @param {Object} config An Array of column config objects. See this class's
35079 * config objects for details.
35081 Roo.grid.ColumnModel = function(config){
35083 * The config passed into the constructor
35085 this.config = config;
35088 // if no id, create one
35089 // if the column does not have a dataIndex mapping,
35090 // map it to the order it is in the config
35091 for(var i = 0, len = config.length; i < len; i++){
35093 if(typeof c.dataIndex == "undefined"){
35096 if(typeof c.renderer == "string"){
35097 c.renderer = Roo.util.Format[c.renderer];
35099 if(typeof c.id == "undefined"){
35102 if(c.editor && c.editor.xtype){
35103 c.editor = Roo.factory(c.editor, Roo.grid);
35105 if(c.editor && c.editor.isFormField){
35106 c.editor = new Roo.grid.GridEditor(c.editor);
35108 this.lookup[c.id] = c;
35112 * The width of columns which have no width specified (defaults to 100)
35115 this.defaultWidth = 100;
35118 * Default sortable of columns which have no sortable specified (defaults to false)
35121 this.defaultSortable = false;
35125 * @event widthchange
35126 * Fires when the width of a column changes.
35127 * @param {ColumnModel} this
35128 * @param {Number} columnIndex The column index
35129 * @param {Number} newWidth The new width
35131 "widthchange": true,
35133 * @event headerchange
35134 * Fires when the text of a header changes.
35135 * @param {ColumnModel} this
35136 * @param {Number} columnIndex The column index
35137 * @param {Number} newText The new header text
35139 "headerchange": true,
35141 * @event hiddenchange
35142 * Fires when a column is hidden or "unhidden".
35143 * @param {ColumnModel} this
35144 * @param {Number} columnIndex The column index
35145 * @param {Boolean} hidden true if hidden, false otherwise
35147 "hiddenchange": true,
35149 * @event columnmoved
35150 * Fires when a column is moved.
35151 * @param {ColumnModel} this
35152 * @param {Number} oldIndex
35153 * @param {Number} newIndex
35155 "columnmoved" : true,
35157 * @event columlockchange
35158 * Fires when a column's locked state is changed
35159 * @param {ColumnModel} this
35160 * @param {Number} colIndex
35161 * @param {Boolean} locked true if locked
35163 "columnlockchange" : true
35165 Roo.grid.ColumnModel.superclass.constructor.call(this);
35167 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
35169 * @cfg {String} header The header text to display in the Grid view.
35172 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
35173 * {@link Roo.data.Record} definition from which to draw the column's value. If not
35174 * specified, the column's index is used as an index into the Record's data Array.
35177 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
35178 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
35181 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
35182 * Defaults to the value of the {@link #defaultSortable} property.
35183 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
35186 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
35189 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
35192 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
35195 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
35198 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
35199 * given the cell's data value. See {@link #setRenderer}. If not specified, the
35200 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
35201 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
35204 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
35207 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
35210 * @cfg {String} valign (Optional) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined.
35213 * @cfg {String} cursor (Optional)
35216 * @cfg {String} tooltip (Optional)
35219 * @cfg {Number} xs (Optional)
35222 * @cfg {Number} sm (Optional)
35225 * @cfg {Number} md (Optional)
35228 * @cfg {Number} lg (Optional)
35231 * Returns the id of the column at the specified index.
35232 * @param {Number} index The column index
35233 * @return {String} the id
35235 getColumnId : function(index){
35236 return this.config[index].id;
35240 * Returns the column for a specified id.
35241 * @param {String} id The column id
35242 * @return {Object} the column
35244 getColumnById : function(id){
35245 return this.lookup[id];
35250 * Returns the column for a specified dataIndex.
35251 * @param {String} dataIndex The column dataIndex
35252 * @return {Object|Boolean} the column or false if not found
35254 getColumnByDataIndex: function(dataIndex){
35255 var index = this.findColumnIndex(dataIndex);
35256 return index > -1 ? this.config[index] : false;
35260 * Returns the index for a specified column id.
35261 * @param {String} id The column id
35262 * @return {Number} the index, or -1 if not found
35264 getIndexById : function(id){
35265 for(var i = 0, len = this.config.length; i < len; i++){
35266 if(this.config[i].id == id){
35274 * Returns the index for a specified column dataIndex.
35275 * @param {String} dataIndex The column dataIndex
35276 * @return {Number} the index, or -1 if not found
35279 findColumnIndex : function(dataIndex){
35280 for(var i = 0, len = this.config.length; i < len; i++){
35281 if(this.config[i].dataIndex == dataIndex){
35289 moveColumn : function(oldIndex, newIndex){
35290 var c = this.config[oldIndex];
35291 this.config.splice(oldIndex, 1);
35292 this.config.splice(newIndex, 0, c);
35293 this.dataMap = null;
35294 this.fireEvent("columnmoved", this, oldIndex, newIndex);
35297 isLocked : function(colIndex){
35298 return this.config[colIndex].locked === true;
35301 setLocked : function(colIndex, value, suppressEvent){
35302 if(this.isLocked(colIndex) == value){
35305 this.config[colIndex].locked = value;
35306 if(!suppressEvent){
35307 this.fireEvent("columnlockchange", this, colIndex, value);
35311 getTotalLockedWidth : function(){
35312 var totalWidth = 0;
35313 for(var i = 0; i < this.config.length; i++){
35314 if(this.isLocked(i) && !this.isHidden(i)){
35315 this.totalWidth += this.getColumnWidth(i);
35321 getLockedCount : function(){
35322 for(var i = 0, len = this.config.length; i < len; i++){
35323 if(!this.isLocked(i)){
35328 return this.config.length;
35332 * Returns the number of columns.
35335 getColumnCount : function(visibleOnly){
35336 if(visibleOnly === true){
35338 for(var i = 0, len = this.config.length; i < len; i++){
35339 if(!this.isHidden(i)){
35345 return this.config.length;
35349 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
35350 * @param {Function} fn
35351 * @param {Object} scope (optional)
35352 * @return {Array} result
35354 getColumnsBy : function(fn, scope){
35356 for(var i = 0, len = this.config.length; i < len; i++){
35357 var c = this.config[i];
35358 if(fn.call(scope||this, c, i) === true){
35366 * Returns true if the specified column is sortable.
35367 * @param {Number} col The column index
35368 * @return {Boolean}
35370 isSortable : function(col){
35371 if(typeof this.config[col].sortable == "undefined"){
35372 return this.defaultSortable;
35374 return this.config[col].sortable;
35378 * Returns the rendering (formatting) function defined for the column.
35379 * @param {Number} col The column index.
35380 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
35382 getRenderer : function(col){
35383 if(!this.config[col].renderer){
35384 return Roo.grid.ColumnModel.defaultRenderer;
35386 return this.config[col].renderer;
35390 * Sets the rendering (formatting) function for a column.
35391 * @param {Number} col The column index
35392 * @param {Function} fn The function to use to process the cell's raw data
35393 * to return HTML markup for the grid view. The render function is called with
35394 * the following parameters:<ul>
35395 * <li>Data value.</li>
35396 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
35397 * <li>css A CSS style string to apply to the table cell.</li>
35398 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
35399 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
35400 * <li>Row index</li>
35401 * <li>Column index</li>
35402 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
35404 setRenderer : function(col, fn){
35405 this.config[col].renderer = fn;
35409 * Returns the width for the specified column.
35410 * @param {Number} col The column index
35413 getColumnWidth : function(col){
35414 return this.config[col].width * 1 || this.defaultWidth;
35418 * Sets the width for a column.
35419 * @param {Number} col The column index
35420 * @param {Number} width The new width
35422 setColumnWidth : function(col, width, suppressEvent){
35423 this.config[col].width = width;
35424 this.totalWidth = null;
35425 if(!suppressEvent){
35426 this.fireEvent("widthchange", this, col, width);
35431 * Returns the total width of all columns.
35432 * @param {Boolean} includeHidden True to include hidden column widths
35435 getTotalWidth : function(includeHidden){
35436 if(!this.totalWidth){
35437 this.totalWidth = 0;
35438 for(var i = 0, len = this.config.length; i < len; i++){
35439 if(includeHidden || !this.isHidden(i)){
35440 this.totalWidth += this.getColumnWidth(i);
35444 return this.totalWidth;
35448 * Returns the header for the specified column.
35449 * @param {Number} col The column index
35452 getColumnHeader : function(col){
35453 return this.config[col].header;
35457 * Sets the header for a column.
35458 * @param {Number} col The column index
35459 * @param {String} header The new header
35461 setColumnHeader : function(col, header){
35462 this.config[col].header = header;
35463 this.fireEvent("headerchange", this, col, header);
35467 * Returns the tooltip for the specified column.
35468 * @param {Number} col The column index
35471 getColumnTooltip : function(col){
35472 return this.config[col].tooltip;
35475 * Sets the tooltip for a column.
35476 * @param {Number} col The column index
35477 * @param {String} tooltip The new tooltip
35479 setColumnTooltip : function(col, tooltip){
35480 this.config[col].tooltip = tooltip;
35484 * Returns the dataIndex for the specified column.
35485 * @param {Number} col The column index
35488 getDataIndex : function(col){
35489 return this.config[col].dataIndex;
35493 * Sets the dataIndex for a column.
35494 * @param {Number} col The column index
35495 * @param {Number} dataIndex The new dataIndex
35497 setDataIndex : function(col, dataIndex){
35498 this.config[col].dataIndex = dataIndex;
35504 * Returns true if the cell is editable.
35505 * @param {Number} colIndex The column index
35506 * @param {Number} rowIndex The row index - this is nto actually used..?
35507 * @return {Boolean}
35509 isCellEditable : function(colIndex, rowIndex){
35510 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
35514 * Returns the editor defined for the cell/column.
35515 * return false or null to disable editing.
35516 * @param {Number} colIndex The column index
35517 * @param {Number} rowIndex The row index
35520 getCellEditor : function(colIndex, rowIndex){
35521 return this.config[colIndex].editor;
35525 * Sets if a column is editable.
35526 * @param {Number} col The column index
35527 * @param {Boolean} editable True if the column is editable
35529 setEditable : function(col, editable){
35530 this.config[col].editable = editable;
35535 * Returns true if the column is hidden.
35536 * @param {Number} colIndex The column index
35537 * @return {Boolean}
35539 isHidden : function(colIndex){
35540 return this.config[colIndex].hidden;
35545 * Returns true if the column width cannot be changed
35547 isFixed : function(colIndex){
35548 return this.config[colIndex].fixed;
35552 * Returns true if the column can be resized
35553 * @return {Boolean}
35555 isResizable : function(colIndex){
35556 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
35559 * Sets if a column is hidden.
35560 * @param {Number} colIndex The column index
35561 * @param {Boolean} hidden True if the column is hidden
35563 setHidden : function(colIndex, hidden){
35564 this.config[colIndex].hidden = hidden;
35565 this.totalWidth = null;
35566 this.fireEvent("hiddenchange", this, colIndex, hidden);
35570 * Sets the editor for a column.
35571 * @param {Number} col The column index
35572 * @param {Object} editor The editor object
35574 setEditor : function(col, editor){
35575 this.config[col].editor = editor;
35579 Roo.grid.ColumnModel.defaultRenderer = function(value)
35581 if(typeof value == "object") {
35584 if(typeof value == "string" && value.length < 1){
35588 return String.format("{0}", value);
35591 // Alias for backwards compatibility
35592 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
35595 * Ext JS Library 1.1.1
35596 * Copyright(c) 2006-2007, Ext JS, LLC.
35598 * Originally Released Under LGPL - original licence link has changed is not relivant.
35601 * <script type="text/javascript">
35605 * @class Roo.grid.AbstractSelectionModel
35606 * @extends Roo.util.Observable
35607 * Abstract base class for grid SelectionModels. It provides the interface that should be
35608 * implemented by descendant classes. This class should not be directly instantiated.
35611 Roo.grid.AbstractSelectionModel = function(){
35612 this.locked = false;
35613 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
35616 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
35617 /** @ignore Called by the grid automatically. Do not call directly. */
35618 init : function(grid){
35624 * Locks the selections.
35627 this.locked = true;
35631 * Unlocks the selections.
35633 unlock : function(){
35634 this.locked = false;
35638 * Returns true if the selections are locked.
35639 * @return {Boolean}
35641 isLocked : function(){
35642 return this.locked;
35646 * Ext JS Library 1.1.1
35647 * Copyright(c) 2006-2007, Ext JS, LLC.
35649 * Originally Released Under LGPL - original licence link has changed is not relivant.
35652 * <script type="text/javascript">
35655 * @extends Roo.grid.AbstractSelectionModel
35656 * @class Roo.grid.RowSelectionModel
35657 * The default SelectionModel used by {@link Roo.grid.Grid}.
35658 * It supports multiple selections and keyboard selection/navigation.
35660 * @param {Object} config
35662 Roo.grid.RowSelectionModel = function(config){
35663 Roo.apply(this, config);
35664 this.selections = new Roo.util.MixedCollection(false, function(o){
35669 this.lastActive = false;
35673 * @event selectionchange
35674 * Fires when the selection changes
35675 * @param {SelectionModel} this
35677 "selectionchange" : true,
35679 * @event afterselectionchange
35680 * Fires after the selection changes (eg. by key press or clicking)
35681 * @param {SelectionModel} this
35683 "afterselectionchange" : true,
35685 * @event beforerowselect
35686 * Fires when a row is selected being selected, return false to cancel.
35687 * @param {SelectionModel} this
35688 * @param {Number} rowIndex The selected index
35689 * @param {Boolean} keepExisting False if other selections will be cleared
35691 "beforerowselect" : true,
35694 * Fires when a row is selected.
35695 * @param {SelectionModel} this
35696 * @param {Number} rowIndex The selected index
35697 * @param {Roo.data.Record} r The record
35699 "rowselect" : true,
35701 * @event rowdeselect
35702 * Fires when a row is deselected.
35703 * @param {SelectionModel} this
35704 * @param {Number} rowIndex The selected index
35706 "rowdeselect" : true
35708 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
35709 this.locked = false;
35712 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
35714 * @cfg {Boolean} singleSelect
35715 * True to allow selection of only one row at a time (defaults to false)
35717 singleSelect : false,
35720 initEvents : function(){
35722 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
35723 this.grid.on("mousedown", this.handleMouseDown, this);
35724 }else{ // allow click to work like normal
35725 this.grid.on("rowclick", this.handleDragableRowClick, this);
35728 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
35729 "up" : function(e){
35731 this.selectPrevious(e.shiftKey);
35732 }else if(this.last !== false && this.lastActive !== false){
35733 var last = this.last;
35734 this.selectRange(this.last, this.lastActive-1);
35735 this.grid.getView().focusRow(this.lastActive);
35736 if(last !== false){
35740 this.selectFirstRow();
35742 this.fireEvent("afterselectionchange", this);
35744 "down" : function(e){
35746 this.selectNext(e.shiftKey);
35747 }else if(this.last !== false && this.lastActive !== false){
35748 var last = this.last;
35749 this.selectRange(this.last, this.lastActive+1);
35750 this.grid.getView().focusRow(this.lastActive);
35751 if(last !== false){
35755 this.selectFirstRow();
35757 this.fireEvent("afterselectionchange", this);
35762 var view = this.grid.view;
35763 view.on("refresh", this.onRefresh, this);
35764 view.on("rowupdated", this.onRowUpdated, this);
35765 view.on("rowremoved", this.onRemove, this);
35769 onRefresh : function(){
35770 var ds = this.grid.dataSource, i, v = this.grid.view;
35771 var s = this.selections;
35772 s.each(function(r){
35773 if((i = ds.indexOfId(r.id)) != -1){
35775 s.add(ds.getAt(i)); // updating the selection relate data
35783 onRemove : function(v, index, r){
35784 this.selections.remove(r);
35788 onRowUpdated : function(v, index, r){
35789 if(this.isSelected(r)){
35790 v.onRowSelect(index);
35796 * @param {Array} records The records to select
35797 * @param {Boolean} keepExisting (optional) True to keep existing selections
35799 selectRecords : function(records, keepExisting){
35801 this.clearSelections();
35803 var ds = this.grid.dataSource;
35804 for(var i = 0, len = records.length; i < len; i++){
35805 this.selectRow(ds.indexOf(records[i]), true);
35810 * Gets the number of selected rows.
35813 getCount : function(){
35814 return this.selections.length;
35818 * Selects the first row in the grid.
35820 selectFirstRow : function(){
35825 * Select the last row.
35826 * @param {Boolean} keepExisting (optional) True to keep existing selections
35828 selectLastRow : function(keepExisting){
35829 this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
35833 * Selects the row immediately following the last selected row.
35834 * @param {Boolean} keepExisting (optional) True to keep existing selections
35836 selectNext : function(keepExisting){
35837 if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
35838 this.selectRow(this.last+1, keepExisting);
35839 this.grid.getView().focusRow(this.last);
35844 * Selects the row that precedes the last selected row.
35845 * @param {Boolean} keepExisting (optional) True to keep existing selections
35847 selectPrevious : function(keepExisting){
35849 this.selectRow(this.last-1, keepExisting);
35850 this.grid.getView().focusRow(this.last);
35855 * Returns the selected records
35856 * @return {Array} Array of selected records
35858 getSelections : function(){
35859 return [].concat(this.selections.items);
35863 * Returns the first selected record.
35866 getSelected : function(){
35867 return this.selections.itemAt(0);
35872 * Clears all selections.
35874 clearSelections : function(fast){
35879 var ds = this.grid.dataSource;
35880 var s = this.selections;
35881 s.each(function(r){
35882 this.deselectRow(ds.indexOfId(r.id));
35886 this.selections.clear();
35893 * Selects all rows.
35895 selectAll : function(){
35899 this.selections.clear();
35900 for(var i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
35901 this.selectRow(i, true);
35906 * Returns True if there is a selection.
35907 * @return {Boolean}
35909 hasSelection : function(){
35910 return this.selections.length > 0;
35914 * Returns True if the specified row is selected.
35915 * @param {Number/Record} record The record or index of the record to check
35916 * @return {Boolean}
35918 isSelected : function(index){
35919 var r = typeof index == "number" ? this.grid.dataSource.getAt(index) : index;
35920 return (r && this.selections.key(r.id) ? true : false);
35924 * Returns True if the specified record id is selected.
35925 * @param {String} id The id of record to check
35926 * @return {Boolean}
35928 isIdSelected : function(id){
35929 return (this.selections.key(id) ? true : false);
35933 handleMouseDown : function(e, t){
35934 var view = this.grid.getView(), rowIndex;
35935 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
35938 if(e.shiftKey && this.last !== false){
35939 var last = this.last;
35940 this.selectRange(last, rowIndex, e.ctrlKey);
35941 this.last = last; // reset the last
35942 view.focusRow(rowIndex);
35944 var isSelected = this.isSelected(rowIndex);
35945 if(e.button !== 0 && isSelected){
35946 view.focusRow(rowIndex);
35947 }else if(e.ctrlKey && isSelected){
35948 this.deselectRow(rowIndex);
35949 }else if(!isSelected){
35950 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
35951 view.focusRow(rowIndex);
35954 this.fireEvent("afterselectionchange", this);
35957 handleDragableRowClick : function(grid, rowIndex, e)
35959 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
35960 this.selectRow(rowIndex, false);
35961 grid.view.focusRow(rowIndex);
35962 this.fireEvent("afterselectionchange", this);
35967 * Selects multiple rows.
35968 * @param {Array} rows Array of the indexes of the row to select
35969 * @param {Boolean} keepExisting (optional) True to keep existing selections
35971 selectRows : function(rows, keepExisting){
35973 this.clearSelections();
35975 for(var i = 0, len = rows.length; i < len; i++){
35976 this.selectRow(rows[i], true);
35981 * Selects a range of rows. All rows in between startRow and endRow are also selected.
35982 * @param {Number} startRow The index of the first row in the range
35983 * @param {Number} endRow The index of the last row in the range
35984 * @param {Boolean} keepExisting (optional) True to retain existing selections
35986 selectRange : function(startRow, endRow, keepExisting){
35991 this.clearSelections();
35993 if(startRow <= endRow){
35994 for(var i = startRow; i <= endRow; i++){
35995 this.selectRow(i, true);
35998 for(var i = startRow; i >= endRow; i--){
35999 this.selectRow(i, true);
36005 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
36006 * @param {Number} startRow The index of the first row in the range
36007 * @param {Number} endRow The index of the last row in the range
36009 deselectRange : function(startRow, endRow, preventViewNotify){
36013 for(var i = startRow; i <= endRow; i++){
36014 this.deselectRow(i, preventViewNotify);
36020 * @param {Number} row The index of the row to select
36021 * @param {Boolean} keepExisting (optional) True to keep existing selections
36023 selectRow : function(index, keepExisting, preventViewNotify){
36024 if(this.locked || (index < 0 || index >= this.grid.dataSource.getCount())) {
36027 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
36028 if(!keepExisting || this.singleSelect){
36029 this.clearSelections();
36031 var r = this.grid.dataSource.getAt(index);
36032 this.selections.add(r);
36033 this.last = this.lastActive = index;
36034 if(!preventViewNotify){
36035 this.grid.getView().onRowSelect(index);
36037 this.fireEvent("rowselect", this, index, r);
36038 this.fireEvent("selectionchange", this);
36044 * @param {Number} row The index of the row to deselect
36046 deselectRow : function(index, preventViewNotify){
36050 if(this.last == index){
36053 if(this.lastActive == index){
36054 this.lastActive = false;
36056 var r = this.grid.dataSource.getAt(index);
36057 this.selections.remove(r);
36058 if(!preventViewNotify){
36059 this.grid.getView().onRowDeselect(index);
36061 this.fireEvent("rowdeselect", this, index);
36062 this.fireEvent("selectionchange", this);
36066 restoreLast : function(){
36068 this.last = this._last;
36073 acceptsNav : function(row, col, cm){
36074 return !cm.isHidden(col) && cm.isCellEditable(col, row);
36078 onEditorKey : function(field, e){
36079 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
36084 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
36086 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36088 }else if(k == e.ENTER && !e.ctrlKey){
36092 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
36094 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
36096 }else if(k == e.ESC){
36100 g.startEditing(newCell[0], newCell[1]);
36105 * Ext JS Library 1.1.1
36106 * Copyright(c) 2006-2007, Ext JS, LLC.
36108 * Originally Released Under LGPL - original licence link has changed is not relivant.
36111 * <script type="text/javascript">
36114 * @class Roo.grid.CellSelectionModel
36115 * @extends Roo.grid.AbstractSelectionModel
36116 * This class provides the basic implementation for cell selection in a grid.
36118 * @param {Object} config The object containing the configuration of this model.
36119 * @cfg {Boolean} enter_is_tab Enter behaves the same as tab. (eg. goes to next cell) default: false
36121 Roo.grid.CellSelectionModel = function(config){
36122 Roo.apply(this, config);
36124 this.selection = null;
36128 * @event beforerowselect
36129 * Fires before a cell is selected.
36130 * @param {SelectionModel} this
36131 * @param {Number} rowIndex The selected row index
36132 * @param {Number} colIndex The selected cell index
36134 "beforecellselect" : true,
36136 * @event cellselect
36137 * Fires when a cell is selected.
36138 * @param {SelectionModel} this
36139 * @param {Number} rowIndex The selected row index
36140 * @param {Number} colIndex The selected cell index
36142 "cellselect" : true,
36144 * @event selectionchange
36145 * Fires when the active selection changes.
36146 * @param {SelectionModel} this
36147 * @param {Object} selection null for no selection or an object (o) with two properties
36149 <li>o.record: the record object for the row the selection is in</li>
36150 <li>o.cell: An array of [rowIndex, columnIndex]</li>
36153 "selectionchange" : true,
36156 * Fires when the tab (or enter) was pressed on the last editable cell
36157 * You can use this to trigger add new row.
36158 * @param {SelectionModel} this
36162 * @event beforeeditnext
36163 * Fires before the next editable sell is made active
36164 * You can use this to skip to another cell or fire the tabend
36165 * if you set cell to false
36166 * @param {Object} eventdata object : { cell : [ row, col ] }
36168 "beforeeditnext" : true
36170 Roo.grid.CellSelectionModel.superclass.constructor.call(this);
36173 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel, {
36175 enter_is_tab: false,
36178 initEvents : function(){
36179 this.grid.on("mousedown", this.handleMouseDown, this);
36180 this.grid.getGridEl().on(Roo.isIE ? "keydown" : "keypress", this.handleKeyDown, this);
36181 var view = this.grid.view;
36182 view.on("refresh", this.onViewChange, this);
36183 view.on("rowupdated", this.onRowUpdated, this);
36184 view.on("beforerowremoved", this.clearSelections, this);
36185 view.on("beforerowsinserted", this.clearSelections, this);
36186 if(this.grid.isEditor){
36187 this.grid.on("beforeedit", this.beforeEdit, this);
36192 beforeEdit : function(e){
36193 this.select(e.row, e.column, false, true, e.record);
36197 onRowUpdated : function(v, index, r){
36198 if(this.selection && this.selection.record == r){
36199 v.onCellSelect(index, this.selection.cell[1]);
36204 onViewChange : function(){
36205 this.clearSelections(true);
36209 * Returns the currently selected cell,.
36210 * @return {Array} The selected cell (row, column) or null if none selected.
36212 getSelectedCell : function(){
36213 return this.selection ? this.selection.cell : null;
36217 * Clears all selections.
36218 * @param {Boolean} true to prevent the gridview from being notified about the change.
36220 clearSelections : function(preventNotify){
36221 var s = this.selection;
36223 if(preventNotify !== true){
36224 this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
36226 this.selection = null;
36227 this.fireEvent("selectionchange", this, null);
36232 * Returns true if there is a selection.
36233 * @return {Boolean}
36235 hasSelection : function(){
36236 return this.selection ? true : false;
36240 handleMouseDown : function(e, t){
36241 var v = this.grid.getView();
36242 if(this.isLocked()){
36245 var row = v.findRowIndex(t);
36246 var cell = v.findCellIndex(t);
36247 if(row !== false && cell !== false){
36248 this.select(row, cell);
36254 * @param {Number} rowIndex
36255 * @param {Number} collIndex
36257 select : function(rowIndex, colIndex, preventViewNotify, preventFocus, /*internal*/ r){
36258 if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
36259 this.clearSelections();
36260 r = r || this.grid.dataSource.getAt(rowIndex);
36263 cell : [rowIndex, colIndex]
36265 if(!preventViewNotify){
36266 var v = this.grid.getView();
36267 v.onCellSelect(rowIndex, colIndex);
36268 if(preventFocus !== true){
36269 v.focusCell(rowIndex, colIndex);
36272 this.fireEvent("cellselect", this, rowIndex, colIndex);
36273 this.fireEvent("selectionchange", this, this.selection);
36278 isSelectable : function(rowIndex, colIndex, cm){
36279 return !cm.isHidden(colIndex);
36283 handleKeyDown : function(e){
36284 //Roo.log('Cell Sel Model handleKeyDown');
36285 if(!e.isNavKeyPress()){
36288 var g = this.grid, s = this.selection;
36291 var cell = g.walkCells(0, 0, 1, this.isSelectable, this);
36293 this.select(cell[0], cell[1]);
36298 var walk = function(row, col, step){
36299 return g.walkCells(row, col, step, sm.isSelectable, sm);
36301 var k = e.getKey(), r = s.cell[0], c = s.cell[1];
36308 // handled by onEditorKey
36309 if (g.isEditor && g.editing) {
36313 newCell = walk(r, c-1, -1);
36315 newCell = walk(r, c+1, 1);
36320 newCell = walk(r+1, c, 1);
36324 newCell = walk(r-1, c, -1);
36328 newCell = walk(r, c+1, 1);
36332 newCell = walk(r, c-1, -1);
36337 if(g.isEditor && !g.editing){
36338 g.startEditing(r, c);
36347 this.select(newCell[0], newCell[1]);
36353 acceptsNav : function(row, col, cm){
36354 return !cm.isHidden(col) && cm.isCellEditable(col, row);
36358 * @param {Number} field (not used) - as it's normally used as a listener
36359 * @param {Number} e - event - fake it by using
36361 * var e = Roo.EventObjectImpl.prototype;
36362 * e.keyCode = e.TAB
36366 onEditorKey : function(field, e){
36368 var k = e.getKey(),
36371 ed = g.activeEditor,
36373 ///Roo.log('onEditorKey' + k);
36376 if (this.enter_is_tab && k == e.ENTER) {
36382 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
36384 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36390 } else if(k == e.ENTER && !e.ctrlKey){
36393 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36395 } else if(k == e.ESC){
36400 var ecall = { cell : newCell, forward : forward };
36401 this.fireEvent('beforeeditnext', ecall );
36402 newCell = ecall.cell;
36403 forward = ecall.forward;
36407 //Roo.log('next cell after edit');
36408 g.startEditing.defer(100, g, [newCell[0], newCell[1]]);
36409 } else if (forward) {
36410 // tabbed past last
36411 this.fireEvent.defer(100, this, ['tabend',this]);
36416 * Ext JS Library 1.1.1
36417 * Copyright(c) 2006-2007, Ext JS, LLC.
36419 * Originally Released Under LGPL - original licence link has changed is not relivant.
36422 * <script type="text/javascript">
36426 * @class Roo.grid.EditorGrid
36427 * @extends Roo.grid.Grid
36428 * Class for creating and editable grid.
36429 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
36430 * The container MUST have some type of size defined for the grid to fill. The container will be
36431 * automatically set to position relative if it isn't already.
36432 * @param {Object} dataSource The data model to bind to
36433 * @param {Object} colModel The column model with info about this grid's columns
36435 Roo.grid.EditorGrid = function(container, config){
36436 Roo.grid.EditorGrid.superclass.constructor.call(this, container, config);
36437 this.getGridEl().addClass("xedit-grid");
36439 if(!this.selModel){
36440 this.selModel = new Roo.grid.CellSelectionModel();
36443 this.activeEditor = null;
36447 * @event beforeedit
36448 * Fires before cell editing is triggered. The edit event object has the following properties <br />
36449 * <ul style="padding:5px;padding-left:16px;">
36450 * <li>grid - This grid</li>
36451 * <li>record - The record being edited</li>
36452 * <li>field - The field name being edited</li>
36453 * <li>value - The value for the field being edited.</li>
36454 * <li>row - The grid row index</li>
36455 * <li>column - The grid column index</li>
36456 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
36458 * @param {Object} e An edit event (see above for description)
36460 "beforeedit" : true,
36463 * Fires after a cell is edited. <br />
36464 * <ul style="padding:5px;padding-left:16px;">
36465 * <li>grid - This grid</li>
36466 * <li>record - The record being edited</li>
36467 * <li>field - The field name being edited</li>
36468 * <li>value - The value being set</li>
36469 * <li>originalValue - The original value for the field, before the edit.</li>
36470 * <li>row - The grid row index</li>
36471 * <li>column - The grid column index</li>
36473 * @param {Object} e An edit event (see above for description)
36475 "afteredit" : true,
36477 * @event validateedit
36478 * Fires after a cell is edited, but before the value is set in the record.
36479 * You can use this to modify the value being set in the field, Return false
36480 * to cancel the change. The edit event object has the following properties <br />
36481 * <ul style="padding:5px;padding-left:16px;">
36482 * <li>editor - This editor</li>
36483 * <li>grid - This grid</li>
36484 * <li>record - The record being edited</li>
36485 * <li>field - The field name being edited</li>
36486 * <li>value - The value being set</li>
36487 * <li>originalValue - The original value for the field, before the edit.</li>
36488 * <li>row - The grid row index</li>
36489 * <li>column - The grid column index</li>
36490 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
36492 * @param {Object} e An edit event (see above for description)
36494 "validateedit" : true
36496 this.on("bodyscroll", this.stopEditing, this);
36497 this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick, this);
36500 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
36502 * @cfg {Number} clicksToEdit
36503 * The number of clicks on a cell required to display the cell's editor (defaults to 2)
36510 trackMouseOver: false, // causes very odd FF errors
36512 onCellDblClick : function(g, row, col){
36513 this.startEditing(row, col);
36516 onEditComplete : function(ed, value, startValue){
36517 this.editing = false;
36518 this.activeEditor = null;
36519 ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
36521 var field = this.colModel.getDataIndex(ed.col);
36526 originalValue: startValue,
36533 var cell = Roo.get(this.view.getCell(ed.row,ed.col));
36536 if(String(value) !== String(startValue)){
36538 if(this.fireEvent("validateedit", e) !== false && !e.cancel){
36539 r.set(field, e.value);
36540 // if we are dealing with a combo box..
36541 // then we also set the 'name' colum to be the displayField
36542 if (ed.field.displayField && ed.field.name) {
36543 r.set(ed.field.name, ed.field.el.dom.value);
36546 delete e.cancel; //?? why!!!
36547 this.fireEvent("afteredit", e);
36550 this.fireEvent("afteredit", e); // always fire it!
36552 this.view.focusCell(ed.row, ed.col);
36556 * Starts editing the specified for the specified row/column
36557 * @param {Number} rowIndex
36558 * @param {Number} colIndex
36560 startEditing : function(row, col){
36561 this.stopEditing();
36562 if(this.colModel.isCellEditable(col, row)){
36563 this.view.ensureVisible(row, col, true);
36565 var r = this.dataSource.getAt(row);
36566 var field = this.colModel.getDataIndex(col);
36567 var cell = Roo.get(this.view.getCell(row,col));
36572 value: r.data[field],
36577 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
36578 this.editing = true;
36579 var ed = this.colModel.getCellEditor(col, row);
36585 ed.render(ed.parentEl || document.body);
36591 (function(){ // complex but required for focus issues in safari, ie and opera
36595 ed.on("complete", this.onEditComplete, this, {single: true});
36596 ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
36597 this.activeEditor = ed;
36598 var v = r.data[field];
36599 ed.startEdit(this.view.getCell(row, col), v);
36600 // combo's with 'displayField and name set
36601 if (ed.field.displayField && ed.field.name) {
36602 ed.field.el.dom.value = r.data[ed.field.name];
36606 }).defer(50, this);
36612 * Stops any active editing
36614 stopEditing : function(){
36615 if(this.activeEditor){
36616 this.activeEditor.completeEdit();
36618 this.activeEditor = null;
36622 * Called to get grid's drag proxy text, by default returns this.ddText.
36625 getDragDropText : function(){
36626 var count = this.selModel.getSelectedCell() ? 1 : 0;
36627 return String.format(this.ddText, count, count == 1 ? '' : 's');
36632 * Ext JS Library 1.1.1
36633 * Copyright(c) 2006-2007, Ext JS, LLC.
36635 * Originally Released Under LGPL - original licence link has changed is not relivant.
36638 * <script type="text/javascript">
36641 // private - not really -- you end up using it !
36642 // This is a support class used internally by the Grid components
36645 * @class Roo.grid.GridEditor
36646 * @extends Roo.Editor
36647 * Class for creating and editable grid elements.
36648 * @param {Object} config any settings (must include field)
36650 Roo.grid.GridEditor = function(field, config){
36651 if (!config && field.field) {
36653 field = Roo.factory(config.field, Roo.form);
36655 Roo.grid.GridEditor.superclass.constructor.call(this, field, config);
36656 field.monitorTab = false;
36659 Roo.extend(Roo.grid.GridEditor, Roo.Editor, {
36662 * @cfg {Roo.form.Field} field Field to wrap (or xtyped)
36665 alignment: "tl-tl",
36668 cls: "x-small-editor x-grid-editor",
36673 * Ext JS Library 1.1.1
36674 * Copyright(c) 2006-2007, Ext JS, LLC.
36676 * Originally Released Under LGPL - original licence link has changed is not relivant.
36679 * <script type="text/javascript">
36684 Roo.grid.PropertyRecord = Roo.data.Record.create([
36685 {name:'name',type:'string'}, 'value'
36689 Roo.grid.PropertyStore = function(grid, source){
36691 this.store = new Roo.data.Store({
36692 recordType : Roo.grid.PropertyRecord
36694 this.store.on('update', this.onUpdate, this);
36696 this.setSource(source);
36698 Roo.grid.PropertyStore.superclass.constructor.call(this);
36703 Roo.extend(Roo.grid.PropertyStore, Roo.util.Observable, {
36704 setSource : function(o){
36706 this.store.removeAll();
36709 if(this.isEditableValue(o[k])){
36710 data.push(new Roo.grid.PropertyRecord({name: k, value: o[k]}, k));
36713 this.store.loadRecords({records: data}, {}, true);
36716 onUpdate : function(ds, record, type){
36717 if(type == Roo.data.Record.EDIT){
36718 var v = record.data['value'];
36719 var oldValue = record.modified['value'];
36720 if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
36721 this.source[record.id] = v;
36723 this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
36730 getProperty : function(row){
36731 return this.store.getAt(row);
36734 isEditableValue: function(val){
36735 if(val && val instanceof Date){
36737 }else if(typeof val == 'object' || typeof val == 'function'){
36743 setValue : function(prop, value){
36744 this.source[prop] = value;
36745 this.store.getById(prop).set('value', value);
36748 getSource : function(){
36749 return this.source;
36753 Roo.grid.PropertyColumnModel = function(grid, store){
36756 g.PropertyColumnModel.superclass.constructor.call(this, [
36757 {header: this.nameText, sortable: true, dataIndex:'name', id: 'name'},
36758 {header: this.valueText, resizable:false, dataIndex: 'value', id: 'value'}
36760 this.store = store;
36761 this.bselect = Roo.DomHelper.append(document.body, {
36762 tag: 'select', style:'display:none', cls: 'x-grid-editor', children: [
36763 {tag: 'option', value: 'true', html: 'true'},
36764 {tag: 'option', value: 'false', html: 'false'}
36767 Roo.id(this.bselect);
36770 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
36771 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
36772 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
36773 'int' : new g.GridEditor(new f.NumberField({selectOnFocus:true, allowDecimals:false, style:'text-align:left;'})),
36774 'boolean' : new g.GridEditor(new f.Field({el:this.bselect,selectOnFocus:true}))
36776 this.renderCellDelegate = this.renderCell.createDelegate(this);
36777 this.renderPropDelegate = this.renderProp.createDelegate(this);
36780 Roo.extend(Roo.grid.PropertyColumnModel, Roo.grid.ColumnModel, {
36784 valueText : 'Value',
36786 dateFormat : 'm/j/Y',
36789 renderDate : function(dateVal){
36790 return dateVal.dateFormat(this.dateFormat);
36793 renderBool : function(bVal){
36794 return bVal ? 'true' : 'false';
36797 isCellEditable : function(colIndex, rowIndex){
36798 return colIndex == 1;
36801 getRenderer : function(col){
36803 this.renderCellDelegate : this.renderPropDelegate;
36806 renderProp : function(v){
36807 return this.getPropertyName(v);
36810 renderCell : function(val){
36812 if(val instanceof Date){
36813 rv = this.renderDate(val);
36814 }else if(typeof val == 'boolean'){
36815 rv = this.renderBool(val);
36817 return Roo.util.Format.htmlEncode(rv);
36820 getPropertyName : function(name){
36821 var pn = this.grid.propertyNames;
36822 return pn && pn[name] ? pn[name] : name;
36825 getCellEditor : function(colIndex, rowIndex){
36826 var p = this.store.getProperty(rowIndex);
36827 var n = p.data['name'], val = p.data['value'];
36829 if(typeof(this.grid.customEditors[n]) == 'string'){
36830 return this.editors[this.grid.customEditors[n]];
36832 if(typeof(this.grid.customEditors[n]) != 'undefined'){
36833 return this.grid.customEditors[n];
36835 if(val instanceof Date){
36836 return this.editors['date'];
36837 }else if(typeof val == 'number'){
36838 return this.editors['number'];
36839 }else if(typeof val == 'boolean'){
36840 return this.editors['boolean'];
36842 return this.editors['string'];
36848 * @class Roo.grid.PropertyGrid
36849 * @extends Roo.grid.EditorGrid
36850 * This class represents the interface of a component based property grid control.
36851 * <br><br>Usage:<pre><code>
36852 var grid = new Roo.grid.PropertyGrid("my-container-id", {
36860 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
36861 * The container MUST have some type of size defined for the grid to fill. The container will be
36862 * automatically set to position relative if it isn't already.
36863 * @param {Object} config A config object that sets properties on this grid.
36865 Roo.grid.PropertyGrid = function(container, config){
36866 config = config || {};
36867 var store = new Roo.grid.PropertyStore(this);
36868 this.store = store;
36869 var cm = new Roo.grid.PropertyColumnModel(this, store);
36870 store.store.sort('name', 'ASC');
36871 Roo.grid.PropertyGrid.superclass.constructor.call(this, container, Roo.apply({
36874 enableColLock:false,
36875 enableColumnMove:false,
36877 trackMouseOver: false,
36880 this.getGridEl().addClass('x-props-grid');
36881 this.lastEditRow = null;
36882 this.on('columnresize', this.onColumnResize, this);
36885 * @event beforepropertychange
36886 * Fires before a property changes (return false to stop?)
36887 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
36888 * @param {String} id Record Id
36889 * @param {String} newval New Value
36890 * @param {String} oldval Old Value
36892 "beforepropertychange": true,
36894 * @event propertychange
36895 * Fires after a property changes
36896 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
36897 * @param {String} id Record Id
36898 * @param {String} newval New Value
36899 * @param {String} oldval Old Value
36901 "propertychange": true
36903 this.customEditors = this.customEditors || {};
36905 Roo.extend(Roo.grid.PropertyGrid, Roo.grid.EditorGrid, {
36908 * @cfg {Object} customEditors map of colnames=> custom editors.
36909 * the custom editor can be one of the standard ones (date|string|number|int|boolean), or a
36910 * grid editor eg. Roo.grid.GridEditor(new Roo.form.TextArea({selectOnFocus:true})),
36911 * false disables editing of the field.
36915 * @cfg {Object} propertyNames map of property Names to their displayed value
36918 render : function(){
36919 Roo.grid.PropertyGrid.superclass.render.call(this);
36920 this.autoSize.defer(100, this);
36923 autoSize : function(){
36924 Roo.grid.PropertyGrid.superclass.autoSize.call(this);
36926 this.view.fitColumns();
36930 onColumnResize : function(){
36931 this.colModel.setColumnWidth(1, this.container.getWidth(true)-this.colModel.getColumnWidth(0));
36935 * Sets the data for the Grid
36936 * accepts a Key => Value object of all the elements avaiable.
36937 * @param {Object} data to appear in grid.
36939 setSource : function(source){
36940 this.store.setSource(source);
36944 * Gets all the data from the grid.
36945 * @return {Object} data data stored in grid
36947 getSource : function(){
36948 return this.store.getSource();
36957 * @class Roo.grid.Calendar
36958 * @extends Roo.util.Grid
36959 * This class extends the Grid to provide a calendar widget
36960 * <br><br>Usage:<pre><code>
36961 var grid = new Roo.grid.Calendar("my-container-id", {
36964 selModel: mySelectionModel,
36965 autoSizeColumns: true,
36966 monitorWindowResize: false,
36967 trackMouseOver: true
36968 eventstore : real data store..
36974 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
36975 * The container MUST have some type of size defined for the grid to fill. The container will be
36976 * automatically set to position relative if it isn't already.
36977 * @param {Object} config A config object that sets properties on this grid.
36979 Roo.grid.Calendar = function(container, config){
36980 // initialize the container
36981 this.container = Roo.get(container);
36982 this.container.update("");
36983 this.container.setStyle("overflow", "hidden");
36984 this.container.addClass('x-grid-container');
36986 this.id = this.container.id;
36988 Roo.apply(this, config);
36989 // check and correct shorthanded configs
36993 for (var r = 0;r < 6;r++) {
36996 for (var c =0;c < 7;c++) {
37000 if (this.eventStore) {
37001 this.eventStore= Roo.factory(this.eventStore, Roo.data);
37002 this.eventStore.on('load',this.onLoad, this);
37003 this.eventStore.on('beforeload',this.clearEvents, this);
37007 this.dataSource = new Roo.data.Store({
37008 proxy: new Roo.data.MemoryProxy(rows),
37009 reader: new Roo.data.ArrayReader({}, [
37010 'weekday0', 'weekday1', 'weekday2', 'weekday3', 'weekday4', 'weekday5', 'weekday6' ])
37013 this.dataSource.load();
37014 this.ds = this.dataSource;
37015 this.ds.xmodule = this.xmodule || false;
37018 var cellRender = function(v,x,r)
37020 return String.format(
37021 '<div class="fc-day fc-widget-content"><div>' +
37022 '<div class="fc-event-container"></div>' +
37023 '<div class="fc-day-number">{0}</div>'+
37025 '<div class="fc-day-content"><div style="position:relative"></div></div>' +
37026 '</div></div>', v);
37031 this.colModel = new Roo.grid.ColumnModel( [
37033 xtype: 'ColumnModel',
37035 dataIndex : 'weekday0',
37037 renderer : cellRender
37040 xtype: 'ColumnModel',
37042 dataIndex : 'weekday1',
37044 renderer : cellRender
37047 xtype: 'ColumnModel',
37049 dataIndex : 'weekday2',
37050 header : 'Tuesday',
37051 renderer : cellRender
37054 xtype: 'ColumnModel',
37056 dataIndex : 'weekday3',
37057 header : 'Wednesday',
37058 renderer : cellRender
37061 xtype: 'ColumnModel',
37063 dataIndex : 'weekday4',
37064 header : 'Thursday',
37065 renderer : cellRender
37068 xtype: 'ColumnModel',
37070 dataIndex : 'weekday5',
37072 renderer : cellRender
37075 xtype: 'ColumnModel',
37077 dataIndex : 'weekday6',
37078 header : 'Saturday',
37079 renderer : cellRender
37082 this.cm = this.colModel;
37083 this.cm.xmodule = this.xmodule || false;
37087 //this.selModel = new Roo.grid.CellSelectionModel();
37088 //this.sm = this.selModel;
37089 //this.selModel.init(this);
37093 this.container.setWidth(this.width);
37097 this.container.setHeight(this.height);
37104 * The raw click event for the entire grid.
37105 * @param {Roo.EventObject} e
37110 * The raw dblclick event for the entire grid.
37111 * @param {Roo.EventObject} e
37115 * @event contextmenu
37116 * The raw contextmenu event for the entire grid.
37117 * @param {Roo.EventObject} e
37119 "contextmenu" : true,
37122 * The raw mousedown event for the entire grid.
37123 * @param {Roo.EventObject} e
37125 "mousedown" : true,
37128 * The raw mouseup event for the entire grid.
37129 * @param {Roo.EventObject} e
37134 * The raw mouseover event for the entire grid.
37135 * @param {Roo.EventObject} e
37137 "mouseover" : true,
37140 * The raw mouseout event for the entire grid.
37141 * @param {Roo.EventObject} e
37146 * The raw keypress event for the entire grid.
37147 * @param {Roo.EventObject} e
37152 * The raw keydown event for the entire grid.
37153 * @param {Roo.EventObject} e
37161 * Fires when a cell is clicked
37162 * @param {Grid} this
37163 * @param {Number} rowIndex
37164 * @param {Number} columnIndex
37165 * @param {Roo.EventObject} e
37167 "cellclick" : true,
37169 * @event celldblclick
37170 * Fires when a cell is double clicked
37171 * @param {Grid} this
37172 * @param {Number} rowIndex
37173 * @param {Number} columnIndex
37174 * @param {Roo.EventObject} e
37176 "celldblclick" : true,
37179 * Fires when a row is clicked
37180 * @param {Grid} this
37181 * @param {Number} rowIndex
37182 * @param {Roo.EventObject} e
37186 * @event rowdblclick
37187 * Fires when a row is double clicked
37188 * @param {Grid} this
37189 * @param {Number} rowIndex
37190 * @param {Roo.EventObject} e
37192 "rowdblclick" : true,
37194 * @event headerclick
37195 * Fires when a header is clicked
37196 * @param {Grid} this
37197 * @param {Number} columnIndex
37198 * @param {Roo.EventObject} e
37200 "headerclick" : true,
37202 * @event headerdblclick
37203 * Fires when a header cell is double clicked
37204 * @param {Grid} this
37205 * @param {Number} columnIndex
37206 * @param {Roo.EventObject} e
37208 "headerdblclick" : true,
37210 * @event rowcontextmenu
37211 * Fires when a row is right clicked
37212 * @param {Grid} this
37213 * @param {Number} rowIndex
37214 * @param {Roo.EventObject} e
37216 "rowcontextmenu" : true,
37218 * @event cellcontextmenu
37219 * Fires when a cell is right clicked
37220 * @param {Grid} this
37221 * @param {Number} rowIndex
37222 * @param {Number} cellIndex
37223 * @param {Roo.EventObject} e
37225 "cellcontextmenu" : true,
37227 * @event headercontextmenu
37228 * Fires when a header is right clicked
37229 * @param {Grid} this
37230 * @param {Number} columnIndex
37231 * @param {Roo.EventObject} e
37233 "headercontextmenu" : true,
37235 * @event bodyscroll
37236 * Fires when the body element is scrolled
37237 * @param {Number} scrollLeft
37238 * @param {Number} scrollTop
37240 "bodyscroll" : true,
37242 * @event columnresize
37243 * Fires when the user resizes a column
37244 * @param {Number} columnIndex
37245 * @param {Number} newSize
37247 "columnresize" : true,
37249 * @event columnmove
37250 * Fires when the user moves a column
37251 * @param {Number} oldIndex
37252 * @param {Number} newIndex
37254 "columnmove" : true,
37257 * Fires when row(s) start being dragged
37258 * @param {Grid} this
37259 * @param {Roo.GridDD} dd The drag drop object
37260 * @param {event} e The raw browser event
37262 "startdrag" : true,
37265 * Fires when a drag operation is complete
37266 * @param {Grid} this
37267 * @param {Roo.GridDD} dd The drag drop object
37268 * @param {event} e The raw browser event
37273 * Fires when dragged row(s) are dropped on a valid DD target
37274 * @param {Grid} this
37275 * @param {Roo.GridDD} dd The drag drop object
37276 * @param {String} targetId The target drag drop object
37277 * @param {event} e The raw browser event
37282 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
37283 * @param {Grid} this
37284 * @param {Roo.GridDD} dd The drag drop object
37285 * @param {String} targetId The target drag drop object
37286 * @param {event} e The raw browser event
37291 * Fires when the dragged row(s) first cross another DD target while being dragged
37292 * @param {Grid} this
37293 * @param {Roo.GridDD} dd The drag drop object
37294 * @param {String} targetId The target drag drop object
37295 * @param {event} e The raw browser event
37297 "dragenter" : true,
37300 * Fires when the dragged row(s) leave another DD target while being dragged
37301 * @param {Grid} this
37302 * @param {Roo.GridDD} dd The drag drop object
37303 * @param {String} targetId The target drag drop object
37304 * @param {event} e The raw browser event
37309 * Fires when a row is rendered, so you can change add a style to it.
37310 * @param {GridView} gridview The grid view
37311 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
37317 * Fires when the grid is rendered
37318 * @param {Grid} grid
37323 * Fires when a date is selected
37324 * @param {DatePicker} this
37325 * @param {Date} date The selected date
37329 * @event monthchange
37330 * Fires when the displayed month changes
37331 * @param {DatePicker} this
37332 * @param {Date} date The selected month
37334 'monthchange': true,
37336 * @event evententer
37337 * Fires when mouse over an event
37338 * @param {Calendar} this
37339 * @param {event} Event
37341 'evententer': true,
37343 * @event eventleave
37344 * Fires when the mouse leaves an
37345 * @param {Calendar} this
37348 'eventleave': true,
37350 * @event eventclick
37351 * Fires when the mouse click an
37352 * @param {Calendar} this
37355 'eventclick': true,
37357 * @event eventrender
37358 * Fires before each cell is rendered, so you can modify the contents, like cls / title / qtip
37359 * @param {Calendar} this
37360 * @param {data} data to be modified
37362 'eventrender': true
37366 Roo.grid.Grid.superclass.constructor.call(this);
37367 this.on('render', function() {
37368 this.view.el.addClass('x-grid-cal');
37370 (function() { this.setDate(new Date()); }).defer(100,this); //default today..
37374 if (!Roo.grid.Calendar.style) {
37375 Roo.grid.Calendar.style = Roo.util.CSS.createStyleSheet({
37378 '.x-grid-cal .x-grid-col' : {
37379 height: 'auto !important',
37380 'vertical-align': 'top'
37382 '.x-grid-cal .fc-event-hori' : {
37393 Roo.extend(Roo.grid.Calendar, Roo.grid.Grid, {
37395 * @cfg {Store} eventStore The store that loads events.
37400 activeDate : false,
37403 monitorWindowResize : false,
37406 resizeColumns : function() {
37407 var col = (this.view.el.getWidth() / 7) - 3;
37408 // loop through cols, and setWidth
37409 for(var i =0 ; i < 7 ; i++){
37410 this.cm.setColumnWidth(i, col);
37413 setDate :function(date) {
37415 Roo.log('setDate?');
37417 this.resizeColumns();
37418 var vd = this.activeDate;
37419 this.activeDate = date;
37420 // if(vd && this.el){
37421 // var t = date.getTime();
37422 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
37423 // Roo.log('using add remove');
37425 // this.fireEvent('monthchange', this, date);
37427 // this.cells.removeClass("fc-state-highlight");
37428 // this.cells.each(function(c){
37429 // if(c.dateValue == t){
37430 // c.addClass("fc-state-highlight");
37431 // setTimeout(function(){
37432 // try{c.dom.firstChild.focus();}catch(e){}
37442 var days = date.getDaysInMonth();
37444 var firstOfMonth = date.getFirstDateOfMonth();
37445 var startingPos = firstOfMonth.getDay()-this.startDay;
37447 if(startingPos < this.startDay){
37451 var pm = date.add(Date.MONTH, -1);
37452 var prevStart = pm.getDaysInMonth()-startingPos;
37456 this.cells = this.view.el.select('.x-grid-row .x-grid-col',true);
37458 this.textNodes = this.view.el.query('.x-grid-row .x-grid-col .x-grid-cell-text');
37459 //this.cells.addClassOnOver('fc-state-hover');
37461 var cells = this.cells.elements;
37462 var textEls = this.textNodes;
37464 //Roo.each(cells, function(cell){
37465 // cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
37468 days += startingPos;
37470 // convert everything to numbers so it's fast
37471 var day = 86400000;
37472 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
37475 //Roo.log(prevStart);
37477 var today = new Date().clearTime().getTime();
37478 var sel = date.clearTime().getTime();
37479 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
37480 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
37481 var ddMatch = this.disabledDatesRE;
37482 var ddText = this.disabledDatesText;
37483 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
37484 var ddaysText = this.disabledDaysText;
37485 var format = this.format;
37487 var setCellClass = function(cal, cell){
37489 //Roo.log('set Cell Class');
37491 var t = d.getTime();
37496 cell.dateValue = t;
37498 cell.className += " fc-today";
37499 cell.className += " fc-state-highlight";
37500 cell.title = cal.todayText;
37503 // disable highlight in other month..
37504 cell.className += " fc-state-highlight";
37509 //cell.className = " fc-state-disabled";
37510 cell.title = cal.minText;
37514 //cell.className = " fc-state-disabled";
37515 cell.title = cal.maxText;
37519 if(ddays.indexOf(d.getDay()) != -1){
37520 // cell.title = ddaysText;
37521 // cell.className = " fc-state-disabled";
37524 if(ddMatch && format){
37525 var fvalue = d.dateFormat(format);
37526 if(ddMatch.test(fvalue)){
37527 cell.title = ddText.replace("%0", fvalue);
37528 cell.className = " fc-state-disabled";
37532 if (!cell.initialClassName) {
37533 cell.initialClassName = cell.dom.className;
37536 cell.dom.className = cell.initialClassName + ' ' + cell.className;
37541 for(; i < startingPos; i++) {
37542 cells[i].dayName = (++prevStart);
37543 Roo.log(textEls[i]);
37544 d.setDate(d.getDate()+1);
37546 //cells[i].className = "fc-past fc-other-month";
37547 setCellClass(this, cells[i]);
37552 for(; i < days; i++){
37553 intDay = i - startingPos + 1;
37554 cells[i].dayName = (intDay);
37555 d.setDate(d.getDate()+1);
37557 cells[i].className = ''; // "x-date-active";
37558 setCellClass(this, cells[i]);
37562 for(; i < 42; i++) {
37563 //textEls[i].innerHTML = (++extraDays);
37565 d.setDate(d.getDate()+1);
37566 cells[i].dayName = (++extraDays);
37567 cells[i].className = "fc-future fc-other-month";
37568 setCellClass(this, cells[i]);
37571 //this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
37573 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
37575 // this will cause all the cells to mis
37578 for (var r = 0;r < 6;r++) {
37579 for (var c =0;c < 7;c++) {
37580 this.ds.getAt(r).set('weekday' + c ,cells[i++].dayName );
37584 this.cells = this.view.el.select('.x-grid-row .x-grid-col',true);
37585 for(i=0;i<cells.length;i++) {
37587 this.cells.elements[i].dayName = cells[i].dayName ;
37588 this.cells.elements[i].className = cells[i].className;
37589 this.cells.elements[i].initialClassName = cells[i].initialClassName ;
37590 this.cells.elements[i].title = cells[i].title ;
37591 this.cells.elements[i].dateValue = cells[i].dateValue ;
37597 //this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
37598 //this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
37600 ////if(totalRows != 6){
37601 //this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
37602 // this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
37605 this.fireEvent('monthchange', this, date);
37610 * Returns the grid's SelectionModel.
37611 * @return {SelectionModel}
37613 getSelectionModel : function(){
37614 if(!this.selModel){
37615 this.selModel = new Roo.grid.CellSelectionModel();
37617 return this.selModel;
37621 this.eventStore.load()
37627 findCell : function(dt) {
37628 dt = dt.clearTime().getTime();
37630 this.cells.each(function(c){
37631 //Roo.log("check " +c.dateValue + '?=' + dt);
37632 if(c.dateValue == dt){
37642 findCells : function(rec) {
37643 var s = rec.data.start_dt.clone().clearTime().getTime();
37645 var e= rec.data.end_dt.clone().clearTime().getTime();
37648 this.cells.each(function(c){
37649 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
37651 if(c.dateValue > e){
37654 if(c.dateValue < s){
37663 findBestRow: function(cells)
37667 for (var i =0 ; i < cells.length;i++) {
37668 ret = Math.max(cells[i].rows || 0,ret);
37675 addItem : function(rec)
37677 // look for vertical location slot in
37678 var cells = this.findCells(rec);
37680 rec.row = this.findBestRow(cells);
37682 // work out the location.
37686 for(var i =0; i < cells.length; i++) {
37694 if (crow.start.getY() == cells[i].getY()) {
37696 crow.end = cells[i];
37712 for (var i = 0; i < cells.length;i++) {
37713 cells[i].rows = Math.max(cells[i].rows || 0 , rec.row + 1 );
37720 clearEvents: function() {
37722 if (!this.eventStore.getCount()) {
37725 // reset number of rows in cells.
37726 Roo.each(this.cells.elements, function(c){
37730 this.eventStore.each(function(e) {
37731 this.clearEvent(e);
37736 clearEvent : function(ev)
37739 Roo.each(ev.els, function(el) {
37740 el.un('mouseenter' ,this.onEventEnter, this);
37741 el.un('mouseleave' ,this.onEventLeave, this);
37749 renderEvent : function(ev,ctr) {
37751 ctr = this.view.el.select('.fc-event-container',true).first();
37755 this.clearEvent(ev);
37761 var cells = ev.cells;
37762 var rows = ev.rows;
37763 this.fireEvent('eventrender', this, ev);
37765 for(var i =0; i < rows.length; i++) {
37769 cls += ' fc-event-start';
37771 if ((i+1) == rows.length) {
37772 cls += ' fc-event-end';
37775 //Roo.log(ev.data);
37776 // how many rows should it span..
37777 var cg = this.eventTmpl.append(ctr,Roo.apply({
37780 }, ev.data) , true);
37783 cg.on('mouseenter' ,this.onEventEnter, this, ev);
37784 cg.on('mouseleave' ,this.onEventLeave, this, ev);
37785 cg.on('click', this.onEventClick, this, ev);
37789 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
37790 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
37793 cg.setXY([sbox.x +2, sbox.y +(ev.row * 20)]);
37794 cg.setWidth(ebox.right - sbox.x -2);
37798 renderEvents: function()
37800 // first make sure there is enough space..
37802 if (!this.eventTmpl) {
37803 this.eventTmpl = new Roo.Template(
37804 '<div class="roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable {fccls} {cls}" style="position: absolute" unselectable="on">' +
37805 '<div class="fc-event-inner">' +
37806 '<span class="fc-event-time">{time}</span>' +
37807 '<span class="fc-event-title" qtip="{qtip}">{title}</span>' +
37809 '<div class="ui-resizable-heandle ui-resizable-e"> </div>' +
37817 this.cells.each(function(c) {
37818 //Roo.log(c.select('.fc-day-content div',true).first());
37819 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, (c.rows || 1) * 20));
37822 var ctr = this.view.el.select('.fc-event-container',true).first();
37825 this.eventStore.each(function(ev){
37827 this.renderEvent(ev);
37831 this.view.layout();
37835 onEventEnter: function (e, el,event,d) {
37836 this.fireEvent('evententer', this, el, event);
37839 onEventLeave: function (e, el,event,d) {
37840 this.fireEvent('eventleave', this, el, event);
37843 onEventClick: function (e, el,event,d) {
37844 this.fireEvent('eventclick', this, el, event);
37847 onMonthChange: function () {
37851 onLoad: function () {
37853 //Roo.log('calendar onload');
37855 if(this.eventStore.getCount() > 0){
37859 this.eventStore.each(function(d){
37864 if (typeof(add.end_dt) == 'undefined') {
37865 Roo.log("Missing End time in calendar data: ");
37869 if (typeof(add.start_dt) == 'undefined') {
37870 Roo.log("Missing Start time in calendar data: ");
37874 add.start_dt = typeof(add.start_dt) == 'string' ? Date.parseDate(add.start_dt,'Y-m-d H:i:s') : add.start_dt,
37875 add.end_dt = typeof(add.end_dt) == 'string' ? Date.parseDate(add.end_dt,'Y-m-d H:i:s') : add.end_dt,
37876 add.id = add.id || d.id;
37877 add.title = add.title || '??';
37885 this.renderEvents();
37895 render : function ()
37899 if (!this.view.el.hasClass('course-timesheet')) {
37900 this.view.el.addClass('course-timesheet');
37902 if (this.tsStyle) {
37907 Roo.log(_this.grid.view.el.getWidth());
37910 this.tsStyle = Roo.util.CSS.createStyleSheet({
37911 '.course-timesheet .x-grid-row' : {
37914 '.x-grid-row td' : {
37915 'vertical-align' : 0
37917 '.course-edit-link' : {
37919 'text-overflow' : 'ellipsis',
37920 'overflow' : 'hidden',
37921 'white-space' : 'nowrap',
37922 'cursor' : 'pointer'
37927 '.de-act-sup-link' : {
37928 'color' : 'purple',
37929 'text-decoration' : 'line-through'
37933 'text-decoration' : 'line-through'
37935 '.course-timesheet .course-highlight' : {
37936 'border-top-style': 'dashed !important',
37937 'border-bottom-bottom': 'dashed !important'
37939 '.course-timesheet .course-item' : {
37940 'font-family' : 'tahoma, arial, helvetica',
37941 'font-size' : '11px',
37942 'overflow' : 'hidden',
37943 'padding-left' : '10px',
37944 'padding-right' : '10px',
37945 'padding-top' : '10px'
37953 monitorWindowResize : false,
37954 cellrenderer : function(v,x,r)
37959 xtype: 'CellSelectionModel',
37966 beforeload : function (_self, options)
37968 options.params = options.params || {};
37969 options.params._month = _this.monthField.getValue();
37970 options.params.limit = 9999;
37971 options.params['sort'] = 'when_dt';
37972 options.params['dir'] = 'ASC';
37973 this.proxy.loadResponse = this.loadResponse;
37975 //this.addColumns();
37977 load : function (_self, records, options)
37979 _this.grid.view.el.select('.course-edit-link', true).on('click', function() {
37980 // if you click on the translation.. you can edit it...
37981 var el = Roo.get(this);
37982 var id = el.dom.getAttribute('data-id');
37983 var d = el.dom.getAttribute('data-date');
37984 var t = el.dom.getAttribute('data-time');
37985 //var id = this.child('span').dom.textContent;
37988 Pman.Dialog.CourseCalendar.show({
37992 productitem_active : id ? 1 : 0
37994 _this.grid.ds.load({});
37999 _this.panel.fireEvent('resize', [ '', '' ]);
38002 loadResponse : function(o, success, response){
38003 // this is overridden on before load..
38005 Roo.log("our code?");
38006 //Roo.log(success);
38007 //Roo.log(response)
38008 delete this.activeRequest;
38010 this.fireEvent("loadexception", this, o, response);
38011 o.request.callback.call(o.request.scope, null, o.request.arg, false);
38016 result = o.reader.read(response);
38018 Roo.log("load exception?");
38019 this.fireEvent("loadexception", this, o, response, e);
38020 o.request.callback.call(o.request.scope, null, o.request.arg, false);
38023 Roo.log("ready...");
38024 // loop through result.records;
38025 // and set this.tdate[date] = [] << array of records..
38027 Roo.each(result.records, function(r){
38029 if(typeof(_this.tdata[r.data.when_dt.format('j')]) == 'undefined'){
38030 _this.tdata[r.data.when_dt.format('j')] = [];
38032 _this.tdata[r.data.when_dt.format('j')].push(r.data);
38035 //Roo.log(_this.tdata);
38037 result.records = [];
38038 result.totalRecords = 6;
38040 // let's generate some duumy records for the rows.
38041 //var st = _this.dateField.getValue();
38043 // work out monday..
38044 //st = st.add(Date.DAY, -1 * st.format('w'));
38046 var date = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38048 var firstOfMonth = date.getFirstDayOfMonth();
38049 var days = date.getDaysInMonth();
38051 var firstAdded = false;
38052 for (var i = 0; i < result.totalRecords ; i++) {
38053 //var d= st.add(Date.DAY, i);
38056 for(var w = 0 ; w < 7 ; w++){
38057 if(!firstAdded && firstOfMonth != w){
38064 var dd = (d > 0 && d < 10) ? "0"+d : d;
38065 row['weekday'+w] = String.format(
38066 '<span style="font-size: 16px;"><b>{0}</b></span>'+
38067 '<span class="course-edit-link" style="color:blue;" data-id="0" data-date="{1}"> Add New</span>',
38069 date.format('Y-m-')+dd
38072 if(typeof(_this.tdata[d]) != 'undefined'){
38073 Roo.each(_this.tdata[d], function(r){
38077 var desc = (r.productitem_id_descrip) ? r.productitem_id_descrip : '';
38078 if(r.parent_id*1>0){
38079 is_sub = (r.productitem_id_visible*1 < 1) ? 'de-act-sup-link' :'sub-link';
38082 if(r.productitem_id_visible*1 < 1 && r.parent_id*1 < 1){
38083 deactive = 'de-act-link';
38086 row['weekday'+w] += String.format(
38087 '<br /><span class="course-edit-link {3} {4}" qtip="{5}" data-id="{0}">{2} - {1}</span>',
38089 r.product_id_name, //1
38090 r.when_dt.format('h:ia'), //2
38100 // only do this if something added..
38102 result.records.push(_this.grid.dataSource.reader.newRow(row));
38106 // push it twice. (second one with an hour..
38110 this.fireEvent("load", this, o, o.request.arg);
38111 o.request.callback.call(o.request.scope, result, o.request.arg, true);
38113 sortInfo : {field: 'when_dt', direction : 'ASC' },
38115 xtype: 'HttpProxy',
38118 url : baseURL + '/Roo/Shop_course.php'
38121 xtype: 'JsonReader',
38138 'name': 'parent_id',
38142 'name': 'product_id',
38146 'name': 'productitem_id',
38164 click : function (_self, e)
38166 var sd = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38167 sd.setMonth(sd.getMonth()-1);
38168 _this.monthField.setValue(sd.format('Y-m-d'));
38169 _this.grid.ds.load({});
38175 xtype: 'Separator',
38179 xtype: 'MonthField',
38182 render : function (_self)
38184 _this.monthField = _self;
38185 // _this.monthField.set today
38187 select : function (combo, date)
38189 _this.grid.ds.load({});
38192 value : (function() { return new Date(); })()
38195 xtype: 'Separator',
38201 text : "Blue: in-active, green: in-active sup-event, red: de-active, purple: de-active sup-event"
38211 click : function (_self, e)
38213 var sd = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38214 sd.setMonth(sd.getMonth()+1);
38215 _this.monthField.setValue(sd.format('Y-m-d'));
38216 _this.grid.ds.load({});
38229 * Ext JS Library 1.1.1
38230 * Copyright(c) 2006-2007, Ext JS, LLC.
38232 * Originally Released Under LGPL - original licence link has changed is not relivant.
38235 * <script type="text/javascript">
38239 * @class Roo.LoadMask
38240 * A simple utility class for generically masking elements while loading data. If the element being masked has
38241 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
38242 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
38243 * element's UpdateManager load indicator and will be destroyed after the initial load.
38245 * Create a new LoadMask
38246 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
38247 * @param {Object} config The config object
38249 Roo.LoadMask = function(el, config){
38250 this.el = Roo.get(el);
38251 Roo.apply(this, config);
38253 this.store.on('beforeload', this.onBeforeLoad, this);
38254 this.store.on('load', this.onLoad, this);
38255 this.store.on('loadexception', this.onLoadException, this);
38256 this.removeMask = false;
38258 var um = this.el.getUpdateManager();
38259 um.showLoadIndicator = false; // disable the default indicator
38260 um.on('beforeupdate', this.onBeforeLoad, this);
38261 um.on('update', this.onLoad, this);
38262 um.on('failure', this.onLoad, this);
38263 this.removeMask = true;
38267 Roo.LoadMask.prototype = {
38269 * @cfg {Boolean} removeMask
38270 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
38271 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
38274 * @cfg {String} msg
38275 * The text to display in a centered loading message box (defaults to 'Loading...')
38277 msg : 'Loading...',
38279 * @cfg {String} msgCls
38280 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
38282 msgCls : 'x-mask-loading',
38285 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
38291 * Disables the mask to prevent it from being displayed
38293 disable : function(){
38294 this.disabled = true;
38298 * Enables the mask so that it can be displayed
38300 enable : function(){
38301 this.disabled = false;
38304 onLoadException : function()
38306 Roo.log(arguments);
38308 if (typeof(arguments[3]) != 'undefined') {
38309 Roo.MessageBox.alert("Error loading",arguments[3]);
38313 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
38314 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
38321 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
38324 onLoad : function()
38326 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
38330 onBeforeLoad : function(){
38331 if(!this.disabled){
38332 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
38337 destroy : function(){
38339 this.store.un('beforeload', this.onBeforeLoad, this);
38340 this.store.un('load', this.onLoad, this);
38341 this.store.un('loadexception', this.onLoadException, this);
38343 var um = this.el.getUpdateManager();
38344 um.un('beforeupdate', this.onBeforeLoad, this);
38345 um.un('update', this.onLoad, this);
38346 um.un('failure', this.onLoad, this);
38351 * Ext JS Library 1.1.1
38352 * Copyright(c) 2006-2007, Ext JS, LLC.
38354 * Originally Released Under LGPL - original licence link has changed is not relivant.
38357 * <script type="text/javascript">
38362 * @class Roo.XTemplate
38363 * @extends Roo.Template
38364 * Provides a template that can have nested templates for loops or conditionals. The syntax is:
38366 var t = new Roo.XTemplate(
38367 '<select name="{name}">',
38368 '<tpl for="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
38372 // then append, applying the master template values
38375 * Supported features:
38380 {a_variable} - output encoded.
38381 {a_variable.format:("Y-m-d")} - call a method on the variable
38382 {a_variable:raw} - unencoded output
38383 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
38384 {a_variable:this.method_on_template(...)} - call a method on the template object.
38389 <tpl for="a_variable or condition.."></tpl>
38390 <tpl if="a_variable or condition"></tpl>
38391 <tpl exec="some javascript"></tpl>
38392 <tpl name="named_template"></tpl> (experimental)
38394 <tpl for="."></tpl> - just iterate the property..
38395 <tpl for=".."></tpl> - iterates with the parent (probably the template)
38399 Roo.XTemplate = function()
38401 Roo.XTemplate.superclass.constructor.apply(this, arguments);
38408 Roo.extend(Roo.XTemplate, Roo.Template, {
38411 * The various sub templates
38416 * basic tag replacing syntax
38419 * // you can fake an object call by doing this
38423 re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
38426 * compile the template
38428 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
38431 compile: function()
38435 s = ['<tpl>', s, '</tpl>'].join('');
38437 var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
38438 nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
38439 ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
38440 execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
38441 namedRe = /^<tpl\b[^>]*?name="(\w+)"/, // named templates..
38446 while(true == !!(m = s.match(re))){
38447 var forMatch = m[0].match(nameRe),
38448 ifMatch = m[0].match(ifRe),
38449 execMatch = m[0].match(execRe),
38450 namedMatch = m[0].match(namedRe),
38455 name = forMatch && forMatch[1] ? forMatch[1] : '';
38458 // if - puts fn into test..
38459 exp = ifMatch && ifMatch[1] ? ifMatch[1] : null;
38461 fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
38466 // exec - calls a function... returns empty if true is returned.
38467 exp = execMatch && execMatch[1] ? execMatch[1] : null;
38469 exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
38477 case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
38478 case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
38479 default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
38482 var uid = namedMatch ? namedMatch[1] : id;
38486 id: namedMatch ? namedMatch[1] : id,
38493 s = s.replace(m[0], '');
38495 s = s.replace(m[0], '{xtpl'+ id + '}');
38500 for(var i = tpls.length-1; i >= 0; --i){
38501 this.compileTpl(tpls[i]);
38502 this.tpls[tpls[i].id] = tpls[i];
38504 this.master = tpls[tpls.length-1];
38508 * same as applyTemplate, except it's done to one of the subTemplates
38509 * when using named templates, you can do:
38511 * var str = pl.applySubTemplate('your-name', values);
38514 * @param {Number} id of the template
38515 * @param {Object} values to apply to template
38516 * @param {Object} parent (normaly the instance of this object)
38518 applySubTemplate : function(id, values, parent)
38522 var t = this.tpls[id];
38526 if(t.test && !t.test.call(this, values, parent)){
38530 Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");
38531 Roo.log(e.toString());
38537 if(t.exec && t.exec.call(this, values, parent)){
38541 Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");
38542 Roo.log(e.toString());
38547 var vs = t.target ? t.target.call(this, values, parent) : values;
38548 parent = t.target ? values : parent;
38549 if(t.target && vs instanceof Array){
38551 for(var i = 0, len = vs.length; i < len; i++){
38552 buf[buf.length] = t.compiled.call(this, vs[i], parent);
38554 return buf.join('');
38556 return t.compiled.call(this, vs, parent);
38558 Roo.log("Xtemplate.applySubTemplate : Exception thrown");
38559 Roo.log(e.toString());
38560 Roo.log(t.compiled);
38565 compileTpl : function(tpl)
38567 var fm = Roo.util.Format;
38568 var useF = this.disableFormats !== true;
38569 var sep = Roo.isGecko ? "+" : ",";
38570 var undef = function(str) {
38571 Roo.log("Property not found :" + str);
38575 var fn = function(m, name, format, args)
38577 //Roo.log(arguments);
38578 args = args ? args.replace(/\\'/g,"'") : args;
38579 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
38580 if (typeof(format) == 'undefined') {
38581 format= 'htmlEncode';
38583 if (format == 'raw' ) {
38587 if(name.substr(0, 4) == 'xtpl'){
38588 return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent)'+sep+"'";
38591 // build an array of options to determine if value is undefined..
38593 // basically get 'xxxx.yyyy' then do
38594 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
38595 // (function () { Roo.log("Property not found"); return ''; })() :
38600 Roo.each(name.split('.'), function(st) {
38601 lookfor += (lookfor.length ? '.': '') + st;
38602 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
38605 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
38608 if(format && useF){
38610 args = args ? ',' + args : "";
38612 if(format.substr(0, 5) != "this."){
38613 format = "fm." + format + '(';
38615 format = 'this.call("'+ format.substr(5) + '", ';
38619 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
38623 // called with xxyx.yuu:(test,test)
38625 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
38627 // raw.. - :raw modifier..
38628 return "'"+ sep + udef_st + name + ")"+sep+"'";
38632 // branched to use + in gecko and [].join() in others
38634 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
38635 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
38638 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
38639 body.push(tpl.body.replace(/(\r\n|\n)/g,
38640 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
38641 body.push("'].join('');};};");
38642 body = body.join('');
38645 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
38647 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
38653 applyTemplate : function(values){
38654 return this.master.compiled.call(this, values, {});
38655 //var s = this.subs;
38658 apply : function(){
38659 return this.applyTemplate.apply(this, arguments);
38664 Roo.XTemplate.from = function(el){
38665 el = Roo.getDom(el);
38666 return new Roo.XTemplate(el.value || el.innerHTML);